move rpc type to rpc package

This commit is contained in:
billettc 2020-11-06 11:38:43 -05:00
parent 28f43ef6c1
commit 7604ae3075
7 changed files with 51 additions and 53 deletions

View File

@ -4,8 +4,7 @@ import (
"context"
"net/http"
"github.com/dfuse-io/solana-go"
//"github.com/dfuse-io/solana-go"
"github.com/ybbus/jsonrpc"
)
@ -32,7 +31,7 @@ func (c *Client) SetHeader(k, v string) {
c.headers.Set(k, v)
}
func (c *Client) GetBalance(ctx context.Context, publicKey string, commitment solana.CommitmentType) (out *solana.GetBalanceResult, err error) {
func (c *Client) GetBalance(ctx context.Context, publicKey string, commitment CommitmentType) (out *GetBalanceResult, err error) {
params := []interface{}{publicKey}
if commitment != "" {
params = append(params, string(commitment))
@ -42,7 +41,7 @@ func (c *Client) GetBalance(ctx context.Context, publicKey string, commitment so
return
}
func (c *Client) GetRecentBlockhash(ctx context.Context, commitment solana.CommitmentType) (out *solana.GetRecentBlockhashResult, err error) {
func (c *Client) GetRecentBlockhash(ctx context.Context, commitment CommitmentType) (out *GetRecentBlockhashResult, err error) {
var params []interface{}
if commitment != "" {
params = append(params, string(commitment))
@ -52,7 +51,7 @@ func (c *Client) GetRecentBlockhash(ctx context.Context, commitment solana.Commi
return
}
func (c *Client) GetSlot(ctx context.Context, commitment solana.CommitmentType) (out solana.GetSlotResult, err error) {
func (c *Client) GetSlot(ctx context.Context, commitment CommitmentType) (out GetSlotResult, err error) {
var params []interface{}
if commitment != "" {
params = append(params, string(commitment))
@ -62,7 +61,7 @@ func (c *Client) GetSlot(ctx context.Context, commitment solana.CommitmentType)
return
}
func (c *Client) GetConfirmedBlock(ctx context.Context, slot uint64, encoding string) (out *solana.GetConfirmedBlockResult, err error) {
func (c *Client) GetConfirmedBlock(ctx context.Context, slot uint64, encoding string) (out *GetConfirmedBlockResult, err error) {
if encoding == "" {
encoding = "json"
}
@ -72,17 +71,17 @@ func (c *Client) GetConfirmedBlock(ctx context.Context, slot uint64, encoding st
return
}
func (c *Client) GetAccountInfo(ctx context.Context, publicKey solana.PublicKey) (out *solana.GetAccountInfoResult, err error) {
func (c *Client) GetAccountInfo(ctx context.Context, publicKey string) (out *GetAccountInfoResult, err error) {
obj := map[string]interface{}{
"encoding": "base64",
}
params := []interface{}{publicKey.String(), obj}
params := []interface{}{publicKey, obj}
err = c.rpcClient.CallFor(&out, "getAccountInfo", params...)
return
}
func (c *Client) GetProgramAccounts(ctx context.Context, publicKey string, opts *solana.GetProgramAccountsOpts) (out *solana.GetProgramAccountsResult, err error) {
func (c *Client) GetProgramAccounts(ctx context.Context, publicKey string, opts *GetProgramAccountsOpts) (out *GetProgramAccountsResult, err error) {
params := []interface{}{publicKey}
if opts != nil {
params = append(params, opts)

View File

@ -6,8 +6,6 @@ import (
"fmt"
"testing"
"github.com/dfuse-io/solana-go"
"github.com/stretchr/testify/require"
)
@ -16,7 +14,7 @@ func TestClient_GetAccountInfo(t *testing.T) {
//rpcClient := NewRPCClient("api.mainnet-beta.solana.com:443")
c := NewClient("http://api.mainnet-beta.solana.com:80/rpc")
//c := NewClient("testnet.solana.com:8899")
accInfo, err := c.GetAccountInfo(context.Background(), solana.MustPublicKeyFromBase58("7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932"))
accInfo, err := c.GetAccountInfo(context.Background(), "7xLk17EQQ5KLDLDe44wCmupJKJjTGd8hs3eSVVhCx932")
require.NoError(t, err)
d, err := json.MarshalIndent(accInfo, "", " ")
require.NoError(t, err)

View File

@ -1,8 +1,10 @@
package solana
package rpc
import (
"encoding/base64"
"fmt"
"github.com/dfuse-io/solana-go"
)
// type ContactInfo struct {
@ -15,7 +17,7 @@ import (
type RPCContext struct {
Context struct {
Slot U64
Slot solana.U64
} `json:"context,omitempty"`
}
@ -23,12 +25,12 @@ type RPCContext struct {
type GetBalanceResult struct {
RPCContext
Value U64 `json:"value"`
Value solana.U64 `json:"value"`
}
///
type GetSlotResult U64
type GetSlotResult solana.U64
///
@ -38,40 +40,40 @@ type GetRecentBlockhashResult struct {
}
type BlockhashResult struct {
Blockhash PublicKey `json:"blockhash"` /* make this a `Hash` type, which is a copy of the PublicKey` type */
FeeCalculator FeeCalculator `json:"feeCalculator"`
Blockhash solana.PublicKey `json:"blockhash"` /* make this a `Hash` type, which is a copy of the PublicKey` type */
FeeCalculator FeeCalculator `json:"feeCalculator"`
}
type FeeCalculator struct {
LamportsPerSignature U64 `json:"lamportsPerSignature"`
LamportsPerSignature solana.U64 `json:"lamportsPerSignature"`
}
///
type GetConfirmedBlockResult struct {
Blockhash PublicKey `json:"blockhash"`
PreviousBlockhash PublicKey `json:"previousBlockhash"` // could be zeroes if ledger was clean-up and this is unavailable
ParentSlot U64 `json:"parentSlot"`
Blockhash solana.PublicKey `json:"blockhash"`
PreviousBlockhash solana.PublicKey `json:"previousBlockhash"` // could be zeroes if ledger was clean-up and this is unavailable
ParentSlot solana.U64 `json:"parentSlot"`
Transactions []TransactionWithMeta `json:"transactions"`
Rewards []BlockReward `json:"rewards"`
BlockTime U64 `json:"blockTime,omitempty"`
BlockTime solana.U64 `json:"blockTime,omitempty"`
}
type BlockReward struct {
Pubkey PublicKey `json:"pubkey"`
Lamports U64 `json:"lamports"`
Pubkey solana.PublicKey `json:"pubkey"`
Lamports solana.U64 `json:"lamports"`
}
type TransactionWithMeta struct {
Transaction *Transaction `json:"transaction"`
Meta *TransactionMeta `json:"meta,omitempty"`
Transaction *solana.Transaction `json:"transaction"`
Meta *TransactionMeta `json:"meta,omitempty"`
}
type TransactionMeta struct {
Err interface{} `json:"err"`
Fee U64 `json:"fee"`
PreBalances []U64 `json:"preBalances"`
PostBalances []U64 `json:"postBalances"`
Err interface{} `json:"err"`
Fee solana.U64 `json:"fee"`
PreBalances []solana.U64 `json:"preBalances"`
PostBalances []solana.U64 `json:"postBalances"`
}
///
@ -82,11 +84,11 @@ type GetAccountInfoResult struct {
}
type Account struct {
Lamports U64 `json:"lamports"`
Data []string `json:"data"`
Owner PublicKey `json:"owner"`
Executable bool `json:"executable"`
RentEpoch U64 `json:"rentEpoch"`
Lamports solana.U64 `json:"lamports"`
Data []string `json:"data"`
Owner solana.PublicKey `json:"owner"`
Executable bool `json:"executable"`
RentEpoch solana.U64 `json:"rentEpoch"`
}
func (a *Account) MustDataToBytes() []byte {
@ -102,8 +104,8 @@ func (a *Account) DataToBytes() ([]byte, error) {
}
type KeyedAccount struct {
Pubkey PublicKey `json:"pubkey"`
Account *Account `json:"account"`
Pubkey solana.PublicKey `json:"pubkey"`
Account *Account `json:"account"`
}
///
@ -121,12 +123,12 @@ type GetProgramAccountsOpts struct {
type RPCFilter struct {
Memcmp *RPCFilterMemcmp `json:"memcmp,omitempty"`
DataSize U64 `json:"dataSize,omitempty"`
DataSize solana.U64 `json:"dataSize,omitempty"`
}
type RPCFilterMemcmp struct {
Offset int `json:"offset"`
Bytes Base58 `json:"bytes"`
Offset int `json:"offset"`
Bytes solana.Base58 `json:"bytes"`
}
///

View File

@ -75,15 +75,13 @@ type MarketV2 struct {
EndPadding [7]byte `json:"-",struc:"[5]pad"`
}
type Orderbook struct {
BumpIndex uint32 `struc:"uint32,sizeof=Nodes"`
Padding [4]byte
FreeListLen uint32
Padding [4]byte
BumpIndex uint32 `struc:"uint32,sizeof=Nodes"`
Padding [4]byte
FreeListLen uint32
FreeListHead uint32
Root uint32
LeafCount uint32
Root uint32
LeafCount uint32
Nodes []SlabNode
}

View File

@ -5,14 +5,15 @@ import (
"os"
"strings"
"github.com/dfuse-io/solana-go"
"github.com/dfuse-io/solana-go/rpc"
"github.com/dfuse-io/solana-go/vault"
"github.com/spf13/viper"
)
func getClient() *solana.Client {
func getClient() *rpc.Client {
httpHeaders := viper.GetStringSlice("global-http-header")
api := solana.NewClient(sanitizeAPIURL(viper.GetString("global-rpc-url")))
api := rpc.NewClient(sanitizeAPIURL(viper.GetString("global-rpc-url")))
for i := 0; i < 25; i++ {
if val := os.Getenv(fmt.Sprintf("SLNC_GLOBAL_HTTP_HEADER_%d", i)); val != "" {

View File

@ -33,7 +33,7 @@ var getAccountCmd = &cobra.Command{
fmt.Println(string(data))
obj, err := decode(acct.Owner, acct.Data)
obj, err := decode(acct.Owner, acct.MustDataToBytes())
if err != nil {
return err
}

View File

@ -30,7 +30,7 @@ var getProgramAccountsCmd = &cobra.Command{
acct := keyedAcct.Account
fmt.Println("Data len:", len(acct.Data), keyedAcct.Pubkey)
obj, err := decode(acct.Owner, acct.Data)
obj, err := decode(acct.Owner, acct.MustDataToBytes())
if err != nil {
return err
}