LookupInvoice
LookupInvoice attempts to look up an invoice according to its payment hash. The passed payment hash must be exactly 32 bytes, if not, an error is returned.
Source: lightning.proto
gRPC
rpc LookupInvoice (PaymentHash) returns (Invoice);
REST
| HTTP Method | Path |
|---|---|
| GET | /v1/invoice/{r_hash_str} |
Code Samples
- gRPC
- REST
- lncli
- Javascript
- Python
- grpcurl
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const GRPC_HOST = 'localhost:10009'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
const TLS_PATH = 'LND_DIR/tls.cert'
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new lnrpc.Lightning(GRPC_HOST, creds);
let request = {
r_hash_str: <string>,
r_hash: <bytes>,
};
client.lookupInvoice(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "memo": <string>,
// "r_preimage": <bytes>,
// "r_hash": <bytes>,
// "value": <int64>,
// "value_msat": <int64>,
// "settled": <bool>,
// "creation_date": <int64>,
// "settle_date": <int64>,
// "payment_request": <string>,
// "description_hash": <bytes>,
// "expiry": <int64>,
// "fallback_addr": <string>,
// "cltv_expiry": <uint64>,
// "route_hints": <RouteHint>,
// "private": <bool>,
// "add_index": <uint64>,
// "settle_index": <uint64>,
// "amt_paid": <int64>,
// "amt_paid_sat": <int64>,
// "amt_paid_msat": <int64>,
// "state": <InvoiceState>,
// "htlcs": <InvoiceHTLC>,
// "features": <FeaturesEntry>,
// "is_keysend": <bool>,
// "payment_addr": <bytes>,
// "is_amp": <bool>,
// "amp_invoice_state": <AmpInvoiceStateEntry>,
// "is_blinded": <bool>,
// "blinded_path_config": <BlindedPathConfig>,
// }
import codecs, grpc, os
# Generate the following 2 modules by compiling the lightning.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
GRPC_HOST = 'localhost:10009'
MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
TLS_PATH = 'LND_DIR/tls.cert'
# create macaroon credentials
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
def metadata_callback(context, callback):
callback([('macaroon', macaroon)], None)
auth_creds = grpc.metadata_call_credentials(metadata_callback)
# create SSL credentials
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
cert = open(TLS_PATH, 'rb').read()
ssl_creds = grpc.ssl_channel_credentials(cert)
# combine macaroon and SSL credentials
combined_creds = grpc.composite_channel_credentials(ssl_creds, auth_creds)
# make the request
channel = grpc.secure_channel(GRPC_HOST, combined_creds)
stub = lightningstub.LightningStub(channel)
request = lnrpc.PaymentHash(
r_hash_str=<string>,
r_hash=<bytes>,
)
response = stub.LookupInvoice(request)
print(response)
# {
# "memo": <string>,
# "r_preimage": <bytes>,
# "r_hash": <bytes>,
# "value": <int64>,
# "value_msat": <int64>,
# "settled": <bool>,
# "creation_date": <int64>,
# "settle_date": <int64>,
# "payment_request": <string>,
# "description_hash": <bytes>,
# "expiry": <int64>,
# "fallback_addr": <string>,
# "cltv_expiry": <uint64>,
# "route_hints": <RouteHint>,
# "private": <bool>,
# "add_index": <uint64>,
# "settle_index": <uint64>,
# "amt_paid": <int64>,
# "amt_paid_sat": <int64>,
# "amt_paid_msat": <int64>,
# "state": <InvoiceState>,
# "htlcs": <InvoiceHTLC>,
# "features": <FeaturesEntry>,
# "is_keysend": <bool>,
# "payment_addr": <bytes>,
# "is_amp": <bool>,
# "amp_invoice_state": <AmpInvoiceStateEntry>,
# "is_blinded": <bool>,
# "blinded_path_config": <BlindedPathConfig>,
# }
# grpcurl docs: https://github.com/fullstorydev/grpcurl
# Proto source: https://github.com/lightningnetwork/lnd
GRPC_HOST=localhost:10009
LND_DIR=~/.lnd
LND_SOURCE=path/to/lnd
NETWORK=mainnet
MACAROON_PATH="$LND_DIR/data/chain/bitcoin/$NETWORK/admin.macaroon"
TLS_PATH="$LND_DIR/tls.cert"
grpcurl \
-import-path $LND_SOURCE/lnrpc/ \
-proto lightning.proto \
-cacert $TLS_PATH \
-H "macaroon: $(xxd -ps -u -c 1000 $MACAROON_PATH)" \
-d '{ "r_hash_str": <string>, "r_hash": BASE64_ENCODED_VALUE }' \
$GRPC_HOST \
lnrpc.Lightning/LookupInvoice
- Javascript
- Python
- curl
const fs = require('fs');
const request = require('request');
const REST_HOST = 'localhost:8080'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
let options = {
url: `https://${REST_HOST}/v1/invoice/{r_hash_str}`,
// Work-around for self-signed certificates.
rejectUnauthorized: false,
json: true,
headers: {
'Grpc-Metadata-macaroon': fs.readFileSync(MACAROON_PATH).toString('hex'),
},
}
request.get(options, function(error, response, body) {
console.log(body);
});
// Console output:
// {
// "memo": <string>, // <string>
// "r_preimage": <string>, // <bytes>
// "r_hash": <string>, // <bytes>
// "value": <string>, // <int64>
// "value_msat": <string>, // <int64>
// "settled": <boolean>, // <bool>
// "creation_date": <string>, // <int64>
// "settle_date": <string>, // <int64>
// "payment_request": <string>, // <string>
// "description_hash": <string>, // <bytes>
// "expiry": <string>, // <int64>
// "fallback_addr": <string>, // <string>
// "cltv_expiry": <string>, // <uint64>
// "route_hints": <array>, // <RouteHint>
// "private": <boolean>, // <bool>
// "add_index": <string>, // <uint64>
// "settle_index": <string>, // <uint64>
// "amt_paid": <string>, // <int64>
// "amt_paid_sat": <string>, // <int64>
// "amt_paid_msat": <string>, // <int64>
// "state": <string>, // <InvoiceState>
// "htlcs": <array>, // <InvoiceHTLC>
// "features": <object>, // <FeaturesEntry>
// "is_keysend": <boolean>, // <bool>
// "payment_addr": <string>, // <bytes>
// "is_amp": <boolean>, // <bool>
// "amp_invoice_state": <object>, // <AmpInvoiceStateEntry>
// "is_blinded": <boolean>, // <bool>
// "blinded_path_config": <object>, // <BlindedPathConfig>
// }
import base64, codecs, json, requests
REST_HOST = 'localhost:8080'
MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
TLS_PATH = 'LND_DIR/tls.cert'
url = f'https://{REST_HOST}/v1/invoice/{r_hash_str}'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
r = requests.get(url, headers=headers, verify=TLS_PATH)
print(r.json())
# {
# "memo": <string>,
# "r_preimage": <bytes>,
# "r_hash": <bytes>,
# "value": <int64>,
# "value_msat": <int64>,
# "settled": <bool>,
# "creation_date": <int64>,
# "settle_date": <int64>,
# "payment_request": <string>,
# "description_hash": <bytes>,
# "expiry": <int64>,
# "fallback_addr": <string>,
# "cltv_expiry": <uint64>,
# "route_hints": <RouteHint>,
# "private": <bool>,
# "add_index": <uint64>,
# "settle_index": <uint64>,
# "amt_paid": <int64>,
# "amt_paid_sat": <int64>,
# "amt_paid_msat": <int64>,
# "state": <InvoiceState>,
# "htlcs": <InvoiceHTLC>,
# "features": <FeaturesEntry>,
# "is_keysend": <bool>,
# "payment_addr": <bytes>,
# "is_amp": <bool>,
# "amp_invoice_state": <AmpInvoiceStateEntry>,
# "is_blinded": <bool>,
# "blinded_path_config": <BlindedPathConfig>,
# }
REST_HOST=localhost:8080
LND_DIR=~/.lnd
NETWORK=mainnet
MACAROON_PATH="$LND_DIR/data/chain/bitcoin/$NETWORK/admin.macaroon"
TLS_PATH="$LND_DIR/tls.cert"
curl \
--cacert $TLS_PATH \
-H "Grpc-Metadata-macaroon: $(xxd -ps -u -c 1000 $MACAROON_PATH)" \
https://$REST_HOST/v1/invoice/{r_hash_str}
$ lncli lookupinvoice --help
NAME:
lncli lookupinvoice - Lookup an existing invoice by its payment hash.
USAGE:
lncli lookupinvoice [command options] rhash
CATEGORY:
Invoices
OPTIONS:
--rhash value the 32 byte payment hash of the invoice to query for, the hash should be a hex-encoded string
Messages
lnrpc.PaymentHash
Source: lightning.proto
| Field | gRPC Type | REST Type | REST Placement |
|---|---|---|---|
r_hash_strdeprecated | string | string | path |
r_hash | bytes | string | query |
lnrpc.Invoice
Source: lightning.proto
| Field | gRPC Type | REST Type |
|---|---|---|
memo | string | string |
r_preimage | bytes | string |
r_hash | bytes | string |
value | int64 | string |
value_msat | int64 | string |
settleddeprecated | bool | boolean |
creation_date | int64 | string |
settle_date | int64 | string |
payment_request | string | string |
description_hash | bytes | string |
expiry | int64 | string |
fallback_addr | string | string |
cltv_expiry | uint64 | string |
route_hints | RouteHint[] | array |
private | bool | boolean |
add_index | uint64 | string |
settle_index | uint64 | string |
amt_paiddeprecated | int64 | string |
amt_paid_sat | int64 | string |
amt_paid_msat | int64 | string |
state | InvoiceState | string |
htlcs | InvoiceHTLC[] | array |
features | FeaturesEntry[] | object |
is_keysend | bool | boolean |
payment_addr | bytes | string |
is_amp | bool | boolean |
amp_invoice_state | AmpInvoiceStateEntry[] | object |
is_blinded | bool | boolean |
blinded_path_config | BlindedPathConfig | object |
Nested Messages
lnrpc.AMP
| Field | gRPC Type | REST Type |
|---|---|---|
root_share | bytes | string |
set_id | bytes | string |
child_index | uint32 | integer |
hash | bytes | string |
preimage | bytes | string |
lnrpc.AMPInvoiceState
| Field | gRPC Type | REST Type |
|---|---|---|
state | InvoiceHTLCState | string |
settle_index | uint64 | string |
settle_time | int64 | string |
amt_paid_msat | int64 | string |
lnrpc.BlindedPathConfig
| Field | gRPC Type | REST Type |
|---|---|---|
min_num_real_hops | uint32 | integer |
num_hops | uint32 | integer |
max_num_paths | uint32 | integer |
node_omission_list | bytes[] | array |
incoming_channel_list | uint64[] | array |
lnrpc.Feature
| Field | gRPC Type | REST Type |
|---|---|---|
name | string | string |
is_required | bool | boolean |
is_known | bool | boolean |
lnrpc.HopHint
| Field | gRPC Type | REST Type |
|---|---|---|
node_id | string | string |
chan_id | uint64 | string |
fee_base_msat | uint32 | integer |
fee_proportional_millionths | uint32 | integer |
cltv_expiry_delta | uint32 | integer |
lnrpc.Invoice.AmpInvoiceStateEntry
| Field | gRPC Type | REST Type |
|---|---|---|
key | string | unknown |
value | AMPInvoiceState | unknown |
lnrpc.Invoice.FeaturesEntry
| Field | gRPC Type | REST Type |
|---|---|---|
key | uint32 | unknown |
value | Feature | unknown |
lnrpc.InvoiceHTLC
| Field | gRPC Type | REST Type |
|---|---|---|
chan_id | uint64 | string |
htlc_index | uint64 | string |
amt_msat | uint64 | string |
accept_height | int32 | integer |
accept_time | int64 | string |
resolve_time | int64 | string |
expiry_height | int32 | integer |
state | InvoiceHTLCState | string |
custom_records | CustomRecordsEntry[] | object |
mpp_total_amt_msat | uint64 | string |
amp | AMP | object |
custom_channel_data | bytes | string |
lnrpc.InvoiceHTLC.CustomRecordsEntry
| Field | gRPC Type | REST Type |
|---|---|---|
key | uint64 | unknown |
value | bytes | unknown |
lnrpc.RouteHint
| Field | gRPC Type | REST Type |
|---|---|---|
hop_hints | HopHint[] | array |
Enums
lnrpc.Invoice.InvoiceState
| Name | Number |
|---|---|
OPEN | 0 |
SETTLED | 1 |
CANCELED | 2 |
ACCEPTED | 3 |
lnrpc.InvoiceHTLCState
| Name | Number |
|---|---|
ACCEPTED | 0 |
SETTLED | 1 |
CANCELED | 2 |