Commit 2a060af2 authored by Andrew Jones's avatar Andrew Jones

Hook up lang2 runtime_get_storage, make example compile

parent 3b670898
......@@ -323,5 +323,15 @@ where
/// Prints the given contents to the environmental log.
fn println(&self, content: &str);
/// Returns the value at the *runtime* storage at the position of the key.
///
/// # Errors
///
/// - If the key's entry is empty
/// - If the decoding of the typed value failed
fn get_runtime_storage<R>(&self, key: &[u8]) -> Result<R>
where
R: scale::Decode;
}
}
......@@ -322,4 +322,17 @@ where
pub fn println(&mut self, content: &str) {
T::println(content)
}
/// Returns the value at the *runtime* storage at the position of the key.
///
/// # Errors
///
/// - If the key's entry is empty
/// - If the decoding of the typed value failed
pub fn get_runtime_storage<R>(&mut self, key: &[u8]) -> Result<R>
where
R: scale::Decode,
{
T::get_runtime_storage(&mut self.buffer, key)
}
}
......@@ -38,16 +38,12 @@ mod runtime {
fn get_balance(&self, account: AccountId) -> Balance {
const BALANCE_OF: &[u8] = b"balance:";
let key = account.to_keyed_vec(BALANCE_OF);
match env.runtime_get_storage::<Balance>(&key) {
Some(Ok(balance)) => balance,
Some(Err(_)) => {
env.println("Error decoding balance");
match self.env().get_runtime_storage::<Balance>(&key) {
Ok(balance) => balance,
Err(_) => {
self.env().println("Error reading balance");
0
},
None => {
env.println("Balance for account not found");
0
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment