Documentation
¶
Index ¶
- Constants
- Variables
- func CtxSender(signer CtxSigner, tx *CrossTransaction) (common.Address, error)
- type CTxByPrice
- type CommitEvent
- type ConfirmedFinishEvent
- type ConfirmedMakerEvent
- type ConfirmedTakerEvent
- type CrossBlockEvent
- type CrossTransaction
- func (tx *CrossTransaction) BlockHash() common.Hash
- func (tx *CrossTransaction) ChainId() *big.Int
- func (tx CrossTransaction) DestinationId() *big.Int
- func (tx *CrossTransaction) From() common.Address
- func (tx *CrossTransaction) Hash() (h common.Hash)
- func (tx *CrossTransaction) ID() common.Hash
- func (tx *CrossTransaction) SignHash() (h common.Hash)
- func (tx *CrossTransaction) WithSignature(signer CtxSigner, sig []byte) (*CrossTransaction, error)
- type CrossTransactionModifier
- type CrossTransactionWithSignatures
- func (cws *CrossTransactionWithSignatures) AddSignature(ctx *CrossTransaction) error
- func (cws *CrossTransactionWithSignatures) BlockHash() common.Hash
- func (cws *CrossTransactionWithSignatures) ChainId() *big.Int
- func (cws *CrossTransactionWithSignatures) CrossTransaction() *CrossTransaction
- func (cws *CrossTransactionWithSignatures) DestinationId() *big.Int
- func (cws *CrossTransactionWithSignatures) From() common.Address
- func (cws *CrossTransactionWithSignatures) Hash() (h common.Hash)
- func (cws *CrossTransactionWithSignatures) ID() common.Hash
- func (cws *CrossTransactionWithSignatures) Price() *big.Rat
- func (cws *CrossTransactionWithSignatures) RemoveSignature(index int)
- func (cws *CrossTransactionWithSignatures) Resolution() []*CrossTransaction
- func (cws *CrossTransactionWithSignatures) SetStatus(status CtxStatus)
- func (cws *CrossTransactionWithSignatures) SignaturesLength() int
- func (cws *CrossTransactionWithSignatures) Size() common.StorageSize
- type CrossTransactions
- type CtxDatas
- type CtxID
- type CtxIDs
- type CtxSigner
- type CtxStatus
- type EIP155CtxSigner
- func (s EIP155CtxSigner) Equal(s2 CtxSigner) bool
- func (s EIP155CtxSigner) Hash(tx *CrossTransaction) (h common.Hash)
- func (s EIP155CtxSigner) Sender(tx *CrossTransaction) (common.Address, error)
- func (s EIP155CtxSigner) SignatureValues(tx *CrossTransaction, sig []byte) (R, S, V *big.Int, err error)
- type ModType
- type NewAnchorEvent
- type NewFinishEvent
- type NewTakerEvent
- type OwnerCrossTransactionWithSignatures
- type Recept
- type ReceptTransaction
- type RemoteChainInfo
- type SignHash
- type SignedCtxEvent
Constants ¶
const ( Normal = ModType(iota) Remote Reorg )
Variables ¶
var ( ErrInvalidRecept = errors.New("invalid recept transaction") ErrChainIdMissMatch = fmt.Errorf("[%w]: recept chainId miss match", ErrInvalidRecept) ErrToMissMatch = fmt.Errorf("[%w]: recept to address miss match", ErrInvalidRecept) ErrFromMissMatch = fmt.Errorf("[%w]: recept from address miss match", ErrInvalidRecept) )
var ErrDuplicateSign = errors.New("signatures already exist")
var ErrInvalidSign = errors.New("invalid signature, different sign hash")
Functions ¶
func CtxSender ¶
func CtxSender(signer CtxSigner, tx *CrossTransaction) (common.Address, error)
Sender returns the address derived from the signature (V, R, S) using secp256k1 elliptic curve and an error if it failed deriving or upon an incorrect signature.
Sender may cache the address, allowing it to be used regardless of signing method. The cache is invalidated if the cached signer does not match the signer used in the current call.
Types ¶
type CTxByPrice ¶
type CTxByPrice CrossTransactions
CTxByPrice implements both the sort and the heap interface, making it useful for all at once sorting as well as individually adding and removing elements.
func (CTxByPrice) Len ¶
func (s CTxByPrice) Len() int
func (CTxByPrice) Less ¶
func (s CTxByPrice) Less(i, j int) bool
func (*CTxByPrice) Pop ¶
func (s *CTxByPrice) Pop() interface{}
func (*CTxByPrice) Push ¶
func (s *CTxByPrice) Push(x interface{})
func (CTxByPrice) Swap ¶
func (s CTxByPrice) Swap(i, j int)
type CommitEvent ¶ added in v1.0.6
type CommitEvent struct { Tx *CrossTransactionWithSignatures InvalidSigIndex []int }
type ConfirmedFinishEvent ¶
type ConfirmedFinishEvent struct {
Finishes []*CrossTransactionModifier
}
type ConfirmedMakerEvent ¶
type ConfirmedMakerEvent struct {
Txs []*CrossTransaction
}
type ConfirmedTakerEvent ¶
type ConfirmedTakerEvent struct {
Txs []*ReceptTransaction
}
type CrossBlockEvent ¶ added in v1.0.6
type CrossBlockEvent struct { Number *big.Int ConfirmedMaker ConfirmedMakerEvent NewTaker NewTakerEvent ConfirmedTaker ConfirmedTakerEvent NewFinish NewFinishEvent ConfirmedFinish ConfirmedFinishEvent NewAnchor NewAnchorEvent ReorgTaker NewTakerEvent ReorgFinish NewFinishEvent }
func (CrossBlockEvent) IsEmpty ¶ added in v1.0.6
func (e CrossBlockEvent) IsEmpty() bool
type CrossTransaction ¶
type CrossTransaction struct { Data ctxdata // contains filtered or unexported fields }
func NewCrossTransaction ¶
func SignCtx ¶
func SignCtx(tx *CrossTransaction, s CtxSigner, signHash SignHash) (*CrossTransaction, error)
SignTx signs the transaction using the given signer and private key
func (*CrossTransaction) BlockHash ¶
func (tx *CrossTransaction) BlockHash() common.Hash
func (*CrossTransaction) ChainId ¶
func (tx *CrossTransaction) ChainId() *big.Int
func (CrossTransaction) DestinationId ¶
func (tx CrossTransaction) DestinationId() *big.Int
func (*CrossTransaction) From ¶ added in v1.0.6
func (tx *CrossTransaction) From() common.Address
func (*CrossTransaction) Hash ¶
func (tx *CrossTransaction) Hash() (h common.Hash)
func (*CrossTransaction) ID ¶
func (tx *CrossTransaction) ID() common.Hash
func (*CrossTransaction) SignHash ¶
func (tx *CrossTransaction) SignHash() (h common.Hash)
func (*CrossTransaction) WithSignature ¶
func (tx *CrossTransaction) WithSignature(signer CtxSigner, sig []byte) (*CrossTransaction, error)
type CrossTransactionModifier ¶ added in v1.0.4
type CrossTransactionWithSignatures ¶
type CrossTransactionWithSignatures struct { Data CtxDatas Status CtxStatus `json:"status" gencodec:"required"` // default = pending BlockNum uint64 `json:"blockNum" gencodec:"required"` // contains filtered or unexported fields }
func NewCrossTransactionWithSignatures ¶
func NewCrossTransactionWithSignatures(ctx *CrossTransaction, num uint64) *CrossTransactionWithSignatures
func (*CrossTransactionWithSignatures) AddSignature ¶
func (cws *CrossTransactionWithSignatures) AddSignature(ctx *CrossTransaction) error
func (*CrossTransactionWithSignatures) BlockHash ¶
func (cws *CrossTransactionWithSignatures) BlockHash() common.Hash
func (*CrossTransactionWithSignatures) ChainId ¶
func (cws *CrossTransactionWithSignatures) ChainId() *big.Int
func (*CrossTransactionWithSignatures) CrossTransaction ¶ added in v1.0.4
func (cws *CrossTransactionWithSignatures) CrossTransaction() *CrossTransaction
func (*CrossTransactionWithSignatures) DestinationId ¶
func (cws *CrossTransactionWithSignatures) DestinationId() *big.Int
func (*CrossTransactionWithSignatures) From ¶ added in v1.0.6
func (cws *CrossTransactionWithSignatures) From() common.Address
func (*CrossTransactionWithSignatures) Hash ¶
func (cws *CrossTransactionWithSignatures) Hash() (h common.Hash)
func (*CrossTransactionWithSignatures) ID ¶
func (cws *CrossTransactionWithSignatures) ID() common.Hash
func (*CrossTransactionWithSignatures) Price ¶
func (cws *CrossTransactionWithSignatures) Price() *big.Rat
func (*CrossTransactionWithSignatures) RemoveSignature ¶
func (cws *CrossTransactionWithSignatures) RemoveSignature(index int)
func (*CrossTransactionWithSignatures) Resolution ¶
func (cws *CrossTransactionWithSignatures) Resolution() []*CrossTransaction
func (*CrossTransactionWithSignatures) SetStatus ¶ added in v1.0.6
func (cws *CrossTransactionWithSignatures) SetStatus(status CtxStatus)
func (*CrossTransactionWithSignatures) SignaturesLength ¶
func (cws *CrossTransactionWithSignatures) SignaturesLength() int
func (*CrossTransactionWithSignatures) Size ¶
func (cws *CrossTransactionWithSignatures) Size() common.StorageSize
type CrossTransactions ¶
type CrossTransactions []*CrossTransaction
Transactions is a Transaction slice type for basic sorting.
func (CrossTransactions) GetRlp ¶
func (s CrossTransactions) GetRlp(i int) []byte
GetRlp implements Rlpable and returns the i'th element of s in rlp.
func (CrossTransactions) Swap ¶
func (s CrossTransactions) Swap(i, j int)
Swap swaps the i'th and the j'th element in s.
type CtxDatas ¶
type CtxDatas struct { Value *big.Int `json:"value" gencodec:"required"` //Token for sell CTxId common.Hash `json:"ctxId" gencodec:"required"` //cross_transaction ID TxHash common.Hash `json:"txHash" gencodec:"required"` From common.Address `json:"from" gencodec:"required"` //Token owner To common.Address `json:"to" gencodec:"required"` //Token to BlockHash common.Hash `json:"blockHash" gencodec:"required"` //The Hash of block in which the message resides DestinationId *big.Int `json:"destinationId" gencodec:"required"` //Message destination networkId DestinationValue *big.Int `json:"destinationValue" gencodec:"required"` //Token charge Input []byte `json:"input" gencodec:"required"` // Signature values V []*big.Int `json:"v" gencodec:"required"` //chainId R []*big.Int `json:"r" gencodec:"required"` S []*big.Int `json:"s" gencodec:"required"` }
type CtxSigner ¶
type CtxSigner interface { // Sender returns the sender address of the transaction. Sender(tx *CrossTransaction) (common.Address, error) // SignatureValues returns the raw R, S, V values corresponding to the // given signature. SignatureValues(tx *CrossTransaction, sig []byte) (r, s, v *big.Int, err error) // Hash returns the hash to be signed. Hash(tx *CrossTransaction) common.Hash // Equal returns true if the given signer is the same as the receiver. Equal(CtxSigner) bool }
Signer encapsulates transaction signature handling. Note that this interface is not a stable API and may change at any time to accommodate new protocol rules.
func MakeCtxSigner ¶
MakeSigner returns a Signer based on the given chain config and block number.
type CtxStatus ¶
type CtxStatus uint8
const ( // unsigned transaction CtxStatusPending CtxStatus = iota // CtxStatusWaiting is the status code of a cross transaction if waiting for orders. CtxStatusWaiting // CtxStatusIllegal is the status code of a cross transaction if waiting for orders. CtxStatusIllegal // CtxStatusExecuting is the status code of a cross transaction if taker executing. CtxStatusExecuting // CtxStatusExecuted is the status code of a cross transaction if taker confirmed. CtxStatusExecuted // CtxStatusFinished is the status code of a cross transaction if make finishing. CtxStatusFinishing // CtxStatusFinished is the status code of a cross transaction if make finish confirmed. CtxStatusFinished )
*
|------| <-new-- maker |------| |local | (pending->waiting) |remote| | | (upAnchor->illegal) | | | | | | |ctxdb | taker --mod-> |ctxdb | | | (executing) | | |status| |status| | | confirmTaker --mod-> | | | mod | (executed) | only | | with | | has | |number| <-mod-- finish |number| | | (finishing) | on | | | |saving| | | <-mod-- confirmFinish | | | | (finished) | | |------| |------|
func (CtxStatus) MarshalText ¶ added in v1.0.5
func (*CtxStatus) UnmarshalText ¶ added in v1.0.6
type EIP155CtxSigner ¶
type EIP155CtxSigner struct {
// contains filtered or unexported fields
}
EIP155Transaction implements Signer using the EIP155 rules.
func NewEIP155CtxSigner ¶
func NewEIP155CtxSigner(chainId *big.Int) EIP155CtxSigner
func (EIP155CtxSigner) Equal ¶
func (s EIP155CtxSigner) Equal(s2 CtxSigner) bool
func (EIP155CtxSigner) Hash ¶
func (s EIP155CtxSigner) Hash(tx *CrossTransaction) (h common.Hash)
func (EIP155CtxSigner) Sender ¶
func (s EIP155CtxSigner) Sender(tx *CrossTransaction) (common.Address, error)
func (EIP155CtxSigner) SignatureValues ¶
func (s EIP155CtxSigner) SignatureValues(tx *CrossTransaction, sig []byte) (R, S, V *big.Int, err error)
WithSignature returns a new transaction with the given signature. This signature needs to be in the [R || S || V] format where V is 0 or 1.
type NewAnchorEvent ¶ added in v1.0.6
type NewAnchorEvent struct {
ChainInfo []*RemoteChainInfo
}
type NewFinishEvent ¶
type NewFinishEvent struct {
Finishes []*CrossTransactionModifier
}
type NewTakerEvent ¶
type NewTakerEvent struct {
Takers []*ReceptTransaction
}
type OwnerCrossTransactionWithSignatures ¶
type OwnerCrossTransactionWithSignatures struct { Cws *CrossTransactionWithSignatures Time uint64 }
type ReceptTransaction ¶
type ReceptTransaction struct { CTxId common.Hash `json:"ctxId" gencodec:"required"` //cross_transaction ID TxHash common.Hash `json:"txHash" gencodec:"required"` //taker txHash From common.Address `json:"from" gencodec:"required"` //Token seller To common.Address `json:"to" gencodec:"required"` //Token buyer DestinationId *big.Int `json:"destinationId" gencodec:"required"` //Message destination networkId ChainId *big.Int `json:"chainId" gencodec:"required"` }
func NewReceptTransaction ¶
func (ReceptTransaction) Check ¶ added in v1.0.6
func (rtx ReceptTransaction) Check(maker *CrossTransactionWithSignatures) error
func (*ReceptTransaction) ConstructData ¶
func (rtx *ReceptTransaction) ConstructData(crossContract abi.ABI) ([]byte, error)
type RemoteChainInfo ¶
type SignedCtxEvent ¶
type SignedCtxEvent struct { Txs []*CrossTransactionWithSignatures CallBack func([]CommitEvent) }