solana

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NilIdlTypeDefTy = IdlTypeDef{Type: IdlTypeDefTy{
	Kind:   "struct",
	Fields: &IdlTypeDefStruct{},
}}

Functions

This section is empty.

Types

type ATALookup

type ATALookup struct {
	// Field that determines whether the ATA lookup is necessary. Basically
	// just need to check this field exists. Dot separated location.
	Location string
	// If the field exists, initialize a ATA account using the Wallet, Token Program, and Mint addresses below
	WalletAddress Lookup
	TokenProgram  Lookup // Deprecated: The token program is now fetched from the mint account
	MintAddress   Lookup
	Optional      bool
}

type AccountConstant

type AccountConstant struct {
	Name       string `json:"name,omitempty"`
	Address    string `json:"address"`
	IsSigner   bool   `json:"isSigner,omitempty"`
	IsWritable bool   `json:"isWritable,omitempty"`
}

AccountConstant represents a fixed address, provided in Base58 format, converted into a `solana.PublicKey`.

type AccountLookup

type AccountLookup struct {
	Name     string `json:"name,omitempty"`
	Location string `json:"location"`
	// IsSigner and IsWritable can either be a constant bool or a location to a bitmap which decides the bools
	IsSigner   MetaBool `json:"isSigner,omitempty"`
	IsWritable MetaBool `json:"isWritable,omitempty"`
}

AccountLookup dynamically derives an account address from args using a specified location path.

type AccountsFromLookupTable

type AccountsFromLookupTable struct {
	LookupTableName string `json:"lookupTableName"`
	IncludeIndexes  []int  `json:"includeIndexes"`
}

AccountsFromLookupTable extracts accounts from a lookup table that was previously read and stored in memory.

type ChainContractReader

type ChainContractReader struct {
	IDL            `json:"anchorIDL"`
	*PollingFilter `json:"pollingFilter,omitempty"`
	// Reads key is the off-chain name for this read.
	Reads map[string]ReadDefinition `json:"reads"`
}

func (*ChainContractReader) UnmarshalJSON

func (c *ChainContractReader) UnmarshalJSON(bytes []byte) error

type ContractReader

type ContractReader struct {
	Namespaces map[string]ChainContractReader `json:"namespaces"`
	// AddressShareGroups lists namespaces groups that share the same address.
	// Whichever namespace or i.e. Binding from the list is Bound first will share that address with the rest of the group.
	// Namespaces that were bound after the first one still have to be Bound to be initialised.
	// If they are Bound with an empty address string, they will use the address of the first Bound contract.
	// If they are Bound with a non-empty address string, an error will be thrown unless the address matches the address of the first Bound shared contract.
	AddressShareGroups [][]string `json:"addressShareGroups,omitempty"`
}

func (*ContractReader) UnmarshalJSON

func (c *ContractReader) UnmarshalJSON(bytes []byte) error

type ContractWriterConfig

type ContractWriterConfig struct {
	Programs map[string]ProgramConfig `json:"programs"`
}

nolint // ignoring naming suggestion

type DerivedLookupTable

type DerivedLookupTable struct {
	Name     string `json:"name,omitempty"`
	Accounts Lookup `json:"accounts"`
	Optional bool   `json:"optional"`
}

DerivedLookupTable represents a lookup table that is used to derive addresses for a program.

type EventDefinitions

type EventDefinitions struct {
	IndexedField0 *IndexedField `json:"indexedField0"`
	IndexedField1 *IndexedField `json:"indexedField1"`
	IndexedField2 *IndexedField `json:"indexedField2"`
	IndexedField3 *IndexedField `json:"indexedField3"`
	// PollingFilter should be defined on a contract level in ContractPollingFilter, unless event needs to override the
	// contract level filter options.
	*PollingFilter `json:"pollingFilter,omitempty"`
}

type IDL

type IDL struct {
	Version      string           `json:"version"`
	Name         string           `json:"name"`
	Instructions []IdlInstruction `json:"instructions"`
	Accounts     IdlTypeDefSlice  `json:"accounts,omitempty"`
	Types        IdlTypeDefSlice  `json:"types,omitempty"`
	Events       []IdlEvent       `json:"events,omitempty"`
	Errors       []IdlErrorCode   `json:"errors,omitempty"`
	Constants    []IdlConstant    `json:"constants,omitempty"`
}

https://github.com/project-serum/anchor/blob/97e9e03fb041b8b888a9876a7c0676d9bb4736f3/ts/src/idl.ts

type IdlAccount

type IdlAccount struct {
	Docs     []string `json:"docs"` // @custom
	Name     string   `json:"name"`
	IsMut    bool     `json:"isMut"`
	IsSigner bool     `json:"isSigner"`
	Optional bool     `json:"optional"` // @custom
}

type IdlAccountItem

type IdlAccountItem struct {
	IdlAccount  *IdlAccount
	IdlAccounts *IdlAccounts
}

type IdlAccountItem = IdlAccount | IdlAccounts;

func (IdlAccountItem) MarshalJSON

func (env IdlAccountItem) MarshalJSON() ([]byte, error)

func (*IdlAccountItem) UnmarshalJSON

func (env *IdlAccountItem) UnmarshalJSON(data []byte) error

type IdlAccountItemSlice

type IdlAccountItemSlice []IdlAccountItem

func (IdlAccountItemSlice) NumAccounts

func (slice IdlAccountItemSlice) NumAccounts() (count int)

type IdlAccounts

type IdlAccounts struct {
	Name     string              `json:"name"`
	Docs     []string            `json:"docs"` // @custom
	Accounts IdlAccountItemSlice `json:"accounts"`
}

A nested/recursive version of IdlAccount.

type IdlConstant

type IdlConstant struct {
	Name  string
	Type  IdlType
	Value string
}

type IdlEnumFields

type IdlEnumFields struct {
	IdlEnumFieldsNamed *IdlEnumFieldsNamed
	IdlEnumFieldsTuple *IdlEnumFieldsTuple
}

type IdlEnumFields = IdlEnumFieldsNamed | IdlEnumFieldsTuple;

func (*IdlEnumFields) UnmarshalJSON

func (env *IdlEnumFields) UnmarshalJSON(data []byte) error

TODO: verify with examples

type IdlEnumFieldsNamed

type IdlEnumFieldsNamed []IdlField

type IdlEnumFieldsTuple

type IdlEnumFieldsTuple []IdlType

type IdlEnumVariant

type IdlEnumVariant struct {
	Name   string         `json:"name"`
	Docs   []string       `json:"docs"` // @custom
	Fields *IdlEnumFields `json:"fields,omitempty"`
}

func (*IdlEnumVariant) IsUint8

func (variant *IdlEnumVariant) IsUint8() bool

type IdlEnumVariantSlice

type IdlEnumVariantSlice []IdlEnumVariant

func (IdlEnumVariantSlice) IsAllUint8

func (slice IdlEnumVariantSlice) IsAllUint8() bool

func (IdlEnumVariantSlice) IsSimpleEnum

func (slice IdlEnumVariantSlice) IsSimpleEnum() bool

type IdlErrorCode

type IdlErrorCode struct {
	Code int    `json:"code"`
	Name string `json:"name"`
	Msg  string `json:"msg,omitempty"`
}

type IdlEvent

type IdlEvent struct {
	Name   string          `json:"name"`
	Fields []IdlEventField `json:"fields"`
}

type IdlEventField

type IdlEventField struct {
	Name  string  `json:"name"`
	Type  IdlType `json:"type"`
	Index bool    `json:"index"`
}

type IdlField

type IdlField struct {
	Name string   `json:"name"`
	Docs []string `json:"docs"` // @custom
	Type IdlType  `json:"type"`
}

type IdlInstruction

type IdlInstruction struct {
	Name     string              `json:"name"`
	Docs     []string            `json:"docs"` // @custom
	Accounts IdlAccountItemSlice `json:"accounts"`
	Args     []IdlField          `json:"args"`
}

type IdlType

type IdlType struct {
	AsString     IdlTypeAsString
	AsIdlTypeVec *IdlTypeVec

	AsIdlTypeDefined *IdlTypeDefined
	AsIdlTypeArray   *IdlTypeArray
	// contains filtered or unexported fields
}

Wrapper type:

func NewIdlStringType

func NewIdlStringType(asString IdlTypeAsString) IdlType

func (*IdlType) GetArray

func (env *IdlType) GetArray() *IdlTypeArray

func (*IdlType) GetIdlTypeDefined

func (env *IdlType) GetIdlTypeDefined() *IdlTypeDefined

func (*IdlType) GetIdlTypeOption

func (env *IdlType) GetIdlTypeOption() *IdlTypeOption

func (*IdlType) GetIdlTypeVec

func (env *IdlType) GetIdlTypeVec() *IdlTypeVec

func (*IdlType) GetString

func (env *IdlType) GetString() IdlTypeAsString

Getters:

func (*IdlType) IsArray

func (env *IdlType) IsArray() bool

func (*IdlType) IsIdlTypeDefined

func (env *IdlType) IsIdlTypeDefined() bool

func (*IdlType) IsIdlTypeOption

func (env *IdlType) IsIdlTypeOption() bool

func (*IdlType) IsIdlTypeVec

func (env *IdlType) IsIdlTypeVec() bool

func (*IdlType) IsString

func (env *IdlType) IsString() bool

func (IdlType) MarshalJSON

func (env IdlType) MarshalJSON() ([]byte, error)

func (*IdlType) UnmarshalJSON

func (env *IdlType) UnmarshalJSON(data []byte) error

type IdlTypeArray

type IdlTypeArray struct {
	Thing IdlType
	Num   int
}

Wrapper type:

type IdlTypeAsString

type IdlTypeAsString string
const (
	IdlTypeBool      IdlTypeAsString = "bool"
	IdlTypeU8        IdlTypeAsString = "u8"
	IdlTypeI8        IdlTypeAsString = "i8"
	IdlTypeU16       IdlTypeAsString = "u16"
	IdlTypeI16       IdlTypeAsString = "i16"
	IdlTypeU32       IdlTypeAsString = "u32"
	IdlTypeI32       IdlTypeAsString = "i32"
	IdlTypeU64       IdlTypeAsString = "u64"
	IdlTypeI64       IdlTypeAsString = "i64"
	IdlTypeU128      IdlTypeAsString = "u128"
	IdlTypeI128      IdlTypeAsString = "i128"
	IdlTypeBytes     IdlTypeAsString = "bytes"
	IdlTypeString    IdlTypeAsString = "string"
	IdlTypePublicKey IdlTypeAsString = "publicKey"

	// Custom additions:
	IdlTypeUnixTimestamp IdlTypeAsString = "unixTimestamp"
	IdlTypeHash          IdlTypeAsString = "hash"
	IdlTypeDuration      IdlTypeAsString = "duration"
)

type IdlTypeDef

type IdlTypeDef struct {
	Name string       `json:"name"`
	Type IdlTypeDefTy `json:"type"`
}

type IdlTypeDefSlice

type IdlTypeDefSlice []IdlTypeDef

func (IdlTypeDefSlice) GetByName

func (named IdlTypeDefSlice) GetByName(name string) *IdlTypeDef

type IdlTypeDefStruct

type IdlTypeDefStruct = []IdlField

type IdlTypeDefTy

type IdlTypeDefTy struct {
	Kind IdlTypeDefTyKind `json:"kind"`

	Fields   *IdlTypeDefStruct   `json:"fields,omitempty"`
	Variants IdlEnumVariantSlice `json:"variants,omitempty"`
	Codec    string              `json:"codec,omitempty"`
}

type IdlTypeDefTyEnum

type IdlTypeDefTyEnum struct {
	Kind IdlTypeDefTyKind `json:"kind"` // == "enum"

	Variants IdlEnumVariantSlice `json:"variants,omitempty"`
}

type IdlTypeDefTyKind

type IdlTypeDefTyKind string
const (
	IdlTypeDefTyKindStruct IdlTypeDefTyKind = "struct"
	IdlTypeDefTyKindEnum   IdlTypeDefTyKind = "enum"
	IdlTypeDefTyKindCustom IdlTypeDefTyKind = "custom"
)

type IdlTypeDefTyStruct

type IdlTypeDefTyStruct struct {
	Kind IdlTypeDefTyKind `json:"kind"` // == "struct"

	Fields *IdlTypeDefStruct `json:"fields,omitempty"`
}

type IdlTypeDefined

type IdlTypeDefined struct {
	Defined string `json:"defined"`
}

User defined type.

type IdlTypeOption

type IdlTypeOption struct {
	Option IdlType `json:"option"`
}

type IdlTypeVec

type IdlTypeVec struct {
	Vec IdlType `json:"vec"`
}

type IndexedField

type IndexedField struct {
	OffChainPath string `json:"offChainPath"`
	OnChainPath  string `json:"onChainPath"`
}

type InternalField

type InternalField struct {
	// must map directly to IDL type
	TypeName string `json:"typeName"`
	Location string `json:"location"`
	IDL      string `json:"idl"`
}

type Lookup

type Lookup struct {
	Optional                bool
	AccountConstant         *AccountConstant         `json:"accountConstant,omitempty"`
	AccountLookup           *AccountLookup           `json:"accountLookup,omitempty"`
	PDALookups              *PDALookups              `json:"pdas,omitempty"`
	AccountsFromLookupTable *AccountsFromLookupTable `json:"accountsFromLookupTable,omitempty"`
}

func (Lookup) IsNil

func (l Lookup) IsNil() bool

type LookupTables

type LookupTables struct {
	DerivedLookupTables []DerivedLookupTable `json:"derivedLookupTables,omitempty"`
	StaticLookupTables  [][32]byte           `json:"staticLookupTables,omitempty"` // solana.PublicKey
}

LookupTables represents a list of lookup tables that are used to derive addresses for a program.

type MetaBool

type MetaBool struct {
	Value          bool   `json:"value,omitempty"`          // bool value
	BitmapLocation string `json:"bitmapLocation,omitempty"` // dot separated location of the bitmap
}

type MethodConfig

type MethodConfig struct {
	FromAddress        string                `json:"fromAddress"`
	InputModifications codec.ModifiersConfig `json:"inputModifications,omitempty"`
	ChainSpecificName  string                `json:"chainSpecificName"`
	LookupTables       LookupTables          `json:"lookupTables,omitempty"`
	Accounts           []Lookup              `json:"accounts"`
	ATAs               []ATALookup           `json:"atas,omitempty"`
	// Location in the args where the debug ID is stored
	DebugIDLocation string `json:"debugIDLocation,omitempty"`
	ArgsTransform   string `json:"argsTransform,omitempty"`
	// Overhead added to calculated compute units in the args transform
	ComputeUnitLimitOverhead uint32 `json:"ComputeUnitLimitOverhead,omitempty"`
	// Configs for buffering payloads to support larger transaction sizes for this method
	BufferPayloadMethod string `json:"bufferPayloadMethod,omitempty"`
}

type MultiReader

type MultiReader struct {
	// Reads is a list of reads that is sequentially read to fill out a complete response for the parent read.
	// Parent ReadDefinition has to define codec modifiers which adds fields that are to be filled out by the reads in Reads.
	Reads []ReadDefinition `json:"reads,omitempty"`
	// ReuseParams If true, params from parent read will be reused for all MultiReader Reads.
	ReuseParams bool `json:"reuseParams"`
}

type PDALookups

type PDALookups struct {
	Name string `json:"name,omitempty"`
	// The public key of the PDA to be combined with seeds. If there are multiple PublicKeys
	// there will be multiple PDAs generated by combining each PublicKey with the seeds.
	PublicKey Lookup `json:"publicKey"`
	// Seeds to be derived from an additional lookup
	Seeds      []Seed `json:"seeds"`
	IsSigner   bool   `json:"isSigner,omitempty"`
	IsWritable bool   `json:"isWritable,omitempty"`
	// OPTIONAL: On-chain location and type of desired data from PDA (e.g. a sub-account of the data account)
	InternalField InternalField `json:"internalField,omitempty"`
}

PDALookups generates Program Derived Addresses (PDA) by combining a derived public key with one or more seeds.

type PDASeed

type PDASeed struct {
	Name string  `json:"name"`
	Type IdlType `json:"type"`
}

type PDATypeDef

type PDATypeDef struct {
	Prefix []byte    `json:"prefix,omitempty"`
	Seeds  []PDASeed `json:"seeds,omitempty"`
}

PDA is a struct that does not correlate to an official IDL type It is needed to encode seeds to calculate the address for PDA account reads

type PollingFilter

type PollingFilter struct {
	Retention       *time.Duration `json:"retention,omitempty"`     // maximum amount of time to retain logs
	MaxLogsKept     *int64         `json:"maxLogsKept,omitempty"`   // maximum number of logs to retain ( 0 = unlimited )
	StartingBlock   *int64         `json:"startingBlock,omitempty"` // which block to start looking for logs
	IncludeReverted *bool          `json:"includeReverted"`         // whether to include logs emitted by transactions which failed while executing on chain
}

type ProgramConfig

type ProgramConfig struct {
	Methods map[string]MethodConfig `json:"methods"`
	IDL     string                  `json:"idl"`
}

type ReadDefinition

type ReadDefinition struct {
	ChainSpecificName       string                `json:"chainSpecificName"`
	ReadType                ReadType              `json:"readType,omitempty"`
	ErrOnMissingAccountData bool                  `json:"errOnMissingAccountData,omitempty"`
	InputModifications      codec.ModifiersConfig `json:"inputModifications,omitempty"`
	OutputModifications     codec.ModifiersConfig `json:"outputModifications,omitempty"`
	PDADefinition           PDATypeDef            `json:"pdaDefinition,omitempty"` // Only used for PDA account reads
	MultiReader             *MultiReader          `json:"multiReader,omitempty"`
	EventDefinitions        *EventDefinitions     `json:"eventDefinitions,omitempty"`
	// ResponseAddressHardCoder hardcodes the address of the contract into the defined field in the response.
	ResponseAddressHardCoder *codec.HardCodeModifierConfig `json:"responseAddressHardCoder,omitempty"`
}

func (ReadDefinition) HasPollingFilter

func (d ReadDefinition) HasPollingFilter() bool

type ReadType

type ReadType int
const (
	Account ReadType = iota
	Event
)

func (ReadType) String

func (r ReadType) String() string

type Seed

type Seed struct {
	Static  []byte `json:"static,omitempty"`  // Static seed value
	Dynamic Lookup `json:"dynamic,omitempty"` // Dynamic lookup for seed
}

Jump to

Keyboard shortcuts

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