@@ -38,6 +38,10 @@ const fundTransactions = signedTxs => {
38 return sendRequest('/request', {txs:signedTxs});
38 return sendRequest('/request', {txs:signedTxs});
41+// resolves when address has at least cost balance
42+// returns true if gas tank was used, false otherwise
43+// askForFunding: callback that takes (address, requiredBalance, currentBalance)
44+// and tells the user to get that address the required balance
41const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFunding) => {
45const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFunding) => {
42 let balance = await web3.eth.getBalance(address);
46 let balance = await web3.eth.getBalance(address);
@@ -45,9 +49,16 @@ const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFundi
52+ if (point !== null) {
48− const fundsRemaining = await remainingTransactions(point);
53+ const fundsRemaining = await remainingTransactions(point);
49− if (fundsRemaining < signedTxs.length) {
54+ if (fundsRemaining < signedTxs.length) {
50− throw new Error('tank: request invalid');
55+ throw new Error('tank: request invalid');
58+ console.log('tank: skipping remaining-funds check');
59+ //TODO if we can't always (easily) provide a point, and the
60+ // fundTransactions call is gonna fail anyway, should we maybe
61+ // just not bother doing this check in the first place?
53 const res = await fundTransactions(signedTxs);
64 const res = await fundTransactions(signedTxs);
@@ -57,6 +68,7 @@ const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFundi
57 await waitForTransactionConfirm(web3, res.txHash);
68 await waitForTransactionConfirm(web3, res.txHash);
58 let newBalance = await web3.eth.getBalance(address);
69 let newBalance = await web3.eth.getBalance(address);
59 console.log('tank: funds have confirmed', balance >= cost, balance, newBalance);
70 console.log('tank: funds have confirmed', balance >= cost, balance, newBalance);
62 } catch (e) {
74 } catch (e) {
@@ -69,12 +81,12 @@ const ensureFundsFor = async (web3, point, address, cost, signedTxs, askForFundi
70 console.log('tank: already have sufficient funds');
82 console.log('tank: already have sufficient funds');
74// resolves when address has at least minBalance
87// resolves when address has at least minBalance
76−// askForFunding: callback that takes (address, requiredBalance, currentBalance)
89+//TODO should maybe do a "we got it" callback also, so clients can hide msg?
77−// and tells the user to get that address the required balance
78async function waitForBalance(web3, address, minBalance, askForFunding) {
90async function waitForBalance(web3, address, minBalance, askForFunding) {
79 console.log('tank: awaiting balance', address, minBalance);
91 console.log('tank: awaiting balance', address, minBalance);
80 return new Promise((resolve, reject) => {
92 return new Promise((resolve, reject) => {