gagliardetto / solana-go

Go SDK library and RPC client for the Solana Blockchain
Apache License 2.0
902 stars 259 forks source link

GetBlockWithOpts using `solana.EncodingJSONParsed` not working #20

Open jfmyers opened 2 years ago

jfmyers commented 2 years ago

I am attempting to pull blocks with the JSON Parsed option and repeatedly receive the following error:

2021/11/18 16:06:17 rpc.GetBlockResult.Transactions: []rpc.TransactionWithMeta: rpc.TransactionWithMeta.Transaction: solana.Transaction.Message: solana.Message.AccountKeys: []solana.PublicKey: unmarshalerDecoder: ReadString: expects " or n, but found {, error found in #1 byte of ...|{"pubkey":"|..., bigger context ...|{"pubkey":"2oz91K9pKf2sYr4oRtQvxBcxxo8gniZvXyNoMTQY|..., error found in #10 byte of ...|ble":true},{"pubkey"|..., bigger context ...|8gniZvXyNoMTQYhoqv","signer":true,"writable":true},{"pubkey":"7ycfa1ENNT5dVVoMtiMjsgVbkWKFJbu6nF2h1U|...
exit status 1

Version: github.com/gagliardetto/solana-go v1.0.2 Endpoint: rpc.MainNetBeta_RPC

Here is my code:

package main

import (
    "context"
    "log"

    "github.com/davecgh/go-spew/spew"
    "github.com/gagliardetto/solana-go"
    "github.com/gagliardetto/solana-go/rpc"
)

func main() {
    client := rpc.New(rpc.MainNetBeta_RPC)

    example, err := client.GetRecentBlockhash(context.TODO(), rpc.CommitmentFinalized)
    if err != nil {
        panic(err)
    }

    includeRewards := true
    out, err := client.GetBlockWithOpts(
        context.TODO(),
        uint64(example.Context.Slot),
        // You can specify more options here:
        &rpc.GetBlockOpts{
            Encoding:   solana.EncodingJSONParsed,
            Commitment: rpc.CommitmentFinalized,
            // Get only signatures:
            TransactionDetails: rpc.TransactionDetailsFull,
            // Exclude rewards:
            Rewards: &includeRewards,
        },
    )
    if err != nil {
        log.Fatal(err)
    }
    spew.Dump(out)
}

Any ideas on how to resolve this issue?

gagliardetto commented 2 years ago

Hi

the GetBlock method is currently broken and won't accept anything that's not solana.EncodingBase64 (or solana.EncodingBase58).

I'm working on a fix, and it will be included in the next release.

gtors commented 2 years ago

GetBlock method is currently broken

@gagliardetto could you please provide details about what is broken in the GetBlock/GetTransaction?

bantalon commented 1 year ago

@gagliardetto

We already integrated the SDK for encoding outgoing transactions. So first of all, thank you!

We are looking to use it now for block parsing and would be happy to use the jsonParsed encoding. Do you have an estimation how much time / effort is needed to implement and release support for this encoding?

maestroi commented 1 year ago

Trying to use the same, is the work around to do a rawjsonrpc request ?

cpucorecore commented 1 month ago

I'm facing the same issue. Is the project dead?