@@ -1,4 +1,3 @@
1−import Tx from 'ethereumjs-tx';
2import * as azimuth from 'azimuth-js';
1import * as azimuth from 'azimuth-js';
3import * as tank from './tank';
2import * as tank from './tank';
@@ -9,7 +8,11 @@ import {
9 CRYPTO_SUITE_VERSION,
8 CRYPTO_SUITE_VERSION,
10} from './keys';
9} from './keys';
11import { addHexPrefix } from './wallet';
10import { addHexPrefix } from './wallet';
12+ sendAndAwaitAllSerial,
14+ sendSignedTransaction,
12−import { sendAndAwaitAll } from './txn';
15+} from './txn';
13import getSuggestedGasPrice from './getSuggestedGasPrice';
16import getSuggestedGasPrice from './getSuggestedGasPrice';
14import { GAS_LIMITS } from './constants';
17import { GAS_LIMITS } from './constants';
15import { toBN } from 'web3-utils';
18import { toBN } from 'web3-utils';
@@ -29,6 +32,8 @@ export const TRANSACTION_PROGRESS = {
30export async function reticketPointBetweenWallets({
33export async function reticketPointBetweenWallets({
31 fromWallet,
34 fromWallet,
@@ -144,26 +149,37 @@ export async function reticketPointBetweenWallets({
144 progress(TRANSACTION_PROGRESS.SIGNING);
149 progress(TRANSACTION_PROGRESS.SIGNING);
146 const suggestedGasPrice = await getSuggestedGasPrice(networkType);
151 const suggestedGasPrice = await getSuggestedGasPrice(networkType);
152+ const chainId = await web3.eth.net.getId();
147 const gasPrice = safeToWei(suggestedGasPrice.toFixed(), 'gwei');
153 const gasPrice = safeToWei(suggestedGasPrice.toFixed(), 'gwei');
148 const gasPriceBN = toBN(gasPrice);
154 const gasPriceBN = toBN(gasPrice);
149− let totalCost = toBN(0);
150 let inviteNonce = await web3.eth.getTransactionCount(fromWallet.address);
155 let inviteNonce = await web3.eth.getTransactionCount(fromWallet.address);
151− txs = txs.map(tx => {
156+ const totalCost = txs.reduce(
152− tx.from = fromWallet.address;
153− tx.nonce = inviteNonce++;
154− tx.gasPrice = gasPriceBN;
155− totalCost = totalCost.add(gasPriceBN.mul(toBN(tx.gas)));
157+ (acc, tx) => acc.add(gasPriceBN.mul(toBN(tx.gas))),
156− return tx;
158+ toBN(0)
159− let txPairs = txs.map(tx => {
161+ let txPairs = [];
160− let stx = new Tx(tx);
162+
161− stx.sign(Buffer.from(fromWallet.privateKey, 'hex'));
163+ // Must be done in serial else hardware will give nonce errors
162− return {
164+ for (let i = 0; i < txs.length; i++) {
165+ const stx = await signTransaction({
167+ walletType: fromWalletType,
168+ walletHdPath: fromWalletHdPath,
171+ nonce: inviteNonce + i,
173+ gasPrice: suggestedGasPrice.toFixed(),
174+ gasLimit: txs[i].gas,
163 raw: hexify(stx.serialize()),
177 raw: hexify(stx.serialize()),
164 signed: stx,
178 signed: stx,
182+ inviteNonce = inviteNonce + txs.length;
169 // ensuring funding for transactions
185 // ensuring funding for transactions
@@ -175,6 +191,7 @@ export async function reticketPointBetweenWallets({
177 fromWallet.address,
193 fromWallet.address,
178 totalCost,
195 totalCost,
179 txPairs.map(p => p.raw),
196 txPairs.map(p => p.raw),
180 askForFunding,
197 askForFunding,
@@ -187,7 +204,7 @@ export async function reticketPointBetweenWallets({
188 progress(TRANSACTION_PROGRESS.TRANSFERRING);
205 progress(TRANSACTION_PROGRESS.TRANSFERRING);
190− await sendAndAwaitAll(web3, txPairs.map(p => p.signed), usedTank);
207+ await sendAndAwaitAllSerial(web3, txPairs.map(p => p.signed), usedTank);
193 // move leftover eth
210 // move leftover eth
@@ -201,17 +218,24 @@ export async function reticketPointBetweenWallets({
201 const sendEthCost = gasPriceBN.mul(toBN(gasLimit));
218 const sendEthCost = gasPriceBN.mul(toBN(gasLimit));
202 if (transferEth && balance.gt(sendEthCost)) {
219 if (transferEth && balance.gt(sendEthCost)) {
203 const value = balance.sub(sendEthCost);
220 const value = balance.sub(sendEthCost);
204− const tx = {
221+ const txn = {
205 to: toWallet.ownership.keys.address,
222 to: toWallet.ownership.keys.address,
206 value: value,
223 value: value,
225+ const stx = signTransaction({
227+ walletType: fromWalletType,
228+ walletHdPath: fromWalletHdPath,
207 gasPrice: gasPriceBN,
232 gasPrice: gasPriceBN,
208− gas: gasLimit,
233+ gasLimit,
209 nonce: inviteNonce++,
234 nonce: inviteNonce++,
211− let stx = new Tx(tx);
236+ // let stx = new Tx(tx);
212− stx.sign(fromWallet.privateKey);
237+ // stx.sign(fromWallet.privateKey);
213− const rawTx = hexify(stx.serialize());
238+ sendSignedTransaction(web3, stx).catch(err => {
214− web3.eth.sendSignedTransaction(rawTx).catch(err => {
215 console.log('error sending value tx, who cares', err);
239 console.log('error sending value tx, who cares', err);