srml-contract: update ext_random(_seed) (#2635)

* Initial implementation.

* Rename random_seed to random

* Update rustdocs

* Update COMPLEXITY.md

* Fix comment.

* Limit the size of subject.

* Bump the runtime version.

* Fix doc

* Update node/runtime/src/lib.rs

Co-Authored-By: thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Sergei Pepyakin
2019-05-23 11:34:17 +02:00
committed by Gavin Wood
parent b017e683dc
commit 12f052ce9d
5 changed files with 61 additions and 35 deletions
+13 -3
View File
@@ -527,9 +527,19 @@ define_env!(Env, <E: Ext>,
Ok(())
},
// Load the latest block RNG seed into the scratch buffer
ext_random_seed(ctx) => {
ctx.scratch_buf = ctx.ext.random_seed().encode();
// Stores the random number for the current block for the given subject into the scratch
// buffer.
//
// The data is encoded as T::Hash. The current contents of the scratch buffer are
// overwritten.
ext_random(ctx, subject_ptr: u32, subject_len: u32) => {
// The length of a subject can't exceed `max_subject_len`.
if subject_len > ctx.schedule.max_subject_len {
return Err(sandbox::HostError);
}
let subject_buf = read_sandbox_memory(ctx, subject_ptr, subject_len)?;
ctx.scratch_buf = ctx.ext.random(&subject_buf).encode();
Ok(())
},