├── .envrc ├── .github └── workflows │ └── tests.yml ├── .gitignore ├── .goreleaser.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── account.go ├── account_test.go ├── cli ├── cli.go └── getpass.go ├── cmd └── slnc │ ├── cmd │ ├── common.go │ ├── decoding.go │ ├── get.go │ ├── get_account.go │ ├── get_balance.go │ ├── get_confirmed_block.go │ ├── get_program_accounts.go │ ├── get_recent_block_hash.go │ ├── get_slot.go │ ├── get_spl_token.go │ ├── get_transactions.go │ ├── is_blockhash_valid.go │ ├── logging.go │ ├── request_airdrop.go │ ├── root.go │ ├── serum.go │ ├── serum_get.go │ ├── serum_get_market.go │ ├── serum_list.go │ ├── serum_list_markets.go │ ├── system.go │ ├── system_transfer.go │ ├── token.go │ ├── token_get.go │ ├── token_get_mint.go │ ├── token_list.go │ ├── token_list_mints.go │ ├── token_registry.go │ ├── token_registry_get.go │ ├── token_registry_list.go │ ├── token_registry_register.go │ ├── token_transfer.go │ ├── vault.go │ ├── vault_add.go │ ├── vault_create.go │ ├── vault_export.go │ └── vault_list.go │ └── main.go ├── constants.go ├── diff ├── diff.go ├── diff_test.go ├── init_test.go └── logging.go ├── generic_instruction.go ├── generic_instruction_test.go ├── go.mod ├── go.sum ├── init_test.go ├── interface.go ├── json.go ├── keys.go ├── keys_test.go ├── logging.go ├── message.go ├── nativetype_test.go ├── nativetypes.go ├── program_ids.go ├── programs ├── associated-token-account │ ├── Create.go │ └── instructions.go ├── bpf-loader │ └── loader.go ├── serum │ ├── data │ │ └── markets.json │ ├── init_test.go │ ├── instruction.go │ ├── instruction_test.go │ ├── json.go │ ├── logging.go │ ├── market.go │ ├── math.go │ ├── math_test.go │ ├── program.go │ ├── queue.go │ ├── queue_test.go │ ├── rice-box.go │ ├── rpc.go │ ├── rpc_test.go │ ├── testdata │ │ ├── orderbook.hex │ │ ├── serum-event-queue-new.bin.zst │ │ ├── serum-event-queue-old.bin.zst │ │ ├── serum-open-orders-new.hex │ │ ├── serum-open-orders-new.json │ │ ├── serum-open-orders-old.hex │ │ └── serum-open-orders-old.json │ ├── types.go │ └── types_test.go ├── system │ ├── AdvanceNonceAccount.go │ ├── AdvanceNonceAccount_test.go │ ├── Allocate.go │ ├── AllocateWithSeed.go │ ├── AllocateWithSeed_test.go │ ├── Allocate_test.go │ ├── Assign.go │ ├── AssignWithSeed.go │ ├── AssignWithSeed_test.go │ ├── Assign_test.go │ ├── AuthorizeNonceAccount.go │ ├── AuthorizeNonceAccount_test.go │ ├── CreateAccount.go │ ├── CreateAccountWithSeed.go │ ├── CreateAccountWithSeed_test.go │ ├── CreateAccount_test.go │ ├── InitializeNonceAccount.go │ ├── InitializeNonceAccount_test.go │ ├── Transfer.go │ ├── TransferWithSeed.go │ ├── TransferWithSeed_test.go │ ├── Transfer_test.go │ ├── WithdrawNonceAccount.go │ ├── WithdrawNonceAccount_test.go │ ├── accounts.go │ ├── accounts_test.go │ ├── init_test.go │ ├── instructions.go │ ├── logging.go │ ├── testing_utils.go │ └── types.go ├── token │ ├── Approve.go │ ├── ApproveChecked.go │ ├── ApproveChecked_test.go │ ├── Approve_test.go │ ├── Burn.go │ ├── BurnChecked.go │ ├── BurnChecked_test.go │ ├── Burn_test.go │ ├── CloseAccount.go │ ├── CloseAccount_test.go │ ├── FreezeAccount.go │ ├── FreezeAccount_test.go │ ├── InitializeAccount.go │ ├── InitializeAccount2.go │ ├── InitializeAccount2_test.go │ ├── InitializeAccount3.go │ ├── InitializeAccount3_test.go │ ├── InitializeAccount_test.go │ ├── InitializeMint.go │ ├── InitializeMint2.go │ ├── InitializeMint2_test.go │ ├── InitializeMint_test.go │ ├── InitializeMultisig.go │ ├── InitializeMultisig2.go │ ├── InitializeMultisig2_test.go │ ├── InitializeMultisig_test.go │ ├── MintTo.go │ ├── MintToChecked.go │ ├── MintToChecked_test.go │ ├── MintTo_test.go │ ├── Revoke.go │ ├── Revoke_test.go │ ├── SetAuthority.go │ ├── SetAuthority_test.go │ ├── SyncNative.go │ ├── SyncNative_test.go │ ├── ThawAccount.go │ ├── ThawAccount_test.go │ ├── Transfer.go │ ├── TransferChecked.go │ ├── TransferChecked_test.go │ ├── Transfer_test.go │ ├── accounts.go │ ├── accounts_test.go │ ├── instructions.go │ ├── json.go │ ├── rpc.go │ ├── testing_utils.go │ └── types.go └── tokenregistry │ ├── instruction.go │ ├── logging.go │ ├── program.go │ ├── rpc.go │ ├── types.go │ └── types_test.go ├── registry.go ├── registry_test.go ├── rpc ├── client-with-ratelimit.go ├── client-with-ratelimit2.go ├── client.go ├── client_test.go ├── deprecated.go ├── endpoints.go ├── errors.go ├── examples │ ├── getAccountInfo │ │ └── getAccountInfo.go │ ├── getBalance │ │ └── getBalance.go │ ├── getBlock │ │ └── getBlock.go │ ├── getBlockCommitment │ │ └── getBlockCommitment.go │ ├── getBlockHeight │ │ └── getBlockHeight.go │ ├── getBlockProduction │ │ └── getBlockProduction.go │ ├── getBlockTime │ │ └── getBlockTime.go │ ├── getBlocks │ │ └── getBlocks.go │ ├── getBlocksWithLimit │ │ └── getBlocksWithLimit.go │ ├── getClusterNodes │ │ └── getClusterNodes.go │ ├── getConfirmedBlock │ │ └── getConfirmedBlock.go │ ├── getConfirmedBlocks │ │ └── getConfirmedBlocks.go │ ├── getConfirmedBlocksWithLimit │ │ └── getConfirmedBlocksWithLimit.go │ ├── getConfirmedSignaturesForAddress2 │ │ └── getConfirmedSignaturesForAddress2.go │ ├── getConfirmedTransaction │ │ └── getConfirmedTransaction.go │ ├── getEpochInfo │ │ └── getEpochInfo.go │ ├── getEpochSchedule │ │ └── getEpochSchedule.go │ ├── getFeeCalculatorForBlockhash │ │ └── getFeeCalculatorForBlockhash.go │ ├── getFeeForMessage │ │ └── getFeeForMessage.go │ ├── getFeeRateGovernor │ │ └── getFeeRateGovernor.go │ ├── getFees │ │ └── getFees.go │ ├── getFirstAvailableBlock │ │ └── getFirstAvailableBlock.go │ ├── getGenesisHash │ │ └── getGenesisHash.go │ ├── getHealth │ │ └── getHealth.go │ ├── getHighestSnapshotSlot │ │ └── getHighestSnapshotSlot.go │ ├── getIdentity │ │ └── getIdentity.go │ ├── getInflationGovernor │ │ └── getInflationGovernor.go │ ├── getInflationRate │ │ └── getInflationRate.go │ ├── getInflationReward │ │ └── getInflationReward.go │ ├── getLargestAccounts │ │ └── getLargestAccounts.go │ ├── getLatestBlockhash │ │ └── getLatestBlockhash.go │ ├── getLeaderSchedule │ │ └── getLeaderSchedule.go │ ├── getMaxRetransmitSlot │ │ └── getMaxRetransmitSlot.go │ ├── getMaxShredInsertSlot │ │ └── getMaxShredInsertSlot.go │ ├── getMinimumBalanceForRentExemption │ │ └── getMinimumBalanceForRentExemption.go │ ├── getMultipleAccounts │ │ └── getMultipleAccounts.go │ ├── getProgramAccounts │ │ └── getProgramAccounts.go │ ├── getRecentBlockhash │ │ └── getRecentBlockhash.go │ ├── getRecentPerformanceSamples │ │ └── getRecentPerformanceSamples.go │ ├── getSignatureStatuses │ │ └── getSignatureStatuses.go │ ├── getSignaturesForAddress │ │ └── getSignaturesForAddress.go │ ├── getSlot │ │ └── getSlot.go │ ├── getSlotLeader │ │ └── getSlotLeader.go │ ├── getSlotLeaders │ │ └── getSlotLeaders.go │ ├── getSnapshotSlot │ │ └── getSnapshotSlot.go │ ├── getStakeActivation │ │ └── getStakeActivation.go │ ├── getSupply │ │ └── getSupply.go │ ├── getTokenAccountBalance │ │ └── getTokenAccountBalance.go │ ├── getTokenAccountsByDelegate │ │ └── getTokenAccountsByDelegate.go │ ├── getTokenAccountsByOwner │ │ └── getTokenAccountsByOwner.go │ ├── getTokenLargestAccounts │ │ └── getTokenLargestAccounts.go │ ├── getTokenSupply │ │ └── getTokenSupply.go │ ├── getTransaction │ │ └── getTransaction.go │ ├── getTransactionCount │ │ └── getTransactionCount.go │ ├── getVersion │ │ └── getVersion.go │ ├── getVoteAccounts │ │ └── getVoteAccounts.go │ ├── isBlockhashValid │ │ └── isValidBlockhash.go │ ├── minimumLedgerSlot │ │ └── minimumLedgerSlot.go │ ├── requestAirdrop │ │ └── requestAirdrop.go │ ├── sendEncodedTransaction │ │ └── sendEncodedTransaction.go │ ├── sendRawTransaction │ │ └── sendRawTransaction.go │ ├── sendTransaction │ │ └── sendTransaction.go │ └── simulateTransaction │ │ └── simulateTransaction.go ├── getAccountInfo.go ├── getBalance.go ├── getBlock.go ├── getBlockCommitment.go ├── getBlockHeight.go ├── getBlockProduction.go ├── getBlockTime.go ├── getBlocks.go ├── getBlocksWithLimit.go ├── getClusterNodes.go ├── getEpochInfo.go ├── getEpochSchedule.go ├── getFeeCalculatorForBlockhash.go ├── getFeeForMessage.go ├── getFeeRateGovernor.go ├── getFees.go ├── getFirstAvailableBlock.go ├── getGenesisHash.go ├── getHealth.go ├── getHighestSnapshotSlot.go ├── getIdentity.go ├── getInflationGovernor.go ├── getInflationRate.go ├── getInflationReward.go ├── getLargestAccounts.go ├── getLatestBlockhash.go ├── getLeaderSchedule.go ├── getMaxRetransmitSlot.go ├── getMaxShredInsertSlot.go ├── getMinimumBalanceForRentExemption.go ├── getMultipleAccounts.go ├── getParsedTransaction.go ├── getProgramAccounts.go ├── getRecentBlockhash.go ├── getRecentPerformanceSamples.go ├── getSignatureStatuses.go ├── getSignaturesForAddress.go ├── getSlot.go ├── getSlotLeader.go ├── getSlotLeaders.go ├── getSnapshotSlot.go ├── getStakeActivation.go ├── getSupply.go ├── getTokenAccountBalance.go ├── getTokenAccountsByDelegate.go ├── getTokenAccountsByOwner.go ├── getTokenLargestAccounts.go ├── getTokenSupply.go ├── getTransaction.go ├── getTransactionCount.go ├── getVersion.go ├── getVoteAccounts.go ├── isBlockhashValid.go ├── json.go ├── jsonrpc │ ├── LICENSE │ ├── README.md │ ├── jsonrpc.go │ └── jsonrpc_test.go ├── logging.go ├── minimumLedgerSlot.go ├── requestAirdrop.go ├── rpc_test.go ├── sendAndConfirmTransaction │ └── sendAndConfirmTransaction.go ├── sendEncodedTransaction.go ├── sendRawTransaction.go ├── sendTransaction.go ├── simulateTransaction.go ├── types.go ├── types_test.go └── ws │ ├── accountSubscribe.go │ ├── blockSubscribe.go │ ├── client.go │ ├── client_test.go │ ├── examples │ ├── accountSubscribe │ │ └── accountSubscribe.go │ ├── logsSubscribe │ │ └── logsSubscribe.go │ ├── programSubscribe │ │ └── programSubscribe.go │ ├── rootSubscribe │ │ └── rootSubscribe.go │ ├── signatureSubscribe │ │ └── signatureSubscribe.go │ ├── slotSubscribe │ │ └── slotSubscribe.go │ └── voteSubscribe │ │ └── voteSubscribe.go │ ├── json.go │ ├── logging.go │ ├── logsSubscribe.go │ ├── programSubscribe.go │ ├── rootSubscribe.go │ ├── signatureSubscribe.go │ ├── slotSubscribe.go │ ├── slotsUpdatesSubscribe.go │ ├── subscription.go │ ├── types.go │ └── voteSubscribe.go ├── sysvar.go ├── testdata └── standard.solana-keygen.json ├── text ├── encoder.go ├── encoder_test.go ├── format │ └── format.go ├── interface.go ├── tag.go ├── tools.go ├── tree.go └── types.go ├── transaction.go ├── transaction_test.go ├── transaction_v0_test.go ├── types.go ├── types_test.go ├── util.go ├── vault ├── json.go ├── kmsgcp.go ├── kmsmanager.go ├── passphrase.go ├── secretboxer.go └── vault.go └── zap-box ├── encoder.go └── utils.go /.envrc: -------------------------------------------------------------------------------- 1 | export SLNC_GLOBAL_INSECURE_VAULT_PASSPHRASE=secure 2 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | name: tests 3 | jobs: 4 | test: 5 | strategy: 6 | matrix: 7 | go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x] 8 | os: [ubuntu-latest, macos-latest, windows-latest] 9 | runs-on: ${{ matrix.os }} 10 | steps: 11 | - name: Install Go 12 | uses: actions/setup-go@v2 13 | with: 14 | go-version: ${{ matrix.go-version }} 15 | - name: Checkout code 16 | uses: actions/checkout@v2 17 | - name: Test 18 | run: go test ./... -count=100 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | dist/ 3 | rpc/debug-utils.go 4 | 5 | .DS_Store 6 | 7 | solana-vault.json 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change log 2 | 3 | The format is based on 4 | [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this 5 | project adheres to 6 | [Semantic Versioning](https://semver.org/spec/v2.0.0.html). See 7 | [MAINTAINERS.md](./MAINTAINERS.md) for instructions to keep up to 8 | date. 9 | 10 | ``` 11 | ⚠️ solana-go works using SemVer but in 0 version, which means that the 'minor' will be changed when some broken changes are introduced into the application, and the 'patch' will be changed when a new feature with new changes is added or for bug fixing. As soon as v1.0.0 be released, solana-go will start to use SemVer as usual. 12 | ``` 13 | 14 | # [v0.1.0] 2020-11-09 15 | 16 | First release 17 | 18 | # Includes the following features: 19 | 20 | * Get basic information from the chain about accounts, balances, etc. 21 | * Issue SOL native token transfer 22 | * Issue SPL token transfers 23 | * Get Project SERUM markets list and live market data -------------------------------------------------------------------------------- /cli/cli.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 dfuse Platform Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cli 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/pkg/errors" 21 | ) 22 | 23 | func GetDecryptPassphrase() (string, error) { 24 | passphrase, err := GetPassword("Enter passphrase to decrypt your vault: ") 25 | if err != nil { 26 | return "", fmt.Errorf("reading password: %s", err) 27 | } 28 | 29 | return passphrase, nil 30 | } 31 | func GetEncryptPassphrase() (string, error) { 32 | passphrase, err := GetPassword("Enter passphrase to encrypt your vault: ") 33 | if err != nil { 34 | return "", fmt.Errorf("reading password: %s", err) 35 | } 36 | 37 | passphraseConfirm, err := GetPassword("Confirm passphrase: ") 38 | if err != nil { 39 | return "", fmt.Errorf("reading confirmation password: %s", err) 40 | } 41 | 42 | if passphrase != passphraseConfirm { 43 | fmt.Println() 44 | return "", errors.New("passphrase mismatch!") 45 | } 46 | return passphrase, nil 47 | 48 | } 49 | -------------------------------------------------------------------------------- /cli/getpass.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 dfuse Platform Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cli 16 | 17 | import ( 18 | "fmt" 19 | "os" 20 | 21 | "golang.org/x/crypto/ssh/terminal" 22 | ) 23 | 24 | func GetPassword(input string) (string, error) { 25 | fd := os.Stdin.Fd() 26 | fmt.Printf(input) 27 | pass, err := terminal.ReadPassword(int(fd)) 28 | fmt.Println("") 29 | return string(pass), err 30 | } 31 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/get.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 dfuse Platform Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cmd 16 | 17 | import "github.com/spf13/cobra" 18 | 19 | var getCmd = &cobra.Command{ 20 | Use: "get", 21 | Short: "Fetch information from a cluster", 22 | } 23 | 24 | func init() { 25 | RootCmd.AddCommand(getCmd) 26 | } 27 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/get_recent_block_hash.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import ( 21 | "context" 22 | "encoding/json" 23 | "fmt" 24 | 25 | "github.com/spf13/cobra" 26 | ) 27 | 28 | var getRecentBlockhashCmd = &cobra.Command{ 29 | Use: "recent-blockhash", 30 | Short: "Retrieve a recent blockhash, needed for crafting transactions", 31 | Args: cobra.ExactArgs(0), 32 | RunE: func(cmd *cobra.Command, args []string) error { 33 | client := getClient() 34 | ctx := context.Background() 35 | 36 | resp, err := client.GetRecentBlockhash(ctx, "") 37 | if err != nil { 38 | return err 39 | } 40 | 41 | cnt, _ := json.MarshalIndent(resp.Value, "", " ") 42 | fmt.Println(string(cnt)) 43 | 44 | return nil 45 | }, 46 | } 47 | 48 | func init() { 49 | getCmd.AddCommand(getRecentBlockhashCmd) 50 | } 51 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/get_slot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import ( 21 | "context" 22 | "fmt" 23 | 24 | "github.com/spf13/cobra" 25 | ) 26 | 27 | var getSlotCmd = &cobra.Command{ 28 | Use: "slot", 29 | Short: "Retrieve the current slot the node is processing", 30 | Args: cobra.ExactArgs(0), 31 | RunE: func(cmd *cobra.Command, args []string) error { 32 | client := getClient() 33 | ctx := context.Background() 34 | 35 | resp, err := client.GetSlot(ctx, "") 36 | if err != nil { 37 | return err 38 | } 39 | 40 | fmt.Println(resp) 41 | 42 | return nil 43 | }, 44 | } 45 | 46 | func init() { 47 | getCmd.AddCommand(getSlotCmd) 48 | } 49 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/is_blockhash_valid.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package cmd 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/gagliardetto/solana-go" 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var isBlockhashValidCmd = &cobra.Command{ 25 | Use: "isblockhashvalid {blockhash}", 26 | Short: "Checks if a given blockhash is valid", 27 | Args: cobra.ExactArgs(1), 28 | RunE: func(cmd *cobra.Command, args []string) error { 29 | client := getClient() 30 | 31 | resp, err := client.IsBlockhashValid( 32 | cmd.Context(), 33 | solana.MustHashFromBase58(args[0]), 34 | "", 35 | ) 36 | if err != nil { 37 | return err 38 | } 39 | 40 | fmt.Println(resp.Value) 41 | 42 | return nil 43 | }, 44 | } 45 | 46 | func init() { 47 | getCmd.AddCommand(isBlockhashValidCmd) 48 | } 49 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/serum.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import "github.com/spf13/cobra" 21 | 22 | var serumCmd = &cobra.Command{ 23 | Use: "serum", 24 | Short: "serum commands", 25 | SilenceUsage: false, 26 | } 27 | 28 | func init() { 29 | RootCmd.AddCommand(serumCmd) 30 | } 31 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/serum_get.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import ( 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var serumGetCmd = &cobra.Command{ 25 | Use: "get", 26 | Short: "Get Serum objects", 27 | } 28 | 29 | func init() { 30 | serumCmd.AddCommand(serumGetCmd) 31 | } 32 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/serum_list.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import ( 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var serumListCmd = &cobra.Command{ 25 | Use: "list", 26 | Short: "List Serum objects", 27 | } 28 | 29 | func init() { 30 | serumCmd.AddCommand(serumListCmd) 31 | } 32 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/system.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import "github.com/spf13/cobra" 21 | 22 | var systemCmd = &cobra.Command{ 23 | Use: "system", 24 | Short: "System Instructions", 25 | } 26 | 27 | func init() { 28 | RootCmd.AddCommand(systemCmd) 29 | } 30 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/system_transfer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import ( 21 | "context" 22 | "fmt" 23 | 24 | "github.com/spf13/cobra" 25 | ) 26 | 27 | var systemTransferCmd = &cobra.Command{ 28 | Use: "transfer {from} {to} {amount}", 29 | Short: "Create and sign a native SOL token transfer", 30 | Args: cobra.ExactArgs(3), 31 | RunE: func(cmd *cobra.Command, args []string) error { 32 | client := getClient() 33 | // v := mustGetWallet() 34 | ctx := context.Background() 35 | 36 | from := args[0] 37 | to := args[1] 38 | amount := args[2] 39 | 40 | fmt.Println(from, to, amount) 41 | 42 | _ = client 43 | _ = ctx 44 | 45 | return nil 46 | }, 47 | } 48 | 49 | func init() { 50 | systemCmd.AddCommand(systemTransferCmd) 51 | } 52 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/token.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import "github.com/spf13/cobra" 21 | 22 | var tokenCmd = &cobra.Command{ 23 | Use: "token", 24 | Short: "Tokens related Instructions", 25 | } 26 | 27 | func init() { 28 | RootCmd.AddCommand(tokenCmd) 29 | } 30 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/token_get.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import ( 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var tokenGetCmd = &cobra.Command{ 25 | Use: "get", 26 | Short: "Retrieves token objects", 27 | } 28 | 29 | func init() { 30 | tokenCmd.AddCommand(tokenGetCmd) 31 | } 32 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/token_list.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import ( 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | var tokenListCmd = &cobra.Command{ 25 | Use: "list", 26 | Short: "Retrieves token objects", 27 | } 28 | 29 | func init() { 30 | tokenCmd.AddCommand(tokenListCmd) 31 | } 32 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/token_registry.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import "github.com/spf13/cobra" 21 | 22 | var tokenRegistryCmd = &cobra.Command{ 23 | Use: "token-registry", 24 | Short: "Token Registry related Instructions", 25 | } 26 | 27 | func init() { 28 | RootCmd.AddCommand(tokenRegistryCmd) 29 | } 30 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/token_transfer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import ( 21 | "context" 22 | "fmt" 23 | 24 | "github.com/spf13/cobra" 25 | ) 26 | 27 | var tokenTransferCmd = &cobra.Command{ 28 | Use: "transfer {from} {to} {amount}", 29 | Short: "Create and sign a token transfer transaction", 30 | Args: cobra.ExactArgs(3), 31 | RunE: func(cmd *cobra.Command, args []string) error { 32 | client := getClient() 33 | ctx := context.Background() 34 | 35 | from := args[0] 36 | to := args[1] 37 | amount := args[2] 38 | 39 | fmt.Println(from, to, amount) 40 | 41 | _ = client 42 | _ = ctx 43 | 44 | return nil 45 | }, 46 | } 47 | 48 | func init() { 49 | tokenCmd.AddCommand(tokenTransferCmd) 50 | } 51 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/vault.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import ( 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | // vaultCmd represents the vault command 25 | var vaultCmd = &cobra.Command{ 26 | Use: "vault", 27 | Short: "The slnc Vault is a secure Solana keys vault", 28 | } 29 | 30 | func init() { 31 | RootCmd.AddCommand(vaultCmd) 32 | } 33 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/vault_export.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import ( 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | // vaultExportCommand represents the export command 25 | var vaultExportCommand = &cobra.Command{ 26 | Use: "export", 27 | Short: "Export private keys (and corresponding public keys) inside a Solana vault.", 28 | Run: func(cmd *cobra.Command, args []string) { 29 | vault := mustGetWallet() 30 | 31 | vault.PrintPrivateKeys() 32 | }, 33 | } 34 | 35 | func init() { 36 | vaultCmd.AddCommand(vaultExportCommand) 37 | } 38 | -------------------------------------------------------------------------------- /cmd/slnc/cmd/vault_list.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package cmd 19 | 20 | import ( 21 | "github.com/spf13/cobra" 22 | ) 23 | 24 | // vaultListCmd represents the list command 25 | var vaultListCmd = &cobra.Command{ 26 | Use: "list", 27 | Short: "List public keys inside a Solana vault.", 28 | Long: `List public keys inside a Solana vault. 29 | 30 | The wallet file contains a lits of public keys for easy reference, but 31 | you cannot trust that these public keys have their counterpart in the 32 | wallet, unless you check with the "list" command. 33 | `, 34 | Run: func(cmd *cobra.Command, args []string) { 35 | vault := mustGetWallet() 36 | 37 | vault.PrintPublicKeys() 38 | }, 39 | } 40 | 41 | func init() { 42 | vaultCmd.AddCommand(vaultListCmd) 43 | } 44 | -------------------------------------------------------------------------------- /cmd/slnc/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 dfuse Platform Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "github.com/gagliardetto/solana-go/cmd/slnc/cmd" 19 | ) 20 | 21 | var version = "dev" 22 | 23 | func init() { 24 | cmd.Version = version 25 | } 26 | 27 | func main() { 28 | cmd.Execute() 29 | } 30 | -------------------------------------------------------------------------------- /constants.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package solana 16 | 17 | const ( 18 | // There are 1-billion lamports in one SOL. 19 | LAMPORTS_PER_SOL uint64 = 1000000000 20 | ) 21 | -------------------------------------------------------------------------------- /diff/init_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 dfuse Platform Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package diff 16 | 17 | import "github.com/streamingfast/logging" 18 | 19 | func init() { 20 | logging.TestingOverride() 21 | } 22 | -------------------------------------------------------------------------------- /diff/logging.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 dfuse Platform Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package diff 16 | 17 | import ( 18 | "fmt" 19 | "reflect" 20 | 21 | "github.com/streamingfast/logging" 22 | "go.uber.org/zap" 23 | ) 24 | 25 | var traceEnabled = logging.IsTraceEnabled("solana-go", "github.com/gagliardetto/solana-go/diff") 26 | var zlog = zap.NewNop() 27 | 28 | func init() { 29 | logging.Register("github.com/gagliardetto/solana-go/diff", &zlog) 30 | } 31 | 32 | type reflectType struct { 33 | in interface{} 34 | } 35 | 36 | func (r reflectType) String() string { 37 | if r.in == nil { 38 | return "" 39 | } 40 | 41 | valueOf := reflect.ValueOf(r.in) 42 | return fmt.Sprintf("%s (zero? %t, value %s)", valueOf.Type(), valueOf.IsZero(), r.in) 43 | } 44 | -------------------------------------------------------------------------------- /generic_instruction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package solana 16 | 17 | // NewInstruction creates a generic instruction with the provided 18 | // programID, accounts, and data bytes. 19 | func NewInstruction( 20 | programID PublicKey, 21 | accounts AccountMetaSlice, 22 | data []byte, 23 | ) *GenericInstruction { 24 | return &GenericInstruction{ 25 | AccountValues: accounts, 26 | ProgID: programID, 27 | DataBytes: data, 28 | } 29 | } 30 | 31 | var _ Instruction = &GenericInstruction{} 32 | 33 | type GenericInstruction struct { 34 | AccountValues AccountMetaSlice 35 | ProgID PublicKey 36 | DataBytes []byte 37 | } 38 | 39 | func (in *GenericInstruction) ProgramID() PublicKey { 40 | return in.ProgID 41 | } 42 | 43 | func (in *GenericInstruction) Accounts() []*AccountMeta { 44 | return in.AccountValues 45 | } 46 | 47 | func (in *GenericInstruction) Data() ([]byte, error) { 48 | return in.DataBytes, nil 49 | } 50 | -------------------------------------------------------------------------------- /generic_instruction_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package solana 16 | 17 | import ( 18 | "testing" 19 | 20 | "github.com/stretchr/testify/require" 21 | ) 22 | 23 | func TestNewInstruction(t *testing.T) { 24 | progID := MemoProgramID 25 | accounts := []*AccountMeta{ 26 | Meta(SPLAssociatedTokenAccountProgramID).SIGNER().WRITE(), 27 | } 28 | data := []byte("hello world") 29 | 30 | ins := NewInstruction(progID, accounts, data) 31 | 32 | require.Equal(t, progID, ins.ProgramID()) 33 | require.Equal(t, accounts, ins.Accounts()) 34 | { 35 | got, err := ins.Data() 36 | require.NoError(t, err) 37 | require.Equal(t, data, got) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /init_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 dfuse Platform Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package solana 16 | 17 | import ( 18 | "go.uber.org/zap" 19 | ) 20 | 21 | func init() { 22 | zlog, _ = zap.NewDevelopment() 23 | } 24 | -------------------------------------------------------------------------------- /interface.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package solana 16 | 17 | type AccountsSettable interface { 18 | SetAccounts(accounts []*AccountMeta) error 19 | } 20 | 21 | type AccountsGettable interface { 22 | GetAccounts() (accounts []*AccountMeta) 23 | } 24 | -------------------------------------------------------------------------------- /json.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package solana 16 | 17 | import ( 18 | jsoniter "github.com/json-iterator/go" 19 | ) 20 | 21 | var json = jsoniter.ConfigCompatibleWithStandardLibrary 22 | -------------------------------------------------------------------------------- /logging.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package solana 19 | 20 | import ( 21 | "github.com/streamingfast/logging" 22 | "go.uber.org/zap" 23 | ) 24 | 25 | var traceEnabled = logging.IsTraceEnabled("solana-go", "github.com/gagliardetto/solana-go") 26 | 27 | var zlog = zap.NewNop() 28 | 29 | func init() { 30 | logging.Register("github.com/gagliardetto/solana-go", &zlog) 31 | } 32 | -------------------------------------------------------------------------------- /programs/serum/json.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package serum 16 | 17 | import ( 18 | jsoniter "github.com/json-iterator/go" 19 | ) 20 | 21 | var json = jsoniter.ConfigCompatibleWithStandardLibrary 22 | -------------------------------------------------------------------------------- /programs/serum/logging.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package serum 19 | 20 | import ( 21 | "github.com/streamingfast/logging" 22 | "go.uber.org/zap" 23 | ) 24 | 25 | var zlog = zap.NewNop() 26 | var traceEnabled = logging.IsTraceEnabled("solana-go", "github.com/gagliardetto/solana-go/program/serum") 27 | 28 | func init() { 29 | logging.Register("github.com/gagliardetto/solana-go/program/serum", &zlog) 30 | } 31 | -------------------------------------------------------------------------------- /programs/serum/program.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package serum 19 | 20 | import "github.com/gagliardetto/solana-go" 21 | 22 | // DEXProgramIDV2 represents the fixed address on which the Serum DEX v2 smart contract is deployed 23 | var DEXProgramIDV2 = solana.MustPublicKeyFromBase58("EUqojwWA2rd19FZrzeBncJsm38Jm1hEhE3zsmX3bRc2o") 24 | 25 | var DEXProgramIDV3 = solana.MustPublicKeyFromBase58("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin") 26 | -------------------------------------------------------------------------------- /programs/serum/testdata/serum-event-queue-new.bin.zst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/top-comengineer/solana_go/381fe57b9361dd8a017d6f130dd066ebb75b8c34/programs/serum/testdata/serum-event-queue-new.bin.zst -------------------------------------------------------------------------------- /programs/serum/testdata/serum-event-queue-old.bin.zst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/top-comengineer/solana_go/381fe57b9361dd8a017d6f130dd066ebb75b8c34/programs/serum/testdata/serum-event-queue-old.bin.zst -------------------------------------------------------------------------------- /programs/system/AdvanceNonceAccount_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_AdvanceNonceAccount(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("AdvanceNonceAccount"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(AdvanceNonceAccount) 32 | fu.Fuzz(params) 33 | params.AccountMetaSlice = nil 34 | buf := new(bytes.Buffer) 35 | err := encodeT(*params, buf) 36 | ag_require.NoError(t, err) 37 | // 38 | got := new(AdvanceNonceAccount) 39 | err = decodeT(got, buf.Bytes()) 40 | got.AccountMetaSlice = nil 41 | ag_require.NoError(t, err) 42 | ag_require.Equal(t, params, got) 43 | } 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /programs/system/AllocateWithSeed_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_AllocateWithSeed(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("AllocateWithSeed"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(AllocateWithSeed) 32 | fu.Fuzz(params) 33 | params.AccountMetaSlice = nil 34 | buf := new(bytes.Buffer) 35 | err := encodeT(*params, buf) 36 | ag_require.NoError(t, err) 37 | // 38 | got := new(AllocateWithSeed) 39 | err = decodeT(got, buf.Bytes()) 40 | got.AccountMetaSlice = nil 41 | ag_require.NoError(t, err) 42 | ag_require.Equal(t, params, got) 43 | } 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /programs/system/Allocate_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_Allocate(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("Allocate"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(Allocate) 32 | fu.Fuzz(params) 33 | params.AccountMetaSlice = nil 34 | buf := new(bytes.Buffer) 35 | err := encodeT(*params, buf) 36 | ag_require.NoError(t, err) 37 | // 38 | got := new(Allocate) 39 | err = decodeT(got, buf.Bytes()) 40 | got.AccountMetaSlice = nil 41 | ag_require.NoError(t, err) 42 | ag_require.Equal(t, params, got) 43 | } 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /programs/system/AssignWithSeed_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_AssignWithSeed(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("AssignWithSeed"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(AssignWithSeed) 32 | fu.Fuzz(params) 33 | params.AccountMetaSlice = nil 34 | buf := new(bytes.Buffer) 35 | err := encodeT(*params, buf) 36 | ag_require.NoError(t, err) 37 | // 38 | got := new(AssignWithSeed) 39 | err = decodeT(got, buf.Bytes()) 40 | got.AccountMetaSlice = nil 41 | ag_require.NoError(t, err) 42 | ag_require.Equal(t, params, got) 43 | } 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /programs/system/Assign_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_Assign(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("Assign"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(Assign) 32 | fu.Fuzz(params) 33 | params.AccountMetaSlice = nil 34 | buf := new(bytes.Buffer) 35 | err := encodeT(*params, buf) 36 | ag_require.NoError(t, err) 37 | // 38 | got := new(Assign) 39 | err = decodeT(got, buf.Bytes()) 40 | got.AccountMetaSlice = nil 41 | ag_require.NoError(t, err) 42 | ag_require.Equal(t, params, got) 43 | } 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /programs/system/AuthorizeNonceAccount_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_AuthorizeNonceAccount(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("AuthorizeNonceAccount"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(AuthorizeNonceAccount) 32 | fu.Fuzz(params) 33 | params.AccountMetaSlice = nil 34 | buf := new(bytes.Buffer) 35 | err := encodeT(*params, buf) 36 | ag_require.NoError(t, err) 37 | // 38 | got := new(AuthorizeNonceAccount) 39 | err = decodeT(got, buf.Bytes()) 40 | got.AccountMetaSlice = nil 41 | ag_require.NoError(t, err) 42 | ag_require.Equal(t, params, got) 43 | } 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /programs/system/CreateAccount_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_CreateAccount(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("CreateAccount"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(CreateAccount) 32 | fu.Fuzz(params) 33 | params.AccountMetaSlice = nil 34 | buf := new(bytes.Buffer) 35 | err := encodeT(*params, buf) 36 | ag_require.NoError(t, err) 37 | // 38 | got := new(CreateAccount) 39 | err = decodeT(got, buf.Bytes()) 40 | got.AccountMetaSlice = nil 41 | ag_require.NoError(t, err) 42 | ag_require.Equal(t, params, got) 43 | } 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /programs/system/InitializeNonceAccount_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_InitializeNonceAccount(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("InitializeNonceAccount"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(InitializeNonceAccount) 32 | fu.Fuzz(params) 33 | params.AccountMetaSlice = nil 34 | buf := new(bytes.Buffer) 35 | err := encodeT(*params, buf) 36 | ag_require.NoError(t, err) 37 | // 38 | got := new(InitializeNonceAccount) 39 | err = decodeT(got, buf.Bytes()) 40 | got.AccountMetaSlice = nil 41 | ag_require.NoError(t, err) 42 | ag_require.Equal(t, params, got) 43 | } 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /programs/system/TransferWithSeed_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_TransferWithSeed(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("TransferWithSeed"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(TransferWithSeed) 32 | fu.Fuzz(params) 33 | params.AccountMetaSlice = nil 34 | buf := new(bytes.Buffer) 35 | err := encodeT(*params, buf) 36 | ag_require.NoError(t, err) 37 | // 38 | got := new(TransferWithSeed) 39 | err = decodeT(got, buf.Bytes()) 40 | got.AccountMetaSlice = nil 41 | ag_require.NoError(t, err) 42 | ag_require.Equal(t, params, got) 43 | } 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /programs/system/Transfer_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_Transfer(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("Transfer"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(Transfer) 32 | fu.Fuzz(params) 33 | params.AccountMetaSlice = nil 34 | buf := new(bytes.Buffer) 35 | err := encodeT(*params, buf) 36 | ag_require.NoError(t, err) 37 | // 38 | got := new(Transfer) 39 | err = decodeT(got, buf.Bytes()) 40 | got.AccountMetaSlice = nil 41 | ag_require.NoError(t, err) 42 | ag_require.Equal(t, params, got) 43 | } 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /programs/system/WithdrawNonceAccount_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_WithdrawNonceAccount(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("WithdrawNonceAccount"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(WithdrawNonceAccount) 32 | fu.Fuzz(params) 33 | params.AccountMetaSlice = nil 34 | buf := new(bytes.Buffer) 35 | err := encodeT(*params, buf) 36 | ag_require.NoError(t, err) 37 | // 38 | got := new(WithdrawNonceAccount) 39 | err = decodeT(got, buf.Bytes()) 40 | got.AccountMetaSlice = nil 41 | ag_require.NoError(t, err) 42 | ag_require.Equal(t, params, got) 43 | } 44 | }) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /programs/system/init_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 dfuse Platform Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | 17 | import "github.com/streamingfast/logging" 18 | 19 | func init() { 20 | logging.TestingOverride() 21 | } 22 | -------------------------------------------------------------------------------- /programs/system/logging.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package system 19 | 20 | import ( 21 | "github.com/streamingfast/logging" 22 | "go.uber.org/zap" 23 | ) 24 | 25 | var traceEnabled = logging.IsTraceEnabled("solana-go", "github.com/gagliardetto/solana-go/system") 26 | var zlog = zap.NewNop() 27 | 28 | func init() { 29 | logging.Register("github.com/gagliardetto/solana-go/system", &zlog) 30 | } 31 | -------------------------------------------------------------------------------- /programs/system/testing_utils.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | 17 | import ( 18 | "bytes" 19 | "fmt" 20 | 21 | ag_binary "github.com/gagliardetto/binary" 22 | ) 23 | 24 | func encodeT(data interface{}, buf *bytes.Buffer) error { 25 | if err := ag_binary.NewBinEncoder(buf).Encode(data); err != nil { 26 | return fmt.Errorf("unable to encode instruction: %w", err) 27 | } 28 | return nil 29 | } 30 | 31 | func decodeT(dst interface{}, data []byte) error { 32 | return ag_binary.NewBinDecoder(data).Decode(dst) 33 | } 34 | -------------------------------------------------------------------------------- /programs/system/types.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package system 16 | -------------------------------------------------------------------------------- /programs/token/ApproveChecked_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_ApproveChecked(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("ApproveChecked"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(ApproveChecked) 32 | fu.Fuzz(params) 33 | params.Accounts = nil 34 | params.Signers = nil 35 | buf := new(bytes.Buffer) 36 | err := encodeT(*params, buf) 37 | ag_require.NoError(t, err) 38 | // 39 | got := new(ApproveChecked) 40 | err = decodeT(got, buf.Bytes()) 41 | params.Accounts = nil 42 | params.Signers = nil 43 | ag_require.NoError(t, err) 44 | ag_require.Equal(t, params, got) 45 | } 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /programs/token/Approve_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_Approve(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("Approve"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(Approve) 32 | fu.Fuzz(params) 33 | params.Accounts = nil 34 | params.Signers = nil 35 | buf := new(bytes.Buffer) 36 | err := encodeT(*params, buf) 37 | ag_require.NoError(t, err) 38 | // 39 | got := new(Approve) 40 | err = decodeT(got, buf.Bytes()) 41 | got.Accounts = nil 42 | params.Signers = nil 43 | ag_require.NoError(t, err) 44 | ag_require.Equal(t, params, got) 45 | } 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /programs/token/BurnChecked_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_BurnChecked(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("BurnChecked"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(BurnChecked) 32 | fu.Fuzz(params) 33 | params.Accounts = nil 34 | params.Signers = nil 35 | buf := new(bytes.Buffer) 36 | err := encodeT(*params, buf) 37 | ag_require.NoError(t, err) 38 | // 39 | got := new(BurnChecked) 40 | err = decodeT(got, buf.Bytes()) 41 | params.Accounts = nil 42 | params.Signers = nil 43 | ag_require.NoError(t, err) 44 | ag_require.Equal(t, params, got) 45 | } 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /programs/token/Burn_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_Burn(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("Burn"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(Burn) 32 | fu.Fuzz(params) 33 | params.Accounts = nil 34 | params.Signers = nil 35 | buf := new(bytes.Buffer) 36 | err := encodeT(*params, buf) 37 | ag_require.NoError(t, err) 38 | // 39 | got := new(Burn) 40 | err = decodeT(got, buf.Bytes()) 41 | params.Accounts = nil 42 | params.Signers = nil 43 | ag_require.NoError(t, err) 44 | ag_require.Equal(t, params, got) 45 | } 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /programs/token/CloseAccount_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_CloseAccount(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("CloseAccount"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(CloseAccount) 32 | fu.Fuzz(params) 33 | params.Accounts = nil 34 | params.Signers = nil 35 | buf := new(bytes.Buffer) 36 | err := encodeT(*params, buf) 37 | ag_require.NoError(t, err) 38 | // 39 | got := new(CloseAccount) 40 | err = decodeT(got, buf.Bytes()) 41 | params.Accounts = nil 42 | params.Signers = nil 43 | ag_require.NoError(t, err) 44 | ag_require.Equal(t, params, got) 45 | } 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /programs/token/FreezeAccount_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_FreezeAccount(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("FreezeAccount"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(FreezeAccount) 32 | fu.Fuzz(params) 33 | params.Accounts = nil 34 | params.Signers = nil 35 | buf := new(bytes.Buffer) 36 | err := encodeT(*params, buf) 37 | ag_require.NoError(t, err) 38 | // 39 | got := new(FreezeAccount) 40 | err = decodeT(got, buf.Bytes()) 41 | params.Accounts = nil 42 | params.Signers = nil 43 | ag_require.NoError(t, err) 44 | ag_require.Equal(t, params, got) 45 | } 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /programs/token/InitializeAccount2_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | ag_gofuzz "github.com/gagliardetto/gofuzz" 20 | ag_require "github.com/stretchr/testify/require" 21 | "strconv" 22 | "testing" 23 | ) 24 | 25 | func TestEncodeDecode_InitializeAccount2(t *testing.T) { 26 | fu := ag_gofuzz.New().NilChance(0) 27 | for i := 0; i < 1; i++ { 28 | t.Run("InitializeAccount2"+strconv.Itoa(i), func(t *testing.T) { 29 | { 30 | params := new(InitializeAccount2) 31 | fu.Fuzz(params) 32 | params.AccountMetaSlice = nil 33 | buf := new(bytes.Buffer) 34 | err := encodeT(*params, buf) 35 | ag_require.NoError(t, err) 36 | // 37 | got := new(InitializeAccount2) 38 | err = decodeT(got, buf.Bytes()) 39 | got.AccountMetaSlice = nil 40 | ag_require.NoError(t, err) 41 | ag_require.Equal(t, params, got) 42 | } 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /programs/token/InitializeAccount3_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | ag_gofuzz "github.com/gagliardetto/gofuzz" 20 | ag_require "github.com/stretchr/testify/require" 21 | "strconv" 22 | "testing" 23 | ) 24 | 25 | func TestEncodeDecode_InitializeAccount3(t *testing.T) { 26 | fu := ag_gofuzz.New().NilChance(0) 27 | for i := 0; i < 1; i++ { 28 | t.Run("InitializeAccount3"+strconv.Itoa(i), func(t *testing.T) { 29 | { 30 | params := new(InitializeAccount3) 31 | fu.Fuzz(params) 32 | params.AccountMetaSlice = nil 33 | buf := new(bytes.Buffer) 34 | err := encodeT(*params, buf) 35 | ag_require.NoError(t, err) 36 | // 37 | got := new(InitializeAccount3) 38 | err = decodeT(got, buf.Bytes()) 39 | got.AccountMetaSlice = nil 40 | ag_require.NoError(t, err) 41 | ag_require.Equal(t, params, got) 42 | } 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /programs/token/InitializeAccount_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | ag_gofuzz "github.com/gagliardetto/gofuzz" 20 | ag_require "github.com/stretchr/testify/require" 21 | "strconv" 22 | "testing" 23 | ) 24 | 25 | func TestEncodeDecode_InitializeAccount(t *testing.T) { 26 | fu := ag_gofuzz.New().NilChance(0) 27 | for i := 0; i < 1; i++ { 28 | t.Run("InitializeAccount"+strconv.Itoa(i), func(t *testing.T) { 29 | { 30 | params := new(InitializeAccount) 31 | fu.Fuzz(params) 32 | params.AccountMetaSlice = nil 33 | buf := new(bytes.Buffer) 34 | err := encodeT(*params, buf) 35 | ag_require.NoError(t, err) 36 | // 37 | got := new(InitializeAccount) 38 | err = decodeT(got, buf.Bytes()) 39 | got.AccountMetaSlice = nil 40 | ag_require.NoError(t, err) 41 | ag_require.Equal(t, params, got) 42 | } 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /programs/token/InitializeMint2_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | ag_gofuzz "github.com/gagliardetto/gofuzz" 20 | ag_require "github.com/stretchr/testify/require" 21 | "strconv" 22 | "testing" 23 | ) 24 | 25 | func TestEncodeDecode_InitializeMint2(t *testing.T) { 26 | fu := ag_gofuzz.New().NilChance(0) 27 | for i := 0; i < 1; i++ { 28 | t.Run("InitializeMint2"+strconv.Itoa(i), func(t *testing.T) { 29 | { 30 | params := new(InitializeMint2) 31 | fu.Fuzz(params) 32 | params.AccountMetaSlice = nil 33 | buf := new(bytes.Buffer) 34 | err := encodeT(*params, buf) 35 | ag_require.NoError(t, err) 36 | // 37 | got := new(InitializeMint2) 38 | err = decodeT(got, buf.Bytes()) 39 | got.AccountMetaSlice = nil 40 | ag_require.NoError(t, err) 41 | ag_require.Equal(t, params, got) 42 | } 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /programs/token/InitializeMint_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | ag_gofuzz "github.com/gagliardetto/gofuzz" 20 | ag_require "github.com/stretchr/testify/require" 21 | "strconv" 22 | "testing" 23 | ) 24 | 25 | func TestEncodeDecode_InitializeMint(t *testing.T) { 26 | fu := ag_gofuzz.New().NilChance(0) 27 | for i := 0; i < 1; i++ { 28 | t.Run("InitializeMint"+strconv.Itoa(i), func(t *testing.T) { 29 | { 30 | params := new(InitializeMint) 31 | fu.Fuzz(params) 32 | params.AccountMetaSlice = nil 33 | buf := new(bytes.Buffer) 34 | err := encodeT(*params, buf) 35 | ag_require.NoError(t, err) 36 | // 37 | got := new(InitializeMint) 38 | err = decodeT(got, buf.Bytes()) 39 | got.AccountMetaSlice = nil 40 | ag_require.NoError(t, err) 41 | ag_require.Equal(t, params, got) 42 | } 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /programs/token/MintToChecked_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_MintToChecked(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("MintToChecked"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(MintToChecked) 32 | fu.Fuzz(params) 33 | params.Accounts = nil 34 | params.Signers = nil 35 | buf := new(bytes.Buffer) 36 | err := encodeT(*params, buf) 37 | ag_require.NoError(t, err) 38 | // 39 | got := new(MintToChecked) 40 | err = decodeT(got, buf.Bytes()) 41 | params.Accounts = nil 42 | params.Signers = nil 43 | ag_require.NoError(t, err) 44 | ag_require.Equal(t, params, got) 45 | } 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /programs/token/MintTo_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_MintTo(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("MintTo"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(MintTo) 32 | fu.Fuzz(params) 33 | params.Accounts = nil 34 | params.Signers = nil 35 | buf := new(bytes.Buffer) 36 | err := encodeT(*params, buf) 37 | ag_require.NoError(t, err) 38 | // 39 | got := new(MintTo) 40 | err = decodeT(got, buf.Bytes()) 41 | params.Accounts = nil 42 | params.Signers = nil 43 | ag_require.NoError(t, err) 44 | ag_require.Equal(t, params, got) 45 | } 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /programs/token/Revoke_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_Revoke(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("Revoke"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(Revoke) 32 | fu.Fuzz(params) 33 | params.Accounts = nil 34 | params.Signers = nil 35 | buf := new(bytes.Buffer) 36 | err := encodeT(*params, buf) 37 | ag_require.NoError(t, err) 38 | // 39 | got := new(Revoke) 40 | err = decodeT(got, buf.Bytes()) 41 | params.Accounts = nil 42 | params.Signers = nil 43 | ag_require.NoError(t, err) 44 | ag_require.Equal(t, params, got) 45 | } 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /programs/token/SetAuthority_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_SetAuthority(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("SetAuthority"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(SetAuthority) 32 | fu.Fuzz(params) 33 | params.Accounts = nil 34 | params.Signers = nil 35 | buf := new(bytes.Buffer) 36 | err := encodeT(*params, buf) 37 | ag_require.NoError(t, err) 38 | // 39 | got := new(SetAuthority) 40 | err = decodeT(got, buf.Bytes()) 41 | params.Accounts = nil 42 | params.Signers = nil 43 | ag_require.NoError(t, err) 44 | ag_require.Equal(t, params, got) 45 | } 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /programs/token/SyncNative_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | ag_gofuzz "github.com/gagliardetto/gofuzz" 20 | ag_require "github.com/stretchr/testify/require" 21 | "strconv" 22 | "testing" 23 | ) 24 | 25 | func TestEncodeDecode_SyncNative(t *testing.T) { 26 | fu := ag_gofuzz.New().NilChance(0) 27 | for i := 0; i < 1; i++ { 28 | t.Run("SyncNative"+strconv.Itoa(i), func(t *testing.T) { 29 | { 30 | params := new(SyncNative) 31 | fu.Fuzz(params) 32 | params.AccountMetaSlice = nil 33 | buf := new(bytes.Buffer) 34 | err := encodeT(*params, buf) 35 | ag_require.NoError(t, err) 36 | // 37 | got := new(SyncNative) 38 | err = decodeT(got, buf.Bytes()) 39 | got.AccountMetaSlice = nil 40 | ag_require.NoError(t, err) 41 | ag_require.Equal(t, params, got) 42 | } 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /programs/token/ThawAccount_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_ThawAccount(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("ThawAccount"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(ThawAccount) 32 | fu.Fuzz(params) 33 | params.Accounts = nil 34 | params.Signers = nil 35 | buf := new(bytes.Buffer) 36 | err := encodeT(*params, buf) 37 | ag_require.NoError(t, err) 38 | // 39 | got := new(ThawAccount) 40 | err = decodeT(got, buf.Bytes()) 41 | params.Accounts = nil 42 | params.Signers = nil 43 | ag_require.NoError(t, err) 44 | ag_require.Equal(t, params, got) 45 | } 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /programs/token/TransferChecked_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_TransferChecked(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("TransferChecked"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(TransferChecked) 32 | fu.Fuzz(params) 33 | params.Accounts = nil 34 | params.Signers = nil 35 | buf := new(bytes.Buffer) 36 | err := encodeT(*params, buf) 37 | ag_require.NoError(t, err) 38 | // 39 | got := new(TransferChecked) 40 | err = decodeT(got, buf.Bytes()) 41 | params.Accounts = nil 42 | params.Signers = nil 43 | ag_require.NoError(t, err) 44 | ag_require.Equal(t, params, got) 45 | } 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /programs/token/Transfer_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "strconv" 20 | "testing" 21 | 22 | ag_gofuzz "github.com/gagliardetto/gofuzz" 23 | ag_require "github.com/stretchr/testify/require" 24 | ) 25 | 26 | func TestEncodeDecode_Transfer(t *testing.T) { 27 | fu := ag_gofuzz.New().NilChance(0) 28 | for i := 0; i < 1; i++ { 29 | t.Run("Transfer"+strconv.Itoa(i), func(t *testing.T) { 30 | { 31 | params := new(Transfer) 32 | fu.Fuzz(params) 33 | params.Accounts = nil 34 | params.Signers = nil 35 | buf := new(bytes.Buffer) 36 | err := encodeT(*params, buf) 37 | ag_require.NoError(t, err) 38 | // 39 | got := new(Transfer) 40 | err = decodeT(got, buf.Bytes()) 41 | got.Accounts = nil 42 | params.Signers = nil 43 | ag_require.NoError(t, err) 44 | ag_require.Equal(t, params, got) 45 | } 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /programs/token/json.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | jsoniter "github.com/json-iterator/go" 19 | ) 20 | 21 | var json = jsoniter.ConfigCompatibleWithStandardLibrary 22 | -------------------------------------------------------------------------------- /programs/token/testing_utils.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package token 16 | 17 | import ( 18 | "bytes" 19 | "fmt" 20 | ag_binary "github.com/gagliardetto/binary" 21 | ) 22 | 23 | func encodeT(data interface{}, buf *bytes.Buffer) error { 24 | if err := ag_binary.NewBinEncoder(buf).Encode(data); err != nil { 25 | return fmt.Errorf("unable to encode instruction: %w", err) 26 | } 27 | return nil 28 | } 29 | 30 | func decodeT(dst interface{}, data []byte) error { 31 | return ag_binary.NewBinDecoder(data).Decode(dst) 32 | } 33 | -------------------------------------------------------------------------------- /programs/tokenregistry/logging.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package tokenregistry 19 | 20 | import ( 21 | "github.com/streamingfast/logging" 22 | "go.uber.org/zap" 23 | ) 24 | 25 | var zlog = zap.NewNop() 26 | var traceEnabled = logging.IsTraceEnabled("solana-go", "github.com/gagliardetto/solana-go/program/tokenregistry") 27 | 28 | func init() { 29 | logging.Register("github.com/gagliardetto/solana-go/program/tokenregistry", &zlog) 30 | } 31 | -------------------------------------------------------------------------------- /registry_test.go: -------------------------------------------------------------------------------- 1 | package solana 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func TestRegisterInstructionDecoder(t *testing.T) { 10 | 11 | decoder := func(instructionAccounts []*AccountMeta, data []byte) (interface{}, error) { 12 | return nil, nil 13 | } 14 | decoderAnother := func(instructionAccounts []*AccountMeta, data []byte) (interface{}, error) { 15 | return nil, nil 16 | } 17 | 18 | assert.NotPanics(t, func() { 19 | RegisterInstructionDecoder(BPFLoaderProgramID, decoder) 20 | }) 21 | assert.NotPanics(t, func() { 22 | RegisterInstructionDecoder(BPFLoaderProgramID, decoder) 23 | }) 24 | assert.Panics(t, func() { 25 | RegisterInstructionDecoder(BPFLoaderProgramID, decoderAnother) 26 | }) 27 | } 28 | -------------------------------------------------------------------------------- /rpc/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | // rpc error: 18 | // - https://github.com/solana-labs/solana/blob/d5961e9d9f005966f409fbddd40c3651591b27fb/client/src/rpc_custom_error.rs 19 | 20 | // transaction error: 21 | // - https://github.com/solana-labs/solana/blob/8817f59b6e5ce26f578b0834dbfac5c7daa82fab/sdk/src/transaction.rs 22 | // - https://github.com/solana-labs/solana/blob/899b09872bd7c4af4d1c9c73f7b26d268af276eb/storage-proto/proto/transaction_by_addr.proto 23 | 24 | // instruction error 25 | // - https://github.com/solana-labs/solana/blob/f6371cce176d481b4132e5061262ca015db0f8b1/sdk/program/src/instruction.rs 26 | -------------------------------------------------------------------------------- /rpc/examples/getBlockCommitment/getBlockCommitment.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | example, err := client.GetRecentBlockhash(context.TODO(), rpc.CommitmentFinalized) 29 | if err != nil { 30 | panic(err) 31 | } 32 | 33 | out, err := client.GetBlockCommitment( 34 | context.TODO(), 35 | uint64(example.Context.Slot), 36 | ) 37 | if err != nil { 38 | panic(err) 39 | } 40 | spew.Dump(out) 41 | } 42 | -------------------------------------------------------------------------------- /rpc/examples/getBlockHeight/getBlockHeight.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetBlockHeight( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | spew.Dump(out) 36 | } 37 | -------------------------------------------------------------------------------- /rpc/examples/getBlockProduction/getBlockProduction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | { 29 | out, err := client.GetBlockProduction(context.TODO()) 30 | if err != nil { 31 | panic(err) 32 | } 33 | spew.Dump(out) 34 | } 35 | { 36 | out, err := client.GetBlockProductionWithOpts( 37 | context.TODO(), 38 | &rpc.GetBlockProductionOpts{ 39 | Commitment: rpc.CommitmentFinalized, 40 | // Range: &rpc.SlotRangeRequest{ 41 | // FirstSlot: XXXXXX, 42 | // Identity: solana.MustPublicKeyFromBase58("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"), 43 | // }, 44 | }, 45 | ) 46 | if err != nil { 47 | panic(err) 48 | } 49 | spew.Dump(out) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /rpc/examples/getBlockTime/getBlockTime.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | "time" 20 | 21 | "github.com/davecgh/go-spew/spew" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.TestNet_RPC 27 | client := rpc.New(endpoint) 28 | 29 | example, err := client.GetRecentBlockhash( 30 | context.TODO(), 31 | rpc.CommitmentFinalized, 32 | ) 33 | if err != nil { 34 | panic(err) 35 | } 36 | 37 | out, err := client.GetBlockTime( 38 | context.TODO(), 39 | uint64(example.Context.Slot), 40 | ) 41 | if err != nil { 42 | panic(err) 43 | } 44 | spew.Dump(out) 45 | spew.Dump(out.Time().Format(time.RFC1123)) 46 | } 47 | -------------------------------------------------------------------------------- /rpc/examples/getBlocks/getBlocks.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | example, err := client.GetRecentBlockhash( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | 36 | endSlot := uint64(example.Context.Slot) 37 | out, err := client.GetBlocks( 38 | context.TODO(), 39 | uint64(example.Context.Slot-3), 40 | &endSlot, 41 | rpc.CommitmentFinalized, 42 | ) 43 | if err != nil { 44 | panic(err) 45 | } 46 | spew.Dump(out) 47 | } 48 | -------------------------------------------------------------------------------- /rpc/examples/getBlocksWithLimit/getBlocksWithLimit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | example, err := client.GetRecentBlockhash( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | 36 | limit := uint64(4) 37 | out, err := client.GetBlocksWithLimit( 38 | context.TODO(), 39 | uint64(example.Context.Slot-10), 40 | limit, 41 | rpc.CommitmentFinalized, 42 | ) 43 | if err != nil { 44 | panic(err) 45 | } 46 | spew.Dump(out) 47 | } 48 | -------------------------------------------------------------------------------- /rpc/examples/getClusterNodes/getClusterNodes.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetClusterNodes( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/getConfirmedBlocks/getConfirmedBlocks.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | example, err := client.GetRecentBlockhash( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | 36 | { 37 | endSlot := uint64(example.Context.Slot) 38 | // deprecated and is going to be removed in solana-core v1.8 39 | out, err := client.GetConfirmedBlocks( 40 | context.TODO(), 41 | uint64(example.Context.Slot-3), 42 | &endSlot, 43 | rpc.CommitmentFinalized, 44 | ) 45 | if err != nil { 46 | panic(err) 47 | } 48 | spew.Dump(out) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /rpc/examples/getConfirmedBlocksWithLimit/getConfirmedBlocksWithLimit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | example, err := client.GetRecentBlockhash( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | 36 | limit := uint64(3) 37 | { // deprecated and is going to be removed in solana-core v1.8 38 | out, err := client.GetConfirmedBlocksWithLimit( 39 | context.TODO(), 40 | uint64(example.Context.Slot-10), 41 | limit, 42 | rpc.CommitmentFinalized, 43 | ) 44 | if err != nil { 45 | panic(err) 46 | } 47 | spew.Dump(out) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /rpc/examples/getConfirmedSignaturesForAddress2/getConfirmedSignaturesForAddress2.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.TestNet_RPC 27 | client := rpc.New(endpoint) 28 | 29 | pubKey := solana.MustPublicKeyFromBase58("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt") // serum token 30 | { 31 | // deprecated and is going to be removed in solana-core v1.8 32 | out, err := client.GetConfirmedSignaturesForAddress2( 33 | context.TODO(), 34 | pubKey, 35 | // TODO: 36 | nil, 37 | ) 38 | if err != nil { 39 | panic(err) 40 | } 41 | spew.Dump(out) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /rpc/examples/getConfirmedTransaction/getConfirmedTransaction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.TestNet_RPC 27 | client := rpc.New(endpoint) 28 | 29 | pubKey := solana.MustPublicKeyFromBase58("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt") // serum token 30 | // Let's get a valid transaction to use in the example: 31 | example, err := client.GetConfirmedSignaturesForAddress2( 32 | context.TODO(), 33 | pubKey, 34 | nil, 35 | ) 36 | if err != nil { 37 | panic(err) 38 | } 39 | 40 | out, err := client.GetConfirmedTransaction( 41 | context.TODO(), 42 | example[0].Signature, 43 | ) 44 | if err != nil { 45 | panic(err) 46 | } 47 | spew.Dump(out) 48 | } 49 | -------------------------------------------------------------------------------- /rpc/examples/getEpochInfo/getEpochInfo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetEpochInfo( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | spew.Dump(out) 36 | } 37 | -------------------------------------------------------------------------------- /rpc/examples/getEpochSchedule/getEpochSchedule.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetEpochSchedule( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/getFeeCalculatorForBlockhash/getFeeCalculatorForBlockhash.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | example, err := client.GetRecentBlockhash( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | 36 | out, err := client.GetFeeCalculatorForBlockhash( 37 | context.TODO(), 38 | example.Value.Blockhash, 39 | rpc.CommitmentFinalized, 40 | ) 41 | if err != nil { 42 | panic(err) 43 | } 44 | spew.Dump(out) 45 | } 46 | -------------------------------------------------------------------------------- /rpc/examples/getFeeForMessage/getFeeForMessage.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | example, err := client.GetFeeForMessage( 29 | context.Background(), 30 | "AQABAgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAQAA", 31 | rpc.CommitmentProcessed, 32 | ) 33 | if err != nil { 34 | panic(err) 35 | } 36 | spew.Dump(example) 37 | } 38 | -------------------------------------------------------------------------------- /rpc/examples/getFeeRateGovernor/getFeeRateGovernor.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetFeeRateGovernor( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/getFees/getFees.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetFees( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | spew.Dump(out) 36 | } 37 | -------------------------------------------------------------------------------- /rpc/examples/getFirstAvailableBlock/getFirstAvailableBlock.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetFirstAvailableBlock( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/getGenesisHash/getGenesisHash.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetGenesisHash( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/getHealth/getHealth.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetHealth( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) 35 | spew.Dump(out == rpc.HealthOk) 36 | } 37 | -------------------------------------------------------------------------------- /rpc/examples/getHighestSnapshotSlot/getHighestSnapshotSlot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | example, err := client.GetHighestSnapshotSlot( 29 | context.Background(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(example) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/getIdentity/getIdentity.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetIdentity( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/getInflationGovernor/getInflationGovernor.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetInflationGovernor( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | spew.Dump(out) 36 | } 37 | -------------------------------------------------------------------------------- /rpc/examples/getInflationRate/getInflationRate.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetInflationRate( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/getInflationReward/getInflationReward.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.TestNet_RPC 27 | client := rpc.New(endpoint) 28 | 29 | pubKey := solana.MustPublicKeyFromBase58("6dmNQ5jwLeLk5REvio1JcMshcbvkYMwy26sJ8pbkvStu") 30 | 31 | out, err := client.GetInflationReward( 32 | context.TODO(), 33 | []solana.PublicKey{ 34 | pubKey, 35 | }, 36 | &rpc.GetInflationRewardOpts{ 37 | Commitment: rpc.CommitmentFinalized, 38 | }, 39 | ) 40 | if err != nil { 41 | panic(err) 42 | } 43 | spew.Dump(out) 44 | } 45 | -------------------------------------------------------------------------------- /rpc/examples/getLargestAccounts/getLargestAccounts.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetLargestAccounts( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | rpc.LargestAccountsFilterCirculating, 32 | ) 33 | if err != nil { 34 | panic(err) 35 | } 36 | spew.Dump(out) 37 | } 38 | -------------------------------------------------------------------------------- /rpc/examples/getLatestBlockhash/getLatestBlockhash.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | example, err := client.GetLatestBlockhash( 29 | context.Background(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | spew.Dump(example) 36 | } 37 | -------------------------------------------------------------------------------- /rpc/examples/getLeaderSchedule/getLeaderSchedule.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetLeaderSchedule( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) // NOTE: this creates a lot of output 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/getMaxRetransmitSlot/getMaxRetransmitSlot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetMaxRetransmitSlot( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/getMaxShredInsertSlot/getMaxShredInsertSlot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetMaxShredInsertSlot( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/getMinimumBalanceForRentExemption/getMinimumBalanceForRentExemption.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | dataSize := uint64(1024 * 9) 29 | out, err := client.GetMinimumBalanceForRentExemption( 30 | context.TODO(), 31 | dataSize, 32 | rpc.CommitmentFinalized, 33 | ) 34 | if err != nil { 35 | panic(err) 36 | } 37 | spew.Dump(out) 38 | } 39 | -------------------------------------------------------------------------------- /rpc/examples/getProgramAccounts/getProgramAccounts.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.TestNet_RPC 27 | client := rpc.New(endpoint) 28 | 29 | out, err := client.GetProgramAccounts( 30 | context.TODO(), 31 | solana.MustPublicKeyFromBase58("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"), 32 | ) 33 | if err != nil { 34 | panic(err) 35 | } 36 | spew.Dump(len(out)) 37 | spew.Dump(out) // NOTE: this can generate a lot of output 38 | } 39 | -------------------------------------------------------------------------------- /rpc/examples/getRecentBlockhash/getRecentBlockhash.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | recent, err := client.GetRecentBlockhash( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | spew.Dump(recent) 36 | } 37 | -------------------------------------------------------------------------------- /rpc/examples/getRecentPerformanceSamples/getRecentPerformanceSamples.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | limit := uint(3) 29 | out, err := client.GetRecentPerformanceSamples( 30 | context.TODO(), 31 | &limit, 32 | ) 33 | if err != nil { 34 | panic(err) 35 | } 36 | spew.Dump(out) 37 | } 38 | -------------------------------------------------------------------------------- /rpc/examples/getSignatureStatuses/getSignatureStatuses.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.TestNet_RPC 27 | client := rpc.New(endpoint) 28 | 29 | out, err := client.GetSignatureStatuses( 30 | context.TODO(), 31 | true, 32 | // All the transactions you want the get the status for: 33 | solana.MustSignatureFromBase58("2CwH8SqVZWFa1EvsH7vJXGFors1NdCuWJ7Z85F8YqjCLQ2RuSHQyeGKkfo1Tj9HitSTeLoMWnxpjxF2WsCH8nGWh"), 34 | solana.MustSignatureFromBase58("5YJHZPeHZuZjhunBc1CCB1NDRNf2tTJNpdb3azGsR7PfyEncCDhr95wG8EWrvjNXBc4wCKixkheSbCxoC2NCG3X7"), 35 | ) 36 | if err != nil { 37 | panic(err) 38 | } 39 | spew.Dump(out) 40 | } 41 | -------------------------------------------------------------------------------- /rpc/examples/getSignaturesForAddress/getSignaturesForAddress.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.TestNet_RPC 27 | client := rpc.New(endpoint) 28 | 29 | out, err := client.GetSignaturesForAddress( 30 | context.TODO(), 31 | solana.MustPublicKeyFromBase58("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"), 32 | ) 33 | if err != nil { 34 | panic(err) 35 | } 36 | spew.Dump(out) 37 | } 38 | -------------------------------------------------------------------------------- /rpc/examples/getSlot/getSlot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetSlot( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | spew.Dump(out) 36 | } 37 | -------------------------------------------------------------------------------- /rpc/examples/getSlotLeader/getSlotLeader.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetSlotLeader( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | spew.Dump(out) 36 | } 37 | -------------------------------------------------------------------------------- /rpc/examples/getSlotLeaders/getSlotLeaders.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | recent, err := client.GetRecentBlockhash( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | 36 | out, err := client.GetSlotLeaders( 37 | context.TODO(), 38 | uint64(recent.Context.Slot), 39 | 10, 40 | ) 41 | if err != nil { 42 | panic(err) 43 | } 44 | spew.Dump(out) 45 | } 46 | -------------------------------------------------------------------------------- /rpc/examples/getSnapshotSlot/getSnapshotSlot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetSnapshotSlot( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/getStakeActivation/getStakeActivation.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.TestNet_RPC 27 | client := rpc.New(endpoint) 28 | 29 | pubKey := solana.MustPublicKeyFromBase58("EW2p7QCJNHMVj5nQCcW7Q2BDETtNBXn68FyucU4RCjvb") 30 | out, err := client.GetStakeActivation( 31 | context.TODO(), 32 | pubKey, 33 | rpc.CommitmentFinalized, 34 | nil, 35 | ) 36 | if err != nil { 37 | panic(err) 38 | } 39 | spew.Dump(out) 40 | } 41 | -------------------------------------------------------------------------------- /rpc/examples/getSupply/getSupply.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetSupply(context.TODO(), rpc.CommitmentFinalized) 29 | if err != nil { 30 | panic(err) 31 | } 32 | spew.Dump(out) 33 | } 34 | -------------------------------------------------------------------------------- /rpc/examples/getTokenAccountBalance/getTokenAccountBalance.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.TestNet_RPC 27 | client := rpc.New(endpoint) 28 | 29 | pubKey := solana.MustPublicKeyFromBase58("EzK5qLWhftu8Z2znVa5fozVtobbjhd8Gdu9hQHpC8bec") 30 | out, err := client.GetTokenAccountBalance( 31 | context.TODO(), 32 | pubKey, 33 | rpc.CommitmentFinalized, 34 | ) 35 | if err != nil { 36 | panic(err) 37 | } 38 | spew.Dump(out) 39 | } 40 | -------------------------------------------------------------------------------- /rpc/examples/getTokenAccountsByDelegate/getTokenAccountsByDelegate.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.TestNet_RPC 27 | client := rpc.New(endpoint) 28 | 29 | pubKey := solana.MustPublicKeyFromBase58("AfkALUPjQp8R1rUwE6KhT38NuTYWCncwwHwcJu7UtAfV") 30 | out, err := client.GetTokenAccountsByDelegate( 31 | context.TODO(), 32 | pubKey, 33 | &rpc.GetTokenAccountsConfig{ 34 | Mint: solana.MustPublicKeyFromBase58("So11111111111111111111111111111111111111112").ToPointer(), 35 | }, 36 | nil, 37 | ) 38 | if err != nil { 39 | panic(err) 40 | } 41 | spew.Dump(out) 42 | } 43 | -------------------------------------------------------------------------------- /rpc/examples/getTokenLargestAccounts/getTokenLargestAccounts.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.MainNetBeta_RPC 27 | client := rpc.New(endpoint) 28 | 29 | pubKey := solana.MustPublicKeyFromBase58("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt") // serum token 30 | out, err := client.GetTokenLargestAccounts( 31 | context.TODO(), 32 | pubKey, 33 | rpc.CommitmentFinalized, 34 | ) 35 | if err != nil { 36 | panic(err) 37 | } 38 | spew.Dump(out) 39 | } 40 | -------------------------------------------------------------------------------- /rpc/examples/getTokenSupply/getTokenSupply.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.MainNetBeta_RPC 27 | client := rpc.New(endpoint) 28 | 29 | pubKey := solana.MustPublicKeyFromBase58("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt") // serum token 30 | out, err := client.GetTokenSupply( 31 | context.TODO(), 32 | pubKey, 33 | rpc.CommitmentFinalized, 34 | ) 35 | if err != nil { 36 | panic(err) 37 | } 38 | spew.Dump(out) 39 | } 40 | -------------------------------------------------------------------------------- /rpc/examples/getTransactionCount/getTransactionCount.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetTransactionCount( 29 | context.TODO(), 30 | rpc.CommitmentFinalized, 31 | ) 32 | if err != nil { 33 | panic(err) 34 | } 35 | spew.Dump(out) 36 | } 37 | -------------------------------------------------------------------------------- /rpc/examples/getVersion/getVersion.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.GetVersion( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/getVoteAccounts/getVoteAccounts.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.TestNet_RPC 27 | client := rpc.New(endpoint) 28 | 29 | out, err := client.GetVoteAccounts( 30 | context.TODO(), 31 | &rpc.GetVoteAccountsOpts{ 32 | VotePubkey: solana.MustPublicKeyFromBase58("vot33MHDqT6nSwubGzqtc6m16ChcUywxV7tNULF19Vu").ToPointer(), 33 | }, 34 | ) 35 | if err != nil { 36 | panic(err) 37 | } 38 | spew.Dump(out) 39 | } 40 | -------------------------------------------------------------------------------- /rpc/examples/isBlockhashValid/isValidBlockhash.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | "fmt" 20 | 21 | "github.com/davecgh/go-spew/spew" 22 | "github.com/gagliardetto/solana-go" 23 | "github.com/gagliardetto/solana-go/rpc" 24 | ) 25 | 26 | func main() { 27 | endpoint := rpc.MainNetBeta_RPC 28 | client := rpc.New(endpoint) 29 | 30 | blockHash := solana.MustHashFromBase58("J7rBdM6AecPDEZp8aPq5iPSNKVkU5Q76F3oAV4eW5wsW") 31 | out, err := client.IsBlockhashValid( 32 | context.TODO(), 33 | blockHash, 34 | rpc.CommitmentFinalized, 35 | ) 36 | if err != nil { 37 | panic(err) 38 | } 39 | spew.Dump(out) 40 | spew.Dump(out.Value) // true or false 41 | 42 | fmt.Println("is blockhash valid:", out.Value) 43 | } 44 | -------------------------------------------------------------------------------- /rpc/examples/minimumLedgerSlot/minimumLedgerSlot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | 28 | out, err := client.MinimumLedgerSlot( 29 | context.TODO(), 30 | ) 31 | if err != nil { 32 | panic(err) 33 | } 34 | spew.Dump(out) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/requestAirdrop/requestAirdrop.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.TestNet_RPC 27 | client := rpc.New(endpoint) 28 | 29 | amount := solana.LAMPORTS_PER_SOL // 1 sol 30 | pubKey := solana.MustPublicKeyFromBase58("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") 31 | out, err := client.RequestAirdrop( 32 | context.TODO(), 33 | pubKey, 34 | amount, 35 | "", 36 | ) 37 | if err != nil { 38 | panic(err) 39 | } 40 | spew.Dump(out) 41 | } 42 | -------------------------------------------------------------------------------- /rpc/examples/sendEncodedTransaction/sendEncodedTransaction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | "fmt" 20 | 21 | "github.com/gagliardetto/solana-go/rpc" 22 | ) 23 | 24 | func main() { 25 | endpoint := rpc.TestNet_RPC 26 | client := rpc.New(endpoint) 27 | base64Tx := "AepZ357SXFu9tOBeX8v8aqkPNyGq/RUN4EvDzWAT/Fsg1htQu0Zp6F6OxO645I5z98VI4XacPKJp8rtHOE7Q9Q0BAAED8gJOoYf0IvSirfhOq6ZFf3R3ekB5vFWlaGTEq3irvwFakK+tD9il+9jzzs+gU1wzZxkmXZqyeBhbaXogNlk1GQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAou6RU2rKBCg2RzcJqZwEr4y2VBsWbkYLYMKFcOz64j4BAgIAAQwCAAAAAOH1BQAAAAA=" 28 | 29 | sig, err := client.SendEncodedTransaction(context.TODO(), base64Tx) 30 | if err != nil { 31 | panic(err) 32 | } 33 | 34 | fmt.Println("Submitted tx signature: ", sig.String()) 35 | } 36 | -------------------------------------------------------------------------------- /rpc/examples/sendRawTransaction/sendRawTransaction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | "encoding/base64" 20 | "fmt" 21 | 22 | "github.com/gagliardetto/solana-go/rpc" 23 | ) 24 | 25 | func main() { 26 | endpoint := rpc.TestNet_RPC 27 | client := rpc.New(endpoint) 28 | base64Tx := "AfjEs3XhTc3hrxEvlnMPkm/cocvAUbFNbCl00qKnrFue6J53AhEqIFmcJJlJW3EDP5RmcMz+cNTTcZHW/WJYwAcBAAEDO8hh4VddzfcO5jbCt95jryl6y8ff65UcgukHNLWH+UQGgxCGGpgyfQVQV02EQYqm4QwzUt2qf9f1gVLM7rI4hwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA6ANIF55zOZWROWRkeh+lExxZBnKFqbvIxZDLE7EijjoBAgIAAQwCAAAAOTAAAAAAAAA=" 29 | 30 | txRaw, err := base64.StdEncoding.DecodeString(base64Tx) 31 | if err != nil { 32 | panic(err) 33 | } 34 | 35 | sig, err := client.SendRawTransaction(context.TODO(), txRaw) 36 | if err != nil { 37 | panic(err) 38 | } 39 | 40 | fmt.Println("Submitted tx signature: ", sig.String()) 41 | } 42 | -------------------------------------------------------------------------------- /rpc/examples/simulateTransaction/simulateTransaction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | func main() { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /rpc/getBalance.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | package rpc 18 | 19 | import ( 20 | "context" 21 | 22 | "github.com/gagliardetto/solana-go" 23 | ) 24 | 25 | // GetBalance returns the balance of the account of provided publicKey. 26 | func (cl *Client) GetBalance( 27 | ctx context.Context, 28 | 29 | // Pubkey of account to query. Required. 30 | publicKey solana.PublicKey, 31 | 32 | // Commitment requirement. Optional. 33 | commitment CommitmentType, 34 | ) (out *GetBalanceResult, err error) { 35 | params := []interface{}{publicKey} 36 | if commitment != "" { 37 | params = append(params, M{"commitment": string(commitment)}) 38 | } 39 | 40 | err = cl.rpcClient.CallForInto(ctx, &out, "getBalance", params) 41 | return 42 | } 43 | -------------------------------------------------------------------------------- /rpc/getBlockCommitment.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // GetBlockCommitment returns commitment for particular block. 22 | func (cl *Client) GetBlockCommitment( 23 | ctx context.Context, 24 | block uint64, // block, identified by Slot 25 | ) (out *GetBlockCommitmentResult, err error) { 26 | params := []interface{}{block} 27 | err = cl.rpcClient.CallForInto(ctx, &out, "getBlockCommitment", params) 28 | return 29 | } 30 | 31 | type GetBlockCommitmentResult struct { 32 | // nil if Unknown block, or array of u64 integers 33 | // logging the amount of cluster stake in lamports 34 | // that has voted on the block at each depth from 0 to `MAX_LOCKOUT_HISTORY` + 1 35 | Commitment []uint64 `json:"commitment"` 36 | 37 | // Total active stake, in lamports, of the current epoch. 38 | TotalStake uint64 `json:"totalStake"` 39 | } 40 | -------------------------------------------------------------------------------- /rpc/getBlockHeight.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // GetBlockHeight returns the current block height of the node. 22 | func (cl *Client) GetBlockHeight( 23 | ctx context.Context, 24 | commitment CommitmentType, // optional 25 | ) (out uint64, err error) { 26 | params := []interface{}{} 27 | if commitment != "" { 28 | params = append(params, M{"commitment": commitment}) 29 | } 30 | err = cl.rpcClient.CallForInto(ctx, &out, "getBlockHeight", params) 31 | return 32 | } 33 | -------------------------------------------------------------------------------- /rpc/getBlocksWithLimit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // GetBlocksWithLimit returns a list of confirmed blocks starting at the given slot. 22 | // The result field will be an array of u64 integers listing 23 | // confirmed blocks starting at startSlot for up to limit blocks, inclusive. 24 | func (cl *Client) GetBlocksWithLimit( 25 | ctx context.Context, 26 | startSlot uint64, 27 | limit uint64, 28 | commitment CommitmentType, // optional; "processed" is not supported. If parameter not provided, the default is "finalized". 29 | ) (out *BlocksResult, err error) { 30 | params := []interface{}{startSlot, limit} 31 | if commitment != "" { 32 | params = append(params, 33 | // TODO: provide commitment as string instead of object? 34 | M{"commitment": commitment}, 35 | ) 36 | } 37 | err = cl.rpcClient.CallForInto(ctx, &out, "getBlocksWithLimit", params) 38 | return 39 | } 40 | -------------------------------------------------------------------------------- /rpc/getFeeForMessage.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // Get the fee the network will charge for a particular Message. 22 | // 23 | // **NEW**: This method is only available in solana-core v1.9 or newer. Please use 24 | // `getFees` for solana-core v1.8. 25 | func (cl *Client) GetFeeForMessage( 26 | ctx context.Context, 27 | message string, // Base-64 encoded Message 28 | commitment CommitmentType, // optional 29 | ) (out *GetFeeForMessageResult, err error) { 30 | params := []interface{}{message} 31 | if commitment != "" { 32 | params = append(params, M{"commitment": commitment}) 33 | } 34 | err = cl.rpcClient.CallForInto(ctx, &out, "getFeeForMessage", params) 35 | return 36 | } 37 | 38 | type GetFeeForMessageResult struct { 39 | RPCContext 40 | 41 | // Fee corresponding to the message at the specified blockhash. 42 | Value *uint64 `json:"value"` 43 | } 44 | -------------------------------------------------------------------------------- /rpc/getFirstAvailableBlock.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // GetFirstAvailableBlock returns the slot of the lowest confirmed block that has not been purged from the ledger. 22 | func (cl *Client) GetFirstAvailableBlock(ctx context.Context) (out uint64, err error) { 23 | err = cl.rpcClient.CallForInto(ctx, &out, "getFirstAvailableBlock", nil) 24 | return 25 | } 26 | -------------------------------------------------------------------------------- /rpc/getGenesisHash.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/gagliardetto/solana-go" 21 | ) 22 | 23 | // GetGenesisHash returns the genesis hash. 24 | func (cl *Client) GetGenesisHash(ctx context.Context) (out solana.Hash, err error) { 25 | err = cl.rpcClient.CallForInto(ctx, &out, "getGenesisHash", nil) 26 | return 27 | } 28 | -------------------------------------------------------------------------------- /rpc/getHealth.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // GetHealth returns the current health of the node. 22 | // If one or more --trusted-validator arguments are provided 23 | // to solana-validator, "ok" is returned when the node has within 24 | // HEALTH_CHECK_SLOT_DISTANCE slots of the highest trusted validator, 25 | // otherwise an error is returned. "ok" is always returned if no 26 | // trusted validators are provided. 27 | // 28 | // - If the node is healthy: "ok" 29 | // - If the node is unhealthy, a JSON RPC error response is returned. 30 | // The specifics of the error response are UNSTABLE and may change in the future. 31 | func (cl *Client) GetHealth(ctx context.Context) (out string, err error) { 32 | err = cl.rpcClient.CallForInto(ctx, &out, "getHealth", nil) 33 | return 34 | } 35 | 36 | const HealthOk = "ok" 37 | -------------------------------------------------------------------------------- /rpc/getHighestSnapshotSlot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // Returns the highest slot information that the node has snapshots for. 22 | // This will find the highest full snapshot slot, and the highest incremental 23 | // snapshot slot _based on_ the full snapshot slot, if there is one. 24 | // 25 | // **NEW: This method is only available in solana-core v1.9 or newer. Please use 26 | // `getSnapshotSlot` for solana-core v1.8** 27 | func (cl *Client) GetHighestSnapshotSlot(ctx context.Context) (out *GetHighestSnapshotSlotResult, err error) { 28 | err = cl.rpcClient.CallForInto(ctx, &out, "getHighestSnapshotSlot", nil) 29 | return 30 | } 31 | 32 | type GetHighestSnapshotSlotResult struct { 33 | Full uint64 `json:"full"` // Highest full snapshot slot. 34 | Incremental *uint64 `json:"incremental,omitempty"` // Highest incremental snapshot slot based on full. 35 | } 36 | -------------------------------------------------------------------------------- /rpc/getIdentity.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/gagliardetto/solana-go" 21 | ) 22 | 23 | // GetIdentity returns the identity pubkey for the current node. 24 | func (cl *Client) GetIdentity(ctx context.Context) (out *GetIdentityResult, err error) { 25 | err = cl.rpcClient.CallForInto(ctx, &out, "getIdentity", nil) 26 | return 27 | } 28 | 29 | type GetIdentityResult struct { 30 | // The identity pubkey of the current node. 31 | Identity solana.PublicKey `json:"identity"` 32 | } 33 | -------------------------------------------------------------------------------- /rpc/getInflationRate.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // GetInflationRate returns the specific inflation values for the current epoch. 22 | func (cl *Client) GetInflationRate(ctx context.Context) (out *GetInflationRateResult, err error) { 23 | err = cl.rpcClient.CallForInto(ctx, &out, "getInflationRate", nil) 24 | return 25 | } 26 | 27 | type GetInflationRateResult struct { 28 | // Total inflation. 29 | Total float64 `json:"total"` 30 | 31 | // Inflation allocated to validators. 32 | Validator float64 `json:"validator"` 33 | 34 | // Inflation allocated to the foundation. 35 | Foundation float64 `json:"foundation"` 36 | 37 | // Epoch for which these values are valid. 38 | Epoch float64 `json:"epoch"` 39 | } 40 | -------------------------------------------------------------------------------- /rpc/getMaxRetransmitSlot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // GetMaxRetransmitSlot returns the max slot seen from retransmit stage. 22 | func (cl *Client) GetMaxRetransmitSlot(ctx context.Context) (out uint64, err error) { 23 | err = cl.rpcClient.CallForInto(ctx, &out, "getMaxRetransmitSlot", nil) 24 | return 25 | } 26 | -------------------------------------------------------------------------------- /rpc/getMaxShredInsertSlot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // GetMaxShredInsertSlot returns the max slot seen from after shred insert. 22 | func (cl *Client) GetMaxShredInsertSlot(ctx context.Context) (out uint64, err error) { 23 | err = cl.rpcClient.CallForInto(ctx, &out, "getMaxShredInsertSlot", nil) 24 | return 25 | } 26 | -------------------------------------------------------------------------------- /rpc/getMinimumBalanceForRentExemption.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | package rpc 18 | 19 | import ( 20 | "context" 21 | ) 22 | 23 | // GetMinimumBalanceForRentExemption returns minimum balance required to make account rent exempt. 24 | func (cl *Client) GetMinimumBalanceForRentExemption( 25 | ctx context.Context, 26 | dataSize uint64, 27 | commitment CommitmentType, // optional 28 | ) (lamport uint64, err error) { 29 | params := []interface{}{dataSize} 30 | if commitment != "" { 31 | params = append(params, M{"commitment": commitment}) 32 | } 33 | err = cl.rpcClient.CallForInto(ctx, &lamport, "getMinimumBalanceForRentExemption", params) 34 | return 35 | } 36 | -------------------------------------------------------------------------------- /rpc/getRecentBlockhash.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | package rpc 18 | 19 | import ( 20 | "context" 21 | ) 22 | 23 | // GetRecentBlockhash returns a recent block hash from the ledger, 24 | // and a fee schedule that can be used to compute the cost of submitting a transaction using it. 25 | func (cl *Client) GetRecentBlockhash( 26 | ctx context.Context, 27 | commitment CommitmentType, // optional 28 | ) (out *GetRecentBlockhashResult, err error) { 29 | params := []interface{}{} 30 | if commitment != "" { 31 | params = append(params, M{"commitment": commitment}) 32 | } 33 | 34 | err = cl.rpcClient.CallForInto(ctx, &out, "getRecentBlockhash", params) 35 | return 36 | } 37 | -------------------------------------------------------------------------------- /rpc/getSlot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | package rpc 18 | 19 | import ( 20 | "context" 21 | ) 22 | 23 | // GetSlot returns the slot that has reached the given or default commitment level. 24 | func (cl *Client) GetSlot( 25 | ctx context.Context, 26 | commitment CommitmentType, // optional 27 | ) (out uint64, err error) { 28 | params := []interface{}{} 29 | if commitment != "" { 30 | params = append(params, M{"commitment": commitment}) 31 | } 32 | 33 | err = cl.rpcClient.CallForInto(ctx, &out, "getSlot", params) 34 | return 35 | } 36 | -------------------------------------------------------------------------------- /rpc/getSlotLeader.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/gagliardetto/solana-go" 21 | ) 22 | 23 | // GetSlotLeader returns the current slot leader. 24 | func (cl *Client) GetSlotLeader( 25 | ctx context.Context, 26 | commitment CommitmentType, // optional 27 | ) (out solana.PublicKey, err error) { 28 | params := []interface{}{} 29 | if commitment != "" { 30 | params = append(params, M{"commitment": commitment}) 31 | } 32 | err = cl.rpcClient.CallForInto(ctx, &out, "getSlotLeader", params) 33 | return 34 | } 35 | -------------------------------------------------------------------------------- /rpc/getSlotLeaders.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/gagliardetto/solana-go" 21 | ) 22 | 23 | // GetSlotLeaders returns the slot leaders for a given slot range. 24 | func (cl *Client) GetSlotLeaders( 25 | ctx context.Context, 26 | start uint64, 27 | limit uint64, 28 | ) (out []solana.PublicKey, err error) { 29 | params := []interface{}{start, limit} 30 | err = cl.rpcClient.CallForInto(ctx, &out, "getSlotLeaders", params) 31 | return 32 | } 33 | -------------------------------------------------------------------------------- /rpc/getSnapshotSlot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // GetSnapshotSlot returns the highest slot that the node has a snapshot for. 22 | func (cl *Client) GetSnapshotSlot(ctx context.Context) (out uint64, err error) { 23 | err = cl.rpcClient.CallForInto(ctx, &out, "getSnapshotSlot", nil) 24 | return 25 | } 26 | -------------------------------------------------------------------------------- /rpc/getTokenAccountBalance.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/gagliardetto/solana-go" 21 | ) 22 | 23 | // GetTokenAccountBalance returns the token balance of an SPL Token account. 24 | func (cl *Client) GetTokenAccountBalance( 25 | ctx context.Context, 26 | account solana.PublicKey, 27 | commitment CommitmentType, // optional 28 | ) (out *GetTokenAccountBalanceResult, err error) { 29 | params := []interface{}{account} 30 | if commitment != "" { 31 | params = append(params, 32 | M{"commitment": commitment}, 33 | ) 34 | } 35 | err = cl.rpcClient.CallForInto(ctx, &out, "getTokenAccountBalance", params) 36 | return 37 | } 38 | 39 | type GetTokenAccountBalanceResult struct { 40 | RPCContext 41 | Value *UiTokenAmount `json:"value"` 42 | } 43 | -------------------------------------------------------------------------------- /rpc/getTokenSupply.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/gagliardetto/solana-go" 21 | ) 22 | 23 | // GetTokenSupply returns the total supply of an SPL Token type. 24 | func (cl *Client) GetTokenSupply( 25 | ctx context.Context, 26 | tokenMint solana.PublicKey, // Pubkey of token Mint to query 27 | commitment CommitmentType, // optional 28 | ) (out *GetTokenSupplyResult, err error) { 29 | params := []interface{}{tokenMint} 30 | if commitment != "" { 31 | params = append(params, 32 | M{"commitment": commitment}, 33 | ) 34 | } 35 | err = cl.rpcClient.CallForInto(ctx, &out, "getTokenSupply", params) 36 | return 37 | } 38 | 39 | type GetTokenSupplyResult struct { 40 | RPCContext 41 | Value *UiTokenAmount `json:"value"` 42 | } 43 | -------------------------------------------------------------------------------- /rpc/getTransactionCount.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // GetTransactionCount returns the current Transaction count from the ledger. 22 | func (cl *Client) GetTransactionCount( 23 | ctx context.Context, 24 | commitment CommitmentType, // optional 25 | ) (out uint64, err error) { 26 | params := []interface{}{} 27 | if commitment != "" { 28 | params = append(params, 29 | M{"commitment": commitment}, 30 | ) 31 | } 32 | err = cl.rpcClient.CallForInto(ctx, &out, "getTransactionCount", params) 33 | return 34 | } 35 | -------------------------------------------------------------------------------- /rpc/getVersion.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // GetVersion returns the current solana versions running on the node. 22 | func (cl *Client) GetVersion(ctx context.Context) (out *GetVersionResult, err error) { 23 | err = cl.rpcClient.CallForInto(ctx, &out, "getVersion", nil) 24 | return 25 | } 26 | 27 | type GetVersionResult struct { 28 | // Software version of solana-core. 29 | SolanaCore string `json:"solana-core"` 30 | 31 | // Unique identifier of the current software's feature set. 32 | FeatureSet int64 `json:"feature-set"` 33 | } 34 | -------------------------------------------------------------------------------- /rpc/isBlockhashValid.go: -------------------------------------------------------------------------------- 1 | package rpc 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/gagliardetto/solana-go" 7 | ) 8 | 9 | // Returns whether a blockhash is still valid or not 10 | // 11 | // **NEW: This method is only available in solana-core v1.9 or newer. Please use 12 | // `getFeeCalculatorForBlockhash` for solana-core v1.8** 13 | func (cl *Client) IsBlockhashValid( 14 | ctx context.Context, 15 | // Blockhash to be queried. Required. 16 | blockHash solana.Hash, 17 | 18 | // Commitment requirement. Optional. 19 | commitment CommitmentType, 20 | ) (out *IsValidBlockhashResult, err error) { 21 | params := []interface{}{blockHash} 22 | if commitment != "" { 23 | params = append(params, M{"commitment": string(commitment)}) 24 | } 25 | 26 | err = cl.rpcClient.CallForInto(ctx, &out, "isBlockhashValid", params) 27 | return 28 | } 29 | -------------------------------------------------------------------------------- /rpc/json.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | jsoniter "github.com/json-iterator/go" 19 | ) 20 | 21 | var json = jsoniter.ConfigCompatibleWithStandardLibrary 22 | -------------------------------------------------------------------------------- /rpc/jsonrpc/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Alexander Gehres 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /rpc/logging.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package rpc 19 | 20 | import ( 21 | "github.com/streamingfast/logging" 22 | "go.uber.org/zap" 23 | ) 24 | 25 | var traceEnabled = logging.IsTraceEnabled("solana-go", "github.com/gagliardetto/solana-go/rpc") 26 | var zlog *zap.Logger 27 | 28 | func init() { 29 | logging.Register("github.com/gagliardetto/solana-go/rpc", &zlog) 30 | } 31 | -------------------------------------------------------------------------------- /rpc/minimumLedgerSlot.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package rpc 16 | 17 | import ( 18 | "context" 19 | ) 20 | 21 | // MinimumLedgerSlot returns the lowest slot that the node 22 | // has information about in its ledger. This value may increase 23 | // over time if the node is configured to purge older ledger data. 24 | func (cl *Client) MinimumLedgerSlot(ctx context.Context) (out uint64, err error) { 25 | err = cl.rpcClient.CallForInto(ctx, &out, "minimumLedgerSlot", nil) 26 | return 27 | } 28 | -------------------------------------------------------------------------------- /rpc/requestAirdrop.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | package rpc 18 | 19 | import ( 20 | "context" 21 | 22 | "github.com/gagliardetto/solana-go" 23 | ) 24 | 25 | // RequestAirdrop requests an airdrop of lamports to a publicKey. 26 | // Returns transaction signature of airdrop. 27 | func (cl *Client) RequestAirdrop( 28 | ctx context.Context, 29 | account solana.PublicKey, 30 | lamports uint64, 31 | commitment CommitmentType, // optional; used for retrieving blockhash and verifying airdrop success. 32 | ) (signature solana.Signature, err error) { 33 | params := []interface{}{ 34 | account, 35 | lamports, 36 | } 37 | if commitment != "" { 38 | params = append(params, 39 | M{"commitment": commitment}, 40 | ) 41 | } 42 | err = cl.rpcClient.CallForInto(ctx, &signature, "requestAirdrop", params) 43 | return 44 | } 45 | -------------------------------------------------------------------------------- /rpc/ws/examples/rootSubscribe/rootSubscribe.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | "github.com/gagliardetto/solana-go/rpc/ws" 23 | ) 24 | 25 | func main() { 26 | client, err := ws.Connect(context.Background(), rpc.TestNet_WS) 27 | if err != nil { 28 | panic(err) 29 | } 30 | defer client.Close() 31 | 32 | sub, err := client.RootSubscribe() 33 | if err != nil { 34 | panic(err) 35 | } 36 | 37 | for { 38 | got, err := sub.Recv() 39 | if err != nil { 40 | panic(err) 41 | } 42 | spew.Dump(got) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /rpc/ws/examples/signatureSubscribe/signatureSubscribe.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go" 22 | "github.com/gagliardetto/solana-go/rpc" 23 | "github.com/gagliardetto/solana-go/rpc/ws" 24 | ) 25 | 26 | func main() { 27 | client, err := ws.Connect(context.Background(), rpc.TestNet_WS) 28 | if err != nil { 29 | panic(err) 30 | } 31 | defer client.Close() 32 | 33 | txSig := solana.MustSignatureFromBase58("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") 34 | 35 | sub, err := client.SignatureSubscribe( 36 | txSig, 37 | "", 38 | ) 39 | if err != nil { 40 | panic(err) 41 | } 42 | defer sub.Unsubscribe() 43 | 44 | for { 45 | got, err := sub.Recv() 46 | if err != nil { 47 | panic(err) 48 | } 49 | spew.Dump(got) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /rpc/ws/examples/slotSubscribe/slotSubscribe.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | "github.com/gagliardetto/solana-go/rpc/ws" 23 | ) 24 | 25 | func main() { 26 | client, err := ws.Connect(context.Background(), rpc.TestNet_WS) 27 | if err != nil { 28 | panic(err) 29 | } 30 | defer client.Close() 31 | 32 | sub, err := client.SlotSubscribe() 33 | if err != nil { 34 | panic(err) 35 | } 36 | defer sub.Unsubscribe() 37 | 38 | for { 39 | got, err := sub.Recv() 40 | if err != nil { 41 | panic(err) 42 | } 43 | spew.Dump(got) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /rpc/ws/examples/voteSubscribe/voteSubscribe.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "context" 19 | 20 | "github.com/davecgh/go-spew/spew" 21 | "github.com/gagliardetto/solana-go/rpc" 22 | "github.com/gagliardetto/solana-go/rpc/ws" 23 | ) 24 | 25 | func main() { 26 | client, err := ws.Connect(context.Background(), rpc.MainNetBeta_WS) 27 | if err != nil { 28 | panic(err) 29 | } 30 | defer client.Close() 31 | 32 | // NOTE: this subscription must be enabled by the node you're connecting to. 33 | // This subscription is disabled by default. 34 | sub, err := client.VoteSubscribe() 35 | if err != nil { 36 | panic(err) 37 | } 38 | defer sub.Unsubscribe() 39 | 40 | for { 41 | got, err := sub.Recv() 42 | if err != nil { 43 | panic(err) 44 | } 45 | spew.Dump(got) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /rpc/ws/json.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package ws 16 | 17 | import ( 18 | // stdjson "encoding/json" 19 | jsoniter "github.com/json-iterator/go" 20 | ) 21 | 22 | var json = jsoniter.ConfigCompatibleWithStandardLibrary 23 | -------------------------------------------------------------------------------- /rpc/ws/logging.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package ws 19 | 20 | import ( 21 | "github.com/streamingfast/logging" 22 | "go.uber.org/zap" 23 | ) 24 | 25 | var zlog *zap.Logger 26 | var traceEnabled = logging.IsTraceEnabled("solana-go", "github.com/gagliardetto/solana-go/rpc/ws") 27 | 28 | func init() { 29 | logging.Register("github.com/gagliardetto/solana-go/rpc/ws", &zlog) 30 | } 31 | -------------------------------------------------------------------------------- /testdata/standard.solana-keygen.json: -------------------------------------------------------------------------------- 1 | [254,235,166,85,112,29,132,16,126,87,234,58,144,120,98,141,75,133,85,10,31,71,74,147,81,189,128,180,112,21,110,62,209,238,65,42,248,12,152,28,130,46,170,32,19,8,11,29,255,208,207,18,123,131,230,60,249,157,68,133,246,187,45,62] -------------------------------------------------------------------------------- /text/interface.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 dfuse Platform Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package text 16 | 17 | type TextEncodable interface { 18 | TextEncode(encoder *Encoder, option *Option) error 19 | } 20 | -------------------------------------------------------------------------------- /text/tag.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 dfuse Platform Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package text 16 | 17 | import ( 18 | "reflect" 19 | "strings" 20 | ) 21 | 22 | type fieldTag struct { 23 | Linear bool 24 | Skip bool 25 | Label string 26 | NoTypeName bool 27 | } 28 | 29 | func parseFieldTag(tag reflect.StructTag) *fieldTag { 30 | t := &fieldTag{} 31 | tagStr := tag.Get("text") 32 | if tagStr == "" { 33 | return t 34 | } 35 | for _, s := range strings.Split(tagStr, ",") { 36 | if strings.HasPrefix(s, "linear") { 37 | t.Linear = true 38 | } else if strings.HasPrefix(s, "notype") { 39 | t.NoTypeName = true 40 | } else if s == "-" { 41 | t.Skip = true 42 | } else { 43 | t.Label = s 44 | } 45 | } 46 | return t 47 | } 48 | -------------------------------------------------------------------------------- /text/tree.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package text 16 | 17 | import ( 18 | "io" 19 | 20 | "github.com/gagliardetto/treeout" 21 | ) 22 | 23 | type TreeEncoder struct { 24 | output io.Writer 25 | *treeout.Tree 26 | } 27 | 28 | type EncodableToTree interface { 29 | EncodeToTree(parent treeout.Branches) 30 | } 31 | 32 | func NewTreeEncoder(w io.Writer, doc string) *TreeEncoder { 33 | return &TreeEncoder{ 34 | output: w, 35 | Tree: treeout.New(doc), 36 | } 37 | } 38 | 39 | func (enc *TreeEncoder) WriteString(s string) (int, error) { 40 | return enc.output.Write([]byte(s)) 41 | } 42 | -------------------------------------------------------------------------------- /types_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // This file has been modified by github.com/gagliardetto 3 | // 4 | // Copyright 2020 dfuse Platform Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | package solana 19 | 20 | import ( 21 | "bytes" 22 | "testing" 23 | 24 | bin "github.com/gagliardetto/binary" 25 | "github.com/stretchr/testify/assert" 26 | "github.com/stretchr/testify/require" 27 | ) 28 | 29 | func TestCompiledInstructions(t *testing.T) { 30 | traceEnabled = true 31 | 32 | ci := &CompiledInstruction{ 33 | ProgramIDIndex: 5, 34 | Accounts: []uint16{2, 5, 8}, 35 | Data: Base58([]byte{1, 2, 3, 4, 5}), 36 | } 37 | buf := &bytes.Buffer{} 38 | encoder := bin.NewBinEncoder(buf) 39 | err := encoder.Encode(ci) 40 | require.NoError(t, err) 41 | assert.Equal(t, []byte{0x5, 0x0, 0x3, 0x2, 0x0, 0x5, 0x0, 0x8, 0x0, 0x5, 0x1, 0x2, 0x3, 0x4, 0x5}, buf.Bytes()) 42 | } 43 | -------------------------------------------------------------------------------- /vault/json.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 github.com/gagliardetto 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package vault 16 | 17 | import ( 18 | jsoniter "github.com/json-iterator/go" 19 | ) 20 | 21 | var json = jsoniter.ConfigCompatibleWithStandardLibrary 22 | -------------------------------------------------------------------------------- /vault/kmsmanager.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 dfuse Platform Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package vault 16 | 17 | type KMSManager interface { 18 | Encrypt([]byte) ([]byte, error) 19 | Decrypt([]byte) ([]byte, error) 20 | } 21 | 22 | // Passthrough encryption (no encryption, that is) 23 | 24 | func NewPassthroughKeyManager() *PassthroughKeyManager { 25 | return &PassthroughKeyManager{} 26 | } 27 | 28 | type PassthroughKeyManager struct{} 29 | 30 | func (k PassthroughKeyManager) Encrypt(in []byte) ([]byte, error) { return in, nil } 31 | func (k PassthroughKeyManager) Decrypt(in []byte) ([]byte, error) { return in, nil } 32 | --------------------------------------------------------------------------------