Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate promises into StateManager #719

Merged
merged 5 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/vm-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
steps:
- uses: actions/setup-node@v1
with:
node-version: 8.x
node-version: 12.x
- uses: actions/checkout@v1
- name: Cache node modules
ryanio marked this conversation as resolved.
Show resolved Hide resolved
id: cache-node-modules
uses: actions/cache@v1
with:
path: node_modules
key: "${{ runner.os }}-node8-${{ hashFiles('**/package.json') }}"
key: "${{ runner.os }}-node12-${{ hashFiles('**/package.json') }}"
- run: npm install
if: steps.cache-node-modules.outputs.cache-hit != 'true'
working-directory: '${{ env.cwd }}'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/vm-nightly-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
steps:
- uses: actions/setup-node@v1
with:
node-version: 8.x
node-version: 12.x
- uses: actions/checkout@v1
- run: npm install
working-directory: '${{ env.cwd }}'
Expand All @@ -27,7 +27,7 @@ jobs:
steps:
- uses: actions/setup-node@v1
with:
node-version: 8.x
node-version: 12.x
- uses: actions/checkout@v1
- run: npm install
working-directory: '${{ env.cwd }}'
Expand All @@ -42,7 +42,7 @@ jobs:
steps:
- uses: actions/setup-node@v1
with:
node-version: 8.x
node-version: 12.x
- uses: actions/checkout@v1
- run: npm install
working-directory: '${{ env.cwd }}'
Expand All @@ -57,7 +57,7 @@ jobs:
steps:
- uses: actions/setup-node@v1
with:
node-version: 8.x
node-version: 12.x
- uses: actions/checkout@v1
- run: npm install
working-directory: '${{ env.cwd }}'
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/vm-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ jobs:
steps:
- uses: actions/setup-node@v1
with:
node-version: 8.x
node-version: 12.x
- uses: actions/checkout@v1
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v1
with:
path: node_modules
key: "${{ runner.os }}-node8-${{ hashFiles('**/package.json') }}"
key: "${{ runner.os }}-node12-${{ hashFiles('**/package.json') }}"
- run: npm install
if: steps.cache-node-modules.outputs.cache-hit != 'true'
working-directory: '${{ env.cwd }}'
Expand All @@ -51,14 +51,14 @@ jobs:
steps:
- uses: actions/setup-node@v1
with:
node-version: 8.x
node-version: 12.x
- uses: actions/checkout@v1
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v1
with:
path: node_modules
key: "${{ runner.os }}-node8-${{ hashFiles('**/package.json') }}"
key: "${{ runner.os }}-node12-${{ hashFiles('**/package.json') }}"
- run: npm install
if: steps.cache-node-modules.outputs.cache-hit != 'true'
working-directory: '${{ env.cwd }}'
Expand All @@ -73,14 +73,14 @@ jobs:
steps:
- uses: actions/setup-node@v1
with:
node-version: 8.x
node-version: 12.x
- uses: actions/checkout@v1
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v1
with:
path: node_modules
key: "${{ runner.os }}-node8-${{ hashFiles('**/package.json') }}"
key: "${{ runner.os }}-node12-${{ hashFiles('**/package.json') }}"
- run: npm install
if: steps.cache-node-modules.outputs.cache-hit != 'true'
working-directory: '${{ env.cwd }}'
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ vm.runTx(
{
tx: tx,
},
function(err, result) {
function (err, result) {
if (err) {
// Handle errors appropriately
}
Expand Down
6 changes: 3 additions & 3 deletions packages/vm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ const PUSH1 = '60'
// Note that numbers added are hex values, so '20' would be '32' as decimal e.g.
const code = [PUSH1, '03', PUSH1, '05', ADD, STOP]

vm.on('step', function(data) {
vm.on('step', function (data) {
console.log(`Opcode: ${data.opcode.name}\tStack: ${data.stack}`)
})

vm.runCode({
code: Buffer.from(code.join(''), 'hex'),
gasLimit: new BN(0xffff),
})
.then(results => {
.then((results) => {
console.log('Returned : ' + results.returnValue.toString('hex'))
console.log('gasUsed : ' + results.gasUsed.toString())
})
.catch(err => console.log('Error : ' + err))
.catch((err) => console.log('Error : ' + err))
```

## Example
Expand Down
6 changes: 3 additions & 3 deletions packages/vm/docs/classes/_exceptions_.vmerror.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

\+ **new VmError**(`error`: [ERROR](../enums/_exceptions_.error.md)): *[VmError](_exceptions_.vmerror.md)*

*Defined in [exceptions.ts:18](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/exceptions.ts#L18)*
*Defined in [exceptions.ts:19](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/exceptions.ts#L19)*

**Parameters:**

Expand All @@ -39,12 +39,12 @@ Name | Type |

• **error**: *[ERROR](../enums/_exceptions_.error.md)*

*Defined in [exceptions.ts:17](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/exceptions.ts#L17)*
*Defined in [exceptions.ts:18](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/exceptions.ts#L18)*

___

### errorType

• **errorType**: *string*

*Defined in [exceptions.ts:18](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/exceptions.ts#L18)*
*Defined in [exceptions.ts:19](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/exceptions.ts#L19)*
67 changes: 44 additions & 23 deletions packages/vm/docs/classes/_index_.vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@ This class is an AsyncEventEmitter, please consult the README to learn how to us
* [allowUnlimitedContractSize](_index_.vm.md#allowunlimitedcontractsize)
* [blockchain](_index_.vm.md#blockchain)
* [opts](_index_.vm.md#opts)
* [pStateManager](_index_.vm.md#pstatemanager)
* [stateManager](_index_.vm.md#statemanager)

### Methods

* [copy](_index_.vm.md#copy)
* [init](_index_.vm.md#init)
* [runBlock](_index_.vm.md#runblock)
* [runBlockchain](_index_.vm.md#runblockchain)
* [runCall](_index_.vm.md#runcall)
* [runCode](_index_.vm.md#runcode)
* [runTx](_index_.vm.md#runtx)
* [create](_index_.vm.md#static-create)

## Constructors

### constructor

\+ **new VM**(`opts`: [VMOpts](../interfaces/_index_.vmopts.md)): *[VM](_index_.vm.md)*

*Defined in [index.ts:75](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L75)*
*Defined in [index.ts:84](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L84)*

Instantiates a new [VM](_index_.vm.md) Object.

Expand All @@ -63,15 +64,15 @@ Name | Type | Default | Description |

• **_common**: *Common*

*Defined in [index.ts:69](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L69)*
*Defined in [index.ts:68](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L68)*

___

### _emit

• **_emit**: *function*

*Defined in [index.ts:74](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L74)*
*Defined in [index.ts:73](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L73)*

#### Type declaration:

Expand All @@ -90,67 +91,69 @@ ___

• **_opcodes**: *OpcodeList*

*Defined in [index.ts:73](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L73)*
*Defined in [index.ts:72](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L72)*

___

### allowUnlimitedContractSize

• **allowUnlimitedContractSize**: *boolean*

*Defined in [index.ts:72](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L72)*
*Defined in [index.ts:71](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L71)*

___

### blockchain

• **blockchain**: *Blockchain*

*Defined in [index.ts:71](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L71)*
*Defined in [index.ts:70](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L70)*

___

### opts

• **opts**: *[VMOpts](../interfaces/_index_.vmopts.md)*

*Defined in [index.ts:68](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L68)*

___

### pStateManager

• **pStateManager**: *PStateManager*

*Defined in [index.ts:75](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L75)*
*Defined in [index.ts:67](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L67)*

___

### stateManager

• **stateManager**: *[StateManager](_state_index_.statemanager.md)*

*Defined in [index.ts:70](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L70)*
*Defined in [index.ts:69](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L69)*

## Methods

### copy

▸ **copy**(): *[VM](_index_.vm.md)*

*Defined in [index.ts:196](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L196)*
*Defined in [index.ts:220](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L220)*

Returns a copy of the [VM](_index_.vm.md) instance.

**Returns:** *[VM](_index_.vm.md)*

___

### init

▸ **init**(): *Promise‹void›*

*Defined in [index.ts:140](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L140)*

**Returns:** *Promise‹void›*

___

### runBlock

▸ **runBlock**(`opts`: [RunBlockOpts](../interfaces/_runblock_.runblockopts.md)): *Promise‹[RunBlockResult](../interfaces/_runblock_.runblockresult.md)›*

*Defined in [index.ts:160](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L160)*
*Defined in [index.ts:180](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L180)*

Processes the `block` running all of the transactions it contains and updating the miner's account

Expand All @@ -172,7 +175,7 @@ ___

▸ **runBlockchain**(`blockchain`: any): *Promise‹void›*

*Defined in [index.ts:146](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L146)*
*Defined in [index.ts:165](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L165)*

Processes blocks and adds them to the blockchain.

Expand All @@ -192,7 +195,7 @@ ___

▸ **runCall**(`opts`: [RunCallOpts](../interfaces/_runcall_.runcallopts.md)): *Promise‹[EVMResult](../interfaces/_evm_evm_.evmresult.md)›*

*Defined in [index.ts:180](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L180)*
*Defined in [index.ts:202](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L202)*

runs a call (or create) operation.

Expand All @@ -212,7 +215,7 @@ ___

▸ **runCode**(`opts`: [RunCodeOpts](../interfaces/_runcode_.runcodeopts.md)): *Promise‹[ExecResult](../interfaces/_evm_evm_.execresult.md)›*

*Defined in [index.ts:189](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L189)*
*Defined in [index.ts:212](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L212)*

Runs EVM code.

Expand All @@ -232,7 +235,7 @@ ___

▸ **runTx**(`opts`: [RunTxOpts](../interfaces/_runtx_.runtxopts.md)): *Promise‹[RunTxResult](../interfaces/_runtx_.runtxresult.md)›*

*Defined in [index.ts:171](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L171)*
*Defined in [index.ts:192](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L192)*

Process a transaction. Run the vm. Transfers eth. Checks balances.

Expand All @@ -247,3 +250,21 @@ Name | Type |
`opts` | [RunTxOpts](../interfaces/_runtx_.runtxopts.md) |

**Returns:** *Promise‹[RunTxResult](../interfaces/_runtx_.runtxresult.md)›*

___

### `Static` create

▸ **create**(`opts`: [VMOpts](../interfaces/_index_.vmopts.md)): *Promise‹[VM](_index_.vm.md)›*

*Defined in [index.ts:80](https://github.com/ethereumjs/ethereumjs-vm/blob/master/packages/vm/lib/index.ts#L80)*

VM async constructor. Creates engine instance and initializes it.

**Parameters:**

Name | Type | Default | Description |
------ | ------ | ------ | ------ |
`opts` | [VMOpts](../interfaces/_index_.vmopts.md) | {} | VM engine constructor options |

**Returns:** *Promise‹[VM](_index_.vm.md)›*
Loading