-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: impl TryFrom<TransactionReceipt> for ReceiptEnvelope
#395
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use crate::{other::OtherFields, ConversionError, Log}; | ||
use alloy_consensus::{Receipt, ReceiptEnvelope, ReceiptWithBloom, TxType}; | ||
use alloy_primitives::{Address, Bloom, Log as PrimitivesLog, LogData, B256, U128, U256, U64, U8}; | ||
use alloy_primitives::{Address, Bloom, B256, U128, U256, U64, U8}; | ||
use itertools::Itertools; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Transaction receipt | ||
|
@@ -75,23 +76,18 @@ impl TransactionReceipt { | |
/// A transaction is considered successful if the status code is `1`. | ||
fn success(&self) -> bool { | ||
match &self.status_code { | ||
Some(status) => status == &U64::from(1), | ||
Some(status) => status.to::<u64>() == 1, | ||
None => false, | ||
} | ||
} | ||
|
||
/// Returns the logs emitted by the transaction. | ||
/// Converts the logs from the RPC type to the internal type. | ||
fn logs(&self) -> Vec<PrimitivesLog<LogData>> { | ||
let mut logs = Vec::new(); | ||
for log in &self.logs { | ||
let rpc_log: Log = log.clone(); | ||
let log_data = LogData::try_from(rpc_log).unwrap_or_default(); | ||
let result = PrimitivesLog { address: log.address, data: log_data }; | ||
logs.push(result); | ||
} | ||
|
||
logs | ||
/// Returns an iterator over the logs for prmitives type conversion. | ||
fn logs_iter( | ||
&self, | ||
) -> impl Iterator<Item = alloy_primitives::Log<alloy_primitives::LogData>> + '_ { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we also want into_logs, so we can consume the type in TryFrom There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
just to confirm, is this what you suggested to have? not 100% sure |
||
self.logs.iter().map(|log| { | ||
alloy_primitives::Log::new_unchecked(log.address, log.topics.clone(), log.data.clone()) | ||
}) | ||
} | ||
} | ||
|
||
|
@@ -103,7 +99,7 @@ impl TryFrom<TransactionReceipt> for ReceiptWithBloom { | |
receipt: Receipt { | ||
success: tx_receipt.success(), | ||
cumulative_gas_used: tx_receipt.cumulative_gas_used.to::<u64>(), | ||
logs: tx_receipt.logs(), | ||
logs: tx_receipt.logs_iter().collect_vec(), | ||
}, | ||
bloom: tx_receipt.logs_bloom, | ||
}; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with changing the
status_code
from U64 to u64 and use a serde_with hex_opt for thisThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean
#[serde(with = "hex")]
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, but we can do this separately
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that status is always 0 or 1, I would also be comfortable just deserializing it to a bool. "real" future compatibility would be a non-exhaustive enum imho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checked #396 , will leave this nit on that PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya sorry for stepping on your PR's toes a bit here. I feel like the infallible conversion will serve your needs better? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no worries, i like embed approach better.
one q is I had checked
impl AsRef<ReceiptEnvelope> for TransactionReceipt
meet the goal what this PR had supposed to, should I have to close the PR?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will talk internally, and then close one of them. If you like the embed approach better, we'll likely go in that direction :)
thank you for making the issue and PR regardless!