implement eth_getTransactionByHash, eth_getBlockByHash, eth_getTransactionByHash. fix accounts

pull/7/head
Iuri Matias 6 years ago
parent 3010dc0b76
commit d20d81dd2b
  1. 4
      remix-simulator/README.md
  2. 8
      remix-simulator/src/methods/accounts.js
  3. 31
      remix-simulator/src/methods/blocks.js
  4. 36
      remix-simulator/src/methods/transactions.js

@ -28,9 +28,9 @@ Implemented:
* [_] eth_sendRawTransaction
* [X] eth_call
* [~] eth_estimateGas
* [_] eth_getBlockByHash
* [~] eth_getBlockByHash
* [~] eth_getBlockByNumber
* [_] eth_getTransactionByHash
* [~] eth_getTransactionByHash
* [_] eth_getTransactionByBlockHashAndIndex
* [_] eth_getTransactionByBlockNumberAndIndex
* [~] eth_getTransactionReceipt

@ -7,13 +7,15 @@ var Web3 = require('web3')
var Accounts = function () {
this.web3 = new Web3()
// TODO: make it random and/or use remix-libs
this.accounts = [this.web3.eth.accounts.create(['abcd']), this.web3.eth.accounts.create(['ef12']), this.web3.eth.accounts.create(['ef34'])]
this.accountsList = [this.web3.eth.accounts.create(['abcd']), this.web3.eth.accounts.create(['ef12']), this.web3.eth.accounts.create(['ef34'])]
this.accounts = {}
this.accountsKeys = {}
executionContext.init({get: () => { return true }})
for (let _account of this.accounts) {
for (let _account of this.accountsList) {
this.accountsKeys[_account.address.toLowerCase()] = _account.privateKey
this.accounts[_account.address.toLowerCase()] = { privateKey: Buffer.from(_account.privateKey.replace("0x", ""), 'hex'), nonce: 0 }
executionContext.vm().stateManager.getAccount(Buffer.from(_account.address.toLowerCase().replace("0x", ""), 'hex'), (err, account) => {
var balance = '0x56BC75E2D63100000'
@ -31,7 +33,7 @@ Accounts.prototype.methods = function () {
}
Accounts.prototype.eth_accounts = function (payload, cb) {
return cb(null, this.accounts.map((x) => x.address))
return cb(null, this.accountsList.map((x) => x.address))
}
Accounts.prototype.eth_getBalance = function (payload, cb) {

@ -11,7 +11,8 @@ Blocks.prototype.methods = function () {
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_blockNumber: this.eth_blockNumber.bind(this),
eth_getBlockByHash: this.eth_getBlockByHash.bind(this)
}
}
@ -26,7 +27,33 @@ Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
'miner': this.coinbase,
'mixHash': '0x0000000000000000000000000000000000000000000000000000000000000000',
'nonce': '0x0000000000000042',
'number': Web3.utils.tohex(this.blockNumber),
'number': Web3.utils.toHex(this.blockNumber),
'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000000',
'receiptsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
'size': '0x1f8',
'stateRoot': '0xb7917653f92e62394d2207d0f39a1320ff1cb93d1cee80d3c492627e00b219ff',
'timestamp': '0x0',
'totalDifficulty': '0x0',
'transactions': [],
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'uncles': []
}
cb(null, b)
}
Blocks.prototype.eth_getBlockByHash = function (payload, cb) {
let b = {
'difficulty': '0x0',
'extraData': '0x',
'gasLimit': '0x7a1200',
'gasUsed': '0x0',
'hash': '0xdb731f3622ef37b4da8db36903de029220dba74c41185f8429f916058b86559f',
'logsBloom': '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
'miner': this.coinbase,
'mixHash': '0x0000000000000000000000000000000000000000000000000000000000000000',
'nonce': '0x0000000000000042',
'number': Web3.utils.toHex(this.blockNumber),
'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000000',
'receiptsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',

@ -1,5 +1,6 @@
var RemixLib = require('remix-lib')
var executionContext = RemixLib.execution.executionContext
var ethJSUtil = require('ethereumjs-util')
var processTx = require('./txProcess.js')
function hexConvert(ints) {
@ -17,8 +18,6 @@ function hexConvert(ints) {
var Transactions = function (accounts) {
this.accounts = accounts
// TODO: fix me; this is a temporary and very hackish thing just to get the getCode working for now
//this.deployedContracts = {}
}
Transactions.prototype.methods = function () {
@ -28,7 +27,8 @@ Transactions.prototype.methods = function () {
eth_getCode: this.eth_getCode.bind(this),
eth_call: this.eth_call.bind(this),
eth_estimateGas: this.eth_estimateGas.bind(this),
eth_getTransactionCount: this.eth_getTransactionCount.bind(this)
eth_getTransactionCount: this.eth_getTransactionCount.bind(this),
eth_getTransactionByHash: this.eth_getTransactionByHash.bind(this)
}
}
@ -68,10 +68,10 @@ Transactions.prototype.eth_getCode = function (payload, cb) {
let address = payload.params[0]
const account = ethJSUtil.toBuffer(address)
executionContext.vm().stateManager.getContractCode(account, (error, result) => {
cb(error, hexConvert(result))
})
//cb(null, this.deployedContracts[address] || '0x')
}
Transactions.prototype.eth_call = function (payload, cb) {
@ -87,4 +87,32 @@ Transactions.prototype.eth_getTransactionCount = function (payload, cb) {
})
}
Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
const address = payload.params[0]
executionContext.web3().eth.getTransactionReceipt(address, (error, receipt) => {
if (error) {
return cb(error)
}
web3.eth.getBlock(receipt.hash).then((block) => {
const r = {
"hash": receipt.transactionHash,
//"nonce": 2,
"blockHash": receipt.hash,
"blockNumber": block.number,
//"transactionIndex": 0,
"from": receipt.from,
"to": receipt.to,
"value": receipt.value,
"gas": receipt.gas,
"gasPrice": '2000000000000',
"input": receipt.input
}
cb(null, r)
})
})
}
module.exports = Transactions

Loading…
Cancel
Save