Skip to content

Commit

Permalink
feat: add debug mode for build_script_with_sections
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasArrachea committed Jan 10, 2025
1 parent 3e1f1ef commit 549786b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions crates/rust-client/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,10 @@ impl<R: FeltRng> Client<R> {
let future_notes: Vec<(NoteDetails, NoteTag)> =
transaction_request.expected_future_notes().cloned().collect();

let tx_script = transaction_request
.build_transaction_script(self.get_account_capabilities(account_id).await?)?;
let tx_script = transaction_request.build_transaction_script(
self.get_account_capabilities(account_id).await?,
self.in_debug_mode,
)?;

let foreign_accounts = transaction_request.foreign_accounts().clone();
let mut tx_args = transaction_request.into_transaction_args(tx_script);
Expand Down
3 changes: 2 additions & 1 deletion crates/rust-client/src/transactions/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,15 @@ impl TransactionRequest {
pub(crate) fn build_transaction_script(
&self,
account_capabilities: AccountCapabilities,
in_debug_mode: bool,
) -> Result<TransactionScript, TransactionRequestError> {
match &self.script_template {
Some(TransactionScriptTemplate::CustomScript(script)) => Ok(script.clone()),
Some(TransactionScriptTemplate::SendNotes(notes)) => {
let tx_script_builder =
TransactionScriptBuilder::new(account_capabilities, self.expiration_delta);

Ok(tx_script_builder.build_send_notes_script(notes)?)
Ok(tx_script_builder.build_send_notes_script(notes, in_debug_mode)?)
},
None => {
if self.input_notes.is_empty() {
Expand Down
9 changes: 6 additions & 3 deletions crates/rust-client/src/transactions/script_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,19 @@ impl TransactionScriptBuilder {
pub fn build_send_notes_script(
&self,
output_notes: &[PartialNote],
in_debug_mode: bool,
) -> Result<TransactionScript, TransactionScriptBuilderError> {
let send_note_procedure = self
.account_capabilities
.interfaces
.send_note_procedure(self.account_capabilities.account_id, output_notes)?;

self.build_script_with_sections(vec![send_note_procedure])
self.build_script_with_sections(vec![send_note_procedure], in_debug_mode)
}

/// Builds a simple authentication script for the transaction that doesn't send any notes.
pub fn build_auth_script(&self) -> Result<TransactionScript, TransactionScriptBuilderError> {
self.build_script_with_sections(vec![])
self.build_script_with_sections(vec![], false)
}

/// Builds a transaction script with the specified sections.
Expand All @@ -168,6 +169,7 @@ impl TransactionScriptBuilder {
fn build_script_with_sections(
&self,
sections: Vec<String>,
debug_mode: bool,
) -> Result<TransactionScript, TransactionScriptBuilderError> {
let script = format!(
"{} begin {} {} {} end",
Expand All @@ -177,7 +179,8 @@ impl TransactionScriptBuilder {
self.script_authentication()
);

let tx_script = TransactionScript::compile(script, vec![], TransactionKernel::assembler())
let assembler = TransactionKernel::assembler().with_debug_mode(debug_mode);
let tx_script = TransactionScript::compile(script, vec![], assembler)
.map_err(TransactionScriptBuilderError::InvalidTransactionScript)?;

Ok(tx_script)
Expand Down

0 comments on commit 549786b

Please sign in to comment.