lnsocket

A minimal C library for connecting to the lightning network
git clone git://jb55.com/lnsocket
Log | Files | Refs | Submodules | README | LICENSE

commit 64338fe2d7d9a0fa5c8d91d12529b146bb2db213
parent 9e5d61433d389894a9b39840be20f41d3494c05f
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 16 Mar 2022 18:03:38 -0700

lnsocket.js: add destroy method

We need this to free wasm resources

Diffstat:
M.gitignore | 1+
Mexamples/node.js | 2+-
Mlnsocket_lib.js | 6++++++
3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore @@ -15,3 +15,4 @@ node_modules package-lock.json /libsodium*.tar.gz /deps/libsodium +/deps/secp256k1 diff --git a/examples/node.js b/examples/node.js @@ -16,7 +16,7 @@ async function go() { } }) - ln.disconnect() + ln.destroy() console.log(summary.result) return summary.result } diff --git a/lnsocket_lib.js b/lnsocket_lib.js @@ -63,6 +63,7 @@ async function lnsocket_init() { const COMMANDO_REPLY_TERM = 0x594d const lnsocket_create = module.cwrap("lnsocket_create", "number") + const lnsocket_destroy = module.cwrap("lnsocket_destroy", "number") const lnsocket_encrypt = module.cwrap("lnsocket_encrypt", "number", ["int", "array", "int", "int"]) const lnsocket_decrypt = module.cwrap("lnsocket_decrypt", "number", ["int", "array", "int"]) const lnsocket_msgbuf = module.cwrap("lnsocket_msgbuf", "number", ["int"]) @@ -291,6 +292,11 @@ async function lnsocket_init() { return false } + LNSocket.prototype.destroy = function _lnsocket_destroy() { + this.disconnect() + lnsocket_destroy(this.ln) + } + function handle_connect(ln, node_id, host) { const ws = new SocketImpl(host) return new Promise((resolve, reject) => {