gagliardetto / solana-go

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

Cannot build account meta during transaction decoding #167

Closed matterai closed 10 months ago

matterai commented 10 months ago

Assume I have a code simply fetches a transaction. Then I take specific instruction and try to call ResolveInstructionAccounts method. It returns me an error: cannot build account meta list without address tables.

Code running:

tx, err := rpcService.GetTransactionInfo(logEvent.Value.Signature)
if err != nil {
  return err
}

idoPurchase := tx.Message.Instructions[4]
accounts, err := idoPurchase.ResolveInstructionAccounts(&tx.Message) // Error returns here!
if err != nil {
  return err
}

inst, err := system.DecodeInstruction(accounts, idoPurchase.Data)
if err != nil {
  return err
}

spew.Dump(inst)

Transaction I fetch using code from docs. Code for fetching transaction looks like this:

func (s *SolanaRpcService) GetTransactionInfo(signature solana.Signature) (*solana.Transaction, error) {
    version := uint64(0)
    out, err := s.rpcClient.GetTransaction(
        context.Background(),
        signature,
        &rpc.GetTransactionOpts{
            Encoding:                       solana.EncodingBase64,
            MaxSupportedTransactionVersion: &version,
        },
    )
    if err != nil {
        return nil, err
    }

    tx, err := solana.TransactionFromDecoder(bin.NewBinDecoder(out.Transaction.GetBinary()))
    if err != nil {
        return nil, err
    }

    return tx, nil
}

I am not quite sure what am I doing wrong? Please, elaborate me or give me a reference to the doc part which I missed.

gagliardetto commented 10 months ago

You need to resolve the address table lookups first

https://github.com/gagliardetto/solana-go#address-lookup-tables

matterai commented 10 months ago

Yep it's worked. Thank you.