diff --git a/bin/MasterDistiller.js b/bin/MasterDistiller.js index 405372af81a1c4e96a276d479762dcf28b2bbdfe..47a73c7702aa13a450d328d1b136e08db1a140fc 100755 --- a/bin/MasterDistiller.js +++ b/bin/MasterDistiller.js @@ -30,12 +30,13 @@ function init() if ( table[i] == notation.potency ) notation.name = table[i+1] if ( undefined == notation.name ) - notation = { 'potency': 15, 'name': 'finney' }; - notation.num = BigNumber( 10 ).pow( notation.potency ); + notation = { 'potency': 15, 'name': 'finney' }; + notation.num = BigNumber( 10 ).pow( notation.potency ); bfa = new Libbfa(); web3 = bfa.newweb3(); Distillery = bfa.contract( web3, 'Distillery' ); - requestBalances(); + requestDistBalance() + .then( requestBalances ) } function palletSort(a,b) @@ -58,13 +59,17 @@ function palletSort(a,b) return 0; } +async function requestDistBalance() +{ + return web3.eth.getBalance(Distillery.contractaddress) + .then( (bal) => { return Distillery.contractbalance = new BigNumber( bal ) } ) +} + async function requestBalances() { - var distbal = await web3.eth.getBalance(Distillery.contractaddress); var count = await Distillery.methods.numberOfBeneficiaries().call(); var pallet = new Array; var i; - Distillery.contractbalance = new BigNumber( distbal ); // Fetch addresses from the list in the contract. for ( i=0; i<count; i++ ) { @@ -126,7 +131,21 @@ function editAccount( entry, pallet ) + rcpt.gasUsed + " gas." ); - requestBalances(); + var beforeBal = Distillery.contractbalance; + requestDistBalance() + .then( + function() + { + console.log( + "Distributed " + + beforeBal.minus( Distillery.contractbalance ).div( notation.num ).toFixed() + + " " + + notation.name + + "." + ); + requestBalances(); + } + ) } } );