ClosedChannels
ClosedChannels returns a description of all the closed channels that this node was a participant in.
Source: lightning.proto
gRPC
rpc ClosedChannels (ClosedChannelsRequest) returns (ClosedChannelsResponse);
REST
HTTP Method | Path |
---|---|
GET | /v1/channels/closed |
Code Samples
- gRPC
- REST
- Shell
- Javascript
- Python
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 = {
cooperative: <bool>,
local_force: <bool>,
remote_force: <bool>,
breach: <bool>,
funding_canceled: <bool>,
abandoned: <bool>,
};
client.closedChannels(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "channels": <ChannelCloseSummary>,
// }
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.ClosedChannelsRequest(
cooperative=<bool>,
local_force=<bool>,
remote_force=<bool>,
breach=<bool>,
funding_canceled=<bool>,
abandoned=<bool>,
)
response = stub.ClosedChannels(request)
print(response)
# {
# "channels": <ChannelCloseSummary>,
# }
- Javascript
- Python
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/channels/closed`,
// 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:
// {
// "channels": <array>, // <ChannelCloseSummary>
// }
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/channels/closed'
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())
# {
# "channels": <ChannelCloseSummary>,
# }
$ lncli closedchannels --help
NAME:
lncli closedchannels - List all closed channels.
USAGE:
lncli closedchannels [command options] [arguments...]
CATEGORY:
Channels
OPTIONS:
--cooperative list channels that were closed cooperatively
--local_force list channels that were force-closed by the local node
--remote_force list channels that were force-closed by the remote node
--breach list channels for which the remote node attempted to broadcast a prior revoked channel state
--funding_canceled list channels that were never fully opened
--abandoned list channels that were abandoned by the local node
Messages
lnrpc.ClosedChannelsRequest
Source: lightning.proto
Field | gRPC Type | REST Type | REST Placement |
---|---|---|---|
cooperative | bool | boolean | query |
local_force | bool | boolean | query |
remote_force | bool | boolean | query |
breach | bool | boolean | query |
funding_canceled | bool | boolean | query |
abandoned | bool | boolean | query |
lnrpc.ClosedChannelsResponse
Source: lightning.proto
Field | gRPC Type | REST Type |
---|---|---|
channels | ChannelCloseSummary[] | array |
Nested Messages
lnrpc.ChannelCloseSummary
Field | gRPC Type | REST Type |
---|---|---|
channel_point | string | string |
chan_id | uint64 | string |
chain_hash | string | string |
closing_tx_hash | string | string |
remote_pubkey | string | string |
capacity | int64 | string |
close_height | uint32 | integer |
settled_balance | int64 | string |
time_locked_balance | int64 | string |
close_type | ClosureType | string |
open_initiator | Initiator | string |
close_initiator | Initiator | string |
resolutions | Resolution[] | array |
alias_scids | uint64[] | array |
zero_conf_confirmed_scid | uint64 | string |
lnrpc.Resolution
Field | gRPC Type | REST Type |
---|---|---|
resolution_type | ResolutionType | string |
outcome | ResolutionOutcome | string |
outpoint | OutPoint | object |
amount_sat | uint64 | string |
sweep_txid | string | string |
lnrpc.OutPoint
Field | gRPC Type | REST Type |
---|---|---|
txid_bytes | bytes | string |
txid_str | string | string |
output_index | uint32 | integer |
Enums
lnrpc.ChannelCloseSummary.ClosureType
Name | Number |
---|---|
COOPERATIVE_CLOSE | 0 |
LOCAL_FORCE_CLOSE | 1 |
REMOTE_FORCE_CLOSE | 2 |
BREACH_CLOSE | 3 |
FUNDING_CANCELED | 4 |
ABANDONED | 5 |
lnrpc.Initiator
Name | Number |
---|---|
INITIATOR_UNKNOWN | 0 |
INITIATOR_LOCAL | 1 |
INITIATOR_REMOTE | 2 |
INITIATOR_BOTH | 3 |
lnrpc.ResolutionType
Name | Number |
---|---|
TYPE_UNKNOWN | 0 |
ANCHOR | 1 |
INCOMING_HTLC | 2 |
OUTGOING_HTLC | 3 |
COMMIT | 4 |
lnrpc.ResolutionOutcome
Name | Number |
---|---|
OUTCOME_UNKNOWN | 0 |
CLAIMED | 1 |
UNCLAIMED | 2 |
ABANDONED | 3 |
FIRST_STAGE | 4 |
TIMEOUT | 5 |