Skip to content

Commit

Permalink
feat: btc add psbtHexString func.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhangguiguang committed Apr 9, 2024
1 parent a63102d commit a2e2b99
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/btc/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions core/btc/transaction_psbt.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package btc

import (
"bytes"
"encoding/hex"

"github.com/btcsuite/btcd/btcutil/psbt"
"github.com/coming-chat/wallet-SDK/core/base"
)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit a2e2b99

Please sign in to comment.