diff --git a/dan_layer/engine/src/runtime/impl.rs b/dan_layer/engine/src/runtime/impl.rs index 4edf3deb2..7bb2e37b1 100644 --- a/dan_layer/engine/src/runtime/impl.rs +++ b/dan_layer/engine/src/runtime/impl.rs @@ -887,12 +887,7 @@ impl> RuntimeInte self.tracker.write_with(|state| { let vault_lock = state.lock_substate(&SubstateAddress::Vault(vault_id), LockFlag::Read)?; - // NOTE: A BTreeSet does not decode when received in the WASM - let non_fungible_ids = state - .get_vault(&vault_lock)? - .get_non_fungible_ids() - .iter() - .collect::>(); + let non_fungible_ids = state.get_vault(&vault_lock)?.get_non_fungible_ids(); let result = InvokeResult::encode(&non_fungible_ids)?; state.unlock_substate(vault_lock)?; Ok(result) @@ -1238,8 +1233,7 @@ impl> RuntimeInte self.tracker.write_with(|state| { let bucket = state.get_bucket(bucket_id)?; - let non_fungible_ids = bucket.non_fungible_ids().iter().collect::>(); - Ok(InvokeResult::encode(&non_fungible_ids)?) + Ok(InvokeResult::encode(bucket.non_fungible_ids())?) }) }, } diff --git a/dan_layer/engine/tests/account_nfts.rs b/dan_layer/engine/tests/account_nfts.rs index f6574b093..ea770619b 100644 --- a/dan_layer/engine/tests/account_nfts.rs +++ b/dan_layer/engine/tests/account_nfts.rs @@ -2,7 +2,12 @@ // SPDX-License-Identifier: BSD-3-Clause use tari_engine_types::instruction::Instruction; -use tari_template_lib::{args, models::ComponentAddress, prelude::Metadata, resource::TOKEN_SYMBOL}; +use tari_template_lib::{ + args, + models::{ComponentAddress, NonFungibleId}, + prelude::Metadata, + resource::TOKEN_SYMBOL, +}; use tari_template_test_tooling::TemplateTest; #[test] @@ -57,6 +62,11 @@ fn basic_nft_mint() { Instruction::PutLastInstructionOutputOnWorkspace { key: b"my_nft".to_vec(), }, + Instruction::CallFunction { + template_address: account_nft_template_test.get_template_address("Account"), + function: "get_non_fungible_ids_for_bucket".to_string(), + args: args![Variable("my_nft")], + }, Instruction::CallMethod { component_address: owner_component_address, method: "deposit".to_string(), @@ -68,4 +78,9 @@ fn basic_nft_mint() { .unwrap(); assert!(result.finalize.result.is_accept()); + + let bucket_nfts = result.finalize.execution_results[2] + .decode::>() + .unwrap(); + assert_eq!(bucket_nfts.len(), 1); } diff --git a/dan_layer/engine_types/Cargo.toml b/dan_layer/engine_types/Cargo.toml index c80489eb8..8304f5ef1 100644 --- a/dan_layer/engine_types/Cargo.toml +++ b/dan_layer/engine_types/Cargo.toml @@ -16,7 +16,7 @@ tari_template_lib = { workspace = true } tari_utilities = { workspace = true } borsh = { workspace = true } -# if we set this version in the workspace it would break other crates +# if we set this version in the workspace it would break other crates base64 = "0.21.0" blake2 = { workspace = true } rand = { workspace = true } @@ -27,7 +27,6 @@ serde = { workspace = true, default-features = true } serde_json = { workspace = true } thiserror = { workspace = true } - [features] default = ["debugging"] # Includes the ability to create free test coins diff --git a/dan_layer/template_builtin/templates/account/src/lib.rs b/dan_layer/template_builtin/templates/account/src/lib.rs index e8a06df63..19ee52b1f 100644 --- a/dan_layer/template_builtin/templates/account/src/lib.rs +++ b/dan_layer/template_builtin/templates/account/src/lib.rs @@ -26,6 +26,7 @@ use tari_template_lib::prelude::*; #[template] mod account_template { use super::*; + pub struct Account { // TODO: Lazy key value map/store vaults: BTreeMap, @@ -234,5 +235,11 @@ mod account_template { let v = self.get_vault_mut(resource); v.create_proof_by_amount(amount) } + + /// Utility function to allow bucket NFT content to be inspected. An empty vec is returned if the bucket does + /// not contain any NFTs or does not contain a NonFungible resource. + pub fn get_non_fungible_ids_for_bucket(bucket: Bucket) -> Vec { + bucket.get_non_fungible_ids() + } } }