-
Notifications
You must be signed in to change notification settings - Fork 1
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
Account locker in manifest summary encountered entities #213
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1e111e2
Add locker execution summary test
sergiupuhalschi-rdx 5789df3
Add locker address to manifest encountered entities
sergiupuhalschi-rdx 816bc9c
Version bump
sergiupuhalschi-rdx 6e73c14
Add kotlin and swift
sergiupuhalschi-rdx 591b4cf
Add swift tests
sergiupuhalschi-rdx 9e402dc
Potential fix for disk space issue in kotlin tests workflow
sergiupuhalschi-rdx 41f6b7a
Update kotlin workflow
sergiupuhalschi-rdx a22a112
Update kotlin test workflow
sergiupuhalschi-rdx ce241d6
Revert "Update kotlin test workflow"
sergiupuhalschi-rdx e42b281
Name refactoring
sergiupuhalschi-rdx 354e519
Improve kotlin coverage
sergiupuhalschi-rdx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
...Sources/Sargon/Extensions/Methods/Address/ManifestEncounteredAddress+Wrap+Functions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import SargonUniFFI | ||
|
||
extension ManifestEncounteredAddress { | ||
public init(validatingAddress bech32String: String) throws { | ||
self = try newManifestEncounteredAddressFromBech32(string: bech32String) | ||
} | ||
|
||
/// The bech32 encoded string for this address. | ||
public var address: String { | ||
manifestEncounteredAddressToString(address: self) | ||
} | ||
|
||
public var networkID: NetworkId { | ||
manifestEncounteredAddressNetworkId(address: self) | ||
} | ||
|
||
public func formatted(_ format: AddressFormat) -> String { | ||
manifestEncounteredAddressFormatted(address: self, format: format) | ||
} | ||
|
||
|
||
} | ||
|
||
#if DEBUG | ||
extension ManifestEncounteredAddress { | ||
public static func random(networkID: NetworkID) -> Self { | ||
.component(newComponentAddressRandom(networkId: networkID)) | ||
} | ||
|
||
public func mapTo(networkID: NetworkID) -> Self { | ||
manifestEncounteredAddressMapToNetwork(address: self, networkId: networkID) | ||
} | ||
} | ||
#endif // DEBUG |
12 changes: 12 additions & 0 deletions
12
...sions/SampleValues/Profile+Supporting+Types/ManifestEncounteredAddress+SampleValues.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Foundation | ||
import SargonUniFFI | ||
|
||
#if DEBUG | ||
extension ManifestEncounteredAddress { | ||
public static let sampleMainnet: Self = newManifestEncounteredAddressSampleMainnet() | ||
public static let sampleMainnetOther: Self = newManifestEncounteredAddressSampleMainnetOther() | ||
|
||
public static let sampleStokenet: Self = newManifestEncounteredAddressSampleStokenet() | ||
public static let sampleStokenetOther: Self = newManifestEncounteredAddressSampleStokenetOther() | ||
} | ||
#endif |
10 changes: 10 additions & 0 deletions
10
.../Sources/Sargon/Extensions/Swiftified/Address/ManifestEncounteredAddress+Swiftified.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import SargonUniFFI | ||
|
||
extension ManifestEncounteredAddress: AddressProtocol { | ||
public var asGeneral: Address { | ||
switch self { | ||
case let .component(componentAddress): Address.component(componentAddress) | ||
case let .locker(lockerAddress): Address.locker(lockerAddress) | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
apple/Tests/TestCases/Address/ManifestEncounteredAddressTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import CustomDump | ||
import Foundation | ||
import Sargon | ||
import SargonUniFFI | ||
import XCTest | ||
|
||
final class ManifestEncounteredAddressTests: AddressTest<ManifestEncounteredAddress> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "sargon" | ||
version = "1.1.12" | ||
version = "1.1.13" | ||
edition = "2021" | ||
build = "build.rs" | ||
|
||
|
1 change: 1 addition & 0 deletions
1
crates/sargon/fixtures/transaction/account_locker_claim_fungibles_and_non_fungibles.dat
Large diffs are not rendered by default.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
crates/sargon/fixtures/transaction/account_locker_claim_fungibles_and_non_fungibles.rtm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
CALL_METHOD | ||
Address("locker_tdx_2_1drgp40wpu5cj0zady4s0pec6rld8muge0j2xx9xuwwc474uzlgja6a") | ||
"claim" | ||
Address("account_tdx_2_12xlu6x99ssrwrs8cnafka8476ursxfyfde3kfyk7d4s9c5kdvcs77x") | ||
Address("resource_tdx_2_1nflxr7dvp29hxhjjp53strsdgv2kv9dxlx6ys52lafrgyljrhwkt27") | ||
Decimal("4") | ||
; | ||
TAKE_FROM_WORKTOP | ||
Address("resource_tdx_2_1nflxr7dvp29hxhjjp53strsdgv2kv9dxlx6ys52lafrgyljrhwkt27") | ||
Decimal("4") | ||
Bucket("bucket1") | ||
; | ||
CALL_METHOD | ||
Address("account_tdx_2_12xlu6x99ssrwrs8cnafka8476ursxfyfde3kfyk7d4s9c5kdvcs77x") | ||
"deposit" | ||
Bucket("bucket1") | ||
; | ||
CALL_METHOD | ||
Address("locker_tdx_2_1drgp40wpu5cj0zady4s0pec6rld8muge0j2xx9xuwwc474uzlgja6a") | ||
"claim" | ||
Address("account_tdx_2_12xlu6x99ssrwrs8cnafka8476ursxfyfde3kfyk7d4s9c5kdvcs77x") | ||
Address("resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc") | ||
Decimal("30") | ||
; | ||
TAKE_FROM_WORKTOP | ||
Address("resource_tdx_2_1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxtfd2jc") | ||
Decimal("30") | ||
Bucket("bucket2") | ||
; | ||
CALL_METHOD | ||
Address("account_tdx_2_12xlu6x99ssrwrs8cnafka8476ursxfyfde3kfyk7d4s9c5kdvcs77x") | ||
"deposit" | ||
Bucket("bucket2") | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...ped_radix_engine_toolkit/high_level/sargon_specific_types/manifest_encountered_address.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use crate::prelude::*; | ||
|
||
address_union!( | ||
/// A tagged union of all the encountered addresses in the manifest. | ||
/// This is to be primarily used for the "using dApps" section of the wallet's tx review screen. | ||
enum ManifestEncounteredAddress: component, locker | ||
); | ||
|
||
macro_rules! impl_try_from_for_manifest_encountered_address { | ||
($($variant:ident => $address_type:ty),*) => { | ||
impl TryFrom<(ScryptoGlobalAddress, NetworkID)> for ManifestEncounteredAddress { | ||
type Error = CommonError; | ||
|
||
fn try_from(value: (ScryptoGlobalAddress, NetworkID)) -> Result<Self> { | ||
let (global_address, network_id) = value; | ||
|
||
$( | ||
if let Ok(address) = <$address_type>::try_from((global_address, network_id)) { | ||
return Ok(ManifestEncounteredAddress::$variant(address)); | ||
} | ||
)* | ||
|
||
Err(CommonError::FailedToCreateAddressFromGlobalAddressAndNetworkID { | ||
global_address_as_hex: global_address.to_hex(), | ||
network_id, | ||
}) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_try_from_for_manifest_encountered_address!( | ||
Component => ComponentAddress, | ||
Locker => LockerAddress | ||
); | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[allow(clippy::upper_case_acronyms)] | ||
type SUT = ManifestEncounteredAddress; | ||
|
||
#[test] | ||
fn sample_values_count() { | ||
let mut set = HashSet::<SUT>::new(); | ||
set.extend(SUT::sample_values_all()); | ||
// Duplicates should be removed | ||
set.extend(SUT::sample_values_all()); | ||
|
||
assert_eq!(set.len(), 8); | ||
} | ||
|
||
#[test] | ||
fn try_from_failure() { | ||
let global_address = ScryptoGlobalAddress::new_or_panic( | ||
ResourceAddress::sample_stokenet() | ||
.scrypto() | ||
.into_node_id() | ||
.0, | ||
); | ||
let network_id = NetworkID::Stokenet; | ||
|
||
let result = SUT::try_from((global_address, network_id)); | ||
assert_eq!( | ||
result.unwrap_err(), | ||
CommonError::FailedToCreateAddressFromGlobalAddressAndNetworkID { | ||
global_address_as_hex: global_address.to_hex(), | ||
network_id, | ||
} | ||
); | ||
} | ||
|
||
macro_rules! generate_try_from_tests { | ||
($($variant:ident => $address_type:ty),*) => { | ||
$( | ||
#[test] | ||
fn $variant() { | ||
let global_address = ScryptoGlobalAddress::new_or_panic( | ||
<$address_type>::sample_stokenet().scrypto().into_node_id().0 | ||
); | ||
let network_id = NetworkID::Stokenet; | ||
|
||
let result = SUT::try_from((global_address, network_id)); | ||
assert!(result.is_ok()); | ||
} | ||
)* | ||
}; | ||
} | ||
|
||
generate_try_from_tests!( | ||
component => ComponentAddress, | ||
locker => LockerAddress | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...sargon-android/src/main/java/com/radixdlt/sargon/extensions/ManifestEncounteredAddress.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.radixdlt.sargon.extensions | ||
|
||
import com.radixdlt.sargon.AddressFormat | ||
import com.radixdlt.sargon.ManifestEncounteredAddress | ||
import com.radixdlt.sargon.NetworkId | ||
import com.radixdlt.sargon.manifestEncounteredAddressFormatted | ||
import com.radixdlt.sargon.manifestEncounteredAddressNetworkId | ||
import com.radixdlt.sargon.manifestEncounteredAddressToString | ||
import com.radixdlt.sargon.newManifestEncounteredAddressFromBech32 | ||
|
||
@Throws(SargonException::class) | ||
fun ManifestEncounteredAddress.Companion.init(validating: String) = | ||
newManifestEncounteredAddressFromBech32(string = validating) | ||
|
||
val ManifestEncounteredAddress.string: String | ||
get() = manifestEncounteredAddressToString(address = this) | ||
|
||
val ManifestEncounteredAddress.networkId: NetworkId | ||
get() = manifestEncounteredAddressNetworkId(address = this) | ||
|
||
fun ManifestEncounteredAddress.formatted( | ||
format: AddressFormat = AddressFormat.DEFAULT | ||
): String = manifestEncounteredAddressFormatted(address = this, format = format) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the enum name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you ask Omar if there is any other address which belongs here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I didn't ask, but should we add other types even if we don't need them in the wallets right now? It will be quite easy to add a new address type when required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not add other types for now, the logic in the Wallet to display the "used dApps" is explicitly for globalGenericComponents + account locker.
At some point, RET had a field called
userApplications
in summary, meant to point that these potentially have associated dApps. Maybe we can have the field in the execution summary more specific to potential dApps used, rather than genericManifestEncounteredAddress
, which presumably, by the name, should include all addressesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GhenadieVP do you have an example? I agree, but I still can't think of a better name to reflect what you described,
UserApplicationAddress
doesn't sound better and it lacks context (as the keywordmanifest
offers).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it too generic? I mean that we are filtering the original addresses after all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first, I thought that
AddressReferencedInTX
is more specific, but now that I think of it all of the addresses referenced in a manifest are referenced in the transaction so I guess you're right and it's better to put emphasis on the fact that the addresses are ofcomponents
. I'll rename it toManifestEncounteredComponentAddress
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it is not component addresses.
LockerAddress
is notComponentAddress
right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's not a component address, but locker is a component, right? But I see what you're saying and that's why I didn't use
component
when naming it initially.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now the
component
keyword expresses that it's not just encountered addresses, but addresses of components (not resources or other types of addresses there are). I'd leave it as is unless someone has other suggestions that reflect the fact that the addresses were filtered to match this criteria.