Skip to content

Commit

Permalink
Merge pull request #128 from radixdlt/fix/subintent-abstractions
Browse files Browse the repository at this point in the history
Fix/subintent abstractions
  • Loading branch information
dhedey authored Oct 15, 2024
2 parents 19a5fe7 + a7e9eb2 commit 9c08da3
Show file tree
Hide file tree
Showing 28 changed files with 213 additions and 478 deletions.
163 changes: 24 additions & 139 deletions Cargo.lock

Large diffs are not rendered by default.

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

# ================================================================
# DEPENDENCIES ON RADIXDLT-SCRYPTO
# ================================================================
#
# To make builds reproducible, we must specify a fixed tag below, not a branch.
#
# Go to your checkout of `radixdlt-scrypto`, then run the following:
# $ git checkout <relevant-branch>
# $ git pull
# $ git rev-parse HEAD | cut -c1-8
# $ git tag "release_name-<8 char hash id from previous command>"
# $ git push origin "release_name-BLAH"
#
# Then use tag="release_name-BLAH" in the below dependencies.
# =================================================================

sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-2ea8b582", features = ["serde"] }
scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-2ea8b582", features = ["serde"] }
scrypto-test = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-2ea8b582" }
radix-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-2ea8b582", features = ["serde"] }
radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-2ea8b582" }
radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-2ea8b582" }
radix-substate-store-queries = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-2ea8b582" }
radix-substate-store-impls = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-2ea8b582" }
radix-substate-store-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-2ea8b582" }
radix-transactions = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-2ea8b582" }
radix-transaction-scenarios = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-2ea8b582" }
radix-engine-toolkit-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-2ea8b582" }

[profile.release]
incremental = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,14 @@ impl ManifestV2Builder {
subintent_hash: Arc<TransactionHash>,
name: ManifestBuilderIntent,
) -> Result<Arc<Self>> {
if !subintent_hash.as_str().contains("subtxid") {
return Err(RadixEngineToolkitError::InstructionAddError {
error: format!(
"Subintent hashes have a HRP with 'subtxid', but the following was provided: {}",
subintent_hash.as_str(),
),
});
}
builder_arc_map(self, |builder| {
builder.name_record.new_intent(&name.name)?;
builder.children.push(subintent_hash.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ impl SignedPartialTransactionV2Builder {

// Constructing the partial transaction
let partial_transaction = PartialTransactionV2 {
root_subintent: Arc::new(IntentCoreV2 {
root_subintent: SubintentV2::new(IntentCoreV2::new(
header,
blobs,
message,
children,
instructions,
}),
)),
non_root_subintents: signed_children
.iter()
.flat_map(|child| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ impl TransactionV2Builder {
// Constructing the transaction intent
let transaction_intent = TransactionIntentV2 {
transaction_header,
root_intent_core: Arc::new(IntentCoreV2 {
root_intent_core: IntentCoreV2::new(
header,
blobs,
message,
children,
instructions,
}),
),
non_root_subintents: signed_children
.iter()
.flat_map(|child| {
Expand Down
56 changes: 34 additions & 22 deletions crates/radix-engine-toolkit-uniffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,88 +21,99 @@ pub type Result<T> = std::result::Result<T, RadixEngineToolkitError>;

#[derive(Clone, Debug, Error, ThisError)]
pub enum RadixEngineToolkitError {
#[error("Length check failed.")]
#[error("Length check failed. Expected {expected}, actual {actual}.")]
InvalidLength {
expected: u64,
actual: u64,
data: Vec<u8>,
},

#[error("Failed to derive network id from address string")]
#[error("Failed to derive network id from address string {address}")]
FailedToExtractNetwork { address: String },

#[error("Failed to Bech32m decode the address")]
#[error("Failed to Bech32m decode the address: {error}")]
Bech32DecodeError { error: String },

#[error("Failed to parse a string into a typed object")]
#[error(
"Failed to parse a string into a typed object {type_name}: {error}"
)]
ParseError { type_name: String, error: String },

#[error(
"Failed to validate content during non-fungible local id conversion"
"Failed to validate content during non-fungible local id conversion: {error}"
)]
NonFungibleContentValidationError { error: String },

#[error("Entity type did not match expected")]
#[error("Entity type {actual:?} did not match expected {expected:?}")]
EntityTypeMismatchError {
expected: Vec<EntityType>,
actual: EntityType,
},

#[error("Failed to perform a derivation")]
#[error("Failed to perform a derivation: {error}")]
DerivationError { error: String },

#[error("Public key is not valid for a given operation")]
InvalidPublicKey,

#[error("Manifest compilation errored out")]
#[error("Failed to add instruction: {error}")]
InstructionAddError { error: String },

#[error("Manifest compilation errored out: {error}")]
CompileError { error: String },

#[error("Manifest decompilation errored out")]
#[error("Manifest decompilation errored out: {error}")]
DecompileError { error: String },

#[error("Failed while trying to prepare transaction part")]
#[error("Failed while trying to prepare transaction part: {error}")]
PrepareError { error: String },

#[error("Failed to SBOR encode some data")]
#[error("Failed to SBOR encode some data: {error}")]
EncodeError { error: String },

#[error("Failed to SBOR decode some payload")]
#[error("Failed to SBOR decode some payload: {error}")]
DecodeError { error: String },

#[error("Static validation of transaction part has failed")]
#[error("Static validation of transaction part has failed: {error}")]
TransactionValidationFailed { error: String },

#[error("Execution analysis failed")]
#[error("Execution analysis failed: {error}")]
ExecutionModuleError { error: String },

#[error("An error occurred during doing a Manifest SBOR encode/decode")]
#[error(
"An error occurred during doing a Manifest SBOR encode/decode: {error}"
)]
ManifestSborError { error: String },

#[error("An error occurred during doing a Scrypto SBOR encode/decode")]
#[error(
"An error occurred during doing a Scrypto SBOR encode/decode: {error}"
)]
ScryptoSborError { error: String },

#[error(
"An error occurred when trying to convert native event data to typed"
"An error occurred when trying to convert native event data to typed: {error}"
)]
TypedNativeEventError { error: String },

#[error("An error occurred when trying to decode the transaction hash")]
FailedToDecodeTransactionHash,
#[error(
"An error occurred when trying to decode the transaction hash: {error:?}"
)]
FailedToDecodeTransactionHash { error: String },

#[error(
"An error ocurred when building the manifest due to the naming of objects"
"An error ocurred when building the manifest due to the naming of objects: {error:?}"
)]
ManifestBuilderNameRecordError { error: NameRecordError },

#[error("The node id has no valid entity type")]
#[error("The node id has no valid entity type: {error}")]
InvalidEntityTypeIdError { error: String },

#[error(
"An error encountered when doing decimal arithmetic pertaining to overflow and underflow"
)]
DecimalError,

#[error("An error that occurred in the signer logic")]
#[error("An error that occurred in the signer logic: {error}")]
SignerError { error: String },

#[error("The receipt is not a valid preview receipt")]
Expand Down Expand Up @@ -168,6 +179,7 @@ impl_dbg_str_from! { NativeDecompileError, DecompileError }
impl_dbg_str_from! { NativePrepareError, PrepareError }
impl_dbg_str_from! { NativeEncodeError, EncodeError }
impl_dbg_str_from! { NativeDecodeError, DecodeError }
impl_dbg_str_from! { NativeTransactionHashBech32DecodeError, FailedToDecodeTransactionHash }
impl_dbg_str_from! { NativeTransactionValidationError, TransactionValidationFailed }
impl_dbg_str_from! { CoreInstructionValidationError, TransactionValidationFailed }
impl_dbg_str_from! { CoreManifestSborError, ManifestSborError }
Expand Down
16 changes: 3 additions & 13 deletions crates/radix-engine-toolkit-uniffi/src/internal_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ mod core {
OlympiaNetwork as CoreOlympiaNetwork,
};
pub use radix_engine_toolkit::functions::transaction_v1::instructions::{
hash as core_transaction_v1_instructions_hash,
to_payload_bytes as core_transaction_v1_instructions_to_payload_bytes,
from_payload_bytes as core_transaction_v1_instructions_from_payload_bytes,
statically_validate as core_transaction_v1_instructions_statically_validate,
extract_addresses as core_transaction_v1_instructions_extract_addresses,
InstructionValidationError as CoreInstructionValidationError,
Expand All @@ -60,7 +57,6 @@ mod core {
decode_transaction_id as core_decode_transaction_id
};
pub use radix_engine_toolkit::functions::transaction_v1::manifest::{
hash as core_transaction_v1_manifest_hash,
to_payload_bytes as core_transaction_v1_manifest_to_payload_bytes,
from_payload_bytes as core_transaction_v1_manifest_from_payload_bytes,
statically_validate as core_transaction_v1_manifest_statically_validate,
Expand All @@ -86,23 +82,14 @@ mod core {
statically_validate as core_transaction_v1_notarized_transaction_statically_validate,
};
pub use radix_engine_toolkit::functions::transaction_v2::instructions::{
hash as core_transaction_v2_instructions_hash,
to_payload_bytes as core_transaction_v2_instructions_to_payload_bytes,
from_payload_bytes as core_transaction_v2_instructions_from_payload_bytes,
extract_addresses as core_transaction_v2_instructions_extract_addresses,
};
pub use radix_engine_toolkit::functions::transaction_v2::manifest::{
hash as core_transaction_v2_manifest_hash,
to_payload_bytes as core_transaction_v2_manifest_to_payload_bytes,
from_payload_bytes as core_transaction_v2_manifest_from_payload_bytes,
statically_analyze as core_transaction_v2_manifest_statically_analyze,
dynamically_analyze as core_transaction_v2_manifest_dynamically_analyze,
};
pub use radix_engine_toolkit::functions::transaction_v2::intent_core::{
hash as core_transaction_v2_intent_core_hash,
to_payload_bytes as core_transaction_v2_intent_core_to_payload_bytes,
from_payload_bytes as core_transaction_v2_intent_core_from_payload_bytes,
};
pub use radix_engine_toolkit::functions::transaction_v2::subintent::{
hash as core_transaction_v2_subintent_hash,
to_payload_bytes as core_transaction_v2_subintent_to_payload_bytes,
Expand Down Expand Up @@ -262,6 +249,9 @@ mod native {
Ed25519Signature as NativeEd25519Signature,
Secp256k1Signature as NativeSecp256k1Signature,
};
pub use radix_transactions::prelude::{
TransactionHashBech32DecodeError as NativeTransactionHashBech32DecodeError,
};
pub use radix_transactions::manifest::{
compile as native_compile,
decompile as native_decompile,
Expand Down
1 change: 1 addition & 0 deletions crates/radix-engine-toolkit-uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub mod prelude {
pub use crate::transaction_v2::partial_transaction::*;
pub use crate::transaction_v2::signed_intent::*;
pub use crate::transaction_v2::signed_partial_transaction::*;
pub use crate::transaction_v2::subintent::*;
pub use crate::transaction_v2::transaction_header::*;
pub use crate::transaction_v2::transaction_intent::*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ impl TransactionHash {
pub fn from_str(string: String, network_id: u8) -> Result<Arc<Self>> {
let network_definition =
core_network_definition_from_network_id(network_id);
let hash = core_decode_transaction_id(&string, &network_definition)
.map_err(|_| {
RadixEngineToolkitError::FailedToDecodeTransactionHash
})?;
let hash = core_decode_transaction_id(&string, &network_definition)?;
Ok(Arc::new(Self(hash, string, network_id)))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl From<NativeIntentV1> for IntentV1 {
let blobs = blobs.blobs;
let instructions = instructions.0;
let manifest = NativeTransactionManifestV1 {
instructions: instructions.as_ref().clone(),
instructions,
blobs: blobs
.iter()
.map(|blob| (native_hash(&blob.0), blob.0.clone()))
Expand Down Expand Up @@ -136,9 +136,8 @@ impl TryFrom<IntentV1> for NativeIntentV1 {
.map(NativeBlobV1)
.collect(),
};
let instructions = NativeInstructionsV1(std::rc::Rc::new(
value.manifest.instructions.0.clone(),
));
let instructions =
NativeInstructionsV1(value.manifest.instructions.0.clone());
let header = value.header.try_into()?;
let message = value.message.try_into()?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ impl TransactionManifestV1 {
network_id: u8,
) -> Result<Arc<Self>> {
let decompiled =
core_transaction_v1_manifest_from_payload_bytes(compiled)?;
core_transaction_v1_manifest_from_payload_bytes(compiled).map_err(
|error| RadixEngineToolkitError::ManifestSborError { error },
)?;
Ok(Arc::new(Self::from_native(&decompiled, network_id)))
}

Expand Down
Loading

0 comments on commit 9c08da3

Please sign in to comment.