Skip to content

Commit

Permalink
Added EIP-1559 fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mdben1247 committed Jul 24, 2021
1 parent 8dda953 commit bf70dc2
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/api/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ mod tests {
"contractAddress": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"logsBloom": "0x0e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d15273310e670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
"logs": [],
"status": "0x1"
"status": "0x1",
"effectiveGasPrice": "0x100"
}"#;

rpc_test! (
Expand All @@ -488,6 +489,7 @@ mod tests {
gas: None, gas_price: None,
value: Some(0x1.into()), data: None,
transaction_type: None, access_list: None,
max_fee_per_gas: None, max_priority_fee_per_gas: None,
}, None
=>
"eth_call", vec![r#"{"to":"0x0000000000000000000000000000000000000123","value":"0x1"}"#, r#""latest""#];
Expand Down Expand Up @@ -520,6 +522,7 @@ mod tests {
gas: None, gas_price: None,
value: Some(0x1.into()), data: None,
transaction_type: None, access_list: None,
max_fee_per_gas: None, max_priority_fee_per_gas: None,
}, None
=>
"eth_estimateGas", vec![r#"{"to":"0x0000000000000000000000000000000000000123","value":"0x1"}"#];
Expand All @@ -532,6 +535,7 @@ mod tests {
gas: None, gas_price: None,
value: Some(0x1.into()), data: None,
transaction_type: None, access_list: None,
max_fee_per_gas: None, max_priority_fee_per_gas: None,
}, None
=>
"eth_estimateGas", vec![r#"{"value":"0x1"}"#];
Expand All @@ -544,6 +548,7 @@ mod tests {
gas: None, gas_price: None,
value: Some(0x1.into()), data: None,
transaction_type: None, access_list: None,
max_fee_per_gas: None, max_priority_fee_per_gas: None,
}, Some(0x123.into())
=>
"eth_estimateGas", vec![r#"{"to":"0x0000000000000000000000000000000000000123","value":"0x1"}"#, r#""0x123""#];
Expand Down Expand Up @@ -782,6 +787,7 @@ mod tests {
value: Some(0x1.into()), data: None,
nonce: None, condition: None,
transaction_type: None, access_list: None,
max_fee_per_gas: None, max_priority_fee_per_gas: None,
}
=>
"eth_sendTransaction", vec![r#"{"from":"0x0000000000000000000000000000000000000123","gasPrice":"0x1","to":"0x0000000000000000000000000000000000000123","value":"0x1"}"#];
Expand Down
6 changes: 6 additions & 0 deletions src/api/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ mod tests {
data: None,
transaction_type: None,
access_list: None,
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
},
CallRequest {
from: Some(Address::from_low_u64_be(0x321)),
Expand All @@ -109,6 +111,8 @@ mod tests {
data: Some(hex!("0493").into()),
transaction_type: None,
access_list: None,
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
},
CallRequest {
from: None,
Expand All @@ -119,6 +123,8 @@ mod tests {
data: Some(hex!("0723").into()),
transaction_type: None,
access_list: None,
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
}
] => "parity_call", vec![
r#"[{"to":"0x0000000000000000000000000000000000000123","value":"0x1"},{"data":"0x0493","from":"0x0000000000000000000000000000000000000321","to":"0x0000000000000000000000000000000000000123"},{"data":"0x0723","to":"0x0000000000000000000000000000000000000765","value":"0x5"}]"#
Expand Down
3 changes: 3 additions & 0 deletions src/api/personal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ mod tests {
value: Some(0x1.into()), data: None,
nonce: None, condition: None,
transaction_type: None, access_list: None,
max_fee_per_gas: None, max_priority_fee_per_gas: None,
}, "hunter2"
=>
"personal_sendTransaction", vec![r#"{"from":"0x0000000000000000000000000000000000000123","gasPrice":"0x1","to":"0x0000000000000000000000000000000000000123","value":"0x1"}"#, r#""hunter2""#];
Expand All @@ -161,6 +162,8 @@ mod tests {
condition: None,
transaction_type: None,
access_list: None,
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
}, "hunter2"
=>
"personal_signTransaction", vec![r#"{"data":"0x603880600c6000396000f300603880600c6000396000f3603880600c6000396000f360","from":"0x407d73d8a49eeb85d32cf465507dd71d507100c1","gas":"0x7f110","gasPrice":"0x9184e72a000","nonce":"0x0","to":"0x853f43d8a49eeb85d32cf465507dd71d507100c1","value":"0x7f110"}"#, r#""hunter2""#];
Expand Down
1 change: 1 addition & 0 deletions src/api/traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ mod tests {
gas: None, gas_price: None,
value: Some(0x1.into()), data: None,
transaction_type: None, access_list: None,
max_fee_per_gas: None, max_priority_fee_per_gas: None,
}, vec![TraceType::Trace], None
=>
"trace_call", vec![r#"{"to":"0x0000000000000000000000000000000000000123","value":"0x1"}"#, r#"["trace"]"#, r#""latest""#];
Expand Down
3 changes: 3 additions & 0 deletions src/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ mod tests {
condition: None,
transaction_type: None,
access_list: None,
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
};

let transaction_receipt = TransactionReceipt {
Expand All @@ -160,6 +162,7 @@ mod tests {
root: Some(H256::zero()),
logs_bloom: Default::default(),
transaction_type: None,
effective_gas_price: Default::default(),
};

let poll_interval = Duration::from_secs(0);
Expand Down
8 changes: 6 additions & 2 deletions src/contract/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ impl<T: Transport> Builder<T> {
chain_id,
transaction_type: tx.transaction_type,
access_list: tx.access_list,
max_fee_per_gas: tx.max_fee_per_gas,
max_priority_fee_per_gas: tx.max_priority_fee_per_gas,
};
let signed_tx = crate::api::Accounts::new(transport.clone())
.sign_transaction(tx, from)
Expand Down Expand Up @@ -208,6 +210,8 @@ impl<T: Transport> Builder<T> {
condition: options.condition,
transaction_type: options.transaction_type,
access_list: options.access_list,
max_fee_per_gas: options.max_fee_per_gas,
max_priority_fee_per_gas: options.max_priority_fee_per_gas,
};
let receipt = send(tx).await?;
match receipt.status {
Expand Down Expand Up @@ -253,7 +257,7 @@ mod tests {
)]));
// receipt
let receipt = ::serde_json::from_str::<rpc::Value>(
"{\"blockHash\":\"0xd5311584a9867d8e129113e1ec9db342771b94bd4533aeab820a5bcc2c54878f\",\"blockNumber\":\"0x256\",\"contractAddress\":\"0x600515dfe465f600f0c9793fa27cd2794f3ec0e1\",\"from\": \"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\"cumulativeGasUsed\":\"0xe57e0\",\"gasUsed\":\"0xe57e0\",\"logs\":[],\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"root\":null,\"transactionHash\":\"0x70ae45a5067fdf3356aa615ca08d925a38c7ff21b486a61e79d5af3969ebc1a1\",\"transactionIndex\":\"0x0\", \"status\": \"0x1\"}"
"{\"blockHash\":\"0xd5311584a9867d8e129113e1ec9db342771b94bd4533aeab820a5bcc2c54878f\",\"blockNumber\":\"0x256\",\"contractAddress\":\"0x600515dfe465f600f0c9793fa27cd2794f3ec0e1\",\"from\": \"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\"cumulativeGasUsed\":\"0xe57e0\",\"gasUsed\":\"0xe57e0\",\"logs\":[],\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"root\":null,\"transactionHash\":\"0x70ae45a5067fdf3356aa615ca08d925a38c7ff21b486a61e79d5af3969ebc1a1\",\"transactionIndex\":\"0x0\", \"status\": \"0x1\", \"effectiveGasPrice\": \"0x100\"}"
).unwrap();
transport.add_response(receipt.clone());
// block number
Expand Down Expand Up @@ -302,7 +306,7 @@ mod tests {
use serde_json::{to_string, to_vec};
let mut transport = TestTransport::default();
let receipt = ::serde_json::from_str::<rpc::Value>(
"{\"blockHash\":\"0xd5311584a9867d8e129113e1ec9db342771b94bd4533aeab820a5bcc2c54878f\",\"blockNumber\":\"0x256\",\"contractAddress\":\"0x600515dfe465f600f0c9793fa27cd2794f3ec0e1\",\"from\":\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\"cumulativeGasUsed\":\"0xe57e0\",\"gasUsed\":\"0xe57e0\",\"logs\":[],\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"root\":null,\"transactionHash\":\"0x70ae45a5067fdf3356aa615ca08d925a38c7ff21b486a61e79d5af3969ebc1a1\",\"transactionIndex\":\"0x0\", \"status\": \"0x1\"}"
"{\"blockHash\":\"0xd5311584a9867d8e129113e1ec9db342771b94bd4533aeab820a5bcc2c54878f\",\"blockNumber\":\"0x256\",\"contractAddress\":\"0x600515dfe465f600f0c9793fa27cd2794f3ec0e1\",\"from\":\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\"cumulativeGasUsed\":\"0xe57e0\",\"gasUsed\":\"0xe57e0\",\"logs\":[],\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"root\":null,\"transactionHash\":\"0x70ae45a5067fdf3356aa615ca08d925a38c7ff21b486a61e79d5af3969ebc1a1\",\"transactionIndex\":\"0x0\", \"status\": \"0x1\", \"effectiveGasPrice\": \"0x100\"}"
).unwrap();

for _ in 0..2 {
Expand Down
14 changes: 14 additions & 0 deletions src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ pub struct Options {
pub transaction_type: Option<U64>,
/// Access list
pub access_list: Option<AccessList>,
/// Max fee per gas
pub max_fee_per_gas: Option<U256>,
/// miner bribe
pub max_priority_fee_per_gas: Option<U256>,
}

impl Options {
Expand Down Expand Up @@ -133,6 +137,8 @@ impl<T: Transport> Contract<T> {
condition,
transaction_type,
access_list,
max_fee_per_gas,
max_priority_fee_per_gas,
} = options;
self.eth
.send_transaction(TransactionRequest {
Expand All @@ -146,6 +152,8 @@ impl<T: Transport> Contract<T> {
condition,
transaction_type,
access_list,
max_fee_per_gas,
max_priority_fee_per_gas,
})
.await
.map_err(Error::from)
Expand Down Expand Up @@ -180,6 +188,8 @@ impl<T: Transport> Contract<T> {
condition: options.condition,
transaction_type: options.transaction_type,
access_list: options.access_list,
max_fee_per_gas: options.max_fee_per_gas,
max_priority_fee_per_gas: options.max_priority_fee_per_gas,
};
confirm::send_transaction_with_confirmation(
self.eth.transport().clone(),
Expand Down Expand Up @@ -207,6 +217,8 @@ impl<T: Transport> Contract<T> {
data: Some(Bytes(data)),
transaction_type: options.transaction_type,
access_list: options.access_list,
max_fee_per_gas: options.max_fee_per_gas,
max_priority_fee_per_gas: options.max_priority_fee_per_gas,
},
None,
)
Expand Down Expand Up @@ -248,6 +260,8 @@ impl<T: Transport> Contract<T> {
data: Some(Bytes(call)),
transaction_type: options.transaction_type,
access_list: options.access_list,
max_fee_per_gas: options.max_fee_per_gas,
max_priority_fee_per_gas: options.max_priority_fee_per_gas,
},
block.into(),
);
Expand Down
6 changes: 6 additions & 0 deletions src/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pub struct BlockHeader {
pub mix_hash: Option<H256>,
/// Nonce
pub nonce: Option<H64>,
/// Base fee
#[serde(rename = "baseFeePerGas", skip_serializing_if = "Option::is_none")]
pub base_fee_per_gas: Option<U256>,
}

/// The block type returned from RPC calls.
Expand Down Expand Up @@ -99,6 +102,9 @@ pub struct Block<TX> {
pub seal_fields: Vec<Bytes>,
/// Uncles' hashes
pub uncles: Vec<H256>,
/// Base fee
#[serde(rename = "baseFeePerGas", skip_serializing_if = "Option::is_none")]
pub base_fee_per_gas: Option<U256>,
/// Transactions
pub transactions: Vec<TX>,
/// Size in bytes
Expand Down
10 changes: 10 additions & 0 deletions src/types/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ pub struct TransactionParameters {
pub transaction_type: Option<U64>,
/// Access list
pub access_list: Option<AccessList>,
/// Max fee per gas
pub max_fee_per_gas: Option<U256>,
/// miner bribe
pub max_priority_fee_per_gas: Option<U256>,
}

/// The default fas for transactions.
Expand All @@ -79,6 +83,8 @@ impl Default for TransactionParameters {
chain_id: None,
transaction_type: None,
access_list: None,
max_fee_per_gas: None,
max_priority_fee_per_gas: None,
}
}
}
Expand All @@ -95,6 +101,8 @@ impl From<CallRequest> for TransactionParameters {
chain_id: None,
transaction_type: call.transaction_type,
access_list: call.access_list,
max_fee_per_gas: call.max_fee_per_gas,
max_priority_fee_per_gas: call.max_priority_fee_per_gas,
}
}
}
Expand All @@ -110,6 +118,8 @@ impl Into<CallRequest> for TransactionParameters {
data: Some(self.data),
transaction_type: self.transaction_type,
access_list: self.access_list,
max_fee_per_gas: self.max_fee_per_gas,
max_priority_fee_per_gas: self.max_priority_fee_per_gas,
}
}
}
Expand Down
23 changes: 18 additions & 5 deletions src/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ pub struct Transaction {
/// Access list
#[serde(rename = "accessList", default, skip_serializing_if = "Option::is_none")]
pub access_list: Option<AccessList>,
/// Max fee per gas
#[serde(rename = "maxFeePerGas", skip_serializing_if = "Option::is_none")]
pub max_fee_per_gas: Option<U256>,
/// miner bribe
#[serde(rename = "maxPriorityFeePerGas", skip_serializing_if = "Option::is_none")]
pub max_priority_fee_per_gas: Option<U256>,
}

/// "Receipt" of an executed transaction: details of its execution.
Expand Down Expand Up @@ -99,6 +105,9 @@ pub struct Receipt {
/// Transaction type, Some(1) for AccessList transaction, None for Legacy
#[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
pub transaction_type: Option<U64>,
/// Effective gas price
#[serde(rename = "effectiveGasPrice")]
pub effective_gas_price: U256,
}

/// Raw bytes of a signed, but not yet sent transaction
Expand Down Expand Up @@ -129,7 +138,7 @@ mod tests {

#[test]
fn test_deserialize_receipt() {
let receipt_str = "{\"blockHash\":\"0x83eaba432089a0bfe99e9fc9022d1cfcb78f95f407821be81737c84ae0b439c5\",\"blockNumber\":\"0x38\",\"contractAddress\":\"0x03d8c4566478a6e1bf75650248accce16a98509f\",\"from\":\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\"to\":\"0x853f43d8a49eeb85d32cf465507dd71d507100c1\",\"cumulativeGasUsed\":\"0x927c0\",\"gasUsed\":\"0x927c0\",\"logs\":[],\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"root\":null,\"transactionHash\":\"0x422fb0d5953c0c48cbb42fb58e1c30f5e150441c68374d70ca7d4f191fd56f26\",\"transactionIndex\":\"0x0\"}";
let receipt_str = "{\"blockHash\":\"0x83eaba432089a0bfe99e9fc9022d1cfcb78f95f407821be81737c84ae0b439c5\",\"blockNumber\":\"0x38\",\"contractAddress\":\"0x03d8c4566478a6e1bf75650248accce16a98509f\",\"from\":\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\",\"to\":\"0x853f43d8a49eeb85d32cf465507dd71d507100c1\",\"cumulativeGasUsed\":\"0x927c0\",\"gasUsed\":\"0x927c0\",\"logs\":[],\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"root\":null,\"transactionHash\":\"0x422fb0d5953c0c48cbb42fb58e1c30f5e150441c68374d70ca7d4f191fd56f26\",\"transactionIndex\":\"0x0\",\"effectiveGasPrice\": \"0x100\"}";

let _receipt: Receipt = serde_json::from_str(receipt_str).unwrap();
}
Expand All @@ -147,7 +156,8 @@ mod tests {
"root": null,
"transactionHash": "0x422fb0d5953c0c48cbb42fb58e1c30f5e150441c68374d70ca7d4f191fd56f26",
"transactionIndex": "0x0",
"status": "0x1"
"status": "0x1",
"effectiveGasPrice": "0x100"
}"#;

let _receipt: Receipt = serde_json::from_str(receipt_str).unwrap();
Expand All @@ -168,7 +178,8 @@ mod tests {
"root": null,
"transactionHash": "0x422fb0d5953c0c48cbb42fb58e1c30f5e150441c68374d70ca7d4f191fd56f26",
"transactionIndex": "0x0",
"status": "0x1"
"status": "0x1",
"effectiveGasPrice": "0x100"
}"#;

let _receipt: Receipt = serde_json::from_str(receipt_str).unwrap();
Expand All @@ -189,7 +200,8 @@ mod tests {
"root": null,
"transactionHash": "0x422fb0d5953c0c48cbb42fb58e1c30f5e150441c68374d70ca7d4f191fd56f26",
"transactionIndex": "0x0",
"status": "0x1"
"status": "0x1",
"effectiveGasPrice": "0x100"
}"#;

let _receipt: Receipt = serde_json::from_str(receipt_str).unwrap();
Expand All @@ -210,7 +222,8 @@ mod tests {
"root": null,
"transactionHash": "0x422fb0d5953c0c48cbb42fb58e1c30f5e150441c68374d70ca7d4f191fd56f26",
"transactionIndex": "0x0",
"status": "0x1"
"status": "0x1",
"effectiveGasPrice": "0x100"
}"#;

let _receipt: Receipt = serde_json::from_str(receipt_str).unwrap();
Expand Down
Loading

0 comments on commit bf70dc2

Please sign in to comment.