Skip to content

Commit

Permalink
Upgrade to v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Oct 10, 2021
1 parent dce349e commit ac739d8
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 15 deletions.
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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).

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/slnc/cmd/serum_get_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions programs/serum/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
16 changes: 15 additions & 1 deletion rpc/examples/getAccountInfo/getAccountInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
16 changes: 13 additions & 3 deletions rpc/getAccountInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,26 @@ 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
}
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".
Expand Down

0 comments on commit ac739d8

Please sign in to comment.