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

Address extend #245

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ extension AccessControllerAddress {
}

public func formatted(_ format: AddressFormat = .default) -> String {
accessControllerAddressFormatted(address: self, format: format)
self.formatted.getString(format)
}

/// The bech32 encoded string for this address.
public var address: String {
accessControllerAddressBech32Address(address: self)
}

public var networkID: NetworkId {
accessControllerAddressNetworkId(address: self)
self.networkId
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,11 @@ extension AccountAddress {
}

public func formatted(_ format: AddressFormat = .default) -> String {
accountAddressFormatted(address: self, format: format)
}

/// The bech32 encoded string for this address.
public var address: String {
accountAddressBech32Address(address: self)
self.formatted.getString(format)
}

public var networkID: NetworkId {
accountAddressNetworkId(address: self)
}

/// Returns `false` for all addresses created with `Ed25519PublicKey`s, i.e.
/// for all accounts created by the Babylon Radix Wallets.
/// Returns `true` for all addresses created with `Secp256k1PublicKey`s, i.e.
/// imported from the Olympia Wallet.
public var isLegacy: Bool {
accountAddressIsLegacy(address: self)
self.networkId
}

/// Formats the AccountAddress to its abbreviated form which is what the user
Expand All @@ -51,7 +38,7 @@ extension AccountAddress {
/// `account_rdx128y6j78mt0aqv6372evz28hrxp8mn06ccddkr7xppc88hyvynvjdwr`
///
public var shortFormat: String {
formatted(AddressFormat.default)
self.formatted(.default)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,21 @@ extension ComponentAddress {
}

public func formatted(_ format: AddressFormat = .default) -> String {
componentAddressFormatted(address: self, format: format)
self.formatted.getString(format)
}

/// The bech32 encoded string for this address.
public var address: String {
componentAddressBech32Address(address: self)
}

public var networkID: NetworkId {
componentAddressNetworkId(address: self)
self.networkId
}

/// If the `EntityType == .globalGenericComponent`
public var isGlobal: Bool {
componentAddressIsGlobal(address: self)
self.kind == .global
}

/// If the `EntityType == .InternalGenericComponent`
public var isInternal: Bool {
componentAddressIsInternal(address: self)
self.kind == .internal
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,11 @@ extension IdentityAddress {
}

public func formatted(_ format: AddressFormat = .default) -> String {
identityAddressFormatted(address: self, format: format)
self.formatted.getString(format)
}

/// The bech32 encoded string for this address.
public var address: String {
identityAddressBech32Address(address: self)
}

public var networkID: NetworkId {
identityAddressNetworkId(address: self)
self.networkId
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ extension LockerAddress {
}

public func formatted(_ format: AddressFormat = .default) -> String {
lockerAddressFormatted(address: self, format: format)
self.formatted.getString(format)
}

/// The bech32 encoded string for this address.
public var address: String {
lockerAddressBech32Address(address: self)
}

public var networkID: NetworkId {
lockerAddressNetworkId(address: self)
self.networkId
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ extension PackageAddress {
}

public func formatted(_ format: AddressFormat = .default) -> String {
packageAddressFormatted(address: self, format: format)
self.formatted.getString(format)
}

/// The bech32 encoded string for this address.
public var address: String {
packageAddressBech32Address(address: self)
}

public var networkID: NetworkId {
packageAddressNetworkId(address: self)
self.networkId
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@ extension PoolAddress {
}

public func formatted(_ format: AddressFormat = .default) -> String {
poolAddressFormatted(address: self, format: format)
self.formatted.getString(format)
}

/// The bech32 encoded string for this address.
public var address: String {
poolAddressBech32Address(address: self)
}

public var networkID: NetworkId {
poolAddressNetworkId(address: self)
self.networkId
}

/// Returns the kind of pool, either 1, 2 or Multi resources.
public var poolKind: PoolKind {
poolAddressKind(address: self)
self.kind
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,28 @@ extension ResourceAddress {
self = try newResourceAddress(bech32: bech32String)
}

/// The bech32 encoded string for this address.
public var address: String {
resourceAddressBech32Address(address: self)
}

public var networkID: NetworkId {
resourceAddressNetworkId(address: self)
self.networkId
}

public func formatted(_ format: AddressFormat = .default) -> String {
resourceAddressFormatted(address: self, format: format)
self.formatted.getString(format)
}

/// If this is an address of a **fungible** resource or not.
public var isFungible: Bool {
resourceAddressIsFungible(address: self)
self.kind == .fungible
}

/// If this is an address of a **non-fungible** resource or not.
public var isNonFungible: Bool {
resourceAddressIsNonFungible(address: self)
self.kind == .nonFungible
}

/// Returns the XRD resource on network identified by `networkID`.
public static func xrd(on networkID: NetworkID) -> Self {
xrdAddressOfNetwork(networkId: networkID)
}

}

#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ extension ValidatorAddress {
}

public func formatted(_ format: AddressFormat = .default) -> String {
validatorAddressFormatted(address: self, format: format)
self.formatted(format)
}

/// The bech32 encoded string for this address.
public var address: String {
validatorAddressBech32Address(address: self)
}

public var networkID: NetworkId {
validatorAddressNetworkId(address: self)
self.networkId
}

}

#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,21 @@ extension VaultAddress {
}

public func formatted(_ format: AddressFormat = .default) -> String {
vaultAddressFormatted(address: self, format: format)
self.formatted.getString(format)
}

/// The bech32 encoded string for this address.
public var address: String {
vaultAddressBech32Address(address: self)
}

public var networkID: NetworkId {
vaultAddressNetworkId(address: self)
self.networkId
}

/// If this is an address of a **fungible** vault or not.
public var isFungible: Bool {
vaultAddressIsFungible(address: self)
self.kind == .fungible
}

/// If this is an address of a **non-fungible** vault or not.
public var isNonFungible: Bool {
vaultAddressIsNonFungible(address: self)
self.kind == .nonFungible
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@ extension NonFungibleGlobalID {
}

public func toRawString() -> String {
nonFungibleGlobalIdToString(globalId: self)
self.asString
}

public func formatted(_ format: AddressFormat = .default) -> String {
nonFungibleGlobalIdFormatted(globalId: self, format: format)
self.formatted.getString(format)
}
}

extension FormattedAddress {
func getString(_ format: AddressFormat) -> String {
switch format {
case .default:
self.default
case .full:
self.full
case .raw:
self.raw
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import SargonUniFFI

extension NonFungibleLocalID {
public func toRawString() -> String {
nonFungibleLocalIdAsStr(id: self)
self.asString
}

public init(integer value: UInt64) {
self = newNonFungibleLocalIdInt(value: value)
}

public func formatted(_ format: AddressFormat = .default) -> String {
nonFungibleLocalIdFormatted(id: self, format: format)
self.formatted.getString(format)
}

public func toUserFacingString() -> String {
nonFungibleLocalIdToUserFacingString(id: self)
self.userFacingString
}

/// Tries to decode an String representation of any NonFungibleLocalID, either:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ extension NonFungibleGlobalID: IdentifiableByStringProtocol {
extension NonFungibleGlobalID {
public init(
nonFungibleResourceAddress: NonFungibleResourceAddress,
localID: NonFungibleLocalID
nonFungibleLocalId: NonFungibleLocalID
) {
self.init(
resourceAddress: nonFungibleResourceAddress.asResourceAddress,
nonFungibleLocalId: localID
)
self = newNonFungibleGlobalId(address: nonFungibleResourceAddress, localId: nonFungibleLocalId)
}

public init(
resourceAddress: ResourceAddress,
nonFungibleLocalId: NonFungibleLocalID
) {
self.init(nonFungibleResourceAddress: NonFungibleResourceAddress(value: resourceAddress), nonFungibleLocalId: nonFungibleLocalId)
}
}
2 changes: 1 addition & 1 deletion crates/sargon-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sargon-uniffi"
# Don't forget to update version in crates/sargon/Cargo.toml
version = "1.1.45"
version = "1.1.46"
edition = "2021"
build = "build.rs"

Expand Down
14 changes: 4 additions & 10 deletions crates/sargon-uniffi/src/profile/v100/address/account_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ decl_ret_wrapped_address!(
///
/// [entt]: https://github.com/radixdlt/radixdlt-scrypto/blob/fc196e21aacc19c0a3dbb13f3cd313dccf4327ca/radix-engine-common/src/types/entity_type.rs
/// [ret]: https://github.com/radixdlt/radix-engine-toolkit/blob/34fcc3d5953f4fe131d63d4ee2c41259a087e7a5/crates/radix-engine-toolkit/src/models/canonical_address_types.rs#L224-L228
account
account,
{
is_legacy: bool = (|internal: InternalAccountAddress| internal.is_legacy_address())
}
);

#[uniffi::export]
Expand Down Expand Up @@ -57,12 +60,3 @@ pub fn new_account_address_sample_stokenet() -> AccountAddress {
pub fn new_account_address_sample_stokenet_other() -> AccountAddress {
InternalAccountAddress::sample_stokenet_other().into()
}

/// Returns `false` for all addresses created with `Ed25519PublicKey`s, i.e.
/// for all accounts created by the Babylon Radix Wallets.
/// Returns `true` for all addresses created with `Secp256k1PublicKey`s, i.e.
/// imported from the legacy Olympia desktop application.
#[uniffi::export]
pub fn account_address_is_legacy(address: &AccountAddress) -> bool {
address.into_internal().is_legacy_address()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ pub enum AddressFormat {
Raw,
Default,
}

#[derive(Clone, PartialEq, Eq, Hash, uniffi::Record)]
pub struct FormattedAddress {
pub full: String,
pub raw: String,
pub default: String,
}
Loading
Loading