Skip to content
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
wants to merge 4 commits into from
Closed

feat: impl TryFrom<TransactionReceipt> for ReceiptEnvelope #395

wants to merge 4 commits into from

Conversation

rkdud007
Copy link

Motivation

  • add conversion from alloy_rpc_types::ReceiptEnvelope to alloy_consensus::ReceiptEnvelope

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@rkdud007 rkdud007 changed the title feat: impl TryFrom<TransactionReceipt> for ReceiptEnvelope feat: impl TryFrom<TransactionReceipt> for ReceiptEnvelope Mar 26, 2024
@rkdud007
Copy link
Author

related to #394 , closed it thought there every conversion had implemented, but realize only for tx

Copy link
Member

@mattsse mattsse left a 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 {
Copy link
Member

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

Copy link
Author

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")]?

Copy link
Member

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

Copy link
Member

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

Copy link
Author

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

Copy link
Member

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? 😅

Copy link
Author

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?

Copy link
Member

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!

crates/rpc-types/src/eth/transaction/receipt.rs Outdated Show resolved Hide resolved
crates/rpc-types/src/eth/transaction/receipt.rs Outdated Show resolved Hide resolved
Comment on lines 85 to 87
fn logs_iter(
&self,
) -> impl Iterator<Item = alloy_primitives::Log<alloy_primitives::LogData>> + '_ {
Copy link
Member

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

Copy link
Author

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

Comment on lines 94 to 110
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 {
Copy link
Member

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

@prestwich
Copy link
Member

closing in favor of #396

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants