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),
|
MinConfs: int32(minConfirms),
|
||||||
MaxConfs: int32(maxConfirms),
|
MaxConfs: int32(maxConfirms),
|
||||||
}
|
}
|
||||||
jsonResponse, err := client.ListUnspent(ctxb, req)
|
resp, err := client.ListUnspent(ctxb, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
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})
|
DIRECTORY=$(dirname ${file})
|
||||||
echo "Generating protos from ${file}, into ${DIRECTORY}"
|
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 \
|
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
|
||||||
--go_out=plugins=grpc,paths=source_relative:. \
|
--go_out=plugins=grpc,paths=source_relative:. \
|
||||||
${file}
|
${file}
|
||||||
|
|||||||
+605
-548
File diff suppressed because it is too large.
Load diff
+23
-14
@@ -669,25 +669,23 @@ service Lightning {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message Utxo {
|
message Utxo {
|
||||||
/// The type of address
|
/// The type of address
|
||||||
AddressType type = 1 [json_name = "address_type"];
|
AddressType type = 1 [json_name = "address_type"];
|
||||||
|
|
||||||
/// The address
|
/// The address
|
||||||
string address = 2 [json_name = "address"];
|
string address = 2 [json_name = "address"];
|
||||||
|
|
||||||
/// The value of the unspent coin in satoshis
|
/// The value of the unspent coin in satoshis
|
||||||
int64 amount_sat = 3 [json_name = "amount_sat"];
|
int64 amount_sat = 3 [json_name = "amount_sat"];
|
||||||
|
|
||||||
/// The scriptpubkey in hex
|
/// The scriptpubkey in hex
|
||||||
string script_pubkey = 4 [json_name = "script_pubkey"];
|
string script_pubkey = 4 [json_name = "script_pubkey"];
|
||||||
|
|
||||||
/// The outpoint in format txid:n
|
/// The outpoint in format txid:n
|
||||||
/// Note that this reuses the `ChannelPoint` message but
|
OutPoint outpoint = 5 [json_name = "outpoint"];
|
||||||
/// is not actually a channel related outpoint, of course
|
|
||||||
ChannelPoint outpoint = 5 [json_name = "outpoint"];
|
|
||||||
|
|
||||||
/// The number of confirmations for the Utxo
|
/// The number of confirmations for the Utxo
|
||||||
int64 confirmations = 6 [json_name = "confirmations"];
|
int64 confirmations = 6 [json_name = "confirmations"];
|
||||||
}
|
}
|
||||||
|
|
||||||
message Transaction {
|
message Transaction {
|
||||||
@@ -800,6 +798,17 @@ message ChannelPoint {
|
|||||||
uint32 output_index = 3 [json_name = "output_index"];
|
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 {
|
message LightningAddress {
|
||||||
/// The identity pubkey of the Lightning node
|
/// The identity pubkey of the Lightning node
|
||||||
string pubkey = 1 [json_name = "pubkey"];
|
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": {
|
"lnrpcPayReq": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -3014,8 +3033,8 @@
|
|||||||
"title": "/ The scriptpubkey in hex"
|
"title": "/ The scriptpubkey in hex"
|
||||||
},
|
},
|
||||||
"outpoint": {
|
"outpoint": {
|
||||||
"$ref": "#/definitions/lnrpcChannelPoint",
|
"$ref": "#/definitions/lnrpcOutPoint",
|
||||||
"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"
|
"title": "/ The outpoint in format txid:n"
|
||||||
},
|
},
|
||||||
"confirmations": {
|
"confirmations": {
|
||||||
"type": "string",
|
"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,
|
// Now that we know we have a proper mapping to an address,
|
||||||
// we'll convert the regular outpoint to an lnrpc variant.
|
// we'll convert the regular outpoint to an lnrpc variant.
|
||||||
outpoint := &lnrpc.ChannelPoint{
|
outpoint := &lnrpc.OutPoint{
|
||||||
FundingTxid: &lnrpc.ChannelPoint_FundingTxidStr{
|
TxidBytes: utxo.OutPoint.Hash[:],
|
||||||
FundingTxidStr: utxo.OutPoint.Hash.String(),
|
TxidStr: utxo.OutPoint.Hash.String(),
|
||||||
},
|
|
||||||
OutputIndex: utxo.OutPoint.Index,
|
OutputIndex: utxo.OutPoint.Index,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user