add eth_getBalance; use accounts in executionContext vm

pull/5370/head
Iuri Matias 6 years ago
parent 6b69be0b8a
commit f604436155
  1. 2
      remix-simulator/README.md
  2. 2
      remix-simulator/package.json
  3. 32
      remix-simulator/src/methods/accounts.js

@ -15,7 +15,7 @@ Implemented:
* [~] eth_gasPrice
* [~] eth_accounts
* [X] eth_blockNumber
* [_] eth_getBalance
* [X] eth_getBalance
* [_] eth_getStorageAt
* [_] eth_getTransactionCount
* [_] eth_getBlockTransactionCountByHash

@ -23,6 +23,8 @@
"fast-async": "^6.3.7",
"merge": "^1.2.0",
"remix-lib": "0.4.5",
"ethereumjs-vm": "3.0.0",
"ethereumjs-util": "^5.1.2",
"standard": "^10.0.3",
"time-stamp": "^2.0.0",
"web3": "1.0.0-beta.27"

@ -1,3 +1,7 @@
var RemixLib = require('remix-lib')
var executionContext = RemixLib.execution.executionContext
var ethJSUtil = require('ethereumjs-util')
var BN = ethJSUtil.BN
var Web3 = require('web3')
var Accounts = function () {
@ -5,18 +9,20 @@ var Accounts = function () {
// 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.accounts[this.accounts[0].address.toLowerCase()] = this.accounts[0]
this.accounts[this.accounts[1].address.toLowerCase()] = this.accounts[1]
this.accounts[this.accounts[2].address.toLowerCase()] = this.accounts[2]
executionContext.init({get: () => { return true }})
this.accounts[this.accounts[0].address.toLowerCase()].privateKey = Buffer.from(this.accounts[this.accounts[0].address.toLowerCase()].privateKey.slice(2), 'hex')
this.accounts[this.accounts[1].address.toLowerCase()].privateKey = Buffer.from(this.accounts[this.accounts[1].address.toLowerCase()].privateKey.slice(2), 'hex')
this.accounts[this.accounts[2].address.toLowerCase()].privateKey = Buffer.from(this.accounts[this.accounts[2].address.toLowerCase()].privateKey.slice(2), 'hex')
for (let _account of this.accounts) {
executionContext.vm().stateManager.getAccount(Buffer.from(_account.address.toLowerCase().replace("0x", ""), 'hex'), (err, account) => {
var balance = '0x56BC75E2D63100000'
account.balance = balance || '0xf00000000000000001'
})
}
}
Accounts.prototype.methods = function () {
return {
eth_accounts: this.eth_accounts.bind(this)
eth_accounts: this.eth_accounts.bind(this),
eth_getBalance: this.eth_getBalance.bind(this)
}
}
@ -24,4 +30,16 @@ Accounts.prototype.eth_accounts = function (payload, cb) {
return cb(null, this.accounts.map((x) => x.address))
}
Accounts.prototype.eth_getBalance = function (payload, cb) {
let address = payload.params[0]
address = ethJSUtil.stripHexPrefix(address)
executionContext.vm().stateManager.getAccount(Buffer.from(address, 'hex'), function (err, account) {
if (err) {
return cb('Account not found')
}
cb(null, new BN(account.balance).toString(10))
})
}
module.exports = Accounts

Loading…
Cancel
Save