From 2335188d8249b9865b1a4f6c837e12211a7d57be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Tue, 6 Feb 2024 17:45:06 +0100 Subject: [PATCH 01/13] First part --- .../traverser/auxiliary/presented_proofs.rs | 38 +++++++++++++++++-- .../src/transaction_types/traverser/traits.rs | 7 +++- .../transaction_types/traverser/traverser.rs | 26 ++++++++++--- .../src/transaction_types/types.rs | 7 ++-- 4 files changed, 64 insertions(+), 14 deletions(-) diff --git a/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs b/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs index 162a32ea..94730b52 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs @@ -15,24 +15,54 @@ // specific language governing permissions and limitations // under the License. +use radix_engine::system::system_modules::execution_trace::*; use scrypto::prelude::*; use crate::transaction_types::*; #[derive(Default)] pub struct PresentedProofsDetector { - presented_proofs: IndexSet, + presented_proofs: IndexMap>, } impl PresentedProofsDetector { - pub fn output(self) -> IndexSet { + pub fn output(self) -> IndexMap> { self.presented_proofs } } impl ManifestSummaryCallback for PresentedProofsDetector { - fn on_create_proof(&mut self, resource_address: &ResourceAddress) { - self.presented_proofs.insert(*resource_address); + fn on_create_proof( + &mut self, + account: &ComponentAddress, + resource: &ResourceSpecifier, + ) { + self.presented_proofs.entry(*account).and_modify(|item| { + if let Some(res) = item.iter().find(|res| { + res.resource_address() == resource.resource_address() + }) { + match res { + ResourceSpecifier::Amount(_, mut amount) => { + match resource { + ResourceSpecifier::Amount(_, new_amount) => { + amount = amount + .checked_add(*new_amount) + .expect("Overflow"); + } + ResourceSpecifier::Ids(_, _) => (), + } + } + ResourceSpecifier::Ids(_, mut ids) => match resource { + ResourceSpecifier::Amount(_, _) => (), + ResourceSpecifier::Ids(_, new_ids) => { + ids.extend(new_ids.clone()); + } + }, + } + } else { + item.push(resource.clone()); + } + }); } } diff --git a/crates/radix-engine-toolkit/src/transaction_types/traverser/traits.rs b/crates/radix-engine-toolkit/src/transaction_types/traverser/traits.rs index d05acf19..671a9908 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/traverser/traits.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/traverser/traits.rs @@ -36,7 +36,12 @@ pub trait ManifestSummaryCallback { /// Called when a proof is created out of an account. #[inline] - fn on_create_proof(&mut self, _resource_address: &ResourceAddress) {} + fn on_create_proof( + &mut self, + _account: &ComponentAddress, + _resource: &ResourceSpecifier, + ) { + } /// Called when a global entity is encountered in the manifest #[inline] diff --git a/crates/radix-engine-toolkit/src/transaction_types/traverser/traverser.rs b/crates/radix-engine-toolkit/src/transaction_types/traverser/traverser.rs index 77098630..35b08481 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/traverser/traverser.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/traverser/traverser.rs @@ -19,6 +19,7 @@ pub mod manifest_summary { use crate::sbor::indexed_manifest_value::*; use crate::transaction_types::*; use crate::utils::*; + use radix_engine::system::system_modules::execution_trace::*; use radix_engine_interface::blueprints::account::*; use transaction::prelude::*; @@ -67,7 +68,7 @@ pub mod manifest_summary { instruction: &InstructionV1, ) { if let InstructionV1::CallMethod { - address: dynamic_address @ DynamicGlobalAddress::Static(_address), + address: dynamic_address @ DynamicGlobalAddress::Static(address), method_name, args, } = instruction @@ -76,25 +77,40 @@ pub mod manifest_summary { return; } + let account = + ComponentAddress::try_from(*address).expect("Must succeed"); + if method_name == ACCOUNT_CREATE_PROOF_OF_AMOUNT_IDENT { if let Some(AccountCreateProofOfAmountInput { resource_address, - .. + amount, }) = to_manifest_type(args) { callbacks.iter_mut().for_each(|callback| { - callback.on_create_proof(&resource_address) + callback.on_create_proof( + &account, + &ResourceSpecifier::Amount( + resource_address, + amount, + ), + ) }); } } else if method_name == ACCOUNT_CREATE_PROOF_OF_NON_FUNGIBLES_IDENT { if let Some(AccountCreateProofOfNonFungiblesInput { resource_address, - .. + ids, }) = to_manifest_type(args) { callbacks.iter_mut().for_each(|callback| { - callback.on_create_proof(&resource_address) + callback.on_create_proof( + &account, + &ResourceSpecifier::Ids( + resource_address, + ids.clone(), + ), + ) }); } } diff --git a/crates/radix-engine-toolkit/src/transaction_types/types.rs b/crates/radix-engine-toolkit/src/transaction_types/types.rs index 24825b66..98a54eba 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/types.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/types.rs @@ -33,9 +33,8 @@ use super::*; /// A summary of the manifest #[derive(Clone, Debug)] pub struct ManifestSummary { - /// The set of the resource addresses of proofs that were presented in - /// the manifest. - pub presented_proofs: IndexSet, + /// The set of the resources of proofs that were presented in the manifest. + pub presented_proofs: IndexMap>, /// The set of accounts withdrawn from observed in the manifest. pub accounts_withdrawn_from: IndexSet, /// The set of accounts deposited into observed in the manifest. @@ -67,7 +66,7 @@ pub struct ExecutionSummary { pub account_deposits: IndexMap>, /// The set of the resource addresses of proofs that were presented in /// the manifest. - pub presented_proofs: IndexSet, + pub presented_proofs: IndexMap>, /// Information on the global entities created in the transaction. pub new_entities: NewEntities, /// The set of all the global entities encountered in the manifest. This is From 2f43c3405f1fc4052e02e6de685a0525333fcb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Tue, 6 Feb 2024 23:41:52 +0100 Subject: [PATCH 02/13] Fixed build --- .../traverser/auxiliary/presented_proofs.rs | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs b/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs index 94730b52..ddbc5972 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs @@ -38,26 +38,33 @@ impl ManifestSummaryCallback for PresentedProofsDetector { resource: &ResourceSpecifier, ) { self.presented_proofs.entry(*account).and_modify(|item| { - if let Some(res) = item.iter().find(|res| { - res.resource_address() == resource.resource_address() - }) { + if let Some((idx, res)) = + item.iter().enumerate().find(|(_, res)| { + res.resource_address() == resource.resource_address() + }) + { match res { - ResourceSpecifier::Amount(_, mut amount) => { - match resource { - ResourceSpecifier::Amount(_, new_amount) => { - amount = amount + ResourceSpecifier::Amount(address, amount) => { + if let ResourceSpecifier::Amount(_, new_amount) = + resource + { + item[idx] = ResourceSpecifier::Amount( + *address, + amount .checked_add(*new_amount) - .expect("Overflow"); - } - ResourceSpecifier::Ids(_, _) => (), + .expect("Overflow"), + ) } } - ResourceSpecifier::Ids(_, mut ids) => match resource { - ResourceSpecifier::Amount(_, _) => (), - ResourceSpecifier::Ids(_, new_ids) => { - ids.extend(new_ids.clone()); + ResourceSpecifier::Ids(address, ids) => { + if let ResourceSpecifier::Ids(_, ids_to_add) = resource + { + let mut new_ids = ids.clone(); + new_ids.extend(ids_to_add.clone()); + item[idx] = + ResourceSpecifier::Ids(*address, new_ids); } - }, + } } } else { item.push(resource.clone()); From 789e89737a660ae03301cc3f084e690039102963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Wed, 7 Feb 2024 00:09:50 +0100 Subject: [PATCH 03/13] Added uniffi implementation --- .../src/transaction/manifest.rs | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/crates/radix-engine-toolkit-uniffi/src/transaction/manifest.rs b/crates/radix-engine-toolkit-uniffi/src/transaction/manifest.rs index fabfe6b4..087ffa9d 100644 --- a/crates/radix-engine-toolkit-uniffi/src/transaction/manifest.rs +++ b/crates/radix-engine-toolkit-uniffi/src/transaction/manifest.rs @@ -701,7 +701,7 @@ impl DetailedManifestClass { pub struct ExecutionSummary { pub account_withdraws: HashMap>, pub account_deposits: HashMap>, - pub presented_proofs: Vec>, + pub presented_proofs: HashMap, Vec>, pub new_entities: NewEntities, pub encountered_entities: Vec>, pub accounts_requiring_auth: Vec>, @@ -753,10 +753,18 @@ impl ExecutionSummary { .presented_proofs .into_iter() .map(|item| { - Arc::new(Address::unsafe_from_raw( - item.into_node_id(), - network_id, - )) + ( + Arc::new(Address::unsafe_from_raw( + item.0.into_node_id(), + network_id, + )), + item.1 + .iter() + .map(|i| { + ResourceSpecifier::from_native(i, network_id) + }) + .collect(), + ) }) .collect(), new_entities: NewEntities::from_native( @@ -826,7 +834,7 @@ impl ExecutionSummary { #[derive(Clone, Debug, Record)] pub struct ManifestSummary { - pub presented_proofs: Vec>, + pub presented_proofs: HashMap, Vec>, pub accounts_withdrawn_from: Vec>, pub accounts_deposited_into: Vec>, pub encountered_entities: Vec>, @@ -843,10 +851,18 @@ impl ManifestSummary { .presented_proofs .into_iter() .map(|item| { - Arc::new(Address::unsafe_from_raw( - item.into_node_id(), - network_id, - )) + ( + Arc::new(Address::unsafe_from_raw( + item.0.into_node_id(), + network_id, + )), + item.1 + .iter() + .map(|i| { + ResourceSpecifier::from_native(i, network_id) + }) + .collect(), + ) }) .collect(), accounts_withdrawn_from: native From 8649543d6474d7ef8c772867fd9dcf843be96504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Wed, 7 Feb 2024 11:00:11 +0100 Subject: [PATCH 04/13] Update --- .../traverser/auxiliary/presented_proofs.rs | 62 ++++++++++--------- .../src/transaction_types/types.rs | 5 +- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs b/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs index ddbc5972..c17a70b1 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs @@ -37,39 +37,43 @@ impl ManifestSummaryCallback for PresentedProofsDetector { account: &ComponentAddress, resource: &ResourceSpecifier, ) { - self.presented_proofs.entry(*account).and_modify(|item| { - if let Some((idx, res)) = - item.iter().enumerate().find(|(_, res)| { - res.resource_address() == resource.resource_address() - }) - { - match res { - ResourceSpecifier::Amount(address, amount) => { - if let ResourceSpecifier::Amount(_, new_amount) = - resource - { - item[idx] = ResourceSpecifier::Amount( - *address, - amount - .checked_add(*new_amount) - .expect("Overflow"), - ) + self.presented_proofs + .entry(*account) + .and_modify(|item| { + if let Some((idx, res)) = + item.iter().enumerate().find(|(_, res)| { + res.resource_address() == resource.resource_address() + }) + { + match res { + ResourceSpecifier::Amount(address, amount) => { + if let ResourceSpecifier::Amount(_, new_amount) = + resource + { + item[idx] = ResourceSpecifier::Amount( + *address, + amount + .checked_add(*new_amount) + .expect("Overflow"), + ) + } } - } - ResourceSpecifier::Ids(address, ids) => { - if let ResourceSpecifier::Ids(_, ids_to_add) = resource - { - let mut new_ids = ids.clone(); - new_ids.extend(ids_to_add.clone()); - item[idx] = - ResourceSpecifier::Ids(*address, new_ids); + ResourceSpecifier::Ids(address, ids) => { + if let ResourceSpecifier::Ids(_, ids_to_add) = + resource + { + let mut new_ids = ids.clone(); + new_ids.extend(ids_to_add.clone()); + item[idx] = + ResourceSpecifier::Ids(*address, new_ids); + } } } + } else { + item.push(resource.clone()); } - } else { - item.push(resource.clone()); - } - }); + }) + .or_insert(vec![resource.clone()]); } } diff --git a/crates/radix-engine-toolkit/src/transaction_types/types.rs b/crates/radix-engine-toolkit/src/transaction_types/types.rs index 98a54eba..959dedc2 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/types.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/types.rs @@ -33,7 +33,7 @@ use super::*; /// A summary of the manifest #[derive(Clone, Debug)] pub struct ManifestSummary { - /// The set of the resources of proofs that were presented in the manifest. + /// The list of the resources of proofs that were presented in the manifest. pub presented_proofs: IndexMap>, /// The set of accounts withdrawn from observed in the manifest. pub accounts_withdrawn_from: IndexSet, @@ -64,8 +64,7 @@ pub struct ExecutionSummary { pub account_withdraws: IndexMap>, /// The deposits done in the manifest. pub account_deposits: IndexMap>, - /// The set of the resource addresses of proofs that were presented in - /// the manifest. + /// The list of the resources of proofs that were presented in the manifest. pub presented_proofs: IndexMap>, /// Information on the global entities created in the transaction. pub new_entities: NewEntities, From d21f810dc911baf5402f8464e42b8ab3b5c3b6ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Wed, 7 Feb 2024 11:01:01 +0100 Subject: [PATCH 05/13] Added tests --- .../tests/transaction_types.rs | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/crates/radix-engine-toolkit/tests/transaction_types.rs b/crates/radix-engine-toolkit/tests/transaction_types.rs index 8eab673b..21790cb0 100644 --- a/crates/radix-engine-toolkit/tests/transaction_types.rs +++ b/crates/radix-engine-toolkit/tests/transaction_types.rs @@ -2282,6 +2282,134 @@ fn account_deposit_settings_changes_are_recognized() { ); } +#[test] +fn presented_proofs_fungible() { + use radix_engine::system::system_modules::execution_trace::*; + + // Arrange + let mut test_runner = TestRunnerBuilder::new().without_trace().build(); + let (_, _, account_1) = test_runner.new_allocated_account(); + let (_, _, account_2) = test_runner.new_allocated_account(); + let address_1 = + test_runner.create_fungible_resource(dec!(100), 0, account_1); + let address_2 = + test_runner.create_fungible_resource(dec!(100), 0, account_1); + let address_3 = + test_runner.create_fungible_resource(dec!(100), 0, account_2); + + //Act + let manifest = ManifestBuilder::new() + .lock_fee_from_faucet() + .create_proof_from_account_of_amount(account_1, address_1, 1) + .create_proof_from_account_of_amount(account_2, address_3, 30) + .create_proof_from_account_of_amount(account_1, address_2, 100) + .create_proof_from_account_of_amount(account_1, address_1, 2) + .create_proof_from_account_of_amount(account_2, address_3, 5) + .build(); + let (manifest_summary, _) = test_runner.summarize(manifest); + + // Assert + assert_eq!(manifest_summary.presented_proofs.len(), 2); + let account_1_proofs = + manifest_summary.presented_proofs.get(&account_1).unwrap(); + assert_eq!(account_1_proofs.len(), 2); + assert_eq!( + account_1_proofs[0], + ResourceSpecifier::Amount(address_1, dec!(3)) + ); + assert_eq!( + account_1_proofs[1], + ResourceSpecifier::Amount(address_2, dec!(100)) + ); + let account_2_proofs = + manifest_summary.presented_proofs.get(&account_2).unwrap(); + assert_eq!(account_2_proofs.len(), 1); + assert_eq!( + account_2_proofs[0], + ResourceSpecifier::Amount(address_3, dec!(35)) + ); +} + +#[test] +fn presented_proofs_non_fungible() { + use radix_engine::system::system_modules::execution_trace::*; + + // Arrange + let mut test_runner = TestRunnerBuilder::new().without_trace().build(); + let (_, _, account_1) = test_runner.new_allocated_account(); + let (_, _, account_2) = test_runner.new_allocated_account(); + let address_1 = test_runner.create_non_fungible_resource(account_1); + let address_2 = test_runner.create_non_fungible_resource(account_1); + let address_3 = test_runner.create_non_fungible_resource(account_2); + + //Act + let manifest = ManifestBuilder::new() + .lock_fee_from_faucet() + .create_proof_from_account_of_non_fungibles( + account_1, + address_1, + [NonFungibleLocalId::integer(1)], + ) + .create_proof_from_account_of_non_fungibles( + account_1, + address_2, + [NonFungibleLocalId::integer(3)], + ) + .create_proof_from_account_of_non_fungibles( + account_2, + address_3, + [ + NonFungibleLocalId::integer(1), + NonFungibleLocalId::integer(2), + ], + ) + .create_proof_from_account_of_non_fungibles( + account_1, + address_1, + [NonFungibleLocalId::integer(2)], + ) + .build(); + let (manifest_summary, _) = test_runner.summarize(manifest); + + // Assert + assert_eq!(manifest_summary.presented_proofs.len(), 2); + let account_1_proofs = + manifest_summary.presented_proofs.get(&account_1).unwrap(); + assert_eq!(account_1_proofs.len(), 2); + assert_eq!( + account_1_proofs[0], + ResourceSpecifier::Ids( + address_1, + [ + NonFungibleLocalId::integer(1), + NonFungibleLocalId::integer(2) + ] + .into() + ) + ); + assert_eq!( + account_1_proofs[1], + ResourceSpecifier::Ids( + address_2, + [NonFungibleLocalId::integer(3)].into() + ) + ); + let account_2_proofs = + manifest_summary.presented_proofs.get(&account_2).unwrap(); + assert_eq!(account_2_proofs.len(), 1); + assert_eq!( + account_2_proofs[0], + ResourceSpecifier::Ids( + address_3, + [ + NonFungibleLocalId::integer(1), + NonFungibleLocalId::integer(2) + ] + .into() + ) + ); +} + fn create_pools( test_runner: &mut DefaultTestRunner, account: ComponentAddress, From 70a7859b81de7547631954778d02be32b6fb0ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Wed, 7 Feb 2024 12:41:26 +0100 Subject: [PATCH 06/13] Small change to test broken workflows run --- crates/radix-engine-toolkit/tests/transaction_types.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/radix-engine-toolkit/tests/transaction_types.rs b/crates/radix-engine-toolkit/tests/transaction_types.rs index 21790cb0..3ad6ba11 100644 --- a/crates/radix-engine-toolkit/tests/transaction_types.rs +++ b/crates/radix-engine-toolkit/tests/transaction_types.rs @@ -2359,8 +2359,8 @@ fn presented_proofs_non_fungible() { account_2, address_3, [ - NonFungibleLocalId::integer(1), NonFungibleLocalId::integer(2), + NonFungibleLocalId::integer(3), ], ) .create_proof_from_account_of_non_fungibles( @@ -2402,8 +2402,8 @@ fn presented_proofs_non_fungible() { ResourceSpecifier::Ids( address_3, [ - NonFungibleLocalId::integer(1), - NonFungibleLocalId::integer(2) + NonFungibleLocalId::integer(2), + NonFungibleLocalId::integer(3) ] .into() ) From 23dc0a144818c874418f9ee00243c51aa7755b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Wed, 7 Feb 2024 13:16:43 +0100 Subject: [PATCH 07/13] Changed fungible proofs aggregation --- .../traverser/auxiliary/presented_proofs.rs | 4 +--- crates/radix-engine-toolkit/tests/transaction_types.rs | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs b/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs index c17a70b1..68a11365 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs @@ -52,9 +52,7 @@ impl ManifestSummaryCallback for PresentedProofsDetector { { item[idx] = ResourceSpecifier::Amount( *address, - amount - .checked_add(*new_amount) - .expect("Overflow"), + *amount.max(new_amount), ) } } diff --git a/crates/radix-engine-toolkit/tests/transaction_types.rs b/crates/radix-engine-toolkit/tests/transaction_types.rs index 3ad6ba11..24c03c57 100644 --- a/crates/radix-engine-toolkit/tests/transaction_types.rs +++ b/crates/radix-engine-toolkit/tests/transaction_types.rs @@ -2300,10 +2300,10 @@ fn presented_proofs_fungible() { //Act let manifest = ManifestBuilder::new() .lock_fee_from_faucet() - .create_proof_from_account_of_amount(account_1, address_1, 1) + .create_proof_from_account_of_amount(account_1, address_1, 60) .create_proof_from_account_of_amount(account_2, address_3, 30) .create_proof_from_account_of_amount(account_1, address_2, 100) - .create_proof_from_account_of_amount(account_1, address_1, 2) + .create_proof_from_account_of_amount(account_1, address_1, 80) .create_proof_from_account_of_amount(account_2, address_3, 5) .build(); let (manifest_summary, _) = test_runner.summarize(manifest); @@ -2315,7 +2315,7 @@ fn presented_proofs_fungible() { assert_eq!(account_1_proofs.len(), 2); assert_eq!( account_1_proofs[0], - ResourceSpecifier::Amount(address_1, dec!(3)) + ResourceSpecifier::Amount(address_1, dec!(80)) ); assert_eq!( account_1_proofs[1], @@ -2326,7 +2326,7 @@ fn presented_proofs_fungible() { assert_eq!(account_2_proofs.len(), 1); assert_eq!( account_2_proofs[0], - ResourceSpecifier::Amount(address_3, dec!(35)) + ResourceSpecifier::Amount(address_3, dec!(30)) ); } From 08f04c3e125b4cbd1654aa9b769b8ee2592a180e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Wed, 7 Feb 2024 15:08:21 +0100 Subject: [PATCH 08/13] Updated implementation with raw list of records --- .../traverser/auxiliary/presented_proofs.rs | 33 +----------- .../tests/transaction_types.rs | 50 +++++++++++++++---- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs b/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs index 68a11365..c1afc8c9 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/presented_proofs.rs @@ -39,38 +39,7 @@ impl ManifestSummaryCallback for PresentedProofsDetector { ) { self.presented_proofs .entry(*account) - .and_modify(|item| { - if let Some((idx, res)) = - item.iter().enumerate().find(|(_, res)| { - res.resource_address() == resource.resource_address() - }) - { - match res { - ResourceSpecifier::Amount(address, amount) => { - if let ResourceSpecifier::Amount(_, new_amount) = - resource - { - item[idx] = ResourceSpecifier::Amount( - *address, - *amount.max(new_amount), - ) - } - } - ResourceSpecifier::Ids(address, ids) => { - if let ResourceSpecifier::Ids(_, ids_to_add) = - resource - { - let mut new_ids = ids.clone(); - new_ids.extend(ids_to_add.clone()); - item[idx] = - ResourceSpecifier::Ids(*address, new_ids); - } - } - } - } else { - item.push(resource.clone()); - } - }) + .and_modify(|res_vector| res_vector.push(resource.clone())) .or_insert(vec![resource.clone()]); } } diff --git a/crates/radix-engine-toolkit/tests/transaction_types.rs b/crates/radix-engine-toolkit/tests/transaction_types.rs index 24c03c57..2acfb000 100644 --- a/crates/radix-engine-toolkit/tests/transaction_types.rs +++ b/crates/radix-engine-toolkit/tests/transaction_types.rs @@ -2312,22 +2312,30 @@ fn presented_proofs_fungible() { assert_eq!(manifest_summary.presented_proofs.len(), 2); let account_1_proofs = manifest_summary.presented_proofs.get(&account_1).unwrap(); - assert_eq!(account_1_proofs.len(), 2); + assert_eq!(account_1_proofs.len(), 3); assert_eq!( account_1_proofs[0], - ResourceSpecifier::Amount(address_1, dec!(80)) + ResourceSpecifier::Amount(address_1, dec!(60)) ); assert_eq!( account_1_proofs[1], ResourceSpecifier::Amount(address_2, dec!(100)) ); + assert_eq!( + account_1_proofs[2], + ResourceSpecifier::Amount(address_1, dec!(80)) + ); let account_2_proofs = manifest_summary.presented_proofs.get(&account_2).unwrap(); - assert_eq!(account_2_proofs.len(), 1); + assert_eq!(account_2_proofs.len(), 2); assert_eq!( account_2_proofs[0], ResourceSpecifier::Amount(address_3, dec!(30)) ); + assert_eq!( + account_2_proofs[1], + ResourceSpecifier::Amount(address_3, dec!(5)) + ); } #[test] @@ -2366,6 +2374,14 @@ fn presented_proofs_non_fungible() { .create_proof_from_account_of_non_fungibles( account_1, address_1, + [ + NonFungibleLocalId::integer(1), + NonFungibleLocalId::integer(2), + ], + ) + .create_proof_from_account_of_non_fungibles( + account_2, + address_3, [NonFungibleLocalId::integer(2)], ) .build(); @@ -2375,16 +2391,12 @@ fn presented_proofs_non_fungible() { assert_eq!(manifest_summary.presented_proofs.len(), 2); let account_1_proofs = manifest_summary.presented_proofs.get(&account_1).unwrap(); - assert_eq!(account_1_proofs.len(), 2); + assert_eq!(account_1_proofs.len(), 3); assert_eq!( account_1_proofs[0], ResourceSpecifier::Ids( address_1, - [ - NonFungibleLocalId::integer(1), - NonFungibleLocalId::integer(2) - ] - .into() + [NonFungibleLocalId::integer(1)].into() ) ); assert_eq!( @@ -2394,9 +2406,20 @@ fn presented_proofs_non_fungible() { [NonFungibleLocalId::integer(3)].into() ) ); + assert_eq!( + account_1_proofs[2], + ResourceSpecifier::Ids( + address_1, + [ + NonFungibleLocalId::integer(1), + NonFungibleLocalId::integer(2) + ] + .into() + ) + ); let account_2_proofs = manifest_summary.presented_proofs.get(&account_2).unwrap(); - assert_eq!(account_2_proofs.len(), 1); + assert_eq!(account_2_proofs.len(), 2); assert_eq!( account_2_proofs[0], ResourceSpecifier::Ids( @@ -2408,6 +2431,13 @@ fn presented_proofs_non_fungible() { .into() ) ); + assert_eq!( + account_2_proofs[01], + ResourceSpecifier::Ids( + address_3, + [NonFungibleLocalId::integer(2)].into() + ) + ); } fn create_pools( From 3e2c5e5d6f99eb1a33ab35cd3df3ca6e2a279f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Wed, 7 Feb 2024 15:17:40 +0100 Subject: [PATCH 09/13] Fixed failing test by changing interface --- .../src/transaction/manifest.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/radix-engine-toolkit-uniffi/src/transaction/manifest.rs b/crates/radix-engine-toolkit-uniffi/src/transaction/manifest.rs index 087ffa9d..4b36c05f 100644 --- a/crates/radix-engine-toolkit-uniffi/src/transaction/manifest.rs +++ b/crates/radix-engine-toolkit-uniffi/src/transaction/manifest.rs @@ -701,7 +701,7 @@ impl DetailedManifestClass { pub struct ExecutionSummary { pub account_withdraws: HashMap>, pub account_deposits: HashMap>, - pub presented_proofs: HashMap, Vec>, + pub presented_proofs: HashMap>, pub new_entities: NewEntities, pub encountered_entities: Vec>, pub accounts_requiring_auth: Vec>, @@ -754,10 +754,11 @@ impl ExecutionSummary { .into_iter() .map(|item| { ( - Arc::new(Address::unsafe_from_raw( + Address::unsafe_from_raw( item.0.into_node_id(), network_id, - )), + ) + .address_string(), item.1 .iter() .map(|i| { @@ -834,7 +835,7 @@ impl ExecutionSummary { #[derive(Clone, Debug, Record)] pub struct ManifestSummary { - pub presented_proofs: HashMap, Vec>, + pub presented_proofs: HashMap>, pub accounts_withdrawn_from: Vec>, pub accounts_deposited_into: Vec>, pub encountered_entities: Vec>, @@ -852,10 +853,11 @@ impl ManifestSummary { .into_iter() .map(|item| { ( - Arc::new(Address::unsafe_from_raw( + Address::unsafe_from_raw( item.0.into_node_id(), network_id, - )), + ) + .address_string(), item.1 .iter() .map(|i| { From 025cdbd6172c7d9bdfcd43520e1943cae3861876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Wed, 7 Feb 2024 16:44:46 +0100 Subject: [PATCH 10/13] Version bump + version udpate script --- crates/generator/Cargo.toml | 2 +- crates/radix-engine-toolkit-json/Cargo.toml | 2 +- crates/radix-engine-toolkit-uniffi/Cargo.toml | 2 +- .../tests/bindings/example.kts | 2 +- .../tests/bindings/example.py | 2 +- .../tests/bindings/example.swift | 2 +- crates/radix-engine-toolkit/Cargo.toml | 2 +- crates/sbor-json/Cargo.toml | 2 +- crates/uniffi-bindgen/Cargo.toml | 4 ++-- scripts/version_update.sh | 14 ++++++++++++++ 10 files changed, 24 insertions(+), 10 deletions(-) create mode 100755 scripts/version_update.sh diff --git a/crates/generator/Cargo.toml b/crates/generator/Cargo.toml index c2642651..382bcf26 100644 --- a/crates/generator/Cargo.toml +++ b/crates/generator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "generator" -version = "1.0.9" +version = "1.0.10" edition = "2021" [dependencies] diff --git a/crates/radix-engine-toolkit-json/Cargo.toml b/crates/radix-engine-toolkit-json/Cargo.toml index 4ca47bbb..1d449805 100644 --- a/crates/radix-engine-toolkit-json/Cargo.toml +++ b/crates/radix-engine-toolkit-json/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "radix-engine-toolkit-json" -version = "1.0.9" +version = "1.0.10" edition = "2021" [dependencies] diff --git a/crates/radix-engine-toolkit-uniffi/Cargo.toml b/crates/radix-engine-toolkit-uniffi/Cargo.toml index fcebe237..e8dc010c 100644 --- a/crates/radix-engine-toolkit-uniffi/Cargo.toml +++ b/crates/radix-engine-toolkit-uniffi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "radix-engine-toolkit-uniffi" -version = "1.0.9" +version = "1.0.10" edition = "2021" build = "build.rs" diff --git a/crates/radix-engine-toolkit-uniffi/tests/bindings/example.kts b/crates/radix-engine-toolkit-uniffi/tests/bindings/example.kts index 80f62d53..7c6ea144 100644 --- a/crates/radix-engine-toolkit-uniffi/tests/bindings/example.kts +++ b/crates/radix-engine-toolkit-uniffi/tests/bindings/example.kts @@ -4,4 +4,4 @@ import com.radixdlt.ret.*; val information = buildInformation(); // Assert -assert(information.version == "1.0.9"); \ No newline at end of file +assert(information.version == "1.0.10"); \ No newline at end of file diff --git a/crates/radix-engine-toolkit-uniffi/tests/bindings/example.py b/crates/radix-engine-toolkit-uniffi/tests/bindings/example.py index 070225ac..519100f8 100644 --- a/crates/radix-engine-toolkit-uniffi/tests/bindings/example.py +++ b/crates/radix-engine-toolkit-uniffi/tests/bindings/example.py @@ -4,4 +4,4 @@ build_info = build_information() # Assert -assert build_info.version == "1.0.9" \ No newline at end of file +assert build_info.version == "1.0.10" \ No newline at end of file diff --git a/crates/radix-engine-toolkit-uniffi/tests/bindings/example.swift b/crates/radix-engine-toolkit-uniffi/tests/bindings/example.swift index a5f518ef..4882e5fe 100644 --- a/crates/radix-engine-toolkit-uniffi/tests/bindings/example.swift +++ b/crates/radix-engine-toolkit-uniffi/tests/bindings/example.swift @@ -6,5 +6,5 @@ do { let buildInformation = radix_engine_toolkit_uniffi.buildInformation() // Assert - assert(buildInformation.version == "1.0.9") + assert(buildInformation.version == "1.0.10") } diff --git a/crates/radix-engine-toolkit/Cargo.toml b/crates/radix-engine-toolkit/Cargo.toml index 0b9fa2ef..fecce573 100644 --- a/crates/radix-engine-toolkit/Cargo.toml +++ b/crates/radix-engine-toolkit/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "radix-engine-toolkit" -version = "1.0.9" +version = "1.0.10" edition = "2021" build = "build.rs" diff --git a/crates/sbor-json/Cargo.toml b/crates/sbor-json/Cargo.toml index 4bcda932..083b97c3 100644 --- a/crates/sbor-json/Cargo.toml +++ b/crates/sbor-json/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sbor-json" -version = "1.0.9" +version = "1.0.10" edition = "2021" description = "The implementation of the SBOR JSON representations" diff --git a/crates/uniffi-bindgen/Cargo.toml b/crates/uniffi-bindgen/Cargo.toml index 8c14092d..3db838e9 100644 --- a/crates/uniffi-bindgen/Cargo.toml +++ b/crates/uniffi-bindgen/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "uniffi-bindgen" -version = "1.0.9" +version = "1.0.10" edition = "2021" [dependencies] -uniffi = { git = "https://github.com/0xOmarA/uniffi-rs", tag = "v0.25.4", features = ["cli"] } \ No newline at end of file +uniffi = { git = "https://github.com/0xOmarA/uniffi-rs", tag = "v0.25.4", features = ["cli"] } diff --git a/scripts/version_update.sh b/scripts/version_update.sh new file mode 100755 index 00000000..bfa5fcb0 --- /dev/null +++ b/scripts/version_update.sh @@ -0,0 +1,14 @@ +# +# Update version before release +# +# How to use: edit 'old_version' and 'new_version' variables, run script from current folder. +# +# Requires cargo-edit utility, to install run command: cargo install cargo-edit +# + +old_version="1.0.9" +new_version="1.0.10" + +cd .. +cargo set-version $new_version +sed -i "" -e "s/$old_version/$new_version/g" crates/radix-engine-toolkit-uniffi/tests/bindings/example.kts crates/radix-engine-toolkit-uniffi/tests/bindings/example.py crates/radix-engine-toolkit-uniffi/tests/bindings/example.swift From e4c2eeb581450ddee1c6f0b242b0d54a753f89fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Wed, 7 Feb 2024 23:30:10 +0100 Subject: [PATCH 11/13] Build aarch64 fix #1 --- .github/workflows/build.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e9ca39bd..7e410db5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -125,6 +125,7 @@ jobs: echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV echo "AR=aarch64-linux-gnu-gcc-ar" >> $GITHUB_ENV + echo "HOST_CC=x86_64-linux-gnu-gcc" >> $GITHUB_ENV - name: Build Dependencies (android) uses: nttld/setup-ndk@v1 id: setup-ndk @@ -220,6 +221,7 @@ jobs: name: uniffi-bindings path: uniffi-bindings publish-swift-spm: + if: false needs: [build, generate-uniffi-bindings] runs-on: macos-latest steps: @@ -351,6 +353,7 @@ jobs: name: "RadixEngineToolkit.xcframework" path: "./artifacts/RadixEngineToolkit.xcframework" publish-kotlin-maven-github: + if: false needs: [build, generate-uniffi-bindings] runs-on: macos-latest permissions: @@ -381,6 +384,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} publish-kotlin-maven-central: + if: false needs: [build, generate-uniffi-bindings] runs-on: ubuntu-latest permissions: @@ -441,6 +445,7 @@ jobs: arguments: build javadoc publishMavenCentralPublicationToMavenCentralRepository -Psigning.secretKeyRingFile=rdx-secring.gpg -Psigning.password=${{ env.GPG_PASSPHRASE_GPG_PASSPHRASE }} -Psigning.keyId=${{ secrets.GPG_KEY_ID }} -PossrhUsername=${{ env.MAVEN_CENTRAL_MAVEN_CENTRAL_USERNAME }} -PossrhPassword=${{ env.MAVEN_CENTRAL_MAVEN_CENTRAL_PASSWORD }} build-root-directory: interop/kotlin/ret-kotlin publish-android-maven: + if: false needs: [build, generate-uniffi-bindings] runs-on: macos-latest permissions: @@ -478,6 +483,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} publish-dotnet-nuget: + if: false needs: [build, generate-uniffi-bindings] runs-on: ubuntu-latest permissions: @@ -533,6 +539,7 @@ jobs: working-directory: interop/csharp/ run: dotnet nuget push RadixDlt.RadixEngineToolkit.*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ORG_API_KEY }} publish-python-package: + if: false needs: [build, generate-uniffi-bindings] runs-on: ubuntu-latest permissions: From 4934a4c43ef73d1a6f32af55ece1925a47f5015e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Thu, 8 Feb 2024 00:04:34 +0100 Subject: [PATCH 12/13] Build pc-windows fix #1 --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7e410db5..5177ed3c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -155,6 +155,7 @@ jobs: echo "CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc" >> $GITHUB_ENV echo "CC=x86_64-w64-mingw32-gcc" >> $GITHUB_ENV echo "AR=x86_64-w64-mingw32-gcc-ar" >> $GITHUB_ENV + echo "HOST_CC=x86_64-linux-gnu-gcc" >> $GITHUB_ENV - name: Build working-directory: crates/${{ matrix.build-target.crate }} From f93152b43c4364cbc0413f3b492639d3506ff4eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Strug?= Date: Thu, 8 Feb 2024 00:19:56 +0100 Subject: [PATCH 13/13] Cleanup --- .github/workflows/build.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5177ed3c..4333ab3c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -222,7 +222,6 @@ jobs: name: uniffi-bindings path: uniffi-bindings publish-swift-spm: - if: false needs: [build, generate-uniffi-bindings] runs-on: macos-latest steps: @@ -354,7 +353,6 @@ jobs: name: "RadixEngineToolkit.xcframework" path: "./artifacts/RadixEngineToolkit.xcframework" publish-kotlin-maven-github: - if: false needs: [build, generate-uniffi-bindings] runs-on: macos-latest permissions: @@ -385,7 +383,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} publish-kotlin-maven-central: - if: false needs: [build, generate-uniffi-bindings] runs-on: ubuntu-latest permissions: @@ -446,7 +443,6 @@ jobs: arguments: build javadoc publishMavenCentralPublicationToMavenCentralRepository -Psigning.secretKeyRingFile=rdx-secring.gpg -Psigning.password=${{ env.GPG_PASSPHRASE_GPG_PASSPHRASE }} -Psigning.keyId=${{ secrets.GPG_KEY_ID }} -PossrhUsername=${{ env.MAVEN_CENTRAL_MAVEN_CENTRAL_USERNAME }} -PossrhPassword=${{ env.MAVEN_CENTRAL_MAVEN_CENTRAL_PASSWORD }} build-root-directory: interop/kotlin/ret-kotlin publish-android-maven: - if: false needs: [build, generate-uniffi-bindings] runs-on: macos-latest permissions: @@ -484,7 +480,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} publish-dotnet-nuget: - if: false needs: [build, generate-uniffi-bindings] runs-on: ubuntu-latest permissions: @@ -540,7 +535,6 @@ jobs: working-directory: interop/csharp/ run: dotnet nuget push RadixDlt.RadixEngineToolkit.*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ORG_API_KEY }} publish-python-package: - if: false needs: [build, generate-uniffi-bindings] runs-on: ubuntu-latest permissions: