ADD: some util cli scripts
This commit is contained in:
		
							parent
							
								
									cc4503ecbd
								
							
						
					
					
						commit
						070a7d8232
					
				
							
								
								
									
										46
									
								
								scripts/important-channels.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								scripts/important-channels.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					let important_channels = {
 | 
				
			||||||
 | 
					  '02d23fa6794d8fd056c757f3c8f4877782138dafffedc831fc570cab572620dc61': 'paywithmoon.com',
 | 
				
			||||||
 | 
					  '03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f': 'ACINQ',
 | 
				
			||||||
 | 
					  '03abf6f44c355dec0d5aa155bdbdd6e0c8fefe318eff402de65c6eb2e1be55dc3e': 'OpenNode',
 | 
				
			||||||
 | 
					  '0242a4ae0c5bef18048fbecf995094b74bfb0f7391418d71ed394784373f41e4f3': 'coingate.com',
 | 
				
			||||||
 | 
					  '0232e20e7b68b9b673fb25f48322b151a93186bffe4550045040673797ceca43cf': 'zigzag.io',
 | 
				
			||||||
 | 
					  '024a2e265cd66066b78a788ae615acdc84b5b0dec9efac36d7ac87513015eaf6ed': 'Bitrefill.com/lightning',
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					let lightning = require('../lightning');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					lightning.listChannels({}, function(err, response) {
 | 
				
			||||||
 | 
					  console.log();
 | 
				
			||||||
 | 
					  if (err) {
 | 
				
			||||||
 | 
					    console.error('lnd failure:', err);
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  let lightningListChannels = response;
 | 
				
			||||||
 | 
					  for (let channel of lightningListChannels.channels) {
 | 
				
			||||||
 | 
					    if (channel.capacity < 5000000) {
 | 
				
			||||||
 | 
					      console.log(
 | 
				
			||||||
 | 
					        'lncli closechannel',
 | 
				
			||||||
 | 
					        channel.channel_point.replace(':', ' '),
 | 
				
			||||||
 | 
					        (!channel.active && '--force') || '',
 | 
				
			||||||
 | 
					        '#',
 | 
				
			||||||
 | 
					        'low capacity channel',
 | 
				
			||||||
 | 
					        channel.capacity / 100000000,
 | 
				
			||||||
 | 
					        'btc',
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for (let 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  openchannel --node_key ', important, '--local_amt  16777215', '#', important_channels[important]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  process.exit();
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
							
								
								
									
										58
									
								
								scripts/show_user.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								scripts/show_user.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,58 @@
 | 
				
			|||||||
 | 
					import { User } from '../class/';
 | 
				
			||||||
 | 
					import { BigNumber } from 'bignumber.js';
 | 
				
			||||||
 | 
					const config = require('../config');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var Redis = require('ioredis');
 | 
				
			||||||
 | 
					var redis = new Redis(config.redis);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					redis.info(function(err, info) {
 | 
				
			||||||
 | 
					  if (err || !info) {
 | 
				
			||||||
 | 
					    console.error('redis failure');
 | 
				
			||||||
 | 
					    process.exit(5);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					let bitcoinclient = require('../bitcoin');
 | 
				
			||||||
 | 
					let lightning = require('../lightning');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					(async () => {
 | 
				
			||||||
 | 
					  let userid = process.argv[2];
 | 
				
			||||||
 | 
					  let U = new User(redis, bitcoinclient, lightning);
 | 
				
			||||||
 | 
					  U._userid = userid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let userinvoices = await U.getUserInvoices();
 | 
				
			||||||
 | 
					  let txs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let calculatedBalance = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  console.log('\ndb balance\n==============\n', await U.getBalance());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  console.log('\nuserinvoices\n================\n');
 | 
				
			||||||
 | 
					  for (let invo of userinvoices) {
 | 
				
			||||||
 | 
					    if (invo && invo.ispaid) {
 | 
				
			||||||
 | 
					      console.log('+', +invo.amt, new Date(invo.timestamp * 1000).toString());
 | 
				
			||||||
 | 
					      calculatedBalance += +invo.amt;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  console.log('\ntxs\n===\n');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  txs = await U.getTxs();
 | 
				
			||||||
 | 
					  for (let tx of txs) {
 | 
				
			||||||
 | 
					    if (tx.type === 'bitcoind_tx') {
 | 
				
			||||||
 | 
					      console.log('+', new BigNumber(tx.amount).multipliedBy(100000000).toNumber(), '[on-chain refill]');
 | 
				
			||||||
 | 
					      calculatedBalance += new BigNumber(tx.amount).multipliedBy(100000000).toNumber();
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      console.log('-', +tx.value, new Date(tx.timestamp * 1000).toString(), tx.memo, '; preimage:', tx.payment_preimage || '');
 | 
				
			||||||
 | 
					      calculatedBalance -= +tx.value;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let locked = await U.getLockedPayments();
 | 
				
			||||||
 | 
					  for (let loc of locked) {
 | 
				
			||||||
 | 
					    console.log('-', loc.amount + /* fee limit */ Math.floor(loc.amount * 0.01), new Date(loc.timestamp * 1000).toString(), '[locked]');
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  console.log('\ncalculatedBalance\n================\n', calculatedBalance, await U.getCalculatedBalance());
 | 
				
			||||||
 | 
					  process.exit();
 | 
				
			||||||
 | 
					})();
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user