diff --git a/README.md b/README.md index 109115e1..6a118723 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Solana SDK library for Go -[![GoDoc](https://pkg.go.dev/badge/github.com/gagliardetto/solana-go?status.svg)](https://pkg.go.dev/github.com/gagliardetto/solana-go@v0.5.1?tab=doc) +[![GoDoc](https://pkg.go.dev/badge/github.com/gagliardetto/solana-go?status.svg)](https://pkg.go.dev/github.com/gagliardetto/solana-go@v1.0.1?tab=doc) [![GitHub tag (latest SemVer pre-release)](https://img.shields.io/github/v/tag/gagliardetto/solana-go?include_prereleases&label=release-tag)](https://github.com/gagliardetto/solana-go/releases) [![Build Status](https://github.com/gagliardetto/solana-go/workflows/tests/badge.svg?branch=main)](https://github.com/gagliardetto/solana-go/actions?query=branch%3Amain) [![TODOs](https://badgen.net/https/api.tickgit.com/badgen/github.com/gagliardetto/solana-go/main)](https://www.tickgit.com/browse?repo=github.com/gagliardetto/solana-go&branch=main) @@ -64,7 +64,7 @@ More contracts to come. ## Current development status -There is currently **no stable release**. The SDK is actively developed and latest is `v0.5.1` which is an `alpha` release. +There is currently **no stable release**. The SDK is actively developed and latest is `v1.0.1` which is an `alpha` release. The RPC and WS client implementation is based on [this RPC spec](https://github.com/solana-labs/solana/blob/dff9c88193da142693cabebfcd3bf68fa8e8b873/docs/src/developing/clients/jsonrpc-api.md). @@ -74,11 +74,9 @@ The RPC and WS client implementation is based on [this RPC spec](https://github. ## Installation -> :warning: `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. - ```bash $ cd my-project -$ go get github.com/gagliardetto/solana-go@v0.5.1 +$ go get github.com/gagliardetto/solana-go@v1.0.1 ``` ## Pretty-Print transactions/instructions @@ -471,11 +469,11 @@ func main() { // ... which means that the supply is 9998022451.607088 } { - // Or you can use `GetAccountDataIn` which does all of the above in one call: + // Or you can use `GetAccountDataInto` which does all of the above in one call: pubKey := solana.MustPublicKeyFromBase58("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt") // serum token var mint token.Mint // Get the account, and decode its data into the provided mint object: - err := client.GetAccountDataIn( + err := client.GetAccountDataInto( context.TODO(), pubKey, &mint, @@ -485,6 +483,20 @@ func main() { } spew.Dump(mint) } + { + // // Or you can use `GetAccountDataBorshInto` which does all of the above in one call but for borsh-encoded data: + // var metadata token_metadata.Metadata + // // Get the account, and decode its data into the provided metadata object: + // err := client.GetAccountDataBorshInto( + // context.TODO(), + // pubKey, + // &metadata, + // ) + // if err != nil { + // panic(err) + // } + // spew.Dump(metadata) + } { pubKey := solana.MustPublicKeyFromBase58("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R") // raydium token // advanced usage diff --git a/cmd/slnc/cmd/serum_get_market.go b/cmd/slnc/cmd/serum_get_market.go index 20e0cbed..31ae8aaa 100644 --- a/cmd/slnc/cmd/serum_get_market.go +++ b/cmd/slnc/cmd/serum_get_market.go @@ -94,7 +94,7 @@ type orderBookEntry struct { func getOrderBook(ctx context.Context, market *serum.MarketMeta, cli *rpc.Client, address solana.PublicKey, desc bool) (out []*orderBookEntry, totalSize *big.Float, err error) { var o serum.Orderbook - if err := cli.GetAccountDataIn(ctx, address, &o); err != nil { + if err := cli.GetAccountDataInto(ctx, address, &o); err != nil { return nil, nil, fmt.Errorf("getting orderbook: %w", err) } diff --git a/go.mod b/go.mod index 0013b6f6..2a508a56 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/davecgh/go-spew v1.1.1 github.com/dfuse-io/logging v0.0.0-20210109005628-b97a57253f70 github.com/fatih/color v1.7.0 - github.com/gagliardetto/binary v0.4.4 + github.com/gagliardetto/binary v0.5.0 github.com/gagliardetto/gofuzz v1.2.2 github.com/gagliardetto/treeout v0.1.4 github.com/google/go-cmp v0.5.1 diff --git a/go.sum b/go.sum index 8e224325..5809af47 100644 --- a/go.sum +++ b/go.sum @@ -91,6 +91,8 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/gagliardetto/binary v0.4.4 h1:EeADyw6t/5+/8Dtdt8LZ2X8Kd0vDJW0XXDi5iUgrFrc= github.com/gagliardetto/binary v0.4.4/go.mod h1:peJR9PvwamL4YOh1nHWCPLry2VEfeeD1ADvewka7HnQ= +github.com/gagliardetto/binary v0.5.0 h1:fLVIbMEQp5zbW0SFtg0z/WHy2iUw/SMeuakzfa5ayhI= +github.com/gagliardetto/binary v0.5.0/go.mod h1:peJR9PvwamL4YOh1nHWCPLry2VEfeeD1ADvewka7HnQ= github.com/gagliardetto/gofuzz v1.2.2 h1:XL/8qDMzcgvR4+CyRQW9UGdwPRPMHVJfqQ/uMvSUuQw= github.com/gagliardetto/gofuzz v1.2.2/go.mod h1:bkH/3hYLZrMLbfYWA0pWzXmi5TTRZnu4pMGZBkqMKvY= github.com/gagliardetto/treeout v0.1.4 h1:ozeYerrLCmCubo1TcIjFiOWTTGteOOHND1twdFpgwaw= diff --git a/programs/serum/rpc.go b/programs/serum/rpc.go index e872e1a3..dbb6d8f1 100644 --- a/programs/serum/rpc.go +++ b/programs/serum/rpc.go @@ -90,11 +90,11 @@ func FetchMarket(ctx context.Context, rpcCli *rpc.Client, marketAddr solana.Publ return nil, fmt.Errorf("unsupported market data length: %d", dataLen) } - if err := rpcCli.GetAccountDataIn(ctx, meta.MarketV2.QuoteMint, &meta.QuoteMint); err != nil { + if err := rpcCli.GetAccountDataInto(ctx, meta.MarketV2.QuoteMint, &meta.QuoteMint); err != nil { return nil, fmt.Errorf("getting quote mint: %w", err) } - if err := rpcCli.GetAccountDataIn(ctx, meta.MarketV2.BaseMint, &meta.BaseMint); err != nil { + if err := rpcCli.GetAccountDataInto(ctx, meta.MarketV2.BaseMint, &meta.BaseMint); err != nil { return nil, fmt.Errorf("getting base token: %w", err) } diff --git a/rpc/examples/getAccountInfo/getAccountInfo.go b/rpc/examples/getAccountInfo/getAccountInfo.go index 52c8e597..b189ddbd 100644 --- a/rpc/examples/getAccountInfo/getAccountInfo.go +++ b/rpc/examples/getAccountInfo/getAccountInfo.go @@ -58,7 +58,7 @@ func main() { pubKey := solana.MustPublicKeyFromBase58("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt") // serum token var mint token.Mint // Get the account, and decode its data into the provided mint object: - err := client.GetAccountDataIn( + err := client.GetAccountDataInto( context.TODO(), pubKey, &mint, @@ -68,6 +68,20 @@ func main() { } spew.Dump(mint) } + { + // // Or you can use `GetAccountDataBorsh` which does all of the above in one call but for borsh-encoded data: + // var metadata token_metadata.Metadata + // // Get the account, and decode its data into the provided metadata object: + // err := client.GetAccountDataBorsh( + // context.TODO(), + // pubKey, + // &metadata, + // ) + // if err != nil { + // panic(err) + // } + // spew.Dump(metadata) + } { pubKey := solana.MustPublicKeyFromBase58("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R") // raydium token // advanced usage diff --git a/rpc/getAccountInfo.go b/rpc/getAccountInfo.go index a026125f..1f314cf2 100644 --- a/rpc/getAccountInfo.go +++ b/rpc/getAccountInfo.go @@ -37,9 +37,9 @@ func (cl *Client) GetAccountInfo(ctx context.Context, account solana.PublicKey) ) } -// GetAccountDataIn populates the provided `inVar` parameter with all -// data associated with the account of provided publicKey. -func (cl *Client) GetAccountDataIn(ctx context.Context, account solana.PublicKey, inVar interface{}) (err error) { +// GetAccountDataInto decodes the binary data and populates +// the provided `inVar` parameter with all data associated with the account of provided publicKey. +func (cl *Client) GetAccountDataInto(ctx context.Context, account solana.PublicKey, inVar interface{}) (err error) { resp, err := cl.GetAccountInfo(ctx, account) if err != nil { return err @@ -47,6 +47,16 @@ func (cl *Client) GetAccountDataIn(ctx context.Context, account solana.PublicKey return bin.NewBinDecoder(resp.Value.Data.GetBinary()).Decode(inVar) } +// GetAccountDataBorshInto decodes the borsh binary data and populates +// the provided `inVar` parameter with all data associated with the account of provided publicKey. +func (cl *Client) GetAccountDataBorshInto(ctx context.Context, account solana.PublicKey, inVar interface{}) (err error) { + resp, err := cl.GetAccountInfo(ctx, account) + if err != nil { + return err + } + return bin.NewBorshDecoder(resp.Value.Data.GetBinary()).Decode(inVar) +} + type GetAccountInfoOpts struct { // Encoding for Account data. // Either "base58" (slow), "base64", "base64+zstd", or "jsonParsed".