EIP-2930 remove type from legacy JSONRPC (#265)
* EIP-2930 remove type from legacy JSONRPC * fmt
This commit is contained in:
parent
dbf9a1cd98
commit
fb9699d8e1
@ -20,10 +20,7 @@ use super::transaction::TypedTxId;
|
||||
use ethereum_types::{Address, Bloom, H160, H256, U256};
|
||||
use heapsize::HeapSizeOf;
|
||||
use rlp::{DecoderError, Rlp, RlpStream};
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use log_entry::{LocalizedLogEntry, LogEntry};
|
||||
use BlockNumber;
|
||||
@ -151,7 +148,7 @@ impl TypedReceipt {
|
||||
// at least one byte needs to be present
|
||||
return Err(DecoderError::RlpIncorrectListLen);
|
||||
}
|
||||
let id = tx[0].try_into();
|
||||
let id = TypedTxId::try_from_wire_byte(tx[0]);
|
||||
if id.is_err() {
|
||||
return Err(DecoderError::Custom("Unknown transaction"));
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ use ethkey::{self, public_to_address, recover, Public, Secret, Signature};
|
||||
use hash::keccak;
|
||||
use heapsize::HeapSizeOf;
|
||||
use rlp::{self, DecoderError, Rlp, RlpStream};
|
||||
use std::{convert::TryInto, ops::Deref};
|
||||
use std::ops::Deref;
|
||||
|
||||
pub type AccessListItem = (H160, Vec<H256>);
|
||||
pub type AccessList = Vec<AccessListItem>;
|
||||
@ -493,7 +493,7 @@ impl TypedTransaction {
|
||||
// at least one byte needs to be present
|
||||
return Err(DecoderError::RlpIncorrectListLen);
|
||||
}
|
||||
let id = tx[0].try_into();
|
||||
let id = TypedTxId::try_from_wire_byte(tx[0]);
|
||||
if id.is_err() {
|
||||
return Err(DecoderError::Custom("Unknown transaction"));
|
||||
}
|
||||
|
@ -18,9 +18,8 @@
|
||||
|
||||
use ethereum_types::U64;
|
||||
use serde_repr::*;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
#[derive(Serialize_repr, Eq, Hash, Deserialize_repr, Debug, Clone, PartialEq)]
|
||||
#[derive(Serialize_repr, Eq, Hash, Deserialize_repr, Debug, Copy, Clone, PartialEq)]
|
||||
#[repr(u8)]
|
||||
pub enum TypedTxId {
|
||||
AccessList = 0x01,
|
||||
@ -28,6 +27,7 @@ pub enum TypedTxId {
|
||||
}
|
||||
|
||||
impl TypedTxId {
|
||||
// used in json tets
|
||||
pub fn from_u8_id(n: u8) -> Option<Self> {
|
||||
match n {
|
||||
0 => Some(Self::Legacy),
|
||||
@ -36,14 +36,30 @@ impl TypedTxId {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_from_wire_byte(n: u8) -> Result<Self, ()> {
|
||||
match n {
|
||||
x if x == TypedTxId::AccessList as u8 => Ok(TypedTxId::AccessList),
|
||||
x if (x & 0x80) != 0x00 => Ok(TypedTxId::Legacy),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
|
||||
#[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),
|
||||
pub fn from_U64_option_id(n: Option<U64>) -> Option<Self> {
|
||||
match n.map(|t| t.as_u64()) {
|
||||
None => Some(Self::Legacy),
|
||||
Some(0x01) => Some(Self::AccessList),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn to_U64_option_id(self) -> Option<U64> {
|
||||
match self {
|
||||
Self::Legacy => None,
|
||||
_ => Some(U64::from(self as u8)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for TypedTxId {
|
||||
@ -52,14 +68,44 @@ impl Default for TypedTxId {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<u8> for TypedTxId {
|
||||
type Error = ();
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn try_from(v: u8) -> Result<Self, Self::Error> {
|
||||
match v {
|
||||
x if x == TypedTxId::AccessList as u8 => Ok(TypedTxId::AccessList),
|
||||
x if (x & 0x80) != 0x00 => Ok(TypedTxId::Legacy),
|
||||
_ => Err(()),
|
||||
}
|
||||
#[test]
|
||||
fn typed_tx_id_try_from_wire() {
|
||||
assert_eq!(
|
||||
Ok(TypedTxId::AccessList),
|
||||
TypedTxId::try_from_wire_byte(0x01)
|
||||
);
|
||||
assert_eq!(Ok(TypedTxId::Legacy), TypedTxId::try_from_wire_byte(0x81));
|
||||
assert_eq!(Err(()), TypedTxId::try_from_wire_byte(0x00));
|
||||
assert_eq!(Err(()), TypedTxId::try_from_wire_byte(0x02));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typed_tx_id_to_u64_option_id() {
|
||||
assert_eq!(None, TypedTxId::Legacy.to_U64_option_id());
|
||||
assert_eq!(
|
||||
Some(U64::from(0x01)),
|
||||
TypedTxId::AccessList.to_U64_option_id()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typed_tx_id_from_u64_option_id() {
|
||||
assert_eq!(Some(TypedTxId::Legacy), TypedTxId::from_U64_option_id(None));
|
||||
assert_eq!(
|
||||
Some(TypedTxId::AccessList),
|
||||
TypedTxId::from_U64_option_id(Some(U64::from(0x01)))
|
||||
);
|
||||
assert_eq!(None, TypedTxId::from_U64_option_id(Some(U64::from(0x02))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typed_tx_id_from_u8_id() {
|
||||
assert_eq!(Some(TypedTxId::Legacy), TypedTxId::from_u8_id(0));
|
||||
assert_eq!(Some(TypedTxId::AccessList), TypedTxId::from_u8_id(1));
|
||||
assert_eq!(None, TypedTxId::from_u8_id(3));
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
// along with OpenEthereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! View onto transaction rlp
|
||||
use std::convert::TryInto;
|
||||
|
||||
use crate::transaction::{signature, TypedTxId};
|
||||
|
||||
@ -52,7 +51,7 @@ impl<'a> TypedTransactionView<'a> {
|
||||
return TypedTxId::Legacy;
|
||||
}
|
||||
let tx = rlp.data().expect("unable to decode tx rlp");
|
||||
let id = tx[0].try_into().expect("unable to decode tx type");
|
||||
let id = TypedTxId::try_from_wire_byte(tx[0]).expect("unable to decode tx type");
|
||||
if id == TypedTxId::Legacy {
|
||||
panic!("Transaction RLP View should be valid. Legacy byte found");
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ impl super::Accounts for Signer {
|
||||
value: filled.value,
|
||||
data: filled.data,
|
||||
};
|
||||
let t = match TypedTxId::from_U64_id(&filled.transaction_type) {
|
||||
let t = match TypedTxId::from_U64_option_id(filled.transaction_type) {
|
||||
Some(TypedTxId::Legacy) => TypedTransaction::Legacy(legacy_tx),
|
||||
Some(TypedTxId::AccessList) => {
|
||||
if filled.access_list.is_none() {
|
||||
|
@ -35,7 +35,7 @@ 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 TypedTxId::from_U64_id(&request.transaction_type) {
|
||||
let tx_typed = match TypedTxId::from_U64_option_id(request.transaction_type) {
|
||||
Some(TypedTxId::Legacy) => TypedTransaction::Legacy(tx_legacy),
|
||||
Some(TypedTxId::AccessList) => {
|
||||
if request.access_list.is_none() {
|
||||
|
@ -23,7 +23,7 @@ use v1::types::{AccessList, Origin, TransactionCondition};
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash)]
|
||||
pub struct TransactionRequest {
|
||||
/// type of transaction.
|
||||
pub transaction_type: U64,
|
||||
pub transaction_type: Option<U64>,
|
||||
/// Sender
|
||||
pub from: Option<Address>,
|
||||
/// Recipient
|
||||
@ -48,7 +48,7 @@ pub struct TransactionRequest {
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash)]
|
||||
pub struct FilledTransactionRequest {
|
||||
/// type of transaction.
|
||||
pub transaction_type: U64,
|
||||
pub transaction_type: Option<U64>,
|
||||
/// Sender
|
||||
pub from: Address,
|
||||
/// Indicates if the sender was filled by default value.
|
||||
@ -92,7 +92,7 @@ impl From<FilledTransactionRequest> for TransactionRequest {
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
pub struct CallRequest {
|
||||
/// type of transaction.
|
||||
pub transaction_type: U64,
|
||||
pub transaction_type: Option<U64>,
|
||||
/// From
|
||||
pub from: Option<Address>,
|
||||
/// To
|
||||
|
@ -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,"type":"0x0","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,"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","type":"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"},"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","type":"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"},"id":1}"#;
|
||||
assert_eq!(
|
||||
tester.io.handle_request_sync(request),
|
||||
Some(response.to_owned())
|
||||
|
@ -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","type":"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"}],"id":1}"#;
|
||||
|
||||
assert_eq!(io.handle_request_sync(request), Some(response.to_owned()));
|
||||
}
|
||||
|
@ -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,"type":"0x0","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,"v":"0x1f","value":"0x9184e72a"},"id":1}"#;
|
||||
|
||||
miner.pending_transactions.lock().insert(hash, signed);
|
||||
assert_eq!(io.handle_request_sync(&request), Some(response.to_owned()));
|
||||
|
@ -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","type":"0x0","value":"0x1"}}},"#,
|
||||
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":"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,"type":"0x0","#
|
||||
+ r#""to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionIndex":null,"#
|
||||
+ &format!("\"v\":\"0x{:x}\",", U256::from(t.original_v()))
|
||||
+ r#""value":"0x1""#
|
||||
+ r#"}},"id":1}"#;
|
||||
|
@ -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,"type":"0x0","#
|
||||
+ r#""to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionIndex":null,"#
|
||||
+ &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,"type":"0x0","value":"0x5"},"id":1}"#;
|
||||
+ r#"","gas":"0x5208","gasPrice":"0x4a817c800","nonce":"0x0","to":null,"value":"0x5"},"id":1}"#;
|
||||
|
||||
// then
|
||||
let res = tester.io.handle_request(&request).wait().unwrap();
|
||||
|
@ -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,"type":"0x0","#
|
||||
+ r#""to":"0xd46e8dd67c5d32be8058bb8eb970870f07244567","transactionIndex":null,"#
|
||||
+ &format!("\"v\":\"0x{:x}\",", U256::from(t.original_v()))
|
||||
+ r#""value":"0x9184e72a""#
|
||||
+ r#"}},"id":1}"#;
|
||||
|
@ -221,7 +221,7 @@ mod tests {
|
||||
let serialized = serde_json::to_string(&t).unwrap();
|
||||
assert_eq!(
|
||||
serialized,
|
||||
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}]"#
|
||||
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}]"#
|
||||
);
|
||||
|
||||
let t = BlockTransactions::Hashes(vec![H256::default().into()]);
|
||||
|
@ -26,9 +26,8 @@ use v1::{
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CallRequest {
|
||||
/// transaction type. Defaults to legacy type.
|
||||
#[serde(default)]
|
||||
#[serde(rename = "type")]
|
||||
pub transaction_type: U64,
|
||||
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
|
||||
pub transaction_type: Option<U64>,
|
||||
/// From
|
||||
pub from: Option<H160>,
|
||||
/// To
|
||||
|
@ -349,7 +349,7 @@ mod tests {
|
||||
|
||||
// when
|
||||
let res = serde_json::to_string(&ConfirmationRequest::from(request));
|
||||
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"}}}"#;
|
||||
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"}}}"#;
|
||||
|
||||
// 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":{"type":"0x0","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":{"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());
|
||||
|
@ -23,8 +23,8 @@ use v1::types::Log;
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Receipt {
|
||||
/// Transaction Type
|
||||
#[serde(rename = "type")]
|
||||
pub transaction_type: U64,
|
||||
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
|
||||
pub transaction_type: Option<U64>,
|
||||
/// Transaction Hash
|
||||
pub transaction_hash: Option<H256>,
|
||||
/// Transaction index
|
||||
@ -78,7 +78,7 @@ impl From<LocalizedReceipt> for Receipt {
|
||||
Receipt {
|
||||
to: r.to.map(Into::into),
|
||||
from: Some(r.from),
|
||||
transaction_type: U64::from(r.transaction_type as u8),
|
||||
transaction_type: r.transaction_type.to_U64_option_id(),
|
||||
transaction_hash: Some(r.transaction_hash),
|
||||
transaction_index: Some(r.transaction_index.into()),
|
||||
block_hash: Some(r.block_hash),
|
||||
@ -99,7 +99,7 @@ impl From<RichReceipt> for Receipt {
|
||||
Receipt {
|
||||
from: Some(r.from),
|
||||
to: r.to.map(Into::into),
|
||||
transaction_type: U64::from(r.transaction_type as u8),
|
||||
transaction_type: r.transaction_type.to_U64_option_id(),
|
||||
transaction_hash: Some(r.transaction_hash),
|
||||
transaction_index: Some(r.transaction_index.into()),
|
||||
block_hash: None,
|
||||
@ -117,7 +117,7 @@ impl From<RichReceipt> for Receipt {
|
||||
|
||||
impl From<TypedReceipt> for Receipt {
|
||||
fn from(r: TypedReceipt) -> Self {
|
||||
let transaction_type = U64::from(r.tx_type() as u8);
|
||||
let transaction_type = r.tx_type().to_U64_option_id();
|
||||
let r = r.receipt().clone();
|
||||
Receipt {
|
||||
from: None,
|
||||
@ -141,16 +141,17 @@ impl From<TypedReceipt> for Receipt {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json;
|
||||
use types::transaction::TypedTxId;
|
||||
use v1::types::{Log, Receipt};
|
||||
|
||||
#[test]
|
||||
fn receipt_serialization() {
|
||||
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 s = r#"{"type":"0x1","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,
|
||||
to: None,
|
||||
transaction_type: Default::default(),
|
||||
transaction_type: TypedTxId::AccessList.to_U64_option_id(),
|
||||
transaction_hash: Some(0.into()),
|
||||
transaction_index: Some(0.into()),
|
||||
block_hash: Some(
|
||||
|
@ -30,8 +30,8 @@ use v1::types::{AccessList, Bytes, TransactionCondition};
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Transaction {
|
||||
/// transaction type
|
||||
#[serde(rename = "type")]
|
||||
pub transaction_type: U64,
|
||||
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
|
||||
pub transaction_type: Option<U64>,
|
||||
/// Hash
|
||||
pub hash: H256,
|
||||
/// Nonce
|
||||
@ -220,7 +220,7 @@ impl Transaction {
|
||||
r: signature.r().into(),
|
||||
s: signature.s().into(),
|
||||
condition: None,
|
||||
transaction_type: U64::from(t.signed.tx_type() as u8),
|
||||
transaction_type: t.signed.tx_type().to_U64_option_id(),
|
||||
access_list,
|
||||
}
|
||||
}
|
||||
@ -263,7 +263,7 @@ impl Transaction {
|
||||
r: signature.r().into(),
|
||||
s: signature.s().into(),
|
||||
condition: None,
|
||||
transaction_type: U64::from(t.tx_type() as u8),
|
||||
transaction_type: t.tx_type().to_U64_option_id(),
|
||||
access_list,
|
||||
}
|
||||
}
|
||||
@ -303,7 +303,6 @@ 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;
|
||||
@ -311,7 +310,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_transaction_serialize() {
|
||||
let mut t = Transaction::default();
|
||||
t.transaction_type = U64::from(TypedTxId::AccessList as u8);
|
||||
t.transaction_type = TypedTxId::AccessList.to_U64_option_id();
|
||||
t.access_list = Some(vec![AccessListItem::default()]);
|
||||
let serialized = serde_json::to_string(&t).unwrap();
|
||||
assert_eq!(
|
||||
|
@ -31,9 +31,8 @@ use std::fmt;
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TransactionRequest {
|
||||
/// type of transaction. Defaults to legacy type.
|
||||
#[serde(default)]
|
||||
#[serde(rename = "type")]
|
||||
pub transaction_type: U64,
|
||||
#[serde(rename = "type", skip_serializing_if = "Option::is_none")]
|
||||
pub transaction_type: Option<U64>,
|
||||
/// Sender
|
||||
pub from: Option<H160>,
|
||||
/// Recipient
|
||||
|
Loading…
Reference in New Issue
Block a user