bridge

package
v0.0.0-...-57c21f4 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EthBlockDelay is the amount of blocks to wait before
	// pushing eth transaction to the stellar network
	EthBlockDelay = 3
	// Withdrawing from smartchain to Stellar fee
	WithdrawFee      = int64(1 * stellar.Precision) //WithdrawFeeof 1 TFT in Stroops
	BridgeNetwork    = "stellar"
	EthMessagePrefix = "\x19Ethereum Signed Message:\n32"
)
View Source
const (
	Protocol = protocol.ID("/p2p/rpc/signer")
)

Variables

View Source
var (
	ErrInvalidTransaction       = errors.New("Invalid transaction")
	ErrTransactionAlreadyExists = errors.Wrap(ErrInvalidTransaction, "transaction already exists")
	ErrAlreadyRefunded          = errors.Wrap(ErrInvalidTransaction, "The deposit was already refunded")
	ErrInvalidFeePayment        = errors.Wrap(ErrInvalidTransaction, "Invalid fee payment")
)
View Source
var (
	// ErrNoAccountLoaded is an error returned for all Light Client methods
	// that require an account and for which no account is loaded.
	ErrNoAccountLoaded = errors.New("no account was loaded into the light client")
)

Functions

func AbiEncodeArgs

func AbiEncodeArgs(addr common.Address, amount *big.Int, txid string) ([]byte, error)

AbiEncodeArgs encodes the arguments for the mint function TODO: better move this to eth package

func IsNoPeerErr

func IsNoPeerErr(err error) bool

IsNoPeerErr checks if an error is means an ethereum client could not execute a call because it has no valid peers

func NewHost

func NewHost(ctx context.Context, secret, relay string, psk string) (host.Host, routing.PeerRouting, error)

func NewSignerServer

func NewSignerServer(host host.Host, bridgeMasterAddress string, bridgeContract *BridgeContract, stellarWallet *stellar.Wallet, depositFee int64) error

Types

type Bridge

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

Bridge is a high lvl structure which listens on contract events and bridge-related stellar transactions, and handles them

func NewBridge

func NewBridge(ctx context.Context, wallet *stellar.Wallet, contract *BridgeContract, config *BridgeConfig, host host.Host, router routing.PeerRouting) (bridge *Bridge, err error)

NewBridge creates a new Bridge. TODO: context is not used

func (*Bridge) Close

func (bridge *Bridge) Close() error

Close bridge TODO: drop the error return value

func (*Bridge) GetClient

func (bridge *Bridge) GetClient() *EthClient

GetClient returns bridgecontract lightclient

func (*Bridge) Start

func (bridge *Bridge) Start(ctx context.Context) error

Start the main processing loop of the bridge

type BridgeConfig

type BridgeConfig struct {
	RescanBridgeAccount bool
	RescanFromHeight    int64 //TODO: change to uint64
	PersistencyFile     string
	Follower            bool
	Relay               string
	Psk                 string
	// deposit fee in TFT units
	DepositFee int64
}

type BridgeContract

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

BridgeContract exposes a higher lvl api for specific contract bindings. In case of proxy contracts, the bridge needs to use the bindings of the implementation contract, but the address of the proxy.

func NewBridgeContract

func NewBridgeContract(ethConfig *EthConfig) (*BridgeContract, error)

NewBridgeContract creates a new wrapper for an allready deployed contract

func (*BridgeContract) AccountAddress

func (bridge *BridgeContract) AccountAddress() (common.Address, error)

AccountAddress returns the account address of the bridge contract

func (*BridgeContract) CreateTokenSignature

func (bridge *BridgeContract) CreateTokenSignature(receiver common.Address, amount int64, txid string) (tokenv1.Signature, error)

func (*BridgeContract) EthClient

func (bridge *BridgeContract) EthClient() *EthClient

EthClient returns the EthClient driving this bridge contract

func (*BridgeContract) FilterWithdraw

func (bridge *BridgeContract) FilterWithdraw(wc chan<- WithdrawEvent, startHeight uint64, endHeight uint64) error

FilterWithdraw filters Withdraw events on the given contract. This call blocks and prints out info about any withdraw as it happened

func (*BridgeContract) GetContractAdress

func (bridge *BridgeContract) GetContractAdress() common.Address

GetContractAdress returns the address of this contract

func (*BridgeContract) GetRequiresSignatureCount

func (bridge *BridgeContract) GetRequiresSignatureCount() (*big.Int, error)

func (*BridgeContract) GetSigners

func (bridge *BridgeContract) GetSigners() ([]common.Address, error)

GetSigners returns the list of signers for the contract

func (*BridgeContract) IsMintTxID

func (bridge *BridgeContract) IsMintTxID(txID string) (bool, error)

func (*BridgeContract) Loop

func (bridge *BridgeContract) Loop(ch chan<- *types.Header)

Loop subscribes to new eth heads. If a new head is received, it is passed on the given channel, after which the internal stats are updated if no update is already in progress

func (*BridgeContract) Mint

func (bridge *BridgeContract) Mint(receiver tfeth.ERC20Address, amount *big.Int, txID string, signatures []tokenv1.Signature) error

func (*BridgeContract) Refresh

func (bridge *BridgeContract) Refresh(head *types.Header) error

Refresh attempts to retrieve the latest header from the chain and extract the associated bridge balance and nonce for connectivity caching.

func (*BridgeContract) SubscribeMint

func (bridge *BridgeContract) SubscribeMint() error

SubscribeMint subscribes to new Mint events on the given contract. This call blocks and prints out info about any mint as it happened

func (*BridgeContract) SubscribeTransfers

func (bridge *BridgeContract) SubscribeTransfers() error

SubscribeTransfers subscribes to new Transfer events on the given contract. This call blocks and prints out info about any transfer as it happened

func (*BridgeContract) SubscribeWithdraw

func (bridge *BridgeContract) SubscribeWithdraw(wc chan<- WithdrawEvent, startHeight uint64) error

SubscribeWithdraw subscribes to new Withdraw events on the given contract. This call blocks and prints out info about any withdraw as it happened

func (*BridgeContract) WatchWithdraw

func (bridge *BridgeContract) WatchWithdraw(opts *bind.WatchOpts, sink chan<- *tokenv1.TokenWithdraw, receiver []common.Address) (event.Subscription, error)

WatchWithdraw is a free log subscription operation binding the contract event 0x884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364.

Solidity: e Withdraw(receiver indexed address, tokens uint256)

This method is copied from the generated bindings and slightly modified, so we can add logic to stay backwards compatible with the old withdraw event signature TODO: is the copy still needed or can we simply use the generated bindings?

type Contract

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

type ERC20BalanceInfo

type ERC20BalanceInfo struct {
	Balance *big.Int       `json:"balance"`
	Address common.Address `json:"address"`
}

ERC20BalanceInfo provides a definition for the ethereum bridge address balance

type EthClient

type EthClient struct {
	*ethclient.Client // Client connection to the Ethereum chain
	// contains filtered or unexported fields
}

EthClient creates a light client that can be used to interact with the Ethereum network,

func NewEthClient

func NewEthClient(lccfg LightClientConfig) (*EthClient, error)

NewLiEthient creates a new light client that can be used to interact with the ETH network. See `EthClient` for more information.

func (*EthClient) AccountAddress

func (c *EthClient) AccountAddress() (common.Address, error)

AccountAddress returns the address of the loaded account, returning an error only if no account was loaded.

func (*EthClient) AccountBalanceAt

func (c *EthClient) AccountBalanceAt(ctx context.Context, blockNumber *big.Int) (*big.Int, error)

AccountBalanceAt returns the balance for the account at the given block height.

func (*EthClient) GetAddress

func (c *EthClient) GetAddress() (common.Address, error)

func (*EthClient) GetBalanceInfo

func (c *EthClient) GetBalanceInfo() (*ERC20BalanceInfo, error)

GetBalanceInfo returns bridge ethereum address and balance

func (*EthClient) Sign

func (c *EthClient) Sign(data []byte) ([]byte, error)

Sign signs the given data and prepends the Ethereum message prefix.

func (*EthClient) SignTx

func (c *EthClient) SignTx(tx *types.Transaction, chainID *big.Int) (*types.Transaction, error)

SignTx signs a given traction with the loaded account, returning the signed transaction and no error on success.

type EthConfig

type EthConfig struct {
	EthNetworkName  string
	EthUrl          string
	EthPrivateKey   string
	ContractAddress string
}

EthConfig combines all configuration required for creating and configuring a EthClient.

type EthSignRequest

type EthSignRequest struct {
	Receiver           common.Address
	Amount             int64
	TxId               string
	RequiredSignatures int64
}

type EthSignResponse

type EthSignResponse struct {
	Who       common.Address
	Signature tokenv1.Signature
}

type LightClientConfig

type LightClientConfig struct {
	NetworkName   string
	EthUrl        string
	NetworkID     uint64
	EthPrivateKey string
	GenesisBlock  *core.Genesis
}

LightClientConfig combines all configuration required for creating and configuring a EthClient.

type Signature

type Signature struct {
	V uint8
	R [32]byte
	S [32]byte
}

TODO: better move this to eth package

type SignerConfig

type SignerConfig struct {
	Secret   string
	BridgeID string
	Network  string
}

func (*SignerConfig) Valid

func (c *SignerConfig) Valid() error

type SignerService

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

func (*SignerService) Sign

Sign signs a stellar sign request This is calable on the libp2p network with RPC

func (*SignerService) SignMint

func (s *SignerService) SignMint(ctx context.Context, request EthSignRequest, response *EthSignResponse) error

type SignersClient

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

func NewSignersClient

func NewSignersClient(host host.Host, router routing.PeerRouting, cosigners []peer.ID, relay *peer.AddrInfo) *SignersClient

NewSignersClient creates a signer client to ask cosigners to sign

func (*SignersClient) Sign

func (*SignersClient) SignMint

func (s *SignersClient) SignMint(ctx context.Context, signRequest EthSignRequest) ([]EthSignResponse, error)

type WithdrawEvent

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

WithdrawEvent holds relevant information about a withdraw event

func (WithdrawEvent) Amount

func (w WithdrawEvent) Amount() *big.Int

Amount withdrawn

func (WithdrawEvent) BlockHash

func (w WithdrawEvent) BlockHash() common.Hash

BlockHash of the containing block

func (WithdrawEvent) BlockHeight

func (w WithdrawEvent) BlockHeight() uint64

BlockHeight of the containing block

func (WithdrawEvent) BlockchainAddress

func (w WithdrawEvent) BlockchainAddress() string

Blockchain address to withdraw to

func (WithdrawEvent) Network

func (w WithdrawEvent) Network() string

Network to withdraw to

func (WithdrawEvent) Receiver

func (w WithdrawEvent) Receiver() common.Address

Receiver of the withdraw

func (WithdrawEvent) TxHash

func (w WithdrawEvent) TxHash() common.Hash

TxHash hash of the transaction

Jump to

Keyboard shortcuts

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