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

Wrap SOME of Radix Engine Toolkit types, first of MANY PRs. #3

Merged
merged 26 commits into from
Feb 19, 2024

Conversation

CyonAlexRDX
Copy link
Contributor

@CyonAlexRDX CyonAlexRDX commented Feb 14, 2024

LOC Delta

Fear not the LOC delta, it is the huge generated Swift file mostly.

Introduction

This PR primary solves the so far unsolved challenge of how to implement and vendor Decimal, renamed to Decimal192 as to not collide with Swift Foundations Decimal. 192 comes from the fact that it is powered by a 192 bit integer inside of Scrypto repo (radix_engine_common crate).

I've solved it by ensuring that Decimal192 is a struct/data class in Swift and Kotlin, and NOT a typealias, which HAS a __inner: String which is named like that so to scare Swift/Kotlin devs to not touch it, while keeping it as a thing which has a thing which has a ScryptoDecimal192. This actives the best of two worlds:

  1. Strong typing in Swift and Kotlin
  2. String typing in Rust.

The goal of this PR is to progress the wrapping of RET inside of Sargon, fulfilling the defined "API" by PR: radixdlt/babylon-wallet-ios#1032

This PR also implements, and stubs out some other RET types, and introduces fundamental building blocks such as Secp256k1Signature - UniFFI exposed! and Ed25519Signature also UniFFI exposed, needed by SignedIntent and other RET types.

This PR also contains improvements to the iOS example app

Changes

Changes in Rust land

  • Decimal renamed to Decimal192 and made production ready. Missing some formatting methods
  • Create Hex64, Hex33, Hex64 bytes types, by changing Hex32Bytes to a macro, this allows typesafe, non generic value (due to restrictions in UniFFI) types for bytes, which we can use in Signature types
  • Secp256k1Signature and Ed25519Signature types
  • Nonce
  • Epoch
  • Dummy placeholder RET types
  • Wallet now vendors mnemonic_with_passphrase_of_device_factor_source_by_id which is used by Example wallet to load the mnemonic

Changes in Sargon Swift SPM Package

  • Swift-ify some types in SPM target sargon mostly wrapping freestanding global functions in methods by use of extensions.
  • Make Decimal192 conform to SignedNumeric swift protocol

Changes in Example wallet iOS

  • Make create account a flow, user can select name and appearance ID.
  • Add screen to show mnemonic

Future

Many more PRs to come, all focused on vendoring RET through Sargon..

Copy link

codecov bot commented Feb 14, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (3e9d604) 99.13% compared to head (edd3748) 99.06%.

Files Patch % Lines
src/core/types/hex_32bytes.rs 97.59% 2 Missing ⚠️
src/core/types/decimal192.rs 99.27% 1 Missing ⚠️
src/core/types/epoch.rs 75.00% 1 Missing ⚠️
src/core/types/nonce.rs 83.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop       #3      +/-   ##
===========================================
- Coverage    99.13%   99.06%   -0.08%     
===========================================
  Files          120      128       +8     
  Lines         2663     2891     +228     
===========================================
+ Hits          2640     2864     +224     
- Misses          23       27       +4     

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

@CyonAlexRDX CyonAlexRDX marked this pull request as ready for review February 19, 2024 13:47
@CyonAlexRDX CyonAlexRDX changed the title Wrap radix engine toolkit Wrap SOME of Radix Engine Toolkit types, first of MANY PRs. Feb 19, 2024
@@ -10,4 +10,7 @@ typedef string Timestamp;
[Custom]
typedef sequence<i8> BagOfBytes;

[Custom]
typedef string InnerDecimal;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the trick, we vendor Decimal192 as a struct with one single stored property (field) __inner: InnerDecimal which in the land of Swift and Kotlin will be __inner: String. It is given that name to hide it as much as possible. It is, in fact, NOT a String but the rust type InnerDecimal which in Rust land holds a ScryptoDecimal192.

This is the best compromise, it allwos for usage of a real decimal in Rust land - the ScryptoDecimal192 - and it allows for its OWN type in Swift/Kotlin, and NOT a silly error prone typealias Decimal192 = String.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To Be Written in coming PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stubbing out the API as per radixdlt/babylon-wallet-ios#1032

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stubbing out the API as per radixdlt/babylon-wallet-ios#1032

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stubbing out the API as per radixdlt/babylon-wallet-ios#1032

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stubbing out the API as per radixdlt/babylon-wallet-ios#1032

blobs() method will probably be turned into just field usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Almost ALL methods inits of Decimal as per radixdlt/babylon-wallet-ios#1032 has been implemented, formatting remains.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@micbakos-rdx please re-install the precommit hook

Copy link
Contributor

@GhenadieVP GhenadieVP left a comment

Choose a reason for hiding this comment

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

Awesome, looks promising!
Waiting to see how stuff around TransactionManifest and building will look like 🚀.

// use radix_engine_common::crypto::Ed25519Signature as ScryptoEd25519Signature;
// use radix_engine_common::crypto::Secp256k1Signature as ScryptoSecp256k1Signature;

// /// Represents any natively supported signature, including public key.
Copy link
Contributor

Choose a reason for hiding this comment

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

To implement later?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@CyonAlexRDX CyonAlexRDX merged commit 73af6c9 into develop Feb 19, 2024
10 of 12 checks passed
@CyonAlexRDX CyonAlexRDX deleted the wrap_radix_engine_toolkit branch February 19, 2024 16:45
CyonAlexRDX pushed a commit that referenced this pull request Apr 1, 2024
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.

3 participants