From 6b4e56b214ed5468cf1ba4fcd84dfbf54bba4412 Mon Sep 17 00:00:00 2001 From: rakita Date: Mon, 8 Feb 2021 14:55:03 +0100 Subject: [PATCH] AccessList in JSONRPC. And enabling github action tests (#255) * Enabling github action tests * Fix failing tests * AccessList to Option in json * failing rust example removed * AccessList for jsonrpc * Tx type as sequence, AccessList as type --- .github/workflows/build-test.yml | 5 +++ .../types/src/transaction/transaction.rs | 3 +- .../types/src/transaction/transaction_id.rs | 10 ++++++ .../types/src/views/typed_transaction.rs | 14 -------- crates/ethjson/src/blockchain/transaction.rs | 6 ++-- crates/rpc/src/v1/helpers/dispatch/signing.rs | 14 +++++--- crates/rpc/src/v1/helpers/fake_sign.rs | 25 +++++++++---- crates/rpc/src/v1/helpers/requests.rs | 13 ++++--- crates/rpc/src/v1/tests/mocked/eth.rs | 6 ++-- crates/rpc/src/v1/tests/mocked/parity.rs | 2 +- crates/rpc/src/v1/tests/mocked/parity_set.rs | 2 +- crates/rpc/src/v1/tests/mocked/signer.rs | 4 +-- crates/rpc/src/v1/tests/mocked/signing.rs | 4 +-- .../rpc/src/v1/tests/mocked/signing_unsafe.rs | 2 +- crates/rpc/src/v1/types/block.rs | 2 +- crates/rpc/src/v1/types/call_request.rs | 13 ++++--- crates/rpc/src/v1/types/confirmations.rs | 4 +-- crates/rpc/src/v1/types/mod.rs | 2 ++ crates/rpc/src/v1/types/receipt.rs | 15 ++++---- crates/rpc/src/v1/types/transaction.rs | 31 +++++++++------- .../src/v1/types/transaction_access_list.rs | 36 +++++++++++++++++++ .../rpc/src/v1/types/transaction_request.rs | 12 +++---- 22 files changed, 144 insertions(+), 81 deletions(-) create mode 100644 crates/rpc/src/v1/types/transaction_access_list.rs diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 6410be554..344591c0a 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -33,3 +33,8 @@ jobs: with: command: test args: --locked --all --release --features "json-tests" --verbose --no-run + - name: Run tests for ${{ matrix.platform }} + uses: actions-rs/cargo@v1 + with: + command: test + args: --locked --all --release --features "json-tests" --verbose diff --git a/crates/ethcore/types/src/transaction/transaction.rs b/crates/ethcore/types/src/transaction/transaction.rs index bf760eb77..230d469f2 100644 --- a/crates/ethcore/types/src/transaction/transaction.rs +++ b/crates/ethcore/types/src/transaction/transaction.rs @@ -24,7 +24,8 @@ use heapsize::HeapSizeOf; use rlp::{self, DecoderError, Rlp, RlpStream}; use std::{convert::TryInto, ops::Deref}; -pub type AccessList = Vec<(H160, Vec)>; +pub type AccessListItem = (H160, Vec); +pub type AccessList = Vec; use super::TypedTxId; diff --git a/crates/ethcore/types/src/transaction/transaction_id.rs b/crates/ethcore/types/src/transaction/transaction_id.rs index 2b5b5ae2b..cb31d1937 100644 --- a/crates/ethcore/types/src/transaction/transaction_id.rs +++ b/crates/ethcore/types/src/transaction/transaction_id.rs @@ -16,6 +16,7 @@ //! Transaction Id. +use ethereum_types::U64; use serde_repr::*; use std::convert::TryFrom; @@ -34,6 +35,15 @@ impl TypedTxId { _ => None, } } + + #[allow(non_snake_case)] + pub fn from_U64_id(n: &U64) -> Option { + match n.0[0] { + 0x0 => Some(Self::Legacy), + 0x1 => Some(Self::AccessList), + _ => None, + } + } } impl Default for TypedTxId { diff --git a/crates/ethcore/types/src/views/typed_transaction.rs b/crates/ethcore/types/src/views/typed_transaction.rs index 3a504c117..c74d91bc0 100644 --- a/crates/ethcore/types/src/views/typed_transaction.rs +++ b/crates/ethcore/types/src/views/typed_transaction.rs @@ -38,20 +38,6 @@ pub struct TypedTransactionView<'a> { impl<'a> TypedTransactionView<'a> { /// Creates new view onto valid transaction rlp. /// Use the `view!` macro to create this view in order to capture debugging info. - /// - /// # Example - /// - /// ``` - /// #[macro_use] - /// extern crate common_types as types; - /// - /// use types::views::{TransactionView}; - /// - /// fn main() { - /// let bytes : &[u8] = &[]; - /// let tx_view = view!(TransactionView, bytes); - /// } - /// ``` pub fn new(rlp: ViewRlp<'a>) -> TypedTransactionView<'a> { let transaction_type = Self::extract_transaction_type(&rlp.rlp); TypedTransactionView { diff --git a/crates/ethjson/src/blockchain/transaction.rs b/crates/ethjson/src/blockchain/transaction.rs index 8f89de1b5..003beb306 100644 --- a/crates/ethjson/src/blockchain/transaction.rs +++ b/crates/ethjson/src/blockchain/transaction.rs @@ -35,13 +35,15 @@ pub struct Transaction { pub v: Uint, pub value: Uint, pub chain_id: Option, - pub access_list: Option>, + pub access_list: Option, pub hash: Option, } +pub type AccessList = Vec; + #[derive(Debug, PartialEq, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct AccessList { +pub struct AccessListItem { pub address: H160, pub storage_keys: Vec, } diff --git a/crates/rpc/src/v1/helpers/dispatch/signing.rs b/crates/rpc/src/v1/helpers/dispatch/signing.rs index 5cc8f9357..0514d85ab 100644 --- a/crates/rpc/src/v1/helpers/dispatch/signing.rs +++ b/crates/rpc/src/v1/helpers/dispatch/signing.rs @@ -59,17 +59,23 @@ impl super::Accounts for Signer { value: filled.value, data: filled.data, }; - let t = match filled.transaction_type { - TypedTxId::Legacy => TypedTransaction::Legacy(legacy_tx), - TypedTxId::AccessList => { + let t = match TypedTxId::from_U64_id(&filled.transaction_type) { + Some(TypedTxId::Legacy) => TypedTransaction::Legacy(legacy_tx), + Some(TypedTxId::AccessList) => { if filled.access_list.is_none() { return Err(Error::new(ErrorCode::InvalidParams)); } TypedTransaction::AccessList(AccessListTx::new( legacy_tx, - filled.access_list.unwrap(), + filled + .access_list + .unwrap_or_default() + .into_iter() + .map(Into::into) + .collect(), )) } + None => return Err(Error::new(ErrorCode::InvalidParams)), }; let hash = t.signature_hash(chain_id); diff --git a/crates/rpc/src/v1/helpers/fake_sign.rs b/crates/rpc/src/v1/helpers/fake_sign.rs index 21cedad1e..1948752d4 100644 --- a/crates/rpc/src/v1/helpers/fake_sign.rs +++ b/crates/rpc/src/v1/helpers/fake_sign.rs @@ -20,7 +20,7 @@ use types::transaction::{ }; use ethereum_types::U256; -use jsonrpc_core::Error; +use jsonrpc_core::{Error, ErrorCode}; use v1::helpers::CallRequest; pub fn sign_call(request: CallRequest) -> Result { @@ -35,12 +35,23 @@ pub fn sign_call(request: CallRequest) -> Result { value: request.value.unwrap_or_default(), data: request.data.unwrap_or_default(), }; - let tx_typed = match request.transaction_type { - TypedTxId::Legacy => TypedTransaction::Legacy(tx_legacy), - TypedTxId::AccessList => TypedTransaction::AccessList(AccessListTx::new( - tx_legacy, - request.access_list.unwrap_or_default(), - )), + let tx_typed = match TypedTxId::from_U64_id(&request.transaction_type) { + Some(TypedTxId::Legacy) => TypedTransaction::Legacy(tx_legacy), + Some(TypedTxId::AccessList) => { + if request.access_list.is_none() { + return Err(Error::new(ErrorCode::InvalidParams)); + } + TypedTransaction::AccessList(AccessListTx::new( + tx_legacy, + request + .access_list + .unwrap_or_default() + .into_iter() + .map(Into::into) + .collect(), + )) + } + _ => return Err(Error::new(ErrorCode::InvalidParams)), }; Ok(tx_typed.fake_sign(from)) } diff --git a/crates/rpc/src/v1/helpers/requests.rs b/crates/rpc/src/v1/helpers/requests.rs index cc17ac4cd..24d0d7826 100644 --- a/crates/rpc/src/v1/helpers/requests.rs +++ b/crates/rpc/src/v1/helpers/requests.rs @@ -15,16 +15,15 @@ // along with OpenEthereum. If not, see . use bytes::Bytes; -use ethereum_types::{Address, H256, U256}; -use types::transaction::{AccessList, TypedTxId}; +use ethereum_types::{Address, H256, U256, U64}; -use v1::types::{Origin, TransactionCondition}; +use v1::types::{AccessList, Origin, TransactionCondition}; /// Transaction request coming from RPC #[derive(Debug, Clone, Default, Eq, PartialEq, Hash)] pub struct TransactionRequest { /// type of transaction. - pub transaction_type: TypedTxId, + pub transaction_type: U64, /// Sender pub from: Option
, /// Recipient @@ -49,7 +48,7 @@ pub struct TransactionRequest { #[derive(Debug, Clone, Default, Eq, PartialEq, Hash)] pub struct FilledTransactionRequest { /// type of transaction. - pub transaction_type: TypedTxId, + pub transaction_type: U64, /// Sender pub from: Address, /// Indicates if the sender was filled by default value. @@ -84,7 +83,7 @@ impl From for TransactionRequest { data: Some(r.data), nonce: r.nonce, condition: r.condition, - access_list: r.access_list, + access_list: r.access_list.map(Into::into), } } } @@ -93,7 +92,7 @@ impl From for TransactionRequest { #[derive(Debug, Default, PartialEq)] pub struct CallRequest { /// type of transaction. - pub transaction_type: TypedTxId, + pub transaction_type: U64, /// From pub from: Option
, /// To diff --git a/crates/rpc/src/v1/tests/mocked/eth.rs b/crates/rpc/src/v1/tests/mocked/eth.rs index 00ea5c6c2..abc19975d 100644 --- a/crates/rpc/src/v1/tests/mocked/eth.rs +++ b/crates/rpc/src/v1/tests/mocked/eth.rs @@ -707,7 +707,7 @@ fn rpc_eth_pending_transaction_by_hash() { .insert(H256::zero(), tx); } - let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"chainId":null,"condition":null,"creates":null,"from":"0x0f65fe9276bc9a24ae7083ae28e2660ef72df99e","gas":"0x5208","gasPrice":"0x1","hash":"0x41df922fd0d4766fcc02e161f8295ec28522f329ae487f14d811e4b64c8d6e31","input":"0x","nonce":"0x0","publicKey":"0x7ae46da747962c2ee46825839c1ef9298e3bd2e70ca2938495c3693a485ec3eaa8f196327881090ff64cf4fbb0a48485d4f83098e189ed3b7a87d5941b59f789","r":"0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353","raw":"0xf85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804","s":"0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804","standardV":"0x0","to":"0x095e7baea6a6c7c4c2dfeb977efac326af552d87","transactionIndex":null,"v":"0x1b","value":"0xa"},"id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"chainId":null,"condition":null,"creates":null,"from":"0x0f65fe9276bc9a24ae7083ae28e2660ef72df99e","gas":"0x5208","gasPrice":"0x1","hash":"0x41df922fd0d4766fcc02e161f8295ec28522f329ae487f14d811e4b64c8d6e31","input":"0x","nonce":"0x0","publicKey":"0x7ae46da747962c2ee46825839c1ef9298e3bd2e70ca2938495c3693a485ec3eaa8f196327881090ff64cf4fbb0a48485d4f83098e189ed3b7a87d5941b59f789","r":"0x48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353","raw":"0xf85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804","s":"0xefffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804","standardV":"0x0","to":"0x095e7baea6a6c7c4c2dfeb977efac326af552d87","transactionIndex":null,"type":"0x0","v":"0x1b","value":"0xa"},"id":1}"#; let request = r#"{ "jsonrpc": "2.0", "method": "eth_getTransactionByHash", @@ -1184,7 +1184,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","from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","data":"0x","logIndex":"0x1","removed":false,"topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"}],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0x0000000000000000000000000000000000000000000000000000000000000000","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0"},"id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":{"blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","contractAddress":null,"cumulativeGasUsed":"0x20","from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","gasUsed":"0x10","logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x4510c","data":"0x","logIndex":"0x1","removed":false,"topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"}],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","root":"0x0000000000000000000000000000000000000000000000000000000000000000","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","type":"0x0"},"id":1}"#; assert_eq!( tester.io.handle_request_sync(request), @@ -1238,7 +1238,7 @@ fn rpc_eth_pending_receipt() { "params": ["0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238"], "id": 1 }"#; - let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"contractAddress":null,"cumulativeGasUsed":"0x20","from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","gasUsed":"0x10","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionHash":"0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238","transactionIndex":"0x0"},"id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"contractAddress":null,"cumulativeGasUsed":"0x20","from":"0xb60e8dd61c5d32be8058bb8eb970870f07233155","gasUsed":"0x10","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionHash":"0xb903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238","transactionIndex":"0x0","type":"0x0"},"id":1}"#; assert_eq!( tester.io.handle_request_sync(request), Some(response.to_owned()) diff --git a/crates/rpc/src/v1/tests/mocked/parity.rs b/crates/rpc/src/v1/tests/mocked/parity.rs index ea1b7c31a..608a44fab 100644 --- a/crates/rpc/src/v1/tests/mocked/parity.rs +++ b/crates/rpc/src/v1/tests/mocked/parity.rs @@ -492,7 +492,7 @@ fn rpc_parity_block_receipts() { "params": [], "id": 1 }"#; - let response = r#"{"jsonrpc":"2.0","result":[{"blockHash":"0x0000000000000000000000000000000000000000000000000000000000000003","blockNumber":"0x0","contractAddress":null,"cumulativeGasUsed":"0x5208","from":"0x0000000000000000000000000000000000000009","gasUsed":"0x5208","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001","to":null,"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000001","transactionIndex":"0x0"}],"id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":[{"blockHash":"0x0000000000000000000000000000000000000000000000000000000000000003","blockNumber":"0x0","contractAddress":null,"cumulativeGasUsed":"0x5208","from":"0x0000000000000000000000000000000000000009","gasUsed":"0x5208","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001","to":null,"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000001","transactionIndex":"0x0","type":"0x0"}],"id":1}"#; assert_eq!(io.handle_request_sync(request), Some(response.to_owned())); } diff --git a/crates/rpc/src/v1/tests/mocked/parity_set.rs b/crates/rpc/src/v1/tests/mocked/parity_set.rs index bea2000a3..011c29be0 100644 --- a/crates/rpc/src/v1/tests/mocked/parity_set.rs +++ b/crates/rpc/src/v1/tests/mocked/parity_set.rs @@ -202,7 +202,7 @@ fn rpc_parity_remove_transaction() { .to_owned() + &format!("0x{:x}", hash) + r#""], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"chainId":null,"condition":null,"creates":null,"from":"0x0000000000000000000000000000000000000002","gas":"0x76c0","gasPrice":"0x9184e72a000","hash":"0x49569012bc8523519642c337fded3f20ba987beab31e14c67223b3d31359956f","input":"0x","nonce":"0x1","publicKey":null,"r":"0x1","raw":"0xe9018609184e72a0008276c0940000000000000000000000000000000000000005849184e72a801f0101","s":"0x1","standardV":"0x4","to":"0x0000000000000000000000000000000000000005","transactionIndex":null,"v":"0x1f","value":"0x9184e72a"},"id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"chainId":null,"condition":null,"creates":null,"from":"0x0000000000000000000000000000000000000002","gas":"0x76c0","gasPrice":"0x9184e72a000","hash":"0x49569012bc8523519642c337fded3f20ba987beab31e14c67223b3d31359956f","input":"0x","nonce":"0x1","publicKey":null,"r":"0x1","raw":"0xe9018609184e72a0008276c0940000000000000000000000000000000000000005849184e72a801f0101","s":"0x1","standardV":"0x4","to":"0x0000000000000000000000000000000000000005","transactionIndex":null,"type":"0x0","v":"0x1f","value":"0x9184e72a"},"id":1}"#; miner.pending_transactions.lock().insert(hash, signed); assert_eq!(io.handle_request_sync(&request), Some(response.to_owned())); diff --git a/crates/rpc/src/v1/tests/mocked/signer.rs b/crates/rpc/src/v1/tests/mocked/signer.rs index 6c0bcee84..917ad9ae1 100644 --- a/crates/rpc/src/v1/tests/mocked/signer.rs +++ b/crates/rpc/src/v1/tests/mocked/signer.rs @@ -118,7 +118,7 @@ fn should_return_list_of_items_to_confirm() { let request = r#"{"jsonrpc":"2.0","method":"signer_requestsToConfirm","params":[],"id":1}"#; let response = concat!( r#"{"jsonrpc":"2.0","result":["#, - r#"{"id":"0x1","origin":"unknown","payload":{"sendTransaction":{"condition":null,"data":"0x","from":"0x0000000000000000000000000000000000000001","gas":"0x989680","gasPrice":"0x2710","nonce":null,"to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","value":"0x1"}}},"#, + r#"{"id":"0x1","origin":"unknown","payload":{"sendTransaction":{"condition":null,"data":"0x","from":"0x0000000000000000000000000000000000000001","gas":"0x989680","gasPrice":"0x2710","nonce":null,"to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","type":"0x0","value":"0x1"}}},"#, r#"{"id":"0x2","origin":"unknown","payload":{"sign":{"address":"0x0000000000000000000000000000000000000001","data":"0x05"}}}"#, r#"],"id":1}"# ); @@ -637,7 +637,7 @@ fn should_confirm_sign_transaction_with_rlp() { + &format!("\"raw\":\"0x{}\",", rlp.to_hex()) + &format!("\"s\":\"0x{:x}\",", U256::from(signature.s())) + &format!("\"standardV\":\"0x{:x}\",", U256::from(t.standard_v())) - + r#""to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionIndex":null,"# + + r#""to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionIndex":null,"type":"0x0","# + &format!("\"v\":\"0x{:x}\",", U256::from(t.original_v())) + r#""value":"0x1""# + r#"}},"id":1}"#; diff --git a/crates/rpc/src/v1/tests/mocked/signing.rs b/crates/rpc/src/v1/tests/mocked/signing.rs index fdeb9b496..f2b809b2f 100644 --- a/crates/rpc/src/v1/tests/mocked/signing.rs +++ b/crates/rpc/src/v1/tests/mocked/signing.rs @@ -418,7 +418,7 @@ fn should_add_sign_transaction_to_the_queue() { + &format!("\"raw\":\"0x{}\",", rlp.to_hex()) + &format!("\"s\":\"0x{:x}\",", U256::from(signature.s())) + &format!("\"standardV\":\"0x{:x}\",", U256::from(t.standard_v())) - + r#""to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionIndex":null,"# + + r#""to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionIndex":null,"type":"0x0","# + &format!("\"v\":\"0x{:x}\",", U256::from(t.original_v())) + r#""value":"0x9184e72a""# + r#"}},"id":1}"#; @@ -610,7 +610,7 @@ fn should_compose_transaction() { let response = r#"{"jsonrpc":"2.0","result":{"condition":null,"data":"0x","from":"0x"# .to_owned() + &from - + r#"","gas":"0x5208","gasPrice":"0x4a817c800","nonce":"0x0","to":null,"value":"0x5"},"id":1}"#; + + r#"","gas":"0x5208","gasPrice":"0x4a817c800","nonce":"0x0","to":null,"type":"0x0","value":"0x5"},"id":1}"#; // then let res = tester.io.handle_request(&request).wait().unwrap(); diff --git a/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs b/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs index c52127736..fde44ed93 100644 --- a/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs +++ b/crates/rpc/src/v1/tests/mocked/signing_unsafe.rs @@ -226,7 +226,7 @@ fn rpc_eth_sign_transaction() { + &format!("\"raw\":\"0x{}\",", rlp.to_hex()) + &format!("\"s\":\"0x{:x}\",", U256::from(signature.s())) + &format!("\"standardV\":\"0x{:x}\",", U256::from(t.standard_v())) - + r#""to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionIndex":null,"# + + r#""to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionIndex":null,"type":"0x0","# + &format!("\"v\":\"0x{:x}\",", U256::from(t.original_v())) + r#""value":"0x9184e72a""# + r#"}},"id":1}"#; diff --git a/crates/rpc/src/v1/types/block.rs b/crates/rpc/src/v1/types/block.rs index 49c603fde..5951e1a82 100644 --- a/crates/rpc/src/v1/types/block.rs +++ b/crates/rpc/src/v1/types/block.rs @@ -221,7 +221,7 @@ mod tests { 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,"chainId":null,"standardV":"0x0","v":"0x0","r":"0x0","s":"0x0","condition":null}]"# + r#"[{"type":"0x0","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,"chainId":null,"standardV":"0x0","v":"0x0","r":"0x0","s":"0x0","condition":null}]"# ); let t = BlockTransactions::Hashes(vec![H256::default().into()]); diff --git a/crates/rpc/src/v1/types/call_request.rs b/crates/rpc/src/v1/types/call_request.rs index 0972dd6bd..dd7a63745 100644 --- a/crates/rpc/src/v1/types/call_request.rs +++ b/crates/rpc/src/v1/types/call_request.rs @@ -14,19 +14,21 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use ethereum_types::{H160, U256}; -use types::transaction::{AccessList, TypedTxId}; -use v1::{helpers::CallRequest as Request, types::Bytes}; +use ethereum_types::{H160, U256, U64}; +use v1::{ + helpers::CallRequest as Request, + types::{AccessList, Bytes}, +}; /// Call request #[derive(Debug, Default, PartialEq, Deserialize)] #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] pub struct CallRequest { - /// transaction type + /// transaction type. Defaults to legacy type. #[serde(default)] #[serde(rename = "type")] - pub transaction_type: TypedTxId, + pub transaction_type: U64, /// From pub from: Option, /// To @@ -42,6 +44,7 @@ pub struct CallRequest { /// Nonce pub nonce: Option, /// Access list + #[serde(skip_serializing_if = "Option::is_none")] pub access_list: Option, } diff --git a/crates/rpc/src/v1/types/confirmations.rs b/crates/rpc/src/v1/types/confirmations.rs index b489f354c..1dfbe7834 100644 --- a/crates/rpc/src/v1/types/confirmations.rs +++ b/crates/rpc/src/v1/types/confirmations.rs @@ -349,7 +349,7 @@ mod tests { // when let res = serde_json::to_string(&ConfirmationRequest::from(request)); - let expected = r#"{"id":"0xf","payload":{"sendTransaction":{"from":"0x0000000000000000000000000000000000000000","to":null,"gasPrice":"0x2710","gas":"0x3a98","value":"0x186a0","data":"0x010203","nonce":"0x1","condition":null}},"origin":{"signer":{"session":"0x0000000000000000000000000000000000000000000000000000000000000005"}}}"#; + let expected = r#"{"id":"0xf","payload":{"sendTransaction":{"type":"0x0","from":"0x0000000000000000000000000000000000000000","to":null,"gasPrice":"0x2710","gas":"0x3a98","value":"0x186a0","data":"0x010203","nonce":"0x1","condition":null}},"origin":{"signer":{"session":"0x0000000000000000000000000000000000000000000000000000000000000005"}}}"#; // then assert_eq!(res.unwrap(), expected.to_owned()); @@ -380,7 +380,7 @@ mod tests { // when let res = serde_json::to_string(&ConfirmationRequest::from(request)); - let expected = r#"{"id":"0xf","payload":{"signTransaction":{"from":"0x0000000000000000000000000000000000000000","to":null,"gasPrice":"0x2710","gas":"0x3a98","value":"0x186a0","data":"0x010203","nonce":"0x1","condition":null}},"origin":"unknown"}"#; + let expected = r#"{"id":"0xf","payload":{"signTransaction":{"type":"0x0","from":"0x0000000000000000000000000000000000000000","to":null,"gasPrice":"0x2710","gas":"0x3a98","value":"0x186a0","data":"0x010203","nonce":"0x1","condition":null}},"origin":"unknown"}"#; // then assert_eq!(res.unwrap(), expected.to_owned()); diff --git a/crates/rpc/src/v1/types/mod.rs b/crates/rpc/src/v1/types/mod.rs index 2da3457d6..ce07f538a 100644 --- a/crates/rpc/src/v1/types/mod.rs +++ b/crates/rpc/src/v1/types/mod.rs @@ -40,6 +40,7 @@ mod sync; mod trace; mod trace_filter; mod transaction; +mod transaction_access_list; mod transaction_condition; mod transaction_request; mod work; @@ -75,6 +76,7 @@ pub use self::{ trace::{LocalizedTrace, TraceResults, TraceResultsWithTransactionHash}, trace_filter::TraceFilter, transaction::{LocalTransactionStatus, RichRawTransaction, Transaction}, + transaction_access_list::{AccessList, AccessListItem}, transaction_condition::TransactionCondition, transaction_request::TransactionRequest, work::Work, diff --git a/crates/rpc/src/v1/types/receipt.rs b/crates/rpc/src/v1/types/receipt.rs index 37042ad1a..64b6c696d 100644 --- a/crates/rpc/src/v1/types/receipt.rs +++ b/crates/rpc/src/v1/types/receipt.rs @@ -15,10 +15,7 @@ // along with OpenEthereum. If not, see . use ethereum_types::{Bloom as H2048, H160, H256, U256, U64}; -use types::{ - receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome, TypedReceipt}, - transaction::TypedTxId, -}; +use types::receipt::{LocalizedReceipt, RichReceipt, TransactionOutcome, TypedReceipt}; use v1::types::Log; /// Receipt @@ -27,7 +24,7 @@ use v1::types::Log; pub struct Receipt { /// Transaction Type #[serde(rename = "type")] - pub transaction_type: TypedTxId, + pub transaction_type: U64, /// Transaction Hash pub transaction_hash: Option, /// Transaction index @@ -81,7 +78,7 @@ impl From for Receipt { Receipt { to: r.to.map(Into::into), from: Some(r.from), - transaction_type: r.transaction_type, + transaction_type: U64::from(r.transaction_type as u8), transaction_hash: Some(r.transaction_hash), transaction_index: Some(r.transaction_index.into()), block_hash: Some(r.block_hash), @@ -102,7 +99,7 @@ impl From for Receipt { Receipt { from: Some(r.from), to: r.to.map(Into::into), - transaction_type: r.transaction_type, + transaction_type: U64::from(r.transaction_type as u8), transaction_hash: Some(r.transaction_hash), transaction_index: Some(r.transaction_index.into()), block_hash: None, @@ -120,7 +117,7 @@ impl From for Receipt { impl From for Receipt { fn from(r: TypedReceipt) -> Self { - let transaction_type = r.tx_type(); + let transaction_type = U64::from(r.tx_type() as u8); let r = r.receipt().clone(); Receipt { from: None, @@ -148,7 +145,7 @@ mod tests { #[test] fn receipt_serialization() { - let s = r#"{"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","from":null,"to":null,"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","transactionLogIndex":null,"type":"mined","removed":false}],"root":"0x000000000000000000000000000000000000000000000000000000000000000a","logsBloom":"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f","status":"0x1"}"#; + let s = r#"{"type":"0x0","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x0","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","from":null,"to":null,"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","transactionLogIndex":null,"type":"mined","removed":false}],"root":"0x000000000000000000000000000000000000000000000000000000000000000a","logsBloom":"0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f","status":"0x1"}"#; let receipt = Receipt { from: None, diff --git a/crates/rpc/src/v1/types/transaction.rs b/crates/rpc/src/v1/types/transaction.rs index 6d6bf419c..42060097a 100644 --- a/crates/rpc/src/v1/types/transaction.rs +++ b/crates/rpc/src/v1/types/transaction.rs @@ -21,10 +21,9 @@ use ethereum_types::{H160, H256, H512, U256, U64}; use miner; use serde::{ser::SerializeStruct, Serialize, Serializer}; use types::transaction::{ - AccessList, Action, LocalizedTransaction, PendingTransaction, SignedTransaction, - TypedTransaction, + Action, LocalizedTransaction, PendingTransaction, SignedTransaction, TypedTransaction, }; -use v1::types::{Bytes, TransactionCondition}; +use v1::types::{AccessList, Bytes, TransactionCondition}; /// Transaction #[derive(Debug, Default, Clone, PartialEq, Serialize)] @@ -32,7 +31,7 @@ use v1::types::{Bytes, TransactionCondition}; pub struct Transaction { /// transaction type #[serde(rename = "type")] - pub transaction_type: u8, + pub transaction_type: U64, /// Hash pub hash: H256, /// Nonce @@ -74,7 +73,8 @@ pub struct Transaction { /// Transaction activates at specified block. pub condition: Option, /// optional access list - pub access_list: AccessList, + #[serde(skip_serializing_if = "Option::is_none")] + pub access_list: Option, } /// Local Transaction Status @@ -186,9 +186,9 @@ impl Transaction { let scheme = CreateContractAddress::FromSenderAndNonce; let access_list = if let TypedTransaction::AccessList(al) = t.as_unsigned() { - al.access_list.clone() + Some(al.access_list.clone().into_iter().map(Into::into).collect()) } else { - Vec::new() + None }; Transaction { @@ -220,7 +220,7 @@ impl Transaction { r: signature.r().into(), s: signature.s().into(), condition: None, - transaction_type: t.signed.tx_type() as u8, + transaction_type: U64::from(t.signed.tx_type() as u8), access_list, } } @@ -230,9 +230,9 @@ impl Transaction { let signature = t.signature(); let scheme = CreateContractAddress::FromSenderAndNonce; let access_list = if let TypedTransaction::AccessList(al) = t.as_unsigned() { - al.access_list.clone() + Some(al.access_list.clone().into_iter().map(Into::into).collect()) } else { - Vec::new() + None }; Transaction { hash: t.hash(), @@ -263,7 +263,7 @@ impl Transaction { r: signature.r().into(), s: signature.s().into(), condition: None, - transaction_type: t.tx_type() as u8, + transaction_type: U64::from(t.tx_type() as u8), access_list, } } @@ -303,15 +303,20 @@ impl LocalTransactionStatus { #[cfg(test)] mod tests { use super::{LocalTransactionStatus, Transaction}; + use ethereum_types::U64; use serde_json; + use types::transaction::TypedTxId; + use v1::types::AccessListItem; #[test] fn test_transaction_serialize() { - let t = Transaction::default(); + let mut t = Transaction::default(); + t.transaction_type = U64::from(TypedTxId::AccessList as u8); + t.access_list = Some(vec![AccessListItem::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,"chainId":null,"standardV":"0x0","v":"0x0","r":"0x0","s":"0x0","condition":null}"# + r#"{"type":"0x1","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,"chainId":null,"standardV":"0x0","v":"0x0","r":"0x0","s":"0x0","condition":null,"accessList":[{"address":"0x0000000000000000000000000000000000000000","storageKeys":[]}]}"# ); } diff --git a/crates/rpc/src/v1/types/transaction_access_list.rs b/crates/rpc/src/v1/types/transaction_access_list.rs new file mode 100644 index 000000000..810537e69 --- /dev/null +++ b/crates/rpc/src/v1/types/transaction_access_list.rs @@ -0,0 +1,36 @@ +use ethereum_types::{H160, H256}; +use serde::Serialize; +use std::vec::Vec; +use types::transaction::AccessListItem as InnerAccessListItem; + +pub type AccessList = Vec; +#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct AccessListItem { + address: H160, + storage_keys: Vec, +} + +impl AccessListItem { + pub fn new(address: H160, storage_keys: Vec) -> Self { + Self { + address, + storage_keys, + } + } +} + +impl From for AccessListItem { + fn from(item: InnerAccessListItem) -> Self { + AccessListItem { + address: item.0, + storage_keys: item.1, + } + } +} + +impl From for InnerAccessListItem { + fn from(item: AccessListItem) -> Self { + (item.address, item.storage_keys) + } +} diff --git a/crates/rpc/src/v1/types/transaction_request.rs b/crates/rpc/src/v1/types/transaction_request.rs index bace3af04..9f5756f7b 100644 --- a/crates/rpc/src/v1/types/transaction_request.rs +++ b/crates/rpc/src/v1/types/transaction_request.rs @@ -17,11 +17,10 @@ //! `TransactionRequest` type use ansi_term::Colour; -use ethereum_types::{H160, U256}; -use types::transaction::{AccessList, TypedTxId}; +use ethereum_types::{H160, U256, U64}; use v1::{ helpers, - types::{Bytes, TransactionCondition}, + types::{AccessList, Bytes, TransactionCondition}, }; use std::fmt; @@ -31,10 +30,10 @@ use std::fmt; #[serde(deny_unknown_fields)] #[serde(rename_all = "camelCase")] pub struct TransactionRequest { - /// type of transaction. If none we assume it is legacy + /// type of transaction. Defaults to legacy type. #[serde(default)] #[serde(rename = "type")] - pub transaction_type: TypedTxId, + pub transaction_type: U64, /// Sender pub from: Option, /// Recipient @@ -52,6 +51,7 @@ pub struct TransactionRequest { /// Delay until this block condition. pub condition: Option, /// Access list + #[serde(skip_serializing_if = "Option::is_none")] pub access_list: Option, } @@ -130,7 +130,7 @@ impl From for TransactionRequest { data: Some(r.data.into()), nonce: r.nonce, condition: r.condition, - access_list: r.access_list, + access_list: r.access_list.map(Into::into), } } }