Skip to content

Receiver checks - #19

Closed
RCasatta wants to merge 2 commits into
Kixunil:masterfrom
RCasatta:receiver
Closed

RCasatta wants to merge 2 commits into
Kixunil:masterfrom
RCasatta:receiver

Conversation

@RCasatta

@RCasatta RCasatta commented Aug 4, 2021

Copy link
Copy Markdown
Collaborator

On top of #17, see only a6aebbb

This is some WIP code (especially Errors and unwrap) but if you can give early feedback on receiver checks through the Checks trait it would be appreciated

@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.

The reason I started modeling it as type-based state machine is I didn't want to assume sync vs async. That trait now forces it to be sync which goes against the goals of the crate.
It may be little less comfortable to write for some people but I think the difference is minimal and it's also somewhat counter-balanced by not having to write trait-impl-related boilerplate.

Comment thread bip78/src/receiver/mod.rs
}

pub fn create_uri(address: &Address, amount: &Amount, pj: &str) -> String {
format!("{}?amount={}&pj={}", address.to_qr_uri(), amount.as_btc(), pj)

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.

FTR, this needs to be URL encoded.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Are we going to add URL dep? for this and for #3 ?

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.

IDK, I would really, really like to move BIP21 to bitcoin and folks there are mostly averse to dependencies. I think encoding is not that hard to do manually if we have to.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I thought we can have BIP21 stuff without URL but with Extras inside rust-bitcoin and then this payjoin separated repo leveraging BIP21 parsing but with a layer on top using also URL

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.

Encoding belongs to BIP21 because it's also used for description etc. If we use a dependency there it should be percent-encoding because url seems to have web semantics.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

are we sure we need to percent-encode pj?

it looks btcpay doesn't percent encode neither I found mention in the bip

@RCasatta

RCasatta commented Aug 5, 2021

Copy link
Copy Markdown
Collaborator Author

The reason I started modeling it as type-based state machine is I didn't want to assume sync vs async. That trait now forces it to be sync which goes against the goals of the crate.
It may be little less comfortable to write for some people but I think the difference is minimal and it's also somewhat counter-balanced by not having to write trait-impl-related boilerplate.

Right, I didn't think about async...

Did you consider implementing the state with phantom data? Something like:

struct PsbtState<S> {
   psbt: PartiallySignedTransaction,
   state: PhantomData<S>
}

@Kixunil

Kixunil commented Aug 5, 2021

Copy link
Copy Markdown
Owner

Yeah, having state as generic would be nicer. I didn't realize at first there are more states than two and then just kept adding them without more thinking.

@RCasatta

RCasatta commented Aug 5, 2021

Copy link
Copy Markdown
Collaborator Author

Is it naive to think you can provide something similar to the Checks trait in sync and async version and support both?

(or only one available through a feature)

@RCasatta

RCasatta commented Aug 5, 2021 •

Copy link
Copy Markdown
Collaborator Author

Is it naive to think you can provide something similar to the Checks trait in sync and async version and support both?

Probably yes, as async are not yet available in traits...

However maybe_async! macro is achieving that, also using async-trait crate

@Kixunil

Kixunil commented Aug 5, 2021

Copy link
Copy Markdown
Owner

Is it naive to think you can provide something similar to the Checks trait in sync and async version and support both?

I was actually researching this topic in the past and concluded it's impossible to do without either loss of performance or having both GAT and a slightly different Future trait. Not that I'd think that much performance loss matters here (one more branch and one more allocation, I think) but I find the result pretty complicated. Also I expect non-async version of at least unbroadcastable method to be blocking which could cause a lot of complication and confusion if accidentally mixed with async.

@RCasatta

RCasatta commented Aug 6, 2021

Copy link
Copy Markdown
Collaborator Author

if accidentally mixed with async

I don't get how you can mix it together, we provide the async version or the other, could you have a look at https://github.com/bitcoindevkit/bdk/blob/5cdc5fb58a4635ce6a302093c78b511255bbc1a3/macros/src/lib.rs#L89 ?

I think providing a trait could make the work of implementers less error-prone

@Kixunil

Kixunil commented Aug 6, 2021 •

Copy link
Copy Markdown
Owner

I'm not familiar with maybe_async, I assumed it will just turn sync values into ready, which could be problematic. Would have to inspect it deeply to tell if there's an issue.

I think providing a trait could make the work of implementers less error-prone

I don't see a huge difference. Could you provide a specific example where error is less likely with trait?

@RCasatta

RCasatta commented Aug 6, 2021

Copy link
Copy Markdown
Collaborator Author

I don't see a huge difference. Could you provide a specific example where error is less likely with trait?

Yeah maybe they are equally likely, I just feel that calling this_is_purely_interactive_wallet() because you are lazy/not-understanding the check you have to do is easier than implementing a trait with all the methods returning false.

But yeah, now I am more convinced that maybe it's not worth the complexity of maybe_async and async-trait

@Kixunil

Kixunil commented Aug 6, 2021

Copy link
Copy Markdown
Owner

OK, let's use state approach. If someone comes up with strong reason to switch we can revisit it.

@RCasatta RCasatta closed this Aug 6, 2021
@RCasatta RCasatta mentioned this pull request Sep 13, 2021
@DanGould DanGould mentioned this pull request Jul 6, 2022
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