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

Changes required by RGB wallet PSBT operations #113

Merged
merged 32 commits into from
Dec 25, 2023
Merged

Changes required by RGB wallet PSBT operations #113

merged 32 commits into from
Dec 25, 2023

Conversation

dr-orlovsky
Copy link
Member

Also includes support for combined tapret/opret commitments.

Mostly ready - will mark for review the moment wallet library will produce PSBTs.

@dr-orlovsky dr-orlovsky added epic Epic task covering multiple steps of implementation refactoring Code refactoring labels Dec 15, 2023
Copy link
Member

@cryptoquick cryptoquick left a comment

Choose a reason for hiding this comment

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

That was a lot of work! Just a couple of concerns... The unsafes make me nervous. If they're necessary, then maybe put some time into documenting why they need to be unsafe.

impl Display for CoinAmount {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let mut int = self.int.to_string();
if f.alternate() {
Copy link
Member

Choose a reason for hiding this comment

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

What is this? Why chunks of 3 bytes? Is unsafe really necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unsafe is required because of from_utf8_unchecked - since we are sure the string is UTF8

Chunks of three bytes to print the separators: 100'000'000

#[allow(clippy::result_large_err)]
impl RgbInvoiceBuilder {
pub fn new(beneficiary: impl Into<Beneficiary>) -> Self {
Self(RgbInvoice {
Copy link
Member

Choose a reason for hiding this comment

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

I would recommend implementing Default, moving this there, then using Default::default() here.

Copy link
Member Author

Choose a reason for hiding this comment

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

With Default you will get an invalid invoice: no transports, no beneficiary; and this will require converting finish to return Result type (and introducing another error type). I am not sure this is better.

) -> Result<(), InventoryError<Self::Error>>;

/// # Safety
Copy link
Member

Choose a reason for hiding this comment

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

Can you re-add the docs for the unsafe code? Just indicating why unsafe and under what conditions

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed it so it since it will not be seen anyway due to the added doc(hidden) method... I do not know how to hide such things properly and at the same time provide those implementing the trait with enough info...

@@ -471,20 +462,19 @@ impl Inventory for Stock {
self.consume_consignment(transfer, resolver, force)
}

fn consume_anchor(
unsafe fn consume_anchor(
Copy link
Member

Choose a reason for hiding this comment

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

Why unsafe?

Copy link
Member Author

Choose a reason for hiding this comment

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

To prevent it from being called from any place other than the clearly defined single place.

Not a best practice, I know - but it is easier not to mistake/miss invalid calls in this way

invoice/src/lib.rs Outdated Show resolved Hide resolved
@dr-orlovsky dr-orlovsky changed the title Changes required by RGB wallet PSBT operations Comlete transfers with PSBT construction and tapret commitments Dec 18, 2023
@dr-orlovsky dr-orlovsky changed the title Comlete transfers with PSBT construction and tapret commitments Complete transfers with PSBT construction and tapret commitments Dec 18, 2023
@dr-orlovsky dr-orlovsky added this to the v0.11.0 milestone Dec 18, 2023
@dr-orlovsky dr-orlovsky marked this pull request as ready for review December 18, 2023 20:17
@dr-orlovsky dr-orlovsky changed the title Complete transfers with PSBT construction and tapret commitments Changes required by RGB wallet PSBT operations Dec 18, 2023
@dr-orlovsky dr-orlovsky merged commit 24c9909 into master Dec 25, 2023
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic Epic task covering multiple steps of implementation refactoring Code refactoring
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

3 participants