Skip to content

Commit

Permalink
[BACKPORT]: Fix smart contract debug print
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Polyakov <[email protected]>
  • Loading branch information
Arjentix committed Dec 27, 2023
1 parent d67f716 commit 5c67e73
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 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
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 5c67e73

Please sign in to comment.