parent
98cf38f6e7
commit
bb6d16b1bb
@ -0,0 +1,40 @@ |
||||
|
||||
# See http://help.github.com/ignore-files/ for more about ignoring files. |
||||
|
||||
# compiled output |
||||
/dist |
||||
/tmp |
||||
/out-tsc |
||||
|
||||
# dependencies |
||||
/node_modules |
||||
|
||||
# IDEs and editors |
||||
/.idea |
||||
.project |
||||
.classpath |
||||
.c9/ |
||||
*.launch |
||||
.settings/ |
||||
*.sublime-workspace |
||||
|
||||
# IDE - VSCode |
||||
.vscode/* |
||||
!.vscode/settings.json |
||||
!.vscode/tasks.json |
||||
!.vscode/launch.json |
||||
!.vscode/extensions.json |
||||
|
||||
# misc |
||||
/.sass-cache |
||||
/connect.lock |
||||
/coverage |
||||
/libpeerconnection.log |
||||
npm-debug.log |
||||
yarn-error.log |
||||
testem.log |
||||
/typings |
||||
|
||||
# System Files |
||||
.DS_Store |
||||
Thumbs.db |
@ -1,138 +1,139 @@ |
||||
|
||||
const Blocks = function (executionContext, _options) { |
||||
this.executionContext = executionContext |
||||
const options = _options || {} |
||||
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) |
||||
class Blocks { |
||||
constructor (executionContext, _options) { |
||||
this.executionContext = executionContext |
||||
const options = _options || {} |
||||
this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000' |
||||
this.blockNumber = 0 |
||||
} |
||||
} |
||||
|
||||
Blocks.prototype.eth_getBlockByNumber = function (payload, cb) { |
||||
let blockIndex = payload.params[0] |
||||
if (blockIndex === 'latest') { |
||||
blockIndex = this.executionContext.latestBlockNumber |
||||
methods () { |
||||
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) |
||||
} |
||||
} |
||||
|
||||
const block = this.executionContext.blocks[blockIndex] |
||||
eth_getBlockByNumber (payload, cb) { |
||||
let blockIndex = payload.params[0] |
||||
if (blockIndex === 'latest') { |
||||
blockIndex = this.executionContext.latestBlockNumber |
||||
} |
||||
|
||||
if (!block) { |
||||
return cb(new Error('block not found')) |
||||
} |
||||
const block = this.executionContext.blocks[blockIndex] |
||||
|
||||
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': [] |
||||
} |
||||
if (!block) { |
||||
return cb(new Error('block not found')) |
||||
} |
||||
|
||||
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' |
||||
let v = value.toString('hex') |
||||
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, 1) |
||||
} |
||||
cb(null, b) |
||||
} |
||||
|
||||
Blocks.prototype.eth_coinbase = function (payload, cb) { |
||||
cb(null, this.coinbase) |
||||
} |
||||
eth_gasPrice (payload, cb) { |
||||
cb(null, 1) |
||||
} |
||||
|
||||
Blocks.prototype.eth_blockNumber = function (payload, cb) { |
||||
cb(null, this.blockNumber) |
||||
} |
||||
eth_coinbase (payload, cb) { |
||||
cb(null, this.coinbase) |
||||
} |
||||
|
||||
Blocks.prototype.eth_getBlockTransactionCountByHash = function (payload, cb) { |
||||
var block = this.executionContext.blocks[payload.params[0]] |
||||
eth_blockNumber (payload, cb) { |
||||
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) { |
||||
var block = this.executionContext.blocks[payload.params[0]] |
||||
cb(null, block.transactions.length) |
||||
} |
||||
|
||||
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, 0) |
||||
} |
||||
cb(null, block.transactions.length) |
||||
} |
||||
|
||||
Blocks.prototype.eth_getUncleCountByBlockNumber = function (payload, cb) { |
||||
cb(null, 0) |
||||
} |
||||
eth_getUncleCountByBlockHash (payload, cb) { |
||||
cb(null, 0) |
||||
} |
||||
|
||||
Blocks.prototype.eth_getStorageAt = function (payload, cb) { |
||||
const [address, position, blockNumber] = payload.params |
||||
eth_getUncleCountByBlockNumber (payload, cb) { |
||||
cb(null, 0) |
||||
} |
||||
|
||||
this.executionContext.web3().debug.storageRangeAt(blockNumber, 'latest', address.toLowerCase(), position, 1, (err, result) => { |
||||
if (err || (result.storage && Object.values(result.storage).length === 0)) { |
||||
return cb(err, '') |
||||
} |
||||
eth_getStorageAt (payload, cb) { |
||||
const [address, position, blockNumber] = payload.params |
||||
|
||||
let value = Object.values(result.storage)[0].value |
||||
cb(err, value) |
||||
}) |
||||
this.executionContext.web3().debug.storageRangeAt(blockNumber, 'latest', address.toLowerCase(), position, 1, (err, result) => { |
||||
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,62 @@ |
||||
class Filters {
|
||||
constructor(executionContext) { |
||||
this.executionContext = executionContext |
||||
} |
||||
|
||||
const Filters = function (executionContext) { |
||||
this.executionContext = executionContext |
||||
} |
||||
|
||||
Filters.prototype.methods = function () { |
||||
return { |
||||
eth_getLogs: this.eth_getLogs.bind(this), |
||||
eth_subscribe: this.eth_subscribe.bind(this), |
||||
eth_unsubscribe: this.eth_unsubscribe.bind(this) |
||||
methods () { |
||||
return { |
||||
eth_getLogs: this.eth_getLogs.bind(this), |
||||
eth_subscribe: this.eth_subscribe.bind(this), |
||||
eth_unsubscribe: this.eth_unsubscribe.bind(this) |
||||
} |
||||
} |
||||
} |
||||
|
||||
Filters.prototype.eth_getLogs = function (payload, cb) { |
||||
let results = this.executionContext.logsManager.getLogsFor(payload.params[0]) |
||||
cb(null, results) |
||||
} |
||||
eth_getLogs (payload, cb) { |
||||
let results = this.executionContext.logsManager.getLogsFor(payload.params[0]) |
||||
cb(null, results) |
||||
} |
||||
|
||||
Filters.prototype.eth_subscribe = function (payload, cb) { |
||||
let subscriptionId = this.executionContext.logsManager.subscribe(payload.params) |
||||
cb(null, subscriptionId) |
||||
} |
||||
eth_subscribe (payload, cb) { |
||||
let subscriptionId = this.executionContext.logsManager.subscribe(payload.params) |
||||
cb(null, subscriptionId) |
||||
} |
||||
|
||||
Filters.prototype.eth_unsubscribe = function (payload, cb) { |
||||
this.executionContext.logsManager.unsubscribe(payload.params[0]) |
||||
cb(null, true) |
||||
} |
||||
eth_unsubscribe (payload, cb) { |
||||
this.executionContext.logsManager.unsubscribe(payload.params[0]) |
||||
cb(null, true) |
||||
} |
||||
|
||||
Filters.prototype.eth_newFilter = function (payload, cb) { |
||||
const filterId = this.executionContext.logsManager.newFilter('filter', payload.params[0]) |
||||
cb(null, filterId) |
||||
} |
||||
eth_newFilter (payload, cb) { |
||||
const filterId = this.executionContext.logsManager.newFilter('filter', payload.params[0]) |
||||
cb(null, filterId) |
||||
} |
||||
|
||||
Filters.prototype.eth_newBlockFilter = function (payload, cb) { |
||||
const filterId = this.executionContext.logsManager.newFilter('block') |
||||
cb(null, filterId) |
||||
} |
||||
eth_newBlockFilter (payload, cb) { |
||||
const filterId = this.executionContext.logsManager.newFilter('block') |
||||
cb(null, filterId) |
||||
} |
||||
|
||||
Filters.prototype.eth_newPendingTransactionFilter = function (payload, cb) { |
||||
const filterId = this.executionContext.logsManager.newFilter('pendingTransactions') |
||||
cb(null, filterId) |
||||
} |
||||
eth_newPendingTransactionFilter (payload, cb) { |
||||
const filterId = this.executionContext.logsManager.newFilter('pendingTransactions') |
||||
cb(null, filterId) |
||||
} |
||||
|
||||
Filters.prototype.eth_uninstallfilter = function (payload, cb) { |
||||
const result = this.executionContext.logsManager.uninstallFilter(payload.params[0]) |
||||
cb(null, result) |
||||
} |
||||
eth_uninstallfilter (payload, cb) { |
||||
const result = this.executionContext.logsManager.uninstallFilter(payload.params[0]) |
||||
cb(null, result) |
||||
} |
||||
|
||||
Filters.prototype.eth_getFilterChanges = function (payload, cb) { |
||||
const filterId = payload.params[0] |
||||
let results = this.executionContext.logsManager.getLogsForFilter(filterId) |
||||
cb(null, results) |
||||
} |
||||
eth_getFilterChanges (payload, cb) { |
||||
const filterId = payload.params[0] |
||||
let results = this.executionContext.logsManager.getLogsForFilter(filterId) |
||||
cb(null, results) |
||||
} |
||||
|
||||
Filters.prototype.eth_getFilterLogs = function (payload, cb) { |
||||
const filterId = payload.params[0] |
||||
let results = this.executionContext.logsManager.getLogsForFilter(filterId, true) |
||||
cb(null, results) |
||||
eth_getFilterLogs (payload, cb) { |
||||
const filterId = payload.params[0] |
||||
let results = this.executionContext.logsManager.getLogsForFilter(filterId, true) |
||||
cb(null, results) |
||||
} |
||||
} |
||||
|
||||
module.exports = Filters |
||||
module.exports = Filters |
Loading…
Reference in new issue