Documentation ¶
Overview ¶
Copyright 2020 Stafi Protocol SPDX-License-Identifier: LGPL-3.0-only
The ethereum package contains the logic for interacting with ethereum chains.
There are 3 major components: the ethconn, the listener, and the writer. The currently supported transfer types are Fungible (ERC20).
Connection ¶
The ethconn contains the ethereum RPC client and can be accessed by both the writer and listener.
Listener ¶
The listener polls for each new block and looks for deposit events in the bridge contract. If a deposit occurs, the listener will fetch additional information from the handler before constructing a message and forwarding it to the router.
Writer ¶
The writer recieves the message and creates a proposals on-chain. Once a proposal is made, the writer then watches for a finalization event and will attempt to execute the proposal if a matching event occurs. The writer skips over any proposals it has already seen.
Index ¶
- Constants
- Variables
- func ConstructErc20ProposalData(amount []byte, recipient []byte) []byte
- func NewListener(conn Connection, cfg *ethconn.Config, log log15.Logger, ...) *listener
- func NewWriter(conn Connection, cfg *ethconn.Config, log log15.Logger, stop <-chan int, ...) *writer
- type Chain
- type Connection
Constants ¶
const ( TransferredStatus uint8 = 2 CancelledStatus uint8 = 3 )
const TxRetryInterval = time.Second * 2
Time between retrying a failed tx
const TxRetryLimit = 10
Maximum number of tx retries before exiting
Variables ¶
var ( BlockDelay = big.NewInt(10) BlockRetryInterval = time.Second * 15 BlockRetryLimit = 20 ErrFatalPolling = errors.New("listener block polling failed") )
var ErrFatalQuery = errors.New("query of chain state failed")
var ErrFatalTx = errors.New("submission of transaction failed")
var ErrNonceTooLow = errors.New("nonce too low")
var ErrTxUnderpriced = errors.New("replacement transaction underpriced")
Functions ¶
func ConstructErc20ProposalData ¶
constructErc20ProposalData returns the bytes to construct a proposal suitable for Erc20
func NewListener ¶
func NewListener(conn Connection, cfg *ethconn.Config, log log15.Logger, bs blockstore.Blockstorer, stop <-chan int, sysErr chan<- error) *listener
NewListener creates and returns a listener
Types ¶
type Connection ¶
type Connection interface { Connect() error Keypair() *secp256k1.Keypair Opts() *bind.TransactOpts CallOpts() *bind.CallOpts LockAndUpdateOpts() error UnlockOpts() Client() *ethclient.Client EnsureHasBytecode(address common.Address) error LatestBlock() (*big.Int, error) WaitForBlock(block *big.Int) error Close() }