Documentation ¶
Index ¶
- Variables
- type AccountInfo
- type AccountInfoEncodedData
- func (e AccountInfoEncodedData) GetData() string
- func (e AccountInfoEncodedData) GetEncoding() Encoding
- func (e AccountInfoEncodedData) GetExecutable() bool
- func (e AccountInfoEncodedData) GetLamports() uint64
- func (e AccountInfoEncodedData) GetOwner() string
- func (e AccountInfoEncodedData) GetRentEpoch() uint64
- type AccountInfoJSONData
- type CommitmentLevel
- type Connection
- type Context
- type Encoding
- type FeeCalculator
- type GetAccountInfoRequest
- type GetAccountInfoResponse
- type GetBalanceRequest
- type GetBalanceResponse
- type GetRecentBlockHashRequest
- type GetRecentBlockHashResponse
- type Instruction
- type InstructionAccountMeta
- type Instructions
- type JSONRPCConnection
- func (j *JSONRPCConnection) Commitment() CommitmentLevel
- func (j *JSONRPCConnection) GetAccountInfo(ctx context.Context, request GetAccountInfoRequest) (*GetAccountInfoResponse, error)
- func (j *JSONRPCConnection) GetBalance(ctx context.Context, request GetBalanceRequest) (*GetBalanceResponse, error)
- func (j *JSONRPCConnection) GetRecentBlockHash(ctx context.Context, request GetRecentBlockHashRequest) (*GetRecentBlockHashResponse, error)
- func (j *JSONRPCConnection) Network() Network
- func (j *JSONRPCConnection) SendTransaction(ctx context.Context, request SendTransactionRequest) (*SendTransactionResponse, error)
- type JSONRPCConnectionOption
- type KeyPair
- type Network
- type PrivateKey
- type PublicKey
- type SendTransactionRequest
- type SendTransactionResponse
- type Signature
- type Signatures
- type Transaction
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnexpectedNetwork = errors.New("unexpected network") ErrTransactionAlreadySigned = errors.New("transaction already signed") )
Functions ¶
This section is empty.
Types ¶
type AccountInfo ¶
type AccountInfo interface { // GetExecutable returns true if this account's Data contains a loaded program GetExecutable() bool // GetLamports returns the number of lamports assigned to this account GetLamports() uint64 // GetOwner returns a base58 encoded Pubkey of the program that owns this account GetOwner() string // GetRentEpoch returns the epoch at which this account will next owe rent GetRentEpoch() uint64 }
AccountInfo is information describing an account
type AccountInfoEncodedData ¶
type AccountInfoEncodedData struct { // Executable is true if this account's Data contains a loaded program Executable bool `json:"executable"` // Lamports is the number of lamports assigned to this account Lamports uint64 `json:"lamports"` // Data is optional data assigned to the account Data []string `json:"data"` // Owner is a base-58 encoded Pubkey of the program that owns this account Owner string `json:"owner"` // RentEpoch is the epoch at which this account will next owe rent RentEpoch uint64 `json:"rentEpoch"` }
AccountInfoEncodedData is information describing an account with data field encoded according to a prescribed Encoding
func (AccountInfoEncodedData) GetData ¶
func (e AccountInfoEncodedData) GetData() string
func (AccountInfoEncodedData) GetEncoding ¶
func (e AccountInfoEncodedData) GetEncoding() Encoding
func (AccountInfoEncodedData) GetExecutable ¶
func (e AccountInfoEncodedData) GetExecutable() bool
func (AccountInfoEncodedData) GetLamports ¶
func (e AccountInfoEncodedData) GetLamports() uint64
func (AccountInfoEncodedData) GetOwner ¶
func (e AccountInfoEncodedData) GetOwner() string
func (AccountInfoEncodedData) GetRentEpoch ¶
func (e AccountInfoEncodedData) GetRentEpoch() uint64
type AccountInfoJSONData ¶
type AccountInfoJSONData struct { // Executable is true if this account's Data contains a loaded program Executable bool `json:"executable"` // Lamports is the number of lamports assigned to this account Lamports uint64 `json:"lamports"` // Data is optional data assigned to the account Data map[string]json.RawMessage `json:"data"` // Owner is a base58 encoded Pubkey of the program that owns this account Owner string `json:"owner"` // RentEpoch is the epoch at which this account will next owe rent RentEpoch uint64 `json:"rentEpoch"` }
AccountInfoJSONData is information describing an account with data field encoded accorded to a prescribed JSONParsedEncoding
func (AccountInfoJSONData) GetExecutable ¶
func (a AccountInfoJSONData) GetExecutable() bool
func (AccountInfoJSONData) GetLamports ¶
func (a AccountInfoJSONData) GetLamports() uint64
func (AccountInfoJSONData) GetOwner ¶
func (a AccountInfoJSONData) GetOwner() string
func (AccountInfoJSONData) GetRentEpoch ¶
func (a AccountInfoJSONData) GetRentEpoch() uint64
type CommitmentLevel ¶
type CommitmentLevel string
CommitmentLevel is the level of commitment desired when querying state
var ( // ProcessedCommitmentLevel indicates to query the most recent // block which has reached 1 confirmation by the connected node ProcessedCommitmentLevel CommitmentLevel = "processed" // ConfirmedCommitmentLevel indicates to query the most recent // block which has reached 1 confirmation by the cluster ConfirmedCommitmentLevel CommitmentLevel = "confirmed" // FinalizedCommitmentLevel indicates to query the most recent // block which has been finalized by the cluster FinalizedCommitmentLevel CommitmentLevel = "finalized" RecentCommitmentLevel CommitmentLevel = "recent" // Deprecated as of v1.5.5 SingleCommitmentLevel CommitmentLevel = "single" // Deprecated as of v1.5.5 SingleGossipCommitmentLevel CommitmentLevel = "singleGossip" // Deprecated as of v1.5.5 RootCommitmentLevel CommitmentLevel = "root" // Deprecated as of v1.5.5 MaxCommitmentLevel CommitmentLevel = "max" // Deprecated as of v1.5.5 )
type Connection ¶
type Connection interface { // Network returns the network with which the connection has been configured to communicate Network() Network // Commitment returns the default commitmentLevel used for requests Commitment() CommitmentLevel // GetAccountInfo returns all the account info for the specified PublicKey GetAccountInfo(ctx context.Context, request GetAccountInfoRequest) (*GetAccountInfoResponse, error) // GetBalance returns the balance of the account of provided PublicKey GetBalance(ctx context.Context, request GetBalanceRequest) (*GetBalanceResponse, error) // GetRecentBlockHash returns a recent block hash from the ledger, and a FeeCalculator that // can be used to calculate the cost of submitting a Transaction. GetRecentBlockHash(ctx context.Context, request GetRecentBlockHashRequest) (*GetRecentBlockHashResponse, error) // SendTransaction submits a signed transaction to the cluster for processing. // This method does not alter the transaction in any way, it relays the // transaction created by clients to the node as-is. SendTransaction(ctx context.Context, request SendTransactionRequest) (*SendTransactionResponse, error) }
Connection represents a connection to a fullnode JSON RPC endpoint
type Context ¶
type Context struct {
Slot uint64 `json:"slot"`
}
Context is extra contextual information for RPC responses
type Encoding ¶
type Encoding string
Encoding specifies encoding for Data in Solana
var ( // Base58Encoding encodes the AccountInfo.Data field in base58 (is slower!) // With this encoding set account data must be < 129 bytes. Base58Encoding Encoding = "base58" // Base64Encoding encodes the AccountInfo.Data field in base64. // No restriction on account data size. Base64Encoding Encoding = "base64" // Base64PlusZSTDEncoding compresses the AccountInfo.Data using // Zstandard and base64 encodes the result. Base64PlusZSTDEncoding Encoding = "base64+zstd" // JSONParsedEncoding encoding 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>. JSONParsedEncoding Encoding = "jsonParsed" )
type FeeCalculator ¶
type FeeCalculator struct {
// contains filtered or unexported fields
}
FeeCalculator can be used to CalculateTransactionFee to send a given Transaction according to the fee schedule at this FeeScheduleBlockHash.
Note: At the moment all this calculator's method CalculateTransactionFee does is just multiply the private property lamportsPerSignature by the no of signatures on a given transaction. The reason to abstract such a simple operation at this point into a FeeCalculator service provider of sorts is in attempt to model the Solana API GetRecentBlockHashResponse which has an object field named 'feeCalculator' that just contains the fee. With such a name it seems possible that this concept may be developed more at some point. i.e. perhaps at some point calculating the transaction fee may include more than just multiplying no of signatures by this number. At which point the object may have more fields added to it. Considering this - it may be a good idea to always call CalculateTransactionFee instead of using this FeeCalculator to get the LamportsPerSignature and multiplying by the no. of signatures on a transaction. This will avoid having to refactor if the calculation ever changes.
func (*FeeCalculator) CalculateTransactionFee ¶
func (f *FeeCalculator) CalculateTransactionFee(transaction Transaction) int64
CalculateTransactionFee determines the cost in Lamports to send the given Transaction.
func (*FeeCalculator) FeeScheduleBlockHash ¶
func (f *FeeCalculator) FeeScheduleBlockHash() string
FeeScheduleBlockHash is the hash of the block during which the fee schedule used by this FeeCalculator was retrieved.
func (*FeeCalculator) LamportsPerSignature ¶
func (f *FeeCalculator) LamportsPerSignature() int64
LamportsPerSignature is the amount of Lamports required per Transaction Signature according to the fee schedule for this FeeScheduleBlockHash.
type GetAccountInfoRequest ¶
type GetAccountInfoRequest struct { PublicKey PublicKey CommitmentLevel CommitmentLevel Encoding Encoding }
type GetAccountInfoResponse ¶
type GetAccountInfoResponse struct { Context Context AccountInfo AccountInfo }
type GetBalanceRequest ¶
type GetBalanceRequest struct { PublicKey PublicKey CommitmentLevel CommitmentLevel }
type GetBalanceResponse ¶
type GetRecentBlockHashRequest ¶
type GetRecentBlockHashRequest struct {
CommitmentLevel CommitmentLevel
}
type GetRecentBlockHashResponse ¶
type GetRecentBlockHashResponse struct { Context Context // BlockHash is a base58 encoded string BlockHash string // FeeCalculator can be used to calculate the fee // to send a given Transaction according to the fee // schedule at this BlockHash FeeCalculator FeeCalculator }
type Instruction ¶
type Instruction struct { // InstructionAccountMeta is a slice of the accounts that are to // be provided to the entrypoint of the program being called. InstructionAccountMeta []InstructionAccountMeta // ProgramIDPubKey identifies the program to which this instruction // will be delivered. ProgramIDPubKey PublicKey // Data is the data to be input to the Program Data []byte }
Instruction is a Transaction instruction and is used to call some Program identified by ProgramIDPubKey
type InstructionAccountMeta ¶
type InstructionAccountMeta struct { // PubKey is a public key identifying the account to be input PubKey PublicKey // IsSigner indicates if instruction requires the encompassing transaction // to contain signature for PubKey IsSigner bool // IsWritable indicates if the account should be loaded as a read-write account IsWritable bool }
InstructionAccountMeta describes one of the accounts that will be provided as input to the program that is going to process an Instruction.
type Instructions ¶
type Instructions []Instruction
Instructions is a list of Instruction entries. It implements the encoding.Compactor interface so that it can be converted into an encoding.CompactArray of signatures.
func (Instructions) Compact ¶
func (i Instructions) Compact() encoding.CompactArray
type JSONRPCConnection ¶
type JSONRPCConnection struct {
// contains filtered or unexported fields
}
JSONRPCConnection is a json-rpc http implementation of the solana.Connection interface
func NewJSONRPCConnection ¶
func NewJSONRPCConnection(opts ...JSONRPCConnectionOption) *JSONRPCConnection
NewJSONRPCConnection returns a new and configured JSONRPCConnection.
The default returned JSONRPCConnection is configured with:
- network: MainnetBeta
- endpoint: https://api.mainnet-beta.solana.com
- commitmentLevel: ConfirmedCommitmentLevel
The passed opts are used to override these default values and configure the returned JSONRPCConnection as desired.
func (*JSONRPCConnection) Commitment ¶
func (j *JSONRPCConnection) Commitment() CommitmentLevel
func (*JSONRPCConnection) GetAccountInfo ¶
func (j *JSONRPCConnection) GetAccountInfo(ctx context.Context, request GetAccountInfoRequest) (*GetAccountInfoResponse, error)
func (*JSONRPCConnection) GetBalance ¶
func (j *JSONRPCConnection) GetBalance(ctx context.Context, request GetBalanceRequest) (*GetBalanceResponse, error)
func (*JSONRPCConnection) GetRecentBlockHash ¶
func (j *JSONRPCConnection) GetRecentBlockHash(ctx context.Context, request GetRecentBlockHashRequest) (*GetRecentBlockHashResponse, error)
func (*JSONRPCConnection) Network ¶
func (j *JSONRPCConnection) Network() Network
func (*JSONRPCConnection) SendTransaction ¶
func (j *JSONRPCConnection) SendTransaction(ctx context.Context, request SendTransactionRequest) (*SendTransactionResponse, error)
type JSONRPCConnectionOption ¶
type JSONRPCConnectionOption interface {
// contains filtered or unexported methods
}
JSONRPCConnectionOption makes a change to the jsonrpcConnectionConfig
func WithCommitmentLevel ¶
func WithCommitmentLevel(c CommitmentLevel) JSONRPCConnectionOption
WithCommitmentLevel sets CommitmentLevel on the JSONRPCConnection
func WithEndpoint ¶
func WithEndpoint(e string) JSONRPCConnectionOption
WithEndpoint sets endpoint on the JSONRPCConnection
func WithNetwork ¶
func WithNetwork(c Network) JSONRPCConnectionOption
WithNetwork sets Network on the JSONRPCConnection Note that this does not change the endpoint that the connection communicates with and so the WithEndpoint option may also need to be applied.
type KeyPair ¶
type KeyPair struct { PublicKey PrivateKey }
func MustNewRandomKeypair ¶
func MustNewRandomKeypair() *KeyPair
func NewRandomKeyPair ¶
type Network ¶
type Network string
func (Network) MustToRPCURL ¶
MustToRPCURL returns the rpc url of the relevant public Solana foundation nodes for MainnetBeta, Testnet and Devnet. Panics if Network n is invalid.
type PrivateKey ¶
type PrivateKey struct {
ed25519.PrivateKey
}
func NewPrivateKeyFromBase58String ¶
func NewPrivateKeyFromBase58String(privateKey string) PrivateKey
func (PrivateKey) PublicKey ¶
func (p PrivateKey) PublicKey() PublicKey
func (PrivateKey) ToBase58 ¶
func (p PrivateKey) ToBase58() string
type PublicKey ¶
type SendTransactionRequest ¶
type SendTransactionRequest struct { // Transaction is the transaction being sent. // Note: it should already be signed. Transaction Transaction // SkipPreflight can be set to true to skip the // preflight transaction checks. // Default value if not specified is false. SkipPreflight bool // PreflightCommitmentLevel is the CommitmentLevel // to use for preflight checks. // Default value if not specified is "finalized". PreflightCommitmentLevel string // Encoding is the Encoding used for the transaction data. // Either "base58" (slow, DEPRECATED), or "base64". // Default value if not specified is "base58". Encoding Encoding // MaxRetries is them maximum number of times for the RPC node // to retry sending the transaction to the leader. // If this parameter not provided, the RPC node will retry the // transaction until it is finalized or until the blockhash expires. MaxRetries uint }
type SendTransactionResponse ¶
type SendTransactionResponse struct { // TransactionID is the First Transaction Signature embedded // in the transaction, as base58 encoded string - aka. transaction id TransactionID string }
type Signature ¶
type Signature [64]byte
Signature is a digital signature in the ed25519 binary format and consumes 64 bytes
type Signatures ¶
type Signatures []Signature
Signatures is a list of Signature entries. It implements the encoding.Compactor interface so that it can be converted into an encoding.CompactArray of signatures.
func (Signatures) Compact ¶
func (s Signatures) Compact() encoding.CompactArray
Compact Signatures into an encoding.CompactArray
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction is a Solana blockchain transaction. Learn more at: https://docs.solana.com/developing/programming-model/transactions
func (*Transaction) AddInstructions ¶
func (t *Transaction) AddInstructions(i ...Instruction) error
AddInstructions adds the given instructions to the transaction. An error will be returned if the Transaction contains Signatures.
func (*Transaction) Sign ¶
func (t *Transaction) Sign(pvtKeys ...PrivateKey) error
Sign signs the Transaction with given PrivateKey(s) and appends a signature to a list of signatures held on the Transaction.
func (*Transaction) ToBase58 ¶
func (t *Transaction) ToBase58(recentBlockHash [32]byte) (string, error)
func (*Transaction) ToBase64 ¶
func (t *Transaction) ToBase64() (string, error)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
Package systemProgram provides a set of functions for constructing Solana system program instructions.
|
Package systemProgram provides a set of functions for constructing Solana system program instructions. |