solana

package
v0.85.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 27 Imported by: 24

Documentation

Index

Constants

View Source
const (

	// PollRate is the rate at which blocks should be polled at.
	PollRate = (time.Second / slotsPerSec) / 2
)

Variables

View Source
var (
	ErrTooManySeeds          = errors.New("too many seeds")
	ErrMaxSeedLengthExceeded = errors.New("max seed length exceeded")

	ErrInvalidPublicKey = errors.New("invalid public key")
)
View Source
var (
	CommitmentRecent = Commitment{Commitment: "recent"}
	CommitmentSingle = Commitment{Commitment: "single"}
	CommitmentRoot   = Commitment{Commitment: "root"}
	CommitmentMax    = Commitment{Commitment: "max"}
)
View Source
var (
	ErrNoAccountInfo     = errors.New("no account info")
	ErrSignatureNotFound = errors.New("signature not found")
	ErrBlockNotAvailable = errors.New("block not available")
)
View Source
var (
	ErrIncorrectProgram     = errors.New("incorrect program")
	ErrIncorrectInstruction = errors.New("incorrect instruction")
)

Functions

func CreateProgramAddress added in v0.74.0

func CreateProgramAddress(program ed25519.PublicKey, seeds ...[]byte) (ed25519.PublicKey, error)

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.

Reference: https://github.com/solana-labs/solana/blob/5548e599fe4920b71766e0ad1d121755ce9c63d5/sdk/program/src/pubkey.rs#L158

func FindProgramAddress added in v0.74.0

func FindProgramAddress(program ed25519.PublicKey, seeds ...[]byte) (ed25519.PublicKey, error)

FindProgramAddress mirrors the implementation of the Solana SDK's FindProgramAddress. Its primary use case (for Kin and Agora) is for deriving associated accounts.

Reference: https://github.com/solana-labs/solana/blob/5548e599fe4920b71766e0ad1d121755ce9c63d5/sdk/program/src/pubkey.rs#L234

Types

type AccountInfo

type AccountInfo struct {
	Data       []byte
	Owner      ed25519.PublicKey
	Lamports   uint64
	Executable bool
}

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 Blockhash

type Blockhash [sha256.Size]byte

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) (*TransactionError, 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 New

func New(endpoint string) Client

New returns a client using the specified endpoint.

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

type CompiledInstruction struct {
	ProgramIndex byte
	Accounts     []byte
	Data         []byte
}

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 Header struct {
	NumSignatures     byte
	NumReadonlySigned byte
	NumReadOnly       byte
}

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

type InstructionError struct {
	Index int
	Err   error
}

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 (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
}

func (Message) Marshal

func (m Message) Marshal() []byte

func (*Message) Unmarshal

func (m *Message) Unmarshal(b []byte) (err error)

type MockClient

type MockClient struct {
	sync.Mutex
	mock.Mock
}

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 (m *MockClient) GetTokenAccountsByOwner(owner, mint ed25519.PublicKey) ([]ed25519.PublicKey, error)

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) (*TransactionError, 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

type Transaction struct {
	Signatures []Signature
	Message    Message
}

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 (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"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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