Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Oct 6, 2024
2 parents 7de47f8 + 12a9ce3 commit 37df9ab
Show file tree
Hide file tree
Showing 10 changed files with 409 additions and 455 deletions.
376 changes: 186 additions & 190 deletions Cargo.lock

Large diffs are not rendered by default.

29 changes: 18 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,24 @@ members = [
# Shared dependencies that all of the crates need - for now this is just the
# `radixdlt-scrypto` dependencies
[workspace.dependencies]
sbor = { version = "1.2.0", features = ["serde"] }
scrypto = { version = "1.2.0", features = ["serde"] }
scrypto-test = { version = "1.2.0" }
radix-common = { version = "1.2.0", features = ["serde"] }
radix-engine = { version = "1.2.0" }
radix-engine-interface = { version = "1.2.0" }
radix-substate-store-queries = { version = "1.2.0" }
radix-substate-store-impls = { version = "1.2.0" }
radix-substate-store-interface = { version = "1.2.0" }
radix-transactions = { version = "1.2.0" }
radix-transaction-scenarios = { version = "1.2.0" }
sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "6ec9c337246b5d4cf3c142bd9af80e9e8bd5fbae", features = [
"serde",
] }
scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "6ec9c337246b5d4cf3c142bd9af80e9e8bd5fbae", features = [
"serde",
] }
scrypto-test = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "6ec9c337246b5d4cf3c142bd9af80e9e8bd5fbae" }
radix-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "6ec9c337246b5d4cf3c142bd9af80e9e8bd5fbae", features = [
"serde",
] }
radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "6ec9c337246b5d4cf3c142bd9af80e9e8bd5fbae" }
radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "6ec9c337246b5d4cf3c142bd9af80e9e8bd5fbae" }
radix-substate-store-queries = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "6ec9c337246b5d4cf3c142bd9af80e9e8bd5fbae" }
radix-substate-store-impls = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "6ec9c337246b5d4cf3c142bd9af80e9e8bd5fbae" }
radix-substate-store-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "6ec9c337246b5d4cf3c142bd9af80e9e8bd5fbae" }
radix-transactions = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "6ec9c337246b5d4cf3c142bd9af80e9e8bd5fbae" }
radix-transaction-scenarios = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "6ec9c337246b5d4cf3c142bd9af80e9e8bd5fbae" }
native-radix-engine-toolkit = { git = "https://github.com/radixdlt/radixdlt-scrypto", rev = "6ec9c337246b5d4cf3c142bd9af80e9e8bd5fbae", package = "radix-engine-toolkit" }

[profile.release]
incremental = false
Expand Down
2 changes: 2 additions & 0 deletions crates/radix-engine-toolkit-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ radix-engine = { workspace = true }
radix-engine-interface = { workspace = true }
radix-substate-store-queries = { workspace = true }
radix-transactions = { workspace = true }
native-radix-engine-toolkit = { workspace = true }

# Core Radix Engine Toolkit
radix-engine-toolkit = { path = "../radix-engine-toolkit" }
Expand All @@ -22,6 +23,7 @@ uniffi = { git = "https://github.com/0xOmarA/uniffi-rs", tag = "v0.25.4", featur
hex = "0.4.3"
thiserror = "1.0.50"
paste = "1.0.12"
serde_json = "1.0.127"

[build-dependencies]
# The UniFFI crate for generating bindings to other languages
Expand Down
28 changes: 19 additions & 9 deletions crates/radix-engine-toolkit-uniffi/src/transaction/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
// specific language governing permissions and limitations
// under the License.

use native_radix_engine_toolkit::receipt::{
RuntimeToolkitTransactionReceipt, SerializableToolkitTransactionReceipt,
};
use sbor::Versioned;

use crate::prelude::*;
Expand Down Expand Up @@ -98,17 +101,24 @@ impl TransactionManifest {
pub fn execution_summary(
&self,
network_id: u8,
encoded_receipt: Vec<u8>,
toolkit_receipt: String,
) -> Result<ExecutionSummary> {
let native = self.clone().to_native();
let versioned_transaction_receipt = native_scrypto_decode::<
NativeVersionedTransactionReceipt,
>(&encoded_receipt)?;
let receipt = versioned_transaction_receipt
.as_latest_version()
.ok_or(RadixEngineToolkitError::InvalidReceipt)?;

core_manifest_execution_summary(&native, receipt)
let network_definition =
core_network_definition_from_network_id(network_id);
let receipt = serde_json::from_str::<
SerializableToolkitTransactionReceipt,
>(&toolkit_receipt)
.ok()
.and_then(|receipt| {
receipt
.into_runtime_receipt(&NativeAddressBech32Decoder::new(
&network_definition,
))
.ok()
})
.ok_or(RadixEngineToolkitError::InvalidReceipt)?;
core_manifest_execution_summary(&native, &receipt)
.map_err(|_| RadixEngineToolkitError::InvalidReceipt)
.map(|summary| ExecutionSummary::from_native(summary, network_id))?
}
Expand Down
1 change: 1 addition & 0 deletions crates/radix-engine-toolkit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ radix-substate-store-impls = { workspace = true }
radix-substate-store-queries = { workspace = true }
radix-substate-store-interface = { workspace = true }
radix-transactions = { workspace = true }
native-radix-engine-toolkit = { workspace = true }

# Bech32 encoding and decoding of addresses. Used for the Olympia <-> Babylon
# address derivations.
Expand Down
5 changes: 2 additions & 3 deletions crates/radix-engine-toolkit/src/functions/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
// specific language governing permissions and limitations
// under the License.

use native_radix_engine_toolkit::receipt::RuntimeToolkitTransactionReceipt;
use radix_common::prelude::*;
use radix_engine_interface::blueprints::access_controller::*;
use radix_engine_interface::blueprints::account::*;
use radix_transactions::errors::*;
use radix_transactions::prelude::*;
use radix_transactions::validation::*;

use radix_engine::transaction::*;

use crate::transaction_types::*;

pub fn hash(manifest: &TransactionManifestV1) -> Result<Hash, EncodeError> {
Expand Down Expand Up @@ -227,7 +226,7 @@ pub fn summary(manifest: &TransactionManifestV1) -> ManifestSummary {

pub fn execution_summary(
manifest: &TransactionManifestV1,
receipt: &TransactionReceipt,
receipt: &RuntimeToolkitTransactionReceipt,
) -> Result<ExecutionSummary, TransactionTypesError> {
crate::transaction_types::execution_summary(manifest, receipt)
}
Expand Down
18 changes: 5 additions & 13 deletions crates/radix-engine-toolkit/src/transaction_types/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
//! any of the implementation details of how the module finds and determines
//! the transaction types.
use native_radix_engine_toolkit::receipt::RuntimeToolkitTransactionReceipt;
use radix_common::prelude::*;
use radix_engine::transaction::*;
use radix_substate_store_queries::typed_substate_layout::*;
use radix_transactions::prelude::*;

Expand Down Expand Up @@ -131,10 +131,10 @@ pub fn summary(manifest: &TransactionManifestV1) -> ManifestSummary {

pub fn execution_summary(
manifest: &TransactionManifestV1,
receipt: &TransactionReceipt,
receipt: &RuntimeToolkitTransactionReceipt,
) -> Result<ExecutionSummary, TransactionTypesError> {
// Attempt to create a tx types receipt from the passed receipt
let receipt = TransactionTypesReceipt::new(receipt)
let receipt = TransactionTypesReceipt::new(&receipt)
.ok_or(TransactionTypesError::InvalidReceipt)?;

// Settings up the various detectors
Expand Down Expand Up @@ -308,16 +308,8 @@ pub fn execution_summary(
.rev()
.collect::<Vec<DetailedManifestClass>>();

let fee_locks = FeeLocks {
lock: receipt.execution_trace().fee_locks.lock,
contingent_lock: receipt.execution_trace().fee_locks.contingent_lock,
};
let fee_summary = FeeSummary {
execution_cost: receipt.fee_summary.total_execution_cost_in_xrd,
finalization_cost: receipt.fee_summary.total_finalization_cost_in_xrd,
storage_expansion_cost: receipt.fee_summary.total_storage_cost_in_xrd,
royalty_cost: receipt.fee_summary.total_royalty_cost_in_xrd,
};
let fee_locks = receipt.fee_locks();
let fee_summary = receipt.fee_summary();

Ok(ExecutionSummary {
account_withdraws,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ pub mod manifest_summary {
instruction_index: usize,
) {
// At the beginning of an instruction, call the on_instruction callback
callbacks.iter_mut().for_each(
|callback| callback.on_instruction(instruction, instruction_index)
);
callbacks.iter_mut().for_each(|callback| {
callback.on_instruction(instruction, instruction_index)
});

// Notify the callbacks of the created account proofs
handle_on_create_proof(callbacks, instruction);
Expand All @@ -58,9 +58,9 @@ pub mod manifest_summary {
let Ok(global_address) = GlobalAddress::try_from(node_id) else {
continue;
};
callbacks.iter_mut().for_each(
|callback| callback.on_global_entity_encounter(global_address)
);
callbacks.iter_mut().for_each(|callback| {
callback.on_global_entity_encounter(global_address)
});
}
}

Expand Down Expand Up @@ -249,9 +249,9 @@ pub mod execution_summary {
bucket_tracker: &IndexMap<ManifestBucket, ResourceIndicator>,
) {
let worktop_changes_entry = receipt
.execution_trace()
.worktop_changes()
.get(&instruction_index).cloned()
.get(&instruction_index)
.cloned()
.unwrap_or_default();

let inputs = {
Expand Down Expand Up @@ -289,9 +289,9 @@ pub mod execution_summary {
if let Some(resource_indicator) =
bucket_tracker.get(bucket_id)
{
inputs.push(
ResourceSpecifier::from(resource_indicator.clone())
)
inputs.push(ResourceSpecifier::from(
resource_indicator.clone(),
))
}
}
/* Non-sink methods */
Expand Down Expand Up @@ -325,17 +325,16 @@ pub mod execution_summary {

inputs
};
let outputs =
worktop_changes_entry
.iter()
.filter_map(|item| {
if let WorktopChange::Put(resource_specifier) = item {
Some(resource_specifier.clone())
} else {
None
}
})
.collect::<Vec<_>>();
let outputs = worktop_changes_entry
.iter()
.filter_map(|item| {
if let WorktopChange::Put(resource_specifier) = item {
Some(resource_specifier.clone())
} else {
None
}
})
.collect::<Vec<_>>();
callbacks.iter_mut().for_each(|callback| {
ExecutionSummaryCallback::on_instruction(
*callback,
Expand Down Expand Up @@ -531,10 +530,8 @@ pub mod execution_summary {
.expressions()
.contains(&ManifestExpression::EntireWorktop)
{
if let Some(worktop_changes) = receipt
.execution_trace()
.worktop_changes()
.get(&instruction_index)
if let Some(worktop_changes) =
receipt.worktop_changes().get(&instruction_index)
{
for resource_indicator in worktop_changes
.iter()
Expand Down Expand Up @@ -737,7 +734,6 @@ pub mod execution_summary {
resource_address: ResourceAddress,
) -> Option<Decimal> {
receipt
.execution_trace()
.worktop_changes()
.entry(instruction_index)
.or_default()
Expand All @@ -760,7 +756,6 @@ pub mod execution_summary {
resource_address: ResourceAddress,
) -> Option<IndexSet<NonFungibleLocalId>> {
receipt
.execution_trace()
.worktop_changes()
.entry(instruction_index)
.or_default()
Expand All @@ -787,7 +782,6 @@ pub mod execution_summary {
resource_address: ResourceAddress,
) -> Option<IndexSet<NonFungibleLocalId>> {
receipt
.execution_trace()
.worktop_changes()
.entry(instruction_index)
.or_default()
Expand Down
Loading

0 comments on commit 37df9ab

Please sign in to comment.