make sure nonce, transactionIndex and logs are returned

pull/5370/head
yann300 3 years ago
parent abe564ac7f
commit 0b7dae14d9
  1. 23
      libs/remix-lib/src/execution/logsManager.ts
  2. 31
      libs/remix-simulator/src/methods/transactions.ts
  3. 11
      libs/remix-simulator/src/vm-context.ts

@ -55,10 +55,11 @@ export class LogsManager {
if (queryFilter.topics.filter((logTopic) => changeEvent.log.topics.indexOf(logTopic) >= 0).length === 0) return false if (queryFilter.topics.filter((logTopic) => changeEvent.log.topics.indexOf(logTopic) >= 0).length === 0) return false
if (queryType === 'logs') { 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) { if (!queryFilter.toBlock) {
return true return true
} else if (parseInt(queryFilter.toBlock) > parseInt(changeEvent.blockNumber)) { } else if (parseInt(queryFilter.toBlock) >= parseInt(changeEvent.blockNumber)) {
return true 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) { getLogsFor (params) {
const results = [] const results = []
for (const log of this.oldLogs) { for (const log of this.oldLogs) {

@ -71,7 +71,7 @@ export class Transactions {
if (!error && result) { if (!error && result) {
this.vmContext.addBlock(result.block) this.vmContext.addBlock(result.block)
const hash = '0x' + result.tx.hash().toString('hex') 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.vmContext.trackExecResult(hash, result.result.execResult)
return cb(null, result.transactionHash) return cb(null, result.transactionHash)
} }
@ -95,17 +95,19 @@ export class Transactions {
return cb(error) 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 <string, unknown> = { const r: Record <string, unknown> = {
transactionHash: receipt.hash, transactionHash: receipt.hash,
transactionIndex: '0x00', transactionIndex: '0x0',
blockHash: '0x' + txBlock.hash().toString('hex'), blockHash: '0x' + txBlock.hash().toString('hex'),
blockNumber: '0x' + txBlock.header.number.toString('hex'), blockNumber: '0x' + txBlock.header.number.toString('hex'),
gasUsed: receipt.gasUsed, gasUsed: receipt.gasUsed,
cumulativeGasUsed: receipt.gasUsed, // only 1 tx per block cumulativeGasUsed: receipt.gasUsed, // only 1 tx per block
contractAddress: receipt.contractAddress, contractAddress: receipt.contractAddress,
logs: receipt.logs, logs,
status: receipt.status, status: receipt.status,
to: receipt.to to: receipt.to
} }
@ -151,7 +153,7 @@ export class Transactions {
if (!error && result) { if (!error && result) {
this.vmContext.addBlock(result.block) this.vmContext.addBlock(result.block)
const hash = '0x' + result.tx.hash().toString('hex') 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.vmContext.trackExecResult(hash, result.result.execResult)
this.tags[tag] = result.transactionHash 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. // 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) 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 // TODO: params to add later
const r: Record<string, unknown> = { const r: Record<string, unknown> = {
@ -198,9 +201,9 @@ export class Transactions {
gasPrice: '0x4a817c800', // 20000000000 gasPrice: '0x4a817c800', // 20000000000
hash: receipt.transactionHash, hash: receipt.transactionHash,
input: receipt.input, input: receipt.input,
nonce: 2, // 0x15 // the nonce should be updated nonce: '0x' + tx.nonce.toString('hex'),
// "transactionIndex": 0, transactionIndex: '0x0',
value: receipt.value value: receipt.value,
// "value":"0xf3dbb76162000" // 4290000000000000 // "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37 // "v": "0x25", // 37
// "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
@ -234,6 +237,8 @@ export class Transactions {
return cb(error) return cb(error)
} }
const tx = this.vmContext.txByHash[receipt.transactionHash]
// TODO: params to add later // TODO: params to add later
const r: Record<string, unknown> = { const r: Record<string, unknown> = {
blockHash: '0x' + txBlock.hash().toString('hex'), blockHash: '0x' + txBlock.hash().toString('hex'),
@ -245,7 +250,7 @@ export class Transactions {
gasPrice: '0x4a817c800', // 20000000000 gasPrice: '0x4a817c800', // 20000000000
hash: receipt.transactionHash, hash: receipt.transactionHash,
input: receipt.input, input: receipt.input,
nonce: 2, // 0x15 // the nonce should be updated nonce: '0x' + tx.nonce.toString('hex'),
// "transactionIndex": 0, // "transactionIndex": 0,
value: receipt.value value: receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000 // "value":"0xf3dbb76162000" // 4290000000000000
@ -277,6 +282,8 @@ export class Transactions {
return cb(error) return cb(error)
} }
const tx = this.vmContext.txByHash[receipt.transactionHash]
// TODO: params to add later // TODO: params to add later
const r: Record<string, unknown> = { const r: Record<string, unknown> = {
blockHash: '0x' + txBlock.hash().toString('hex'), blockHash: '0x' + txBlock.hash().toString('hex'),
@ -288,8 +295,8 @@ export class Transactions {
gasPrice: '0x4a817c800', // 20000000000 gasPrice: '0x4a817c800', // 20000000000
hash: receipt.transactionHash, hash: receipt.transactionHash,
input: receipt.input, input: receipt.input,
nonce: 2, // 0x15 // the nonce should be updated nonce: '0x' + tx.nonce.toString('hex'),
// "transactionIndex": 0, transactionIndex: '0x0',
value: receipt.value value: receipt.value
// "value":"0xf3dbb76162000" // 4290000000000000 // "value":"0xf3dbb76162000" // 4290000000000000
// "v": "0x25", // 37 // "v": "0x25", // 37

@ -85,7 +85,8 @@ export class VMContext {
customNetWorks customNetWorks
blocks blocks
latestBlockNumber latestBlockNumber
txs blockByTxHash
txByHash
currentVm currentVm
web3vm web3vm
logsManager logsManager
@ -98,7 +99,8 @@ export class VMContext {
this.currentVm = this.createVm(this.currentFork) this.currentVm = this.createVm(this.currentFork)
this.blocks = {} this.blocks = {}
this.latestBlockNumber = 0 this.latestBlockNumber = 0
this.txs = {} this.blockByTxHash = {}
this.txByHash = {}
this.exeResults = {} this.exeResults = {}
this.logsManager = new execution.LogsManager() this.logsManager = new execution.LogsManager()
} }
@ -151,8 +153,9 @@ export class VMContext {
this.logsManager.checkBlock(blockNumber, block, this.web3()) this.logsManager.checkBlock(blockNumber, block, this.web3())
} }
trackTx (tx, block) { trackTx (txHash, block, tx) {
this.txs[tx] = block this.blockByTxHash[txHash] = block
this.txByHash[txHash] = tx
} }
trackExecResult (tx, execReult) { trackExecResult (tx, execReult) {

Loading…
Cancel
Save