types

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxBlockTxesNum   = 99999
	TxMerkleTreeDepth = 10
)
View Source
const (
	BlockPositionOffset = 100000 // must be greater than MaxBlockTxesNum
	TxPositionOffset    = 10000  // must be greater than TxElementsNum
)
View Source
const (
	SignatureLength = 65 // bytes
)
View Source
const (
	TxElementsNum = 2
)

Variables

View Source
var (
	ErrInvalidTxIndex           = errors.New("tx index is invalid")
	ErrBlockTxesNumExceedsLimit = errors.New("block txes num exceeds the limit")
)
View Source
var (
	ErrInvalidTxInIndex  = fmt.Errorf("txin index must be less than %d", TxElementsNum)
	ErrInvalidTxOutIndex = fmt.Errorf("txout index must be less than %d", TxElementsNum)
)
View Source
var (
	ErrInvalidSignatureLength = fmt.Errorf("signature must be %d bytes", SignatureLength)
)
View Source
var (
	NullAddress = common.Address{
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	}
)
View Source
var (
	NullHash = common.Hash{
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00,
	}
)
View Source
var (
	NullSignature = Signature{
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00,
	}
)

Functions

func ParseTxInPosition

func ParseTxInPosition(pos Position) (uint64, uint64, uint64)

func ParseTxOutPosition

func ParseTxOutPosition(pos Position) (uint64, uint64, uint64)

func ParseTxPosition

func ParseTxPosition(pos Position) (blkNum, txIndex uint64)

func PositionToBytes

func PositionToBytes(pos Position) []byte

Types

type Account

type Account struct {
	// contains filtered or unexported fields
}

func NewAccount

func NewAccount(privKey *ecdsa.PrivateKey) *Account

func (*Account) Address

func (a *Account) Address() common.Address

func (*Account) Sign

func (a *Account) Sign(h common.Hash) ([]byte, error)

func (*Account) TransactOpts

func (a *Account) TransactOpts() *bind.TransactOpts

type Block

type Block struct {
	*BlockHeader
	Txes []*Tx `json:"txes"`
}

func NewBlock

func NewBlock(txes []*Tx, blkNum uint64) (*Block, error)

func (*Block) AddTx

func (blk *Block) AddTx(tx *Tx) error

func (*Block) Encode

func (blk *Block) Encode() ([]byte, error)

func (*Block) GetTx

func (blk *Block) GetTx(txIndex uint64) *Tx

func (*Block) Hash

func (blk *Block) Hash() (common.Hash, error)

func (*Block) IsExistTx

func (blk *Block) IsExistTx(txIndex uint64) bool

func (*Block) MerkleTree

func (blk *Block) MerkleTree() (*merkle.Tree, error)

func (*Block) Root

func (blk *Block) Root() (common.Hash, error)

func (*Block) Sign

func (blk *Block) Sign(signer *Account) error

func (*Block) SignerAddress

func (blk *Block) SignerAddress() (common.Address, error)

type BlockHeader

type BlockHeader struct {
	Number    uint64
	Signature Signature
}

type Exit

type Exit struct {
	Owner     common.Address `json:"owner"`
	Amount    *big.Int       `json:"amount"`
	IsStarted bool           `json:"started"`
	IsValid   bool           `json:"valid"`
}

type Position

type Position uint64

func BytesToPosition

func BytesToPosition(b []byte) (Position, error)

func NewTxInPosition

func NewTxInPosition(blkNum, txIndex, inIndex uint64) Position

func NewTxOutPosition

func NewTxOutPosition(blkNum, txIndex, outIndex uint64) Position

func NewTxPosition

func NewTxPosition(blkNum, txIndex uint64) Position

func StrToPosition

func StrToPosition(s string) (Position, error)

func (Position) Bytes

func (pos Position) Bytes() []byte

func (Position) Uint64

func (pos Position) Uint64() uint64

type Signature

type Signature [SignatureLength]byte

func BytesToSignature

func BytesToSignature(b []byte) (Signature, error)

func HexToSignature

func HexToSignature(s string) (Signature, error)

func (Signature) Bytes

func (sig Signature) Bytes() []byte

func (Signature) Hex

func (sig Signature) Hex() string

func (Signature) IsNull

func (sig Signature) IsNull() bool

func (Signature) MarshalText

func (sig Signature) MarshalText() ([]byte, error)

func (Signature) SignerAddress

func (sig Signature) SignerAddress(h common.Hash) (common.Address, error)

type Tx

type Tx struct {
	Inputs  [TxElementsNum]*TxIn  `json:"ins"`
	Outputs [TxElementsNum]*TxOut `json:"outs"`
}

func NewTx

func NewTx() *Tx

func (*Tx) Confirm

func (tx *Tx) Confirm(inIndex uint64, signer *Account) error

func (*Tx) ConfirmationHash

func (tx *Tx) ConfirmationHash() (common.Hash, error)

func (*Tx) ConfirmationSignaturesBytes

func (tx *Tx) ConfirmationSignaturesBytes() ([]byte, error)

func (*Tx) ConfirmationSignerAddress

func (tx *Tx) ConfirmationSignerAddress(inIndex uint64) (common.Address, error)

func (*Tx) Encode

func (tx *Tx) Encode() ([]byte, error)

func (*Tx) ExitOutput added in v0.2.0

func (tx *Tx) ExitOutput(outIndex uint64) error

func (*Tx) GetInput

func (tx *Tx) GetInput(inIndex uint64) *TxIn

func (*Tx) GetOutput

func (tx *Tx) GetOutput(outIndex uint64) *TxOut

func (*Tx) Hash

func (tx *Tx) Hash() (common.Hash, error)

func (*Tx) IsExistInput

func (tx *Tx) IsExistInput(inIndex uint64) bool

func (*Tx) IsExistOutput

func (tx *Tx) IsExistOutput(outIndex uint64) bool

func (*Tx) MerkleLeaf

func (tx *Tx) MerkleLeaf() ([]byte, error)

func (*Tx) RestoreOutput added in v0.4.0

func (tx *Tx) RestoreOutput(outIndex uint64) error

func (*Tx) SetConfirmationSignature

func (tx *Tx) SetConfirmationSignature(inIndex uint64, confSig Signature) error

func (*Tx) SetInput

func (tx *Tx) SetInput(inIndex uint64, txIn *TxIn) error

func (*Tx) SetOutput

func (tx *Tx) SetOutput(outIndex uint64, txOut *TxOut) error

func (*Tx) Sign

func (tx *Tx) Sign(inIndex uint64, signer *Account) error

func (*Tx) SignaturesBytes

func (tx *Tx) SignaturesBytes() ([]byte, error)

func (*Tx) SignerAddress

func (tx *Tx) SignerAddress(inIndex uint64) (common.Address, error)

func (*Tx) SpendOutput

func (tx *Tx) SpendOutput(outIndex uint64) error

type TxIn

type TxIn struct {
	*TxInCore
	Signature             Signature `json:"sig"`
	ConfirmationSignature Signature `json:"confsig"`
}

func NewTxIn

func NewTxIn(blkNum, txIndex, outIndex uint64) *TxIn

func (*TxIn) IsNull

func (txIn *TxIn) IsNull() bool

type TxInCore

type TxInCore struct {
	BlockNumber uint64 `json:"blknum"`
	TxIndex     uint64 `json:"txindex"`
	OutputIndex uint64 `json:"oindex"`
}

type TxOut

type TxOut struct {
	*TxOutCore
	IsSpent  bool `json:"spent"`
	IsExited bool `json:"exited"`
}

func NewTxOut

func NewTxOut(ownerAddr common.Address, amount *big.Int) *TxOut

type TxOutCore

type TxOutCore struct {
	OwnerAddress common.Address `json:"owner"`
	Amount       *big.Int       `json:"amount"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL