diff --git a/core/btc/account_test.go b/core/btc/account_test.go index eb50a45..f11700b 100644 --- a/core/btc/account_test.go +++ b/core/btc/account_test.go @@ -351,6 +351,10 @@ func TestAccount_SignPsbt(t *testing.T) { txn, err := acc.SignPsbt(psbtHex) require.NoError(t, err) require.True(t, txn.Packet.IsComplete()) + + res, err := txn.PsbtHexString() + require.NoError(t, err) + t.Log("signed result: ", res.Value) } func TestChain_PushPsbt(t *testing.T) { diff --git a/core/btc/transaction_psbt.go b/core/btc/transaction_psbt.go index 14d9bac..0085b00 100644 --- a/core/btc/transaction_psbt.go +++ b/core/btc/transaction_psbt.go @@ -1,6 +1,9 @@ package btc import ( + "bytes" + "encoding/hex" + "github.com/btcsuite/btcd/btcutil/psbt" "github.com/coming-chat/wallet-SDK/core/base" ) @@ -44,6 +47,19 @@ func (t *SignedPsbtTransaction) HexString() (res *base.OptionalString, err error return nil, base.ErrUnsupportedFunction } +func (t *SignedPsbtTransaction) PsbtHexString() (*base.OptionalString, error) { + packet := t.Packet + if err := EnsurePsbtFinalize(&packet); err != nil { + return nil, err + } + var buff bytes.Buffer + if err := packet.Serialize(&buff); err != nil { + return nil, err + } + hexString := hex.EncodeToString(buff.Bytes()) + return &base.OptionalString{Value: hexString}, nil +} + func (t *SignedPsbtTransaction) PublishWithChain(c *Chain) (hashs *base.OptionalString, err error) { defer base.CatchPanicAndMapToBasicError(&err)