mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
idStore - add DELEGATE_CALL detection
This commit is contained in:
parent
08a153e203
commit
c1e9444200
@ -247,15 +247,15 @@ function updateBadge(state){
|
|||||||
// Add unconfirmed Tx + Msg
|
// Add unconfirmed Tx + Msg
|
||||||
//
|
//
|
||||||
|
|
||||||
function newUnsignedTransaction(txParams, cb){
|
function newUnsignedTransaction(txParams, onTxDoneCb){
|
||||||
var state = idStore.getState()
|
var state = idStore.getState()
|
||||||
if (!state.isUnlocked) {
|
if (!state.isUnlocked) {
|
||||||
createUnlockRequestNotification({
|
createUnlockRequestNotification({
|
||||||
title: 'Account Unlock Request',
|
title: 'Account Unlock Request',
|
||||||
})
|
})
|
||||||
var txId = idStore.addUnconfirmedTransaction(txParams, cb)
|
idStore.addUnconfirmedTransaction(txParams, onTxDoneCb, noop)
|
||||||
} else {
|
} else {
|
||||||
addUnconfirmedTx(txParams, cb)
|
addUnconfirmedTx(txParams, onTxDoneCb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,13 +271,15 @@ function newUnsignedMessage(msgParams, cb){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addUnconfirmedTx(txParams, cb){
|
function addUnconfirmedTx(txParams, onTxDoneCb){
|
||||||
var txId = idStore.addUnconfirmedTransaction(txParams, cb)
|
idStore.addUnconfirmedTransaction(txParams, onTxDoneCb, function(err, txData){
|
||||||
createTxNotification({
|
if (err) return onTxDoneCb(err)
|
||||||
title: 'New Unsigned Transaction',
|
createTxNotification({
|
||||||
txParams: txParams,
|
title: 'New Unsigned Transaction',
|
||||||
confirm: idStore.approveTransaction.bind(idStore, txId, noop),
|
txParams: txParams,
|
||||||
cancel: idStore.cancelTransaction.bind(idStore, txId),
|
confirm: idStore.approveTransaction.bind(idStore, txData.id, noop),
|
||||||
|
cancel: idStore.cancelTransaction.bind(idStore, txData.id),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
const EventEmitter = require('events').EventEmitter
|
const EventEmitter = require('events').EventEmitter
|
||||||
const inherits = require('util').inherits
|
const inherits = require('util').inherits
|
||||||
const Transaction = require('ethereumjs-tx')
|
const Transaction = require('ethereumjs-tx')
|
||||||
|
const ethUtil = require('ethereumjs-util')
|
||||||
const LightwalletKeyStore = require('eth-lightwallet').keystore
|
const LightwalletKeyStore = require('eth-lightwallet').keystore
|
||||||
const LightwalletSigner = require('eth-lightwallet').signing
|
const LightwalletSigner = require('eth-lightwallet').signing
|
||||||
const async = require('async')
|
const async = require('async')
|
||||||
const clone = require('clone')
|
const clone = require('clone')
|
||||||
const extend = require('xtend')
|
const extend = require('xtend')
|
||||||
const createId = require('web3-provider-engine/util/random-id')
|
const createId = require('web3-provider-engine/util/random-id')
|
||||||
|
const ethBinToOps = require('eth-bin-to-ops')
|
||||||
const autoFaucet = require('./auto-faucet')
|
const autoFaucet = require('./auto-faucet')
|
||||||
const configManager = require('./config-manager-singleton')
|
const configManager = require('./config-manager-singleton')
|
||||||
const messageManager = require('./message-manager')
|
const messageManager = require('./message-manager')
|
||||||
@ -181,13 +183,13 @@ IdentityStore.prototype.exportAccount = function(address, cb) {
|
|||||||
//
|
//
|
||||||
|
|
||||||
// comes from dapp via zero-client hooked-wallet provider
|
// comes from dapp via zero-client hooked-wallet provider
|
||||||
IdentityStore.prototype.addUnconfirmedTransaction = function(txParams, cb){
|
IdentityStore.prototype.addUnconfirmedTransaction = function(txParams, onTxDoneCb, cb){
|
||||||
|
var self = this
|
||||||
// create txData obj with parameters and meta data
|
// create txData obj with parameters and meta data
|
||||||
var time = (new Date()).getTime()
|
var time = (new Date()).getTime()
|
||||||
var txId = createId()
|
var txId = createId()
|
||||||
txParams.metamaskId = txId
|
txParams.metamaskId = txId
|
||||||
txParams.metamaskNetworkId = this._currentState.network
|
txParams.metamaskNetworkId = self._currentState.network
|
||||||
var txData = {
|
var txData = {
|
||||||
id: txId,
|
id: txId,
|
||||||
txParams: txParams,
|
txParams: txParams,
|
||||||
@ -197,14 +199,38 @@ IdentityStore.prototype.addUnconfirmedTransaction = function(txParams, cb){
|
|||||||
configManager.addTx(txData)
|
configManager.addTx(txData)
|
||||||
console.log('addUnconfirmedTransaction:', txData)
|
console.log('addUnconfirmedTransaction:', txData)
|
||||||
|
|
||||||
// keep the cb around for after approval (requires user interaction)
|
// keep the onTxDoneCb around for after approval/denial (requires user interaction)
|
||||||
// This cb fires completion to the Dapp's write operation.
|
// This onTxDoneCb fires completion to the Dapp's write operation.
|
||||||
this._unconfTxCbs[txId] = cb
|
self._unconfTxCbs[txId] = onTxDoneCb
|
||||||
|
|
||||||
// signal update
|
// perform static analyis on the target contract code
|
||||||
this._didUpdate()
|
var provider = self._ethStore._query.currentProvider
|
||||||
|
if (txParams.to) {
|
||||||
|
provider.sendAsync({ id: 1, method: 'eth_getCode', params: [txParams.to, 'latest'] }, function(err, res){
|
||||||
|
if (err) return didComplete(err)
|
||||||
|
if (res.error) return didComplete(res.error)
|
||||||
|
var code = ethUtil.toBuffer(res.result)
|
||||||
|
if (code !== '0x') {
|
||||||
|
var ops = ethBinToOps(code)
|
||||||
|
var containsDelegateCall = ops.some((op)=>op.name === 'DELEGATECALL')
|
||||||
|
txData.containsDelegateCall = containsDelegateCall
|
||||||
|
didComplete()
|
||||||
|
} else {
|
||||||
|
didComplete()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
didComplete()
|
||||||
|
}
|
||||||
|
|
||||||
|
function didComplete(err){
|
||||||
|
if (err) return cb(err)
|
||||||
|
// signal update
|
||||||
|
self._didUpdate()
|
||||||
|
// signal completion of add tx
|
||||||
|
cb(null, txData)
|
||||||
|
}
|
||||||
|
|
||||||
return txId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// comes from metamask ui
|
// comes from metamask ui
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
"debounce": "^1.0.0",
|
"debounce": "^1.0.0",
|
||||||
"dnode": "^1.2.2",
|
"dnode": "^1.2.2",
|
||||||
"end-of-stream": "^1.1.0",
|
"end-of-stream": "^1.1.0",
|
||||||
|
"eth-bin-to-ops": "^1.0.0",
|
||||||
"eth-lightwallet": "^2.3.3",
|
"eth-lightwallet": "^2.3.3",
|
||||||
"eth-store": "^1.1.0",
|
"eth-store": "^1.1.0",
|
||||||
"ethereumjs-tx": "^1.0.0",
|
"ethereumjs-tx": "^1.0.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user