From 30422d9ac7cab360e2ee01be106a2c3d59ae206a Mon Sep 17 00:00:00 2001 From: Overtorment Date: Tue, 5 May 2020 08:22:29 +0100 Subject: [PATCH] REF --- lightning.js | 8 ++-- scripts/important-channels.js | 74 ++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/lightning.js b/lightning.js index 31fb7b3..ee4724c 100644 --- a/lightning.js +++ b/lightning.js @@ -10,7 +10,7 @@ if (process.env.TLSCERT) { } else { lndCert = fs.readFileSync('tls.cert'); } -console.log('using tls.cert', lndCert.toString('hex')); +process.env.VERBOSE && console.log('using tls.cert', lndCert.toString('hex')); let sslCreds = grpc.credentials.createSsl(lndCert); let macaroon; if (process.env.MACAROON) { @@ -18,7 +18,7 @@ if (process.env.MACAROON) { } else { macaroon = fs.readFileSync('admin.macaroon').toString('hex'); } -console.log('using macaroon', macaroon); +process.env.VERBOSE && console.log('using macaroon', macaroon); let macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) { let metadata = new grpc.Metadata(); metadata.add('macaroon', macaroon); @@ -28,7 +28,7 @@ let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds); // trying to unlock the wallet: if (config.lnd.password) { - console.log('trying to unlock the wallet'); + process.env.VERBOSE && console.log('trying to unlock the wallet'); var walletUnlocker = new lnrpc.WalletUnlocker(config.lnd.url, creds); walletUnlocker.unlockWallet( { @@ -36,7 +36,7 @@ if (config.lnd.password) { }, function(err, response) { if (err) { - console.log('unlockWallet failed, probably because its been aleady unlocked'); + process.env.VERBOSE && console.log('unlockWallet failed, probably because its been aleady unlocked'); } else { console.log('unlockWallet:', response); } diff --git a/scripts/important-channels.js b/scripts/important-channels.js index 6e8c3a3..b687d81 100644 --- a/scripts/important-channels.js +++ b/scripts/important-channels.js @@ -72,50 +72,52 @@ lightning.listChannels({}, function(err, response) { } } - console.log('# reconnect important channels that are inactive:\n'); + if (process.argv.includes('--reconnect')) { + console.log('# reconnect important channels that are inactive:\n'); + for (const important of Object.keys(important_channels)) { + for (let channel of lightningListChannels.channels) { + if (channel.remote_pubkey === important && !channel.active) { + console.log( + 'lncli disconnect', + channel.remote_pubkey, + '; sleep 5;', + 'lncli connect', + important_channels[channel.remote_pubkey].uri, + '#', + important_channels[channel.remote_pubkey].name, + ); + } + } + } + } - for (const important of Object.keys(important_channels)) { - for (let channel of lightningListChannels.channels) { - if (channel.remote_pubkey === important && !channel.active) { + if (process.argv.includes('--open')) { + console.log('\n# open important channels:\n'); + for (const important of Object.keys(important_channels)) { + let atLeastOneChannelIsSufficientCapacity = false; + for (let channel of lightningListChannels.channels) { + if (channel.remote_pubkey === important && channel.local_balance >= 4000000 && channel.active) { + atLeastOneChannelIsSufficientCapacity = true; + } + } + + if (!atLeastOneChannelIsSufficientCapacity) { console.log( 'lncli disconnect', - channel.remote_pubkey, - '; sleep 5;', - 'lncli connect', - important_channels[channel.remote_pubkey].uri, + important, + '; sleep 3;', + 'lncli openchannel --node_key', + important, + '--connect', + important_channels[important].uri.split('@')[1], + '--local_amt', + important_channels[important].wumbo ? '167772150' : '16777215', '#', - important_channels[channel.remote_pubkey].name, + important_channels[important].name, ); } } } - console.log('\n# open important channels:\n'); - - for (const important of Object.keys(important_channels)) { - let atLeastOneChannelIsSufficientCapacity = false; - for (let channel of lightningListChannels.channels) { - if (channel.remote_pubkey === important && channel.local_balance >= 4000000 && channel.active) { - atLeastOneChannelIsSufficientCapacity = true; - } - } - - if (!atLeastOneChannelIsSufficientCapacity) { - console.log( - 'lncli disconnect', - important, - '; sleep 3;', - 'lncli openchannel --node_key', - important, - '--connect', - important_channels[important].uri.split('@')[1], - '--local_amt', - important_channels[important].wumbo ? '167772150' : '16777215', - '#', - important_channels[important].name, - ); - } - } - process.exit(); });