Fix postsign (#4347)
* Fix whitespace. * Fix post sign. * Fix message. * Fix tests. * Rest of the problems. * All hail the linter and its omniscience. * ...and its divine omniscience. * Grumbles and wording.
This commit is contained in:
@@ -19,6 +19,7 @@ use std::ops::Deref;
|
||||
use rlp;
|
||||
use util::{Address, H256, U256, Uint, Bytes};
|
||||
use util::bytes::ToPretty;
|
||||
use util::sha3::Hashable;
|
||||
|
||||
use ethkey::Signature;
|
||||
use ethcore::miner::MinerService;
|
||||
@@ -108,8 +109,8 @@ pub fn execute<C, M>(client: &C, miner: &M, accounts: &AccountProvider, payload:
|
||||
.map(ConfirmationResponse::SignTransaction)
|
||||
)
|
||||
},
|
||||
ConfirmationPayload::Signature(address, hash) => {
|
||||
signature(accounts, address, hash, pass)
|
||||
ConfirmationPayload::Signature(address, data) => {
|
||||
signature(accounts, address, data.sha3(), pass)
|
||||
.map(|result| result
|
||||
.map(RpcH520::from)
|
||||
.map(ConfirmationResponse::Signature)
|
||||
@@ -243,8 +244,8 @@ pub fn from_rpc<C, M>(payload: RpcConfirmationPayload, client: &C, miner: &M) ->
|
||||
RpcConfirmationPayload::Decrypt(RpcDecryptRequest { address, msg }) => {
|
||||
ConfirmationPayload::Decrypt(address.into(), msg.into())
|
||||
},
|
||||
RpcConfirmationPayload::Signature(RpcSignRequest { address, hash }) => {
|
||||
ConfirmationPayload::Signature(address.into(), hash.into())
|
||||
RpcConfirmationPayload::Signature(RpcSignRequest { address, data }) => {
|
||||
ConfirmationPayload::Signature(address.into(), data.into())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use util::{Address, U256, Bytes, H256};
|
||||
use util::{Address, U256, Bytes};
|
||||
|
||||
/// Transaction request coming from RPC
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash)]
|
||||
@@ -109,7 +109,7 @@ pub enum ConfirmationPayload {
|
||||
/// Sign Transaction
|
||||
SignTransaction(FilledTransactionRequest),
|
||||
/// Sign request
|
||||
Signature(Address, H256),
|
||||
Signature(Address, Bytes),
|
||||
/// Decrypt request
|
||||
Decrypt(Address, Bytes),
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use std::sync::{Arc, Weak};
|
||||
use transient_hashmap::TransientHashMap;
|
||||
use util::{U256, Mutex, Hashable};
|
||||
use util::{U256, Mutex};
|
||||
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use ethcore::miner::MinerService;
|
||||
@@ -122,9 +122,9 @@ impl<C: 'static, M: 'static> ParitySigning for SigningQueueClient<C, M> where
|
||||
C: MiningBlockChainClient,
|
||||
M: MinerService,
|
||||
{
|
||||
fn post_sign(&self, address: RpcH160, hash: RpcH256) -> Result<RpcEither<RpcU256, RpcConfirmationResponse>, Error> {
|
||||
fn post_sign(&self, address: RpcH160, data: RpcBytes) -> Result<RpcEither<RpcU256, RpcConfirmationResponse>, Error> {
|
||||
self.active()?;
|
||||
self.dispatch(RpcConfirmationPayload::Signature((address, hash).into()))
|
||||
self.dispatch(RpcConfirmationPayload::Signature((address, data).into()))
|
||||
.map(|result| match result {
|
||||
DispatchResult::Value(v) => RpcEither::Or(v),
|
||||
DispatchResult::Promise(promise) => {
|
||||
@@ -187,8 +187,7 @@ impl<C: 'static, M: 'static> EthSigning for SigningQueueClient<C, M> where
|
||||
M: MinerService,
|
||||
{
|
||||
fn sign(&self, address: RpcH160, data: RpcBytes) -> BoxFuture<RpcH520, Error> {
|
||||
let hash = data.0.sha3().into();
|
||||
let res = self.active().and_then(|_| self.dispatch(RpcConfirmationPayload::Signature((address, hash).into())));
|
||||
let res = self.active().and_then(|_| self.dispatch(RpcConfirmationPayload::Signature((address, data).into())));
|
||||
|
||||
let (ready, p) = futures::oneshot();
|
||||
self.handle_dispatch(res, |response| {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
//! Unsafe Signing RPC implementation.
|
||||
|
||||
use std::sync::{Arc, Weak};
|
||||
use util::Hashable;
|
||||
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use ethcore::miner::MinerService;
|
||||
@@ -86,8 +85,7 @@ impl<C: 'static, M: 'static> EthSigning for SigningUnsafeClient<C, M> where
|
||||
M: MinerService,
|
||||
{
|
||||
fn sign(&self, address: RpcH160, data: RpcBytes) -> BoxFuture<RpcH520, Error> {
|
||||
let hash = data.0.sha3().into();
|
||||
let result = match self.handle(RpcConfirmationPayload::Signature((address, hash).into())) {
|
||||
let result = match self.handle(RpcConfirmationPayload::Signature((address, data).into())) {
|
||||
Ok(RpcConfirmationResponse::Signature(signature)) => Ok(signature),
|
||||
Err(e) => Err(e),
|
||||
e => Err(errors::internal("Unexpected result", e)),
|
||||
@@ -131,7 +129,7 @@ impl<C: 'static, M: 'static> ParitySigning for SigningUnsafeClient<C, M> where
|
||||
futures::done(result).boxed()
|
||||
}
|
||||
|
||||
fn post_sign(&self, _: RpcH160, _: RpcH256) -> Result<RpcEither<RpcU256, RpcConfirmationResponse>, Error> {
|
||||
fn post_sign(&self, _: RpcH160, _: RpcBytes) -> Result<RpcEither<RpcU256, RpcConfirmationResponse>, Error> {
|
||||
// We don't support this in non-signer mode.
|
||||
Err(errors::signer_disabled())
|
||||
}
|
||||
|
||||
@@ -85,14 +85,14 @@ fn should_return_list_of_items_to_confirm() {
|
||||
nonce: None,
|
||||
min_block: None,
|
||||
})).unwrap();
|
||||
tester.signer.add_request(ConfirmationPayload::Signature(1.into(), 5.into())).unwrap();
|
||||
tester.signer.add_request(ConfirmationPayload::Signature(1.into(), vec![5].into())).unwrap();
|
||||
|
||||
// when
|
||||
let request = r#"{"jsonrpc":"2.0","method":"signer_requestsToConfirm","params":[],"id":1}"#;
|
||||
let response = concat!(
|
||||
r#"{"jsonrpc":"2.0","result":["#,
|
||||
r#"{"id":"0x1","payload":{"sendTransaction":{"data":"0x","from":"0x0000000000000000000000000000000000000001","gas":"0x989680","gasPrice":"0x2710","minBlock":null,"nonce":null,"to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","value":"0x1"}}},"#,
|
||||
r#"{"id":"0x2","payload":{"sign":{"address":"0x0000000000000000000000000000000000000001","hash":"0x0000000000000000000000000000000000000000000000000000000000000005"}}}"#,
|
||||
r#"{"id":"0x2","payload":{"sign":{"address":"0x0000000000000000000000000000000000000001","data":"0x05"}}}"#,
|
||||
r#"],"id":1}"#
|
||||
);
|
||||
|
||||
@@ -156,7 +156,7 @@ fn should_not_remove_transaction_if_password_is_invalid() {
|
||||
fn should_not_remove_sign_if_password_is_invalid() {
|
||||
// given
|
||||
let tester = signer_tester();
|
||||
tester.signer.add_request(ConfirmationPayload::Signature(0.into(), 5.into())).unwrap();
|
||||
tester.signer.add_request(ConfirmationPayload::Signature(0.into(), vec![5].into())).unwrap();
|
||||
assert_eq!(tester.signer.requests().len(), 1);
|
||||
|
||||
// when
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
use jsonrpc_core::Error;
|
||||
use futures::BoxFuture;
|
||||
|
||||
use v1::types::{U256, H160, H256, Bytes, ConfirmationResponse, TransactionRequest, Either};
|
||||
use v1::types::{U256, H160, Bytes, ConfirmationResponse, TransactionRequest, Either};
|
||||
|
||||
build_rpc_trait! {
|
||||
/// Signing methods implementation.
|
||||
@@ -26,7 +26,7 @@ build_rpc_trait! {
|
||||
/// Posts sign request asynchronously.
|
||||
/// Will return a confirmation ID for later use with check_transaction.
|
||||
#[rpc(name = "parity_postSign")]
|
||||
fn post_sign(&self, H160, H256) -> Result<Either<U256, ConfirmationResponse>, Error>;
|
||||
fn post_sign(&self, H160, Bytes) -> Result<Either<U256, ConfirmationResponse>, Error>;
|
||||
|
||||
/// Posts transaction asynchronously.
|
||||
/// Will return a transaction ID for later use with check_transaction.
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
use std::fmt;
|
||||
use serde::{Serialize, Serializer};
|
||||
use util::log::Colour;
|
||||
use util::bytes::ToPretty;
|
||||
|
||||
use v1::types::{U256, TransactionRequest, RichRawTransaction, H160, H256, H520, Bytes, BlockNumber};
|
||||
use v1::helpers;
|
||||
@@ -64,14 +65,14 @@ pub struct SignRequest {
|
||||
/// Address
|
||||
pub address: H160,
|
||||
/// Hash to sign
|
||||
pub hash: H256,
|
||||
pub data: Bytes,
|
||||
}
|
||||
|
||||
impl From<(H160, H256)> for SignRequest {
|
||||
fn from(tuple: (H160, H256)) -> Self {
|
||||
impl From<(H160, Bytes)> for SignRequest {
|
||||
fn from(tuple: (H160, Bytes)) -> Self {
|
||||
SignRequest {
|
||||
address: tuple.0,
|
||||
hash: tuple.1,
|
||||
data: tuple.1,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,8 +81,8 @@ impl fmt::Display for SignRequest {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"sign 0x{:?} with {}",
|
||||
self.hash,
|
||||
"sign 0x{} with {}",
|
||||
self.data.0.pretty(),
|
||||
Colour::White.bold().paint(format!("0x{:?}", self.address)),
|
||||
)
|
||||
}
|
||||
@@ -172,9 +173,9 @@ impl From<helpers::ConfirmationPayload> for ConfirmationPayload {
|
||||
match c {
|
||||
helpers::ConfirmationPayload::SendTransaction(t) => ConfirmationPayload::SendTransaction(t.into()),
|
||||
helpers::ConfirmationPayload::SignTransaction(t) => ConfirmationPayload::SignTransaction(t.into()),
|
||||
helpers::ConfirmationPayload::Signature(address, hash) => ConfirmationPayload::Signature(SignRequest {
|
||||
helpers::ConfirmationPayload::Signature(address, data) => ConfirmationPayload::Signature(SignRequest {
|
||||
address: address.into(),
|
||||
hash: hash.into(),
|
||||
data: data.into(),
|
||||
}),
|
||||
helpers::ConfirmationPayload::Decrypt(address, msg) => ConfirmationPayload::Decrypt(DecryptRequest {
|
||||
address: address.into(),
|
||||
@@ -248,12 +249,12 @@ mod tests {
|
||||
// given
|
||||
let request = helpers::ConfirmationRequest {
|
||||
id: 15.into(),
|
||||
payload: helpers::ConfirmationPayload::Signature(1.into(), 5.into()),
|
||||
payload: helpers::ConfirmationPayload::Signature(1.into(), vec![5].into()),
|
||||
};
|
||||
|
||||
// when
|
||||
let res = serde_json::to_string(&ConfirmationRequest::from(request));
|
||||
let expected = r#"{"id":"0xf","payload":{"sign":{"address":"0x0000000000000000000000000000000000000001","hash":"0x0000000000000000000000000000000000000000000000000000000000000005"}}}"#;
|
||||
let expected = r#"{"id":"0xf","payload":{"sign":{"address":"0x0000000000000000000000000000000000000001","data":"0x05"}}}"#;
|
||||
|
||||
// then
|
||||
assert_eq!(res.unwrap(), expected.to_owned());
|
||||
|
||||
Reference in New Issue
Block a user