diff --git a/libs/remix-lib/src/execution/logsManager.ts b/libs/remix-lib/src/execution/logsManager.ts index 86f07bf099..6420d53028 100644 --- a/libs/remix-lib/src/execution/logsManager.ts +++ b/libs/remix-lib/src/execution/logsManager.ts @@ -55,10 +55,11 @@ export class LogsManager { if (queryFilter.topics.filter((logTopic) => changeEvent.log.topics.indexOf(logTopic) >= 0).length === 0) return false if (queryType === 'logs') { - if ((queryFilter.address === ('0x' + changeEvent.tx.to.toString('hex'))) && (queryFilter.address === ('0x' + changeEvent.tx.from.toString('hex')))) { + + if ((queryFilter.address === (changeEvent.tx.to || '').toString()) || queryFilter.address === (changeEvent.tx.getSenderAddress().toString())) { if (!queryFilter.toBlock) { return true - } else if (parseInt(queryFilter.toBlock) > parseInt(changeEvent.blockNumber)) { + } else if (parseInt(queryFilter.toBlock) >= parseInt(changeEvent.blockNumber)) { return true } } @@ -144,6 +145,24 @@ export class LogsManager { } } + getLogsByTxHash (hash) { + return this.oldLogs.filter((log) => '0x' + log.tx.hash().toString('hex') === hash) + .map((log) => { + return { + logIndex: '0x1', // 1 + blockNumber: log.blockNumber, + blockHash: ('0x' + log.block.hash().toString('hex')), + transactionHash: ('0x' + log.tx.hash().toString('hex')), + transactionIndex: '0x' + log.txNumber.toString(16), + // TODO: if it's a contract deploy, it should be that address instead + address: log.log.address, + data: log.log.data, + topics: log.log.topics + } + }) + + } + getLogsFor (params) { const results = [] for (const log of this.oldLogs) { diff --git a/libs/remix-simulator/src/methods/transactions.ts b/libs/remix-simulator/src/methods/transactions.ts index 44786c6f62..b0e3e4e3e7 100644 --- a/libs/remix-simulator/src/methods/transactions.ts +++ b/libs/remix-simulator/src/methods/transactions.ts @@ -71,7 +71,7 @@ export class Transactions { if (!error && result) { this.vmContext.addBlock(result.block) const hash = '0x' + result.tx.hash().toString('hex') - this.vmContext.trackTx(hash, result.block) + this.vmContext.trackTx(hash, result.block, result.tx) this.vmContext.trackExecResult(hash, result.result.execResult) return cb(null, result.transactionHash) } @@ -95,17 +95,19 @@ export class Transactions { return cb(error) } - const txBlock = this.vmContext.txs[receipt.hash] + const txBlock = this.vmContext.blockByTxHash[receipt.hash] + + const logs = this.vmContext.logsManager.getLogsByTxHash(receipt.hash) const r: Record = { transactionHash: receipt.hash, - transactionIndex: '0x00', + transactionIndex: '0x0', blockHash: '0x' + txBlock.hash().toString('hex'), blockNumber: '0x' + txBlock.header.number.toString('hex'), gasUsed: receipt.gasUsed, cumulativeGasUsed: receipt.gasUsed, // only 1 tx per block contractAddress: receipt.contractAddress, - logs: receipt.logs, + logs, status: receipt.status, to: receipt.to } @@ -151,7 +153,7 @@ export class Transactions { if (!error && result) { this.vmContext.addBlock(result.block) const hash = '0x' + result.tx.hash().toString('hex') - this.vmContext.trackTx(hash, result.block) + this.vmContext.trackTx(hash, result.block, result.tx) this.vmContext.trackExecResult(hash, result.result.execResult) this.tags[tag] = result.transactionHash // calls are not supposed to return a transaction hash. we do this for keeping track of it and allowing debugging calls. @@ -185,7 +187,8 @@ export class Transactions { return cb(error) } - const txBlock = this.vmContext.txs[receipt.transactionHash] + const txBlock = this.vmContext.blockByTxHash[receipt.transactionHash] + const tx = this.vmContext.txByHash[receipt.transactionHash] // TODO: params to add later const r: Record = { @@ -198,9 +201,9 @@ export class Transactions { gasPrice: '0x4a817c800', // 20000000000 hash: receipt.transactionHash, input: receipt.input, - nonce: 2, // 0x15 // the nonce should be updated - // "transactionIndex": 0, - value: receipt.value + nonce: '0x' + tx.nonce.toString('hex'), + transactionIndex: '0x0', + value: receipt.value, // "value":"0xf3dbb76162000" // 4290000000000000 // "v": "0x25", // 37 // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", @@ -234,6 +237,8 @@ export class Transactions { return cb(error) } + const tx = this.vmContext.txByHash[receipt.transactionHash] + // TODO: params to add later const r: Record = { blockHash: '0x' + txBlock.hash().toString('hex'), @@ -245,7 +250,7 @@ export class Transactions { gasPrice: '0x4a817c800', // 20000000000 hash: receipt.transactionHash, input: receipt.input, - nonce: 2, // 0x15 // the nonce should be updated + nonce: '0x' + tx.nonce.toString('hex'), // "transactionIndex": 0, value: receipt.value // "value":"0xf3dbb76162000" // 4290000000000000 @@ -277,6 +282,8 @@ export class Transactions { return cb(error) } + const tx = this.vmContext.txByHash[receipt.transactionHash] + // TODO: params to add later const r: Record = { blockHash: '0x' + txBlock.hash().toString('hex'), @@ -288,8 +295,8 @@ export class Transactions { gasPrice: '0x4a817c800', // 20000000000 hash: receipt.transactionHash, input: receipt.input, - nonce: 2, // 0x15 // the nonce should be updated - // "transactionIndex": 0, + nonce: '0x' + tx.nonce.toString('hex'), + transactionIndex: '0x0', value: receipt.value // "value":"0xf3dbb76162000" // 4290000000000000 // "v": "0x25", // 37 diff --git a/libs/remix-simulator/src/vm-context.ts b/libs/remix-simulator/src/vm-context.ts index a562331f9c..e862fd0e3f 100644 --- a/libs/remix-simulator/src/vm-context.ts +++ b/libs/remix-simulator/src/vm-context.ts @@ -85,7 +85,8 @@ export class VMContext { customNetWorks blocks latestBlockNumber - txs + blockByTxHash + txByHash currentVm web3vm logsManager @@ -98,7 +99,8 @@ export class VMContext { this.currentVm = this.createVm(this.currentFork) this.blocks = {} this.latestBlockNumber = 0 - this.txs = {} + this.blockByTxHash = {} + this.txByHash = {} this.exeResults = {} this.logsManager = new execution.LogsManager() } @@ -151,8 +153,9 @@ export class VMContext { this.logsManager.checkBlock(blockNumber, block, this.web3()) } - trackTx (tx, block) { - this.txs[tx] = block + trackTx (txHash, block, tx) { + this.blockByTxHash[txHash] = block + this.txByHash[txHash] = tx } trackExecResult (tx, execReult) {