solana-go/rpc/types.go

237 lines
9.7 KiB
Go
Raw Normal View History

2020-11-09 10:09:50 -08:00
// Copyright 2020 dfuse Platform Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2020-11-06 08:38:43 -08:00
package rpc
2020-07-31 09:17:36 -07:00
import (
bin "github.com/dfuse-io/binary"
2020-11-06 08:38:43 -08:00
"github.com/dfuse-io/solana-go"
)
type Context struct {
Slot bin.Uint64
}
2020-07-31 09:17:36 -07:00
type RPCContext struct {
Context Context `json:"context,omitempty"`
2020-07-31 09:17:36 -07:00
}
type GetBalanceResult struct {
2020-07-31 09:17:36 -07:00
RPCContext
Value bin.Uint64 `json:"value"`
2020-07-31 09:17:36 -07:00
}
type GetRecentBlockhashResult struct {
RPCContext
Value BlockhashResult `json:"value"`
}
type BlockhashResult struct {
Blockhash solana.Hash `json:"blockhash"`
FeeCalculator FeeCalculator `json:"feeCalculator"`
}
type FeeCalculator struct {
LamportsPerSignature bin.Uint64 `json:"lamportsPerSignature"`
}
type GetConfirmedBlockResult struct {
Blockhash solana.Hash `json:"blockhash"`
PreviousBlockhash solana.Hash `json:"previousBlockhash"` // could be zeroes if ledger was clean-up and this is unavailable
ParentSlot bin.Uint64 `json:"parentSlot"`
Transactions []TransactionWithMeta `json:"transactions"`
Rewards []BlockReward `json:"rewards"`
BlockTime bin.Uint64 `json:"blockTime,omitempty"`
}
type BlockReward struct {
2021-06-30 12:07:11 -07:00
Pubkey solana.PublicKey `json:"pubkey"` // The public key, as base-58 encoded string, of the account that received the reward
Lamports bin.Int64 `json:"lamports"` // number of reward lamports credited or debited by the account, as a i64
2021-07-02 05:20:40 -07:00
PostBalance bin.Uint64 `json:"postBalance"` // account balance in lamports after the reward was applied
RewardType RewardType `json:"rewardType"` // type of reward: "fee", "rent", "voting", "staking"
}
2021-07-02 05:20:40 -07:00
type RewardType string
const (
RewardTypeFee RewardType = "fee"
RewardTypeRent RewardType = "rent"
RewardTypeVoting RewardType = "voting"
RewardTypeStaking RewardType = "staking"
)
type TransactionWithMeta struct {
2021-06-30 14:35:30 -07:00
Meta *TransactionMeta `json:"meta,omitempty"` // transaction status metadata object
2020-11-06 08:38:43 -08:00
Transaction *solana.Transaction `json:"transaction"`
}
2020-11-11 11:38:52 -08:00
type TransactionParsed struct {
Transaction *ParsedTransaction `json:"transaction"`
Meta *TransactionMeta `json:"meta,omitempty"`
}
2021-06-30 14:35:30 -07:00
type TokenBalance struct {
// TODO: <number> == bin.Int64 ???
AccountIndex uint8 `json:"accountIndex"` // Index of the account in which the token balance is provided for.
Mint solana.PublicKey `json:"mint"` // Pubkey of the token's mint.
UiTokenAmount *UiTokenAmount `json:"uiTokenAmount"`
}
type UiTokenAmount struct {
Amount string `json:"amount"` // Raw amount of tokens as a string, ignoring decimals.
// TODO: <number> == bin.Int64 ???
Decimals uint8 `json:"decimals"` // Number of decimals configured for token's mint.
2021-07-01 13:43:18 -07:00
UiAmount *bin.JSONFloat64 `json:"uiAmount"` // DEPRECATED: Token amount as a float, accounting for decimals.
2021-06-30 14:35:30 -07:00
UiAmountString string `json:"uiAmountString"` // Token amount as a string, accounting for decimals.
}
type TransactionMeta struct {
2021-06-30 14:35:30 -07:00
Err interface{} `json:"err"` // Error if transaction failed, null if transaction succeeded. https://github.com/solana-labs/solana/blob/master/sdk/src/transaction.rs#L24
Fee bin.Uint64 `json:"fee"` // fee this transaction was charged
PreBalances []bin.Uint64 `json:"preBalances"` // array of u64 account balances from before the transaction was processed
PostBalances []bin.Uint64 `json:"postBalances"` // array of u64 account balances after the transaction was processed
InnerInstructions []InnerInstruction `json:"innerInstructions"` // List of inner instructions or omitted if inner instruction recording was not yet enabled during this transaction
PreTokenBalances []TokenBalance `json:"preTokenBalances"` // List of token balances from before the transaction was processed or omitted if token balance recording was not yet enabled during this transaction
PostTokenBalances []TokenBalance `json:"postTokenBalances"` // List of token balances from after the transaction was processed or omitted if token balance recording was not yet enabled during this transaction
LogMessages []string `json:"logMessages"` // array of string log messages or omitted if log message recording was not yet enabled during this transaction
2021-07-02 05:20:40 -07:00
Status DeprecatedTransactionMetaStatus `json:"status"` // DEPRECATED: Transaction status.
2021-06-30 14:35:30 -07:00
2021-07-02 05:20:40 -07:00
Rewards []BlockReward `json:"rewards,omitempty"`
2021-06-30 14:35:30 -07:00
}
type InnerInstruction struct {
// TODO: <number> == bin.Int64 ???
Index uint8 `json:"index"` // Index of the transaction instruction from which the inner instruction(s) originated
Instructions []solana.CompiledInstruction `json:"instructions"` // Ordered list of inner program instructions that were invoked during a single transaction instruction.
}
// Ok interface{} `json:"Ok"` // <null> Transaction was successful
// Err interface{} `json:"Err"` // Transaction failed with TransactionError
type DeprecatedTransactionMetaStatus M
2020-11-11 11:38:52 -08:00
type TransactionSignature struct {
Err interface{} `json:"err,omitempty"` // Error if transaction failed, null if transaction succeeded
Memo string `json:"memo,omitempty"` // Memo associated with the transaction, null if no memo is present
Signature solana.Signature `json:"signature"` // transaction signature as base-58 encoded string
Slot bin.Uint64 `json:"slot,omitempty"` // The slot that contains the block with the transaction
BlockTime bin.Int64 `json:"blockTime,omitempty"` // estimated production time, as Unix timestamp (seconds since the Unix epoch) of when transaction was processed. null if not available.
ConfirmationStatus ConfirmationStatusType `json:"confirmationStatus,omitempty"`
2020-11-11 11:38:52 -08:00
}
type GetAccountInfoResult struct {
2020-07-31 09:17:36 -07:00
RPCContext
Value *Account `json:"value"`
2020-07-31 09:17:36 -07:00
}
type Account struct {
Lamports bin.Uint64 `json:"lamports"` // number of lamports assigned to this account
Owner solana.PublicKey `json:"owner"` // base-58 encoded Pubkey of the program this account has been assigned to
Data solana.Data `json:"data"` // data associated with the account, either as encoded binary data or JSON format {<program>: <state>}, depending on encoding parameter
Executable bool `json:"executable"` // boolean indicating if the account contains a program (and is strictly read-only)
RentEpoch bin.Uint64 `json:"rentEpoch"` // the epoch at which this account will next owe rent
2020-07-31 09:17:36 -07:00
}
2021-07-01 09:27:39 -07:00
type DataSlice struct {
Offset *uint `json:"offset,omitempty"`
Length *uint `json:"length,omitempty"`
}
type GetProgramAccountsOpts struct {
Commitment CommitmentType `json:"commitment,omitempty"`
2021-07-01 09:27:39 -07:00
Encoding EncodingType `json:"encoding,omitempty"`
DataSlice *DataSlice `json:"dataSlice,omitempty"` // limit the returned account data
// Filter on accounts, implicit AND between filters
2021-07-01 09:27:39 -07:00
Filters []RPCFilter `json:"filters,omitempty"` // filter results using various filter objects; account must meet all filter criteria to be included in results
// TODO:
// WithContext *bool `json:"withContext,omitempty"` // wrap the result in an RpcResponse JSON object.
}
2020-11-11 11:38:52 -08:00
type GetProgramAccountsResult []*KeyedAccount
type KeyedAccount struct {
Pubkey solana.PublicKey `json:"pubkey"`
Account *Account `json:"account"`
}
type GetConfirmedSignaturesForAddress2Opts struct {
Limit uint64 `json:"limit,omitempty"`
Before string `json:"before,omitempty"`
2020-11-11 11:38:52 -08:00
Until string `json:"until,omitempty"`
}
type GetConfirmedSignaturesForAddress2Result []*TransactionSignature
type RPCFilter struct {
Memcmp *RPCFilterMemcmp `json:"memcmp,omitempty"`
DataSize bin.Uint64 `json:"dataSize,omitempty"`
}
type RPCFilterMemcmp struct {
2020-11-06 08:38:43 -08:00
Offset int `json:"offset"`
Bytes solana.Base58 `json:"bytes"`
}
2020-07-31 09:17:36 -07:00
type CommitmentType string
const (
CommitmentMax = CommitmentType("max")
CommitmentRecent = CommitmentType("recent")
CommitmentRoot = CommitmentType("root")
CommitmentSingle = CommitmentType("single")
CommitmentSingleGossip = CommitmentType("singleGossip")
)
2020-11-11 11:38:52 -08:00
/// Parsed Transaction
type ParsedTransaction struct {
Signatures []solana.Signature `json:"signatures"`
Message Message `json:"message"`
}
type Message struct {
2021-07-02 05:20:40 -07:00
AccountKeys []solana.PublicKey `json:"accountKeys"`
RecentBlockhash solana.Hash `json:"recentBlockhash"`
Instructions []ParsedInstruction `json:"instructions"`
Header solana.MessageHeader `json:"header"`
2020-11-11 11:38:52 -08:00
}
type AccountKey struct {
PublicKey solana.PublicKey `json:"pubkey"`
Signer bool `json:"signer"`
Writable bool `json:"writable"`
}
type ParsedInstruction struct {
2021-07-02 05:20:40 -07:00
Accounts []bin.Int64 `json:"accounts,omitempty"`
Data solana.Base58 `json:"data,omitempty"`
Parsed *InstructionInfo `json:"parsed,omitempty"`
Program string `json:"program,omitempty"`
ProgramIDIndex bin.Int64 `json:"programIdIndex"`
2020-11-11 11:38:52 -08:00
}
type InstructionInfo struct {
Info map[string]interface{} `json:"info"`
InstructionType string `json:"type"`
}
func (p *ParsedInstruction) IsParsed() bool {
return p.Parsed != nil
}