Skip to content

Commit f9c6c0c

Browse files
committed
XC-412: Formatting
1 parent c82f1a6 commit f9c6c0c

File tree

5 files changed

+394
-235
lines changed

5 files changed

+394
-235
lines changed

evm_rpc_client/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,18 @@ pub mod fixtures;
107107
mod request;
108108
mod runtime;
109109

110-
use crate::request::{CallRequest, CallRequestBuilder, FeeHistoryRequest, FeeHistoryRequestBuilder, GetBlockByNumberRequest, GetBlockByNumberRequestBuilder, GetTransactionCountRequest, GetTransactionCountRequestBuilder, GetTransactionReceiptRequest, GetTransactionReceiptRequestBuilder, Request, RequestBuilder, SendRawTransactionRequest, SendRawTransactionRequestBuilder};
110+
use crate::request::{
111+
CallRequest, CallRequestBuilder, FeeHistoryRequest, FeeHistoryRequestBuilder,
112+
GetBlockByNumberRequest, GetBlockByNumberRequestBuilder, GetTransactionCountRequest,
113+
GetTransactionCountRequestBuilder, GetTransactionReceiptRequest,
114+
GetTransactionReceiptRequestBuilder, Request, RequestBuilder, SendRawTransactionRequest,
115+
SendRawTransactionRequestBuilder,
116+
};
111117
use candid::{CandidType, Principal};
112-
use evm_rpc_types::{BlockTag, CallArgs, ConsensusStrategy, FeeHistoryArgs, GetLogsArgs, GetTransactionCountArgs, Hex, Hex32, RpcConfig, RpcServices};
118+
use evm_rpc_types::{
119+
BlockTag, CallArgs, ConsensusStrategy, FeeHistoryArgs, GetLogsArgs, GetTransactionCountArgs,
120+
Hex, Hex32, RpcConfig, RpcServices,
121+
};
113122
use ic_error_types::RejectCode;
114123
use request::{GetLogsRequest, GetLogsRequestBuilder};
115124
pub use runtime::{IcRuntime, Runtime};
@@ -565,7 +574,9 @@ impl<R> EvmRpcClient<R> {
565574
/// # block_number: Nat256::from(0x52a975_u64),
566575
/// # effective_gas_price: Nat256::from(0x6052340_u64),
567576
/// # gas_used: Nat256::from(0x1308c_u64),
577+
/// # cumulative_gas_used: Nat256::from(0x797db0_u64),
568578
/// # status: Some(Nat256::from(0x1_u8)),
579+
/// # root: None,
569580
/// # transaction_hash: Hex32::from_str("0xa3ece39ae137617669c6933b7578b94e705e765683f260fcfe30eaa41932610f").unwrap(),
570581
/// # contract_address: None,
571582
/// # from: Hex20::from_str("0xd907941c8b3b966546fc408b8c942eb10a4f98df").unwrap(),

evm_rpc_types/src/response/alloy.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,15 @@ impl TryFrom<TransactionReceipt> for alloy_rpc_types::TransactionReceipt {
139139
alloy_consensus::TxType::try_from(receipt.tx_type)?,
140140
alloy_consensus::ReceiptWithBloom {
141141
receipt: alloy_consensus::Receipt {
142-
status: validate_receipt_status(&receipt.block_number, receipt.status)?,
143-
// TODO XC-412: This field is required, why is it missing from `evm_rpc_types::TransactionReceipt`?
144-
cumulative_gas_used: 0,
142+
status: validate_receipt_status(
143+
&receipt.block_number,
144+
receipt.root,
145+
receipt.status,
146+
)?,
147+
cumulative_gas_used: try_from_nat256(
148+
receipt.cumulative_gas_used,
149+
"cumulative_gas_used",
150+
)?,
145151
logs: receipt
146152
.logs
147153
.into_iter()
@@ -176,13 +182,11 @@ impl TryFrom<HexByte> for alloy_consensus::TxType {
176182
type Error = RpcError;
177183

178184
fn try_from(value: HexByte) -> Result<Self, Self::Error> {
179-
Ok(
180-
alloy_consensus::TxType::try_from(value.into_byte()).map_err(|e| {
181-
RpcError::ValidationError(ValidationError::Custom(format!(
182-
"Unable to parse transaction type: {e:?}"
183-
)))
184-
})?,
185-
)
185+
alloy_consensus::TxType::try_from(value.into_byte()).map_err(|e| {
186+
RpcError::ValidationError(ValidationError::Custom(format!(
187+
"Unable to parse transaction type: {e:?}"
188+
)))
189+
})
186190
}
187191
}
188192

@@ -192,32 +196,35 @@ fn validate_difficulty(number: &Nat256, difficulty: Option<Nat256>) -> Result<U2
192196
difficulty
193197
.map(U256::from)
194198
.ok_or(RpcError::ValidationError(ValidationError::Custom(
195-
"Missing difficulty in pre-Paris block".into(),
199+
"Missing difficulty field in pre Paris upgrade block".into(),
196200
)))
197201
} else {
198202
match difficulty.map(U256::from) {
199203
None | Some(U256::ZERO) => Ok(U256::ZERO),
200204
_ => Err(RpcError::ValidationError(ValidationError::Custom(
201-
"Post-Paris block has non-zero difficulty".into(),
205+
"Post Paris upgrade block has non-zero difficulty".into(),
202206
))),
203207
}
204208
}
205209
}
206210

207211
fn validate_receipt_status(
208212
number: &Nat256,
213+
root: Option<Hex32>,
209214
status: Option<Nat256>,
210215
) -> Result<alloy_consensus::Eip658Value, RpcError> {
211216
const BYZANTIUM_BLOCK: u64 = 4_370_000;
212217
if number.as_ref() < &Nat::from(BYZANTIUM_BLOCK) {
213-
// TODO XC-412: How do we want to handle pre-Byzantium blocks?
214-
Err(RpcError::ValidationError(ValidationError::Custom(
215-
"Missing state root in pre-Byzantium receipt".into(),
216-
)))
218+
match root {
219+
None => Err(RpcError::ValidationError(ValidationError::Custom(
220+
"Missing root field in transaction included before the Byzantium upgrade".into(),
221+
))),
222+
Some(root) => Ok(alloy_consensus::Eip658Value::PostState(B256::from(root))),
223+
}
217224
} else {
218225
match status.map(U256::from) {
219226
None => Err(RpcError::ValidationError(ValidationError::Custom(
220-
"Missing status in post-Byzantium receipt".into(),
227+
"Missing status field in transaction included after the Byzantium upgrade".into(),
221228
))),
222229
Some(U256::ZERO) => Ok(alloy_consensus::Eip658Value::Eip658(false)),
223230
Some(U256::ONE) => Ok(alloy_consensus::Eip658Value::Eip658(true)),

src/rpc_client/tests.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ mod eth_get_transaction_receipt {
117117
)
118118
}
119119

120-
121-
122120
#[test]
123121
fn should_deserialize_post_byzantium_transaction_receipt() {
124122
const RECEIPT: &str = r#"{

tests/mock_http_runtime/mock/json/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ impl CanisterHttpRequestMatcher for JsonRpcRequestMatcher {
142142
}
143143
}
144144

145+
#[derive(Clone)]
145146
pub struct JsonRpcResponse {
146147
pub status: u16,
147148
pub headers: Vec<CanisterHttpHeader>,

0 commit comments

Comments
 (0)