Skip to content

Commit

Permalink
return newly created entities
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Mar 30, 2023
1 parent da5bf79 commit 0b1c348
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 3 deletions.
3 changes: 3 additions & 0 deletions radix-engine-toolkit/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ pub enum Error {
NotAnOlympiaAddress {
address: String,
},

/// Transaction was not committed.
TransactionNotCommitted,
}

impl Display for Error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<AccountDeposit>,

/// The set of entities which were newly created in this transaction.
pub created_entities: CreatedEntities,
}

/// The set of addresses encountered in the manifest
Expand All @@ -130,6 +133,26 @@ pub struct EncounteredAddresses {
pub package_addresses: BTreeSet<NetworkAwarePackageAddress>,
}

/// 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<EntityAddress>")]
#[serde_as(as = "BTreeSet<serde_with::TryFromInto<EntityAddress>>")]
pub component_addresses: BTreeSet<NetworkAwareComponentAddress>,

/// The set of addresses of newly created resources.
#[schemars(with = "BTreeSet<EntityAddress>")]
#[serde_as(as = "BTreeSet<serde_with::TryFromInto<EntityAddress>>")]
pub resource_addresses: BTreeSet<NetworkAwareResourceAddress>,

/// The set of addresses of newly created packages.
#[schemars(with = "BTreeSet<EntityAddress>")]
#[serde_as(as = "BTreeSet<serde_with::TryFromInto<EntityAddress>>")]
pub package_addresses: BTreeSet<NetworkAwarePackageAddress>,
}

/// The set of addresses encountered in the manifest
#[serializable]
#[derive(PartialEq, PartialOrd, Eq, Ord)]
Expand Down Expand Up @@ -273,13 +296,18 @@ impl Handler<AnalyzeManifestWithPreviewContextRequest, AnalyzeManifestWithPrevie
}
}?;

let receipt = scrypto_decode::<TransactionReceipt>(&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::<TransactionReceipt>(&request.transaction_receipt)?;
let resource_changes = receipt
.execution_trace
.resource_changes
Expand Down Expand Up @@ -325,6 +353,32 @@ impl Handler<AnalyzeManifestWithPreviewContextRequest, AnalyzeManifestWithPrevie
},
account_withdraws: account_withdraws_visitor.0,
account_deposits: account_deposits_visitor.deposits,
created_entities: CreatedEntities {
component_addresses: commit
.new_component_addresses()
.iter()
.map(|address| NetworkAwareComponentAddress {
address: *address,
network_id: request.network_id,
})
.collect(),
resource_addresses: commit
.new_resource_addresses()
.iter()
.map(|address| NetworkAwareResourceAddress {
address: *address,
network_id: request.network_id,
})
.collect(),
package_addresses: commit
.new_package_addresses()
.iter()
.map(|address| NetworkAwarePackageAddress {
address: *address,
network_id: request.network_id,
})
.collect(),
},
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"account_proof_resources",
"account_withdraws",
"accounts_requiring_auth",
"created_entities",
"encountered_addresses"
],
"properties": {
Expand Down Expand Up @@ -48,6 +49,14 @@
"items": {
"$ref": "#/definitions/AccountDeposit"
}
},
"created_entities": {
"description": "The set of entities which were newly created in this transaction.",
"allOf": [
{
"$ref": "#/definitions/CreatedEntities"
}
]
}
},
"definitions": {
Expand Down Expand Up @@ -504,6 +513,41 @@
"$ref": "#/definitions/EntityAddress"
}
}
},
"CreatedEntities": {
"description": "The set of newly created entities",
"type": "object",
"required": [
"component_addresses",
"package_addresses",
"resource_addresses"
],
"properties": {
"component_addresses": {
"description": "The set of addresses of newly created components.",
"type": "array",
"items": {
"$ref": "#/definitions/EntityAddress"
},
"uniqueItems": true
},
"resource_addresses": {
"description": "The set of addresses of newly created resources.",
"type": "array",
"items": {
"$ref": "#/definitions/EntityAddress"
},
"uniqueItems": true
},
"package_addresses": {
"description": "The set of addresses of newly created packages.",
"type": "array",
"items": {
"$ref": "#/definitions/EntityAddress"
},
"uniqueItems": true
}
}
}
}
}

0 comments on commit 0b1c348

Please sign in to comment.