Merge pull request #6639 from paritytech/wasm-ext-balance
Balance queries implemented in WASM runtime
This commit is contained in:
commit
492da38d67
@ -32,6 +32,11 @@ pub const SIGNATURES: &'static [UserFunctionDescriptor] = &[
|
|||||||
&[I32; 2],
|
&[I32; 2],
|
||||||
Some(I32),
|
Some(I32),
|
||||||
),
|
),
|
||||||
|
Static(
|
||||||
|
"_balance",
|
||||||
|
&[I32; 2],
|
||||||
|
None,
|
||||||
|
),
|
||||||
Static(
|
Static(
|
||||||
"_malloc",
|
"_malloc",
|
||||||
&[I32],
|
&[I32],
|
||||||
@ -163,4 +168,4 @@ pub fn native_bindings<'a>(runtime: &'a mut Runtime) -> interpreter::UserDefined
|
|||||||
globals: ::std::collections::HashMap::new(),
|
globals: ::std::collections::HashMap::new(),
|
||||||
functions: ::std::borrow::Cow::from(SIGNATURES),
|
functions: ::std::borrow::Cow::from(SIGNATURES),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,6 +163,19 @@ impl<'a, 'b> Runtime<'a, 'b> {
|
|||||||
Ok(Some(0.into()))
|
Ok(Some(0.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fetches balance for address
|
||||||
|
pub fn balance(&mut self, context: InterpreterCallerContext)
|
||||||
|
-> Result<Option<interpreter::RuntimeValue>, InterpreterError>
|
||||||
|
{
|
||||||
|
let mut context = context;
|
||||||
|
let return_ptr = context.value_stack.pop_as::<i32>()? as u32;
|
||||||
|
let address = self.pop_address(&mut context)?;
|
||||||
|
let balance = self.ext.balance(&address).map_err(|_| UserTrap::BalanceQueryError)?;
|
||||||
|
let value: H256 = balance.into();
|
||||||
|
self.memory.set(return_ptr, &*value)?;
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
/// Pass suicide to state runtime
|
/// Pass suicide to state runtime
|
||||||
pub fn suicide(&mut self, context: InterpreterCallerContext)
|
pub fn suicide(&mut self, context: InterpreterCallerContext)
|
||||||
-> Result<Option<interpreter::RuntimeValue>, InterpreterError>
|
-> Result<Option<interpreter::RuntimeValue>, InterpreterError>
|
||||||
@ -664,6 +677,9 @@ impl<'a, 'b> interpreter::UserFunctionExecutor<UserTrap> for Runtime<'a, 'b> {
|
|||||||
"_storage_write" => {
|
"_storage_write" => {
|
||||||
self.storage_write(context)
|
self.storage_write(context)
|
||||||
},
|
},
|
||||||
|
"_balance" => {
|
||||||
|
self.balance(context)
|
||||||
|
},
|
||||||
"_suicide" => {
|
"_suicide" => {
|
||||||
self.suicide(context)
|
self.suicide(context)
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user