Add listunspent RPC call

Returns a brief json summary of each utxo found by calling
ListUnspentWitness in the wallet. The two arguments are the
minimum and maximum number of conrfirmations (0=include
unconfirmed)
This commit is contained in:
AdamISZ committed 2018-12-11 15:26:38 +01:00
1 parent 71444e74ac
commit 9bb2a26948
12 files changed
+1076 -558

No files matched your search

+2
View File
@@ -29,6 +29,8 @@ description):
`lnd`.
* SendCoins
* Sends an amount of satoshis to a specific address.
* ListUnspent
* Lists available utxos within a range of confirmations.
* SubscribeTransactions
* Returns a stream which sends async notifications each time a transaction
is created or one is received that pays to us.
+693 -543
View File
File diff suppressed because it is too large. Load diff
+50
View File
@@ -124,6 +124,23 @@ func request_Lightning_SendCoins_0(ctx context.Context, marshaler runtime.Marsha
}
var (
filter_Lightning_ListUnspent_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_Lightning_ListUnspent_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ListUnspentRequest
var metadata runtime.ServerMetadata
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_Lightning_ListUnspent_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.ListUnspent(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
var (
filter_Lightning_NewAddress_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
@@ -1018,6 +1035,35 @@ func RegisterLightningHandler(ctx context.Context, mux *runtime.ServeMux, conn *
})
mux.Handle("GET", pattern_Lightning_ListUnspent_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
if cn, ok := w.(http.CloseNotifier); ok {
go func(done <-chan struct{}, closed <-chan bool) {
select {
case <-done:
case <-closed:
cancel()
}
}(ctx.Done(), cn.CloseNotify())
}
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Lightning_ListUnspent_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Lightning_ListUnspent_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Lightning_NewAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
@@ -1900,6 +1946,8 @@ var (
pattern_Lightning_SendCoins_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "transactions"}, ""))
pattern_Lightning_ListUnspent_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "utxos"}, ""))
pattern_Lightning_NewAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "newaddress"}, ""))
pattern_Lightning_SignMessage_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "signmessage"}, ""))
@@ -1970,6 +2018,8 @@ var (
forward_Lightning_SendCoins_0 = runtime.ForwardResponseMessage
forward_Lightning_ListUnspent_0 = runtime.ForwardResponseMessage
forward_Lightning_NewAddress_0 = runtime.ForwardResponseMessage
forward_Lightning_SignMessage_0 = runtime.ForwardResponseMessage
+48 -3
View File
@@ -231,6 +231,16 @@ service Lightning {
};
}
/** lncli: `listunspent`
ListUnspent returns a list of all utxos spendable by the wallet with a
number of confirmations between the specified minimum and maximum.
*/
rpc ListUnspent (ListUnspentRequest) returns (ListUnspentResponse) {
option (google.api.http) = {
get: "/v1/utxos"
};
}
/**
SubscribeTransactions creates a uni-directional stream from the server to
the client in which any newly discovered transactions relevant to the
@@ -657,6 +667,28 @@ service Lightning {
};
}
message Utxo {
/// The type of address
AddressType type = 1 [json_name = "address_type"];
/// 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 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 number of confirmations for the Utxo
int64 confirmations = 6 [json_name = "confirmations"];
}
message Transaction {
/// The transaction hash
string tx_hash = 1 [ json_name = "tx_hash" ];
@@ -808,18 +840,31 @@ message SendCoinsResponse {
string txid = 1 [json_name = "txid"];
}
message ListUnspentRequest {
/// The minimum number of confirmations to be included.
int32 min_confs = 1;
/// The maximum number of confirmations to be included.
int32 max_confs = 2;
}
message ListUnspentResponse {
/// A list of utxos
repeated Utxo utxos = 1 [json_name = "utxos"];
}
/**
`AddressType` has to be one of:
- `p2wkh`: Pay to witness key hash (`WITNESS_PUBKEY_HASH` = 0)
- `np2wkh`: Pay to nested witness key hash (`NESTED_PUBKEY_HASH` = 1)
*/
message NewAddressRequest {
enum AddressType {
enum AddressType {
WITNESS_PUBKEY_HASH = 0;
NESTED_PUBKEY_HASH = 1;
}
}
message NewAddressRequest {
/// The address type
AddressType type = 1;
}
+88
View File
@@ -1051,6 +1051,41 @@
]
}
},
"/v1/utxos": {
"get": {
"summary": "* lncli: `listunspent`\nListUnspent returns a list of all utxos spendable by the wallet with a\nnumber of confirmations between the specified minimum and maximum.",
"operationId": "ListUnspent",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/lnrpcListUnspentResponse"
}
}
},
"parameters": [
{
"name": "min_confs",
"description": "/ The minimum number of confirmations to be included.",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "max_confs",
"description": "/ The maximum number of confirmations to be included.",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
}
],
"tags": [
"Lightning"
]
}
},
"/v1/verifymessage": {
"post": {
"summary": "* lncli: `verifymessage`\nVerifyMessage verifies a signature over a msg. The signature must be\nzbase32 encoded and signed by an active node in the resident node's\nchannel database. In addition to returning the validity of the signature,\nVerifyMessage also returns the recovered pubkey from the signature.",
@@ -1231,6 +1266,16 @@
}
}
},
"lnrpcAddressType": {
"type": "string",
"enum": [
"WITNESS_PUBKEY_HASH",
"NESTED_PUBKEY_HASH"
],
"default": "WITNESS_PUBKEY_HASH",
"description": "- `p2wkh`: Pay to witness key hash (`WITNESS_PUBKEY_HASH` = 0)\n- `np2wkh`: Pay to nested witness key hash (`NESTED_PUBKEY_HASH` = 1)",
"title": "* \n`AddressType` has to be one of:"
},
"lnrpcChangePasswordRequest": {
"type": "object",
"properties": {
@@ -2194,6 +2239,18 @@
}
}
},
"lnrpcListUnspentResponse": {
"type": "object",
"properties": {
"utxos": {
"type": "array",
"items": {
"$ref": "#/definitions/lnrpcUtxo"
},
"title": "/ A list of utxos"
}
}
},
"lnrpcNetworkInfo": {
"type": "object",
"properties": {
@@ -2919,6 +2976,37 @@
"lnrpcUnlockWalletResponse": {
"type": "object"
},
"lnrpcUtxo": {
"type": "object",
"properties": {
"type": {
"$ref": "#/definitions/lnrpcAddressType",
"title": "/ The type of address"
},
"address": {
"type": "string",
"title": "/ The address"
},
"amount_sat": {
"type": "string",
"format": "int64",
"title": "/ The value of the unspent coin in satoshis"
},
"script_pubkey": {
"type": "string",
"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"
},
"confirmations": {
"type": "string",
"format": "int64",
"title": "/ The number of confirmations for the Utxo"
}
}
},
"lnrpcVerifyMessageRequest": {
"type": "object",
"properties": {