types

package
v3.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxSeeds      = 16
	MaxSeedLength = 32

	PDAMarker = "ProgramDerivedAddress"
)

constants

View Source
const (
	// CommitmentProcessed queries the most recent block which has reached 1 confirmation by the connected node
	CommitmentProcessed = CommitmentType("processed")
	// CommitmentConfirmed queries the most recent block which has reached 1 confirmation by the cluster
	CommitmentConfirmed = CommitmentType("confirmed")
	// CommitmentFinalized queries the most recent block which has been finalized by the cluster
	CommitmentFinalized = CommitmentType("finalized")
)

commitment contants

Variables

View Source
var (
	TokenProgramID = MustPublicKeyFromBase58("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
	ATAProgramID   = MustPublicKeyFromBase58("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL")
)

known program IDs

View Source
var InstructionDecoderRegistry = map[string]InstructionDecoder{}

InstructionDecoderRegistry instruction decoder registry

Functions

func DecodeInstruction

func DecodeInstruction(programID PublicKey, accounts []*AccountMeta, data []byte) (interface{}, error)

DecodeInstruction decode instruction

func NewRandomPrivateKey

func NewRandomPrivateKey() (PublicKey, PrivateKey, error)

NewRandomPrivateKey new random private key

func RegisterInstructionDecoder

func RegisterInstructionDecoder(programID PublicKey, decoder InstructionDecoder)

RegisterInstructionDecoder register instruction decoder

Types

type Account

type Account struct {
	PrivateKey PrivateKey
}

Account account type

func AccountFromPrivateKeyBase58

func AccountFromPrivateKeyBase58(privateKey string) (*Account, error)

AccountFromPrivateKeyBase58 account from private key base58

func NewAccount

func NewAccount() *Account

NewAccount new account

func (*Account) PublicKey

func (a *Account) PublicKey() PublicKey

PublicKey get account public key

type AccountInfo

type AccountInfo struct {
	Lamports   bin.Uint64  `json:"lamports"`
	Data       interface{} `json:"data"` // <[string, encoding]|object>
	Owner      PublicKey   `json:"owner"`
	Executable bool        `json:"executable"`
	RentEpoch  bin.Uint64  `json:"rentEpoch"`
}

AccountInfo account info

type AccountKey

type AccountKey struct {
	PublicKey PublicKey `json:"pubkey"`
	Signer    bool      `json:"signer"`
	Writable  bool      `json:"writable"`
}

AccountKey account key

type AccountMeta

type AccountMeta struct {
	PublicKey  PublicKey
	IsSigner   bool
	IsWritable bool
}

AccountMeta account meta type

type AccountSettable

type AccountSettable interface {
	SetAccounts(accounts []*AccountMeta) error
}

AccountSettable interface

type Base58

type Base58 []byte

Base58 bytes

func (Base58) MarshalJSON

func (t Base58) MarshalJSON() ([]byte, error)

MarshalJSON json marshal

func (Base58) String

func (t Base58) String() string

func (*Base58) UnmarshalJSON

func (t *Base58) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON json unmarshal

type BlockReward

type BlockReward struct {
	Pubkey   PublicKey  `json:"pubkey"`
	Lamports bin.Uint64 `json:"lamports"`
}

BlockReward block reward

type BorshString

type BorshString struct {
	Length  uint32 `bin:"sizeof=Content"`
	Content []byte
}

BorshString borsh string

func ToBorshString

func ToBorshString(str string) BorshString

ToBorshString to borsh encoded string

func (BorshString) MarshalJSON

func (s BorshString) MarshalJSON() ([]byte, error)

MarshalJSON json marshal

func (*BorshString) String

func (s *BorshString) String() string

func (*BorshString) UnmarshalJSON

func (s *BorshString) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON json unmarshal

type ByteWrapper

type ByteWrapper struct {
	io.Reader
}

ByteWrapper type

func (*ByteWrapper) ReadByte

func (w *ByteWrapper) ReadByte() (byte, error)

ReadByte read byte

type CommitmentType

type CommitmentType string

CommitmentType is the level of commitment desired when querying state. https://docs.com/developing/clients/jsonrpc-api#configuring-state-commitment

type CompiledInstruction

type CompiledInstruction struct {
	ProgramIDIndex uint8         `json:"programIdIndex"`
	AccountCount   bin.Varuint16 `json:"-" bin:"sizeof=Accounts"`
	Accounts       Uint8Arr      `json:"accounts"`
	DataLength     bin.Varuint16 `json:"-" bin:"sizeof=Data"`
	Data           Base58        `json:"data"`
}

CompiledInstruction type

func (*CompiledInstruction) ResolveInstructionAccounts

func (ci *CompiledInstruction) ResolveInstructionAccounts(message *Message) (out []*AccountMeta)

ResolveInstructionAccounts resolve instruction accounts

type Context

type Context struct {
	Slot bin.Uint64
}

Context type

type Data

type Data []byte

Data bytes

func (Data) MarshalJSON

func (t Data) MarshalJSON() ([]byte, error)

MarshalJSON json marshal

func (Data) String

func (t Data) String() string

func (*Data) UnmarshalJSON

func (t *Data) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON json unmarshal

type FeeCalculator

type FeeCalculator struct {
	LamportsPerSignature bin.Uint64 `json:"lamportsPerSignature"`
}

FeeCalculator fee calculator

type FeeResult

type FeeResult struct {
	Blockhash            Hash          `json:"blockhash"`
	FeeCalculator        FeeCalculator `json:"feeCalculator"`
	LastValidBlockHeight bin.Uint64    `json:"lastValidBlockHeight"`
	LastValidSlot        bin.Uint64    `json:"lastValidSlot"`
}

FeeResult fee result

type GetAccountInfoResult

type GetAccountInfoResult struct {
	RPCContext
	Value *AccountInfo `json:"value"`
}

GetAccountInfoResult get account info result

type GetBalanceResult

type GetBalanceResult struct {
	RPCContext
	Value bin.Uint64 `json:"value"`
}

GetBalanceResult get balance result

type GetBlockResult

type GetBlockResult struct {
	Blockhash         Hash                  `json:"blockhash"`
	PreviousBlockhash Hash                  `json:"previousBlockhash"`
	ParentSlot        bin.Uint64            `json:"parentSlot"`
	Transactions      []TransactionWithMeta `json:"transactions,omitempty"`
	Signatures        []Signature           `json:"signatures,omitempty"`
	Rewards           []BlockReward         `json:"rewards"`
	BlockTime         bin.Uint64            `json:"blockTime,omitempty"`
}

GetBlockResult get block result

type GetEpochInfoResult

type GetEpochInfoResult struct {
	AbsoluteSlot     bin.Uint64 `json:"absoluteSlot"`
	BlockHeight      bin.Uint64 `json:"blockHeight"`
	Epoch            bin.Uint64 `json:"epoch"`
	SlotIndex        bin.Uint64 `json:"slotIndex"`
	SlotsInEpoch     bin.Uint64 `json:"slotsInEpoch"`
	TransactionCount bin.Uint64 `json:"transactionCount"`
}

type GetFeesResult

type GetFeesResult struct {
	RPCContext
	Value FeeResult `json:"value"`
}

GetFeesResult get fees result

type GetLatestBlockhashResult

type GetLatestBlockhashResult struct {
	RPCContext
	Value LatestBlockhashResult `json:"value"`
}

GetLatestBlockhashResult get latest block hash result

type GetNonceAccountInfoResult

type GetNonceAccountInfoResult struct {
	RPCContext
	Value *NonceAccountValue `json:"value"`
}

GetNonceAccountInfoResult get account info result

type GetProgramAccountsOpts

type GetProgramAccountsOpts struct {
	Commitment CommitmentType `json:"commitment,omitempty"`

	// Filter on accounts, implicit AND between filters
	Filters []RPCFilter `json:"filters,omitempty"`
}

GetProgramAccountsOpts get program account options

type GetProgramAccountsResult

type GetProgramAccountsResult []*KeyedAccount

GetProgramAccountsResult get program accounts result

type GetRecentBlockhashResult

type GetRecentBlockhashResult struct {
	RPCContext
	Value RecentBlockhashResult `json:"value"`
}

GetRecentBlockhashResult get recent block hash result DEPRECATED: Please use getFeeForMessage instead This method is expected to be removed in solana-core v2.0

type GetSignatureStatusesResult

type GetSignatureStatusesResult struct {
	RPCContext
	Value []SignatureStatus `json:"value"`
}

GetSignatureStatusesResult result

type GetSignaturesForAddressOpts

type GetSignaturesForAddressOpts struct {
	Limit  uint64 `json:"limit,omitempty"`
	Before string `json:"before,omitempty"`
	Until  string `json:"until,omitempty"`
}

GetSignaturesForAddressOpts get signatures for address opts

type GetSignaturesForAddressResult

type GetSignaturesForAddressResult []*TransactionSignature

GetSignaturesForAddressResult get signatures for address result

type GetSlotResult

type GetSlotResult bin.Uint64

GetSlotResult get slot result

type GetTokenAmountResult

type GetTokenAmountResult struct {
	RPCContext
	Value TokenAmountResult `json:"value"`
}

GetTokenAmountResult get token amount result including get token account balance and get token supply

type Hash

type Hash = PublicKey

Hash alias of PublicKey

type InstructionDecoder

type InstructionDecoder func(instructionAccounts []*AccountMeta, data []byte) (interface{}, error)

InstructionDecoder receives the AccountMeta FOR THAT INSTRUCTION, and not the accounts of the *Message object. Resolve with CompiledInstruction.ResolveInstructionAccounts(message) beforehand.

type InstructionInfo

type InstructionInfo struct {
	Info            map[string]interface{} `json:"info"`
	InstructionType string                 `json:"type"`
}

InstructionInfo instruction info

type KeyedAccount

type KeyedAccount struct {
	Pubkey  PublicKey    `json:"pubkey"`
	Account *AccountInfo `json:"account"`
}

KeyedAccount keyed account

type LatestBlockhashResult

type LatestBlockhashResult struct {
	Blockhash            Hash       `json:"blockhash"`
	LastValidBlockHeight bin.Uint64 `json:"lastValidBlockHeight"`
}

LatestBlockhashResult latest block hash result

type Message

type Message struct {
	Header          MessageHeader         `json:"header"`
	AccountKeys     []PublicKey           `json:"accountKeys"`
	RecentBlockhash Hash                  `json:"recentBlockhash"`
	Instructions    []CompiledInstruction `json:"instructions"`
}

Message type

func (*Message) AccountMetaList

func (m *Message) AccountMetaList() (out []*AccountMeta)

AccountMetaList get account meta list

func (*Message) IsSigner

func (m *Message) IsSigner(account PublicKey) bool

IsSigner is signer

func (*Message) IsWritable

func (m *Message) IsWritable(account PublicKey) bool

IsWritable is writable

func (*Message) ResolveProgramIDIndex

func (m *Message) ResolveProgramIDIndex(programIDIndex uint8) (PublicKey, error)

ResolveProgramIDIndex resolve programID index

func (*Message) Serialize

func (m *Message) Serialize() ([]byte, error)

SignerKeys signer keys

func (*Message) SignerKeys

func (m *Message) SignerKeys() []PublicKey

SignerKeys signer keys

func (*Message) TouchAccount

func (m *Message) TouchAccount(account PublicKey) bool

TouchAccount touch account

type MessageHeader

type MessageHeader struct {
	NumRequiredSignatures       uint8 `json:"numRequiredSignatures"`
	NumReadonlySignedAccounts   uint8 `json:"numReadonlySignedAccounts"`
	NumReadonlyUnsignedAccounts uint8 `json:"numReadonlyUnsignedAccounts"`
}

MessageHeader type

type NonceAccountData

type NonceAccountData struct {
	Info    *NonceAccountParsed `json:"parsed"`
	Program string              `json:"program"`
	Space   bin.Uint64          `json:"space"`
}

type NonceAccountFee

type NonceAccountFee struct {
	LamportsPerSignature string `json:"lamportsPerSignature"`
}

type NonceAccountInfo

type NonceAccountInfo struct {
	Authority     string           `json:"authority"`
	Blockhash     string           `json:"blockhash"`
	FeeCalculator *NonceAccountFee `json:"feeCalculator"`
}

type NonceAccountParsed

type NonceAccountParsed struct {
	Info *NonceAccountInfo `json:"info"`
	Type string            `json:"type"`
}

type NonceAccountValue

type NonceAccountValue struct {
	Lamports   bin.Uint64        `json:"lamports"`
	Data       *NonceAccountData `json:"data"` // <[string, encoding]|object>
	Owner      PublicKey         `json:"owner"`
	Executable bool              `json:"executable"`
	RentEpoch  bin.Uint64        `json:"rentEpoch"`
}

AccountInfo account info

type Padding

type Padding []byte

Padding bytes

type ParsedInstruction

type ParsedInstruction struct {
	Accounts  []PublicKey      `json:"accounts,omitempty"`
	Data      Base58           `json:"data,omitempty"`
	Parsed    *InstructionInfo `json:"parsed,omitempty"`
	Program   string           `json:"program,omitempty"`
	ProgramID PublicKey        `json:"programId"`
}

ParsedInstruction parsed instruction

func (*ParsedInstruction) IsParsed

func (p *ParsedInstruction) IsParsed() bool

IsParsed is parsed

type ParsedTransaction

type ParsedTransaction struct {
	Signatures []Signature `json:"signatures"`
	Message    RPCMessage  `json:"message"`
}

ParsedTransaction parsed tx

type PrivateKey

type PrivateKey []byte

PrivateKey bytes

func MustPrivateKeyFromBase58

func MustPrivateKeyFromBase58(in string) PrivateKey

MustPrivateKeyFromBase58 must decode private key from base58

func PrivateKeyFromBase58

func PrivateKeyFromBase58(privkey string) (PrivateKey, error)

PrivateKeyFromBase58 decode private key from base58

func PrivateKeyFromSolanaKeygenFile

func PrivateKeyFromSolanaKeygenFile(file string) (PrivateKey, error)

PrivateKeyFromSolanaKeygenFile decode private key from file

func (PrivateKey) PublicKey

func (k PrivateKey) PublicKey() PublicKey

PublicKey get public key

func (PrivateKey) Sign

func (k PrivateKey) Sign(payload []byte) (Signature, error)

Sign sign message

func (PrivateKey) String

func (k PrivateKey) String() string

type PublicKey

type PublicKey [32]byte

PublicKey bytes 32

func FindAssociatedTokenAddress

func FindAssociatedTokenAddress(walletAddress, tokenMintAddress PublicKey) (PublicKey, error)

FindAssociatedTokenAddress find associated token account

func MustPublicKeyFromBase58

func MustPublicKeyFromBase58(in string) PublicKey

MustPublicKeyFromBase58 must get public key from base58

func PublicKeyFindProgramAddress

func PublicKeyFindProgramAddress(seeds [][]byte, programID PublicKey) (PublicKey, byte, error)

PublicKeyFindProgramAddress create derived addresses

func PublicKeyFromBase58

func PublicKeyFromBase58(in string) (out PublicKey, err error)

PublicKeyFromBase58 get public key from base58

func PublicKeyFromBytes

func PublicKeyFromBytes(in []byte) (out PublicKey)

PublicKeyFromBytes get public key from bytes

func (PublicKey) Equals

func (p PublicKey) Equals(pb PublicKey) bool

Equals compare public key

func (PublicKey) IsZero

func (p PublicKey) IsZero() bool

IsZero is zero public key

func (PublicKey) MarshalJSON

func (p PublicKey) MarshalJSON() ([]byte, error)

MarshalJSON json marshal

func (PublicKey) String

func (p PublicKey) String() string

func (PublicKey) ToSlice

func (p PublicKey) ToSlice() []byte

ToSlice to slice

func (*PublicKey) UnmarshalJSON

func (p *PublicKey) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON json unmarshal

func (PublicKey) VerifySignature

func (p PublicKey) VerifySignature(message, sig []byte) bool

VerifySignature verify signature

type RPCContext

type RPCContext struct {
	Context Context `json:"context,omitempty"`
}

RPCContext rpc context

type RPCFilter

type RPCFilter struct {
	Memcmp   *RPCFilterMemcmp `json:"memcmp,omitempty"`
	DataSize bin.Uint64       `json:"dataSize,omitempty"`
}

RPCFilter type

type RPCFilterMemcmp

type RPCFilterMemcmp struct {
	Offset int    `json:"offset"`
	Bytes  Base58 `json:"bytes"`
}

RPCFilterMemcmp type

type RPCMessage

type RPCMessage struct {
	AccountKeys     []*AccountKey       `json:"accountKeys"`
	RecentBlockhash Hash                `json:"recentBlockhash"`
	Instructions    []ParsedInstruction `json:"instructions"`
}

RPCMessage type

type RecentBlockhashResult

type RecentBlockhashResult struct {
	Blockhash     Hash          `json:"blockhash"`
	FeeCalculator FeeCalculator `json:"feeCalculator"`
}

RecentBlockhashResult block hash result

type SendTransactionOptions

type SendTransactionOptions struct {
	SkipPreflight       bool           // disable transaction verification step
	PreflightCommitment CommitmentType // preflight commitment level; default: "finalized"
}

SendTransactionOptions send tx options

type Signature

type Signature [64]byte

Signature 64 bytes

func MustSignatureFromString

func MustSignatureFromString(in string) (out Signature)

MustSignatureFromString must signature from string

func NewSignatureFromBase58

func NewSignatureFromBase58(in string) (out Signature, err error)

NewSignatureFromBase58 new signature from base58

func NewSignatureFromBytes

func NewSignatureFromBytes(in []byte) (out Signature, err error)

NewSignatureFromBytes new signature from bytes

func NewSignatureFromString

func NewSignatureFromString(in string) (out Signature, err error)

NewSignatureFromString new signature from string

func (Signature) MarshalJSON

func (s Signature) MarshalJSON() ([]byte, error)

MarshalJSON json marshal

func (Signature) String

func (s Signature) String() string

func (Signature) ToSlice

func (s Signature) ToSlice() []byte

ToSlice to slice

func (*Signature) UnmarshalJSON

func (s *Signature) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON json unmarshal

func (Signature) Verify

func (s Signature) Verify(publicKey PublicKey, message []byte) bool

Verify verify signature

type SignatureStatus

type SignatureStatus struct {
	Slot               bin.Uint64  `json:"slot"`
	Confirmations      *bin.Uint64 `json:"confirmations"`
	Err                interface{} `json:"err"`
	ConfirmationStatus *string     `json:"confirmationStatus"`
}

SignatureStatus signature status

type SimulateTransactionResponse

type SimulateTransactionResponse struct {
	Err  interface{} `json:"err"`
	Logs []string    `json:"logs"`
}

SimulateTransactionResponse simulate tx responce

type TokenAmountResult

type TokenAmountResult struct {
	Amount         bin.Uint64 `json:"amount"`
	Decimals       uint8      `json:"decimals"`
	UIAmountString string     `json:"uiAmountString"`
}

TokenAmountResult token amount result

type TokenBalances

type TokenBalances struct {
	AccountIndex  uint8             `json:"accountIndex"`
	Mint          PublicKey         `json:"mint"`
	Owner         PublicKey         `json:"owner"`
	UITokenAmount TokenAmountResult `json:"uiTokenAmount"`
}

TokenBalances token balances

type Transaction

type Transaction struct {
	Signatures []Signature `json:"signatures"`
	Message    Message     `json:"message"`
}

Transaction type

func DecodeTransaction

func DecodeTransaction(encodedStr string, encoding string) (*Transaction, error)

DecodeTransaction decode transaction

func NewTransaction

func NewTransaction(instructions []TransactionInstruction, blockHash Hash, opts ...TransactionOption) (*Transaction, error)

NewTransaction new tx

func TransactionFromData

func TransactionFromData(in []byte) (*Transaction, error)

TransactionFromData transaction from data

func (*Transaction) AccountMetaList

func (t *Transaction) AccountMetaList() (out []*AccountMeta)

AccountMetaList get account meta list

func (*Transaction) IsSigner

func (t *Transaction) IsSigner(account PublicKey) bool

IsSigner is signer

func (*Transaction) IsWritable

func (t *Transaction) IsWritable(account PublicKey) bool

IsWritable is writable

func (*Transaction) ResolveProgramIDIndex

func (t *Transaction) ResolveProgramIDIndex(programIDIndex uint8) (PublicKey, error)

ResolveProgramIDIndex resolve programID index

func (*Transaction) Serialize

func (t *Transaction) Serialize(signdata []byte) ([]byte, error)

func (*Transaction) SerializeAll

func (t *Transaction) SerializeAll() ([]byte, error)

func (*Transaction) Sign

func (t *Transaction) Sign(getter privateKeyGetter) (out []Signature, err error)

Sign sign with private key

func (*Transaction) TouchAccount

func (t *Transaction) TouchAccount(account PublicKey) bool

TouchAccount touch account

type TransactionInstruction

type TransactionInstruction interface {
	Accounts() []*AccountMeta // returns the list of accounts the instructions requires
	ProgramID() PublicKey     // the programID the instruction acts on
	Data() ([]byte, error)    // the binary encoded instructions
}

TransactionInstruction interface

type TransactionMeta

type TransactionMeta struct {
	Err               interface{}     `json:"err"`
	Fee               bin.Uint64      `json:"fee"`
	PreBalances       []bin.Uint64    `json:"preBalances,omitempty"`
	PostBalances      []bin.Uint64    `json:"postBalances,omitempty"`
	PreTokenBalances  []TokenBalances `json:"preTokenBalances,omitempty"`
	PostTokenBalances []TokenBalances `json:"postTokenBalances,omitempty"`
	LogMessages       []string        `json:"logMessages"`
}

TransactionMeta tx meta

func (*TransactionMeta) IsStatusOk

func (m *TransactionMeta) IsStatusOk() bool

IsStatusOk in status ok

type TransactionOption

type TransactionOption interface {
	// contains filtered or unexported methods
}

TransactionOption interface

func TransactionPayer

func TransactionPayer(payer PublicKey) TransactionOption

TransactionPayer tx payer

type TransactionParsed

type TransactionParsed struct {
	Transaction *ParsedTransaction `json:"transaction"`
	Meta        *TransactionMeta   `json:"meta,omitempty"`
}

TransactionParsed tx parsed

type TransactionSignature

type TransactionSignature struct {
	Err       interface{} `json:"err,omitempty"`
	Memo      string      `json:"memo,omitempty"`
	Signature string      `json:"signature,omitempty"`
	Slot      bin.Uint64  `json:"slot,omitempty"`
}

TransactionSignature tx signature

type TransactionWithMeta

type TransactionWithMeta struct {
	Slot        bin.Uint64       `json:"slot,omitempty"`
	Transaction *Transaction     `json:"transaction"`
	BlockTime   bin.Uint64       `json:"blockTime,omitempty"`
	Meta        *TransactionMeta `json:"meta,omitempty"`
}

TransactionWithMeta tx with meta

type Uint8Arr

type Uint8Arr []uint8

Uint8Arr array of uint8 solve json marshal will encode '[]uint8' to string rather than an array of numbers

func (Uint8Arr) MarshalJSON

func (t Uint8Arr) MarshalJSON() ([]byte, error)

MarshalJSON json marshal

func (Uint8Arr) String

func (t Uint8Arr) String() string

Jump to

Keyboard shortcuts

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