@@ -55,41 +55,43 @@ const ensureFundsFor = async (
56 let balance = await web3.eth.getBalance(address);
56 let balance = await web3.eth.getBalance(address);
58− if (cost > balance) {
58+ if (cost <= balance) {
59− try {
59+ console.log('tank: already have sufficient funds', cost, address, balance);
60− if (point !== null) {
60+ return false;
61− const fundsRemaining = await remainingTransactions(point);
62− if (fundsRemaining < signedTxs.length) {
63− throw new Error('tank: request invalid');
66− console.log('tank: skipping remaining-funds check');
67− //TODO if we can't always (easily) provide a point, and the
68− // fundTransactions call is gonna fail anyway, should we maybe
69− // just not bother doing this check in the first place?
72− const res = await fundTransactions(signedTxs);
63+ try {
73− if (!res.success) {
64+ if (point !== null) {
65+ const fundsRemaining = await remainingTransactions(point);
66+ if (fundsRemaining < signedTxs.length) {
74− throw new Error('tank: request rejected', res);
67+ throw new Error('tank: request invalid');
76− await waitForTransactionConfirm(web3, res.txHash);
77− let newBalance = await web3.eth.getBalance(address);
79− 'tank: funds have confirmed',
86− } catch (e) {
69+ } else {
87− console.log('tank: funding failed', e);
70+ console.log('tank: no point provided. skipping remaining-funds check');
88− await waitForBalance(web3, address, cost, askForFunding, gotFunding);
71+ //TODO if we can't always (easily) provide a point, and the
72+ // fundTransactions call is gonna fail anyway, should we maybe
73+ // just not bother doing this check in the first place?
91− console.log('tank: already have sufficient funds', cost, address, balance);
76+ const res = await fundTransactions(signedTxs);
78+ throw new Error('tank: request rejected', res);
81+ await waitForTransactionConfirm(web3, res.txHash);
82+ const newBalance = await web3.eth.getBalance(address);
84+ 'tank: funds have confirmed',
91+ console.log('tank: funding failed, waiting on user funds.', e);
92+ await waitForBalance(web3, address, cost, askForFunding, gotFunding);
93 return false;
95 return false;