We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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_RESP_ERROR, 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))
encode, erc := EncodeParam(param) if erc != nil { return nil, erc } fmt.Println(encode) case common.TokenProgramID.String(): param, err := DecodeParam[TokenInstructParam](v.Data) if err != nil { return nil, cerror.NewError(cerror.CODE_NODE_RESP_ERROR, err.Error()) } fmt.Println(cjson.NeatString(param)) encode, erc := EncodeParam(param) if erc != nil { return nil, erc } fmt.Println(encode) default: //param, err := DecodeParam(v.Data) //if err != nil { // continue //} //fmt.Println(cjson.NeatString(param)) continue } } fmt.Println(cjson.NeatString(txn))
The text was updated successfully, but these errors were encountered:
5Mpkm4FoNsncQG837qF1NvRQZMiB7efBLZ2kqVJJe9FgirWaEo8g6trUbCRceZeJMannXap7ry82nG1epXkk91rV
{ "Instruction": 2, "Lamports": 167772160000 }
2Ue3QA7ws8Fh != 3Bxs43ZMjSRQLs6o
how to decode the 3Bxs43ZMjSRQLs6o to get:
Sorry, something went wrong.
No branches or pull requests
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_RESP_ERROR, 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))
The text was updated successfully, but these errors were encountered: