core

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Normal = ModType(iota)
	Remote
	Reorg
)

Variables

View Source
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)
)
View Source
var ErrDuplicateSign = errors.New("signatures already exist")
View Source
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 NewCrossTransaction(amount, charge, networkId *big.Int, id, txHash, bHash common.Hash, from, to common.Address, input []byte) *CrossTransaction

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 CrossTransactionModifier struct {
	Type          ModType
	ID            common.Hash
	Status        CtxStatus
	AtBlockNumber uint64
}

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 (*CrossTransactionWithSignatures) Hash

func (cws *CrossTransactionWithSignatures) Hash() (h common.Hash)

func (*CrossTransactionWithSignatures) ID

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

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) Len

func (s CrossTransactions) Len() int

Len returns the length of s.

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 CtxID added in v1.0.6

type CtxID = common.Hash

type CtxIDs added in v1.0.6

type CtxIDs []CtxID

func (CtxIDs) String added in v1.0.6

func (ids CtxIDs) String() string

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

func MakeCtxSigner(chainID *big.Int) CtxSigner

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 (s CtxStatus) MarshalText() ([]byte, error)

func (CtxStatus) String

func (s CtxStatus) String() string

func (*CtxStatus) UnmarshalText added in v1.0.6

func (s *CtxStatus) UnmarshalText(input []byte) error

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 (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 ModType added in v1.0.6

type ModType uint8

func (ModType) String added in v1.0.6

func (t ModType) String() string

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 Recept

type Recept struct {
	TxId   common.Hash
	TxHash common.Hash
	From   common.Address
	To     common.Address
}

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 NewReceptTransaction(id, txHash common.Hash, from, to common.Address, remoteChainId, chainId *big.Int) *ReceptTransaction

func (ReceptTransaction) Check added in v1.0.6

func (*ReceptTransaction) ConstructData

func (rtx *ReceptTransaction) ConstructData(crossContract abi.ABI) ([]byte, error)

type RemoteChainInfo

type RemoteChainInfo struct {
	RemoteChainId uint64
	BlockNumber   uint64
}

type SignHash

type SignHash func(hash []byte) ([]byte, error)

type SignedCtxEvent

type SignedCtxEvent struct {
	Txs      []*CrossTransactionWithSignatures
	CallBack func([]CommitEvent)
}

Jump to

Keyboard shortcuts

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