1
1
package test
2
2
3
3
import (
4
+ "bytes"
4
5
"context"
5
6
"errors"
6
7
"fmt"
@@ -246,6 +247,25 @@ func (m *mockWalletKit) FundPsbt(_ context.Context,
246
247
return nil , 0 , nil , nil
247
248
}
248
249
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
+
249
269
// SignPsbt expects a partial transaction with all inputs and outputs
250
270
// fully declared and tries to sign all unsigned inputs that have all
251
271
// required fields (UTXO information, BIP32 derivation information,
@@ -258,9 +278,19 @@ func (m *mockWalletKit) FundPsbt(_ context.Context,
258
278
// locking or input/output/fee value validation, PSBT finalization). Any
259
279
// input that is incomplete will be skipped.
260
280
func (m * mockWalletKit ) SignPsbt (_ context.Context ,
261
- _ * psbt.Packet ) (* psbt.Packet , error ) {
281
+ packet * psbt.Packet ) (* psbt.Packet , error ) {
262
282
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
264
294
}
265
295
266
296
// FinalizePsbt expects a partial transaction with all inputs and
0 commit comments