solana rpc 返回"base64+zstd" 结果能解码成可读字符串吗?

官方文档参考:https://docs.solana.com/developing/clients/jsonrpc-api#getaccountinfo "base64+zstd" compresses the Account data using Zstandard and base64-encodes the result.

待解码数据如下:

"data": [
      "c2VydW0DAAAAAAAAAN/1mEELDQohNJI6FgPa4ZU1gA2/byFWYcnA8lt8oeJmAAAAAAAAAAAgyOLJc+L47CrO7pWnR108Q0yBD1qiNMtF1FehLf0ukcb6evO+2606PWXzaqvJdDGxu+TC0vbg5HymAgNFL11hBVQXKA5KOlE6syIUtDhk5KQkBQCetCy8WtJa914hH+uAaKfHvAQAAAAAAAAAAAAADbShIaxCEUfTaEGDulZQgAKnb9kAKcuGa216Ntj3eA10P/oGPAAAAJ7JuAAAAAAAZAAAAAAAAACrHB5LTexVOS4v1tpKHzPkvyUqdBRHI6zjJ7RX1XFSvIsKaabVU0X9IDocEMzOEy9nGL9BlxLZGFqPIE7h69g5g6F112nunsupDQplObWC296rtAfipPi8OMJxe++7Mn8f8FtRkIaWzL7pSp6/hcebfu990RvuTpF6pZHYBWC6T4CWmAAAAAAAZAAAAAAAAAAAAAAAAAAAAEJGyAAAAAAAcGFkZGluZw==",
      "base64"
    ],
请先 登录 后评论

最佳答案 2022-04-17 17:43

这个问题可以,没人解答,我来试试 solana-go-sdk/getAccountInfo.go at 7369c04fccd1043e385a5b1bb11cd57fba90aa09 · devexpert127/solana-go-sdk (github.com) 这里有一个例子

bin "github.com/gagliardetto/binary"
{
    pubKey := solana.MustPublicKeyFromBase58("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R") // raydium token
    // advanced usage
    resp, err := client.GetAccountInfoWithOpts(
        context.TODO(),
        pubKey,
    // You can specify more options here:
        &rpc.GetAccountInfoOpts{
            Encoding:   solana.EncodingBase64Zstd,
            Commitment: rpc.CommitmentFinalized,
    // You can get just a part of the account data by specify a DataSlice:
    // DataSlice: &rpc.DataSlice{
    //  Offset: pointer.ToUint64(0),
    //  Length: pointer.ToUint64(1024),
    // },
            },
    )
    if err != nil {
        panic(err)
    }
    var mint token.Mint
    err = bin.NewBinDecoder(resp.Value.Data.GetBinary()).Decode(&mint)
    if err != nil {
        panic(err)
    }
}
import (
    "fmt"
    bin "github.com/gagliardetto/binary"
    "github.com/gagliardetto/solana-go/programs/token"
)

func main() {
    var mint token.Mint
    err := bin.NewBinDecoder([]byte("c2VydW0DAAAAAAAAAN/1mEELDQohNJI6FgPa4ZU1gA2/byFWYcnA8lt8oeJmAAAAAAAAAAAgyOLJc+L47CrO7pWnR108Q0yBD1qiNMtF1FehLf0ukcb6evO+2606PWXzaqvJdDGxu+TC0vbg5HymAgNFL11hBVQXKA5KOlE6syIUtDhk5KQkBQCetCy8WtJa914hH+uAaKfHvAQAAAAAAAAAAAAADbShIaxCEUfTaEGDulZQgAKnb9kAKcuGa216Ntj3eA10P/oGPAAAAJ7JuAAAAAAAZAAAAAAAAACrHB5LTexVOS4v1tpKHzPkvyUqdBRHI6zjJ7RX1XFSvIsKaabVU0X9IDocEMzOEy9nGL9BlxLZGFqPIE7h69g5g6F112nunsupDQplObWC296rtAfipPi8OMJxe++7Mn8f8FtRkIaWzL7pSp6/hcebfu990RvuTpF6pZHYBWC6T4CWmAAAAAAAZAAAAAAAAAAAAAAAAAAAAEJGyAAAAAAAcGFkZGluZw==")).Decode(&mint)
    if err != nil {
        fmt.Printf("+v", err.Error())
    } else {
        fmt.Printf("+v", mint)
    }
}

16501788161.png

请先 登录 后评论

其它 4 个回答

晓道
请先 登录 后评论
xwisen
请先 登录 后评论
xwisen
请先 登录 后评论
xwisen
请先 登录 后评论
  • 2 关注
  • 1 收藏,3334 浏览
  • xwisen 提出于 2022-04-16 23:42