commit
135e11af82
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 2.6 KiB |
@ -0,0 +1,79 @@ |
||||
import { Block } from '@ethereumjs/block' |
||||
import { ConsensusType } from '@ethereumjs/common' |
||||
import type { VMContext } from '../vm-context' |
||||
import type { Transactions } from '../methods/transactions' |
||||
|
||||
export class EVM { |
||||
vmContext: VMContext |
||||
transactions: Transactions |
||||
|
||||
constructor (vmContext: VMContext, transactions: Transactions) { |
||||
this.vmContext = vmContext |
||||
this.transactions = transactions |
||||
} |
||||
|
||||
methods () { |
||||
return { |
||||
evm_setAutomine: this.evm_setAutomine.bind(this), |
||||
evm_setIntervalMining: this.evm_setIntervalMining.bind(this), |
||||
evm_snapshot: this.evm_snapshot.bind(this), |
||||
evm_revert: this.evm_revert.bind(this), |
||||
evm_increaseTime: this.evm_increaseTime.bind(this), |
||||
evm_setNextBlockTimestamp: this.evm_setNextBlockTimestamp.bind(this), |
||||
evm_setBlockGasLimit: this.evm_setBlockGasLimit.bind(this), |
||||
evm_mine: this.evm_mine.bind(this) |
||||
} |
||||
} |
||||
|
||||
evm_setAutomine (payload, cb) { |
||||
// always on
|
||||
cb() |
||||
} |
||||
|
||||
evm_setIntervalMining (payload, cb) { |
||||
cb() |
||||
} |
||||
|
||||
evm_snapshot (payload, cb) { |
||||
cb() |
||||
} |
||||
|
||||
evm_revert (payload, cb) { |
||||
cb() |
||||
} |
||||
|
||||
evm_increaseTime (payload, cb) { |
||||
cb() |
||||
} |
||||
|
||||
evm_setNextBlockTimestamp (payload, cb) { |
||||
cb() |
||||
} |
||||
|
||||
evm_setBlockGasLimit (payload, cb) { |
||||
cb() |
||||
} |
||||
|
||||
async evm_mine (payload, cb) { |
||||
const runEmptyBlock = () => { |
||||
return new Promise((resolve, reject) => { |
||||
this.transactions.txRunnerVMInstance.runEmptyBlock((error, result) => { |
||||
if (error) { |
||||
reject(error) |
||||
return |
||||
} |
||||
this.vmContext.addBlock(result.block, false, true) |
||||
resolve(result) |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
const blocks = payload.params[0].blocks |
||||
|
||||
for (let b = 0; b < Number(blocks); b++) { |
||||
await runEmptyBlock() |
||||
console.log('mining...', b, this.vmContext.latestBlockNumber) |
||||
} |
||||
cb() |
||||
} |
||||
} |
@ -0,0 +1,18 @@ |
||||
export class Miner { |
||||
vmContext |
||||
|
||||
constructor (vmContext) { |
||||
this.vmContext = vmContext |
||||
} |
||||
|
||||
methods () { |
||||
return { |
||||
miner_start: this.miner_start.bind(this), |
||||
miner_stop: this.miner_stop.bind(this) |
||||
} |
||||
} |
||||
|
||||
miner_start (payload, cb) { cb() } |
||||
|
||||
miner_stop (payload, cb) { cb() } |
||||
} |
@ -1,20 +1,24 @@ |
||||
export function methods (): Record<string, unknown> { |
||||
export class Net { |
||||
vmContext |
||||
options |
||||
|
||||
constructor (vmContext, options) { |
||||
this.vmContext = vmContext |
||||
this.options = options |
||||
} |
||||
|
||||
methods () { |
||||
return { |
||||
net_version: net_version, |
||||
net_listening: net_listening, |
||||
net_peerCount: net_peerCount |
||||
net_version: this.net_version.bind(this), |
||||
net_listening: this.net_listening.bind(this), |
||||
net_peerCount: this.net_peerCount.bind(this) |
||||
} |
||||
} |
||||
} |
||||
|
||||
export function net_version (payload, cb): void { |
||||
// should be configured networkId
|
||||
cb(null, 1337) |
||||
} |
||||
net_version (payload, cb) { cb(null, 1337) } |
||||
|
||||
export function net_listening (payload, cb): void { |
||||
cb(null, true) |
||||
} |
||||
net_listening (payload, cb) { cb(null, true)} |
||||
|
||||
export function net_peerCount (payload, cb): void { |
||||
cb(null, 0) |
||||
net_peerCount (payload, cb) { cb(null, 0)} |
||||
} |
||||
|
||||
|
Loading…
Reference in new issue