From db757b5bbbb06030cfaa0fbc2ef1164fbaebb48a Mon Sep 17 00:00:00 2001 From: ricmoo Date: Thu, 4 Aug 2016 03:20:01 -0400 Subject: [PATCH] Fixed wrong default gasLimit bug and clearing provider. --- lib/wallet.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/wallet.js b/lib/wallet.js index 25111f6eb..df26da855 100644 --- a/lib/wallet.js +++ b/lib/wallet.js @@ -32,7 +32,9 @@ function Wallet(privateKey, provider) { enumerable: true, get: function() { return provider; }, set: function(value) { - if (!providers.isProvider(value)) { throw new Error('invalid provider'); } + if (value !== null && !providers.isProvider(value)) { + throw new Error('invalid provider'); + } provider = value; } }); @@ -148,8 +150,8 @@ utils.defineProperty(Wallet.prototype, 'estimateGas', function(transaction) { }); utils.defineProperty(Wallet.prototype, 'sendTransaction', function(transaction) { - var gasLimit = 3000000; - if (transaction.gasLimit != null) { gasLimit = transaction.gasLimit; } + var gasLimit = transaction.gasLimit; + if (gasLimit == null) { gasLimit = 3000000; } var self = this; @@ -170,7 +172,7 @@ utils.defineProperty(Wallet.prototype, 'sendTransaction', function(transaction) if (transaction.nonce) { return resolve(transaction.nonce); } - provider.getTransactionCount(self.address).then(function(transactionCount) { + provider.getTransactionCount(self.address, 'pending').then(function(transactionCount) { resolve(transactionCount); }, function(error) { reject(error); @@ -181,7 +183,7 @@ utils.defineProperty(Wallet.prototype, 'sendTransaction', function(transaction) Promise.all([gasPrice, nonce]).then(function(results) { var signedTransaction = self.sign({ to: transaction.to, - gasLimit: results[1], + gasLimit: gasLimit, gasPrice: results[0], nonce: results[1], value: transaction.value