-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatelnscribe.py
36 lines (28 loc) · 1.21 KB
/
statelnscribe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from lightning import Plugin
from lndgrpc import lnrpc
import codecs
plugin = Plugin()
@plugin.method("export-channel-state")
def export_channel_state(plugin):
# Connect to LND node using gRPC
cert = plugin.rpc.listconfigs()["tls_cert"]
macaroon = plugin.rpc.invoice("1")["payment_request"]
os.environ["GRPC_SSL_CIPHER_SUITES"] = 'HIGH+ECDSA'
creds = grpc.ssl_channel_credentials(cert)
channel = grpc.secure_channel('localhost:10009', creds)
stub = lnrpc.LightningStub(channel)
# Call listchannels gRPC method
response = stub.ListChannels(lnrpc.ListChannelsRequest())
# Print channel state and balance
for channel in response.channels:
print("Channel ID:", codecs.encode(channel.chan_id, 'hex'))
print("Channel state:", channel.channel_status)
print("Local balance:", channel.local_balance)
print("Remote balance:", channel.remote_balance)
# Call exportchanbackup gRPC method
response = stub.ExportChannelBackup(lnrpc.ChanBackupExportRequest())
# Save channel backup to file
with open('channelstate.backup', 'wb') as f:
f.write(response.backup)
return {'message': 'Channel state exported to channelstate.backup file.'}
plugin.run()