Documentation ¶
Index ¶
- Constants
- Variables
- func CreateProgramAddress(program ed25519.PublicKey, seeds ...[]byte) (ed25519.PublicKey, error)
- func FindProgramAddress(program ed25519.PublicKey, seeds ...[]byte) (ed25519.PublicKey, error)
- type AccountInfo
- type AccountMeta
- type Block
- type BlockTransaction
- type Blockhash
- type Client
- type Commitment
- type CompiledInstruction
- type ConfirmedTransaction
- type CustomError
- type Header
- type Instruction
- type InstructionError
- type InstructionErrorKey
- type Message
- type MockClient
- func (m *MockClient) GetAccountInfo(account ed25519.PublicKey, commitment Commitment) (AccountInfo, error)
- func (m *MockClient) GetBalance(account ed25519.PublicKey) (uint64, error)
- func (m *MockClient) GetBlockTime(slot uint64) (time.Time, error)
- func (m *MockClient) GetConfirmationStatus(signature Signature, commitment Commitment) (bool, error)
- func (m *MockClient) GetConfirmedBlock(slot uint64) (*Block, error)
- func (m *MockClient) GetConfirmedBlocksWithLimit(start, limit uint64) ([]uint64, error)
- func (m *MockClient) GetConfirmedTransaction(sig Signature) (ConfirmedTransaction, error)
- func (m *MockClient) GetMinimumBalanceForRentExemption(size uint64) (lamports uint64, err error)
- func (m *MockClient) GetRecentBlockhash() (Blockhash, error)
- func (m *MockClient) GetSignatureStatus(signature Signature, commitment Commitment) (*SignatureStatus, error)
- func (m *MockClient) GetSignatureStatuses(signature []Signature) ([]*SignatureStatus, error)
- func (m *MockClient) GetSlot(commitment Commitment) (uint64, error)
- func (m *MockClient) GetTokenAccountsByOwner(owner, mint ed25519.PublicKey) ([]ed25519.PublicKey, error)
- func (m *MockClient) RequestAirdrop(account ed25519.PublicKey, lamports uint64, commitment Commitment) (Signature, error)
- func (m *MockClient) SimulateTransaction(txn Transaction) error
- func (m *MockClient) SubmitTransaction(txn Transaction, commitment Commitment) (Signature, *SignatureStatus, error)
- type Signature
- type SignatureStatus
- type SortableAccountMeta
- type Transaction
- type TransactionError
- type TransactionErrorKey
Constants ¶
const (
// MaxTransactionSize taken from: https://github.com/solana-labs/solana/blob/39b3ac6a8d29e14faa1de73d8b46d390ad41797b/sdk/src/packet.rs#L9-L13
MaxTransactionSize = 1232
)
const ( // PollRate is the rate at which blocks should be polled at. PollRate = (time.Second / slotsPerSec) / 2 )
Variables ¶
var ( ErrTooManySeeds = errors.New("too many seeds") ErrMaxSeedLengthExceeded = errors.New("max seed length exceeded") ErrInvalidPublicKey = errors.New("invalid public key") )
var ( CommitmentRecent = Commitment{Commitment: "recent"} CommitmentSingle = Commitment{Commitment: "single"} CommitmentRoot = Commitment{Commitment: "root"} CommitmentMax = Commitment{Commitment: "max"} )
var ( ErrNoAccountInfo = errors.New("no account info") ErrSignatureNotFound = errors.New("signature not found") ErrBlockNotAvailable = errors.New("block not available") )
var ( ErrIncorrectProgram = errors.New("incorrect program") ErrIncorrectInstruction = errors.New("incorrect instruction") )
Functions ¶
func CreateProgramAddress ¶ added in v0.74.0
CreateProgramAddress mirrors the implementation of the Solana SDK's CreateProgramAddress.
ProgramAddresses are public keys that _do not_ lie on the ed25519 curve to ensure that there is no associated private key. In the event that the program and seed parameters result in a valid public key, ErrInvalidPublicKey is returned.
func FindProgramAddress ¶ added in v0.74.0
FindProgramAddress mirrors the implementation of the Solana SDK's FindProgramAddress. Its primary use case (for Kin and Agora) is for deriving associated accounts.
Types ¶
type AccountInfo ¶
AccountInfo contains the Solana account information (not to be confused with a TokenAccount)
type AccountMeta ¶
type AccountMeta struct { PublicKey ed25519.PublicKey IsSigner bool IsWritable bool // contains filtered or unexported fields }
AccountMeta represents the account information required for building transactions.
func NewAccountMeta ¶
func NewAccountMeta(pub ed25519.PublicKey, isSigner bool) AccountMeta
NewAccountMeta creates a new AccountMeta representing a writable account.
func NewReadonlyAccountMeta ¶
func NewReadonlyAccountMeta(pub ed25519.PublicKey, isSigner bool) AccountMeta
NewAccountMeta creates a new AccountMeta representing a readonly account.
type Block ¶
type Block struct { Hash []byte PrevHash []byte ParentSlot uint64 Slot uint64 Transactions []BlockTransaction }
type BlockTransaction ¶
type BlockTransaction struct { Transaction Transaction Err *TransactionError }
type Client ¶
type Client interface { GetMinimumBalanceForRentExemption(size uint64) (lamports uint64, err error) GetSlot(Commitment) (uint64, error) GetRecentBlockhash() (Blockhash, error) GetBlockTime(block uint64) (time.Time, error) GetConfirmedBlock(slot uint64) (*Block, error) GetConfirmedBlocksWithLimit(start, limit uint64) ([]uint64, error) GetConfirmedTransaction(Signature) (ConfirmedTransaction, error) GetBalance(ed25519.PublicKey) (uint64, error) SimulateTransaction(Transaction) error SubmitTransaction(Transaction, Commitment) (Signature, *SignatureStatus, error) GetAccountInfo(ed25519.PublicKey, Commitment) (AccountInfo, error) RequestAirdrop(ed25519.PublicKey, uint64, Commitment) (Signature, error) GetConfirmationStatus(Signature, Commitment) (bool, error) GetSignatureStatus(Signature, Commitment) (*SignatureStatus, error) GetSignatureStatuses([]Signature) ([]*SignatureStatus, error) GetTokenAccountsByOwner(owner, mint ed25519.PublicKey) ([]ed25519.PublicKey, error) }
Client provides an interaction with the Solana JSON RPC API.
Reference: https://docs.solana.com/apps/jsonrpc-api
func NewWithRPCOptions ¶ added in v0.51.0
func NewWithRPCOptions(endpoint string, opts *jsonrpc.RPCClientOpts) Client
NewWithRPCOptions returns a client configured with the specified RPC options.
type Commitment ¶
type Commitment struct {
Commitment string `json:"commitment"`
}
type CompiledInstruction ¶
CompiledInstruction represents an instruction that has been compiled into a transaction.
type ConfirmedTransaction ¶
type ConfirmedTransaction struct { Slot uint64 Transaction Transaction Err *TransactionError }
type CustomError ¶
type CustomError int
CustomError is the numerical error returned by a non-system program.
func (CustomError) Error ¶
func (c CustomError) Error() string
type Instruction ¶
type Instruction struct { Program ed25519.PublicKey Accounts []AccountMeta Data []byte }
Instruction represents a transaction instruction.
func NewInstruction ¶
func NewInstruction(program, data ed25519.PublicKey, accounts ...AccountMeta) Instruction
NewInstruction creates a new instruction.
type InstructionError ¶
InstructionError indicates an instruction returned an error in a transaction.
func (InstructionError) CustomError ¶
func (i InstructionError) CustomError() *CustomError
func (InstructionError) Error ¶
func (i InstructionError) Error() string
func (InstructionError) ErrorKey ¶
func (i InstructionError) ErrorKey() InstructionErrorKey
func (InstructionError) JSONString ¶
func (i InstructionError) JSONString() string
type InstructionErrorKey ¶
type InstructionErrorKey string
InstructionErrorKey is the string keys returned in an instruction error.
Source: https://github.com/solana-labs/solana/blob/master/sdk/src/instruction.rs#L11
const ( InstructionErrorGenericError InstructionErrorKey = "GenericError" InstructionErrorInvalidArgument InstructionErrorKey = "InvalidArgument" InstructionErrorInvalidInstructionData InstructionErrorKey = "InvalidInstructionData" InstructionErrorInvalidAccountData InstructionErrorKey = "InvalidAccountData" InstructionErrorAccountDataTooSmall InstructionErrorKey = "AccountDataTooSmall" InstructionErrorInsufficientFunds InstructionErrorKey = "InsufficientFunds" InstructionErrorIncorrectProgramID InstructionErrorKey = "IncorrectProgramId" InstructionErrorMissingRequiredSignature InstructionErrorKey = "MissingRequiredSignature" InstructionErrorAccountAlreadyInitialized InstructionErrorKey = "AccountAlreadyInitialized" InstructionErrorUninitializedAccount InstructionErrorKey = "UninitializedAccount" InstructionErrorUnbalancedInstruction InstructionErrorKey = "UnbalancedInstruction" InstructionErrorModifiedProgramID InstructionErrorKey = "ModifiedProgramId" InstructionErrorExternalAccountLamportSpend InstructionErrorKey = "ExternalAccountLamportSpend" InstructionErrorExternalAccountDataModified InstructionErrorKey = "ExternalAccountDataModified" InstructionErrorReadonlyLamportChange InstructionErrorKey = "ReadonlyLamportChange" InstructionErrorReadonlyDataModified InstructionErrorKey = "ReadonlyDataModified" InstructionErrorDuplicateAccountIndex InstructionErrorKey = "DuplicateAccountIndex" InstructionErrorExecutableModified InstructionErrorKey = "ExecutableModified" InstructionErrorRentEpochModified InstructionErrorKey = "RentEpochModified" InstructionErrorNotEnoughAccountKeys InstructionErrorKey = "NotEnoughAccountKeys" InstructionErrorAccountDataSizeChanged InstructionErrorKey = "AccountDataSizeChanged" InstructionErrorAccountNotExecutable InstructionErrorKey = "AccountNotExecutable" InstructionErrorAccountBorrowFailed InstructionErrorKey = "AccountBorrowFailed" InstructionErrorAccountBorrowOutstanding InstructionErrorKey = "AccountBorrowOutstanding" InstructionErrorDuplicateAccountOutOfSync InstructionErrorKey = "DuplicateAccountOutOfSync" InstructionErrorCustom InstructionErrorKey = "Custom" InstructionErrorInvalidError InstructionErrorKey = "InvalidError" InstructionErrorExecutableDataModified InstructionErrorKey = "ExecutableDataModified" InstructionErrorExecutableLamportChange InstructionErrorKey = "ExecutableLamportChange" InstructionErrorExecutableAccountNotRentExempt InstructionErrorKey = "ExecutableAccountNotRentExempt" InstructionErrorUnsupportedProgramID InstructionErrorKey = "UnsupportedProgramId" InstructionErrorCallDepth InstructionErrorKey = "CallDepth" InstructionErrorMissingAccount InstructionErrorKey = "MissingAccount" InstructionErrorReentrancyNotAllowed InstructionErrorKey = "ReentrancyNotAllowed" InstructionErrorMaxSeedLengthExceeded InstructionErrorKey = "MaxSeedLengthExceeded" InstructionErrorInvalidSeeds InstructionErrorKey = "InvalidSeeds" InstructionErrorInvalidRealloc InstructionErrorKey = "InvalidRealloc" )
type Message ¶
type Message struct { Header Header Accounts []ed25519.PublicKey RecentBlockhash Blockhash Instructions []CompiledInstruction }
type MockClient ¶
func NewMockClient ¶
func NewMockClient() *MockClient
func (*MockClient) GetAccountInfo ¶
func (m *MockClient) GetAccountInfo(account ed25519.PublicKey, commitment Commitment) (AccountInfo, error)
func (*MockClient) GetBalance ¶
func (m *MockClient) GetBalance(account ed25519.PublicKey) (uint64, error)
func (*MockClient) GetBlockTime ¶ added in v0.55.0
func (m *MockClient) GetBlockTime(slot uint64) (time.Time, error)
func (*MockClient) GetConfirmationStatus ¶
func (m *MockClient) GetConfirmationStatus(signature Signature, commitment Commitment) (bool, error)
func (*MockClient) GetConfirmedBlock ¶
func (m *MockClient) GetConfirmedBlock(slot uint64) (*Block, error)
func (*MockClient) GetConfirmedBlocksWithLimit ¶
func (m *MockClient) GetConfirmedBlocksWithLimit(start, limit uint64) ([]uint64, error)
func (*MockClient) GetConfirmedTransaction ¶
func (m *MockClient) GetConfirmedTransaction(sig Signature) (ConfirmedTransaction, error)
func (*MockClient) GetMinimumBalanceForRentExemption ¶
func (m *MockClient) GetMinimumBalanceForRentExemption(size uint64) (lamports uint64, err error)
func (*MockClient) GetRecentBlockhash ¶
func (m *MockClient) GetRecentBlockhash() (Blockhash, error)
func (*MockClient) GetSignatureStatus ¶
func (m *MockClient) GetSignatureStatus(signature Signature, commitment Commitment) (*SignatureStatus, error)
func (*MockClient) GetSignatureStatuses ¶
func (m *MockClient) GetSignatureStatuses(signature []Signature) ([]*SignatureStatus, error)
func (*MockClient) GetSlot ¶
func (m *MockClient) GetSlot(commitment Commitment) (uint64, error)
func (*MockClient) GetTokenAccountsByOwner ¶
func (*MockClient) RequestAirdrop ¶
func (m *MockClient) RequestAirdrop(account ed25519.PublicKey, lamports uint64, commitment Commitment) (Signature, error)
func (*MockClient) SimulateTransaction ¶
func (m *MockClient) SimulateTransaction(txn Transaction) error
func (*MockClient) SubmitTransaction ¶
func (m *MockClient) SubmitTransaction(txn Transaction, commitment Commitment) (Signature, *SignatureStatus, error)
type Signature ¶
type Signature [ed25519.SignatureSize]byte
type SignatureStatus ¶
type SignatureStatus struct { Slot uint64 ErrorResult *TransactionError // Confirmations will be nil if the transaction has been rooted. Confirmations *int ConfirmationStatus string }
func (SignatureStatus) Confirmed ¶ added in v0.70.0
func (s SignatureStatus) Confirmed() bool
func (SignatureStatus) Finalized ¶ added in v0.70.0
func (s SignatureStatus) Finalized() bool
type SortableAccountMeta ¶
type SortableAccountMeta []AccountMeta
SortableAccountMeta is a sortable []AccountMeta based on the solana transaction account sorting rules.
Reference: https://docs.solana.com/transaction#account-addresses-format
func (SortableAccountMeta) Len ¶
func (s SortableAccountMeta) Len() int
Len is the number of elements in the collection.
func (SortableAccountMeta) Less ¶
func (s SortableAccountMeta) Less(i int, j int) bool
Less reports whether the element with index i should sort before the element with index j.
func (SortableAccountMeta) Swap ¶
func (s SortableAccountMeta) Swap(i int, j int)
Swap swaps the elements with indexes i and j.
type Transaction ¶
func NewTransaction ¶
func NewTransaction(payer ed25519.PublicKey, instructions ...Instruction) Transaction
func (Transaction) Marshal ¶
func (t Transaction) Marshal() []byte
func (*Transaction) SetBlockhash ¶
func (t *Transaction) SetBlockhash(bh Blockhash)
func (*Transaction) Sign ¶
func (t *Transaction) Sign(signers ...ed25519.PrivateKey) error
func (*Transaction) Signature ¶
func (t *Transaction) Signature() []byte
func (*Transaction) String ¶
func (t *Transaction) String() string
func (*Transaction) Unmarshal ¶
func (t *Transaction) Unmarshal(b []byte) error
type TransactionError ¶
type TransactionError struct {
// contains filtered or unexported fields
}
TransactionError contains the transaction error details.
func NewTransactionError ¶
func NewTransactionError(key TransactionErrorKey) *TransactionError
func ParseRPCError ¶
func ParseRPCError(err *jsonrpc.RPCError) (*TransactionError, error)
ParseRPCError parses the jsonrpc.RPCError returned from a method.
func ParseTransactionError ¶
func ParseTransactionError(raw interface{}) (*TransactionError, error)
ParseTransactionError parses the JSON error returned from the "err" field in various RPC methods and fields.
func TransactionErrorFromInstructionError ¶
func TransactionErrorFromInstructionError(err *InstructionError) (*TransactionError, error)
func (TransactionError) Error ¶
func (t TransactionError) Error() string
func (TransactionError) ErrorKey ¶
func (t TransactionError) ErrorKey() TransactionErrorKey
func (TransactionError) InstructionError ¶
func (t TransactionError) InstructionError() *InstructionError
func (TransactionError) JSONString ¶
func (t TransactionError) JSONString() (string, error)
type TransactionErrorKey ¶
type TransactionErrorKey string
TransactionErrorKey is the string key returned in a transaction error.
Source: https://github.com/solana-labs/solana/blob/master/sdk/src/transaction.rs#L22
const ( TransactionErrorAccountInUse TransactionErrorKey = "AccountInUse" TransactionErrorAccountLoadedTwice TransactionErrorKey = "AccountLoadedTwice" TransactionErrorAccountNotFound TransactionErrorKey = "AccountNotFound" TransactionErrorProgramAccountNotFound TransactionErrorKey = "ProgramAccountNotFound" TransactionErrorInsufficientFundsForFee TransactionErrorKey = "InsufficientFundsForFee" TransactionErrorInvalidAccountForFee TransactionErrorKey = "InvalidAccountForFee" TransactionErrorDuplicateSignature TransactionErrorKey = "DuplicateSignature" TransactionErrorBlockhashNotFound TransactionErrorKey = "BlockhashNotFound" TransactionErrorInstructionError TransactionErrorKey = "InstructionError" TransactionErrorCallChainTooDeep TransactionErrorKey = "CallChainTooDeep" TransactionErrorMissingSignatureForFee TransactionErrorKey = "MissingSignatureForFee" TransactionErrorInvalidAccountIndex TransactionErrorKey = "InvalidAccountIndex" TransactionErrorSignatureFailure TransactionErrorKey = "SignatureFailure" TransactionErrorInvalidProgramForExecution TransactionErrorKey = "InvalidProgramForExecution" TransactionErrorSanitizeFailure TransactionErrorKey = "SanitizeFailure" TransactionErrorClusterMaintenance TransactionErrorKey = "ClusterMaintenance" )