|
|
|
@ -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 |
|
|
|
|