Skip to content

Commit f76bad5

Browse files
rmeissnerholgerd77
authored andcommitted
Refactoring
1 parent 586064a commit f76bad5

File tree

2 files changed

+47
-41
lines changed

2 files changed

+47
-41
lines changed

lib/opFns.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,8 @@ module.exports = {
536536
outLength: new BN(0)
537537
}
538538

539-
// Deduct gas costs for hashing
540-
// TODO this is not yet part of the tests
541-
// subGas(runState, new BN(runState._common.param('gasPrices', 'sha3Word')).imul(length.divCeil(new BN(32))))
539+
// Deduct gas costs for hashingq
540+
subGas(runState, new BN(runState._common.param('gasPrices', 'sha3Word')).imul(length.divCeil(new BN(32))))
542541
checkCallMemCost(runState, options, localOpts)
543542
checkOutOfGas(runState, options)
544543
makeCall(runState, options, localOpts, done)

lib/runCall.js

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -78,50 +78,57 @@ module.exports = function (opts, cb) {
7878
createdAddress = toAddress = ethUtil.generateAddress(caller, newNonce.toArray())
7979
}
8080

81-
stateManager.getAccount(createdAddress, function (err, account) {
82-
if (err) {
83-
done(err)
84-
return
85-
}
81+
checkAccountState(createdAddress, setupNewContract, done)
82+
} else {
83+
// else load the `to` account
84+
toAccount = stateManager.cache.get(toAddress)
85+
done()
86+
}
87+
}
8688

87-
if ((account.nonce && new BN(account.nonce) > 0) || account.codeHash.compare(EMPTY_CODE_HASH) !== 0) {
88-
done(ERROR.INVALID_OPCODE)
89-
return
90-
}
89+
function checkAccountState(address, next, done) {
90+
stateManager.getAccount(address, function (err, account) {
91+
if (err) {
92+
done(err)
93+
return
94+
}
9195

92-
stateManager.clearContractStorage(createdAddress, function (err) {
93-
if (err) {
94-
done(err)
95-
return
96-
}
96+
if ((account.nonce && new BN(account.nonce) > 0) || account.codeHash.compare(EMPTY_CODE_HASH) !== 0) {
97+
done(ERROR.INVALID_OPCODE)
98+
return
99+
}
100+
101+
next(address, done)
102+
})
103+
}
97104

98-
async.series([
99-
newContractEvent,
100-
getAccount
101-
], done)
105+
function setupNewContract(address, done) {
106+
stateManager.clearContractStorage(address, function (err) {
107+
if (err) {
108+
done(err)
109+
return
110+
}
102111

103-
function newContractEvent (callback) {
104-
self.emit('newContract', {
105-
address: createdAddress,
106-
code: code
107-
}, callback)
108-
}
112+
async.series([
113+
newContractEvent,
114+
getAccount
115+
], done)
109116

110-
function getAccount (callback) {
111-
stateManager.getAccount(createdAddress, function (err, account) {
112-
toAccount = account
113-
const NONCE_OFFSET = 1
114-
toAccount.nonce = new BN(toAccount.nonce).addn(NONCE_OFFSET).toArrayLike(Buffer)
115-
callback(err)
116-
})
117-
}
117+
function newContractEvent (callback) {
118+
self.emit('newContract', {
119+
address: address,
120+
code: code
121+
}, callback)
122+
}
123+
124+
function getAccount (callback) {
125+
stateManager.getAccount(address, function (err, account) {
126+
toAccount = account
127+
toAccount.nonce = new BN(toAccount.nonce).addn(1).toArrayLike(Buffer)
128+
callback(err)
118129
})
119-
})
120-
} else {
121-
// else load the `to` account
122-
toAccount = stateManager.cache.get(toAddress)
123-
done()
124-
}
130+
}
131+
})
125132
}
126133

127134
function subTxValue (cb) {

0 commit comments

Comments
 (0)