Open yangyile1990 opened 1 year ago
5Mpkm4FoNsncQG837qF1NvRQZMiB7efBLZ2kqVJJe9FgirWaEo8g6trUbCRceZeJMannXap7ry82nG1epXkk91rV
{ "Instruction": 2, "Lamports": 167772160000 }
2Ue3QA7ws8Fh != 3Bxs43ZMjSRQLs6o
how to decode the 3Bxs43ZMjSRQLs6o to get:
type TokenInstructParam struct { Instruction token.Instruction Amount uint64 Decimals uint8 }
type TransferInstructParam struct { Instruction token.Instruction Lamports uint64 }
type TransferInstructParam2 struct { Instruction token.Instruction Lamports uint64 Seed string ProgramID common.PublicKey }
func DecodeParam[T any](data []byte) (*T, error) { var param T err := bin.NewBinDecoder(data).Decode(¶m) if err != nil { return nil, err } return ¶m, nil }
func EncodeParam(param any) (string, *cerror.CError) { buf := new(bytes.Buffer) if err := bin.NewBinEncoder(buf).Encode(param); err != nil { return "", cerror.NewError(cerror.CODE_PARAM_ERROR, err.Error()) } return base58.Encode(buf.Bytes()), nil }
txSig, err := solana.SignatureFromBase58(txid) if err != nil { return nil, cerror.NewError(cerror.CODE_PARAM_ERROR, err.Error()) } out, err := s.client3.GetTransaction(context.TODO(), txSig, &rpc3.GetTransactionOpts{ Encoding: solana.EncodingBase64, }) if err != nil { return nil, cerror.NewError(cerror.CODE_THIRD_REQ_ERROR, err.Error()) } txn, err := out.Transaction.GetTransaction() if err != nil { return nil, cerror.NewError(cerror.CODE_NODE_RESPERROR, err.Error()) } tmg := txn.Message for , v := range tmg.Instructions { program, err := txn.ResolveProgramIDIndex(v.ProgramIDIndex) if err != nil { return nil, cerror.NewError(cerror.CODE_NODE_RESP_ERROR, err.Error()) } fmt.Println(program.String()) switch program.String() { case common.SystemProgramID.String(): param, err := DecodeParamTransferInstructParam if err != nil { return nil, cerror.NewError(cerror.CODE_NODE_RESP_ERROR, err.Error()) } fmt.Println(cjson.NeatString(param))