mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 12:11:09 +00:00
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:
committed by
Gavin Wood
parent
b017e683dc
commit
12f052ce9d
@@ -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(())
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user