|
|
|
@ -8,10 +8,13 @@ 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.accountsKeys = {} |
|
|
|
|
|
|
|
|
|
executionContext.init({get: () => { return true }}) |
|
|
|
|
|
|
|
|
|
for (let _account of this.accounts) { |
|
|
|
|
this.accountsKeys[_account.address.toLowerCase()] = _account.privateKey |
|
|
|
|
|
|
|
|
|
executionContext.vm().stateManager.getAccount(Buffer.from(_account.address.toLowerCase().replace("0x", ""), 'hex'), (err, account) => { |
|
|
|
|
var balance = '0x56BC75E2D63100000' |
|
|
|
|
account.balance = balance || '0xf00000000000000001' |
|
|
|
@ -22,7 +25,8 @@ var Accounts = function () { |
|
|
|
|
Accounts.prototype.methods = function () { |
|
|
|
|
return { |
|
|
|
|
eth_accounts: this.eth_accounts.bind(this), |
|
|
|
|
eth_getBalance: this.eth_getBalance.bind(this) |
|
|
|
|
eth_getBalance: this.eth_getBalance.bind(this), |
|
|
|
|
eth_sign: this.eth_sign.bind(this) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -34,7 +38,7 @@ 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) { |
|
|
|
|
executionContext.vm().stateManager.getAccount(Buffer.from(address, 'hex'), (err, account) => { |
|
|
|
|
if (err) { |
|
|
|
|
return cb('Account not found') |
|
|
|
|
} |
|
|
|
@ -42,4 +46,16 @@ Accounts.prototype.eth_getBalance = function (payload, cb) { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Accounts.prototype.eth_sign = function (payload, cb) { |
|
|
|
|
let address = payload.params[0] |
|
|
|
|
let message = payload.params[1] |
|
|
|
|
|
|
|
|
|
let privateKey = this.accountsKeys[address] |
|
|
|
|
let account = web3.eth.accounts.privateKeyToAccount(privateKey) |
|
|
|
|
|
|
|
|
|
let data = account.sign(message) |
|
|
|
|
|
|
|
|
|
cb(null, data.signature) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
module.exports = Accounts |
|
|
|
|