Skip to content

Commit

Permalink
WIP 2
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Oct 12, 2024
1 parent 5c13a86 commit bb451a1
Show file tree
Hide file tree
Showing 46 changed files with 661 additions and 581 deletions.
38 changes: 19 additions & 19 deletions core-rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions core-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ resolver = "2"
# $ 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-39a21e3a", features = ["serde"] }
radix-transactions = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-39a21e3a" }
radix-transaction-scenarios = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-39a21e3a" }
radix-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-39a21e3a", features = ["serde"] }
radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-39a21e3a" }
radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-39a21e3a" }
radix-substate-store-impls = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-39a21e3a" }
radix-substate-store-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-39a21e3a" }
radix-substate-store-queries = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-39a21e3a" }
radix-rust = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-39a21e3a", features = ["serde"] }
radix-blueprint-schema-init = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-39a21e3a", features = ["serde"] }
radix-engine-toolkit-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-39a21e3a" }
sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-6130d5b2", features = ["serde"] }
radix-transactions = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-6130d5b2" }
radix-transaction-scenarios = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-6130d5b2" }
radix-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-6130d5b2", features = ["serde"] }
radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-6130d5b2" }
radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-6130d5b2" }
radix-substate-store-impls = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-6130d5b2" }
radix-substate-store-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-6130d5b2" }
radix-substate-store-queries = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-6130d5b2" }
radix-rust = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-6130d5b2", features = ["serde"] }
radix-blueprint-schema-init = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-6130d5b2", features = ["serde"] }
radix-engine-toolkit-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "cuttlefish-6130d5b2" }

itertools = { version = "=0.10.5" }
jni = { version = "=0.19.0" }
Expand Down
2 changes: 2 additions & 0 deletions core-rust/core-api-server/src/core_api/conversions/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ pub fn to_api_substate_system_structure(
SystemFieldKind::VmBoot => models::SystemFieldKind::VmBoot,
SystemFieldKind::SystemBoot => models::SystemFieldKind::SystemBoot,
SystemFieldKind::KernelBoot => models::SystemFieldKind::KernelBoot,
SystemFieldKind::TransactionValidationConfiguration => todo!(),
SystemFieldKind::ProtocolUpdateStatusSummary => todo!(),
},
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::core_api::*;
use crate::engine_prelude::*;

use state_manager::query::{dump_component_state, ComponentStateDump, DescendantParentOpt};
use state_manager::query::*;

use std::ops::Deref;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn to_api_scenario_transaction(
Ok(models::ExecutedScenarioTransaction {
logical_name: transaction.logical_name.clone(),
state_version: to_api_state_version(transaction.state_version)?,
intent_hash: to_api_intent_hash(&transaction.intent_hash),
intent_hash_bech32m: to_api_hash_bech32m(context, &transaction.intent_hash)?,
intent_hash: to_api_intent_hash(&transaction.transaction_intent_hash),
intent_hash_bech32m: to_api_hash_bech32m(context, &transaction.transaction_intent_hash)?,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ pub fn to_api_ledger_transaction(
context: &MappingContext,
raw_ledger_transaction: &RawLedgerTransaction,
ledger_transaction: &LedgerTransaction,
payload_identifiers: &PayloadIdentifiers,
hashes: &LedgerTransactionHashes,
) -> Result<models::LedgerTransaction, MappingError> {
let payload_hex = if context.transaction_options.include_raw_ledger {
Some(to_hex(raw_ledger_transaction.as_slice()))
Expand All @@ -320,7 +320,7 @@ pub fn to_api_ledger_transaction(

Ok(match ledger_transaction {
LedgerTransaction::UserV1(tx) => {
let user_identifiers = payload_identifiers.typed.user().ok_or_else(|| {
let user_hashes = hashes.as_user().ok_or_else(|| {
MappingError::MismatchedTransactionIdentifiers {
message: "Transaction hashes for notarized transaction were not user"
.to_string(),
Expand All @@ -331,12 +331,11 @@ pub fn to_api_ledger_transaction(
notarized_transaction: Box::new(to_api_notarized_transaction(
context,
tx,
user_identifiers.intent_hash,
user_identifiers.signed_intent_hash,
user_identifiers.notarized_transaction_hash,
&user_hashes,
)?),
}
}
LedgerTransaction::UserV2(tx) => todo!(),
LedgerTransaction::RoundUpdateV1(tx) => {
models::LedgerTransaction::RoundUpdateLedgerTransaction {
payload_hex,
Expand Down Expand Up @@ -372,9 +371,7 @@ pub fn to_api_ledger_transaction(
pub fn to_api_notarized_transaction(
context: &MappingContext,
notarized: &NotarizedTransactionV1,
intent_hash: &IntentHash,
signed_intent_hash: &SignedIntentHash,
notarized_transaction_hash: &NotarizedTransactionHash,
user_hashes: &UserTransactionHashes,
) -> Result<models::NotarizedTransaction, MappingError> {
let payload_hex = if context.transaction_options.include_raw_notarized {
Some(to_hex(notarized.to_payload_bytes().map_err(|err| {
Expand All @@ -394,8 +391,8 @@ pub fn to_api_notarized_transaction(
signed_intent: Box::new(to_api_signed_intent(
context,
&notarized.signed_intent,
intent_hash,
signed_intent_hash,
&user_hashes.transaction_intent_hash,
&user_hashes.signed_transaction_intent_hash,
)?),
notary_signature: Some(to_api_signature(&notarized.notary_signature.0)),
})
Expand All @@ -405,13 +402,13 @@ pub fn to_api_notarized_transaction(
pub fn to_api_signed_intent(
context: &MappingContext,
signed_intent: &SignedIntentV1,
intent_hash: &IntentHash,
signed_intent_hash: &SignedIntentHash,
transaction_intent_hash: &TransactionIntentHash,
signed_transaction_intent_hash: &SignedTransactionIntentHash,
) -> Result<models::SignedTransactionIntent, MappingError> {
Ok(models::SignedTransactionIntent {
hash: to_api_signed_intent_hash(signed_intent_hash),
hash_bech32m: to_api_hash_bech32m(context, signed_intent_hash)?,
intent: Box::new(to_api_intent(context, &signed_intent.intent, intent_hash)?),
hash: to_api_signed_intent_hash(signed_transaction_intent_hash),
hash_bech32m: to_api_hash_bech32m(context, signed_transaction_intent_hash)?,
intent: Box::new(to_api_intent(context, &signed_intent.intent, transaction_intent_hash)?),
intent_signatures: signed_intent
.intent_signatures
.signatures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ pub(crate) async fn handle_transaction_callpreview(
extract_package_address(&extraction_context, package_address.as_str())
.map_err(|err| err.into_response_error("target.package_address"))?;

InstructionV1::CallFunction {
InstructionV1::CallFunction(CallFunction {
blueprint_name,
function_name,
package_address: package_address.into(),
args: args_from_bytes_vec!(args),
}
})
}
models::TargetIdentifier::ComponentMethodTargetIdentifier {
component_address,
Expand All @@ -64,11 +64,11 @@ pub(crate) async fn handle_transaction_callpreview(
extract_component_address(&extraction_context, component_address.as_str())
.map_err(|err| err.into_response_error("target.component_address"))?;

InstructionV1::CallMethod {
InstructionV1::CallMethod(CallMethod {
address: component_address.into(),
method_name,
args: args_from_bytes_vec!(args),
}
})
}
};

Expand All @@ -77,6 +77,7 @@ pub(crate) async fn handle_transaction_callpreview(
manifest: TransactionManifestV1 {
instructions: vec![requested_call],
blobs: index_map_new(),
object_names: Default::default(),
},
start_epoch_inclusive: None,
end_epoch_exclusive: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,11 @@ fn to_api_parsed_notarized_transaction(
ResponseMode::Full => Some(Box::new(to_api_notarized_transaction(
&context.mapping_context,
&parsed.model,
&intent_hash,
&signed_intent_hash,
&notarized_transaction_hash,
&UserTransactionHashes {
transaction_intent_hash,
signed_transaction_intent_hash,
notarized_transaction_hash,
},
)?)),
};

Expand Down
18 changes: 18 additions & 0 deletions core-rust/node-common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ impl<T> CaptureSupport<T> {
self.capture_value(value.clone());
}

/// Calls [`Self::capture_value()`] with the constructed value, or does nothing if
/// not expecting any value at the moment.
pub fn capture_if_required(&mut self, constructor: impl FnOnce() -> T){
if matches!(self, CaptureSupport::NotExpecting) {
return; // deliberately do nothing
}
self.capture_value(constructor());
}

/// Returns the currently captured value and resets the instance to "not expecting" state.
/// The [`Self::capture_value()`] must have been called before this method.
pub fn retrieve_captured(&mut self) -> T {
Expand All @@ -119,6 +128,15 @@ impl<T> CaptureSupport<T> {
};
value
}

/// Extracts the captured value as an [`Option<T>`].
pub fn into_option(self) -> Option<T> {
match self {
CaptureSupport::NotExpecting => None,
CaptureSupport::Expecting => None,
CaptureSupport::Captured(x) => Some(x),
}
}
}

pub trait IsAccountExt {
Expand Down
Loading

0 comments on commit bb451a1

Please sign in to comment.