Skip to content

Commit cd599b0

Browse files
committed
test: implement SignPsbt RPC
1 parent 45aa156 commit cd599b0

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

test/walletkit_mock.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package test
22

33
import (
4+
"bytes"
45
"context"
56
"errors"
67
"fmt"
@@ -246,6 +247,25 @@ func (m *mockWalletKit) FundPsbt(_ context.Context,
246247
return nil, 0, nil, nil
247248
}
248249

250+
// finalScriptWitness is a sample signature suitable to put into PSBT.
251+
var finalScriptWitness = func() []byte {
252+
const pver = 0
253+
var buf bytes.Buffer
254+
255+
// Write the number of witness elements.
256+
if err := wire.WriteVarInt(&buf, pver, 1); err != nil {
257+
panic(err)
258+
}
259+
260+
// Write a single witness element with a signature.
261+
signature := make([]byte, 64)
262+
if err := wire.WriteVarBytes(&buf, pver, signature); err != nil {
263+
panic(err)
264+
}
265+
266+
return buf.Bytes()
267+
}()
268+
249269
// SignPsbt expects a partial transaction with all inputs and outputs
250270
// fully declared and tries to sign all unsigned inputs that have all
251271
// required fields (UTXO information, BIP32 derivation information,
@@ -258,9 +278,19 @@ func (m *mockWalletKit) FundPsbt(_ context.Context,
258278
// locking or input/output/fee value validation, PSBT finalization). Any
259279
// input that is incomplete will be skipped.
260280
func (m *mockWalletKit) SignPsbt(_ context.Context,
261-
_ *psbt.Packet) (*psbt.Packet, error) {
281+
packet *psbt.Packet) (*psbt.Packet, error) {
262282

263-
return nil, nil
283+
inputs := make([]psbt.PInput, len(packet.Inputs))
284+
copy(inputs, packet.Inputs)
285+
286+
for i := range inputs {
287+
inputs[i].FinalScriptWitness = finalScriptWitness
288+
}
289+
290+
signedPacket := *packet
291+
signedPacket.Inputs = inputs
292+
293+
return &signedPacket, nil
264294
}
265295

266296
// FinalizePsbt expects a partial transaction with all inputs and

0 commit comments

Comments
 (0)