lncli+docs: fix outpoint serialization in JSON output

This commit fixes the JSON output of the outpoint field of locked UTXOs
in the response of the PSBT fund command.
This commit is contained in:
Oliver Gugger 2020-10-05 11:23:33 +02:00
parent 0c0d114d18
commit 8e9f37b0fc
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 25 additions and 25 deletions

View File

@ -415,12 +415,19 @@ func labelTransaction(ctx *cli.Context) error {
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.
type fundPsbtResponse struct {
Psbt string `json:"psbt"`
ChangeOutputIndex int32 `json:"change_output_index"`
Locks []*walletrpc.UtxoLease `json:"locks"`
Psbt string `json:"psbt"`
ChangeOutputIndex int32 `json:"change_output_index"`
Locks []*utxoLease `json:"locks"`
}
var fundPsbtCommand = cli.Command{
@ -592,12 +599,21 @@ func fundPsbt(ctx *cli.Context) error {
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{
Psbt: base64.StdEncoding.EncodeToString(
response.FundedPsbt,
),
ChangeOutputIndex: response.ChangeOutputIndex,
Locks: response.LockedUtxos,
Locks: jsonLocks,
})
return nil

View File

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