Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Jul 28, 2021
1 parent 0535f5f commit 9c9f6d1
Show file tree
Hide file tree
Showing 31 changed files with 78 additions and 74 deletions.
76 changes: 39 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ func main() {
spew.Dump(resp)

var mint token.Mint
// Account{}.Data.GetBinary() returns the *decoded* binary data
// regardless the original encoding (it can handle them all).
err = bin.NewDecoder(resp.Value.Data.GetBinary()).Decode(&mint)
if err != nil {
panic(err)
Expand Down Expand Up @@ -239,7 +241,7 @@ func main() {
// You can specify more options here:
&rpc.GetAccountInfoOpts{
Encoding: solana.EncodingBase64Zstd,
Commitment: rpc.CommitmentType("finalized"),
Commitment: rpc.CommitmentFinalized,
// You can get just a part of the account data by specify a DataSlice:
// DataSlice: &rpc.DataSlice{
// Offset: pointer.ToUint64(0),
Expand Down Expand Up @@ -285,7 +287,7 @@ func main() {
out, err := client.GetBalance(
context.TODO(),
pubKey,
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -319,7 +321,7 @@ func main() {
endpoint := rpc.TestNet_RPC
client := rpc.New(endpoint)

example, err := client.GetRecentBlockhash(context.TODO(), rpc.CommitmentType("finalized"))
example, err := client.GetRecentBlockhash(context.TODO(), rpc.CommitmentFinalized)
if err != nil {
panic(err)
}
Expand All @@ -341,7 +343,7 @@ func main() {
// You can specify more options here:
&rpc.GetBlockOpts{
Encoding: solana.EncodingBase64,
Commitment: rpc.CommitmentType("finalized"),
Commitment: rpc.CommitmentFinalized,
// Get only signatures:
TransactionDetails: rpc.TransactionDetailsSignatures,
// Exclude rewards:
Expand Down Expand Up @@ -372,7 +374,7 @@ func main() {
endpoint := rpc.TestNet_RPC
client := rpc.New(endpoint)

example, err := client.GetRecentBlockhash(context.TODO(), rpc.CommitmentType("finalized"))
example, err := client.GetRecentBlockhash(context.TODO(), rpc.CommitmentFinalized)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -406,7 +408,7 @@ func main() {

out, err := client.GetBlockHeight(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -442,7 +444,7 @@ func main() {
out, err := client.GetBlockProductionWithOpts(
context.TODO(),
&rpc.GetBlockProductionOpts{
Commitment: rpc.CommitmentType("finalized"),
Commitment: rpc.CommitmentFinalized,
// Range: &rpc.SlotRangeRequest{
// FirstSlot: XXXXXX,
// Identity: solana.MustPublicKeyFromBase58("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"),
Expand Down Expand Up @@ -476,7 +478,7 @@ func main() {

example, err := client.GetRecentBlockhash(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -512,7 +514,7 @@ func main() {

example, err := client.GetRecentBlockhash(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand All @@ -523,7 +525,7 @@ func main() {
context.TODO(),
uint64(example.Context.Slot-3),
&endSlot,
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand All @@ -550,7 +552,7 @@ func main() {

example, err := client.GetRecentBlockhash(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand All @@ -561,7 +563,7 @@ func main() {
context.TODO(),
uint64(example.Context.Slot-10),
limit,
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -616,7 +618,7 @@ func main() {

example, err := client.GetRecentBlockhash(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand All @@ -640,7 +642,7 @@ func main() {
// You can specify more options here:
&rpc.GetConfirmedBlockOpts{
Encoding: solana.EncodingBase64,
Commitment: rpc.CommitmentType("finalized"),
Commitment: rpc.CommitmentFinalized,
// Get only signatures:
TransactionDetails: rpc.TransactionDetailsSignatures,
// Exclude rewards:
Expand Down Expand Up @@ -673,7 +675,7 @@ func main() {

example, err := client.GetRecentBlockhash(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand All @@ -686,7 +688,7 @@ func main() {
context.TODO(),
uint64(example.Context.Slot-3),
&endSlot,
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -714,7 +716,7 @@ func main() {

example, err := client.GetRecentBlockhash(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand All @@ -726,7 +728,7 @@ func main() {
context.TODO(),
uint64(example.Context.Slot-10),
limit,
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -827,7 +829,7 @@ func main() {

out, err := client.GetEpochInfo(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -880,7 +882,7 @@ func main() {

example, err := client.GetRecentBlockhash(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand All @@ -889,7 +891,7 @@ func main() {
out, err := client.GetFeeCalculatorForBlockhash(
context.TODO(),
example.Value.Blockhash,
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -942,7 +944,7 @@ func main() {

out, err := client.GetFees(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -1074,7 +1076,7 @@ func main() {

out, err := client.GetInflationGovernor(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -1134,7 +1136,7 @@ func main() {
pubKey,
},
&rpc.GetInflationRewardOpts{
Commitment: rpc.CommitmentType("finalized"),
Commitment: rpc.CommitmentFinalized,
},
)
if err != nil {
Expand Down Expand Up @@ -1162,7 +1164,7 @@ func main() {

out, err := client.GetLargestAccounts(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
rpc.LargestAccountsFilterCirculating,
)
if err != nil {
Expand Down Expand Up @@ -1270,7 +1272,7 @@ func main() {
out, err := client.GetMinimumBalanceForRentExemption(
context.TODO(),
dataSize,
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -1315,7 +1317,7 @@ func main() {
},
&rpc.GetMultipleAccountsOpts{
Encoding: solana.EncodingBase64Zstd,
Commitment: rpc.CommitmentType("finalized"),
Commitment: rpc.CommitmentFinalized,
// You can get just a part of the account data by specify a DataSlice:
// DataSlice: &rpc.DataSlice{
// Offset: pointer.ToUint64(0),
Expand Down Expand Up @@ -1378,7 +1380,7 @@ func main() {

recent, err := client.GetRecentBlockhash(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -1492,7 +1494,7 @@ func main() {

out, err := client.GetSlot(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand All @@ -1519,7 +1521,7 @@ func main() {

out, err := client.GetSlotLeader(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand All @@ -1546,7 +1548,7 @@ func main() {

recent, err := client.GetRecentBlockhash(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -1611,7 +1613,7 @@ func main() {
out, err := client.GetStakeActivation(
context.TODO(),
pubKey,
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
nil,
)
if err != nil {
Expand Down Expand Up @@ -1639,7 +1641,7 @@ func main() {

out, err := client.GetSupply(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -1669,7 +1671,7 @@ func main() {
out, err := client.GetTokenAccountBalance(
context.TODO(),
pubKey,
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -1765,7 +1767,7 @@ func main() {
out, err := client.GetTokenLargestAccounts(
context.TODO(),
pubKey,
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -1795,7 +1797,7 @@ func main() {
out, err := client.GetTokenSupply(
context.TODO(),
pubKey,
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down Expand Up @@ -1897,7 +1899,7 @@ func main() {

out, err := client.GetTransactionCount(
context.TODO(),
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down
4 changes: 3 additions & 1 deletion rpc/examples/getAccountInfo/getAccountInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func main() {
spew.Dump(resp)

var mint token.Mint
// Account{}.Data.GetBinary() returns the *decoded* binary data
// regardless the original encoding (it can handle them all).
err = bin.NewDecoder(resp.Value.Data.GetBinary()).Decode(&mint)
if err != nil {
panic(err)
Expand Down Expand Up @@ -61,7 +63,7 @@ func main() {
// You can specify more options here:
&rpc.GetAccountInfoOpts{
Encoding: solana.EncodingBase64Zstd,
Commitment: rpc.CommitmentType("finalized"),
Commitment: rpc.CommitmentFinalized,
// You can get just a part of the account data by specify a DataSlice:
// DataSlice: &rpc.DataSlice{
// Offset: pointer.ToUint64(0),
Expand Down
2 changes: 1 addition & 1 deletion rpc/examples/getBalance/getBalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
out, err := client.GetBalance(
context.TODO(),
pubKey,
rpc.CommitmentType("finalized"),
rpc.CommitmentFinalized,
)
if err != nil {
panic(err)
Expand Down
4 changes: 2 additions & 2 deletions rpc/examples/getBlock/getBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func main() {
endpoint := rpc.TestNet_RPC
client := rpc.New(endpoint)

example, err := client.GetRecentBlockhash(context.TODO(), rpc.CommitmentType("finalized"))
example, err := client.GetRecentBlockhash(context.TODO(), rpc.CommitmentFinalized)
if err != nil {
panic(err)
}
Expand All @@ -34,7 +34,7 @@ func main() {
// You can specify more options here:
&rpc.GetBlockOpts{
Encoding: solana.EncodingBase64,
Commitment: rpc.CommitmentType("finalized"),
Commitment: rpc.CommitmentFinalized,
// Get only signatures:
TransactionDetails: rpc.TransactionDetailsSignatures,
// Exclude rewards:
Expand Down
2 changes: 1 addition & 1 deletion rpc/examples/getBlockCommitment/getBlockCommitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func main() {
endpoint := rpc.TestNet_RPC
client := rpc.New(endpoint)

example, err := client.GetRecentBlockhash(context.TODO(), rpc.CommitmentType("finalized"))
example, err := client.GetRecentBlockhash(context.TODO(), rpc.CommitmentFinalized)
if err != nil {
panic(err)
}
Expand Down
Loading

0 comments on commit 9c9f6d1

Please sign in to comment.