Skip to content

Conversation

@astral-bitlight
Copy link
Contributor

No description provided.

@astral-bitlight
Copy link
Contributor Author

Since RgbInvoice is currently a type alias for CallRequest, we can’t directly implement methods like new() on it. To address this, I propose refactoring it into a newtype wrapper (a zero-cost abstraction) with an explicit constructor

@astral-bitlight astral-bitlight marked this pull request as ready for review April 18, 2025 08:12
@codecov
Copy link

codecov bot commented Apr 19, 2025

Codecov Report

Attention: Patch coverage is 0% with 28 lines in your changes missing coverage. Please review.

Project coverage is 4.1%. Comparing base (79e68c1) to head (acb8248).
Report is 151 commits behind head on v0.12.

Files with missing lines Patch % Lines
invoice/src/lib.rs 0.0% 28 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##           v0.12   #305     +/-   ##
======================================
- Coverage    4.9%   4.1%   -0.7%     
======================================
  Files         11     13      +2     
  Lines       1298   1553    +255     
======================================
+ Hits          63     64      +1     
- Misses      1235   1489    +254     
Flag Coverage Δ
rust 4.1% <0.0%> (-0.7%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

Can you please also fix the clippy lints?

Comment on lines 133 to 144
pub fn new(
scope: T,
beneficiary: RgbBeneficiary,
// Core parameters
value: Option<u64>,
expiry_time: Option<DateTime<Utc>>,
// Additional fields
api: Option<TypeName>,
call: Option<CallState>,
lock: Option<TinyBlob>,
endpoints: Option<impl Into<ConfinedVec<Endpoint, 0, 10>>>,
) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

This is why I prefer (and rust guidelines) recommend builders in such cases: calls to functions with too many unnamed arguments (some of which will be just Nones) hard to read in the code. Clippy also grumbles about this.

Why you are not satisfied with the builder we have for the invoices?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think using the builder is totally ok, which is why this PR was initially marked as a draft

api: Option<TypeName>,
call: Option<CallState>,
lock: Option<TinyBlob>,
endpoints: Option<impl Into<ConfinedVec<Endpoint, 0, 10>>>,
Copy link
Member

Choose a reason for hiding this comment

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

this rather should be

Suggested change
endpoints: Option<impl Into<ConfinedVec<Endpoint, 0, 10>>>,
endpoints: impl IntoIterator<Endpoint>,

And the method should panic if too many endpoints are provided

Bp(bp::ParseWitnessOutError),
}

pub struct RgbInvoice<T: Display + FromStr>(CallRequest<T, RgbBeneficiary>);
Copy link
Member

Choose a reason for hiding this comment

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

I think we still should have the default value here. Also we need derives

Suggested change
pub struct RgbInvoice<T: Display + FromStr>(CallRequest<T, RgbBeneficiary>);
#[derive(Clone, Eq, PartialEq, Debug, From)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "serde",
serde(
transparent,
bound(
serialize = "T: serde::Serialize, A: serde::Serialize",
deserialize = "T: serde::Deserialize<'de>, A: serde::Deserialize<'de>"
)
)
)]
pub struct RgbInvoice<T: Display + FromStr = CallScope<ContractQuery>>(CallRequest<T, RgbBeneficiary>);

@astral-bitlight
Copy link
Contributor Author

I've added serde support and fixed constructor param issue

@dr-orlovsky
Copy link
Member

@astral-bitlight is this PR is still actual and needed?

@astral-bitlight
Copy link
Contributor Author

We can closed it for now

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