Skip to content

Commit

Permalink
[fix] #0000: Fix smart contract debug print (#4178)
Browse files Browse the repository at this point in the history
[fix]: Fix smart contract debug print

Signed-off-by: Daniil Polyakov <[email protected]>
  • Loading branch information
Arjentix authored Dec 28, 2023
1 parent 2ca4b9f commit f147295
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion smart_contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ workspace = true

[features]
# Enables debugging tools such as `dbg()` and `DebugUnwrapExt`
debug = []
debug = ["iroha_smart_contract_utils/debug"]

[dependencies]
iroha_data_model.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion smart_contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ unsafe extern "C" fn _iroha_smart_contract_dealloc(offset: *mut u8, len: usize)
///
/// # Example
///
/// ```
/// ```ignore
/// use iroha_smart_contract::{prelude::*, parse};
///
/// let account_id = parse!("alice@wonderland" as AccountId);
Expand Down
3 changes: 3 additions & 0 deletions smart_contract/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ license.workspace = true
[lints]
workspace = true

[features]
debug = []

[dependencies]
iroha_data_model.workspace = true

Expand Down
7 changes: 5 additions & 2 deletions smart_contract/utils/src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! WASM debugging utilities
#[cfg(feature = "debug")]
use alloc::format;
use core::fmt::Debug;

#[cfg(not(test))]
Expand Down Expand Up @@ -30,9 +32,9 @@ pub fn dbg<T: Debug + ?Sized>(_obj: &T) {
use tests::_dbg_mock as host_dbg;

#[allow(clippy::used_underscore_binding)]
let s = format!("{:?}", _obj);
let s = format!("{_obj:?}");
// Safety: `host_dbg` doesn't take ownership of it's pointer parameter
unsafe { iroha_smart_contract_utils::encode_and_execute(&s, host_dbg) }
unsafe { crate::encode_and_execute(&s, host_dbg) }
}
}

Expand Down Expand Up @@ -89,6 +91,7 @@ impl<T> DebugUnwrapExt for Option<T> {
return self.unwrap();

#[cfg(feature = "debug")]
#[allow(clippy::single_match_else, clippy::option_if_let_else)]
{
match self {
Some(out) => out,
Expand Down

0 comments on commit f147295

Please sign in to comment.