Documentation ¶
Index ¶
- Constants
- Variables
- func DecimalsInBigInt(decimal uint32) *big.Int
- func DecodeInstruction(programID PublicKey, accounts []*AccountMeta, data []byte) (interface{}, error)
- func IsAnyOfEncodingType(candidate EncodingType, allowed ...EncodingType) bool
- func NewRandomPrivateKey() (PublicKey, PrivateKey, error)
- func RegisterInstructionDecoder(programID PublicKey, decoder InstructionDecoder)
- type Account
- type AccountMeta
- type AccountMetaSlice
- type AccountsGettable
- type AccountsSettable
- type Base58
- type ByteWrapper
- type CompiledInstruction
- type Data
- type EncodingType
- type Hash
- type Instruction
- type InstructionDecoder
- type Message
- func (m *Message) AccountMetaList() (out []*AccountMeta)
- func (mx *Message) EncodeToTree(txTree treeout.Branches)
- func (m *Message) IsSigner(account PublicKey) bool
- func (m *Message) IsWritable(account PublicKey) bool
- func (mx *Message) MarshalBinary() ([]byte, error)
- func (mx *Message) MarshalWithEncoder(encoder *bin.Encoder) error
- func (m *Message) ResolveProgramIDIndex(programIDIndex uint16) (PublicKey, error)
- func (m *Message) TouchAccount(account PublicKey) bool
- func (mx *Message) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)
- type MessageHeader
- type Padding
- type PrivateKey
- type PublicKey
- func CreateProgramAddress(seeds [][]byte, programID PublicKey) (PublicKey, error)
- func CreateWithSeed(base PublicKey, seed string, owner PublicKey) (PublicKey, error)
- func FindAssociatedTokenAddress(walletAddress PublicKey, splTokenMintAddress PublicKey) (PublicKey, uint8, error)
- func FindProgramAddress(seed [][]byte, programID PublicKey) (PublicKey, uint8, error)
- func MustPublicKeyFromBase58(in string) PublicKey
- func PublicKeyFromBase58(in string) (out PublicKey, err error)
- func PublicKeyFromBytes(in []byte) (out PublicKey)
- func (p PublicKey) Bytes() []byte
- func (p PublicKey) Equals(pb PublicKey) bool
- func (p PublicKey) IsZero() bool
- func (p PublicKey) MarshalJSON() ([]byte, error)
- func (p PublicKey) MarshalText() ([]byte, error)
- func (p PublicKey) String() string
- func (p PublicKey) ToPointer() *PublicKey
- func (p *PublicKey) UnmarshalJSON(data []byte) (err error)
- func (p *PublicKey) UnmarshalText(data []byte) (err error)
- type PublicKeySlice
- type Signature
- type Transaction
- func (t *Transaction) AccountMetaList() (out []*AccountMeta)
- func (tx *Transaction) EncodeToTree(parent treeout.Branches)
- func (tx *Transaction) EncodeTree(encoder *text.TreeEncoder) (int, error)
- func (t *Transaction) IsSigner(account PublicKey) bool
- func (t *Transaction) IsWritable(account PublicKey) bool
- func (tx *Transaction) MarshalBinary() ([]byte, error)
- func (tx *Transaction) MarshalWithEncoder(encoder *bin.Encoder) error
- func (t *Transaction) ResolveProgramIDIndex(programIDIndex uint16) (PublicKey, error)
- func (tx *Transaction) Sign(getter privateKeyGetter) (out []Signature, err error)
- func (t *Transaction) TouchAccount(account PublicKey) bool
- func (tx *Transaction) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)
- type TransactionBuilder
- func (builder *TransactionBuilder) AddInstruction(instruction Instruction) *TransactionBuilder
- func (builder *TransactionBuilder) Build() (*Transaction, error)
- func (builder *TransactionBuilder) SetFeePayer(feePayer PublicKey) *TransactionBuilder
- func (builder *TransactionBuilder) SetRecentBlockHash(recentBlockHash Hash) *TransactionBuilder
- func (builder *TransactionBuilder) WithOpt(opt TransactionOption) *TransactionBuilder
- type TransactionOption
Constants ¶
const ( /// Number of bytes in a pubkey. PublicKeyLength = 32 // Maximum length of derived pubkey seed. MaxSeedLength = 32 // Maximum number of seeds. MaxSeeds = 16 )
const ( // There are 1-billion lamports in one SOL. LAMPORTS_PER_SOL uint64 = 1000000000 )
const PDA_MARKER = "ProgramDerivedAddress"
Variables ¶
var ( // Create new accounts, allocate account data, assign accounts to owning programs, // transfer lamports from System Program owned accounts and pay transacation fees. SystemProgramID = MustPublicKeyFromBase58("11111111111111111111111111111111") // Add configuration data to the chain and the list of public keys that are permitted to modify it. ConfigProgramID = MustPublicKeyFromBase58("Config1111111111111111111111111111111111111") // Create and manage accounts representing stake and rewards for delegations to validators. StakeProgramID = MustPublicKeyFromBase58("Stake11111111111111111111111111111111111111") // Create and manage accounts that track validator voting state and rewards. VoteProgramID = MustPublicKeyFromBase58("Vote111111111111111111111111111111111111111") BPFLoaderDeprecatedProgramID = MustPublicKeyFromBase58("BPFLoader1111111111111111111111111111111111") // Deploys, upgrades, and executes programs on the chain. BPFLoaderProgramID = MustPublicKeyFromBase58("BPFLoader2111111111111111111111111111111111") BPFLoaderUpgradeableProgramID = MustPublicKeyFromBase58("BPFLoaderUpgradeab1e11111111111111111111111") // Verify secp256k1 public key recovery operations (ecrecover). Secp256k1ProgramID = MustPublicKeyFromBase58("KeccakSecp256k11111111111111111111111111111") FeatureProgramID = MustPublicKeyFromBase58("Feature111111111111111111111111111111111111") )
var ( // A Token program on the Solana blockchain. // This program defines a common implementation for Fungible and Non Fungible tokens. SPLTokenProgramID = MustPublicKeyFromBase58("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA") // A Uniswap-like exchange for the Token program on the Solana blockchain, // implementing multiple automated market maker (AMM) curves. SPLTokenSwapProgramID = MustPublicKeyFromBase58("SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8") SPLTokenSwapFeeOwner = MustPublicKeyFromBase58("HfoTxFR1Tm6kGmWgYWD6J7YHVy1UwqSULUGVLXkJqaKN") // A lending protocol for the Token program on the Solana blockchain inspired by Aave and Compound. SPLTokenLendingProgramID = MustPublicKeyFromBase58("LendZqTs8gn5CTSJU1jWKhKuVpjJGom45nnwPb2AMTi") // This program defines the convention and provides the mechanism for mapping // the user's wallet address to the associated token accounts they hold. SPLAssociatedTokenAccountProgramID = MustPublicKeyFromBase58("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL") // The Memo program is a simple program that validates a string of UTF-8 encoded characters // and verifies that any accounts provided are signers of the transaction. // The program also logs the memo, as well as any verified signer addresses, // to the transaction log, so that anyone can easily observe memos // and know they were approved by zero or more addresses // by inspecting the transaction log from a trusted provider. SPLMemoProgramID = MustPublicKeyFromBase58("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr") )
SPL:
var ( // The Clock sysvar contains data on cluster time, // including the current slot, epoch, and estimated wall-clock Unix timestamp. // It is updated every slot. SysVarClockPubkey = MustPublicKeyFromBase58("SysvarC1ock11111111111111111111111111111111") // The EpochSchedule sysvar contains epoch scheduling constants that are set in genesis, // and enables calculating the number of slots in a given epoch, // the epoch for a given slot, etc. // (Note: the epoch schedule is distinct from the leader schedule) SysVarEpochSchedulePubkey = MustPublicKeyFromBase58("SysvarEpochSchedu1e111111111111111111111111") // The Fees sysvar contains the fee calculator for the current slot. // It is updated every slot, based on the fee-rate governor. SysVarFeesPubkey = MustPublicKeyFromBase58("SysvarFees111111111111111111111111111111111") // The Instructions sysvar contains the serialized instructions in a Message while that Message is being processed. // This allows program instructions to reference other instructions in the same transaction. SysVarInstructionsPubkey = MustPublicKeyFromBase58("Sysvar1nstructions1111111111111111111111111") // The RecentBlockhashes sysvar contains the active recent blockhashes as well as their associated fee calculators. // It is updated every slot. // Entries are ordered by descending block height, // so the first entry holds the most recent block hash, // and the last entry holds an old block hash. SysVarRecentBlockHashesPubkey = MustPublicKeyFromBase58("SysvarRecentB1ockHashes11111111111111111111") // The Rent sysvar contains the rental rate. // Currently, the rate is static and set in genesis. // The Rent burn percentage is modified by manual feature activation. SysVarRentPubkey = MustPublicKeyFromBase58("SysvarRent111111111111111111111111111111111") // SysVarRewardsPubkey = MustPublicKeyFromBase58("SysvarRewards111111111111111111111111111111") // The SlotHashes sysvar contains the most recent hashes of the slot's parent banks. // It is updated every slot. SysVarSlotHashesPubkey = MustPublicKeyFromBase58("SysvarS1otHashes111111111111111111111111111") // The SlotHistory sysvar contains a bitvector of slots present over the last epoch. It is updated every slot. SysVarSlotHistoryPubkey = MustPublicKeyFromBase58("SysvarS1otHistory11111111111111111111111111") // The StakeHistory sysvar contains the history of cluster-wide stake activations and de-activations per epoch. // It is updated at the start of every epoch. SysVarStakeHistoryPubkey = MustPublicKeyFromBase58("SysvarStakeHistory1111111111111111111111111") )
var InstructionDecoderRegistry = map[string]InstructionDecoder{}
Functions ¶
func DecimalsInBigInt ¶
func DecodeInstruction ¶
func DecodeInstruction(programID PublicKey, accounts []*AccountMeta, data []byte) (interface{}, error)
func IsAnyOfEncodingType ¶ added in v0.3.5
func IsAnyOfEncodingType(candidate EncodingType, allowed ...EncodingType) bool
IsAnyOfEncodingType checks whether the provided `candidate` is any of the `allowed`.
func NewRandomPrivateKey ¶
func NewRandomPrivateKey() (PublicKey, PrivateKey, error)
func RegisterInstructionDecoder ¶
func RegisterInstructionDecoder(programID PublicKey, decoder InstructionDecoder)
Types ¶
type Account ¶
type Account struct {
PrivateKey PrivateKey
}
func NewAccount ¶
func NewAccount() *Account
type AccountMeta ¶
func Meta ¶ added in v0.4.0
func Meta( pubKey PublicKey, ) *AccountMeta
Meta intializes a new AccountMeta with the provided pubKey.
func NewAccountMeta ¶ added in v0.4.0
func NewAccountMeta( pubKey PublicKey, WRITE bool, SIGNER bool, ) *AccountMeta
func (*AccountMeta) SIGNER ¶ added in v0.4.0
func (meta *AccountMeta) SIGNER() *AccountMeta
SIGNER sets IsSigner to true.
func (*AccountMeta) WRITE ¶ added in v0.4.0
func (meta *AccountMeta) WRITE() *AccountMeta
WRITE sets IsWritable to true.
type AccountMetaSlice ¶ added in v0.4.0
type AccountMetaSlice []*AccountMeta
func (*AccountMetaSlice) Append ¶ added in v0.4.0
func (slice *AccountMetaSlice) Append(account *AccountMeta)
func (AccountMetaSlice) GetAccounts ¶ added in v0.4.0
func (slice AccountMetaSlice) GetAccounts() []*AccountMeta
func (AccountMetaSlice) GetSigners ¶ added in v0.4.0
func (slice AccountMetaSlice) GetSigners() []*AccountMeta
GetSigners returns the accounts that are signers.
func (*AccountMetaSlice) SetAccounts ¶ added in v0.4.0
func (slice *AccountMetaSlice) SetAccounts(accounts []*AccountMeta) error
type AccountsGettable ¶ added in v0.4.0
type AccountsGettable interface {
GetAccounts() (accounts []*AccountMeta)
}
type AccountsSettable ¶ added in v0.4.0
type AccountsSettable interface {
SetAccounts(accounts []*AccountMeta) error
}
type ByteWrapper ¶
func (*ByteWrapper) ReadByte ¶
func (w *ByteWrapper) ReadByte() (byte, error)
type CompiledInstruction ¶
type CompiledInstruction struct { // Index into the message.accountKeys array indicating the program account that executes this instruction. // NOTE: it is actually a uint8, but using a uint16 because uint8 is treated as a byte everywhere, // and that can be an issue. ProgramIDIndex uint16 `json:"programIdIndex"` AccountCount bin.Varuint16 `json:"-" bin:"sizeof=Accounts"` DataLength bin.Varuint16 `json:"-" bin:"sizeof=Data"` // List of ordered indices into the message.accountKeys array indicating which accounts to pass to the program. // NOTE: it is actually a []uint8, but using a uint16 because []uint8 is treated as a []byte everywhere, // and that can be an issue. Accounts []uint16 `json:"accounts"` // The program input data encoded in a base-58 string. Data Base58 `json:"data"` }
func (*CompiledInstruction) ResolveInstructionAccounts ¶
func (ci *CompiledInstruction) ResolveInstructionAccounts(message *Message) (out []*AccountMeta)
type Data ¶
type Data struct { Content []byte Encoding EncodingType }
func (Data) MarshalJSON ¶
func (*Data) UnmarshalJSON ¶
type EncodingType ¶
type EncodingType string
const ( EncodingBase58 EncodingType = "base58" // limited to Account data of less than 129 bytes EncodingBase64 EncodingType = "base64" // will return base64 encoded data for Account data of any size EncodingBase64Zstd EncodingType = "base64+zstd" // compresses the Account data using Zstandard and base64-encodes the result // attempts to use program-specific state parsers to // return more human-readable and explicit account state data. // If "jsonParsed" is requested but a parser cannot be found, // the field falls back to "base64" encoding, detectable when the data field is type <string>. // Cannot be used if specifying dataSlice parameters (offset, length). EncodingJSONParsed EncodingType = "jsonParsed" EncodingJSON EncodingType = "json" // NOTE: you're probably looking for EncodingJSONParsed )
type Hash ¶
type Hash PublicKey
func HashFromBase58 ¶
func MustHashFromBase58 ¶
func (Hash) MarshalJSON ¶
func (*Hash) UnmarshalJSON ¶
type Instruction ¶
type Instruction interface { ProgramID() PublicKey // the programID the instruction acts on Accounts() []*AccountMeta // returns the list of accounts the instructions requires Data() ([]byte, error) // the binary encoded instructions }
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 Message ¶
type Message struct { // List of base-58 encoded public keys used by the transaction, // including by the instructions and for signatures. // The first `message.header.numRequiredSignatures` public keys must sign the transaction. AccountKeys []PublicKey `json:"accountKeys"` // Details the account types and signatures required by the transaction. Header MessageHeader `json:"header"` // A base-58 encoded hash of a recent block in the ledger used to // prevent transaction duplication and to give transactions lifetimes. RecentBlockhash Hash `json:"recentBlockhash"` // List of program instructions that will be executed in sequence // and committed in one atomic transaction if all succeed. Instructions []CompiledInstruction `json:"instructions"` }
func (*Message) AccountMetaList ¶
func (m *Message) AccountMetaList() (out []*AccountMeta)
func (*Message) EncodeToTree ¶ added in v0.4.0
func (*Message) IsWritable ¶
func (*Message) MarshalBinary ¶ added in v0.3.5
func (*Message) MarshalWithEncoder ¶ added in v0.4.0
func (*Message) ResolveProgramIDIndex ¶
func (*Message) TouchAccount ¶
type MessageHeader ¶
type MessageHeader struct { // The total number of signatures required to make the transaction valid. // The signatures must match the first `numRequiredSignatures` of `message.account_keys`. NumRequiredSignatures uint8 `json:"numRequiredSignatures"` // The last numReadonlySignedAccounts of the signed keys are read-only accounts. // Programs may process multiple transactions that load read-only accounts within // a single PoH entry, but are not permitted to credit or debit lamports or modify // account data. // Transactions targeting the same read-write account are evaluated sequentially. NumReadonlySignedAccounts uint8 `json:"numReadonlySignedAccounts"` // The last `numReadonlyUnsignedAccounts` of the unsigned keys are read-only accounts. NumReadonlyUnsignedAccounts uint8 `json:"numReadonlyUnsignedAccounts"` }
func (*MessageHeader) EncodeToTree ¶ added in v0.4.0
func (header *MessageHeader) EncodeToTree(mxBranch treeout.Branches)
type PrivateKey ¶
type PrivateKey []byte
func MustPrivateKeyFromBase58 ¶
func MustPrivateKeyFromBase58(in string) PrivateKey
func PrivateKeyFromBase58 ¶
func PrivateKeyFromBase58(privkey string) (PrivateKey, error)
func PrivateKeyFromSolanaKeygenFile ¶
func PrivateKeyFromSolanaKeygenFile(file string) (PrivateKey, error)
func (PrivateKey) PublicKey ¶
func (k PrivateKey) PublicKey() PublicKey
func (PrivateKey) String ¶
func (k PrivateKey) String() string
type PublicKey ¶
type PublicKey [PublicKeyLength]byte
func CreateProgramAddress ¶ added in v0.4.0
Create a program address. Ported from https://github.com/solana-labs/solana/blob/216983c50e0a618facc39aa07472ba6d23f1b33a/sdk/program/src/pubkey.rs#L204
func CreateWithSeed ¶ added in v0.4.0
func FindAssociatedTokenAddress ¶ added in v0.4.0
func FindProgramAddress ¶ added in v0.4.0
Find a valid program address and its corresponding bump seed.
func MustPublicKeyFromBase58 ¶
func PublicKeyFromBase58 ¶
func PublicKeyFromBytes ¶
func (PublicKey) IsZero ¶
IsZero returns whether the public key is zero. NOTE: the System Program public key is also zero.
func (PublicKey) MarshalJSON ¶
func (PublicKey) MarshalText ¶ added in v0.3.4
func (*PublicKey) UnmarshalJSON ¶
func (*PublicKey) UnmarshalText ¶ added in v0.3.4
type PublicKeySlice ¶ added in v0.4.0
type PublicKeySlice []PublicKey
func (*PublicKeySlice) Append ¶ added in v0.4.0
func (slice *PublicKeySlice) Append(pubkey PublicKey)
func (PublicKeySlice) Has ¶ added in v0.4.0
func (slice PublicKeySlice) Has(pubkey PublicKey) bool
func (*PublicKeySlice) UniqueAppend ¶ added in v0.4.0
func (slice *PublicKeySlice) UniqueAppend(pubkey PublicKey) bool
UniqueAppend appends the provided pubkey only if it is not already present in the slice. Returns true when the provided pubkey wasn't already present.
type Signature ¶
type Signature [64]byte
func MustSignatureFromBase58 ¶
func SignatureFromBase58 ¶
func (Signature) MarshalJSON ¶
func (*Signature) UnmarshalJSON ¶
type Transaction ¶
type Transaction struct { // A list of base-58 encoded signatures applied to the transaction. // The list is always of length `message.header.numRequiredSignatures` and not empty. // The signature at index `i` corresponds to the public key at index // `i` in `message.account_keys`. The first one is used as the transaction id. Signatures []Signature `json:"signatures"` // Defines the content of the transaction. Message Message `json:"message"` }
func MustTransactionFromData ¶
func MustTransactionFromData(decoder *bin.Decoder) *Transaction
func NewTransaction ¶
func NewTransaction(instructions []Instruction, recentBlockHash Hash, opts ...TransactionOption) (*Transaction, error)
func TransactionFromDecoder ¶ added in v0.4.0
func TransactionFromDecoder(decoder *bin.Decoder) (*Transaction, error)
func (*Transaction) AccountMetaList ¶
func (t *Transaction) AccountMetaList() (out []*AccountMeta)
func (*Transaction) EncodeToTree ¶ added in v0.4.0
func (tx *Transaction) EncodeToTree(parent treeout.Branches)
func (*Transaction) EncodeTree ¶ added in v0.4.0
func (tx *Transaction) EncodeTree(encoder *text.TreeEncoder) (int, error)
func (*Transaction) IsSigner ¶
func (t *Transaction) IsSigner(account PublicKey) bool
func (*Transaction) IsWritable ¶
func (t *Transaction) IsWritable(account PublicKey) bool
func (*Transaction) MarshalBinary ¶ added in v0.3.5
func (tx *Transaction) MarshalBinary() ([]byte, error)
func (*Transaction) MarshalWithEncoder ¶ added in v0.4.0
func (tx *Transaction) MarshalWithEncoder(encoder *bin.Encoder) error
func (*Transaction) ResolveProgramIDIndex ¶
func (t *Transaction) ResolveProgramIDIndex(programIDIndex uint16) (PublicKey, error)
func (*Transaction) Sign ¶
func (tx *Transaction) Sign(getter privateKeyGetter) (out []Signature, err error)
func (*Transaction) TouchAccount ¶
func (t *Transaction) TouchAccount(account PublicKey) bool
func (*Transaction) UnmarshalWithDecoder ¶ added in v0.4.0
func (tx *Transaction) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)
type TransactionBuilder ¶ added in v0.4.0
type TransactionBuilder struct {
// contains filtered or unexported fields
}
func NewTransactionBuilder ¶ added in v0.4.0
func NewTransactionBuilder() *TransactionBuilder
NewTransactionBuilder creates a new instruction builder.
func (*TransactionBuilder) AddInstruction ¶ added in v0.4.0
func (builder *TransactionBuilder) AddInstruction(instruction Instruction) *TransactionBuilder
AddInstruction adds the provided instruction to the builder.
func (*TransactionBuilder) Build ¶ added in v0.4.0
func (builder *TransactionBuilder) Build() (*Transaction, error)
Build builds and returns a *Transaction.
func (*TransactionBuilder) SetFeePayer ¶ added in v0.4.0
func (builder *TransactionBuilder) SetFeePayer(feePayer PublicKey) *TransactionBuilder
Set transaction fee payer. If not set, defaults to first signer account of the first instruction.
func (*TransactionBuilder) SetRecentBlockHash ¶ added in v0.4.0
func (builder *TransactionBuilder) SetRecentBlockHash(recentBlockHash Hash) *TransactionBuilder
SetRecentBlockHash sets the recent blockhash for the instruction builder.
func (*TransactionBuilder) WithOpt ¶ added in v0.4.0
func (builder *TransactionBuilder) WithOpt(opt TransactionOption) *TransactionBuilder
WithOpt adds a TransactionOption.
type TransactionOption ¶
type TransactionOption interface {
// contains filtered or unexported methods
}
func TransactionPayer ¶
func TransactionPayer(payer PublicKey) TransactionOption
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
programs
|
|
serum
Code generated by rice embed-go; DO NOT EDIT.
|
Code generated by rice embed-go; DO NOT EDIT. |
token
Code generated by rice embed-go; DO NOT EDIT.
|
Code generated by rice embed-go; DO NOT EDIT. |
jsonrpc
Package jsonrpc provides a JSON-RPC 2.0 client that sends JSON-RPC requests and receives JSON-RPC responses using HTTP.
|
Package jsonrpc provides a JSON-RPC 2.0 client that sends JSON-RPC requests and receives JSON-RPC responses using HTTP. |