parent
6c1c567790
commit
a1f50eb141
@ -0,0 +1,15 @@ |
|||||||
|
{ |
||||||
|
"extends": "../../.eslintrc", |
||||||
|
"rules": { |
||||||
|
"@typescript-eslint/no-var-requires": "off", |
||||||
|
"@typescript-eslint/no-empty-function": "off", |
||||||
|
"@typescript-eslint/no-unused-vars": "off" |
||||||
|
}, |
||||||
|
"env": { |
||||||
|
"browser": true, |
||||||
|
"amd": true, |
||||||
|
"node": true, |
||||||
|
"es6": true |
||||||
|
}, |
||||||
|
"ignorePatterns": ["!**/*"] |
||||||
|
} |
@ -1,138 +1,140 @@ |
|||||||
|
|
||||||
const Blocks = function (executionContext, _options) { |
class Blocks { |
||||||
this.executionContext = executionContext |
constructor (executionContext, _options) { |
||||||
const options = _options || {} |
this.executionContext = executionContext |
||||||
this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000' |
const options = _options || {} |
||||||
this.blockNumber = 0 |
this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000' |
||||||
} |
this.blockNumber = 0 |
||||||
|
|
||||||
Blocks.prototype.methods = function () { |
|
||||||
return { |
|
||||||
eth_getBlockByNumber: this.eth_getBlockByNumber.bind(this), |
|
||||||
eth_gasPrice: this.eth_gasPrice.bind(this), |
|
||||||
eth_coinbase: this.eth_coinbase.bind(this), |
|
||||||
eth_blockNumber: this.eth_blockNumber.bind(this), |
|
||||||
eth_getBlockByHash: this.eth_getBlockByHash.bind(this), |
|
||||||
eth_getBlockTransactionCountByHash: this.eth_getBlockTransactionCountByHash.bind(this), |
|
||||||
eth_getBlockTransactionCountByNumber: this.eth_getBlockTransactionCountByNumber.bind(this), |
|
||||||
eth_getUncleCountByBlockHash: this.eth_getUncleCountByBlockHash.bind(this), |
|
||||||
eth_getUncleCountByBlockNumber: this.eth_getUncleCountByBlockNumber.bind(this), |
|
||||||
eth_getStorageAt: this.eth_getStorageAt.bind(this) |
|
||||||
} |
} |
||||||
} |
|
||||||
|
|
||||||
Blocks.prototype.eth_getBlockByNumber = function (payload, cb) { |
methods () { |
||||||
let blockIndex = payload.params[0] |
return { |
||||||
if (blockIndex === 'latest') { |
eth_getBlockByNumber: this.eth_getBlockByNumber.bind(this), |
||||||
blockIndex = this.executionContext.latestBlockNumber |
eth_gasPrice: this.eth_gasPrice.bind(this), |
||||||
|
eth_coinbase: this.eth_coinbase.bind(this), |
||||||
|
eth_blockNumber: this.eth_blockNumber.bind(this), |
||||||
|
eth_getBlockByHash: this.eth_getBlockByHash.bind(this), |
||||||
|
eth_getBlockTransactionCountByHash: this.eth_getBlockTransactionCountByHash.bind(this), |
||||||
|
eth_getBlockTransactionCountByNumber: this.eth_getBlockTransactionCountByNumber.bind(this), |
||||||
|
eth_getUncleCountByBlockHash: this.eth_getUncleCountByBlockHash.bind(this), |
||||||
|
eth_getUncleCountByBlockNumber: this.eth_getUncleCountByBlockNumber.bind(this), |
||||||
|
eth_getStorageAt: this.eth_getStorageAt.bind(this) |
||||||
|
} |
||||||
} |
} |
||||||
|
|
||||||
const block = this.executionContext.blocks[blockIndex] |
eth_getBlockByNumber (payload, cb) { |
||||||
|
let blockIndex = payload.params[0] |
||||||
|
if (blockIndex === 'latest') { |
||||||
|
blockIndex = this.executionContext.latestBlockNumber |
||||||
|
} |
||||||
|
|
||||||
if (!block) { |
const block = this.executionContext.blocks[blockIndex] |
||||||
return cb(new Error('block not found')) |
|
||||||
} |
|
||||||
|
|
||||||
let b = { |
if (!block) { |
||||||
'number': toHex(block.header.number), |
return cb(new Error('block not found')) |
||||||
'hash': toHex(block.hash()), |
} |
||||||
'parentHash': toHex(block.header.parentHash), |
|
||||||
'nonce': toHex(block.header.nonce), |
|
||||||
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', |
|
||||||
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', |
|
||||||
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', |
|
||||||
'stateRoot': toHex(block.header.stateRoot), |
|
||||||
'miner': this.coinbase, |
|
||||||
'difficulty': toHex(block.header.difficulty), |
|
||||||
'totalDifficulty': toHex(block.header.totalDifficulty), |
|
||||||
'extraData': toHex(block.header.extraData), |
|
||||||
'size': '0x027f07', // 163591
|
|
||||||
'gasLimit': toHex(block.header.gasLimit), |
|
||||||
'gasUsed': toHex(block.header.gasUsed), |
|
||||||
'timestamp': toHex(block.header.timestamp), |
|
||||||
'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')), |
|
||||||
'uncles': [] |
|
||||||
} |
|
||||||
|
|
||||||
cb(null, b) |
let b = { |
||||||
|
'number': this.toHex(block.header.number), |
||||||
|
'hash': this.toHex(block.hash()), |
||||||
|
'parentHash': this.toHex(block.header.parentHash), |
||||||
|
'nonce': this.toHex(block.header.nonce), |
||||||
|
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', |
||||||
|
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', |
||||||
|
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', |
||||||
|
'stateRoot': this.toHex(block.header.stateRoot), |
||||||
|
'miner': this.coinbase, |
||||||
|
'difficulty': this.toHex(block.header.difficulty), |
||||||
|
'totalDifficulty': this.toHex(block.header.totalDifficulty), |
||||||
|
'extraData': this.toHex(block.header.extraData), |
||||||
|
'size': '0x027f07', // 163591
|
||||||
|
'gasLimit': this.toHex(block.header.gasLimit), |
||||||
|
'gasUsed': this.toHex(block.header.gasUsed), |
||||||
|
'timestamp': this.toHex(block.header.timestamp), |
||||||
|
'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')), |
||||||
|
'uncles': [] |
||||||
|
} |
||||||
|
|
||||||
|
cb(null, b) |
||||||
} |
} |
||||||
|
|
||||||
function toHex (value) { |
toHex (value) { |
||||||
if (!value) return '0x0' |
if (!value) return '0x0' |
||||||
let v = value.toString('hex') |
let v = value.toString('hex') |
||||||
return ((v === '0x' || v === '') ? '0x0' : ('0x' + v)) |
return ((v === '0x' || v === '') ? '0x0' : ('0x' + v)) |
||||||
} |
|
||||||
|
|
||||||
Blocks.prototype.eth_getBlockByHash = function (payload, cb) { |
|
||||||
var block = this.executionContext.blocks[payload.params[0]] |
|
||||||
|
|
||||||
let b = { |
|
||||||
'number': toHex(block.header.number), |
|
||||||
'hash': toHex(block.hash()), |
|
||||||
'parentHash': toHex(block.header.parentHash), |
|
||||||
'nonce': toHex(block.header.nonce), |
|
||||||
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', |
|
||||||
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', |
|
||||||
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', |
|
||||||
'stateRoot': toHex(block.header.stateRoot), |
|
||||||
'miner': this.coinbase, |
|
||||||
'difficulty': toHex(block.header.difficulty), |
|
||||||
'totalDifficulty': toHex(block.header.totalDifficulty), |
|
||||||
'extraData': toHex(block.header.extraData), |
|
||||||
'size': '0x027f07', // 163591
|
|
||||||
'gasLimit': toHex(block.header.gasLimit), |
|
||||||
'gasUsed': toHex(block.header.gasUsed), |
|
||||||
'timestamp': toHex(block.header.timestamp), |
|
||||||
'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')), |
|
||||||
'uncles': [] |
|
||||||
} |
} |
||||||
|
|
||||||
cb(null, b) |
eth_getBlockByHash (payload, cb) { |
||||||
} |
var block = this.executionContext.blocks[payload.params[0]] |
||||||
|
|
||||||
|
let b = { |
||||||
|
'number': this.toHex(block.header.number), |
||||||
|
'hash': this.toHex(block.hash()), |
||||||
|
'parentHash': this.toHex(block.header.parentHash), |
||||||
|
'nonce': this.toHex(block.header.nonce), |
||||||
|
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', |
||||||
|
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', |
||||||
|
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', |
||||||
|
'stateRoot': this.toHex(block.header.stateRoot), |
||||||
|
'miner': this.coinbase, |
||||||
|
'difficulty': this.toHex(block.header.difficulty), |
||||||
|
'totalDifficulty': this.toHex(block.header.totalDifficulty), |
||||||
|
'extraData': this.toHex(block.header.extraData), |
||||||
|
'size': '0x027f07', // 163591
|
||||||
|
'gasLimit': this.toHex(block.header.gasLimit), |
||||||
|
'gasUsed': this.toHex(block.header.gasUsed), |
||||||
|
'timestamp': this.toHex(block.header.timestamp), |
||||||
|
'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')), |
||||||
|
'uncles': [] |
||||||
|
} |
||||||
|
|
||||||
Blocks.prototype.eth_gasPrice = function (payload, cb) { |
cb(null, b) |
||||||
cb(null, 1) |
} |
||||||
} |
|
||||||
|
|
||||||
Blocks.prototype.eth_coinbase = function (payload, cb) { |
eth_gasPrice (payload, cb) { |
||||||
cb(null, this.coinbase) |
cb(null, 1) |
||||||
} |
} |
||||||
|
|
||||||
Blocks.prototype.eth_blockNumber = function (payload, cb) { |
eth_coinbase (payload, cb) { |
||||||
cb(null, this.blockNumber) |
cb(null, this.coinbase) |
||||||
} |
} |
||||||
|
|
||||||
Blocks.prototype.eth_getBlockTransactionCountByHash = function (payload, cb) { |
eth_blockNumber (payload, cb) { |
||||||
var block = this.executionContext.blocks[payload.params[0]] |
cb(null, this.blockNumber) |
||||||
|
} |
||||||
|
|
||||||
cb(null, block.transactions.length) |
eth_getBlockTransactionCountByHash (payload, cb) { |
||||||
} |
var block = this.executionContext.blocks[payload.params[0]] |
||||||
|
|
||||||
Blocks.prototype.eth_getBlockTransactionCountByNumber = function (payload, cb) { |
cb(null, block.transactions.length) |
||||||
var block = this.executionContext.blocks[payload.params[0]] |
} |
||||||
|
|
||||||
cb(null, block.transactions.length) |
eth_getBlockTransactionCountByNumber (payload, cb) { |
||||||
} |
var block = this.executionContext.blocks[payload.params[0]] |
||||||
|
|
||||||
Blocks.prototype.eth_getUncleCountByBlockHash = function (payload, cb) { |
cb(null, block.transactions.length) |
||||||
cb(null, 0) |
} |
||||||
} |
|
||||||
|
|
||||||
Blocks.prototype.eth_getUncleCountByBlockNumber = function (payload, cb) { |
eth_getUncleCountByBlockHash (payload, cb) { |
||||||
cb(null, 0) |
cb(null, 0) |
||||||
} |
} |
||||||
|
|
||||||
Blocks.prototype.eth_getStorageAt = function (payload, cb) { |
eth_getUncleCountByBlockNumber (payload, cb) { |
||||||
const [address, position, blockNumber] = payload.params |
cb(null, 0) |
||||||
|
} |
||||||
|
|
||||||
this.executionContext.web3().debug.storageRangeAt(blockNumber, 'latest', address.toLowerCase(), position, 1, (err, result) => { |
eth_getStorageAt (payload, cb) { |
||||||
if (err || (result.storage && Object.values(result.storage).length === 0)) { |
const [address, position, blockNumber] = payload.params |
||||||
return cb(err, '') |
|
||||||
} |
|
||||||
|
|
||||||
let value = Object.values(result.storage)[0].value |
this.executionContext.web3().debug.storageRangeAt(blockNumber, 'latest', address.toLowerCase(), position, 1, (err, result) => { |
||||||
cb(err, value) |
if (err || (result.storage && Object.values(result.storage).length === 0)) { |
||||||
}) |
return cb(err, '') |
||||||
|
} |
||||||
|
|
||||||
|
let value = Object.values(result.storage)[0].value |
||||||
|
cb(err, value) |
||||||
|
}) |
||||||
|
} |
||||||
} |
} |
||||||
|
|
||||||
module.exports = Blocks |
module.exports = Blocks |
||||||
|
@ -1,61 +1,63 @@ |
|||||||
|
|
||||||
const Filters = function (executionContext) { |
class Filters {
|
||||||
this.executionContext = executionContext |
constructor(executionContext) { |
||||||
} |
this.executionContext = executionContext |
||||||
|
} |
||||||
|
|
||||||
Filters.prototype.methods = function () { |
methods () { |
||||||
return { |
return { |
||||||
eth_getLogs: this.eth_getLogs.bind(this), |
eth_getLogs: this.eth_getLogs.bind(this), |
||||||
eth_subscribe: this.eth_subscribe.bind(this), |
eth_subscribe: this.eth_subscribe.bind(this), |
||||||
eth_unsubscribe: this.eth_unsubscribe.bind(this) |
eth_unsubscribe: this.eth_unsubscribe.bind(this) |
||||||
|
} |
||||||
} |
} |
||||||
} |
|
||||||
|
|
||||||
Filters.prototype.eth_getLogs = function (payload, cb) { |
eth_getLogs (payload, cb) { |
||||||
let results = this.executionContext.logsManager.getLogsFor(payload.params[0]) |
let results = this.executionContext.logsManager.getLogsFor(payload.params[0]) |
||||||
cb(null, results) |
cb(null, results) |
||||||
} |
} |
||||||
|
|
||||||
Filters.prototype.eth_subscribe = function (payload, cb) { |
eth_subscribe (payload, cb) { |
||||||
let subscriptionId = this.executionContext.logsManager.subscribe(payload.params) |
let subscriptionId = this.executionContext.logsManager.subscribe(payload.params) |
||||||
cb(null, subscriptionId) |
cb(null, subscriptionId) |
||||||
} |
} |
||||||
|
|
||||||
Filters.prototype.eth_unsubscribe = function (payload, cb) { |
eth_unsubscribe (payload, cb) { |
||||||
this.executionContext.logsManager.unsubscribe(payload.params[0]) |
this.executionContext.logsManager.unsubscribe(payload.params[0]) |
||||||
cb(null, true) |
cb(null, true) |
||||||
} |
} |
||||||
|
|
||||||
Filters.prototype.eth_newFilter = function (payload, cb) { |
eth_newFilter (payload, cb) { |
||||||
const filterId = this.executionContext.logsManager.newFilter('filter', payload.params[0]) |
const filterId = this.executionContext.logsManager.newFilter('filter', payload.params[0]) |
||||||
cb(null, filterId) |
cb(null, filterId) |
||||||
} |
} |
||||||
|
|
||||||
Filters.prototype.eth_newBlockFilter = function (payload, cb) { |
eth_newBlockFilter (payload, cb) { |
||||||
const filterId = this.executionContext.logsManager.newFilter('block') |
const filterId = this.executionContext.logsManager.newFilter('block') |
||||||
cb(null, filterId) |
cb(null, filterId) |
||||||
} |
} |
||||||
|
|
||||||
Filters.prototype.eth_newPendingTransactionFilter = function (payload, cb) { |
eth_newPendingTransactionFilter (payload, cb) { |
||||||
const filterId = this.executionContext.logsManager.newFilter('pendingTransactions') |
const filterId = this.executionContext.logsManager.newFilter('pendingTransactions') |
||||||
cb(null, filterId) |
cb(null, filterId) |
||||||
} |
} |
||||||
|
|
||||||
Filters.prototype.eth_uninstallfilter = function (payload, cb) { |
eth_uninstallfilter (payload, cb) { |
||||||
const result = this.executionContext.logsManager.uninstallFilter(payload.params[0]) |
const result = this.executionContext.logsManager.uninstallFilter(payload.params[0]) |
||||||
cb(null, result) |
cb(null, result) |
||||||
} |
} |
||||||
|
|
||||||
Filters.prototype.eth_getFilterChanges = function (payload, cb) { |
eth_getFilterChanges (payload, cb) { |
||||||
const filterId = payload.params[0] |
const filterId = payload.params[0] |
||||||
let results = this.executionContext.logsManager.getLogsForFilter(filterId) |
let results = this.executionContext.logsManager.getLogsForFilter(filterId) |
||||||
cb(null, results) |
cb(null, results) |
||||||
} |
} |
||||||
|
|
||||||
Filters.prototype.eth_getFilterLogs = function (payload, cb) { |
eth_getFilterLogs (payload, cb) { |
||||||
const filterId = payload.params[0] |
const filterId = payload.params[0] |
||||||
let results = this.executionContext.logsManager.getLogsForFilter(filterId, true) |
let results = this.executionContext.logsManager.getLogsForFilter(filterId, true) |
||||||
cb(null, results) |
cb(null, results) |
||||||
|
} |
||||||
} |
} |
||||||
|
|
||||||
module.exports = Filters |
module.exports = Filters |
||||||
|
@ -0,0 +1,18 @@ |
|||||||
|
{ |
||||||
|
"extends": "../../tsconfig.json", |
||||||
|
"compilerOptions": { |
||||||
|
"module": "commonjs", |
||||||
|
"outDir": "../../dist/out-tsc", |
||||||
|
"allowJs": true, |
||||||
|
"declaration": true, |
||||||
|
"rootDir": "./", |
||||||
|
"types": ["node"] |
||||||
|
}, |
||||||
|
"exclude": ["**/*.spec.js"], |
||||||
|
"include": [ |
||||||
|
"src/**/*.js", |
||||||
|
"./index.js", |
||||||
|
"bin/" |
||||||
|
] |
||||||
|
} |
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue