Skip to content

Commit

Permalink
Transaction analysis v2 (#242)
Browse files Browse the repository at this point in the history
* add additional fields

* wip

* wip

* wip

* fix ios tests

* fix

* wip

* wip

* fix

* wip

* wip

* wi[

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* update test

---------

Co-authored-by: Ghenadie Vasiliev-Pusca <[email protected]>
  • Loading branch information
sergiupuhalschi-rdx and GhenadieVP authored Oct 30, 2024
1 parent cdc28ae commit 8cac8a1
Show file tree
Hide file tree
Showing 39 changed files with 857 additions and 339 deletions.
8 changes: 4 additions & 4 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 @@ -11,10 +11,6 @@ extension SubintentManifest {
subintentManifestString(manifest: self)
}

public var networkID: NetworkID {
subintentManifestNetworkId(manifest: self)
}

public var blobs: Blobs {
subintentManifestBlobs(manifest: self)
}
Expand All @@ -26,8 +22,4 @@ extension SubintentManifest {
public var involvedResourceAddresses: [ResourceAddress] {
subintentManifestInvolvedResourceAddresses(manifest: self)
}

public var summary: ManifestSummary? {
subintentManifestSummary(manifest: self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ extension TransactionManifest {
transactionManifestInstructionsString(manifest: self)
}

public var networkID: NetworkID {
transactionManifestNetworkId(manifest: self)
}

public var blobs: Blobs {
transactionManifestBlobs(manifest: self)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ extension TransactionManifestV2 {
transactionManifestStringV2(manifest: self)
}

public var networkID: NetworkID {
transactionManifestNetworkIdV2(manifest: self)
}

public var blobs: Blobs {
transactionManifestBlobsV2(manifest: self)
}
Expand All @@ -28,6 +24,6 @@ extension TransactionManifestV2 {
}

public var summary: ManifestSummary? {
transactionManifestSummaryV2(manifest: self)
try? transactionManifestSummaryV2(manifest: self)
}
}
2 changes: 1 addition & 1 deletion apple/Tests/TestCases/RET/TransactionManifestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class TransactionManifestTests: Test<TransactionManifest> {

func test_manifest_network_id() {
let manifest = TransactionManifest.sample
XCTAssertNoDifference(manifest.networkID, .mainnet)
XCTAssertNoDifference(manifest.networkId, .mainnet)
}

func test_manifest_blobs() {
Expand Down
4 changes: 2 additions & 2 deletions apple/Tests/TestCases/RET/TransactionManifestV2Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class TransactionManifestV2Tests: Test<TransactionManifestV2> {

func test_manifest_network_id() {
let manifest = SUT.sample
XCTAssertNoDifference(manifest.networkID, .mainnet)
XCTAssertNoDifference(manifest.networkId, .mainnet)
}

func test_manifest_blobs() {
Expand All @@ -34,4 +34,4 @@ final class TransactionManifestV2Tests: Test<TransactionManifestV2> {
func test_manifest_summary() {
XCTAssertNoDifference(SUT.sample.summary?.addressesOfAccountsWithdrawnFrom, [AccountAddress.sampleMainnet])
}
}
}
4 changes: 2 additions & 2 deletions 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.41"
version = "1.1.42"
edition = "2021"
build = "build.rs"

Expand All @@ -21,7 +21,7 @@ required-features = ["build-binary"]
sargon = { path = "../sargon" }
sargon-uniffi-conversion-macros = { path = "../sargon-uniffi-conversion-macros" }

radix-engine-toolkit = { git = "https://github.com/radixdlt/radix-engine-toolkit", rev = "51f0115f1e93f6910b4931ef8367eec2f5b11805" }
radix-engine-toolkit = { git = "https://github.com/radixdlt/radix-engine-toolkit", rev = "263bc81f497f686b7327ffcc45fbaad6e04df85a" }

# zeroize = "1.7.0"
zeroize = { git = "https://github.com/RustCrypto/utils", rev = "df6d2f48a5e8afe8eef04ba32e2af55bacb41375", features = [
Expand Down
4 changes: 2 additions & 2 deletions crates/sargon-uniffi/src/core/error/common_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,8 @@ pub enum CommonError {
InvalidSignedPartialTransactionFailedToEncode { underlying: String } =
10197,

#[error("Failed to generate manifest summary")]
FailedToGenerateManifestSummary = 10198,
#[error("Failed to generate manifest summary, reason: '{underlying}'")]
FailedToGenerateManifestSummary { underlying: String } = 10198,

#[error("Index Securified expected Unsecurified")]
IndexSecurifiedExpectedUnsecurified = 10199,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::RwLockWriteGuard;

use crate::prelude::*;
use std::sync::RwLockWriteGuard;

#[uniffi::export]
impl SargonOS {
Expand All @@ -14,21 +13,42 @@ impl SargonOS {
&self,
instructions: String,
blobs: Blobs,
message: Message,
are_instructions_originating_from_host: bool,
nonce: Nonce,
notary_public_key: PublicKey,
) -> Result<TransactionToReview> {
self.wrapped
.perform_transaction_preview_analysis(
.analyse_transaction_preview(
instructions,
blobs.into_internal(),
message.into_internal(),
are_instructions_originating_from_host,
nonce.into_internal(),
notary_public_key.into_internal(),
)
.await
.into_result()
}

/// Performs initial transaction analysis for a given raw manifest, including:
/// 1. Creating the SubintentManifest.
/// 2. Validating if the manifest is open or enclosed.
/// 3. If open, the manifest with its summary is returned.
/// 4. If enclosed, it extracts the transaction signers and then transaction preview GW request is executed.
/// 3. The execution summary is created with the manifest and receipt.
/// Maps relevant errors to ensure proper handling by the hosts.
pub async fn analyse_pre_auth_preview(
&self,
instructions: String,
blobs: Blobs,
nonce: Nonce,
) -> Result<PreAuthToReview> {
self.wrapped
.analyse_pre_auth_preview(
instructions,
blobs.into_internal(),
nonce.into_internal(),
)
.await
.into_result()
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod pre_auth_to_review;
mod transaction_to_review;

pub use pre_auth_to_review::*;
pub use transaction_to_review::*;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::prelude::*;
use sargon::PreAuthEnclosedManifest as InternalPreAuthEnclosedManifest;
use sargon::PreAuthOpenManifest as InternalPreAuthOpenManifest;
use sargon::PreAuthToReview as InternalPreAuthToReview;

/// This is the result of the Pre-Auth preview analysis.
/// It contains all the information needed to compute and display the transaction details to the user.
#[derive(Clone, PartialEq, InternalConversion, uniffi::Enum)]
pub enum PreAuthToReview {
Open(PreAuthOpenManifest),
Enclosed(PreAuthEnclosedManifest),
}

/// Pre-Auth analysis open manifest, which contains multiple interactions with the parent manifest,
/// thus its preview can be computed only based on the static analysis manifest summary
#[derive(Clone, PartialEq, InternalConversion, uniffi::Record)]
pub struct PreAuthOpenManifest {
pub manifest: SubintentManifest,
pub summary: ManifestSummary,
}

/// Pre-Auth analysis enclosed manifest, which does not contain any interactions with the parent manifest,
/// thus its preview can be computed as if it would have been a standalone transaction.
#[derive(Clone, PartialEq, InternalConversion, uniffi::Record)]
pub struct PreAuthEnclosedManifest {
pub manifest: SubintentManifest,
pub summary: ExecutionSummary,
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ pub struct ManifestSummary {
/// The deposits done in the manifest.
pub account_deposits: HashMap<AccountAddress, Vec<AccountDeposit>>,

/// The list of the resources of proofs that were presented in the manifest.
pub presented_proofs: Vec<ResourceSpecifier>,

/// Addresses of accounts withdrawn from in the manifest.
pub addresses_of_accounts_withdrawn_from: Vec<AccountAddress>,

/// Addresses of accounts deposited into in the manifest.
pub addresses_of_accounts_deposited_into: Vec<AccountAddress>,

/// The set of all the global entities encountered in the manifest. This is
/// to be primarily used for the "using dApps" section of the wallet's tx
/// review screen.
pub encountered_entities: Vec<ManifestEncounteredComponentAddress>,

/// Addresses of accounts encountered in the manifest where privileged
/// methods were called. The wallets will need to collect signatures
/// of the accounts of all those addresses, which might be multiple
Expand All @@ -27,4 +35,8 @@ pub struct ManifestSummary {
/// of the identities of all those addresses, which might be multiple
/// signatures per Persona, if MFA has been setup.
pub addresses_of_personas_requiring_auth: Vec<IdentityAddress>,

/// The set of instructions encountered in the manifest that are reserved
/// and can only be included in the manifest by the wallet itself.
pub reserved_instructions: Vec<ReservedInstruction>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ pub fn subintent_manifest_string(manifest: &SubintentManifest) -> String {
manifest.into_internal().manifest_string()
}

#[uniffi::export]
pub fn subintent_manifest_summary(
manifest: &SubintentManifest,
) -> Option<ManifestSummary> {
manifest.into_internal().summary().map(|s| s.into())
}

#[uniffi::export]
pub fn subintent_manifest_involved_resource_addresses(
manifest: &SubintentManifest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ pub fn transaction_manifest_string_v2(
#[uniffi::export]
pub fn transaction_manifest_summary_v2(
manifest: &TransactionManifestV2,
) -> Option<ManifestSummary> {
manifest.into_internal().summary().map(|s| s.into())
) -> Result<ManifestSummary> {
manifest.into_internal().summary().into_result()
}

#[uniffi::export]
Expand Down
4 changes: 2 additions & 2 deletions crates/sargon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sargon"
# Don't forget to update version in crates/sargon-uniffi/Cargo.toml
version = "1.1.41"
version = "1.1.42"
edition = "2021"
build = "build.rs"

Expand Down Expand Up @@ -89,7 +89,7 @@ radix-engine-toolkit-common = { git = "https://github.com/radixdlt/radixdlt-scry

radix-transactions = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-2ea8b582" }

radix-engine-toolkit = { git = "https://github.com/radixdlt/radix-engine-toolkit", rev = "51f0115f1e93f6910b4931ef8367eec2f5b11805" }
radix-engine-toolkit = { git = "https://github.com/radixdlt/radix-engine-toolkit", rev = "263bc81f497f686b7327ffcc45fbaad6e04df85a" }

# enum-iterator = "1.4.1"
enum-iterator = { git = "https://github.com/stephaneyfx/enum-iterator/", rev = "9d472a1237cfd03b1c7657fdcba74c8070bfb4ea" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
CALL_METHOD
Address("account_sim1cyvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cve475w0q")
"lock_fee"
Decimal("500")
;
CALL_METHOD
Address("account_sim1cyvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cve475w0q")
"withdraw"
Address("resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3")
Decimal("330")
;
TAKE_FROM_WORKTOP
Address("resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3")
Decimal("150")
Bucket("bucket1")
;
CALL_METHOD
Address("account_sim1c8mulhl5yrk6hh4jsyldps5sdrp08r5v9wusupvzxgqvhlp4c4nwjz")
"try_deposit_or_abort"
Bucket("bucket1")
Enum<0u8>()
;
TAKE_FROM_WORKTOP
Address("resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3")
Decimal("130")
Bucket("bucket2")
;
CALL_METHOD
Address("account_sim1c8s2hass5g62ckwpv78y8ykdqljtetv4ve6etcz64gveykxznj36tr")
"try_deposit_or_abort"
Bucket("bucket2")
Enum<0u8>()
;
TAKE_FROM_WORKTOP
Address("resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3")
Decimal("50")
Bucket("bucket3")
;
CALL_METHOD
Address("account_sim1c8ct6jdcwqrg3gzskyxuy0z933fe55fyjz6p56730r95ulzwl3ppva")
"try_deposit_or_abort"
Bucket("bucket3")
Enum<0u8>()
;
YIELD_TO_PARENT;
25 changes: 25 additions & 0 deletions crates/sargon/fixtures/transaction/resource_transfer_subintent.rtm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CALL_METHOD
Address("account_rdx128y6j78mt0aqv6372evz28hrxp8mn06ccddkr7xppc88hyvynvjdwr")
"lock_fee"
Decimal("0.61")
;
CALL_METHOD
Address("account_rdx128y6j78mt0aqv6372evz28hrxp8mn06ccddkr7xppc88hyvynvjdwr")
"withdraw"
Address("resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd")
Decimal("1337")
;
TAKE_FROM_WORKTOP
Address("resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd")
Decimal("1337")
Bucket("bucket1")
;
CALL_METHOD
Address("account_rdx12xkzynhzgtpnnd02tudw2els2g9xl73yk54ppw8xekt2sdrlaer264")
"try_deposit_or_abort"
Bucket("bucket1")
Enum<0u8>()
;
YIELD_TO_PARENT;


4 changes: 2 additions & 2 deletions crates/sargon/src/core/error/common_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,8 @@ pub enum CommonError {
InvalidSignedPartialTransactionFailedToEncode { underlying: String } =
10197,

#[error("Failed to generate manifest summary")]
FailedToGenerateManifestSummary = 10198,
#[error("Failed to generate manifest summary, reason: '{underlying}'")]
FailedToGenerateManifestSummary { underlying: String } = 10198,

#[error("Index Securified expected Unsecurified")]
IndexSecurifiedExpectedUnsecurified = 10199,
Expand Down
Loading

0 comments on commit 8cac8a1

Please sign in to comment.