"use strict";

var assign = require("lodash").assign;
var eth_getTransactionCount = require("../wrappers/eth").getTransactionCount;
var verifyRawTransactionNonce = require("./verify-raw-transaction-nonce");
var RPCError = require("../errors/rpc-error");


/**
 * Use the number of transactions from this account to set the nonce.
 * @param {Object} packaged Packaged transaction.
 * @param {string} address The sender's Ethereum address.
 * @param {function} callback Callback function.
 * @return {Object} Packaged transaction with nonce set.
 */
function setRawTransactionNonce(packaged, address, callback) {
  return function (dispatch, getState) {
    dispatch(eth_getTransactionCount([address, "pending"], function (err, transactionCount) {
      if (getState().debug.tx) console.log("transaction count:", address, transactionCount, parseInt(transactionCount, transactionCount.toString().startsWith("0x") ? 16 : 10));
      if (err) return callback(err);
      if (transactionCount == null) return callback(new RPCError("NO_RESPONSE"));
      callback(null, assign({}, packaged, { nonce: dispatch(verifyRawTransactionNonce(parseInt(transactionCount, transactionCount.toString().startsWith("0x") ? 16 : 10))) }));
    }));
  };
}

module.exports = setRawTransactionNonce;

@@ -833,95 +833,11 @@
 ount
-, parseInt(transactionCount, transactionCount.toString().startsWith(%220x%22) ? 16 : 10)
 );%0A
+
     
@@ -947,24 +947,134 @@
 ESPONSE%22));%0A
+      var txCount = typeof transactionCount === %22number%22 ? transactionCount : parseInt(transactionCount, 16);%0A
       callba
@@ -1151,90 +1151,15 @@
 nce(
-parseInt(transactionCount, transactionCount.toString().startsWith(%220x%22) ? 16 : 10)
+txCount
 )) %7D

make what is going on more clear based on code review