Add RPC/getTransaction
This commit is contained in:
parent
e24be63947
commit
dd2d5478e9
|
@ -0,0 +1,52 @@
|
|||
package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
bin "github.com/dfuse-io/binary"
|
||||
"github.com/dfuse-io/solana-go"
|
||||
)
|
||||
|
||||
type GetTransactionResult struct {
|
||||
Slot bin.Uint64 `json:"slot"` // the slot this transaction was processed in
|
||||
// TODO: int64 as readable time
|
||||
BlockTime bin.Int64 `json:"blockTime"` // estimated production time, as Unix timestamp (seconds since the Unix epoch) of when the transaction was processed. null if not available
|
||||
Transaction *ParsedTransaction `json:"transaction"`
|
||||
Meta *TransactionMeta `json:"meta,omitempty"`
|
||||
}
|
||||
|
||||
type GetTransactionOpts struct {
|
||||
Encoding EncodingType `json:"encoding,omitempty"`
|
||||
Commitment CommitmentType `json:"commitment,omitempty"` // "processed" is not supported. If parameter not provided, the default is "finalized".
|
||||
}
|
||||
|
||||
// GetTransaction returns transaction details for a confirmed transaction.
|
||||
// NEW: This method is only available in solana-core v1.7 or newer.
|
||||
// Please use getConfirmedTransaction for solana-core v1.6
|
||||
func (cl *Client) GetTransaction(
|
||||
ctx context.Context,
|
||||
txSig solana.Signature, // transaction signature
|
||||
opts *GetTransactionOpts,
|
||||
) (out *GetTransactionResult, err error) {
|
||||
params := []interface{}{txSig}
|
||||
if opts != nil {
|
||||
obj := M{}
|
||||
if opts.Encoding != "" {
|
||||
obj["encoding"] = opts.Encoding
|
||||
}
|
||||
if opts.Commitment != "" {
|
||||
obj["commitment"] = opts.Commitment
|
||||
}
|
||||
if len(obj) > 0 {
|
||||
params = append(params, obj)
|
||||
}
|
||||
}
|
||||
err = cl.rpcClient.CallFor(&out, "getTransaction", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if out == nil {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
return
|
||||
}
|
35
rpc/types.go
35
rpc/types.go
|
@ -58,10 +58,19 @@ type GetConfirmedBlockResult struct {
|
|||
type BlockReward struct {
|
||||
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
|
||||
PostBalance bin.Int64 `json:"postBalance"` // account balance in lamports after the reward was applied
|
||||
RewardType string `json:"rewardType"` // type of reward: "fee", "rent", "voting", "staking"
|
||||
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"
|
||||
}
|
||||
|
||||
type RewardType string
|
||||
|
||||
const (
|
||||
RewardTypeFee RewardType = "fee"
|
||||
RewardTypeRent RewardType = "rent"
|
||||
RewardTypeVoting RewardType = "voting"
|
||||
RewardTypeStaking RewardType = "staking"
|
||||
)
|
||||
|
||||
type TransactionWithMeta struct {
|
||||
Meta *TransactionMeta `json:"meta,omitempty"` // transaction status metadata object
|
||||
Transaction *solana.Transaction `json:"transaction"`
|
||||
|
@ -99,10 +108,9 @@ type TransactionMeta struct {
|
|||
|
||||
LogMessages []string `json:"logMessages"` // array of string log messages or omitted if log message recording was not yet enabled during this transaction
|
||||
|
||||
Status DeprecatedTransactionMetaStatus `json:"status"` // Transaction status; DEPRECATED.
|
||||
Status DeprecatedTransactionMetaStatus `json:"status"` // DEPRECATED: Transaction status.
|
||||
|
||||
// TODO: not present in spec doc, but present in json.
|
||||
// Rewards []BlockReward `json:"rewards"`
|
||||
Rewards []BlockReward `json:"rewards,omitempty"`
|
||||
}
|
||||
|
||||
type InnerInstruction struct {
|
||||
|
@ -198,9 +206,10 @@ type ParsedTransaction struct {
|
|||
}
|
||||
|
||||
type Message struct {
|
||||
AccountKeys []*AccountKey `json:"accountKeys"`
|
||||
RecentBlockhash solana.Hash `json:"recentBlockhash"`
|
||||
Instructions []ParsedInstruction `json:"instructions"`
|
||||
AccountKeys []solana.PublicKey `json:"accountKeys"`
|
||||
RecentBlockhash solana.Hash `json:"recentBlockhash"`
|
||||
Instructions []ParsedInstruction `json:"instructions"`
|
||||
Header solana.MessageHeader `json:"header"`
|
||||
}
|
||||
|
||||
type AccountKey struct {
|
||||
|
@ -210,11 +219,11 @@ type AccountKey struct {
|
|||
}
|
||||
|
||||
type ParsedInstruction struct {
|
||||
Accounts []solana.PublicKey `json:"accounts,omitempty"`
|
||||
Data solana.Base58 `json:"data,omitempty"`
|
||||
Parsed *InstructionInfo `json:"parsed,omitempty"`
|
||||
Program string `json:"program,omitempty"`
|
||||
ProgramID solana.PublicKey `json:"programId"`
|
||||
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"`
|
||||
}
|
||||
|
||||
type InstructionInfo struct {
|
||||
|
|
Loading…
Reference in New Issue