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
This commit is contained in:
rakita 2021-02-08 14:55:03 +01:00 committed by GitHub
parent f40e198eb7
commit 6b4e56b214
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 144 additions and 81 deletions

View File

@ -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

View File

@ -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<H256>)>;
pub type AccessListItem = (H160, Vec<H256>);
pub type AccessList = Vec<AccessListItem>;
use super::TypedTxId;

View File

@ -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<Self> {
match n.0[0] {
0x0 => Some(Self::Legacy),
0x1 => Some(Self::AccessList),
_ => None,
}
}
}
impl Default for TypedTxId {

View File

@ -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 {

View File

@ -35,13 +35,15 @@ pub struct Transaction {
pub v: Uint,
pub value: Uint,
pub chain_id: Option<Uint>,
pub access_list: Option<Vec<AccessList>>,
pub access_list: Option<AccessList>,
pub hash: Option<H256>,
}
pub type AccessList = Vec<AccessListItem>;
#[derive(Debug, PartialEq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccessList {
pub struct AccessListItem {
pub address: H160,
pub storage_keys: Vec<H256>,
}

View File

@ -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);

View File

@ -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<SignedTransaction, Error> {
@ -35,12 +35,23 @@ pub fn sign_call(request: CallRequest) -> Result<SignedTransaction, Error> {
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(
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(),
)),
request
.access_list
.unwrap_or_default()
.into_iter()
.map(Into::into)
.collect(),
))
}
_ => return Err(Error::new(ErrorCode::InvalidParams)),
};
Ok(tx_typed.fake_sign(from))
}

View File

@ -15,16 +15,15 @@
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
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<Address>,
/// 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<FilledTransactionRequest> 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<FilledTransactionRequest> for TransactionRequest {
#[derive(Debug, Default, PartialEq)]
pub struct CallRequest {
/// type of transaction.
pub transaction_type: TypedTxId,
pub transaction_type: U64,
/// From
pub from: Option<Address>,
/// To

View File

@ -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())

View File

@ -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()));
}

View File

@ -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()));

View File

@ -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}"#;

View File

@ -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();

View File

@ -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}"#;

View File

@ -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()]);

View File

@ -14,19 +14,21 @@
// You should have received a copy of the GNU General Public License
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
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<H160>,
/// To
@ -42,6 +44,7 @@ pub struct CallRequest {
/// Nonce
pub nonce: Option<U256>,
/// Access list
#[serde(skip_serializing_if = "Option::is_none")]
pub access_list: Option<AccessList>,
}

View File

@ -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());

View File

@ -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,

View File

@ -15,10 +15,7 @@
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
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<H256>,
/// Transaction index
@ -81,7 +78,7 @@ impl From<LocalizedReceipt> 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<RichReceipt> 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<RichReceipt> for Receipt {
impl From<TypedReceipt> 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,

View File

@ -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<TransactionCondition>,
/// optional access list
pub access_list: AccessList,
#[serde(skip_serializing_if = "Option::is_none")]
pub access_list: Option<AccessList>,
}
/// 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":[]}]}"#
);
}

View File

@ -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<AccessListItem>;
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccessListItem {
address: H160,
storage_keys: Vec<H256>,
}
impl AccessListItem {
pub fn new(address: H160, storage_keys: Vec<H256>) -> Self {
Self {
address,
storage_keys,
}
}
}
impl From<InnerAccessListItem> for AccessListItem {
fn from(item: InnerAccessListItem) -> Self {
AccessListItem {
address: item.0,
storage_keys: item.1,
}
}
}
impl From<AccessListItem> for InnerAccessListItem {
fn from(item: AccessListItem) -> Self {
(item.address, item.storage_keys)
}
}

View File

@ -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<H160>,
/// Recipient
@ -52,6 +51,7 @@ pub struct TransactionRequest {
/// Delay until this block condition.
pub condition: Option<TransactionCondition>,
/// Access list
#[serde(skip_serializing_if = "Option::is_none")]
pub access_list: Option<AccessList>,
}
@ -130,7 +130,7 @@ impl From<helpers::FilledTransactionRequest> 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),
}
}
}