bsc

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockInterval              = 3 * time.Second
	BlockHeightPollInterval    = BlockInterval * 5
	BlockFinalityConfirmations = 10
	MonitorBlockMaxConcurrency = 300 // number of concurrent requests to synchronize older blocks from source chain
	RPCCallRetry               = 5
)
View Source
const (
	JsonrpcApiVersion                                = 3
	JsonrpcErrorCodeSystem         jsonrpc.ErrorCode = -31000
	JsonrpcErrorCodeTxPoolOverflow jsonrpc.ErrorCode = -31001
	JsonrpcErrorCodePending        jsonrpc.ErrorCode = -31002
	JsonrpcErrorCodeExecuting      jsonrpc.ErrorCode = -31003
	JsonrpcErrorCodeNotFound       jsonrpc.ErrorCode = -31004
	JsonrpcErrorLackOfResource     jsonrpc.ErrorCode = -31005
	JsonrpcErrorCodeTimeout        jsonrpc.ErrorCode = -31006
	JsonrpcErrorCodeSystemTimeout  jsonrpc.ErrorCode = -31007
	JsonrpcErrorCodeScore          jsonrpc.ErrorCode = -30000
)
View Source
const (
	DuplicateTransactionError = iota + 2000
	TransactionPoolOverflowError
	ExpiredTransactionError
	FutureTransactionError
	TransitionInterruptedError
	InvalidTransactionError
	InvalidQueryError
	InvalidResultError
	NoActiveContractError
	NotContractAddressError
	InvalidPatchDataError
	CommittedTransactionError
)
View Source
const (
	ResultStatusSuccess           = "0x1"
	ResultStatusFailureCodeRevert = 32
	ResultStatusFailureCodeEnd    = 99
)
View Source
const (
	ParliaGasLimitBoundDivisor uint64 = 256                // The bound divisor of the gas limit, used in update calculations.
	MinGasLimit                uint64 = 5000               // Minimum the gas limit may ever be.
	MaxGasLimit                uint64 = 0x7fffffffffffffff // Maximum the gas limit (2^63-1).
)
View Source
const (
	DefaultGasLimit = 25000000
)

Variables

This section is empty.

Functions

func HexToAddress

func HexToAddress(s string) common.Address

func NewReceiver

func NewReceiver(
	src, dst chain.BTPAddress, urls []string,
	rawOpts json.RawMessage, l log.Logger) (chain.Receiver, error)

func NewSender

func NewSender(
	src, dst chain.BTPAddress,
	urls []string, w wallet.Wallet,
	rawOpts json.RawMessage, l log.Logger) (chain.Sender, error)

func SealHash

func SealHash(header *types.Header, chainId *big.Int) (hash ethCommon.Hash)

SealHash returns the hash of a block prior to it being sealed.

Types

type Address

type Address string

Address T_ADDR_EOA, T_ADDR_SCORE

func (Address) Value

func (a Address) Value() ([]byte, error)

type BMCRelayMethodParams

type BMCRelayMethodParams struct {
	Prev     string `json:"_prev"`
	Messages string `json:"_msg"`
}

type BMCStatus

type BMCStatus struct {
	TxSeq            HexInt `json:"tx_seq"`
	RxSeq            HexInt `json:"rx_seq"`
	BMRIndex         HexInt `json:"relay_idx"`
	RotateHeight     HexInt `json:"rotate_height"`
	RotateTerm       HexInt `json:"rotate_term"`
	DelayLimit       HexInt `json:"delay_limit"`
	MaxAggregation   HexInt `json:"max_agg"`
	CurrentHeight    HexInt `json:"cur_height"`
	RxHeight         HexInt `json:"rx_height"`
	RxHeightSrc      HexInt `json:"rx_height_src"`
	BlockIntervalSrc HexInt `json:"block_interval_src"`
	BlockIntervalDst HexInt `json:"block_interval_dst"`
}

type BlockNotification

type BlockNotification struct {
	Hash          common.Hash
	Height        *big.Int
	Header        *types.Header
	Receipts      types.Receipts
	HasBTPMessage *bool
}

type BlockRequest

type BlockRequest struct {
	Height             *big.Int       `json:"height"`
	EventFilters       []*EventFilter `json:"eventFilters,omitempty"`
	SrcContractAddress common.Address `json:"srcContractAddress,omitempty"`
}

type BnOptions

type BnOptions struct {
	StartHeight uint64
	Concurrency uint64
}

type Client

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

grouped rpc api clients

func (*Client) CallContract

func (cl *Client) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

func (*Client) FilterLogs

func (cl *Client) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]ethTypes.Log, error)

func (*Client) GetBMCClient

func (cl *Client) GetBMCClient() *bmcperiphery.Bmcperiphery

func (*Client) GetBalance

func (cl *Client) GetBalance(ctx context.Context, hexAddr string) (*big.Int, error)

func (*Client) GetBlockByHash

func (cl *Client) GetBlockByHash(hash common.Hash) (*bscTypes.Block, error)

func (*Client) GetBlockNumber

func (cl *Client) GetBlockNumber() (uint64, error)

func (*Client) GetBlockReceipts

func (cl *Client) GetBlockReceipts(hash common.Hash) (ethTypes.Receipts, error)

func (*Client) GetChainID

func (c *Client) GetChainID() *big.Int

func (*Client) GetEthClient

func (c *Client) GetEthClient() *ethclient.Client

func (*Client) GetHeaderByHeight

func (cl *Client) GetHeaderByHeight(ctx context.Context, height *big.Int) (*ethTypes.Header, error)

func (*Client) GetMedianGasPriceForBlock

func (cl *Client) GetMedianGasPriceForBlock(ctx context.Context) (gasPrice *big.Int, gasHeight *big.Int, err error)

func (*Client) GetStatus

func (cl *Client) GetStatus(opts *bind.CallOpts, _link string) (bmcperiphery.TypesLinkStats, error)

func (*Client) HandleRelayMessage

func (cl *Client) HandleRelayMessage(opts *bind.TransactOpts, _prev string, _msg []byte) (*ethTypes.Transaction, error)

func (*Client) Log

func (c *Client) Log() log.Logger

func (*Client) NonceAt

func (cl *Client) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)

func (*Client) ParseMessage

func (cl *Client) ParseMessage(log ethTypes.Log) (*bmcperiphery.BmcperipheryMessage, error)

func (*Client) SuggestGasPrice

func (cl *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error)

func (*Client) TransactionByHash

func (cl *Client) TransactionByHash(ctx context.Context, blockHash common.Hash) (tx *ethTypes.Transaction, isPending bool, err error)

func (*Client) TransactionCount

func (cl *Client) TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)

func (*Client) TransactionInBlock

func (cl *Client) TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*ethTypes.Transaction, error)

func (*Client) TransactionReceipt

func (cl *Client) TransactionReceipt(ctx context.Context, txHash common.Hash) (*ethTypes.Receipt, error)

type EVMLog

type EVMLog struct {
	Address     string
	Topics      [][]byte
	Data        []byte
	BlockNumber uint64
	TxHash      []byte
	TxIndex     uint
	BlockHash   []byte
	Index       uint
	Removed     bool
}

func MakeLog

func MakeLog(log *types.Log) *EVMLog

type EventFilter

type EventFilter struct {
	Addr      Address   `json:"addr,omitempty"`
	Signature string    `json:"event"`
	Indexed   []*string `json:"indexed,omitempty"`
	Data      []*string `json:"data,omitempty"`
}

type EventLog

type EventLog struct {
	Addr    []byte
	Indexed [][]byte
	Data    [][]byte
}

type HexBytes

type HexBytes string

HexBytes T_BIN_DATA, T_HASH

func (HexBytes) Value

func (hs HexBytes) Value() ([]byte, error)

type HexInt

type HexInt string

HexInt T_INT

func (HexInt) Int

func (i HexInt) Int() (int, error)

func (HexInt) Value

func (i HexInt) Value() (int64, error)

type IClient

type IClient interface {
	Log() log.Logger
	GetBalance(ctx context.Context, hexAddr string) (*big.Int, error)
	GetBlockNumber() (uint64, error)
	GetBlockByHash(hash common.Hash) (*bscTypes.Block, error)
	GetHeaderByHeight(ctx context.Context, height *big.Int) (*ethTypes.Header, error)
	GetBlockReceipts(hash common.Hash) (ethTypes.Receipts, error)
	GetMedianGasPriceForBlock(ctx context.Context) (gasPrice *big.Int, gasHeight *big.Int, err error)
	GetChainID() *big.Int

	// ethClient
	FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]ethTypes.Log, error)
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
	NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
	TransactionByHash(ctx context.Context, blockHash common.Hash) (tx *ethTypes.Transaction, isPending bool, err error)
	CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*ethTypes.Receipt, error)
	TransactionCount(ctx context.Context, blockHash common.Hash) (uint, error)
	TransactionInBlock(ctx context.Context, blockHash common.Hash, index uint) (*ethTypes.Transaction, error)

	// bmcClient
	ParseMessage(log ethTypes.Log) (*bmcperiphery.BmcperipheryMessage, error)
	HandleRelayMessage(opts *bind.TransactOpts, _prev string, _msg []byte) (*ethTypes.Transaction, error)
	GetStatus(opts *bind.CallOpts, _link string) (bmcperiphery.TypesLinkStats, error)
}

type IVerifier

type IVerifier interface {
	Next() *big.Int
	Verify(header *types.Header, nextHeader *types.Header, receipts ethTypes.Receipts) error
	Update(header *types.Header) (err error)
	ParentHash() ethCommon.Hash
	IsValidator(addr ethCommon.Address, curHeight *big.Int) bool
}

type Receipt

type Receipt struct {
	// Consensus fields: These fields are defined by the Yellow Paper
	Type              uint8
	PostState         []byte
	Status            uint64
	CumulativeGasUsed uint64
	Bloom             []byte
	Logs              []*EVMLog

	TxHash          common.Hash
	ContractAddress common.Address
	GasUsed         uint64

	BlockHash        common.Hash
	BlockNumber      uint64
	TransactionIndex uint
}

func MakeReceipt

func MakeReceipt(receipt *types.Receipt) *Receipt

type ReceiptProof

type ReceiptProof struct {
	Index  int
	Events []byte
	Height int64
}

type ReceiverOptions

type ReceiverOptions struct {
	SyncConcurrency uint64           `json:"syncConcurrency"`
	Verifier        *VerifierOptions `json:"verifier"`
}

func (*ReceiverOptions) Unmarshal

func (opts *ReceiverOptions) Unmarshal(v map[string]interface{}) error

type RelayMessage

type RelayMessage struct {
	ReceiptProofs [][]byte
	// contains filtered or unexported fields
}

type Signature

type Signature string

Signature T_SIG

type TransactionHashParam

type TransactionHashParam struct {
	Hash common.Hash
}

type TransactionParam

type TransactionParam struct {
	FromAddress string      `json:"from" validate:"required,t_addr_eoa"`
	ToAddress   string      `json:"to" validate:"required,t_addr"`
	NetworkID   HexInt      `json:"nid" validate:"required,t_int"`
	Params      interface{} `json:"params,omitempty"`
	TransactOpt *bind.TransactOpts
}

type TransactionResult

type TransactionResult struct {
	To                 Address `json:"to"`
	CumulativeStepUsed HexInt  `json:"cumulativeStepUsed"`
	StepUsed           HexInt  `json:"stepUsed"`
	StepPrice          HexInt  `json:"stepPrice"`
	EventLogs          []struct {
		Addr    Address  `json:"scoreAddress"`
		Indexed []string `json:"indexed"`
		Data    []string `json:"data"`
	} `json:"eventLogs"`
	LogsBloom HexBytes `json:"logsBloom"`
	Status    HexInt   `json:"status"`
	Failure   *struct {
		CodeValue    HexInt `json:"code"`
		MessageValue string `json:"message"`
	} `json:"failure,omitempty"`
	SCOREAddress Address  `json:"scoreAddress,omitempty"`
	BlockHash    HexBytes `json:"blockHash" validate:"required,t_hash"`
	BlockHeight  HexInt   `json:"blockHeight" validate:"required,t_int"`
	TxIndex      HexInt   `json:"txIndex" validate:"required,t_int"`
	TxHash       HexBytes `json:"txHash" validate:"required,t_int"`
}

type Verifier

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

next points to height whose parentHash is expected parentHash of height h is got from next-1's hash

func (*Verifier) ChainID

func (vr *Verifier) ChainID() *big.Int

func (*Verifier) IsValidator

func (vr *Verifier) IsValidator(addr ethCommon.Address, curHeight *big.Int) bool

func (*Verifier) Next

func (vr *Verifier) Next() *big.Int

func (*Verifier) ParentHash

func (vr *Verifier) ParentHash() ethCommon.Hash

func (*Verifier) Update

func (vr *Verifier) Update(header *types.Header) (err error)

func (*Verifier) Verify

func (vr *Verifier) Verify(header *types.Header, nextHeader *types.Header, receipts ethTypes.Receipts) error

prove that header is linked to verified nextHeader only then can header be used for receiver.Callback or vr.Update()

type VerifierOptions

type VerifierOptions struct {
	BlockHeight   uint64          `json:"blockHeight"`
	BlockHash     common.HexBytes `json:"parentHash"`
	ValidatorData common.HexBytes `json:"validatorData"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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