srml-contracts: Add ability to read substrate's storage (#4108)

* Add `ext_get_runtime_storage`

* Implement testing for ext_get_runtime_storage

* Add integration test.

* Update spec version

* Fix the doc

* Save memory allocation.
This commit is contained in:
Sergei Pepyakin
2019-11-18 13:37:15 +01:00
committed by GitHub
parent 0d658ab286
commit 33b3865858
4 changed files with 274 additions and 3 deletions
+13 -1
View File
@@ -22,7 +22,10 @@ use crate::rent;
use rstd::prelude::*;
use sr_primitives::traits::{Bounded, CheckedAdd, CheckedSub, Zero};
use support::traits::{WithdrawReason, Currency, Time, Randomness};
use support::{
storage::unhashed,
traits::{WithdrawReason, Currency, Time, Randomness},
};
pub type AccountIdOf<T> = <T as system::Trait>::AccountId;
pub type CallOf<T> = <T as Trait>::Call;
@@ -175,6 +178,11 @@ pub trait Ext {
/// Returns the maximum allowed size of a storage item.
fn max_value_size(&self) -> u32;
/// Returns the value of runtime under the given key.
///
/// Returns `None` if the value doesn't exist.
fn get_runtime_storage(&self, key: &[u8]) -> Option<Vec<u8>>;
}
/// Loader is a companion of the `Vm` trait. It loads an appropriate abstract
@@ -785,6 +793,10 @@ where
fn max_value_size(&self) -> u32 {
self.ctx.config.max_value_size
}
fn get_runtime_storage(&self, key: &[u8]) -> Option<Vec<u8>> {
unhashed::get_raw(&key)
}
}
/// These tests exercise the executive layer.