Merge pull request #534 from ethereum/updateIndex

Make some remix modules public && add getTransactionReceipt to vmprovider
pull/7/head
yann300 7 years ago committed by GitHub
commit 842cc9834e
  1. 8
      src/index.js
  2. 33
      src/web3Provider/web3VmProvider.js

@ -13,6 +13,8 @@ var decodeInfo = require('./solidity/decodeInfo')
var stateDecoder = require('./solidity/stateDecoder')
var astHelper = require('./solidity/astHelper')
var EventManager = require('./lib/eventManager')
var codeUtil = require('./helpers/util')
var web3VMProvider = require('./web3Provider/web3VmProvider')
if (typeof (module) !== 'undefined' && typeof (module.exports) !== 'undefined') {
module.exports = modules()
@ -40,7 +42,8 @@ function modules () {
},
util: {
SourceMappingDecoder: SourceMappingDecoder,
AstWalker: AstWalker
AstWalker: AstWalker,
code: codeUtil
},
solidity: {
decodeInfo: decodeInfo,
@ -49,6 +52,9 @@ function modules () {
},
lib: {
EventManager: EventManager
},
web3: {
web3VMProvider: web3VMProvider
}
}
}

@ -10,6 +10,7 @@ function web3VmProvider () {
this.vm
this.vmTraces = {}
this.txs = {}
this.txsReceipt = {}
this.processingHash
this.processingAddress
this.processingIndex
@ -19,6 +20,7 @@ function web3VmProvider () {
this.debug = {}
this.eth.getCode = function (address, cb) { return self.getCode(address, cb) }
this.eth.getTransaction = function (hash, cb) { return self.getTransaction(hash, cb) }
this.eth.getTransactionReceipt = function (hash, cb) { return self.getTransactionReceipt(hash, cb) }
this.eth.getTransactionFromBlock = function (blockNumber, txIndex, cb) { return self.getTransactionFromBlock(blockNumber, txIndex, cb) }
this.eth.getBlockNumber = function (cb) { return self.getBlockNumber(cb) }
this.debug.traceTransaction = function (hash, options, cb) { return self.traceTransaction(hash, options, cb) }
@ -72,6 +74,7 @@ web3VmProvider.prototype.txWillProcess = function (self, data) {
tx.value = util.hexConvert(data.value)
}
self.txs[self.processingHash] = tx
self.txsReceipt[self.processingHash] = tx
self.storageCache[self.processingHash] = {}
if (tx.to) {
self.vm.stateManager.dumpStorage(tx.to, function (storage) {
@ -85,8 +88,22 @@ web3VmProvider.prototype.txProcessed = function (self, data) {
var lastOp = self.vmTraces[self.processingHash].structLogs[self.processingIndex - 1]
lastOp.error = lastOp.op !== 'RETURN' && lastOp.op !== 'STOP'
self.vmTraces[self.processingHash].gas = '0x' + data.gasUsed.toString(16)
var logs = []
for (var l in data.vm.logs) {
var log = data.vm.logs[l]
logs.push({
data: log[2].toString('hex'),
topics: [log[1][0].toString('hex')],
rawVMResponse: log
})
}
self.txsReceipt[self.processingHash].logs = logs
if (data.createdAddress) {
self.vmTraces[self.processingHash].return = util.hexConvert(data.createdAddress)
var address = util.hexConvert(data.createdAddress)
self.vmTraces[self.processingHash].return = address
self.txsReceipt[self.processingHash].contractAddress = address
} else {
self.vmTraces[self.processingHash].return = util.hexConvert(data.vm.return)
}
@ -192,6 +209,20 @@ web3VmProvider.prototype.getTransaction = function (txHash, cb) {
}
}
web3VmProvider.prototype.getTransactionReceipt = function (txHash, cb) {
// same as getTransaction but return the created address also
if (this.txsReceipt[txHash]) {
if (cb) {
cb(null, this.txsReceipt[txHash])
}
return this.txsReceipt[txHash]
} else {
if (cb) {
cb('unable to retrieve txReceipt ' + txHash, null)
}
}
}
web3VmProvider.prototype.getTransactionFromBlock = function (blockNumber, txIndex, cb) {
var mes = 'not supposed to be needed by remix in vmmode'
console.log(mes)

Loading…
Cancel
Save