Skip to content

Commit

Permalink
build: upgrade solana sdk.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhangguiguang committed Oct 10, 2023
1 parent 50f206b commit 39c2979
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 32 deletions.
6 changes: 3 additions & 3 deletions core/solana/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package solana
import (
"strings"

"github.com/blocto/solana-go-sdk/pkg/hdwallet"
solana "github.com/blocto/solana-go-sdk/types"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/coming-chat/wallet-SDK/core/base"
"github.com/portto/solana-go-sdk/pkg/hdwallet"
solana "github.com/portto/solana-go-sdk/types"
"github.com/tyler-smith/go-bip39"
)

Expand All @@ -25,7 +25,7 @@ func NewAccountWithMnemonic(mnemonic string) (*Account, error) {
if err != nil {
return nil, err
}

account, err := solana.AccountFromSeed(derivedKey.PrivateKey)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion core/solana/address_util.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package solana

import (
"github.com/blocto/solana-go-sdk/common"
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/portto/solana-go-sdk/common"
)

type Util struct {
Expand Down
21 changes: 10 additions & 11 deletions core/solana/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"strconv"
"strings"

"github.com/blocto/solana-go-sdk/client"
"github.com/blocto/solana-go-sdk/common"
"github.com/blocto/solana-go-sdk/program/system"
"github.com/blocto/solana-go-sdk/rpc"
"github.com/blocto/solana-go-sdk/types"
"github.com/coming-chat/wallet-SDK/core/base"
"github.com/portto/solana-go-sdk/client"
"github.com/portto/solana-go-sdk/common"
"github.com/portto/solana-go-sdk/program/sysprog"
"github.com/portto/solana-go-sdk/rpc"

hexTypes "github.com/centrifuge/go-substrate-rpc-client/v4/types"
"github.com/portto/solana-go-sdk/types"
)

const (
Expand Down Expand Up @@ -160,7 +160,7 @@ func (c *Chain) EstimateTransactionFeeUsePublicKey(transaction base.Transaction,
return c.EstimateTransactionFee(transaction)
}

func decodeTransaction(tx *client.GetTransactionResponse, to *base.TransactionDetail) error {
func decodeTransaction(tx *client.Transaction, to *base.TransactionDetail) error {
base.CatchPanicAndMapToBasicError(nil)

if tx == nil || tx.BlockTime == nil {
Expand All @@ -179,13 +179,12 @@ func decodeTransaction(tx *client.GetTransactionResponse, to *base.TransactionDe
data := instruction.Data
instruct := binary.LittleEndian.Uint32(data[:4])
toidx := -1
switch sysprog.Instruction(instruct) {
case sysprog.InstructionTransfer:
switch system.Instruction(instruct) {
case system.InstructionTransfer:
toidx = instruction.Accounts[1]
case sysprog.InstructionTransferWithSeed:
case system.InstructionTransferWithSeed:
toidx = instruction.Accounts[2]
}
if toidx == -1 {
default:
continue
}

Expand Down
9 changes: 4 additions & 5 deletions core/solana/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,24 @@ import (

"github.com/coming-chat/wallet-SDK/core/base"
"github.com/coming-chat/wallet-SDK/core/testcase"
"github.com/portto/solana-go-sdk/rpc"
)

func newChainAndAccount() (*Chain, *Account) {
// chain := NewChainWithRpc(rpc.MainnetRPCEndpoint)
chain := NewChainWithRpc(rpc.DevnetRPCEndpoint)
chain := NewChainWithRpc(DevnetRPCEndpoint)
// c := client.NewClient(rpc.LocalnetRPCEndpoint)
account, _ := NewAccountWithMnemonic(testcase.M1)
return chain, account
}

func DevnetChain() *Chain {
return NewChainWithRpc(rpc.DevnetRPCEndpoint)
return NewChainWithRpc(DevnetRPCEndpoint)
}
func TestnetChain() *Chain {
return NewChainWithRpc(rpc.TestnetRPCEndpoint)
return NewChainWithRpc(TestnetRPCEndpoint)
}
func MainnetChain() *Chain {
return NewChainWithRpc(rpc.MainnetRPCEndpoint)
return NewChainWithRpc(MainnetRPCEndpoint)
}

func TestAirdrop(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions core/solana/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"errors"
"strconv"

"github.com/blocto/solana-go-sdk/client"
"github.com/blocto/solana-go-sdk/common"
"github.com/blocto/solana-go-sdk/program/system"
"github.com/blocto/solana-go-sdk/types"
"github.com/coming-chat/wallet-SDK/core/base"
"github.com/portto/solana-go-sdk/client"
"github.com/portto/solana-go-sdk/common"
"github.com/portto/solana-go-sdk/program/sysprog"
"github.com/portto/solana-go-sdk/types"
)

type Token struct {
Expand Down Expand Up @@ -88,7 +88,7 @@ func transactionMessage(client *client.Client, fromAddress, toAddress, amount st
pubFrom := common.PublicKeyFromString(fromAddress) // from is same as to, or it's must valid

// to fetch recent blockhash
res, err := client.GetRecentBlockhash(context.Background())
res, err := client.GetLatestBlockhash(context.Background())
if err != nil {
return nil, err
}
Expand All @@ -98,7 +98,7 @@ func transactionMessage(client *client.Client, fromAddress, toAddress, amount st
FeePayer: pubFrom,
RecentBlockhash: res.Blockhash, // recent blockhash
Instructions: []types.Instruction{
sysprog.Transfer(sysprog.TransferParam{
system.Transfer(system.TransferParam{
From: pubFrom, // from
To: pubTo, // to
Amount: amountUint,
Expand Down
2 changes: 1 addition & 1 deletion core/solana/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package solana
import (
"encoding/hex"

"github.com/blocto/solana-go-sdk/types"
"github.com/coming-chat/wallet-SDK/core/base"
"github.com/portto/solana-go-sdk/types"
)

type Transaction struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.19

require (
github.com/ChainSafe/go-schnorrkel v0.0.0-20210318173838-ccb5cd955283
github.com/blocto/solana-go-sdk v1.26.0
github.com/btcsuite/btcd v0.23.4
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/btcutil v1.1.2
Expand All @@ -24,7 +25,6 @@ require (
github.com/itering/subscan v0.1.0
github.com/novifinancial/serde-reflection/serde-generate/runtime/golang v0.0.0-20210526181959-1694c58d103e
github.com/pierrec/xxHash v0.1.5
github.com/portto/solana-go-sdk v1.18.0
github.com/shopspring/decimal v1.3.1
github.com/starcoinorg/starcoin-go v0.0.0-20220821052347-0e482a42c59e
github.com/stretchr/testify v1.8.2
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw=
cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k=
cosmossdk.io/tools/rosetta v0.2.1 h1:ddOMatOH+pbxWbrGJKRAawdBkPYLfKXutK9IETnjYxw=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4=
Expand Down Expand Up @@ -111,6 +110,8 @@ github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/blocktree/go-owcrypt v1.1.10 h1:eQhxJnUt265LUHJYbPHn9Cw76THir7lv8cWeW2Mtl8s=
github.com/blocktree/go-owcrypt v1.1.10/go.mod h1:n98+UALIX82e7jhNvfYcG9pz3cDGO026EjslMrqgNvc=
github.com/blocto/solana-go-sdk v1.26.0 h1:NpLKmP89TPbX35U07kFgfcTibLFcb69NK0wYgEwLfTM=
github.com/blocto/solana-go-sdk v1.26.0/go.mod h1:Xoyhhb3hrGpEQ5rJps5a3OgMwDpmEhrd9bgzFKkkwMs=
github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
Expand Down Expand Up @@ -625,7 +626,6 @@ github.com/mtibben/percent v0.2.1/go.mod h1:KG9uO+SZkUp+VkRHsCdYQV3XSZrrSpR3O9ib
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0=
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E=
github.com/near/borsh-go v0.3.1-0.20210831082424-4377deff6791/go.mod h1:NeMochZp7jN/pYFuxLkrZtmLqbADmnp/y1+/dL+AsyQ=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/novifinancial/serde-reflection/serde-generate/runtime/golang v0.0.0-20210526181959-1694c58d103e h1:OT96oaEAXKKpbiRwX58Wu3G7nVZXwYUwwgjPMmb9N8I=
github.com/novifinancial/serde-reflection/serde-generate/runtime/golang v0.0.0-20210526181959-1694c58d103e/go.mod h1:NrRYJCFtaewjIRr4B9V2AyWsAEMW0Zqdjs8Bm+bACbM=
Expand Down Expand Up @@ -681,8 +681,6 @@ github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6J
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/portto/solana-go-sdk v1.18.0 h1:wCIIojlDTP44pxNRGgJzoS+tFPqFVxLlFasc5qsXrUE=
github.com/portto/solana-go-sdk v1.18.0/go.mod h1:gZbsZglfaZaU/5BkDQUPKGA7hgUWVxGFLcoeiPg3zD4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=
Expand Down

0 comments on commit 39c2979

Please sign in to comment.