From 98f57b6ccfb012e4237ef08e7f6b7fdc6293bced Mon Sep 17 00:00:00 2001 From: hukla <129692708+huklaa@users.noreply.github.com> Date: Mon, 10 Aug 2026 07:04:07 +0300 Subject: [PATCH 1/3] fix: use CodeBuilder for oracle script linking --- rust-client/src/bin/oracle_data_query.rs | 27 +++--------------------- 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/rust-client/src/bin/oracle_data_query.rs b/rust-client/src/bin/oracle_data_query.rs index 2847274..f69d59c 100644 --- a/rust-client/src/bin/oracle_data_query.rs +++ b/rust-client/src/bin/oracle_data_query.rs @@ -3,9 +3,7 @@ use miden_client::{ component::AccountComponentMetadata, AccountBuilder, AccountComponent, AccountId, AccountType, StorageMapKey, StorageSlot, StorageSlotName, }, - assembly::{ - CodeBuilder, DefaultSourceManager, Module, ModuleKind, Path as AssemblyPath, - }, + assembly::CodeBuilder, auth::NoAuth, builder::ClientBuilder, keystore::FilesystemKeyStore, @@ -13,7 +11,7 @@ use miden_client::{ domain::account::AccountStorageRequirements, Endpoint, GrpcClient, }, - transaction::{ForeignAccount, TransactionKernel, TransactionRequestBuilder}, + transaction::{ForeignAccount, TransactionRequestBuilder}, Client, ClientError, Felt, Word, ZERO, }; use miden_client_sqlite_store::ClientBuilderSqliteExt; @@ -95,21 +93,6 @@ pub async fn get_oracle_foreign_accounts( Ok(foreign_accounts) } -fn create_library( - library_path: &str, - source_code: &str, -) -> Result, Box> { - let source_manager = Arc::new(DefaultSourceManager::default()); - let assembler = TransactionKernel::assembler_with_source_manager(source_manager.clone()); - let module = Module::parser(ModuleKind::Library).parse_str( - AssemblyPath::new(library_path), - source_code, - source_manager, - )?; - let library = assembler.assemble_library([module])?; - Ok(library) -} - #[tokio::main] async fn main() -> Result<(), ClientError> { // ------------------------------------------------------------------------- @@ -203,13 +186,9 @@ async fn main() -> Result<(), ClientError> { let script_path = Path::new("../masm/scripts/oracle_reader_script.masm"); let script_code = fs::read_to_string(script_path).unwrap(); - let library_path = "external_contract::oracle_reader"; - let account_component_lib = - create_library(library_path, &contract_code).unwrap(); - let tx_script = client .code_builder() - .with_dynamically_linked_library(&account_component_lib) + .with_linked_module("external_contract::oracle_reader", &contract_code) .unwrap() .compile_tx_script(&script_code) .unwrap(); From 4e3011936e4411f269eb2556d212da2cca2a8740 Mon Sep 17 00:00:00 2001 From: hukla <129692708+huklaa@users.noreply.github.com> Date: Mon, 10 Aug 2026 16:07:19 +0300 Subject: [PATCH 2/3] fix: make oracle MASM paths cwd-independent --- rust-client/src/bin/oracle_data_query.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rust-client/src/bin/oracle_data_query.rs b/rust-client/src/bin/oracle_data_query.rs index f69d59c..8617a6c 100644 --- a/rust-client/src/bin/oracle_data_query.rs +++ b/rust-client/src/bin/oracle_data_query.rs @@ -16,7 +16,7 @@ use miden_client::{ }; use miden_client_sqlite_store::ClientBuilderSqliteExt; use rand::RngCore; -use std::{fs, path::Path, sync::Arc}; +use std::sync::Arc; /// Import the oracle + its publishers and return the ForeignAccount list /// Due to Pragma's decentralized oracle architecture, we need to get the @@ -147,13 +147,14 @@ async fn main() -> Result<(), ClientError> { // ------------------------------------------------------------------------- // Create Oracle Reader contract // ------------------------------------------------------------------------- - let contract_code = - fs::read_to_string(Path::new("../masm/accounts/oracle_reader.masm")).unwrap(); + // Compile-time inclusion keeps the example independent of the directory + // from which the binary is launched. + let contract_code = include_str!("../../../masm/accounts/oracle_reader.masm"); let contract_slot_name = StorageSlotName::new("miden::tutorials::oracle_reader").expect("valid slot name"); let contract_component_code = CodeBuilder::new() - .compile_component_code("external_contract::oracle_reader", &contract_code) + .compile_component_code("external_contract::oracle_reader", contract_code) .unwrap(); let contract_component = AccountComponent::new( contract_component_code, @@ -183,14 +184,13 @@ async fn main() -> Result<(), ClientError> { // ------------------------------------------------------------------------- // Build the script that calls our `get_price` procedure // ------------------------------------------------------------------------- - let script_path = Path::new("../masm/scripts/oracle_reader_script.masm"); - let script_code = fs::read_to_string(script_path).unwrap(); + let script_code = include_str!("../../../masm/scripts/oracle_reader_script.masm"); let tx_script = client .code_builder() - .with_linked_module("external_contract::oracle_reader", &contract_code) + .with_linked_module("external_contract::oracle_reader", contract_code) .unwrap() - .compile_tx_script(&script_code) + .compile_tx_script(script_code) .unwrap(); let tx_increment_request = TransactionRequestBuilder::new() From 37a5bff36530d0845afc670b4fdc76dc458d1d4d Mon Sep 17 00:00:00 2001 From: hukla <129692708+huklaa@users.noreply.github.com> Date: Mon, 10 Aug 2026 17:14:07 +0300 Subject: [PATCH 3/3] docs: update oracle tutorial linking API --- docs/src/rust-client/oracle_tutorial.md | 43 +++++++------------------ 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/docs/src/rust-client/oracle_tutorial.md b/docs/src/rust-client/oracle_tutorial.md index 865d99b..27181e2 100644 --- a/docs/src/rust-client/oracle_tutorial.md +++ b/docs/src/rust-client/oracle_tutorial.md @@ -57,9 +57,7 @@ use miden_client::{ component::AccountComponentMetadata, AccountBuilder, AccountComponent, AccountId, AccountType, StorageMapKey, StorageSlot, StorageSlotName, }, - assembly::{ - CodeBuilder, DefaultSourceManager, Module, ModuleKind, Path as AssemblyPath, - }, + assembly::CodeBuilder, auth::NoAuth, builder::ClientBuilder, keystore::FilesystemKeyStore, @@ -67,12 +65,12 @@ use miden_client::{ domain::account::AccountStorageRequirements, Endpoint, GrpcClient, }, - transaction::{ForeignAccount, TransactionKernel, TransactionRequestBuilder}, + transaction::{ForeignAccount, TransactionRequestBuilder}, Client, ClientError, Felt, Word, ZERO, }; use miden_client_sqlite_store::ClientBuilderSqliteExt; use rand::RngCore; -use std::{fs, path::Path, sync::Arc}; +use std::sync::Arc; /// Import the oracle + its publishers and return the ForeignAccount list /// Due to Pragma's decentralized oracle architecture, we need to get the @@ -149,21 +147,6 @@ pub async fn get_oracle_foreign_accounts( Ok(foreign_accounts) } -fn create_library( - library_path: &str, - source_code: &str, -) -> Result, Box> { - let source_manager = Arc::new(DefaultSourceManager::default()); - let assembler = TransactionKernel::assembler_with_source_manager(source_manager.clone()); - let module = Module::parser(ModuleKind::Library).parse_str( - AssemblyPath::new(library_path), - source_code, - source_manager, - )?; - let library = assembler.assemble_library([module])?; - Ok(library) -} - #[tokio::main] async fn main() -> Result<(), ClientError> { // ------------------------------------------------------------------------- @@ -218,13 +201,14 @@ async fn main() -> Result<(), ClientError> { // ------------------------------------------------------------------------- // Create Oracle Reader contract // ------------------------------------------------------------------------- - let contract_code = - fs::read_to_string(Path::new("../masm/accounts/oracle_reader.masm")).unwrap(); + // Compile-time inclusion keeps the example independent of the directory + // from which the binary is launched. + let contract_code = include_str!("../masm/accounts/oracle_reader.masm"); let contract_slot_name = StorageSlotName::new("miden::tutorials::oracle_reader").expect("valid slot name"); let contract_component_code = CodeBuilder::new() - .compile_component_code("external_contract::oracle_reader", &contract_code) + .compile_component_code("external_contract::oracle_reader", contract_code) .unwrap(); let contract_component = AccountComponent::new( contract_component_code, @@ -254,18 +238,13 @@ async fn main() -> Result<(), ClientError> { // ------------------------------------------------------------------------- // Build the script that calls our `get_price` procedure // ------------------------------------------------------------------------- - let script_path = Path::new("../masm/scripts/oracle_reader_script.masm"); - let script_code = fs::read_to_string(script_path).unwrap(); - - let library_path = "external_contract::oracle_reader"; - let account_component_lib = - create_library(library_path, &contract_code).unwrap(); + let script_code = include_str!("../masm/scripts/oracle_reader_script.masm"); let tx_script = client .code_builder() - .with_dynamically_linked_library(&account_component_lib) + .with_linked_module("external_contract::oracle_reader", contract_code) .unwrap() - .compile_tx_script(&script_code) + .compile_tx_script(script_code) .unwrap(); let tx_increment_request = TransactionRequestBuilder::new() @@ -455,4 +434,4 @@ This defaults to Pragma's current testnet oracle. To read from a different deplo ### Continue learning -Next tutorial: [How to Use Unauthenticated Notes](./unauthenticated_note_how_to.md) +Next tutorial: [How to Use Unauthenticated Notes](./unauthenticated_note_how_to.md) \ No newline at end of file