bridge

package
v0.0.0-...-9394277 Latest Latest
Warning

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

Go to latest
Published: May 13, 2023 License: Apache-2.0 Imports: 51 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 * stellarPrecision)
	BridgeNetwork    = "stellar"
	EthMessagePrefix = "\x19Ethereum Signed Message:\n32"
)
View Source
const (
	TFTMainnet = "TFT:GBOVQKJYHXRR3DX6NOX2RRYFRCUMSADGDESTDNBDS6CDVLGVESRTAC47"
	TFTTest    = "TFT:GA47YZA3PKFUZMPLQ3B5F2E3CJIB57TGGU7SPCQT2WAEYKN766PWIMB3"
)
View Source
const ERC20AddressLength = 20
View Source
const (
	Protocol = protocol.ID("/p2p/rpc/signer")
)

Variables

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

func GetHorizonClient

func GetHorizonClient(network string) (*horizonclient.Client, error)

GetHorizonClient gets an horizon client for a specific network

func IntToStroops

func IntToStroops(x int64) int64

IntToStroops converts units to stroops (1 TFT = 1000000 stroops)

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 NewGater

func NewGater(accept peer.ID) connmgr.ConnectionGater

func NewHost

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

func NewStellarWallet

func NewStellarWallet(ctx context.Context, config *StellarConfig, depositFee int64) (*stellarWallet, error)

Types

type Blockheight

type Blockheight struct {
	LastHeight    uint64 `json:"lastHeight"`
	StellarCursor string `json:"stellarCursor"`
}

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 *stellarWallet, contract *BridgeContract, config *BridgeConfig, host host.Host, router routing.PeerRouting) (bridge *Bridge, err error)

NewBridge creates a new Bridge.

func (*Bridge) Close

func (bridge *Bridge) Close() error

Close bridge

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

func (bridge *BridgeContract) EthBalance() (*big.Int, 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 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) TokenBalance

func (bridge *BridgeContract) TokenBalance(address common.Address) (*big.Int, error)

func (*BridgeContract) TransferFunds

func (bridge *BridgeContract) TransferFunds(recipient common.Address, amount *big.Int) error

TransferFunds transfers funds from one address to another

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

type ChainPersistency

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

func (*ChainPersistency) GetHeight

func (b *ChainPersistency) GetHeight() (*Blockheight, error)

func (*ChainPersistency) Save

func (b *ChainPersistency) Save(blockheight *Blockheight) error

type Contract

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

type ERC20Address

type ERC20Address [ERC20AddressLength]byte

func GetErc20AddressFromB64

func GetErc20AddressFromB64(input string) (ERC20Address, error)

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
}

type SignerConfig

type SignerConfig struct {
	Secret   string
	BridgeID string
	Network  string
}

func (*SignerConfig) Valid

func (c *SignerConfig) Valid() error

type SignerService

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

func NewSignerServer

func NewSignerServer(host host.Host, bridgeMasterAddress string, bridgeContract *BridgeContract, stellarWallet *stellarWallet) (*SignerService, error)

func (*SignerService) Sign

func (s *SignerService) Sign(ctx context.Context, request StellarSignRequest, response *StellarSignResponse) error

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(ctx context.Context, host host.Host, router routing.PeerRouting, addresses []string, relay *peer.AddrInfo) (*SignersClient, error)

NewSignersClient creates a signer client with given stellar addresses the addresses are going to be used to get libp2p ID where we connect to and ask them to sign

func (*SignersClient) Sign

func (*SignersClient) SignMint

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

type StellarConfig

type StellarConfig struct {
	// network for the stellar config
	StellarNetwork string
	// seed for the stellar bridge wallet
	StellarSeed string
	// stellar fee wallet address
	StellarFeeWallet string
}

func (*StellarConfig) Validate

func (c *StellarConfig) Validate() (err error)

type StellarSignRequest

type StellarSignRequest struct {
	TxnXDR             string
	RequiredSignatures int
	Receiver           common.Address
	Block              uint64
	Message            string
}

type StellarSignResponse

type StellarSignResponse struct {
	// Signature is a base64 of the signautre
	Signature string
	// The account address
	Address string
}

type StellarTransactionStorage

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

func NewStellarTransactionStorage

func NewStellarTransactionStorage(network, addressToScan string) *StellarTransactionStorage

func (*StellarTransactionStorage) FetchTransactionsForStorage

func (s *StellarTransactionStorage) FetchTransactionsForStorage(ctx context.Context, cursor string, handler func(op hProtocol.Transaction)) error

func (*StellarTransactionStorage) GetTransactionWithId

func (s *StellarTransactionStorage) GetTransactionWithId(txid string) (*hProtocol.Transaction, error)

func (*StellarTransactionStorage) ScanBridgeAccount

func (s *StellarTransactionStorage) ScanBridgeAccount() error

func (*StellarTransactionStorage) StoreTransaction

func (s *StellarTransactionStorage) StoreTransaction(txn hProtocol.Transaction)

func (*StellarTransactionStorage) TransactionExists

func (s *StellarTransactionStorage) TransactionExists(txn *txnbuild.Transaction) (exists bool, err error)

func (*StellarTransactionStorage) TransactionExistsAndScan

func (s *StellarTransactionStorage) TransactionExistsAndScan(txn *txnbuild.Transaction) (exists bool, err 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