on master help sign in
fix: clean up console.logs and add sanity check for new balance
commit9ab590ecfb97bddad186afb7b24910565791d0d8 authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateTue 27 Aug 2019, 13:46 (7 years ago) parent6a54528
1 file changed+21−4
src/lib/tank.js+21−4
src/lib/tank.js+21−4
@@ -81,20 +81,36 @@ const ensureFundsFor = async (
8181
8282 const res = await fundTransactions(signedTxs);
8383 if (!res.success) {
84− throw new Error('tank: request rejected', res);
84+ throw new Error(`tank: request rejected ${JSON.stringify(res)}`);
8585 }
8686
8787 await waitForTransactionConfirm(web3, res.txHash);
8888
8989 const newBalance = await web3.eth.getBalance(address);
90+
91+ // sanity check
92+ if (newBalance.lt(cost)) {
93+ throw new Error(
94+ `tank: transaction funded but the new balance of ` +
95+ `${newBalance.toString()}wei is still less than ` +
96+ `${cost.toString()}wei.`
97+ );
98+ }
99+
90100 console.log(
91101 `tank: funds have confirmed: ${address} now has ` +
92102 ` ${newBalance.toString()}wei, up from ${balance.toString()}wei`
93103 );
94104 return true;
95− } catch (e) {
96− console.log('tank: funding failed, waiting on user funds...', e);
97− await waitForBalance(web3, address, cost, askForFunding, gotFunding);
105+ } catch (error) {
106+ console.error(error);
107+ await waitForBalance(
108+ web3,
109+ address,
110+ cost.toString(),
111+ askForFunding,
112+ gotFunding
113+ );
98114 }
99115
100116 return false;
@@ -102,6 +118,7 @@ const ensureFundsFor = async (
102118
103119// returns a promise that resolves when address has at least minBalance
104120function waitForBalance(web3, address, minBalance, askForFunding, gotFunding) {
121+ minBalance = toBN(minBalance);
105122 return retry(async (bail, n) => {
106123 const balance = toBN(await web3.eth.getBalance(address));
107124 if (balance.gte(minBalance)) {