Merge pull request #4673 from guggero/psbt-nested-segwit-fix

PSBT funding: don't include scriptSig field for nested SegWit inputs
This commit is contained in:
Olaoluwa Osuntokun 2020-10-06 15:22:37 -07:00 committed by GitHub
commit c7e948bb5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 29 deletions

View File

@ -415,12 +415,19 @@ func labelTransaction(ctx *cli.Context) error {
return nil return nil
} }
// fundPsbtResponse is a struct that contains JSOn annotations for nice result // utxoLease contains JSON annotations for a lease on an unspent output.
type utxoLease struct {
ID string `json:"id"`
OutPoint OutPoint `json:"outpoint"`
Expiration uint64 `json:"expiration"`
}
// fundPsbtResponse is a struct that contains JSON annotations for nice result
// serialization. // serialization.
type fundPsbtResponse struct { type fundPsbtResponse struct {
Psbt string `json:"psbt"` Psbt string `json:"psbt"`
ChangeOutputIndex int32 `json:"change_output_index"` ChangeOutputIndex int32 `json:"change_output_index"`
Locks []*walletrpc.UtxoLease `json:"locks"` Locks []*utxoLease `json:"locks"`
} }
var fundPsbtCommand = cli.Command{ var fundPsbtCommand = cli.Command{
@ -592,12 +599,21 @@ func fundPsbt(ctx *cli.Context) error {
return err return err
} }
jsonLocks := make([]*utxoLease, len(response.LockedUtxos))
for idx, lock := range response.LockedUtxos {
jsonLocks[idx] = &utxoLease{
ID: hex.EncodeToString(lock.Id),
OutPoint: NewOutPointFromProto(lock.Outpoint),
Expiration: lock.Expiration,
}
}
printJSON(&fundPsbtResponse{ printJSON(&fundPsbtResponse{
Psbt: base64.StdEncoding.EncodeToString( Psbt: base64.StdEncoding.EncodeToString(
response.FundedPsbt, response.FundedPsbt,
), ),
ChangeOutputIndex: response.ChangeOutputIndex, ChangeOutputIndex: response.ChangeOutputIndex,
Locks: response.LockedUtxos, Locks: jsonLocks,
}) })
return nil return nil

View File

@ -34,11 +34,7 @@ $ lncli wallet psbt fund --outputs='{"bcrt1qjrdns4f5zwkv29ln86plqzs092yd5fg6nsz8
"locks": [ "locks": [
{ {
"id": "ede19a92ed321a4705f8a1cccc1d4f6182545d4bb4fae08bd5937831b7e38f98", "id": "ede19a92ed321a4705f8a1cccc1d4f6182545d4bb4fae08bd5937831b7e38f98",
"outpoint": { "outpoint": "f8efa583e93ab71debe62a5374f91563aa10a3461518042aaddb464b656350e2:1",
"txid_bytes": "e25063654b46dbad2a04181546a310aa6315f974532ae6eb1db73ae983a5eff8",
"txid_str": "f8efa583e93ab71debe62a5374f91563aa10a3461518042aaddb464b656350e2:1",
"output_index": 1
},
"expiration": 1601553408 "expiration": 1601553408
} }
] ]
@ -174,20 +170,12 @@ $ lncli wallet psbt fund --outputs='{"bcrt1qjrdns4f5zwkv29ln86plqzs092yd5fg6nsz8
"locks": [ "locks": [
{ {
"id": "ede19a92ed321a4705f8a1cccc1d4f6182545d4bb4fae08bd5937831b7e38f98", "id": "ede19a92ed321a4705f8a1cccc1d4f6182545d4bb4fae08bd5937831b7e38f98",
"outpoint": { "outpoint": "3597b451ff56bc901eb806e8c644a004e934b4c208679756b4cddc455c768c48:1",
"txid_bytes": "488c765c45dccdb456976708c2b434e904a044c6e806b81e90bc56ff51b49735",
"txid_str": "3597b451ff56bc901eb806e8c644a004e934b4c208679756b4cddc455c768c48:1",
"output_index": 1
},
"expiration": 1601560626 "expiration": 1601560626
}, },
{ {
"id": "ede19a92ed321a4705f8a1cccc1d4f6182545d4bb4fae08bd5937831b7e38f98", "id": "ede19a92ed321a4705f8a1cccc1d4f6182545d4bb4fae08bd5937831b7e38f98",
"outpoint": { "outpoint": "f8efa583e93ab71debe62a5374f91563aa10a3461518042aaddb464b656350e2:1",
"txid_bytes": "e25063654b46dbad2a04181546a310aa6315f974532ae6eb1db73ae983a5eff8",
"txid_str": "f8efa583e93ab71debe62a5374f91563aa10a3461518042aaddb464b656350e2:1",
"output_index": 1
},
"expiration": 1601560626 "expiration": 1601560626
} }
] ]
@ -475,11 +463,7 @@ $ lncli wallet psbt fund --outputs='{"bcrt1qh33ghvgjj3ef625nl9jxz6nnrz2z9e65vsde
"locks": [ "locks": [
{ {
"id": "ede19a92ed321a4705f8a1cccc1d4f6182545d4bb4fae08bd5937831b7e38f98", "id": "ede19a92ed321a4705f8a1cccc1d4f6182545d4bb4fae08bd5937831b7e38f98",
"outpoint": { "outpoint": "3597b451ff56bc901eb806e8c644a004e934b4c208679756b4cddc455c768c48:1",
"txid_bytes": "488c765c45dccdb456976708c2b434e904a044c6e806b81e90bc56ff51b49735",
"txid_str": "3597b451ff56bc901eb806e8c644a004e934b4c208679756b4cddc455c768c48:1",
"output_index": 1
},
"expiration": 1601562037 "expiration": 1601562037
} }
] ]

2
go.mod
View File

@ -9,7 +9,7 @@ require (
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcutil v1.0.2 github.com/btcsuite/btcutil v1.0.2
github.com/btcsuite/btcutil/psbt v1.0.3-0.20200826194809-5f93e33af2b0 github.com/btcsuite/btcutil/psbt v1.0.3-0.20200826194809-5f93e33af2b0
github.com/btcsuite/btcwallet v0.11.1-0.20201002003944-e6d01202cb6b github.com/btcsuite/btcwallet v0.11.1-0.20201005184831-a7f551a6301c
github.com/btcsuite/btcwallet/wallet/txauthor v1.0.0 github.com/btcsuite/btcwallet/wallet/txauthor v1.0.0
github.com/btcsuite/btcwallet/wallet/txrules v1.0.0 github.com/btcsuite/btcwallet/wallet/txrules v1.0.0
github.com/btcsuite/btcwallet/walletdb v1.3.3 github.com/btcsuite/btcwallet/walletdb v1.3.3

4
go.sum
View File

@ -37,8 +37,8 @@ github.com/btcsuite/btcutil v1.0.2 h1:9iZ1Terx9fMIOtq1VrwdqfsATL9MC2l8ZrUY6YZ2ut
github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts= github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts=
github.com/btcsuite/btcutil/psbt v1.0.3-0.20200826194809-5f93e33af2b0 h1:3Zumkyl6PWyHuVJ04me0xeD9CnPOhNgeGpapFbzy7O4= github.com/btcsuite/btcutil/psbt v1.0.3-0.20200826194809-5f93e33af2b0 h1:3Zumkyl6PWyHuVJ04me0xeD9CnPOhNgeGpapFbzy7O4=
github.com/btcsuite/btcutil/psbt v1.0.3-0.20200826194809-5f93e33af2b0/go.mod h1:LVveMu4VaNSkIRTZu2+ut0HDBRuYjqGocxDMNS1KuGQ= github.com/btcsuite/btcutil/psbt v1.0.3-0.20200826194809-5f93e33af2b0/go.mod h1:LVveMu4VaNSkIRTZu2+ut0HDBRuYjqGocxDMNS1KuGQ=
github.com/btcsuite/btcwallet v0.11.1-0.20201002003944-e6d01202cb6b h1:gblgCqJNcFulA2eiQLweSbfB8H/0SgviQ0Bkx7ADLwE= github.com/btcsuite/btcwallet v0.11.1-0.20201005184831-a7f551a6301c h1:1FMwQTKFp9Pf7ZYW0gTHSeyIKNd1fF+wx1f2RvUHngA=
github.com/btcsuite/btcwallet v0.11.1-0.20201002003944-e6d01202cb6b/go.mod h1:owv9oZqM0HnUW+ByF7VqOgfs2eb0ooiePW/+Tl/i/Nk= github.com/btcsuite/btcwallet v0.11.1-0.20201005184831-a7f551a6301c/go.mod h1:owv9oZqM0HnUW+ByF7VqOgfs2eb0ooiePW/+Tl/i/Nk=
github.com/btcsuite/btcwallet/wallet/txauthor v1.0.0 h1:KGHMW5sd7yDdDMkCZ/JpP0KltolFsQcB973brBnfj4c= github.com/btcsuite/btcwallet/wallet/txauthor v1.0.0 h1:KGHMW5sd7yDdDMkCZ/JpP0KltolFsQcB973brBnfj4c=
github.com/btcsuite/btcwallet/wallet/txauthor v1.0.0/go.mod h1:VufDts7bd/zs3GV13f/lXc/0lXrPnvxD/NvmpG/FEKU= github.com/btcsuite/btcwallet/wallet/txauthor v1.0.0/go.mod h1:VufDts7bd/zs3GV13f/lXc/0lXrPnvxD/NvmpG/FEKU=
github.com/btcsuite/btcwallet/wallet/txrules v1.0.0 h1:2VsfS0sBedcM5KmDzRMT3+b6xobqWveZGvjb+jFez5w= github.com/btcsuite/btcwallet/wallet/txrules v1.0.0 h1:2VsfS0sBedcM5KmDzRMT3+b6xobqWveZGvjb+jFez5w=

View File

@ -1048,7 +1048,7 @@ func (w *WalletKit) FundPsbt(_ context.Context,
Id: lock.lockID[:], Id: lock.lockID[:],
Outpoint: &lnrpc.OutPoint{ Outpoint: &lnrpc.OutPoint{
TxidBytes: lock.outpoint.Hash[:], TxidBytes: lock.outpoint.Hash[:],
TxidStr: lock.outpoint.String(), TxidStr: lock.outpoint.Hash.String(),
OutputIndex: lock.outpoint.Index, OutputIndex: lock.outpoint.Index,
}, },
Expiration: uint64(lock.expiration.Unix()), Expiration: uint64(lock.expiration.Unix()),