Commit 13a65fab authored by Iuri Matias's avatar Iuri Matias

add eth_sign & eth_getCompilers

parent c3a5040f
...@@ -23,7 +23,7 @@ Implemented: ...@@ -23,7 +23,7 @@ Implemented:
* [_] eth_getUncleCountByBlockHash * [_] eth_getUncleCountByBlockHash
* [_] eth_getUncleCountByBlockNumber * [_] eth_getUncleCountByBlockNumber
* [~] eth_getCode * [~] eth_getCode
* [_] eth_sign * [~] eth_sign
* [X] eth_sendTransaction * [X] eth_sendTransaction
* [_] eth_sendRawTransaction * [_] eth_sendRawTransaction
* [X] eth_call * [X] eth_call
...@@ -36,7 +36,7 @@ Implemented: ...@@ -36,7 +36,7 @@ Implemented:
* [~] eth_getTransactionReceipt * [~] eth_getTransactionReceipt
* [_] eth_getUncleByBlockHashAndIndex * [_] eth_getUncleByBlockHashAndIndex
* [_] eth_getUncleByBlockNumberAndIndex * [_] eth_getUncleByBlockNumberAndIndex
* [_] eth_getCompilers (DEPRECATED) * [X] eth_getCompilers (DEPRECATED)
* [_] eth_compileSolidity (DEPRECATED) * [_] eth_compileSolidity (DEPRECATED)
* [_] eth_compileLLL (DEPRECATED) * [_] eth_compileLLL (DEPRECATED)
* [_] eth_compileSerpent (DEPRECATED) * [_] eth_compileSerpent (DEPRECATED)
...@@ -65,4 +65,20 @@ Implemented: ...@@ -65,4 +65,20 @@ Implemented:
* [_] shh_uninstallFilter * [_] shh_uninstallFilter
* [_] shh_getFilterChanges * [_] shh_getFilterChanges
* [_] shh_getMessages * [_] 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 () { ...@@ -8,10 +8,13 @@ var Accounts = function () {
this.web3 = new Web3() this.web3 = new Web3()
// TODO: make it random and/or use remix-libs // 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.web3.eth.accounts.create(['abcd']), this.web3.eth.accounts.create(['ef12']), this.web3.eth.accounts.create(['ef34'])]
this.accountsKeys = {}
executionContext.init({get: () => { return true }}) executionContext.init({get: () => { return true }})
for (let _account of this.accounts) { 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) => { executionContext.vm().stateManager.getAccount(Buffer.from(_account.address.toLowerCase().replace("0x", ""), 'hex'), (err, account) => {
var balance = '0x56BC75E2D63100000' var balance = '0x56BC75E2D63100000'
account.balance = balance || '0xf00000000000000001' account.balance = balance || '0xf00000000000000001'
...@@ -22,7 +25,8 @@ var Accounts = function () { ...@@ -22,7 +25,8 @@ var Accounts = function () {
Accounts.prototype.methods = function () { Accounts.prototype.methods = function () {
return { return {
eth_accounts: this.eth_accounts.bind(this), 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) { ...@@ -34,7 +38,7 @@ Accounts.prototype.eth_getBalance = function (payload, cb) {
let address = payload.params[0] let address = payload.params[0]
address = ethJSUtil.stripHexPrefix(address) 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) { if (err) {
return cb('Account not found') return cb('Account not found')
} }
...@@ -42,4 +46,16 @@ Accounts.prototype.eth_getBalance = function (payload, cb) { ...@@ -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 module.exports = Accounts
...@@ -11,7 +11,8 @@ Misc.prototype.methods = function () { ...@@ -11,7 +11,8 @@ Misc.prototype.methods = function () {
eth_syncing: this.eth_syncing.bind(this), eth_syncing: this.eth_syncing.bind(this),
eth_mining: this.eth_mining.bind(this), eth_mining: this.eth_mining.bind(this),
eth_hashrate: this.eth_hashrate.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) { ...@@ -41,4 +42,8 @@ Misc.prototype.web3_sha3 = function (payload, cb) {
cb(null, web3.utils.sha3(str)) cb(null, web3.utils.sha3(str))
} }
Misc.prototype.eth_getCompilers = function (payload, cb) {
cb(null, [])
}
module.exports = Misc module.exports = Misc
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment