-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reorganize files * Simplify ExecutionResult * Make ExecutionResult a discriminated union * Reduce Memory to a single class * Make parseBytecode easier to read
- Loading branch information
Showing
116 changed files
with
329 additions
and
694 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { State } from './State' | ||
import { Byte } from './Byte' | ||
import { VMError } from './errors' | ||
|
||
export type ExecutionResult = | ||
| ExecutionSuccess | ||
| ExecutionRevert | ||
| ExecutionError | ||
|
||
export interface ExecutionSuccess { | ||
type: 'ExecutionSuccess', | ||
state: State, | ||
gasUsed: number, | ||
gasRefund: number, | ||
returnValue: Byte[], | ||
} | ||
|
||
export interface ExecutionRevert { | ||
type: 'ExecutionRevert', | ||
gasUsed: number, | ||
returnValue: Byte[], | ||
} | ||
|
||
export interface ExecutionError { | ||
type: 'ExecutionError', | ||
error: VMError, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Address } from './Address' | ||
import { Bytes32 } from './Bytes32' | ||
import { Byte } from './Byte' | ||
|
||
export interface Message { | ||
readonly account: Address, | ||
readonly code: readonly Byte[], | ||
readonly data: readonly Byte[], | ||
readonly origin: Address, | ||
readonly sender: Address, | ||
readonly gasLimit: number, | ||
readonly gasPrice: Bytes32, | ||
readonly value: Bytes32, | ||
readonly enableStateModifications: boolean, | ||
readonly callDepth: number, | ||
} |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ExecutionContext } from './ExecutionContext' | ||
import { Message } from './Message' | ||
import { opSTOP } from './opcodes/control' | ||
import { VMError } from './errors' | ||
import { ExecutionResult } from './ExecutionResult' | ||
import { State } from './State' | ||
|
||
export function executeCode (message: Message, state: State): ExecutionResult { | ||
const ctx = new ExecutionContext(message, state) | ||
|
||
while (ctx.returnValue === undefined) { | ||
const opcode = ctx.code[ctx.programCounter] || opSTOP | ||
ctx.programCounter++ | ||
try { | ||
opcode(ctx) | ||
} catch (error) { | ||
if (error instanceof VMError) { | ||
return { | ||
type: 'ExecutionError', | ||
error, | ||
} | ||
} else { | ||
// programmer error | ||
throw error | ||
} | ||
} | ||
} | ||
|
||
if (ctx.reverted) { | ||
return { | ||
type: 'ExecutionRevert', | ||
gasUsed: ctx.gasUsed, | ||
returnValue: ctx.returnValue, | ||
} | ||
} else { | ||
return { | ||
type: 'ExecutionSuccess', | ||
gasUsed: ctx.gasUsed, | ||
gasRefund: ctx.gasRefund, | ||
returnValue: ctx.returnValue, | ||
state: ctx.state, | ||
} | ||
} | ||
} |
Oops, something went wrong.