Introduce ext_println to contract runtime (#2239)

* Implement `ext_println` in contract runtime

* Only allow contracts to import `ext_println` on dev chains

* Configure dev chain to allow contracts with `ext_println`

* Increment spec version

* Docs

* Rename config to the more specific enable_println
This commit is contained in:
Andrew Jones
2019-04-11 14:49:17 +01:00
committed by Sergei Pepyakin
parent 18df051947
commit 1e0c1d8850
5 changed files with 75 additions and 14 deletions
@@ -628,4 +628,15 @@ define_env!(Env, <E: Ext>,
Ok(())
},
// Prints utf8 encoded string from the data buffer.
// Only available on `--dev` chains.
// This function may be removed at any time, superseded by a more general contract debugging feature.
ext_println(ctx, str_ptr: u32, str_len: u32) => {
let data = read_sandbox_memory(ctx, str_ptr, str_len)?;
if let Ok(utf8) = core::str::from_utf8(&data) {
runtime_io::print(utf8);
}
Ok(())
},
);