gagliardetto / solana-go

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

How to tell if a certain type of Solana program is not supported when parsing a transaction #106

Closed ionutRD closed 1 year ago

ionutRD commented 2 years ago

I noticed that certain type of Solana programs are not supported, one example being Memos. Is there a way to tell whether a transaction has instructions that are not supported such as Memos? I am asking because when parsing a transaction that has memos, I get this rather vague error, required [X] byte, remaining [Y]. Skipping these errors seems a bit risky because it doesn't tell much about what kind of instructions/programs are in the transaction.

The only solution that I found for identifying whether a transactions has memo instructions/programs is to look at Meta field, and more precisely in the logMessages field where I can see whether there are Memo programs.

        "logMessages": [
          "Program 11111111111111111111111111111111 invoke [1]",
          "Program 11111111111111111111111111111111 success",
          "Program 11111111111111111111111111111111 invoke [1]",
          "Program 11111111111111111111111111111111 success",
          "Program 11111111111111111111111111111111 invoke [1]",
          "Program 11111111111111111111111111111111 success",
          "Program MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr invoke [1]",
          "Program log: Memo (len 12): \"...\"",
          "Program MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr consumed 5936 of 800000 compute units",
          "Program MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr success"
        ],

While this option would work for Memos, it wouldn't work for other unsupported programs. Also, is there a list of unsupported Solana Programs/Instructions?

The code that I use to parse the transaction is this one:

  // parse transaction:
  tx, err := solana.TransactionFromDecoder(bin.NewBinDecoder(data))
  if err != nil {
      ...
  }

This line solana.TransactionFromDecoder(bin.NewBinDecoder(data)) returns an error of this kind required [X] byte, remaining [Y] when there is at least one instruction/program that is a Memo.

gagliardetto commented 2 years ago

Can you try with the latest? go get github.com/gagliardetto/solana-go@3d8aa7fccde7cefdc0b9c870e190e766a372eb7c

That should give you more verbose errors.

That's very strange; the data is probably malformed because solana.TransactionFromDecoder is instruction-agnostic.

Can you share the base64 of the data that it fails to parse?

Is that maybe the new transaction format?

ionutRD commented 2 years ago

I am trying the latest now. The base64 is this one Alkhq/BfGdBeok4oBP21xAwT4oO/R5PvkKqbCTq4sHHRsto+uDQCFcdp8hXh1g5D3mTh8GAJW8xE+EDD27f9IweTkH2Afiu4h5aM+Xbo0mklc0/Vi1xawd7SZVbstXDLtWdoJaf4Zt+20F/SasURzw/P4dkD+Q6BjgUNHT+vg5gOgAIBAQUaJV0Ch/DG6XwNcizWbI7STLgSbIOrg0Dl67Oo30WU1uA/NIbYLPRmuLarIJ4J0CcN3IWEm4Gf8675KhnXef2LaDXzjFgWVSbAO2yyTF6dK1oO3gTExie957LXDwu6oJMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVKU1qZKSEGTSTocWDaOHx8NbXdvJK7geQfqEBBBUSNlyFnQmYh1aMkGtq3c6TIOsk32S6XMUnN9DQgFGQq4lwEAwIAAgwCAAAAgJaYAAAAAAADAgAFDAIAAACAlpgAAAAAAAMCAAYMAgAAAICWmAAAAAAABAAMSGVsbG8gRmFiaW8hAX5s37FH6IeB4QeMYxD4LtpXf1DaupH/ro7W+kEQnofaAgECAQA=

gagliardetto commented 2 years ago

Thanks!

Do you also have a transaction sig for that?

ionutRD commented 2 years ago

This is the signature 2nMjR8mdczMJZZ1XeQ5Y37GxfrRQmaV74eypnD9ggpQMmaWfETq9C5DoGKha4bMamu9tFQQArBAgxzQ5vnng1ZdG

ionutRD commented 2 years ago

the error becomes

 unable to decode tx.Message: unable to decode accountIndex for ix[0].Accounts[228]: required [1] byte, remaining [0]

when I try with the latest version

ionutRD commented 2 years ago

I think this is not working because this is a v0 tx.

gagliardetto commented 2 years ago

Yep

https://explorer.solana.com/tx/2nMjR8mdczMJZZ1XeQ5Y37GxfrRQmaV74eypnD9ggpQMmaWfETq9C5DoGKha4bMamu9tFQQArBAgxzQ5vnng1ZdG?cluster=devnet

gagliardetto commented 2 years ago

The old transaction version is called LEGACY.

I'm gonna add support for the new tx version soon.

ionutRD commented 2 years ago

do you have a rough timeline on when this is going to be available?

gagliardetto commented 2 years ago

I'll try to get that done this week.

ionutRD commented 2 years ago

thanks for the update.

gagliardetto commented 2 years ago

Does it work with https://github.com/gagliardetto/solana-go/releases/tag/v1.7.1 ?

ionutRD commented 2 years ago

it's working thanks