Skip to content

Commit

Permalink
Merge pull request #50 from radixdlt/feature/newly-created-resources
Browse files Browse the repository at this point in the history
Feature: Newly created resources
  • Loading branch information
0xOmarA authored Mar 30, 2023
2 parents 587cda1 + 0b1c348 commit ef27344
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 9 deletions.
7 changes: 1 addition & 6 deletions benches/benches/decompilation_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::time::Duration;

use benches::{Invoke, RadixEngineToolkit};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use native_transaction::{
Expand Down Expand Up @@ -59,8 +57,6 @@ fn decompile_intent_with_core_toolkit_benchmarks(c: &mut Criterion) {
let compiled_transaction = hex::decode(include_str!("./transaction.hex")).unwrap();

let mut group = c.benchmark_group("Decompile Intent with Toolkit Core");
group.sample_size(10);

group.bench_function("Decompile Unknown Intent to String", |b| {
b.iter(|| {
black_box({
Expand Down Expand Up @@ -169,8 +165,7 @@ fn decompile_intent_with_toolkit_wrapper_benchmarks(c: &mut Criterion) {

criterion_group!(
name = benches;
config = Criterion::default().measurement_time(Duration::from_secs(10));
// config = Criterion::default();
config = Criterion::default();
targets = decompile_intent_natively_benchmarks, decompile_intent_with_toolkit_wrapper_benchmarks, decompile_intent_with_core_toolkit_benchmarks
);
criterion_main!(benches);
Binary file modified benches/lib/libradix_engine_toolkit.dylib
Binary file not shown.
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 ef27344

Please sign in to comment.