on master help sign in
fix: clean up console.logs and add sanity check for new balance
9ab590eMatt Condon (shrugs)
src/lib/tank.js+21−4
@@ -81,20 +81,36 @@ const ensureFundsFor = async (
81
81
82 const res = await fundTransactions(signedTxs);
82 const res = await fundTransactions(signedTxs);
83 if (!res.success) {
83 if (!res.success) {
84− throw new Error('tank: request rejected', res);
84+ throw new Error(`tank: request rejected ${JSON.stringify(res)}`);
85 }
85 }
86
86
87 await waitForTransactionConfirm(web3, res.txHash);
87 await waitForTransactionConfirm(web3, res.txHash);
88
88
89 const newBalance = await web3.eth.getBalance(address);
89 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+
90 console.log(
100 console.log(
91 `tank: funds have confirmed: ${address} now has ` +
101 `tank: funds have confirmed: ${address} now has ` +
92 ` ${newBalance.toString()}wei, up from ${balance.toString()}wei`
102 ` ${newBalance.toString()}wei, up from ${balance.toString()}wei`
93 );
103 );
94 return true;
104 return true;
95− } catch (e) {
105+ } catch (error) {
96− console.log('tank: funding failed, waiting on user funds...', e);
106+ console.error(error);
97− await waitForBalance(web3, address, cost, askForFunding, gotFunding);
107+ await waitForBalance(
108+ web3,
109+ address,
110+ cost.toString(),
111+ askForFunding,
112+ gotFunding
113+ );
98 }
114 }
99
115
100 return false;
116 return false;
@@ -102,6 +118,7 @@ const ensureFundsFor = async (
102
118
103// returns a promise that resolves when address has at least minBalance
119// returns a promise that resolves when address has at least minBalance
104function waitForBalance(web3, address, minBalance, askForFunding, gotFunding) {
120function waitForBalance(web3, address, minBalance, askForFunding, gotFunding) {
121+ minBalance = toBN(minBalance);
105 return retry(async (bail, n) => {
122 return retry(async (bail, n) => {
106 const balance = toBN(await web3.eth.getBalance(address));
123 const balance = toBN(await web3.eth.getBalance(address));
107 if (balance.gte(minBalance)) {
124 if (balance.gte(minBalance)) {