Merge pull request #2477 from cfromknecht/utxo-lnrpc
lnrpc: replace ChanPoint w/ OutPoint in ListUnspent resp
This commit is contained in:
7 files changed
+710
-571
No files matched your search
+17
-2
@@ -340,11 +340,26 @@ func listUnspent(ctx *cli.Context) error {
|
||||
MinConfs: int32(minConfirms),
|
||||
MaxConfs: int32(maxConfirms),
|
||||
}
|
||||
jsonResponse, err := client.ListUnspent(ctxb, req)
|
||||
resp, err := client.ListUnspent(ctxb, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printRespJSON(jsonResponse)
|
||||
|
||||
// Parse the response into the final json object that will be printed
|
||||
// to stdout. At the moment, this filters out the raw txid bytes from
|
||||
// each utxo's outpoint and only prints the txid string.
|
||||
var listUnspentResp = struct {
|
||||
Utxos []*Utxo `json:"utxos"`
|
||||
}{
|
||||
Utxos: make([]*Utxo, 0, len(resp.Utxos)),
|
||||
}
|
||||
for _, protoUtxo := range resp.Utxos {
|
||||
utxo := NewUtxoFromProto(protoUtxo)
|
||||
listUnspentResp.Utxos = append(listUnspentResp.Utxos, utxo)
|
||||
}
|
||||
|
||||
printJSON(listUnspentResp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
)
|
||||
|
||||
// OutPoint displays an outpoint string in the form "<txid>:<output-index>".
|
||||
type OutPoint string
|
||||
|
||||
// NewOutPointFromProto formats the lnrpc.OutPoint into an OutPoint for display.
|
||||
func NewOutPointFromProto(op *lnrpc.OutPoint) OutPoint {
|
||||
return OutPoint(fmt.Sprintf("%s:%d", op.TxidStr, op.OutputIndex))
|
||||
}
|
||||
|
||||
// Utxo displays information about an unspent output, including its address,
|
||||
// amount, pkscript, and confirmations.
|
||||
type Utxo struct {
|
||||
Type lnrpc.AddressType `json:"address_type"`
|
||||
Address string `json:"address"`
|
||||
AmountSat int64 `json:"amount_sat"`
|
||||
ScriptPubkey string `json:"script_pubkey"`
|
||||
OutPoint OutPoint `json:"outpoint"`
|
||||
Confirmations int64 `json:"confirmations"`
|
||||
}
|
||||
|
||||
// NewUtxoFromProto creates a display Utxo from the Utxo proto. This filters out
|
||||
// the raw txid bytes from the provided outpoint, which will otherwise be
|
||||
// printed in base64.
|
||||
func NewUtxoFromProto(utxo *lnrpc.Utxo) *Utxo {
|
||||
return &Utxo{
|
||||
Type: utxo.Type,
|
||||
Address: utxo.Address,
|
||||
AmountSat: utxo.AmountSat,
|
||||
ScriptPubkey: utxo.ScriptPubkey,
|
||||
OutPoint: NewOutPointFromProto(utxo.Outpoint),
|
||||
Confirmations: utxo.Confirmations,
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -27,7 +27,7 @@ do
|
||||
DIRECTORY=$(dirname ${file})
|
||||
echo "Generating protos from ${file}, into ${DIRECTORY}"
|
||||
|
||||
protoc -I/usr/local/include -I.\
|
||||
protoc -I/usr/local/include -I. \
|
||||
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
|
||||
--go_out=plugins=grpc,paths=source_relative:. \
|
||||
${file}
|
||||
|
||||
+605
-548
File diff suppressed because it is too large.
Load diff
+23
-14
@@ -669,25 +669,23 @@ service Lightning {
|
||||
}
|
||||
|
||||
message Utxo {
|
||||
/// The type of address
|
||||
AddressType type = 1 [json_name = "address_type"];
|
||||
/// The type of address
|
||||
AddressType type = 1 [json_name = "address_type"];
|
||||
|
||||
/// The address
|
||||
string address = 2 [json_name = "address"];
|
||||
/// The address
|
||||
string address = 2 [json_name = "address"];
|
||||
|
||||
/// The value of the unspent coin in satoshis
|
||||
int64 amount_sat = 3 [json_name = "amount_sat"];
|
||||
/// The value of the unspent coin in satoshis
|
||||
int64 amount_sat = 3 [json_name = "amount_sat"];
|
||||
|
||||
/// The scriptpubkey in hex
|
||||
string script_pubkey = 4 [json_name = "script_pubkey"];
|
||||
/// The scriptpubkey in hex
|
||||
string script_pubkey = 4 [json_name = "script_pubkey"];
|
||||
|
||||
/// The outpoint in format txid:n
|
||||
/// Note that this reuses the `ChannelPoint` message but
|
||||
/// is not actually a channel related outpoint, of course
|
||||
ChannelPoint outpoint = 5 [json_name = "outpoint"];
|
||||
/// The outpoint in format txid:n
|
||||
OutPoint outpoint = 5 [json_name = "outpoint"];
|
||||
|
||||
/// The number of confirmations for the Utxo
|
||||
int64 confirmations = 6 [json_name = "confirmations"];
|
||||
/// The number of confirmations for the Utxo
|
||||
int64 confirmations = 6 [json_name = "confirmations"];
|
||||
}
|
||||
|
||||
message Transaction {
|
||||
@@ -800,6 +798,17 @@ message ChannelPoint {
|
||||
uint32 output_index = 3 [json_name = "output_index"];
|
||||
}
|
||||
|
||||
message OutPoint {
|
||||
/// Raw bytes representing the transaction id.
|
||||
bytes txid_bytes = 1 [json_name = "txid_bytes"];
|
||||
|
||||
/// Reversed, hex-encoded string representing the transaction id.
|
||||
string txid_str = 2 [json_name = "txid_str"];
|
||||
|
||||
/// The index of the output on the transaction.
|
||||
uint32 output_index = 3 [json_name = "output_index"];
|
||||
}
|
||||
|
||||
message LightningAddress {
|
||||
/// The identity pubkey of the Lightning node
|
||||
string pubkey = 1 [json_name = "pubkey"];
|
||||
|
||||
+21
-2
@@ -2435,6 +2435,25 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"lnrpcOutPoint": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"txid_bytes": {
|
||||
"type": "string",
|
||||
"format": "byte",
|
||||
"description": "/ Raw bytes representing the transaction id."
|
||||
},
|
||||
"txid_str": {
|
||||
"type": "string",
|
||||
"description": "/ Reversed, hex-encoded string representing the transaction id."
|
||||
},
|
||||
"output_index": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"description": "/ The index of the output on the transaction."
|
||||
}
|
||||
}
|
||||
},
|
||||
"lnrpcPayReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -3014,8 +3033,8 @@
|
||||
"title": "/ The scriptpubkey in hex"
|
||||
},
|
||||
"outpoint": {
|
||||
"$ref": "#/definitions/lnrpcChannelPoint",
|
||||
"title": "/ The outpoint in format txid:n\n/ Note that this reuses the `ChannelPoint` message but\n/ is not actually a channel related outpoint, of course"
|
||||
"$ref": "#/definitions/lnrpcOutPoint",
|
||||
"title": "/ The outpoint in format txid:n"
|
||||
},
|
||||
"confirmations": {
|
||||
"type": "string",
|
||||
|
||||
+3
-4
@@ -717,10 +717,9 @@ func (r *rpcServer) ListUnspent(ctx context.Context,
|
||||
|
||||
// Now that we know we have a proper mapping to an address,
|
||||
// we'll convert the regular outpoint to an lnrpc variant.
|
||||
outpoint := &lnrpc.ChannelPoint{
|
||||
FundingTxid: &lnrpc.ChannelPoint_FundingTxidStr{
|
||||
FundingTxidStr: utxo.OutPoint.Hash.String(),
|
||||
},
|
||||
outpoint := &lnrpc.OutPoint{
|
||||
TxidBytes: utxo.OutPoint.Hash[:],
|
||||
TxidStr: utxo.OutPoint.Hash.String(),
|
||||
OutputIndex: utxo.OutPoint.Index,
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user