gagliardetto / solana-go

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

Using GetParsedTransaction to obtain event data is incorrect #223

Open langubtc opened 5 months ago

langubtc commented 5 months ago

Hello developer, I use GetParsedTransaction to get event data, but the data obtained and the data from Solscan are incorrect. Can I ask for your help? tx:LofiBXmyHkjVRiK6Ae76DBBDSLUHFrMpdpZzYYYRz4tmWtj2jXP9bARRpMBwGiGDeDhu5Sz8wTvorxYSdD72Nj2

   func GetTransaction(ctx context.Context, signature string) {
    txSig := solana.MustSignatureFromBase58(signature)
    version := uint64(0)
    out, err := client.GetParsedTransaction(
        context.TODO(),
        txSig,
        &rpc.GetParsedTransactionOpts{
            MaxSupportedTransactionVersion: &version,
            Commitment:                     rpc.CommitmentConfirmed,
        },
    )

    if err != nil {
        panic(err)
    }

    for _, instructions := range out.Meta.InnerInstructions {
        for _, uniner := range instructions.Instructions {
            if uniner.Program == "" && uniner.ProgramId.String() == "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P" {
                binary, err := base58.Decode(uniner.Data.String())
                if err != nil {
                    continue
                }

                acEvent := models.TransactionData{}

                decoder := bin.NewBorshDecoder(binary)

                err = decoder.Decode(&acEvent)
                if err != nil {
                    continue
                }

                fmt.Println(acEvent)
            }

        }
    }
}

out:

{GN5YtALYZdstsseG99VcK3dhpt4aUGVuZb3XkdNk4DUP 5006513049810348600 14928840578314757302 true J37sAcQU91S2zhFLb3PrfJ1z1FJEVicjUuHyLC5AV2xv 345558380229795933 2623109577306031043 1718900353}
type TransactionData struct {
    Mint                 solana.PublicKey `json:"mint"`
    SolAmount            uint64           `json:"solAmount"`
    TokenAmount          uint64           `json:"tokenAmount"`
    IsBuy                bool             `json:"isBuy"`
    User                 solana.PublicKey `json:"user"` 
    Timestamp            int64            `json:"timestamp"`
    VirtualSolReserves   uint64           `json:"virtualSolReserves"`
    VirtualTokenReserves uint64           `json:"virtualTokenReserves"`
}

Looks like the data type is incorrect,I want to get data like this。

{
  "mint": {
    "type": "publicKey",
    "data": "AsjBCMaWLYcemXGxWcqmdB28dhA1nat5Q1h4hR2fpump"
  },
  "solAmount": {
    "type": "u64",
    "data": "2585918907"
  },
  "tokenAmount": {
    "type": "u64",
    "data": "41544892677520"
  },
  "isBuy": {
    "type": "bool",
    "data": false
  },
  "user": {
    "type": "publicKey",
    "data": "DfMxre4cKmvogbLrPigxmibVTTQDuzjdXojWzjCXXhzj"
  },
  "timestamp": {
    "type": "i64",
    "data": "1718900353"
  },
  "virtualSolReserves": {
    "type": "u64",
    "data": "43487672804"
  },
  "virtualTokenReserves": {
    "type": "u64",
    "data": "740209763511468"
  }
}