Documentation ¶
Index ¶
- Constants
- Variables
- func DecimalToStroops(x decimal.Decimal) int64
- func ExtractMemoFromTx(txn *txnbuild.Transaction) (memoAsHex string, err error)
- func GetHorizonClient(network string) (*horizonclient.Client, error)
- func GetNetworkPassPhrase(ntwrk string) string
- func IntToStroops(x int64) int64
- func IsValidStellarAddress(address string) bool
- func StroopsToDecimal(stroops int64) decimal.Decimal
- type StellarConfig
- type TransactionStorage
- func (s *TransactionStorage) GetTransactionWithId(txid string) (tx *hProtocol.Transaction, err error)
- func (s *TransactionStorage) ScanBridgeAccount() error
- func (s *TransactionStorage) StoreTransaction(tx hProtocol.Transaction)
- func (s *TransactionStorage) TransactionExists(txn *txnbuild.Transaction) (exists bool, err error)
- func (s *TransactionStorage) TransactionWithMemoExists(memo string) (exists bool, err error)
- type Wallet
- func (w *Wallet) CreateAndSubmitFeepayment(ctx context.Context, amount uint64, txHash [32]byte) error
- func (w *Wallet) CreateAndSubmitPayment(ctx context.Context, target string, amount uint64, receiver common.Address, ...) (err error)
- func (w *Wallet) CreateAndSubmitRefund(ctx context.Context, target string, amount uint64, txToRefund string, ...) (err error)
- func (w *Wallet) GetAddress() string
- func (w *Wallet) GetAssetCodeAndIssuer() (assetCode, issuer string)
- func (w *Wallet) GetDepositAmountAndSender(txHash string, bridgeAccount string) (depositedAmount int64, sender string, err error)
- func (w *Wallet) GetHorizonClient() (*horizonclient.Client, error)
- func (w *Wallet) GetNetworkPassPhrase() string
- func (w *Wallet) GetSigningRequirements() (cosigners []string, requiredSignatures int, err error)
- func (w *Wallet) GetTransactionEffects(txHash string) (transactionEffects effects.EffectsPage, err error)
- func (w *Wallet) MonitorBridgeAccountAndMint(ctx context.Context, mintFn mint, persistency *state.ChainPersistency) error
- func (w *Wallet) ScanBridgeAccount() error
- func (w *Wallet) SetRequiredSignatures(requiredSignatures int)
- func (w *Wallet) SetSignerClient(client signersClient)
- func (w *Wallet) Sign(tx *txnbuild.Transaction) (*txnbuild.Transaction, error)
- func (w *Wallet) StreamBridgeStellarTransactions(ctx context.Context, cursor string, handler func(op hProtocol.Transaction)) (err error)
Constants ¶
const ( TFTMainnet = "TFT:GBOVQKJYHXRR3DX6NOX2RRYFRCUMSADGDESTDNBDS6CDVLGVESRTAC47" TFTTest = "TFT:GA47YZA3PKFUZMPLQ3B5F2E3CJIB57TGGU7SPCQT2WAEYKN766PWIMB3" Precision = int64(1e7) PrecisionDigits = 7 PageLimit = 100 // TODO: should this be public? )
Variables ¶
var ErrTransactionNotFound = errors.New("transaction not found")
Functions ¶
func DecimalToStroops ¶
DecimalToStroops converts units to stroops (1 TFT = 1000000 stroops)
func ExtractMemoFromTx ¶
func ExtractMemoFromTx(txn *txnbuild.Transaction) (memoAsHex string, err error)
func GetHorizonClient ¶
func GetHorizonClient(network string) (*horizonclient.Client, error)
GetHorizonClient gets an horizon client for a specific network
func GetNetworkPassPhrase ¶
GetNetworkPassPhrase gets the Stellar network passphrase based on a network input
func IntToStroops ¶
IntToStroops converts units to stroops (1 TFT = 1000000 stroops)
func IsValidStellarAddress ¶
func StroopsToDecimal ¶
StroopsToDecimal converts stroops to units (1 TFT = 1000000 stroops)
Types ¶
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 TransactionStorage ¶
type TransactionStorage struct {
// contains filtered or unexported fields
}
func NewTransactionStorage ¶
func NewTransactionStorage(network, addressToScan string) *TransactionStorage
func (*TransactionStorage) GetTransactionWithId ¶
func (s *TransactionStorage) GetTransactionWithId(txid string) (tx *hProtocol.Transaction, err error)
GetTransactionWithId returns a transaction with the given id (hash) returns error if the transaction is not found
func (*TransactionStorage) ScanBridgeAccount ¶
func (s *TransactionStorage) ScanBridgeAccount() error
func (*TransactionStorage) StoreTransaction ¶
func (s *TransactionStorage) StoreTransaction(tx hProtocol.Transaction)
StoreTransaction stores a transaction in the cache If there is a memo of type hash or return and the transaction is created by the account being watched ( the bridge vault account), the memo is kept as well to know that a withdraw, refund or fee transfer already happened.
func (*TransactionStorage) TransactionExists ¶
func (s *TransactionStorage) TransactionExists(txn *txnbuild.Transaction) (exists bool, err error)
TransactionExists checks if a transaction exists on the stellar network it hashes the transaction and checks if the hash is in the list of known transactions this can be used to check if a transaction was already submitted to the stellar network
func (*TransactionStorage) TransactionWithMemoExists ¶
func (s *TransactionStorage) TransactionWithMemoExists(memo string) (exists bool, err error)
TransactionWithMemoExists checks if a transaction with the given memo exists
type Wallet ¶
type Wallet struct { Config *StellarConfig //TODO: should this be public? TransactionStorage *TransactionStorage // contains filtered or unexported fields }
Wallet is the bridge wallet Payments will be funded and fees will be taken with this wallet
func NewWallet ¶
func NewWallet(config *StellarConfig, depositFee int64, withdrawFee int64, stellarTransactionStorage *TransactionStorage) (*Wallet, error)
func (*Wallet) CreateAndSubmitFeepayment ¶
func (w *Wallet) CreateAndSubmitFeepayment(ctx context.Context, amount uint64, txHash [32]byte) error
CreateAndSubmitFeepayment creates and submites a payment to the fee wallet only an amount and hash needs to be specified
func (*Wallet) CreateAndSubmitPayment ¶
func (*Wallet) CreateAndSubmitRefund ¶
func (w *Wallet) CreateAndSubmitRefund(ctx context.Context, target string, amount uint64, txToRefund string, includeWithdrawFee bool) (err error)
CreateAndSubmitRefund refunds a deposit for the transaction txToRefund ( hexadecimal representation of the transaction hash)
func (*Wallet) GetAddress ¶
func (*Wallet) GetAssetCodeAndIssuer ¶
func (*Wallet) GetDepositAmountAndSender ¶
func (w *Wallet) GetDepositAmountAndSender(txHash string, bridgeAccount string) (depositedAmount int64, sender string, err error)
GetDepositAmountAndSender returns the amount of TFT received by the bridge account in stroops and the account that sent it. TODO: is this called from a place where we really only have the transaction hash instead of the entire transaction If the entire transaction is available, there is no need to call horizon
func (*Wallet) GetHorizonClient ¶
func (w *Wallet) GetHorizonClient() (*horizonclient.Client, error)
GetHorizonClient gets the horizon client based on the wallet's network
func (*Wallet) GetNetworkPassPhrase ¶
GetNetworkPassPhrase gets the Stellar network passphrase based on the wallet's network
func (*Wallet) GetSigningRequirements ¶
func (*Wallet) GetTransactionEffects ¶
func (w *Wallet) GetTransactionEffects(txHash string) (transactionEffects effects.EffectsPage, err error)
TODO: is this function really needed? It does an horizon call while the place where this is called from might have the entire transaction present
func (*Wallet) MonitorBridgeAccountAndMint ¶
func (w *Wallet) MonitorBridgeAccountAndMint(ctx context.Context, mintFn mint, persistency *state.ChainPersistency) error
MonitorBridgeAccountAndMint is a blocking function that keeps monitoring the bridge account on the Stellar network for new transactions and calls the mint function when a deposit is made
func (*Wallet) ScanBridgeAccount ¶
func (*Wallet) SetRequiredSignatures ¶
func (*Wallet) SetSignerClient ¶
func (w *Wallet) SetSignerClient(client signersClient)
func (*Wallet) Sign ¶
func (w *Wallet) Sign(tx *txnbuild.Transaction) (*txnbuild.Transaction, error)
Sign returns a new Transaction instance which extends the current instance with a signature from this wallet.