add eth_sign & eth_getCompilers

pull/5370/head
Iuri Matias 6 years ago
parent f604436155
commit f68cb51d1a
  1. 20
      remix-simulator/README.md
  2. 20
      remix-simulator/src/methods/accounts.js
  3. 7
      remix-simulator/src/methods/misc.js

@ -23,7 +23,7 @@ Implemented:
* [_] eth_getUncleCountByBlockHash
* [_] eth_getUncleCountByBlockNumber
* [~] eth_getCode
* [_] eth_sign
* [~] eth_sign
* [X] eth_sendTransaction
* [_] eth_sendRawTransaction
* [X] eth_call
@ -36,7 +36,7 @@ Implemented:
* [~] eth_getTransactionReceipt
* [_] eth_getUncleByBlockHashAndIndex
* [_] eth_getUncleByBlockNumberAndIndex
* [_] eth_getCompilers (DEPRECATED)
* [X] eth_getCompilers (DEPRECATED)
* [_] eth_compileSolidity (DEPRECATED)
* [_] eth_compileLLL (DEPRECATED)
* [_] eth_compileSerpent (DEPRECATED)
@ -65,4 +65,20 @@ Implemented:
* [_] shh_uninstallFilter
* [_] shh_getFilterChanges
* [_] shh_getMessages
* [_] bzz_hive (stub)
* [_] bzz_info (stub)
* [_] debug_traceTransaction
* [_] eth_subscribe
* [_] eth_unsubscribe
* [_] miner_start
* [_] miner_stop
* [_] personal_listAccounts
* [_] personal_lockAccount
* [_] personal_newAccount
* [_] personal_importRawKey
* [_] personal_unlockAccount
* [_] personal_sendTransaction
* [_] rpc_modules
* [_] web3_clientVersion
* [_] web3_sha3

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

@ -11,7 +11,8 @@ Misc.prototype.methods = function () {
eth_syncing: this.eth_syncing.bind(this),
eth_mining: this.eth_mining.bind(this),
eth_hashrate: this.eth_hashrate.bind(this),
web3_sha3: this.web3_sha3.bind(this)
web3_sha3: this.web3_sha3.bind(this),
eth_getCompilers: this.eth_getCompilers.bind(this)
}
}
@ -41,4 +42,8 @@ Misc.prototype.web3_sha3 = function (payload, cb) {
cb(null, web3.utils.sha3(str))
}
Misc.prototype.eth_getCompilers = function (payload, cb) {
cb(null, [])
}
module.exports = Misc

Loading…
Cancel
Save