implement eth_sign

This commit is contained in:
Robert Habermeier 2016-05-29 15:46:57 +02:00
parent 7cea3eb5ed
commit be1ec93271
3 changed files with 30 additions and 18 deletions

View File

@ -27,6 +27,7 @@ use jsonrpc_core::*;
use util::numbers::*;
use util::sha3::*;
use util::rlp::{encode, decode, UntrustedRlp, View};
use util::keys::store::AccountProvider;
use ethcore::client::{BlockChainClient, BlockID, TransactionID, UncleID};
use ethcore::block::IsBlock;
use ethcore::views::*;
@ -39,7 +40,6 @@ use v1::traits::{Eth, EthFilter};
use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, TransactionRequest, CallRequest, OptionalValue, Index, Filter, Log, Receipt};
use v1::helpers::{PollFilter, PollManager};
use v1::impls::{dispatch_transaction, sign_and_dispatch};
use util::keys::store::AccountProvider;
use serde;
/// Eth rpc implementation.
@ -495,12 +495,8 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM> where
}
fn sign(&self, params: Params) -> Result<Value, Error> {
from_params::<(Address, Bytes)>(params).and_then(|(addr, data)| {
let accounts = take_weak!(self.accounts);
match accounts.account_secret(&addr) {
Ok(secret) => rpc_unimplemented!(),
Err(_) => rpc_unimplemented!(),
}
from_params::<(Address, H256)>(params).and_then(|(addr, msg)| {
to_value(&take_weak!(self.accounts).sign(&addr, &msg).unwrap_or(H520::zero()))
})
}
@ -553,15 +549,15 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM> where
})
}
fn compile_lll(&self, _: params) -> Result<Value, Error> {
fn compile_lll(&self, _: Params) -> Result<Value, Error> {
rpc_unimplemented!()
}
fn compile_serpent(&self, _: params) -> Result<Value, Error> {
fn compile_serpent(&self, _: Params) -> Result<Value, Error> {
rpc_unimplemented!()
}
fn compile_solidity(&self, _: params) -> Result<Value, Error> {
fn compile_solidity(&self, _: Params) -> Result<Value, Error> {
rpc_unimplemented!()
}
}

View File

@ -27,7 +27,7 @@ use ethcore::transaction::{Transaction, Action};
use ethminer::{MinerService, ExternalMiner};
use devtools::RandomTempPath;
use util::io::IoChannel;
use util::hash::{Address, FixedHash};
use util::hash::Address;
use util::numbers::{Uint, U256};
use util::keys::{AccountProvider, TestAccount, TestAccountProvider};
use jsonrpc_core::IoHandler;

View File

@ -20,7 +20,7 @@ use std::sync::{Arc, RwLock};
use jsonrpc_core::IoHandler;
use util::hash::{Address, H256, FixedHash};
use util::numbers::{Uint, U256};
use util::keys::{TestAccount, TestAccountProvider};
use util::keys::{AccountProvider, TestAccount, TestAccountProvider};
use ethcore::client::{TestBlockChainClient, EachBlockWith, Executed, TransactionID};
use ethcore::log_entry::{LocalizedLogEntry, LogEntry};
use ethcore::receipt::LocalizedReceipt;
@ -129,6 +129,28 @@ fn rpc_eth_submit_hashrate() {
Some(U256::from(0x500_000)));
}
#[test]
fn rpc_eth_sign() {
let tester = EthTester::default();
let account = tester.accounts_provider.new_account("abcd").unwrap();
let message = H256::from("0x0cc175b9c0f1b6a831c399e26977266192eb5ffee6ae2fec3ad71c777531578f");
let signed = tester.accounts_provider.sign(&account, &message).unwrap();
let req = r#"{
"jsonrpc": "2.0",
"method": "eth_sign",
"params": [
""#.to_owned() + &format!("0x{:?}", account) + r#"",
"0x0cc175b9c0f1b6a831c399e26977266192eb5ffee6ae2fec3ad71c777531578f"
],
"id": 1
}"#;
let res = r#"{"jsonrpc":"2.0","result":""#.to_owned() + &format!("0x{:?}", signed) + r#"","id":1}"#;
assert_eq!(tester.io.handle_request(&req), Some(res));
}
#[test]
#[ignore]
fn rpc_eth_author() {
@ -527,12 +549,6 @@ fn rpc_eth_send_raw_transaction() {
unimplemented!()
}
#[test]
#[ignore]
fn rpc_eth_sign() {
unimplemented!()
}
#[test]
fn rpc_eth_transaction_receipt() {
let receipt = LocalizedReceipt {