-
Notifications
You must be signed in to change notification settings - Fork 273
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
Conversation
impl TryFrom<TransactionReceipt> for ReceiptEnvelope
related to #394 , closed it thought there every conversion had implemented, but realize only for tx |
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.
supportive,
some nits
/// Returns `true` if the transaction was successful. | ||
/// A transaction is considered successful if the status code is `1`. | ||
fn success(&self) -> bool { | ||
match &self.status_code { |
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 this
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.
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!
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
fn into_logs(self) -> impl Iterator<Item = alloy_primitives::Log<alloy_primitives::LogData>> {
self.logs
.into_iter()
.map(|log| alloy_primitives::Log::new_unchecked(log.address, log.topics, log.data))
}
just to confirm, is this what you suggested to have? not 100% sure
impl TryFrom<TransactionReceipt> for ReceiptWithBloom { | ||
type Error = ConversionError; | ||
|
||
fn try_from(tx_receipt: TransactionReceipt) -> Result<Self, Self::Error> { | ||
let receipt_with_bloom = ReceiptWithBloom { | ||
receipt: Receipt { | ||
success: tx_receipt.success(), | ||
cumulative_gas_used: tx_receipt.cumulative_gas_used.to::<u64>(), | ||
logs: tx_receipt.logs_iter().collect_vec(), | ||
}, | ||
bloom: tx_receipt.logs_bloom, | ||
}; | ||
Ok(receipt_with_bloom) | ||
} | ||
} | ||
|
||
impl TryFrom<TransactionReceipt> for ReceiptEnvelope { |
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.
this can also be implemented for &TransactionReceipt, and I'd like to have them as functions of the TransactionReceipt
typ
fn into_(self
fn as_(&self
closing in favor of #396 |
Motivation
alloy_rpc_types::ReceiptEnvelope
toalloy_consensus::ReceiptEnvelope
Solution
PR Checklist