client

package
v0.1.7-beta Latest Latest
Warning

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

Go to latest
Published: May 28, 2023 License: AGPL-3.0 Imports: 20 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCreateBip39Entropy                  = errors.New("failed to create bip39 entropy")
	ErrCreateBip39Mnemonic                 = errors.New("failed to create bip39 mnemonic")
	ErrCreateBip39SeedFromMnemonic         = errors.New("failed to create bip39 seed from mnemonic")
	ErrCreateAccountFromSeed               = errors.New("failed to create account from seed")
	ErrDecodeBase58ToAccount               = errors.New("failed to decode base58 to account")
	ErrDeriveKeyFromSeed                   = errors.New("failed to derive key from seed")
	ErrInvalidPublicKey                    = errors.New("invalid base58 public key")
	ErrInvalidPublicKeyLength              = errors.New("invalid public key length")
	ErrDeserializeTransaction              = errors.New("failed to deserialize transaction")
	ErrGetTransactionFee                   = errors.New("failed to get transaction fee")
	ErrSendTransaction                     = errors.New("failed to send transaction")
	ErrSerializeMessage                    = errors.New("failed to serialize message")
	ErrAddSignature                        = errors.New("failed to add signature")
	ErrSerializeTransaction                = errors.New("failed to serialize transaction")
	ErrInvalidAirdropAmount                = errors.New("invalid airdrop amount; must be greater than 0 and less or equal 2000000000")
	ErrRequestAirdrop                      = errors.New("failed to request airdrop")
	ErrGetSolBalance                       = errors.New("failed to get SOL balance")
	ErrFindAssociatedTokenAddress          = errors.New("failed to find associated token address")
	ErrGetSplTokenBalance                  = errors.New("failed to get SPL token balance")
	ErrGetLatestBlockhash                  = errors.New("failed to get latest blockhash")
	ErrNewTransaction                      = errors.New("failed to create new transaction")
	ErrGetNonceFromNonceAccount            = errors.New("failed to get nonce from nonce account")
	ErrGetMinimumBalanceForRentExemption   = errors.New("failed to get minimum balance for rent exemption")
	ErrGetTransactionStatus                = errors.New("failed to get transaction status")
	ErrSignTransaction                     = errors.New("failed to sign transaction")
	ErrNewMnemonic                         = errors.New("failed to create new mnemonic")
	ErrDeriveAccountFromMnemonicBip44      = errors.New("failed to derive account from mnemonic bip44")
	ErrDeriveAccountsListFromMnemonicBip44 = errors.New("failed to derive accounts list from mnemonic bip44")
	ErrDeriveAccountFromMnemonicBip39      = errors.New("failed to derive account from mnemonic bip39")
	ErrGetAtaBalance                       = errors.New("failed to get associated token account balance")
	ErrWithoutInsufficientFound            = errors.New("you need to send enough SOL to make the account rent-exempt")
	ErrWaitForTransaction                  = errors.New("failed to wait for transaction status")
	ErrContextDone                         = errors.New("context done")
	ErrGetTokenAccount                     = errors.New("failed to get token account")
	ErrDeriveTokenAccount                  = errors.New("failed to derive associated token account")
	ErrGetMintInfo                         = errors.New("failed to get mint info")
	ErrGetTokenSupply                      = errors.New("failed to get token supply")
	ErrGetTokenMetadata                    = errors.New("failed to get token metadata")
	ErrGetMasterEditionInfo                = errors.New("failed to get master edition info")
	ErrGetEditionInfo                      = errors.New("failed to get token edition info")
	ErrMaxSupplyReached                    = errors.New("max edition supply is already printed")
	ErrTokenIsNotMasterEdition             = errors.New("token is not master edition")
	ErrGetMasterEditionCurrentSupply       = errors.New("failed to get master edition current supply")
	ErrNewDurableTransaction               = errors.New("failed to create new durable transaction")
	ErrNoTransactionsFound                 = errors.New("no transactions found")
	ErrTransactionNotFound                 = errors.New("transaction not found")
	ErrTransactionNotConfirmed             = errors.New("transaction not confirmed yet")
)

Predefined package errors

Functions

func CheckSolTransferTransaction

func CheckSolTransferTransaction(meta *client.TransactionMeta, tx types.Transaction, destination string, amount uint64) error

CheckSolTransferTransaction checks if a transaction is a SOL transfer transaction. Verifies that destination account has been credited with the correct amount.

func CheckTokenTransferTransaction

func CheckTokenTransferTransaction(meta *client.TransactionMeta, tx types.Transaction, mint, destination string, amount uint64) error

CheckTokenTransferTransaction checks if a transaction is a token transfer transaction. Verifies that destination account has been credited with the correct amount of the token.

func SignTransaction

func SignTransaction(txSource string, signer types.Account) (string, error)

SignTransaction signs a transaction and returns a base64 encoded transaction.

Types

type Client

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

Solana client wrapper

func New

func New(opts ...ClientOption) *Client

NewClient creates a new client endpoint is the endpoint of the solana RPC node cnf is the configuration for the client

func (*Client) DefaultDecimals

func (c *Client) DefaultDecimals() uint8

DefaultDecimals returns the default decimals

func (*Client) GetAtaBalance

func (c *Client) GetAtaBalance(ctx context.Context, base58Addr string) (types.TokenAmount, error)

GetAtaBalance returns the SPL token balance of the given base58 encoded associated token account address. base58Addr is the base58 encoded associated token account address. Returns the balance in lamports and token decimals, or an error.

func (*Client) GetEditionInfo

func (c *Client) GetEditionInfo(ctx context.Context, base58MintAddr string) (*token_metadata.Edition, error)

GetEditionInfo returns the edition info of a token

func (*Client) GetFungibleTokenMetadata

func (c *Client) GetFungibleTokenMetadata(ctx context.Context, base58MintAddr string) (result *metadata.Metadata, err error)

GetFungibleTokenMetadata returns the on-chain SPL token metadata by the given base58 encoded SPL token mint address. Returns the token metadata or an error.

func (*Client) GetFungibleTokensList

func (c *Client) GetFungibleTokensList(ctx context.Context, walletAddr string) ([]types.TokenAccount, error)

GetFungibleTokensList gets the list of fungible tokens for the given wallet address.

func (*Client) GetMasterEditionInfo

func (c *Client) GetMasterEditionInfo(ctx context.Context, base58MintAddr string) (*token_metadata.Edition, error)

GetMasterEditionInfo returns the master edition info of a token

func (*Client) GetMasterEditionSupply

func (c *Client) GetMasterEditionSupply(ctx context.Context, masterMint common.PublicKey) (current, max uint64, err error)

GetMasterEditionSupply returns the current supply and max supply of a master edition

func (*Client) GetMinimumBalanceForRentExemption

func (c *Client) GetMinimumBalanceForRentExemption(ctx context.Context, size uint64) (uint64, error)

GetMinimumBalanceForRentExemption gets the minimum balance for rent exemption. Returns the minimum balance in lamports or an error.

func (*Client) GetMintInfo

func (c *Client) GetMintInfo(ctx context.Context, base58MintAddr string) (token.MintAccount, error)

GetMintInfo returns the token mint information for a given mint address.

func (*Client) GetNonFungibleTokensList

func (c *Client) GetNonFungibleTokensList(ctx context.Context, walletAddr string) ([]types.TokenAccount, error)

GetNonFungibleTokensList gets the list of non-fungible tokens for the given wallet address. Result includes the list of NFTs and the list of semi-fungible tokens (assets).

func (*Client) GetOldestTransactionForWallet

func (c *Client) GetOldestTransactionForWallet(
	ctx context.Context,
	base58Addr string,
	offsetTxSignature string,
) (string, *client.Transaction, error)

GetOldestTransactionForWallet returns the oldest transaction by the given base58 encoded public key. Returns the transaction or an error.

func (*Client) GetSOLBalance

func (c *Client) GetSOLBalance(ctx context.Context, base58Addr string) (uint64, error)

GetSOLBalance returns the SOL balance of the given base58 encoded account address. Returns the balance or an error.

func (*Client) GetTokenAccountInfo

func (c *Client) GetTokenAccountInfo(ctx context.Context, base58AtaAddr string) (token.TokenAccount, error)

GetTokenAccountInfo returns the token account information for a given token account address. This is a wrapper around the GetTokenAccount function from the solana-go-sdk. base58AtaAddr is the base58 encoded address of the associated token account. The function returns the token account information or an error.

func (*Client) GetTokenBalance

func (c *Client) GetTokenBalance(ctx context.Context, base58Addr, base58MintAddr string) (types.TokenAmount, error)

GetTokenBalance returns the SPL token balance of the given base58 encoded account address and SPL token mint address. base58Addr is the base58 encoded account address. base58MintAddr is the base58 encoded SPL token mint address. Returns the balance in lamports and token decimals, or an error.

func (*Client) GetTokenMetadata

func (c *Client) GetTokenMetadata(ctx context.Context, base58MintAddr string) (*token_metadata.Metadata, error)

GetTokenMetadata returns the metadata of a token

func (*Client) GetTokenSupply

func (c *Client) GetTokenSupply(ctx context.Context, base58MintAddr string) (types.TokenAmount, error)

GetTokenSupply returns the token supply for a given mint address. This is a wrapper around the GetTokenSupply function from the solana-go-sdk. base58MintAddr is the base58 encoded address of the token mint. The function returns the token supply and decimals or an error.

func (*Client) GetTransaction

func (c *Client) GetTransaction(ctx context.Context, txSignature string) (*client.Transaction, error)

GetTransaction returns the transaction by the given base58 encoded transaction signature. Returns the transaction or an error.

func (*Client) GetTransactionFee

func (c *Client) GetTransactionFee(ctx context.Context, txSource string) (uint64, error)

GetTransactionFee gets the fee for a transaction. Returns the fee or error.

func (*Client) GetTransactionStatus

func (c *Client) GetTransactionStatus(ctx context.Context, txhash string) (types.TransactionStatus, error)

GetTransactionStatus gets the transaction status. Returns the transaction status or an error.

func (*Client) NewDurableTransaction

func (c *Client) NewDurableTransaction(ctx context.Context, params NewDurableTransactionParams) (string, error)

NewDurableTransaction creates a new durable transaction. Returns the serialized transaction or an error.

func (*Client) NewTransaction

func (c *Client) NewTransaction(ctx context.Context, params NewTransactionParams) (string, error)

NewTransaction creates a new transaction. Returns the transaction or an error.

func (*Client) RequestAirdrop

func (c *Client) RequestAirdrop(ctx context.Context, base58Addr string, amount uint64) (string, error)

RequestAirdrop sends a request to the solana network to airdrop SOL to the given account. Returns the transaction hash or an error.

func (*Client) SendTransaction

func (c *Client) SendTransaction(ctx context.Context, txSource string, i ...uint8) (string, error)

Send transaction returns the transaction hash or an error

func (*Client) SignTransaction

func (c *Client) SignTransaction(ctx context.Context, wallet sdktypes.Account, txSource string) (string, error)

Sign transaction returns the signed transaction or an error

func (*Client) Solana

func (c *Client) Solana() *client.Client

Solana returns the solana client

func (*Client) ValidateTransactionByReference

func (c *Client) ValidateTransactionByReference(ctx context.Context, reference, destination string, amount uint64, mint string) (string, error)

ValidateTransactionByReference returns the transaction by the given reference. Returns transaction signature or an error if the transaction is not found or the transaction failed.

func (*Client) WaitForTransactionConfirmed

func (c *Client) WaitForTransactionConfirmed(ctx context.Context, txhash string, maxDuration time.Duration) (types.TransactionStatus, error)

WaitForTransactionConfirmed waits for a transaction to be confirmed. Returns the transaction status or an error.

type ClientOption

type ClientOption func(*Client)

func SetHTTPClient

func SetHTTPClient(httpClient *http.Client) ClientOption

SetHTTPClient sets the http client

func SetSolanaEndpoint

func SetSolanaEndpoint(endpoint string) ClientOption

SetSolanaEndpoint sets the solana endpoint

func SetTokenListPath

func SetTokenListPath(path string) ClientOption

SetTokenListPath sets the token list path

func WithCustomDecimals

func WithCustomDecimals(decimals uint8) ClientOption

WithCustomDecimals sets the custom default decimals

func WithCustomSolanaClient

func WithCustomSolanaClient(solana *client.Client) ClientOption

WithCustomSolanaClient sets a custom solana client

type NewDurableTransactionParams

type NewDurableTransactionParams struct {
	FeePayer     *common.PublicKey      // optional; if not provided, the fee payer will be the durable nonce
	NonceAuth    common.PublicKey       // required; the nonce authority
	DurableNonce common.PublicKey       // required; the durable nonce
	Instructions []sdktypes.Instruction // required; the transaction instructions
	Signers      []sdktypes.Account     // transaction signers
}

NewDurableTransactionParams are the parameters for NewDurableTransaction function.

type NewTransactionParams

type NewTransactionParams struct {
	FeePayer     common.PublicKey       // transaction fee payer
	Instructions []sdktypes.Instruction // transaction instructions
	Signers      []sdktypes.Account     // transaction signers
}

NewTransactionParams is the params for NewTransaction function.

Jump to

Keyboard shortcuts

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