stellar

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: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TFTMainnet = "TFT:GBOVQKJYHXRR3DX6NOX2RRYFRCUMSADGDESTDNBDS6CDVLGVESRTAC47"
	TFTTest    = "TFT:GA47YZA3PKFUZMPLQ3B5F2E3CJIB57TGGU7SPCQT2WAEYKN766PWIMB3"

	Precision       = int64(1e7)
	PrecisionDigits = 7
	PageLimit       = 100 // TODO: should this be public?
)

Variables

View Source
var ErrTransactionNotFound = errors.New("transaction not found")

Functions

func DecimalToStroops

func DecimalToStroops(x decimal.Decimal) int64

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

func GetNetworkPassPhrase(ntwrk string) string

GetNetworkPassPhrase gets the Stellar network passphrase based on a network input

func IntToStroops

func IntToStroops(x int64) int64

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

func IsValidStellarAddress

func IsValidStellarAddress(address string) bool

func StroopsToDecimal

func StroopsToDecimal(stroops int64) decimal.Decimal

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 (w *Wallet) CreateAndSubmitPayment(ctx context.Context, target string, amount uint64, receiver common.Address, blockheight uint64, txHash common.Hash, message string, includeWithdrawFee bool) (err error)

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 (w *Wallet) GetAddress() string

func (*Wallet) GetAssetCodeAndIssuer

func (w *Wallet) GetAssetCodeAndIssuer() (assetCode, issuer string)

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

func (w *Wallet) GetNetworkPassPhrase() string

GetNetworkPassPhrase gets the Stellar network passphrase based on the wallet's network

func (*Wallet) GetSigningRequirements

func (w *Wallet) GetSigningRequirements() (cosigners []string, requiredSignatures int, err error)

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 (w *Wallet) ScanBridgeAccount() error

func (*Wallet) SetRequiredSignatures

func (w *Wallet) SetRequiredSignatures(requiredSignatures int)

func (*Wallet) SetSignerClient

func (w *Wallet) SetSignerClient(client signersClient)

func (*Wallet) Sign

Sign returns a new Transaction instance which extends the current instance with a signature from this wallet.

func (*Wallet) StreamBridgeStellarTransactions

func (w *Wallet) StreamBridgeStellarTransactions(ctx context.Context, cursor string, handler func(op hProtocol.Transaction)) (err error)

Jump to

Keyboard shortcuts

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