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
|
|
|
|
2020-11-06 07:40:28 -08:00
|
|
|
import (
|
2020-11-12 14:57:43 -08:00
|
|
|
bin "github.com/dfuse-io/binary"
|
2020-11-06 08:38:43 -08:00
|
|
|
"github.com/dfuse-io/solana-go"
|
2020-11-06 07:40:28 -08:00
|
|
|
)
|
|
|
|
|
2020-07-31 09:17:36 -07:00
|
|
|
type RPCContext struct {
|
|
|
|
Context struct {
|
2020-11-12 14:57:43 -08:00
|
|
|
Slot bin.Uint64
|
2020-07-31 09:17:36 -07:00
|
|
|
} `json:"context,omitempty"`
|
|
|
|
}
|
2020-07-31 13:34:44 -07:00
|
|
|
|
2020-07-31 14:54:41 -07:00
|
|
|
type GetBalanceResult struct {
|
2020-07-31 09:17:36 -07:00
|
|
|
RPCContext
|
2020-11-12 14:57:43 -08:00
|
|
|
Value bin.Uint64 `json:"value"`
|
2020-07-31 09:17:36 -07:00
|
|
|
}
|
|
|
|
|
2020-11-12 14:57:43 -08:00
|
|
|
type GetSlotResult bin.Uint64
|
2020-07-31 14:54:41 -07:00
|
|
|
|
|
|
|
type GetRecentBlockhashResult struct {
|
|
|
|
RPCContext
|
|
|
|
Value BlockhashResult `json:"value"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type BlockhashResult struct {
|
2020-11-06 08:38:43 -08:00
|
|
|
Blockhash solana.PublicKey `json:"blockhash"` /* make this a `Hash` type, which is a copy of the PublicKey` type */
|
|
|
|
FeeCalculator FeeCalculator `json:"feeCalculator"`
|
2020-07-31 14:54:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type FeeCalculator struct {
|
2020-11-12 14:57:43 -08:00
|
|
|
LamportsPerSignature bin.Uint64 `json:"lamportsPerSignature"`
|
2020-07-31 14:54:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type GetConfirmedBlockResult struct {
|
2020-11-06 08:38:43 -08:00
|
|
|
Blockhash solana.PublicKey `json:"blockhash"`
|
|
|
|
PreviousBlockhash solana.PublicKey `json:"previousBlockhash"` // could be zeroes if ledger was clean-up and this is unavailable
|
2020-11-12 14:57:43 -08:00
|
|
|
ParentSlot bin.Uint64 `json:"parentSlot"`
|
2020-07-31 14:54:41 -07:00
|
|
|
Transactions []TransactionWithMeta `json:"transactions"`
|
|
|
|
Rewards []BlockReward `json:"rewards"`
|
2020-11-12 14:57:43 -08:00
|
|
|
BlockTime bin.Uint64 `json:"blockTime,omitempty"`
|
2020-07-31 14:54:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type BlockReward struct {
|
2020-11-06 08:38:43 -08:00
|
|
|
Pubkey solana.PublicKey `json:"pubkey"`
|
2020-11-12 14:57:43 -08:00
|
|
|
Lamports bin.Uint64 `json:"lamports"`
|
2020-07-31 14:54:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type TransactionWithMeta struct {
|
2020-11-06 08:38:43 -08:00
|
|
|
Transaction *solana.Transaction `json:"transaction"`
|
|
|
|
Meta *TransactionMeta `json:"meta,omitempty"`
|
2020-07-31 14:54:41 -07:00
|
|
|
}
|
|
|
|
|
2020-11-11 11:38:52 -08:00
|
|
|
type TransactionParsed struct {
|
|
|
|
Transaction *ParsedTransaction `json:"transaction"`
|
|
|
|
Meta *TransactionMeta `json:"meta,omitempty"`
|
|
|
|
}
|
|
|
|
|
2020-07-31 14:54:41 -07:00
|
|
|
type TransactionMeta struct {
|
2020-11-06 08:38:43 -08:00
|
|
|
Err interface{} `json:"err"`
|
2020-11-12 14:57:43 -08:00
|
|
|
Fee bin.Uint64 `json:"fee"`
|
|
|
|
PreBalances []bin.Uint64 `json:"preBalances"`
|
|
|
|
PostBalances []bin.Uint64 `json:"postBalances"`
|
2020-07-31 14:54:41 -07:00
|
|
|
}
|
|
|
|
|
2020-11-11 11:38:52 -08:00
|
|
|
type TransactionSignature struct {
|
|
|
|
Err interface{} `json:"err,omitempty"`
|
|
|
|
Memo string `json:"memo,omitempty"`
|
|
|
|
Signature string `json:"signature,omitempty"`
|
2020-11-12 14:59:45 -08:00
|
|
|
Slot bin.Uint64 `json:"slot,omitempty"`
|
2020-11-11 11:38:52 -08:00
|
|
|
}
|
2020-07-31 14:54:41 -07:00
|
|
|
|
|
|
|
type GetAccountInfoResult struct {
|
2020-07-31 09:17:36 -07:00
|
|
|
RPCContext
|
2020-07-31 13:34:44 -07:00
|
|
|
Value *Account `json:"value"`
|
2020-07-31 09:17:36 -07:00
|
|
|
}
|
2020-07-31 13:34:44 -07:00
|
|
|
|
|
|
|
type Account struct {
|
2020-11-12 14:57:43 -08:00
|
|
|
Lamports bin.Uint64 `json:"lamports"`
|
2020-11-09 09:59:24 -08:00
|
|
|
Data solana.Data `json:"data"`
|
2020-11-06 08:38:43 -08:00
|
|
|
Owner solana.PublicKey `json:"owner"`
|
|
|
|
Executable bool `json:"executable"`
|
2020-11-12 14:57:43 -08:00
|
|
|
RentEpoch bin.Uint64 `json:"rentEpoch"`
|
2020-07-31 09:17:36 -07:00
|
|
|
}
|
|
|
|
|
2020-07-31 13:34:44 -07:00
|
|
|
type GetProgramAccountsOpts struct {
|
|
|
|
Commitment CommitmentType `json:"commitment,omitempty"`
|
|
|
|
|
|
|
|
// Filter on accounts, implicit AND between filters
|
|
|
|
Filters []RPCFilter `json:"filters,omitempty"`
|
|
|
|
}
|
|
|
|
|
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"`
|
2020-11-20 11:24:07 -08:00
|
|
|
Before string `json:"before,omitempty"`
|
2020-11-11 11:38:52 -08:00
|
|
|
Until string `json:"until,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type GetConfirmedSignaturesForAddress2Result []*TransactionSignature
|
|
|
|
|
2020-07-31 13:34:44 -07:00
|
|
|
type RPCFilter struct {
|
|
|
|
Memcmp *RPCFilterMemcmp `json:"memcmp,omitempty"`
|
2020-11-12 14:57:43 -08:00
|
|
|
DataSize bin.Uint64 `json:"dataSize,omitempty"`
|
2020-07-31 13:34:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
type RPCFilterMemcmp struct {
|
2020-11-06 08:38:43 -08:00
|
|
|
Offset int `json:"offset"`
|
|
|
|
Bytes solana.Base58 `json:"bytes"`
|
2020-07-31 13:34:44 -07:00
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
AccountKeys []*AccountKey `json:"accountKeys"`
|
|
|
|
RecentBlockhash solana.PublicKey/* TODO: change to Hash */ `json:"recentBlockhash"`
|
|
|
|
Instructions []ParsedInstruction `json:"instructions"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type AccountKey struct {
|
|
|
|
PublicKey solana.PublicKey `json:"pubkey"`
|
|
|
|
Signer bool `json:"signer"`
|
|
|
|
Writable bool `json:"writable"`
|
|
|
|
}
|
|
|
|
|
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type InstructionInfo struct {
|
|
|
|
Info map[string]interface{} `json:"info"`
|
|
|
|
InstructionType string `json:"type"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *ParsedInstruction) IsParsed() bool {
|
|
|
|
return p.Parsed != nil
|
|
|
|
}
|