From f52aee83bc34c1c4ccfcd27e7b9f7818fa239e04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 4 Nov 2016 12:05:10 +0100 Subject: [PATCH 1/2] Exposing v,r,s from transaction signature in RPC (#3172) Former-commit-id: bb138aa03c05b3f19ef0633acc7ecc5212b21663 --- Cargo.lock | 10 +++++----- rpc/src/v1/tests/mocked/eth.rs | 2 +- rpc/src/v1/types/block.rs | 2 +- rpc/src/v1/types/transaction.rs | 16 +++++++++++++++- util/bigint/Cargo.toml | 2 +- util/bigint/src/hash.rs | 6 ++++++ 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe0be283c..d4f166029 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -312,7 +312,7 @@ dependencies = [ [[package]] name = "ethcore-bigint" -version = "0.1.1" +version = "0.1.2" dependencies = [ "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -549,7 +549,7 @@ dependencies = [ "elastic-array 0.6.0 (git+https://github.com/ethcore/elastic-array)", "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "eth-secp256k1 0.5.4 (git+https://github.com/ethcore/rust-secp256k1)", - "ethcore-bigint 0.1.1", + "ethcore-bigint 0.1.2", "ethcore-bloom-journal 0.1.0", "ethcore-devtools 1.4.0", "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -580,7 +580,7 @@ name = "ethcrypto" version = "0.1.0" dependencies = [ "eth-secp256k1 0.5.4 (git+https://github.com/ethcore/rust-secp256k1)", - "ethcore-bigint 0.1.1", + "ethcore-bigint 0.1.2", "ethkey 0.2.0", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -603,7 +603,7 @@ version = "0.2.0" dependencies = [ "docopt 0.6.80 (registry+https://github.com/rust-lang/crates.io-index)", "eth-secp256k1 0.5.4 (git+https://github.com/ethcore/rust-secp256k1)", - "ethcore-bigint 0.1.1", + "ethcore-bigint 0.1.2", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1463,7 +1463,7 @@ name = "rlp" version = "0.1.0" dependencies = [ "elastic-array 0.6.0 (git+https://github.com/ethcore/elastic-array)", - "ethcore-bigint 0.1.1", + "ethcore-bigint 0.1.2", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index 5bf79cee5..9092eb743 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -485,7 +485,7 @@ fn rpc_eth_pending_transaction_by_hash() { tester.miner.pending_transactions.lock().insert(H256::zero(), tx); } - let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"creates":null,"from":"0x0f65fe9276bc9a24ae7083ae28e2660ef72df99e","gas":"0x5208","gasPrice":"0x1","hash":"0x41df922fd0d4766fcc02e161f8295ec28522f329ae487f14d811e4b64c8d6e31","input":"0x","nonce":"0x0","publicKey":"0x7ae46da747962c2ee46825839c1ef9298e3bd2e70ca2938495c3693a485ec3eaa8f196327881090ff64cf4fbb0a48485d4f83098e189ed3b7a87d5941b59f789","raw":"0xf85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804","to":"0x095e7baea6a6c7c4c2dfeb977efac326af552d87","transactionIndex":null,"value":"0xa"},"id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"creates":null,"from":"0x0f65fe9276bc9a24ae7083ae28e2660ef72df99e","gas":"0x5208","gasPrice":"0x1","hash":"0x41df922fd0d4766fcc02e161f8295ec28522f329ae487f14d811e4b64c8d6e31","input":"0x","nonce":"0x0","publicKey":"0x7ae46da747962c2ee46825839c1ef9298e3bd2e70ca2938495c3693a485ec3eaa8f196327881090ff64cf4fbb0a48485d4f83098e189ed3b7a87d5941b59f789","r":"0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353","raw":"0xf85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804","s":"0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804","to":"0x095e7baea6a6c7c4c2dfeb977efac326af552d87","transactionIndex":null,"v":0,"value":"0xa"},"id":1}"#; let request = r#"{ "jsonrpc": "2.0", "method": "eth_getTransactionByHash", diff --git a/rpc/src/v1/types/block.rs b/rpc/src/v1/types/block.rs index dcf5d0d23..f52785e90 100644 --- a/rpc/src/v1/types/block.rs +++ b/rpc/src/v1/types/block.rs @@ -139,7 +139,7 @@ mod tests { fn test_serialize_block_transactions() { let t = BlockTransactions::Full(vec![Transaction::default()]); let serialized = serde_json::to_string(&t).unwrap(); - assert_eq!(serialized, r#"[{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x0","gasPrice":"0x0","gas":"0x0","input":"0x","creates":null,"raw":"0x","publicKey":null}]"#); + assert_eq!(serialized, r#"[{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x0","gasPrice":"0x0","gas":"0x0","input":"0x","creates":null,"raw":"0x","publicKey":null,"v":0,"r":"0x0000000000000000000000000000000000000000000000000000000000000000","s":"0x0000000000000000000000000000000000000000000000000000000000000000"}]"#); let t = BlockTransactions::Hashes(vec![H256::default().into()]); let serialized = serde_json::to_string(&t).unwrap(); diff --git a/rpc/src/v1/types/transaction.rs b/rpc/src/v1/types/transaction.rs index 6aa9ee899..0982a5ef9 100644 --- a/rpc/src/v1/types/transaction.rs +++ b/rpc/src/v1/types/transaction.rs @@ -54,10 +54,17 @@ pub struct Transaction { /// Public key of the signer. #[serde(rename="publicKey")] pub public_key: Option, + /// The V field of the signature. + pub v: u8, + /// The R field of the signature. + pub r: H256, + /// The S field of the signature. + pub s: H256, } impl From for Transaction { fn from(t: LocalizedTransaction) -> Transaction { + let signature = t.signature(); Transaction { hash: t.hash().into(), nonce: t.nonce.into(), @@ -79,12 +86,16 @@ impl From for Transaction { }, raw: ::rlp::encode(&t.signed).to_vec().into(), public_key: t.public_key().ok().map(Into::into), + v: signature.v(), + r: signature.r().into(), + s: signature.s().into(), } } } impl From for Transaction { fn from(t: SignedTransaction) -> Transaction { + let signature = t.signature(); Transaction { hash: t.hash().into(), nonce: t.nonce.into(), @@ -106,6 +117,9 @@ impl From for Transaction { }, raw: ::rlp::encode(&t).to_vec().into(), public_key: t.public_key().ok().map(Into::into), + v: signature.v(), + r: signature.r().into(), + s: signature.s().into(), } } } @@ -119,7 +133,7 @@ mod tests { fn test_transaction_serialize() { let t = Transaction::default(); let serialized = serde_json::to_string(&t).unwrap(); - assert_eq!(serialized, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x0","gasPrice":"0x0","gas":"0x0","input":"0x","creates":null,"raw":"0x","publicKey":null}"#); + assert_eq!(serialized, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x0","gasPrice":"0x0","gas":"0x0","input":"0x","creates":null,"raw":"0x","publicKey":null,"v":0,"r":"0x0000000000000000000000000000000000000000000000000000000000000000","s":"0x0000000000000000000000000000000000000000000000000000000000000000"}"#); } } diff --git a/util/bigint/Cargo.toml b/util/bigint/Cargo.toml index c21b5239f..3b6b852cb 100644 --- a/util/bigint/Cargo.toml +++ b/util/bigint/Cargo.toml @@ -4,7 +4,7 @@ homepage = "http://ethcore.io" repository = "https://github.com/ethcore/parity" license = "GPL-3.0" name = "ethcore-bigint" -version = "0.1.1" +version = "0.1.2" authors = ["Ethcore "] build = "build.rs" diff --git a/util/bigint/src/hash.rs b/util/bigint/src/hash.rs index f782d1f90..20cdbae03 100644 --- a/util/bigint/src/hash.rs +++ b/util/bigint/src/hash.rs @@ -386,6 +386,12 @@ macro_rules! impl_hash { } } } + + impl<'a> From<&'a [u8]> for $from { + fn from(s: &'a [u8]) -> $from { + $from::from_slice(s) + } + } } } From f264d10cc5a80e7721d4675b5f9349b83d775da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Fri, 4 Nov 2016 12:33:13 +0100 Subject: [PATCH 2/2] Exposing state root and logsBloom in RPC receipts (#3174) Former-commit-id: 6eeb7a3e5c8354ec9de4027a9d7668b8bf29f4a2 --- ethcore/src/client/client.rs | 4 +- ethcore/src/miner/miner.rs | 2 + ethcore/src/types/receipt.rs | 8 ++++ rpc/src/v1/tests/helpers/miner_service.rs | 2 + rpc/src/v1/tests/mocked/eth.rs | 6 ++- rpc/src/v1/types/receipt.rs | 53 ++++++++++++++--------- 6 files changed, 52 insertions(+), 23 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index a81dfd521..ec59e01cf 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -1050,7 +1050,9 @@ impl BlockChainClient for Client { transaction_hash: transaction_hash.clone(), transaction_index: transaction_index, log_index: i - }).collect() + }).collect(), + log_bloom: receipt.log_bloom, + state_root: receipt.state_root, }) }, _ => None diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 6ad85cb38..19a2b9a10 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -935,6 +935,8 @@ impl MinerService for Miner { } }, logs: receipt.logs.clone(), + log_bloom: receipt.log_bloom, + state_root: receipt.state_root, } }) } diff --git a/ethcore/src/types/receipt.rs b/ethcore/src/types/receipt.rs index 52e6747e8..deefeb383 100644 --- a/ethcore/src/types/receipt.rs +++ b/ethcore/src/types/receipt.rs @@ -93,6 +93,10 @@ pub struct RichReceipt { pub contract_address: Option
, /// Logs pub logs: Vec, + /// Logs bloom + pub log_bloom: LogBloom, + /// State root + pub state_root: H256, } /// Receipt with additional info. @@ -114,6 +118,10 @@ pub struct LocalizedReceipt { pub contract_address: Option
, /// Logs pub logs: Vec, + /// Logs bloom + pub log_bloom: LogBloom, + /// State root + pub state_root: H256, } #[test] diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index dcabba214..af158d564 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -209,6 +209,8 @@ impl MinerService for TestMinerService { gas_used: r.gas_used.clone(), contract_address: None, logs: r.logs.clone(), + log_bloom: r.log_bloom, + state_root: r.state_root, } ) } diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index 9092eb743..9f654e7e0 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -879,7 +879,9 @@ fn rpc_eth_transaction_receipt() { transaction_hash: H256::new(), transaction_index: 0, log_index: 1, - }] + }], + log_bloom: 0.into(), + state_root: 0.into(), }; let hash = H256::from_str("b903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238").unwrap(); @@ -892,7 +894,7 @@ fn rpc_eth_transaction_receipt() { "params": ["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"], "id": 1 }"#; - let response = r#"{"jsonrpc":"2.0","result":{"blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","contractAddress":null,"cumulativeGasUsed":"0x20","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","data":"0x","logIndex":"0x1","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","type":"mined"}],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0"},"id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":{"blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","contractAddress":null,"cumulativeGasUsed":"0x20","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","data":"0x","logIndex":"0x1","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","type":"mined"}],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0"},"id":1}"#; assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned())); } diff --git a/rpc/src/v1/types/receipt.rs b/rpc/src/v1/types/receipt.rs index 066195cbf..24170a14c 100644 --- a/rpc/src/v1/types/receipt.rs +++ b/rpc/src/v1/types/receipt.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use v1::types::{Log, H160, H256, U256}; +use v1::types::{Log, H160, H256, H2048, U256}; use ethcore::receipt::{Receipt as EthReceipt, RichReceipt, LocalizedReceipt}; /// Receipt @@ -43,6 +43,12 @@ pub struct Receipt { pub contract_address: Option, /// Logs pub logs: Vec, + /// State Root + #[serde(rename="root")] + pub state_root: H256, + /// Logs bloom + #[serde(rename="logsBloom")] + pub logs_bloom: H2048, } impl From for Receipt { @@ -56,6 +62,8 @@ impl From for Receipt { gas_used: Some(r.gas_used.into()), contract_address: r.contract_address.map(Into::into), logs: r.logs.into_iter().map(Into::into).collect(), + state_root: r.state_root.into(), + logs_bloom: r.log_bloom.into(), } } } @@ -71,6 +79,8 @@ impl From for Receipt { gas_used: Some(r.gas_used.into()), contract_address: r.contract_address.map(Into::into), logs: r.logs.into_iter().map(Into::into).collect(), + state_root: r.state_root.into(), + logs_bloom: r.log_bloom.into(), } } } @@ -86,6 +96,8 @@ impl From for Receipt { gas_used: None, contract_address: None, logs: r.logs.into_iter().map(Into::into).collect(), + state_root: r.state_root.into(), + logs_bloom: r.log_bloom.into(), } } } @@ -93,35 +105,36 @@ impl From for Receipt { #[cfg(test)] mod tests { use serde_json; - use std::str::FromStr; - use v1::types::{Log, Receipt, U256, H256, H160}; + use v1::types::{Log, Receipt}; #[test] fn receipt_serialization() { - let s = r#"{"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","cumulativeGasUsed":"0x20","gasUsed":"0x10","contractAddress":null,"logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"data":"0x","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","logIndex":"0x1","type":"mined"}]}"#; + let s = r#"{"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","cumulativeGasUsed":"0x20","gasUsed":"0x10","contractAddress":null,"logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"data":"0x","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","logIndex":"0x1","type":"mined"}],"root":"0x000000000000000000000000000000000000000000000000000000000000000a","logsBloom":"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f"}"#; let receipt = Receipt { - transaction_hash: Some(H256::from(0)), - transaction_index: Some(U256::from(0)), - block_hash: Some(H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap()), - block_number: Some(U256::from(0x4510c)), - cumulative_gas_used: U256::from(0x20), - gas_used: Some(U256::from(0x10)), + transaction_hash: Some(0.into()), + transaction_index: Some(0.into()), + block_hash: Some("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5".parse().unwrap()), + block_number: Some(0x4510c.into()), + cumulative_gas_used: 0x20.into(), + gas_used: Some(0x10.into()), contract_address: None, logs: vec![Log { - address: H160::from_str("33990122638b9132ca29c723bdf037f1a891a70c").unwrap(), + address: "33990122638b9132ca29c723bdf037f1a891a70c".parse().unwrap(), topics: vec![ - H256::from_str("a6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc").unwrap(), - H256::from_str("4861736852656700000000000000000000000000000000000000000000000000").unwrap(), + "a6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc".parse().unwrap(), + "4861736852656700000000000000000000000000000000000000000000000000".parse().unwrap(), ], data: vec![].into(), - block_hash: Some(H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap()), - block_number: Some(U256::from(0x4510c)), - transaction_hash: Some(H256::default()), - transaction_index: Some(U256::default()), - log_index: Some(U256::from(1)), - log_type: "mined".to_owned(), - }] + block_hash: Some("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5".parse().unwrap()), + block_number: Some(0x4510c.into()), + transaction_hash: Some(0.into()), + transaction_index: Some(0.into()), + log_index: Some(1.into()), + log_type: "mined".into(), + }], + logs_bloom: 15.into(), + state_root: 10.into(), }; let serialized = serde_json::to_string(&receipt).unwrap();