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

Add backwards-compatibility for UMA v0 from v1 SDK #31

Merged
merged 15 commits into from
Mar 21, 2024

Conversation

shreyav
Copy link
Contributor

@shreyav shreyav commented Mar 19, 2024

No description provided.

@shreyav shreyav requested a review from jklein24 March 19, 2024 18:05
@shreyav shreyav marked this pull request as draft March 19, 2024 18:15
@shreyav shreyav marked this pull request as ready for review March 20, 2024 06:39
Copy link
Contributor

@jklein24 jklein24 left a comment

Choose a reason for hiding this comment

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

Very close, but I think there's one fundamental API design piece here where I think we can do better to handle things similar to how our other SDKs do.

* The minimum and maximum amounts that can be sent in this currency and converted from SATs by
* the receiver.
*/
val convertible: CurrencyConvertible,
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems problematic to me that the caller needs to downcast to either V1 or V0 to get the min and max sendable values. These should be mapped up to interface values instead so that callers don't need to care which they're using.

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 this is okay and the caller doesnt need to downcast based on lightsparkdev/kotlin-sdk@d417b30#r140038947, lmk what you think!

Copy link
Contributor

Choose a reason for hiding this comment

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

Well wouldn't they still need to when parsing a currency object from their counterparty? The demo vasp doesn't really do this right now because it doesn't check min/max boundaries, but it probably should. Try to handle these cases in the demo vasp and you'll see what I mean:

  1. As the sending vasp, I need to tell my user what the min and max sendable amounts are in the receiving currency, and should error out if my user tries to send outside those bounds in the payreq.
  2. As the receiving vasp, I should reject a payreq outside of my currency's min/max range.

}

@Serializable
data class CurrencyV1(
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't love that callers need to know anything about whether to construct a CurrencyV1 or CurrencyV0 object. If you look at how the other SDKs behave, the versioning for this object is totally abstracted away from consumers of the SDK. They just construct a Currency object which gets serialized and deserialized as needed via an internal uma version field.

We can definitely still have separate V1 and V0 objects for each class, but those should really just be internal to the SDK and not even exposed publicly if possible.

@OptIn(ExperimentalSerializationApi::class)
@Serializable
data class PayReqResponse(
data class PayReqResponseV1(
Copy link
Contributor

Choose a reason for hiding this comment

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

We should consider making this an internal constructor and ideally even have the whole version-specific objects be internal if possible. Users shouldn't be directly constructing these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated all of the version specific objects to be internal!

Comment on lines 28 to 30
@Serializable(with = ByteArrayAsHexSerializer::class)
private val signingPubKey: ByteArray?,
@Serializable(with = ByteArrayAsHexSerializer::class)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these also need a default value for future-proofing?

Copy link
Contributor

@jklein24 jklein24 left a comment

Choose a reason for hiding this comment

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

Looking good! I still think we need to make sure that the interfaces fully align for currency though. Comment inline

* @return the [Currency] to be sent to the sender VASP.
*/
@JvmOverloads
fun getCurrency(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit (although I know I'm bad about this in a few places):

Suggested change
fun getCurrency(
fun createCurrency(

* @return the [Currency] to be sent to the sender VASP.
*/
@JvmOverloads
fun getCurrency(
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets add a @file:JvmName annotation so that Java callers don't get the gross CurrencyKt name here.

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 the interface name clashes with @file:JvmName("Currency") - updated to be CurrencyUtils

* The minimum and maximum amounts that can be sent in this currency and converted from SATs by
* the receiver.
*/
val convertible: CurrencyConvertible,
Copy link
Contributor

Choose a reason for hiding this comment

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

Well wouldn't they still need to when parsing a currency object from their counterparty? The demo vasp doesn't really do this right now because it doesn't check min/max boundaries, but it probably should. Try to handle these cases in the demo vasp and you'll see what I mean:

  1. As the sending vasp, I need to tell my user what the min and max sendable amounts are in the receiving currency, and should error out if my user tries to send outside those bounds in the payreq.
  2. As the receiving vasp, I should reject a payreq outside of my currency's min/max range.

@shreyav shreyav merged commit 9beefe1 into release/v1.0 Mar 21, 2024
2 checks passed
@shreyav shreyav deleted the feat/bwd-compat branch March 21, 2024 21:33
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