Merge branch 'i1144-moarrpc' of github.com:MetaMask/metamask-plugin into i1144-moarrpc

feature/default_network_editable
Kevin Serrano 8 years ago
commit 6fd3d6e0d0
No known key found for this signature in database
GPG Key ID: 7CC862A58D2889B4
  1. 1
      CHANGELOG.md
  2. 23
      app/scripts/keyring-controller.js
  3. 13
      app/scripts/lib/tx-utils.js
  4. 2
      package.json
  5. 26
      test/unit/tx-utils-test.js

@ -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

@ -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
//

@ -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) {

@ -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"
},

@ -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')
})
})
})
Loading…
Cancel
Save