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

Bring resource and offering data structures up to latest spec #56

Merged
merged 1 commit into from
May 3, 2024

Conversation

KendallWeihe
Copy link
Contributor

Closes #55

Some implications in these changes which will span to subsequent changes (please object if you take issue):

  • signatures shouldn't be optional (Option<T> type) because that isn't how they exist in the spec. this implies that during the create() we will create the signatures (that is TODO, added comment linking to relevant ticket).
  • we're going to follow a create(options: CreateOptions) paradigm as opposed to inlining all the parameters
  • removed a function required_payment_details_schema which may become relevant again once we address Consider strongly typing JSON Schema types, or using an existing open source lib #54 but for now it's not relevant

Created tickets for subsequent work during this work:


/// Struct that interacts with an [`Offering`] [`Resource`]
pub struct Offering;

/// Struct for passing parameters to [`Offering::create`]
#[derive(Debug, Default)]
Copy link
Contributor

Choose a reason for hiding this comment

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

you mean to leave this Debug flag in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a good callout. The Debug attribute makes it such that the struct automatically implements the std::fmt::Debug trait. The primary use case is for print statements wherein the developer can use {:?} which will print the struct in human readable form. It's totally safe to do this even in production code. The only place we won't want to do this is in places which we know will include PII data. Even then it would be fine but we would reduce the likelihood of accidental abuse, where developers may accidentally log PII.

pub currency_code: String,
/// Minimum amount of currency that the offer is valid for
pub min_subunits: Option<String>,
pub min: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

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

| min | DecimalString | N | minimum amount required to use this payment method.

Is it supposed to be a DecimalString and not string? or they are one in the same?

Just for my understanding, I'm sure this has been thought of a long time ago and I missed it:

from to docs:
DecimalString
Currency amounts have type DecimalString, which is string containing a decimal amount of major currency units. The decimal separator is a period .. The currency symbol must be omitted.

I'm not sure but I have a feeling that most other financial apps use a uint or something to count the satoshi or cents or pesos at the lowest level

Chad says:
To address these issues, a better approach would typically involve using a specialized numeric type designed for handling monetary values. In Rust, you might consider using types like:

i64 or u64: These types can store monetary values as the smallest units of the currency (like cents in USD) to avoid precision issues with floating points.

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 created a ticket for this #53

Basically, it needs to be of type string, but we may be able to add a slightly more constrained type which prohibits non-decimal values

Base automatically changed from kendall/plural-concepts to main April 30, 2024 18:39
@KendallWeihe KendallWeihe force-pushed the kendall/resources-latest-structs branch from 1874714 to bf81765 Compare April 30, 2024 18:40
@KendallWeihe KendallWeihe merged commit c5c234e into main May 3, 2024
6 checks passed
@KendallWeihe KendallWeihe deleted the kendall/resources-latest-structs branch May 3, 2024 18:58
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.

Update resource and offering data structures to latest spec
4 participants