From 0b1c348e3c9b690f467dd95867627cd03f24cf5c Mon Sep 17 00:00:00 2001 From: Omar Date: Thu, 30 Mar 2023 17:13:55 +0300 Subject: [PATCH] return newly created entities --- radix-engine-toolkit/src/error.rs | 3 + .../analyze_manifest_with_preview_context.rs | 60 ++++++++++++++++++- ...anifest_with_preview_context_response.json | 44 ++++++++++++++ 3 files changed, 104 insertions(+), 3 deletions(-) diff --git a/radix-engine-toolkit/src/error.rs b/radix-engine-toolkit/src/error.rs index 3d2e0d38..8282f588 100644 --- a/radix-engine-toolkit/src/error.rs +++ b/radix-engine-toolkit/src/error.rs @@ -201,6 +201,9 @@ pub enum Error { NotAnOlympiaAddress { address: String, }, + + /// Transaction was not committed. + TransactionNotCommitted, } impl Display for Error { diff --git a/radix-engine-toolkit/src/request/analyze_manifest_with_preview_context.rs b/radix-engine-toolkit/src/request/analyze_manifest_with_preview_context.rs index 6927c9ba..b4717aa7 100644 --- a/radix-engine-toolkit/src/request/analyze_manifest_with_preview_context.rs +++ b/radix-engine-toolkit/src/request/analyze_manifest_with_preview_context.rs @@ -17,7 +17,7 @@ use std::collections::BTreeSet; -use crate::error::Result; +use crate::error::{Error, Result}; use crate::model::address::{EntityAddress, NetworkAwarePackageAddress}; use crate::model::address::{NetworkAwareComponentAddress, NetworkAwareResourceAddress}; use crate::model::instruction::Instruction; @@ -27,7 +27,7 @@ use crate::visitor::{ AccountInteractionsInstructionVisitor, AccountProofsInstructionVisitor, AccountWithdraw, AccountWithdrawsInstructionVisitor, AddressAggregatorVisitor, ValueNetworkAggregatorVisitor, }; -use radix_engine::transaction::TransactionReceipt; +use radix_engine::transaction::{TransactionReceipt, TransactionResult}; use radix_engine::types::{scrypto_decode, ComponentAddress}; use toolkit_derive::serializable; @@ -110,6 +110,9 @@ pub struct AnalyzeManifestWithPreviewContextResponse { /// deposits which are guaranteed by the static analysis while the ones referred to as /// "estimate" are deposits which are primarily obtained from the context of the previews pub account_deposits: Vec, + + /// The set of entities which were newly created in this transaction. + pub created_entities: CreatedEntities, } /// The set of addresses encountered in the manifest @@ -130,6 +133,26 @@ pub struct EncounteredAddresses { pub package_addresses: BTreeSet, } +/// The set of newly created entities +#[serializable] +#[derive(PartialEq, PartialOrd, Eq, Ord)] +pub struct CreatedEntities { + /// The set of addresses of newly created components. + #[schemars(with = "BTreeSet")] + #[serde_as(as = "BTreeSet>")] + pub component_addresses: BTreeSet, + + /// The set of addresses of newly created resources. + #[schemars(with = "BTreeSet")] + #[serde_as(as = "BTreeSet>")] + pub resource_addresses: BTreeSet, + + /// The set of addresses of newly created packages. + #[schemars(with = "BTreeSet")] + #[serde_as(as = "BTreeSet>")] + pub package_addresses: BTreeSet, +} + /// The set of addresses encountered in the manifest #[serializable] #[derive(PartialEq, PartialOrd, Eq, Ord)] @@ -273,13 +296,18 @@ impl Handler(&request.transaction_receipt)?; + let commit = match receipt.result { + TransactionResult::Commit(commit) => Ok(commit), + _ => Err(Error::TransactionNotCommitted), + }?; + // Setting up the visitors that will be used on the instructions let mut account_interactions_visitor = AccountInteractionsInstructionVisitor::default(); let mut account_withdraws_visitor = AccountWithdrawsInstructionVisitor::default(); let mut account_proofs_visitor = AccountProofsInstructionVisitor::default(); let mut address_aggregator_visitor = AddressAggregatorVisitor::default(); let mut account_deposits_visitor = { - let receipt = scrypto_decode::(&request.transaction_receipt)?; let resource_changes = receipt .execution_trace .resource_changes @@ -325,6 +353,32 @@ impl Handler