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

Fixing convert number functions for Longs #56

Merged
merged 5 commits into from
Sep 5, 2024

Conversation

matthappens
Copy link
Contributor

@matthappens matthappens commented Sep 5, 2024

Long Serialization

There was an issue serializing longs in UMA Invoices -
most often, the expiration field is a long, since it represents a unix timestamp

This change converts the field to a long and handles serialization/deserialization of said long

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @matthappens and the rest of your teammates on Graphite Graphite

@matthappens matthappens marked this pull request as ready for review September 5, 2024 02:25
@@ -195,7 +195,7 @@ class InvoiceBuilder {
var invoiceUUID: String? = null
var amount: Int? = null
var receivingCurrency: InvoiceCurrency? = null
var expiration: Int? = null
var expiration: Number? = null
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use Number instead of Long directly? I think we're going to need to be explicit about 64-bit ints to be consistent, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

converted all back to Int / Long, it's a bit clearer. during serialization, the values will be converted to their smallest possible representation, so Long fields might actually be serialized as small as a byte, but this detail is now better hidden inside of the getLong/getInt functions

@@ -77,7 +77,7 @@ data class Invoice(
/** The currency of the invoice */
val receivingCurrency: InvoiceCurrency,
/** The unix timestamp the UMA invoice expires */
val expiration: Int,
val expiration: Number,
Copy link
Contributor

Choose a reason for hiding this comment

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

This one should be a Long then, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, it should. I'll switch amount to long as well, to cover msat

@@ -141,12 +141,12 @@ data class Invoice(
when (bytes[offset].toInt()) {
0 -> ib.receiverUma = bytes.getString(offset.valueOffset(), length)
1 -> ib.invoiceUUID = bytes.getString(offset.valueOffset(), length)
2 -> ib.amount = bytes.getNumber(offset.valueOffset(), length)
2 -> ib.amount = bytes.getInt(offset.valueOffset(), length)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a long too? Could just see for units like msats, this could get pretty big. Not sure if @zhenlu was thinking of this as an int or long, though. I know it's a Long in UMA generally.

Copy link
Contributor Author

@matthappens matthappens left a comment

Choose a reason for hiding this comment

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

I also just changed the getInvoice function to use an internal UMA VERSION string, rather than pass as a parameter (this was done in the JS sdk as well)

@matthappens matthappens merged commit 826b5a8 into main Sep 5, 2024
3 checks passed
@matthappens matthappens deleted the mrdavis/uma-sdk-long-serialization branch September 5, 2024 17:04
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