psbt: Indicate which psbt inputs were signed
This commit is contained in:
1 parent
ba8b8d4e17
commit
b2e624cd52
10 files changed
+210
-172
No files matched your search
@@ -98,12 +98,16 @@ func (b *BtcWallet) FundPsbt(packet *psbt.Packet, minConfs int32,
|
||||
// perform any other tasks (such as coin selection, UTXO locking or
|
||||
// input/output/fee value validation, PSBT finalization). Any input that is
|
||||
// incomplete will be skipped.
|
||||
func (b *BtcWallet) SignPsbt(packet *psbt.Packet) error {
|
||||
func (b *BtcWallet) SignPsbt(packet *psbt.Packet) ([]uint32, error) {
|
||||
// In signedInputs we return the indices of psbt inputs that were signed
|
||||
// by our wallet. This way the caller can check if any inputs were signed.
|
||||
var signedInputs []uint32
|
||||
|
||||
// Let's check that this is actually something we can and want to sign.
|
||||
// We need at least one input and one output.
|
||||
err := psbt.VerifyInputOutputLen(packet, true, true)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Go through each input that doesn't have final witness data attached
|
||||
@@ -173,7 +177,7 @@ func (b *BtcWallet) SignPsbt(packet *psbt.Packet) error {
|
||||
// information we need?
|
||||
signMethod, err := validateSigningMethod(in)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch signMethod {
|
||||
@@ -211,11 +215,11 @@ func (b *BtcWallet) SignPsbt(packet *psbt.Packet) error {
|
||||
"PSBT signing: %v", signMethod)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
signedInputs = append(signedInputs, uint32(idx))
|
||||
}
|
||||
|
||||
return nil
|
||||
return signedInputs, nil
|
||||
}
|
||||
|
||||
// validateSigningMethod attempts to detect the signing method that is required
|
||||
|
||||
@@ -318,9 +318,13 @@ func TestSignPsbt(t *testing.T) {
|
||||
|
||||
// Let the wallet do its job. We expect to be the only signer
|
||||
// for this PSBT, so we'll be able to finalize it later.
|
||||
err = w.SignPsbt(packet)
|
||||
signedInputs, err := w.SignPsbt(packet)
|
||||
require.NoError(t, err)
|
||||
|
||||
// We expect one signed input at index 0.
|
||||
require.Len(t, signedInputs, 1)
|
||||
require.EqualValues(t, 0, signedInputs[0])
|
||||
|
||||
// If the witness stack needs to be assembled, give the caller
|
||||
// the option to do that now.
|
||||
tc.inputType.finalize(t, packet)
|
||||
|
||||
@@ -428,7 +428,7 @@ type WalletController interface {
|
||||
// does not perform any other tasks (such as coin selection, UTXO
|
||||
// locking or input/output/fee value validation, PSBT finalization). Any
|
||||
// input that is incomplete will be skipped.
|
||||
SignPsbt(packet *psbt.Packet) error
|
||||
SignPsbt(packet *psbt.Packet) ([]uint32, error)
|
||||
|
||||
// FinalizePsbt expects a partial transaction with all inputs and
|
||||
// outputs fully declared and tries to sign all inputs that belong to
|
||||
|
||||
@@ -188,13 +188,13 @@ func (r *RPCKeyRing) SendOutputs(outputs []*wire.TxOut,
|
||||
// perform any other tasks (such as coin selection, UTXO locking or
|
||||
// input/output/fee value validation, PSBT finalization). Any input that is
|
||||
// incomplete will be skipped.
|
||||
func (r *RPCKeyRing) SignPsbt(packet *psbt.Packet) error {
|
||||
func (r *RPCKeyRing) SignPsbt(packet *psbt.Packet) ([]uint32, error) {
|
||||
ctxt, cancel := context.WithTimeout(context.Background(), r.rpcTimeout)
|
||||
defer cancel()
|
||||
|
||||
var buf bytes.Buffer
|
||||
if err := packet.Serialize(&buf); err != nil {
|
||||
return fmt.Errorf("error serializing PSBT: %v", err)
|
||||
return nil, fmt.Errorf("error serializing PSBT: %v", err)
|
||||
}
|
||||
|
||||
resp, err := r.walletClient.SignPsbt(ctxt, &walletrpc.SignPsbtRequest{
|
||||
@@ -202,7 +202,7 @@ func (r *RPCKeyRing) SignPsbt(packet *psbt.Packet) error {
|
||||
})
|
||||
if err != nil {
|
||||
considerShutdown(err)
|
||||
return fmt.Errorf("error signing PSBT in remote signer "+
|
||||
return nil, fmt.Errorf("error signing PSBT in remote signer "+
|
||||
"instance: %v", err)
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ func (r *RPCKeyRing) SignPsbt(packet *psbt.Packet) error {
|
||||
bytes.NewReader(resp.SignedPsbt), false,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing signed PSBT: %v", err)
|
||||
return nil, fmt.Errorf("error parsing signed PSBT: %v", err)
|
||||
}
|
||||
|
||||
// The caller expects the packet to be modified instead of a new
|
||||
@@ -221,7 +221,7 @@ func (r *RPCKeyRing) SignPsbt(packet *psbt.Packet) error {
|
||||
packet.Outputs = signedPacket.Outputs
|
||||
packet.Unknowns = signedPacket.Unknowns
|
||||
|
||||
return nil
|
||||
return resp.SignedInputs, nil
|
||||
}
|
||||
|
||||
// FinalizePsbt expects a partial transaction with all inputs and outputs fully
|
||||
|
||||
Reference in new issue
Block a user