Skip to content

States for receiver flow - #23

Closed
RCasatta wants to merge 1 commit into
Kixunil:masterfrom
RCasatta:rec_state
Closed

RCasatta wants to merge 1 commit into
Kixunil:masterfrom
RCasatta:rec_state

Conversation

@RCasatta

Copy link
Copy Markdown
Collaborator

Remake of #19 that should be agnostic about sync/async

It's similar to the original but has one state for every needed check

Can't use PhantomData to represent the state because it needs to store at least a boolean

Very WIP, just wanted to have feedback before continuing here

@Kixunil Kixunil left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what problem you're trying to solve by putting data into type state. It looks like you only do it to get specific errors of the same type, so that user doesn't need to define an error type. This could be solved by just providing the error type.

Note that my idea was for checking code to be written like this:

let proposal = UncheckedProposal::from_request(...)?;
let tx = proposal.get_transaction_to_check_broadcast();
// do testmempoolaccept call with tx
if !broadcastable {
    // We could simply allow writing return Err(proposal.not_broadcastable()) to generate error with context.
    return Err(MyError::NotBroadcastableError);
}
let proposal = proposal.assume_broadcastability_was_verified();
// ... same style for other checks

/// Validate a [`PartiallySignedTransaction`] by checking transaction inputs number are equal to the
/// psbt inputs and the same for outputs. Note deserialization already have this guarantee (TODO verify)
#[derive(Clone, Debug)]
pub struct Validated;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated sounds like all checks were finished. Perhaps call it Consistent?

Err(PsbtError::UnequalInputCounts { tx_ins, psbt_ins, })
} else if psbt_outs != tx_outs {
Err(PsbtError::UnequalOutputCounts { tx_outs, psbt_outs, })
} else {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a newtype for this

@RCasatta

Copy link
Copy Markdown
Collaborator Author

I don't understand what problem you're trying to solve by putting data into type state

support std::convert::TryFrom

Note that my idea was for checking code to be written like this:

Yes, I know. My intention was to have one check per state to be less error prone for users

@Kixunil

Kixunil commented Sep 13, 2021

Copy link
Copy Markdown
Owner

support std::convert::TryFrom

Any particular reason? I don't see how TryFrom is helpful.

have one check per state

That was already the case wasn't it? Maybe I misunderstand?

@RCasatta

Copy link
Copy Markdown
Collaborator Author

That was already the case wasn't it? Maybe I misunderstand?

Yeah maybe it's just missing the check if inputs are owned

Any particular reason? I don't see how TryFrom is helpful.

Yeah maybe is unnecessary complication

@RCasatta RCasatta closed this Sep 13, 2021
@DanGould DanGould mentioned this pull request Jul 6, 2022
DanGould referenced this pull request in DanGould/rust-payjoin Feb 6, 2023
Abstract receive into a library
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.

2 participants