aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Serrano <kevgagser@gmail.com>2017-03-09 01:35:51 +0800
committerKevin Serrano <kevgagser@gmail.com>2017-03-09 01:35:51 +0800
commit6fd3d6e0d0887ac01760b436be5dfabc89e28960 (patch)
tree42c6db90a39fb691f26ec8443bd18114ee7cff4d
parent21769a008ccc5fdc2ac5d23a37d401a1d2a20694 (diff)
parent86f71d504cc3acd758958f883520fe913903a2c2 (diff)
downloadtangerine-wallet-browser-6fd3d6e0d0887ac01760b436be5dfabc89e28960.tar
tangerine-wallet-browser-6fd3d6e0d0887ac01760b436be5dfabc89e28960.tar.gz
tangerine-wallet-browser-6fd3d6e0d0887ac01760b436be5dfabc89e28960.tar.bz2
tangerine-wallet-browser-6fd3d6e0d0887ac01760b436be5dfabc89e28960.tar.lz
tangerine-wallet-browser-6fd3d6e0d0887ac01760b436be5dfabc89e28960.tar.xz
tangerine-wallet-browser-6fd3d6e0d0887ac01760b436be5dfabc89e28960.tar.zst
tangerine-wallet-browser-6fd3d6e0d0887ac01760b436be5dfabc89e28960.zip
Merge branch 'i1144-moarrpc' of github.com:MetaMask/metamask-plugin into i1144-moarrpc
-rw-r--r--CHANGELOG.md1
-rw-r--r--app/scripts/keyring-controller.js23
-rw-r--r--app/scripts/lib/tx-utils.js13
-rw-r--r--package.json2
-rw-r--r--test/unit/tx-utils-test.js26
5 files changed, 58 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8c601f172..bf03cf41e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@
- Add two most recently used custom RPCs to network dropdown menu.
- Add personal_sign method support.
- Add ability to customize gas and gasPrice on the transaction approval screen.
+- Increase default gas buffer to 1.5x estimated gas value.
## 3.3.0 2017-2-20
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index e1b1c4335..72f613641 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -164,8 +164,11 @@ class KeyringController extends EventEmitter {
return keyring.getAccounts()
})
.then((accounts) => {
+ return this.checkForDuplicate(type, accounts)
+ })
+ .then((checkedAccounts) => {
this.keyrings.push(keyring)
- return this.setupAccounts(accounts)
+ return this.setupAccounts(checkedAccounts)
})
.then(() => this.persistAllKeyrings())
.then(() => this.fullUpdate())
@@ -175,6 +178,24 @@ class KeyringController extends EventEmitter {
})
}
+ // For now just checks for simple key pairs
+ // but in the future
+ // should possibly add HD and other types
+ //
+ checkForDuplicate (type, newAccount) {
+ return this.getAccounts()
+ .then((accounts) => {
+ switch (type) {
+ case 'Simple Key Pair':
+ let isNotIncluded = !accounts.find((key) => key === newAccount[0] || key === ethUtil.stripHexPrefix(newAccount[0]))
+ return (isNotIncluded) ? Promise.resolve(newAccount) : Promise.reject(new Error('The account you\'re are trying to import is a duplicate'))
+ default:
+ return Promise.resolve(newAccount)
+ }
+ })
+ }
+
+
// Add New Account
// @number keyRingNum
//
diff --git a/app/scripts/lib/tx-utils.js b/app/scripts/lib/tx-utils.js
index 19a2d430e..f5051eb8f 100644
--- a/app/scripts/lib/tx-utils.js
+++ b/app/scripts/lib/tx-utils.js
@@ -55,7 +55,7 @@ module.exports = class txProviderUtils {
// try adding an additional gas buffer to our estimation for safety
const estimatedGasBn = new BN(ethUtil.stripHexPrefix(txData.estimatedGas), 16)
const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
- const estimationWithBuffer = new BN(this.addGasBuffer(estimatedGasBn), 16)
+ const estimationWithBuffer = new BN(this.addGasBuffer(estimatedGasBn, blockGasLimitHex), 16)
// added gas buffer is too high
if (estimationWithBuffer.gt(blockGasLimitBn)) {
txParams.gas = txData.estimatedGas
@@ -68,11 +68,14 @@ module.exports = class txProviderUtils {
return
}
- addGasBuffer (gas) {
- const gasBuffer = new BN('100000', 10)
+ addGasBuffer (gas, blockGasLimitHex) {
+ const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
- const correct = bnGas.add(gasBuffer)
- return ethUtil.addHexPrefix(correct.toString(16))
+ const bufferedGas = bnGas.muln(1.5)
+
+ if (bnGas.gt(blockGasLimitBn)) return gas
+ if (bufferedGas.lt(blockGasLimitBn)) return ethUtil.addHexPrefix(bufferedGas.toString(16))
+ return ethUtil.addHexPrefix(blockGasLimitBn.toString(16))
}
fillInTxParams (txParams, cb) {
diff --git a/package.json b/package.json
index 839f7bcd2..475cdb2b3 100644
--- a/package.json
+++ b/package.json
@@ -109,7 +109,7 @@
"valid-url": "^1.0.9",
"vreme": "^3.0.2",
"web3": "0.18.2",
- "web3-provider-engine": "^10.0.0",
+ "web3-provider-engine": "^10.0.1",
"web3-stream-provider": "^2.0.6",
"xtend": "^4.0.1"
},
diff --git a/test/unit/tx-utils-test.js b/test/unit/tx-utils-test.js
new file mode 100644
index 000000000..65233e1d9
--- /dev/null
+++ b/test/unit/tx-utils-test.js
@@ -0,0 +1,26 @@
+const assert = require('assert')
+const ethUtil = require('ethereumjs-util')
+const BN = ethUtil.BN
+
+const TxUtils = require('../../app/scripts/lib/tx-utils')
+
+
+describe('txUtils', function() {
+ let txUtils
+
+ before(function() {
+ txUtils = new TxUtils()
+ })
+
+ describe('addGasBuffer', function() {
+ it('multiplies by 1.5', function() {
+ const input = '0x123fad'
+ const output = txUtils.addGasBuffer(input, '0x3d4c52') //0x3d4c52 is 4mil for dummy gas limit
+
+ const inputBn = new BN(ethUtil.stripHexPrefix(input), 'hex')
+ const outputBn = new BN(ethUtil.stripHexPrefix(output), 'hex')
+ const expectedBn = inputBn.muln(1.5)
+ assert(outputBn.eq(expectedBn), 'returns 1.5 the input value')
+ })
+ })
+})