solana

package module
v0.0.0-...-7b77819 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 28 Imported by: 6

README

Custom impl of solana-go

Documentation

Index

Constants

View Source
const (
	/// Number of bytes in a pubkey.
	PublicKeyLength = 32
	// Maximum length of derived pubkey seed.
	MaxSeedLength = 32
	// Maximum number of seeds.
	MaxSeeds = 16
	/// Number of bytes in a signature.
	SignatureLength = 64
)
View Source
const (
	// There are 1-billion lamports in one SOL.
	LAMPORTS_PER_SOL uint64 = 1000000000
)
View Source
const PDA_MARKER = "ProgramDerivedAddress"

Variables

View Source
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")

	ComputeBudget = MustPublicKeyFromBase58("ComputeBudget111111111111111111111111111111")
)
View Source
var (
	// A Token program on the Solana blockchain.
	// This program defines a common implementation for Fungible and Non Fungible tokens.
	TokenProgramID = MustPublicKeyFromBase58("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")

	// A Uniswap-like exchange for the Token program on the Solana blockchain,
	// implementing multiple automated market maker (AMM) curves.
	TokenSwapProgramID = MustPublicKeyFromBase58("SwaPpA9LAaLfeLi3a68M4DjnLqgtticKg6CnyNwgAC8")
	TokenSwapFeeOwner  = MustPublicKeyFromBase58("HfoTxFR1Tm6kGmWgYWD6J7YHVy1UwqSULUGVLXkJqaKN")

	// A lending protocol for the Token program on the Solana blockchain inspired by Aave and Compound.
	TokenLendingProgramID = 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.
	MemoProgramID = MustPublicKeyFromBase58("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr")
)

SPL:

View Source
var (
	// The Mint for native SOL Token accounts
	SolMint    = MustPublicKeyFromBase58("So11111111111111111111111111111111111111112")
	WrappedSol = SolMint
)
View Source
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")
)

From https://github.com/solana-labs/solana/blob/94ab0eb49f1bce18d0a157dfe7a2bb1fb39dbe2c/docs/src/developing/runtime-facilities/sysvars.md

View Source
var ErrInstructionDecoderNotFound = errors.New("instruction decoder not found")
View Source
var ErrMaxSeedLengthExceeded = errors.New("Max seed length exceeded")
View Source
var (
	TokenMetadataProgramID = MustPublicKeyFromBase58("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s")
)

Functions

func DecimalsInBigInt

func DecimalsInBigInt(decimal uint32) *big.Int

func DecodeInstruction

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

func GetAddedRemovedPubkeys

func GetAddedRemovedPubkeys(previous PublicKeySlice, next PublicKeySlice) (added PublicKeySlice, removed PublicKeySlice)

GetAddedRemovedPubkeys accepts two slices of pubkeys (`previous` and `next`), and returns two slices: - `added` is the slice of pubkeys that are present in `next` but NOT present in `previous`. - `removed` is the slice of pubkeys that are present in `previous` but are NOT present in `next`.

func IsAnyOfEncodingType

func IsAnyOfEncodingType(candidate EncodingType, allowed ...EncodingType) bool

IsAnyOfEncodingType checks whether the provided `candidate` is any of the `allowed`.

func IsOnCurve

func IsOnCurve(b []byte) bool

Check if the provided `b` is on the ed25519 curve.

func RegisterInstructionDecoder

func RegisterInstructionDecoder(programID PublicKey, decoder InstructionDecoder)

Types

type AccountMeta

type AccountMeta struct {
	PublicKey  PublicKey
	IsWritable bool
	IsSigner   bool
}

func Meta

func Meta(
	pubKey PublicKey,
) *AccountMeta

Meta intializes a new AccountMeta with the provided pubKey.

func NewAccountMeta

func NewAccountMeta(
	pubKey PublicKey,
	WRITE bool,
	SIGNER bool,
) *AccountMeta

func (*AccountMeta) SIGNER

func (meta *AccountMeta) SIGNER() *AccountMeta

SIGNER sets IsSigner to true.

func (*AccountMeta) WRITE

func (meta *AccountMeta) WRITE() *AccountMeta

WRITE sets IsWritable to true.

type AccountMetaSlice

type AccountMetaSlice []*AccountMeta

func (*AccountMetaSlice) Append

func (slice *AccountMetaSlice) Append(account *AccountMeta)

func (AccountMetaSlice) Get

func (slice AccountMetaSlice) Get(index int) *AccountMeta

Get returns the AccountMeta at the desired index. If the index is not present, it returns nil.

func (AccountMetaSlice) GetAccounts

func (slice AccountMetaSlice) GetAccounts() []*AccountMeta

func (AccountMetaSlice) GetKeys

func (slice AccountMetaSlice) GetKeys() PublicKeySlice

GetKeys returns the pubkeys of all AccountMeta.

func (AccountMetaSlice) GetSigners

func (slice AccountMetaSlice) GetSigners() []*AccountMeta

GetSigners returns the accounts that are signers.

func (AccountMetaSlice) Len

func (slice AccountMetaSlice) Len() int

func (*AccountMetaSlice) SetAccounts

func (slice *AccountMetaSlice) SetAccounts(accounts []*AccountMeta) error

func (AccountMetaSlice) SplitFrom

func (slice AccountMetaSlice) SplitFrom(index int) (AccountMetaSlice, AccountMetaSlice)

type AccountsGettable

type AccountsGettable interface {
	GetAccounts() (accounts []*AccountMeta)
}

type AccountsSettable

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

type Base58

type Base58 []byte

func (Base58) MarshalJSON

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

func (Base58) String

func (t Base58) String() string

func (*Base58) UnmarshalJSON

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

type ByteWrapper

type ByteWrapper struct {
	io.Reader
}

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"`

	// 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) ([]*AccountMeta, error)

type Data

type Data struct {
	Content  []byte
	Encoding EncodingType
}

func (Data) MarshalJSON

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

func (Data) MarshalWithEncoder

func (obj Data) MarshalWithEncoder(encoder *bin.Encoder) (err error)

func (Data) String

func (t Data) String() string

func (*Data) UnmarshalJSON

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

func (*Data) UnmarshalWithDecoder

func (obj *Data) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)

type DurationMilliseconds

type DurationMilliseconds int64

DurationMilliseconds represents a duration in milliseconds.

func (DurationMilliseconds) Duration

func (res DurationMilliseconds) Duration() time.Duration

func (DurationMilliseconds) String

func (res DurationMilliseconds) String() string

type DurationSeconds

type DurationSeconds int64

DurationSeconds represents a duration in seconds.

func (DurationSeconds) Duration

func (res DurationSeconds) Duration() time.Duration

func (DurationSeconds) String

func (res DurationSeconds) String() string

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 GenericInstruction

type GenericInstruction struct {
	AccountValues AccountMetaSlice
	ProgID        PublicKey
	DataBytes     []byte
}

func NewInstruction

func NewInstruction(
	programID PublicKey,
	accounts AccountMetaSlice,
	data []byte,
) *GenericInstruction

NewInstruction creates a generic instruction with the provided programID, accounts, and data bytes.

func (*GenericInstruction) Accounts

func (in *GenericInstruction) Accounts() []*AccountMeta

func (*GenericInstruction) Data

func (in *GenericInstruction) Data() ([]byte, error)

func (*GenericInstruction) ProgramID

func (in *GenericInstruction) ProgramID() PublicKey

type Hash

type Hash PublicKey

func HashFromBase58

func HashFromBase58(in string) (Hash, error)

HashFromBase58 decodes a base58 string into a Hash.

func HashFromBytes

func HashFromBytes(in []byte) Hash

HashFromBytes decodes a byte slice into a Hash.

func MustHashFromBase58

func MustHashFromBase58(in string) Hash

MustHashFromBase58 decodes a base58 string into a Hash. Panics on error.

func (Hash) Equals

func (ha Hash) Equals(pb Hash) bool

func (Hash) IsZero

func (ha Hash) IsZero() bool

func (Hash) MarshalJSON

func (ha Hash) MarshalJSON() ([]byte, error)

func (Hash) MarshalText

func (ha Hash) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Hash) String

func (ha Hash) String() string

func (*Hash) UnmarshalJSON

func (ha *Hash) UnmarshalJSON(data []byte) (err error)

func (*Hash) UnmarshalText

func (ha *Hash) UnmarshalText(data []byte) (err error)

UnmarshalText implements encoding.TextUnmarshaler.

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"` // static keys; static keys + dynamic keys if after resolution (i.e. call to `ResolveLookups()`)

	// 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"`

	// List of address table lookups used to load additional accounts for this transaction.
	AddressTableLookups MessageAddressTableLookupSlice `json:"addressTableLookups"`
	// contains filtered or unexported fields
}

func (Message) Account

func (m Message) Account(index uint16) (PublicKey, error)

Account returns the account at the given index.

func (Message) AccountMetaList

func (m Message) AccountMetaList() (AccountMetaSlice, error)

func (*Message) AddAddressTableLookup

func (mx *Message) AddAddressTableLookup(lookup MessageAddressTableLookup) *Message

AddAddressTableLookup adds a new lookup to the message.

func (*Message) EncodeToTree

func (mx *Message) EncodeToTree(txTree treeout.Branches)

func (Message) GetAccountIndex

func (m Message) GetAccountIndex(account PublicKey) (uint16, error)

GetAccountIndex returns the index of the given account (first occurrence of the account).

func (Message) GetAddressTableLookupAccounts

func (mx Message) GetAddressTableLookupAccounts() ([]PublicKey, error)

GetAddressTableLookupAccounts associates the lookups with the accounts in the actual address tables, and returns the accounts. NOTE: you need to call `SetAddressTables` before calling this method, so that the lookups can be associated with the accounts in the address tables.

func (*Message) GetAddressTableLookups

func (mx *Message) GetAddressTableLookups() MessageAddressTableLookupSlice

GetAddressTableLookups returns the lookups used by this message.

func (*Message) GetAddressTables

func (mx *Message) GetAddressTables() map[PublicKey]PublicKeySlice

GetAddressTables returns the actual address tables used by this message. NOTE: you must have called `SetAddressTable` before being able to use this method.

func (Message) GetAllKeys

func (mx Message) GetAllKeys() (keys PublicKeySlice, err error)

GetAllKeys returns ALL the message's account keys (including the keys from resolved address lookup tables).

func (*Message) GetVersion

func (m *Message) GetVersion() MessageVersion

GetVersion returns the message version.

func (Message) HasAccount

func (m Message) HasAccount(account PublicKey) (bool, error)

func (Message) IsSigner

func (m Message) IsSigner(account PublicKey) bool

func (Message) IsVersioned

func (m Message) IsVersioned() bool

func (Message) IsWritable

func (m Message) IsWritable(account PublicKey) (bool, error)

func (*Message) MarshalBinary

func (mx *Message) MarshalBinary() ([]byte, error)

func (Message) MarshalJSON

func (mx Message) MarshalJSON() ([]byte, error)

func (*Message) MarshalLegacy

func (mx *Message) MarshalLegacy() ([]byte, error)

func (*Message) MarshalV0

func (mx *Message) MarshalV0() ([]byte, error)

func (Message) MarshalWithEncoder

func (mx Message) MarshalWithEncoder(encoder *bin.Encoder) error

func (Message) NumLookups

func (mx Message) NumLookups() int

func (Message) NumWritableLookups

func (mx Message) NumWritableLookups() int

func (Message) Program

func (m Message) Program(programIDIndex uint16) (PublicKey, error)

Program returns the program key at the given index.

func (*Message) ResolveLookups

func (mx *Message) ResolveLookups() (err error)

ResolveLookups resolves the address table lookups, and appends the resolved accounts to the `message.AccountKeys` field. NOTE: you need to call `SetAddressTables` before calling this method.

func (Message) ResolveProgramIDIndex

func (m Message) ResolveProgramIDIndex(programIDIndex uint16) (PublicKey, error)

ResolveProgramIDIndex resolves the program ID index to a program ID. DEPRECATED: use `Program(index)` instead.

func (*Message) SetAddressTableLookups

func (mx *Message) SetAddressTableLookups(lookups []MessageAddressTableLookup) *Message

SetAddressTableLookups (re)sets the lookups used by this message.

func (*Message) SetAddressTables

func (mx *Message) SetAddressTables(tables map[PublicKey]PublicKeySlice) error

SetAddressTables sets the actual address tables used by this message. Use `mx.GetAddressTableLookups().GetTableIDs()` to get the list of all address table IDs. NOTE: you can call this once.

func (*Message) SetVersion

func (m *Message) SetVersion(version MessageVersion) *Message

SetVersion sets the message version. This method forces the message to be encoded in the specified version. NOTE: if you set lookups, the version will default to V0.

func (Message) Signers

func (m Message) Signers() PublicKeySlice

Signers returns the pubkeys of all accounts that are signers.

func (Message) ToBase64

func (mx Message) ToBase64() string

func (*Message) UnmarshalBase64

func (mx *Message) UnmarshalBase64(b64 string) error

func (*Message) UnmarshalLegacy

func (mx *Message) UnmarshalLegacy(decoder *bin.Decoder) (err error)

func (*Message) UnmarshalV0

func (mx *Message) UnmarshalV0(decoder *bin.Decoder) (err error)

func (*Message) UnmarshalWithDecoder

func (mx *Message) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)

func (Message) Writable

func (m Message) Writable() (out PublicKeySlice, err error)

Writable returns the pubkeys of all accounts that are writable.

type MessageAddressTableLookup

type MessageAddressTableLookup struct {
	AccountKey      PublicKey       `json:"accountKey"` // The account key of the address table.
	WritableIndexes Uint8SliceAsNum `json:"writableIndexes"`
	ReadonlyIndexes Uint8SliceAsNum `json:"readonlyIndexes"`
}

type MessageAddressTableLookupSlice

type MessageAddressTableLookupSlice []MessageAddressTableLookup

func (MessageAddressTableLookupSlice) GetTableIDs

func (lookups MessageAddressTableLookupSlice) GetTableIDs() PublicKeySlice

GetTableIDs returns the list of all address table IDs.

func (MessageAddressTableLookupSlice) NumLookups

func (lookups MessageAddressTableLookupSlice) NumLookups() int

NumLookups returns the number of accounts from all the lookups.

func (MessageAddressTableLookupSlice) NumWritableLookups

func (lookups MessageAddressTableLookupSlice) NumWritableLookups() int

NumWritableLookups returns the number of writable accounts across all the lookups (all the address tables).

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

func (header *MessageHeader) EncodeToTree(mxBranch treeout.Branches)

type MessageVersion

type MessageVersion int
const (
	MessageVersionLegacy MessageVersion = 0 // default
	MessageVersionV0     MessageVersion = 1 // v0
)

type PK

type PK = PublicKey

PK is a convenience alias for PublicKey

type Padding

type Padding []byte

type PrivateKey

type PrivateKey []byte

func MustPrivateKeyFromBase58

func MustPrivateKeyFromBase58(in string) PrivateKey

func NewRandomPrivateKey

func NewRandomPrivateKey() (PrivateKey, error)

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) Sign

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

func (PrivateKey) String

func (k PrivateKey) String() string

type PublicKey

type PublicKey [PublicKeyLength]byte

func FindAssociatedTokenAddress

func FindAssociatedTokenAddress(
	wallet PublicKey,
	mint PublicKey,
) (PublicKey, uint8, error)

func FindProgramAddress

func FindProgramAddress(seed [][]byte, programID PublicKey) (PublicKey, uint8, error)

Find a valid program address and its corresponding bump seed.

func FindTokenMetadataAddress

func FindTokenMetadataAddress(mint PublicKey) (PublicKey, uint8, error)

FindTokenMetadataAddress returns the token metadata program-derived address given a SPL token mint address.

func MPK

func MPK(in string) PublicKey

MPK is a convenience alias for MustPublicKeyFromBase58

func MustPublicKeyFromBase58

func MustPublicKeyFromBase58(in string) PublicKey

func PublicKeyFromBase58

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

func PublicKeyFromBytes

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

func (PublicKey) Bytes

func (p PublicKey) Bytes() []byte

func (PublicKey) Equals

func (p PublicKey) Equals(pb PublicKey) bool

func (PublicKey) IsAnyOf

func (p PublicKey) IsAnyOf(keys ...PublicKey) bool

IsAnyOf checks if p is equals to any of the provided keys.

func (PublicKey) IsOnCurve

func (p PublicKey) IsOnCurve() bool

Check if a `Pubkey` is on the ed25519 curve.

func (PublicKey) IsZero

func (p PublicKey) IsZero() bool

IsZero returns whether the public key is zero. NOTE: the System Program public key is also zero.

func (PublicKey) MarshalBSON

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

MarshalBSON implements the bson.Marshaler interface.

func (PublicKey) MarshalBSONValue

func (p PublicKey) MarshalBSONValue() (bsontype.Type, []byte, error)

MarshalBSONValue implements the bson.ValueMarshaler interface.

func (PublicKey) MarshalJSON

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

func (PublicKey) MarshalText

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

func (*PublicKey) Set

func (p *PublicKey) Set(s string) (err error)

func (PublicKey) Short

func (p PublicKey) Short(n int) string

Short returns a shortened pubkey string, only including the first n chars, ellipsis, and the last n characters. NOTE: this is ONLY for visual representation for humans, and cannot be used for anything else.

func (PublicKey) String

func (p PublicKey) String() string

func (PublicKey) ToPointer

func (p PublicKey) ToPointer() *PublicKey

ToPointer returns a pointer to the pubkey.

func (*PublicKey) UnmarshalBSON

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

UnmarshalBSON implements the bson.Unmarshaler interface.

func (*PublicKey) UnmarshalBSONValue

func (p *PublicKey) UnmarshalBSONValue(t bsontype.Type, data []byte) (err error)

UnmarshalBSONValue implements the bson.ValueUnmarshaler interface.

func (*PublicKey) UnmarshalJSON

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

func (*PublicKey) UnmarshalText

func (p *PublicKey) UnmarshalText(data []byte) error

func (PublicKey) Verify

func (p PublicKey) Verify(message []byte, signature Signature) bool

type PublicKeySlice

type PublicKeySlice []PublicKey

func (PublicKeySlice) Added

Added returns the elements that are present in `b` but not in `a`.

func (*PublicKeySlice) Append

func (slice *PublicKeySlice) Append(pubkeys ...PublicKey)

func (PublicKeySlice) Contains

func (slice PublicKeySlice) Contains(pubkey PublicKey) bool

Contains returns true if the slice contains the provided pubkey.

func (PublicKeySlice) ContainsAll

func (slice PublicKeySlice) ContainsAll(pubkeys PublicKeySlice) bool

ContainsAll returns true if all the provided pubkeys are present in the slice.

func (PublicKeySlice) ContainsAny

func (slice PublicKeySlice) ContainsAny(pubkeys PublicKeySlice) bool

ContainsAny returns true if any of the provided pubkeys are present in the slice.

func (PublicKeySlice) Dedupe

func (slice PublicKeySlice) Dedupe() PublicKeySlice

Dedupe returns a new slice with all duplicate pubkeys removed.

func (PublicKeySlice) Equals

func (slice PublicKeySlice) Equals(other PublicKeySlice) bool

Equals returns true if the two PublicKeySlices are equal (same order of same keys).

func (PublicKeySlice) First

func (slice PublicKeySlice) First() *PublicKey

First returns the first element of the slice. Returns nil if the slice is empty.

func (PublicKeySlice) GetAddedRemoved

func (prev PublicKeySlice) GetAddedRemoved(next PublicKeySlice) (added PublicKeySlice, removed PublicKeySlice)

GetAddedRemoved compares to the `next` pubkey slice, and returns two slices: - `added` is the slice of pubkeys that are present in `next` but NOT present in `previous`. - `removed` is the slice of pubkeys that are present in `previous` but are NOT present in `next`.

func (PublicKeySlice) Has

func (slice PublicKeySlice) Has(pubkey PublicKey) bool

func (PublicKeySlice) Intersect

func (prev PublicKeySlice) Intersect(next PublicKeySlice) PublicKeySlice

Intersect returns the intersection of two PublicKeySlices, i.e. the elements that are in both PublicKeySlices. The returned PublicKeySlice is sorted and deduped.

func (PublicKeySlice) Last

func (slice PublicKeySlice) Last() *PublicKey

Last returns the last element of the slice. Returns nil if the slice is empty.

func (PublicKeySlice) Len

func (slice PublicKeySlice) Len() int

func (PublicKeySlice) Less

func (slice PublicKeySlice) Less(i, j int) bool

func (PublicKeySlice) Removed

Removed returns the elements that are present in `a` but not in `b`.

func (PublicKeySlice) Same

func (slice PublicKeySlice) Same(other PublicKeySlice) bool

Same returns true if the two slices contain the same public keys, but not necessarily in the same order.

func (PublicKeySlice) Sort

func (slice PublicKeySlice) Sort()

Sort sorts the slice.

func (PublicKeySlice) Split

func (slice PublicKeySlice) Split(chunkSize int) []PublicKeySlice

Split splits the slice into chunks of the specified size.

func (PublicKeySlice) Swap

func (slice PublicKeySlice) Swap(i, j int)

func (PublicKeySlice) ToBase58

func (slice PublicKeySlice) ToBase58() []string

func (PublicKeySlice) ToBytes

func (slice PublicKeySlice) ToBytes() [][]byte

func (PublicKeySlice) ToPointers

func (slice PublicKeySlice) ToPointers() []*PublicKey

func (*PublicKeySlice) UniqueAppend

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 MustSignatureFromBase58(in string) Signature

MustSignatureFromBase58 decodes a base58 string into a Signature. Panics on error.

func SignatureFromBase58

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

SignatureFromBase58 decodes a base58 string into a Signature.

func SignatureFromBytes

func SignatureFromBytes(in []byte) (out Signature)

SignatureFromBytes decodes a byte slice into a Signature.

func (Signature) Equals

func (sig Signature) Equals(pb Signature) bool

func (Signature) IsZero

func (sig Signature) IsZero() bool

func (Signature) MarshalJSON

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

func (Signature) MarshalText

func (p Signature) MarshalText() ([]byte, error)

func (Signature) String

func (p Signature) String() string

func (*Signature) UnmarshalJSON

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

func (*Signature) UnmarshalText

func (p *Signature) UnmarshalText(data []byte) (err error)

func (Signature) Verify

func (s Signature) Verify(pubkey PublicKey, msg []byte) bool

Verify checks that the signature is valid for the given public key and message.

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 MustTransactionFromDecoder

func MustTransactionFromDecoder(decoder *bin.Decoder) *Transaction

MustTransactionFromDecoder decodes a transaction from a decoder. Panics on error.

func NewTransaction

func NewTransaction(instructions []Instruction, recentBlockHash Hash, opts ...TransactionOption) (*Transaction, error)

func TransactionFromBase58

func TransactionFromBase58(b58 string) (*Transaction, error)

func TransactionFromBase64

func TransactionFromBase64(b64 string) (*Transaction, error)

func TransactionFromBytes

func TransactionFromBytes(data []byte) (*Transaction, error)

func TransactionFromDecoder

func TransactionFromDecoder(decoder *bin.Decoder) (*Transaction, error)

TransactionFromDecoder decodes a transaction from a decoder.

func (*Transaction) AccountMetaList

func (t *Transaction) AccountMetaList() ([]*AccountMeta, error)

func (*Transaction) EncodeToTree

func (tx *Transaction) EncodeToTree(parent treeout.Branches)

func (*Transaction) EncodeTree

func (tx *Transaction) EncodeTree(encoder *text.TreeEncoder) (int, error)

func (*Transaction) GetAccountIndex

func (t *Transaction) GetAccountIndex(account PublicKey) (uint16, error)

func (*Transaction) HasAccount

func (t *Transaction) HasAccount(account PublicKey) (bool, error)

func (*Transaction) IsSigner

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

func (*Transaction) IsWritable

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

func (*Transaction) MarshalBinary

func (tx *Transaction) MarshalBinary() ([]byte, error)

func (Transaction) MarshalWithEncoder

func (tx Transaction) MarshalWithEncoder(encoder *bin.Encoder) error

func (Transaction) MustToBase64

func (tx Transaction) MustToBase64() string

func (*Transaction) NumReadonlyAccounts

func (tx *Transaction) NumReadonlyAccounts() int

func (*Transaction) NumSigners

func (tx *Transaction) NumSigners() int

func (*Transaction) NumWriteableAccounts

func (tx *Transaction) NumWriteableAccounts() int

func (*Transaction) PartialSign

func (tx *Transaction) PartialSign(getter privateKeyGetter) (out []Signature, err 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) String

func (tx *Transaction) String() string

String returns a human-readable string representation of the transaction data. To disable colors, set "github.com/MintyFinance/solana-go-custom/text".DisableColors = true

func (Transaction) ToBase64

func (tx Transaction) ToBase64() (string, error)

func (*Transaction) UnmarshalBase64

func (tx *Transaction) UnmarshalBase64(b64 string) error

UnmarshalBase64 decodes a base64 encoded transaction.

func (*Transaction) UnmarshalWithDecoder

func (tx *Transaction) UnmarshalWithDecoder(decoder *bin.Decoder) (err error)

func (*Transaction) VerifySignatures

func (tx *Transaction) VerifySignatures() error

VerifySignatures verifies all the signatures in the transaction against the pubkeys of the signers.

type TransactionBuilder

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

func NewTransactionBuilder

func NewTransactionBuilder() *TransactionBuilder

NewTransactionBuilder creates a new instruction builder.

func (*TransactionBuilder) AddInstruction

func (builder *TransactionBuilder) AddInstruction(instruction Instruction) *TransactionBuilder

AddInstruction adds the provided instruction to the builder.

func (*TransactionBuilder) Build

func (builder *TransactionBuilder) Build() (*Transaction, error)

Build builds and returns a *Transaction.

func (*TransactionBuilder) SetFeePayer

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

func (builder *TransactionBuilder) SetRecentBlockHash(recentBlockHash Hash) *TransactionBuilder

SetRecentBlockHash sets the recent blockhash for the instruction builder.

func (*TransactionBuilder) WithOpt

WithOpt adds a TransactionOption.

type TransactionOption

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

func TransactionAddressTables

func TransactionAddressTables(tables map[PublicKey]PublicKeySlice) TransactionOption

func TransactionPayer

func TransactionPayer(payer PublicKey) TransactionOption

type Uint8SliceAsNum

type Uint8SliceAsNum []uint8

Uint8SliceAsNum is a slice of uint8s that can be marshaled as numbers instead of a byte slice.

func (Uint8SliceAsNum) MarshalJSON

func (slice Uint8SliceAsNum) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

type UnixTimeMilliseconds

type UnixTimeMilliseconds int64

UnixTimeMilliseconds represents a UNIX millisecond-resolution timestamp.

func (UnixTimeMilliseconds) String

func (res UnixTimeMilliseconds) String() string

func (UnixTimeMilliseconds) Time

func (res UnixTimeMilliseconds) Time() time.Time

type UnixTimeSeconds

type UnixTimeSeconds int64

UnixTimeSeconds represents a UNIX second-resolution timestamp.

func (UnixTimeSeconds) String

func (res UnixTimeSeconds) String() string

func (UnixTimeSeconds) Time

func (res UnixTimeSeconds) Time() time.Time

type Wallet

type Wallet struct {
	PrivateKey PrivateKey
}

Wallet is a wrapper around a PrivateKey

func NewWallet

func NewWallet() *Wallet

func WalletFromPrivateKeyBase58

func WalletFromPrivateKeyBase58(privateKey string) (*Wallet, error)

func (*Wallet) PublicKey

func (a *Wallet) PublicKey() PublicKey

Directories

Path Synopsis
cmd
programs
serum
Code generated by rice embed-go; DO NOT EDIT.
Code generated by rice embed-go; DO NOT EDIT.
rpc
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.
ws

Jump to

Keyboard shortcuts

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