Skip to content

Commit 4cb7fae

Browse files
authored
VM: Add type definitions for logs (#1084)
* Add type definition for Log
1 parent 05366ae commit 4cb7fae

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

packages/vm/lib/evm/eei.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { StateManager } from '../state/index'
66
import { VmError, ERROR } from '../exceptions'
77
import Message from './message'
88
import EVM, { EVMResult } from './evm'
9+
import { Log } from './types'
910

1011
function trap(err: ERROR) {
1112
throw new VmError(err)
@@ -41,7 +42,7 @@ export interface Env {
4142
* Immediate (unprocessed) result of running an EVM bytecode.
4243
*/
4344
export interface RunResult {
44-
logs: any // TODO: define type for Log (each log: [Buffer(address), [Buffer(topic0), ...]])
45+
logs: Log[]
4546
returnValue?: Buffer
4647
/**
4748
* A map from the accounts that have self-destructed to the addresses to send their funds to
@@ -392,12 +393,7 @@ export default class EEI {
392393
trap(ERROR.INTERNAL_ERROR)
393394
}
394395

395-
// add address
396-
const log: any = [this._env.address.buf]
397-
log.push(topics)
398-
399-
// add data
400-
log.push(data)
396+
const log: Log = [this._env.address.buf, topics, data]
401397
this._result.logs.push(log)
402398
}
403399

packages/vm/lib/evm/evm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import TxContext from './txContext'
1616
import Message from './message'
1717
import EEI from './eei'
1818
import { short } from './opcodes/util'
19+
import { Log } from './types'
1920
import { default as Interpreter, InterpreterOpts, RunState } from './interpreter'
2021

2122
const debug = createDebugLogger('vm:evm')
@@ -63,7 +64,7 @@ export interface ExecResult {
6364
/**
6465
* Array of logs that the contract emitted
6566
*/
66-
logs?: any[]
67+
logs?: Log[]
6768
/**
6869
* A map from the accounts that have self-destructed to the addresses to send their funds to
6970
*/

packages/vm/lib/evm/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Log that the contract emitted.
3+
* Format: [address, topics, data]
4+
*/
5+
export type Log = [Buffer, Buffer[], Buffer]

packages/vm/lib/runBlock.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { RunTxResult } from './runTx'
88
import { StateManager } from './state'
99

1010
import * as DAOConfig from './config/dao_fork_accounts_config.json'
11+
import { Log } from './evm/types'
1112

1213
/* DAO account list */
1314

@@ -79,7 +80,7 @@ interface TxReceipt {
7980
/**
8081
* Logs emitted
8182
*/
82-
logs: any[]
83+
logs: Log[]
8384
}
8485

8586
/**

0 commit comments

Comments
 (0)