Documentation
¶
Overview ¶
Package solana decodes the accounts and events of the AKT Solana program and attributes program logs.
Index ¶
- Variables
- func MatchesStatus(ev TransferResolved, st TransferStatus) bool
- func PDA(program solana.PublicKey, seeds ...[]byte) solana.PublicKey
- func Resolves(tx Tx, program, address solana.PublicKey, match func(TransferResolved) bool) bool
- func StatusAddress(program solana.PublicKey, id sinkid.ID) solana.PublicKey
- type Account
- type BridgeConfig
- type EvidenceIndex
- type LaunchConfig
- type Mint
- type Minted
- type Outcome
- type RPC
- func (r *RPC) BlockTime(ctx context.Context, slot uint64) (*int64, error)
- func (r *RPC) GenesisHash(ctx context.Context) (string, error)
- func (r *RPC) MultipleAccounts(ctx context.Context, keys []solana.PublicKey) (uint64, []*Account, error)
- func (r *RPC) StreamBlock(ctx context.Context, slot uint64, each func(Tx) error) error
- func (r *RPC) Transaction(ctx context.Context, sig string) (*Tx, error)
- type RPCOptions
- type TransferID
- type TransferResolved
- type TransferStatus
- type Tx
- type VoidReason
Constants ¶
This section is empty.
Variables ¶
var ( DiscLaunchConfig = [8]byte{18, 161, 9, 224, 102, 145, 29, 94} DiscBridgeConfig = [8]byte{40, 206, 51, 233, 246, 40, 178, 85} DiscTransferStatus = [8]byte{32, 200, 30, 253, 33, 153, 127, 45} DiscTransferResolved = [8]byte{205, 27, 228, 215, 90, 3, 236, 176} )
Anchor discriminators, checked against contracts/solana/tests/fixtures/deployed-interface.json.
var ( // ErrBlockMissing reports a resolution block that the owned node cannot serve. ErrBlockMissing = errors.New("resolution evidence unavailable: block missing from owned node history") // ErrNotInBlock reports that no transaction of the resolution block proves the resolution. ErrNotInBlock = errors.New("resolution evidence unavailable in its block") // ErrMultipleInBlock reports more than one transaction proving the resolution; the status account is created once. ErrMultipleInBlock = errors.New("multiple resolution transactions in block") )
var ( ErrUnavailable = errors.New("Solana node is temporarily unavailable") //nolint:staticcheck // verbatim TS text ErrBlockUnavailable = errors.New("resolution evidence unavailable: block missing from owned node history") )
Functions ¶
func MatchesStatus ¶
func MatchesStatus(ev TransferResolved, st TransferStatus) bool
MatchesStatus reports whether ev carries the identity, proof height, slot and outcome of st.
func PDA ¶
PDA returns the program address for seeds. It panics when a seed is longer than 32 bytes or there are more than 16 seeds, which are programming errors.
Types ¶
type BridgeConfig ¶
BridgeConfig is the account at ["bridge"]. The mint policy and usage counters are validated but not kept.
func DecodeBridgeConfig ¶
func DecodeBridgeConfig(data []byte) (BridgeConfig, error)
DecodeBridgeConfig decodes a BridgeConfig account. Trailing bytes are account padding.
type EvidenceIndex ¶
type EvidenceIndex struct {
// contains filtered or unexported fields
}
EvidenceIndex finds the transaction that resolved a transfer in the block of its resolution slot. Blocks are finalized, so the entries of a slot never change; slots are evicted lowest number first, not by use.
func NewEvidenceIndex ¶
func NewEvidenceIndex(rpc *RPC, program solana.PublicKey, maxSlots int, maxBytes int64) *EvidenceIndex
NewEvidenceIndex returns an index over the blocks rpc serves. It keeps at most maxSlots slots and about maxBytes of entries.
func (*EvidenceIndex) Lookup ¶
func (e *EvidenceIndex) Lookup( ctx context.Context, slot uint64, address solana.PublicKey, st TransferStatus, ) (solana.Signature, error)
Lookup returns the signature of the one transaction of slot that resolves st at address.
ErrBlockMissing means the block could not be read; ErrNotInBlock and ErrMultipleInBlock mean the block holds no resolution or several. A cancelled ctx gives ctx.Err() and caches nothing.
type LaunchConfig ¶
type LaunchConfig struct {
Version uint8
Initializer solana.PublicKey
Mint solana.PublicKey
BridgeEnabled bool
InitializedAtSlot uint64
Bump uint8
MintAuthorityBump uint8
}
LaunchConfig is the account at ["config"].
func DecodeLaunchConfig ¶
func DecodeLaunchConfig(data []byte) (LaunchConfig, error)
DecodeLaunchConfig decodes a LaunchConfig account. Trailing bytes are account padding.
type Mint ¶
type Mint struct {
MintAuthority *solana.PublicKey
Supply uint64
Decimals uint8
Initialized bool
FreezeAuthority *solana.PublicKey
}
Mint is an SPL Token mint account.
func DecodeMint ¶
DecodeMint decodes an SPL Token mint account, which is exactly 82 bytes.
type Minted ¶
Minted is an outcome that minted Amount base units to the associated token account of Recipient.
type Outcome ¶
type Outcome struct {
Minted *Minted
Voided *VoidReason
}
Outcome is the Borsh enum TransferOutcome; exactly one field is set.
type RPC ¶
type RPC struct {
// contains filtered or unexported fields
}
RPC is a JSON-RPC client for one Solana node. Every read uses finalized commitment.
func NewRPC ¶
func NewRPC(opts RPCOptions) *RPC
NewRPC returns a client with one keep-alive connection pool sized to both concurrency limits.
func (*RPC) BlockTime ¶
BlockTime returns the block time of slot, or nil when the node has none. Known times are cached per slot.
func (*RPC) GenesisHash ¶
GenesisHash returns the node's genesis hash.
func (*RPC) MultipleAccounts ¶
func (r *RPC) MultipleAccounts(ctx context.Context, keys []solana.PublicKey) (uint64, []*Account, error)
MultipleAccounts reads up to 100 accounts at finalized commitment; a missing account is nil.
func (*RPC) StreamBlock ¶
StreamBlock fetches the finalized block at slot and calls each for its transactions in order, decoding one transaction at a time. A getBlock error, a null result or a malformed block gives ErrBlockUnavailable, possibly after some calls to each; an error from each is returned as is.
type RPCOptions ¶
type RPCOptions struct {
// LegacyRedirects follows the packaged TS global-fetch redirect policy.
LegacyRedirects bool
URL string
Timeout time.Duration
// Concurrency limits concurrent requests other than getBlock.
Concurrency int
// BlockConcurrency limits concurrent getBlock requests.
BlockConcurrency int
Metrics *metrics.Metrics
}
RPCOptions configures the Solana JSON-RPC client.
type TransferID ¶
TransferID is the x/sink record ID as the program stores it.
type TransferResolved ¶
type TransferResolved TransferStatus
TransferResolved is the event a record's resolution emits; it carries the same evidence as TransferStatus.
func DecodeTransferResolved ¶
func DecodeTransferResolved(data []byte) (TransferResolved, error)
DecodeTransferResolved decodes the Anchor event data, discriminator included. The length must be exact.
func ProgramEvents ¶
func ProgramEvents(logs []string, program solana.PublicKey) ([]TransferResolved, error)
ProgramEvents returns the TransferResolved events emitted by program frames, in log order.
Anchor's event parser ignores events emitted inside a CPI, so each "Program data:" line is attributed to the executing frame from the invoke and exit lines instead. Unbalanced logs cannot be attributed and are an error. A later instruction can exhaust the log limit. The runtime then writes `Log truncated` once and keeps logging the messages that still fit, so parsing stops at the first marker: only top-level program frames that closed with success before it count. Data lines with other discriminators are ignored; a TransferResolved that does not decode is an error.
type TransferStatus ¶
type TransferStatus struct {
ID TransferID
ProofHeight uint64
ResolvedAtSlot uint64
Outcome Outcome
}
TransferStatus is the terminal record at ["transfer", SHA256(owner), LE64(height), LE64(sequence)].
func DecodeTransferStatus ¶
func DecodeTransferStatus(data []byte) (TransferStatus, error)
DecodeTransferStatus decodes a TransferStatus account. Trailing bytes are account padding.
type Tx ¶
type Tx struct {
Slot uint64
Version string
Signatures []string
Failed bool
Logs []string
HasLogs bool
Keys []solana.PublicKey
Writable []bool
}
Tx is a transaction decoded from the JSON encoding. Keys lists the static account keys, then meta.loadedAddresses.writable, then meta.loadedAddresses.readonly; Writable holds one flag per key.
type VoidReason ¶
type VoidReason uint8
VoidReason says why a record was voided.
const ( // VoidInvalidRecipient means the proven recipient cannot receive AKT. VoidInvalidRecipient VoidReason = iota // VoidGovernance means Akash governance wrote a void order for the record. VoidGovernance )