Skip to content

Instantly share code, notes, and snippets.

@pseudozach
Created November 28, 2021 23:09
Show Gist options
  • Save pseudozach/924b34a35fdf4e08a82d03fae65c1ddd to your computer and use it in GitHub Desktop.
Save pseudozach/924b34a35fdf4e08a82d03fae65c1ddd to your computer and use it in GitHub Desktop.
Script to check balances of RSK Addresses
var shell = require('shelljs');
var axios = require('axios')
const rskapi = require('rskapi');
const client = rskapi.client('https://public-node.rsk.co:443') // rsk mainnet public node
var mgapikey = 'mgapikey';
var domain = 'mg.domain.com';
var mailgun = require('mailgun-js')({apiKey: mgapikey, domain: domain});
const mil = 1000000;
const rskDecimals = 1000000000000000000;
let repeat = setInterval(function () {(async () => {
try {
const rskbalanceresp = await client.balance('0xf20123853941CDE094b4840F95afEEc2F2b36df0');
const sovbalanceresp = await client.call('0xf20123853941CDE094b4840F95afEEc2F2b36df0', '0xEfC78FC7D48B64958315949279bA181C2114abbD', 'balanceOf(address)', ['0xf20123853941CDE094b4840F95afEEc2F2b36df0'], {});
const rskbalance = 'LNSOV Signer 0xf20123853941CDE094b4840F95afEEc2F2b36df0' + '\nRBTC: ' + parseInt(rskbalanceresp+'',16)/rskDecimals + '\n';
const sovbalance = 'SOV: ' + parseInt(sovbalanceresp+'',16)/rskDecimals + '\n';
const rbtcswapbalanceresp = await client.balance('0x9b076B17D7F9C17b7004aa865c707a68d29eB476');
const erc20swapsovbalanceresp = await client.call('0xf20123853941CDE094b4840F95afEEc2F2b36df0', '0xEfC78FC7D48B64958315949279bA181C2114abbD', 'balanceOf(address)', ['0x1a43aB13AB58de67b4E7EeDE60F1Fc08BB02e643'], {});
const rbtcswapbalance = 'rbtc swap contract 0x9b076B17D7F9C17b7004aa865c707a68d29eB476' + '\nRBTC: ' + parseInt(rbtcswapbalanceresp+'',16)/rskDecimals + '\n';
const erc20swapsovbalance = 'erc20 swap contract 0xEfC78FC7D48B64958315949279bA181C2114abbD' + '\nSOV: ' + parseInt(erc20swapsovbalanceresp+'',16)/rskDecimals + '\n';
// console.log('rsk balances ', rskbalance, sovbalance, rbtcswapbalance, erc20swapsovbalance);
// bitcoin
let onchainbalance = 'Onchain ' + shell.exec('lncli walletbalance | jq .total_balance').stdout.trim() + '\n';
let lnbalance = 'LN ' + shell.exec("lncli listchannels | jq -r '.channels[].local_balance' | awk '{sum+=$1} END {print sum}'").stdout.trim() + '\n';;
// console.log('btc balances: ', onchainbalance, lnbalance);
let emailtext = 'Balance Report for All Acccounts on BuyVM\n\n';
emailtext += 'RSK\n' + rskbalance + sovbalance + rbtcswapbalance + erc20swapsovbalance + '\n\n';
emailtext += 'BTC\n' + onchainbalance + lnbalance + '\n\n';
console.log(emailtext);
sendemail(emailtext);
} catch (err) {
console.log(`error: `, err)
}
})()}, (24*60*60)*1000);
function sendemail (balance) {
console.log(`sending email with balance ${balance}`)
// var htmlbody = '<html>userId: '+req.query.userId+'<br/>address: '+req.query.address+'<br/>amount: $'+req.query.balance+' </html>';
//send these via email
var topupemail = {
from: '<balancemonitor@mg.domain.com>',
to: ["balancemonitor@domain.com", "otheraddress@gmail.com"],
subject: 'buyvm balances',
text: balance,
// html: htmlbody,
// "h:Reply-To": req.query.email
};
mailgun.messages().send(topupemail, function (error, body) {
console.log("sent balancemonitor email: ", body);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment