From 6a20387676036c055b5bff4a296463c56e9312ee Mon Sep 17 00:00:00 2001 From: gagliardetto Date: Wed, 17 Apr 2024 18:43:09 +0200 Subject: [PATCH] Add utility functions --- transaction.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/transaction.go b/transaction.go index e64ab4b0..478c67a7 100644 --- a/transaction.go +++ b/transaction.go @@ -26,6 +26,7 @@ import ( "github.com/davecgh/go-spew/spew" bin "github.com/gagliardetto/binary" "github.com/gagliardetto/treeout" + "github.com/mr-tron/base58" "go.uber.org/zap" "github.com/gagliardetto/solana-go/text" @@ -87,6 +88,27 @@ func TransactionFromDecoder(decoder *bin.Decoder) (*Transaction, error) { return out, nil } +func TransactionFromBytes(data []byte) (*Transaction, error) { + decoder := bin.NewBinDecoder(data) + return TransactionFromDecoder(decoder) +} + +func TransactionFromBase64(b64 string) (*Transaction, error) { + data, err := base64.StdEncoding.DecodeString(b64) + if err != nil { + return nil, err + } + return TransactionFromBytes(data) +} + +func TransactionFromBase58(b58 string) (*Transaction, error) { + data, err := base58.Decode(b58) + if err != nil { + return nil, err + } + return TransactionFromBytes(data) +} + // MustTransactionFromDecoder decodes a transaction from a decoder. // Panics on error. func MustTransactionFromDecoder(decoder *bin.Decoder) *Transaction {