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 RET Addresses #10

Merged
merged 52 commits into from
Feb 21, 2024
Merged

Wrap RET Addresses #10

merged 52 commits into from
Feb 21, 2024

Conversation

CyonAlexRDX
Copy link
Contributor

@CyonAlexRDX CyonAlexRDX commented Feb 20, 2024

I've removed the huge Sargon.swift file and gitignored it since I believe we don't need it checked in to git, see gitignore for rationale.

This PR vendors wrapping of RET's new Canonical*Address types, specifically:

  • AccountAddress (changed from existing to use new wrapping solution)
  • IdentityAddress (changed from existing to use new wrapping solution)
  • ResourceAddress (changed from existing to use new wrapping solution)
  • VaultAddress
  • ValidatorAddress
  • AccesscontrollerAddress
  • PoolAddress
  • PackageAddress
  • ComponentAddress

Also simplify how Decimal192 is implemented, removing one level of indirection.

All addresses have been fully Swiftified on the Swift side, including preview values.

The "interface" of ALL address is this (swift version)

public protocol AddressProtocol: Sendable, CustomStringConvertible {
	init(validatingAddress bech32String: String) throws
	var networkID: NetworkID { get }
	var address: String { get }
}

Sajjon and others added 30 commits February 13, 2024 20:50
…requires more fixed size BagOfBytes, introducing: Hex64Bytes, Hex65Bytes, Hex33Bytes, generated with macro.
…ove sccache ref in direnv, it did not speed up things.
… in Package.swift, also required for when making releses.
…e, we can make external types such as Scrypto's Decimal Uniffi compat directly contrary to what I initially believed.
…moving the Inner type since it was not needed.
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

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 realize we might actually git rm --cached Sargon.swift this and then gitignore it. Because it is added part of all releases, and will be present locally...

Hash,
derive_more::Display,
)]
pub struct InnerDecimal(pub(crate) ScryptoDecimal192);
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 had this because I (incorrectly) thought we could not add custom UniFFI conversion for external types, but we can, so no need for this level of indirection.

@@ -88,7 +59,7 @@ pub struct Decimal192 {
/// due to limitations in UniFII as of Feb 2024, but you should
/// create extension methods on Decimal192 in FFI land, translating
/// these functions into methods.)
__inner: InnerDecimal, // Strange field name to try as much as possible hide it in FFI land.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

UniFFI did in fact remove __ prefix...

uniffi::Record,
)]
#[display("{secret_magic}")]
pub struct AccessControllerAddress {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Declare "manually" and NOT by macro so we can add documentation to it! which is not possible with macro_rules! (or at least too hard for me...).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah wrong! we CAN include doc strings in macros, change incoming.

) -> Result<Self>;
}

macro_rules! decl_ret_wrapped_address {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This macro creates the needed UniFFI converter for each RET address, using String as Builtin type. It impl From the wrapped RET address type into the Sargon address type. and all UniFFI exported function

RetAccessControllerAddress,
accesscontroller
);
decl_ret_wrapped_address!(AccountAddress, RetAccountAddress, account);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

N.B. the actual Sargon address types, e.g. AccountAddress, PackageAddress etc are defined in other files, outside of the macro, so that we can add documentation to them, which is not possible to "inject" into macros.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah wrong! we CAN include doc strings in macros, change incoming.

src/sargon.udl Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unfortunate but, c'est la vie, declaring the Ret canonical address as UniFFI convertible via String make implementation of our wrapping of these types easy and allows for safe Rust code, and safe Swift/Kotlin models, so best of two worlds, at the cost of having to declare them here in the UDL file...

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.

Very very nice 👏!

@@ -9,6 +9,7 @@ extend-exclude = [

[default.extend-identifiers]
inout = "inout"
pool_tdx_2_1c4ml86h8lvfk7jma0jy0vksh8srcxhmtax8nd3aur29qtd2k2wmlzk = "pool_tdx_2_1c4ml86h8lvfk7jma0jy0vksh8srcxhmtax8nd3aur29qtd2k2wmlzk"
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Typos CLI tool corrected that address 😅😅 so had to ignore it

@@ -19,37 +19,8 @@ use radix_engine_common::types::EntityType as ScryptoEntityType;
)]
#[repr(u32)] // it is u32 since used in Derivation Paths (CAP26) where each component is a u32.
pub enum AbstractEntityType {
Copy link
Contributor

Choose a reason for hiding this comment

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

So this is meant only to describe an Entity in the sense of either Account or Identity, but not other address kind?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, account or identity only. I can see if I can remove this perhaps


#if DEBUG
/// TODO: Declare in Rust land? Make non-DEBUG?
public enum Address: Hashable, Equatable, Sendable {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will most probably be needed in the iOS Wallet, where we do need to merge together different kinds of addresses in some places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be added in Rust land immediately when I see we really need it. I still - naive perhaps - think we can avoid having it in wallets. Or at least a smaller tagged union (fewer cases)

@CyonAlexRDX CyonAlexRDX changed the title Wrap ret 2 addresses Wrap RET Addresses Feb 21, 2024
@Sajjon
Copy link
Contributor

Sajjon commented Feb 21, 2024

UniFFI macro invocations introduces a lot of false negatives, decreasing the accuracy in reported code coverage, I've asked about if we can improve accuracy in xd009642/tarpaulin#351 (comment)

Will merge this PR as is, nothing we can do.

@CyonAlexRDX CyonAlexRDX merged commit eb0bc7d into develop Feb 21, 2024
10 of 12 checks passed
@CyonAlexRDX CyonAlexRDX deleted the wrap_ret_2_addresses branch February 21, 2024 19:34
CyonAlexRDX pushed a commit that referenced this pull request Apr 1, 2024
Increase code coverage further
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