on master help sign in
Merge pull request #384 from urbit/m/reticket-bugs
b595254Fang
src/lib/reticket.js+27−27
@@ -148,13 +148,12 @@ export async function reticketPointBetweenWallets({
148
148
149 progress(TRANSACTION_PROGRESS.SIGNING);
149 progress(TRANSACTION_PROGRESS.SIGNING);
150
150
151− const suggestedGasPrice = await getSuggestedGasPrice(networkType);
151+ const gasPriceGwei = (await getSuggestedGasPrice(networkType)).toFixed();
152 const chainId = await web3.eth.net.getId();
152 const chainId = await web3.eth.net.getId();
153− const gasPrice = safeToWei(suggestedGasPrice.toFixed(), 'gwei');
153+ const gasPriceWeiBN = toBN(safeToWei(gasPriceGwei, 'gwei'));
154− const gasPriceBN = toBN(gasPrice);
155 let inviteNonce = await web3.eth.getTransactionCount(fromWallet.address);
154 let inviteNonce = await web3.eth.getTransactionCount(fromWallet.address);
156 const totalCost = txs.reduce(
155 const totalCost = txs.reduce(
157− (acc, tx) => acc.add(gasPriceBN.mul(toBN(tx.gas))),
156+ (acc, tx) => acc.add(gasPriceWeiBN.mul(toBN(tx.gas))),
158 toBN(0)
157 toBN(0)
159 );
158 );
160
159
@@ -170,7 +169,7 @@ export async function reticketPointBetweenWallets({
170 txn: txs[i],
169 txn: txs[i],
171 nonce: inviteNonce + i,
170 nonce: inviteNonce + i,
172 chainId,
171 chainId,
173− gasPrice: suggestedGasPrice.toFixed(),
172+ gasPrice: gasPriceGwei,
174 gasLimit: txs[i].gas,
173 gasLimit: txs[i].gas,
175 });
174 });
176 txPairs.push({
175 txPairs.push({
@@ -215,29 +214,30 @@ export async function reticketPointBetweenWallets({
215 // if non-trivial eth left in invite wallet, transfer to new ownership
214 // if non-trivial eth left in invite wallet, transfer to new ownership
216 let balance = toBN(await web3.eth.getBalance(fromWallet.address));
215 let balance = toBN(await web3.eth.getBalance(fromWallet.address));
217 const gasLimit = GAS_LIMITS.SEND_ETH;
216 const gasLimit = GAS_LIMITS.SEND_ETH;
218− const sendEthCost = gasPriceBN.mul(toBN(gasLimit));
217+ const sendEthCost = gasPriceWeiBN.mul(toBN(gasLimit));
219 if (transferEth && balance.gt(sendEthCost)) {
218 if (transferEth && balance.gt(sendEthCost)) {
219+ try {
220− const value = balance.sub(sendEthCost);
220+ const value = balance.sub(sendEthCost);
221− const txn = {
221+ const txn = {
222− to: toWallet.ownership.keys.address,
222+ to: toWallet.ownership.keys.address,
223− value: value,
223+ value: value,
224− };
224+ };
225− const stx = signTransaction({
225+ const stx = await signTransaction({
226− wallet: fromWallet,
226+ wallet: fromWallet,
227− walletType: fromWalletType,
227+ walletType: fromWalletType,
228− walletHdPath: fromWalletHdPath,
228+ walletHdPath: fromWalletHdPath,
229− txn,
229+ txn,
230− chainId,
230+ chainId,
231− networkType,
231+ networkType,
232− gasPrice: gasPriceBN,
232+ gasPrice: gasPriceGwei,
233− gasLimit,
233+ gasLimit,
234− nonce: inviteNonce++,
234+ nonce: inviteNonce,
235− });
235+ });
236− // let stx = new Tx(tx);
237− // stx.sign(fromWallet.privateKey);
238− sendSignedTransaction(web3, stx).catch(err => {
236+ sendSignedTransaction(web3, stx);
237+ } catch (err) {
239− console.log('error sending value tx, who cares', err);
238+ console.log('error sending value tx, safely ignored:');
239+ console.log(err);
240− });
240+ }
241 }
241 }
242
242
243 progress(TRANSACTION_PROGRESS.DONE);
243 progress(TRANSACTION_PROGRESS.DONE);
src/lib/txn.js+8−8
@@ -127,20 +127,20 @@ const sendSignedTransaction = (web3, stx, doubtNonceError) => {
127 // if there's a nonce error, but we used the gas tank, it's likely
127 // if there's a nonce error, but we used the gas tank, it's likely
128 // that it's because the tank already submitted our transaction.
128 // that it's because the tank already submitted our transaction.
129 // we just wait for first confirmation here.
129 // we just wait for first confirmation here.
130− console.error(err);
130+ const message = err.message || '';
131− const isKnownError = (err.message || '').includes(
131+ const isKnownError = message.includes('known transaction: ');
132− 'known transaction: '
133− );
134− const isNonceError = (err.message || '').includes(
132+ const isNonceError =
135− "the tx doesn't have the correct nonce."
133+ message.includes("the tx doesn't have the correct nonce.") ||
136− );
134+ message.includes('nonce too low');
137 if (isKnownError || (doubtNonceError && isNonceError)) {
135 if (isKnownError || (doubtNonceError && isNonceError)) {
138 console.log(
136 console.log(
139− 'tx send error likely from gas tank submission, ignoring'
137+ 'tx send error likely from gas tank submission, ignoring:',
138+ message
140 );
139 );
141 const txHash = web3.utils.keccak256(rawTx);
140 const txHash = web3.utils.keccak256(rawTx);
142 resolve(txHash);
141 resolve(txHash);
143 } else {
142 } else {
143+ console.error(err);
144 reject(err.message || 'Transaction sending failed!');
144 reject(err.message || 'Transaction sending failed!');
145 }
145 }
146 });
146 });