Skip to content

Commit

Permalink
[core] Add ext_println runtime call bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop committed Apr 11, 2019
1 parent 9eef139 commit 8517e0b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/src/env/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ where
ContractEnv::r#return(&value.encode()[..])
}

/// Prints the given content.
///
/// # Note
///
/// Usable only in development (`--dev`) chains.
pub fn println(content: &str) {
ContractEnv::println(content)
}

/// Stores the given value under the specified key in the contract storage.
///
/// # Safety
Expand Down
6 changes: 6 additions & 0 deletions core/src/env/srml/srml_only/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,10 @@ where
unsafe fn r#return(data: &[u8]) -> ! {
sys::ext_return(data.as_ptr() as u32, data.len() as u32);
}

fn println(content: &str) {
unsafe {
sys::ext_println(content.as_ptr() as u32, content.len() as u32)
}
}
}
9 changes: 9 additions & 0 deletions core/src/env/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ impl TestEnvData {
};
std::process::exit(exit_code)
}

/// Prints the given content.
pub fn println(&self, content: &str) {
println!("{}", content)
}
}

thread_local! {
Expand Down Expand Up @@ -375,4 +380,8 @@ where
);
TEST_ENV_DATA.with(|test_env| test_env.borrow().r#return(data))
}

fn println(content: &str) {
TEST_ENV_DATA.with(|test_env| test_env.borrow().println(content))
}
}
7 changes: 7 additions & 0 deletions core/src/env/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@ pub trait Env: EnvTypes + EnvStorage {
/// returned value. This API is unsafe because it does not provide
/// guarantees on its own to always encode the expected type.
unsafe fn r#return(value: &[u8]) -> !;

/// Prints the given content to Substrate output.
///
/// # Note
///
/// Usable only in development (`--dev`) chains.
fn println(content: &str);
}

0 comments on commit 8517e0b

Please sign in to comment.