mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 06:31:09 +00:00
Some trivial externalities added (#1450)
* Add gas_left, gas_price and balance externalities * Add a value_transferred externality
This commit is contained in:
committed by
Gav Wood
parent
1ccb590d18
commit
0ad2a5fb96
@@ -82,6 +82,14 @@ pub trait Ext {
|
||||
|
||||
/// Returns a reference to the account id of the current contract.
|
||||
fn address(&self) -> &AccountIdOf<Self::T>;
|
||||
|
||||
/// Returns the balance of the current contract.
|
||||
///
|
||||
/// The `value_transferred` is already added.
|
||||
fn balance(&self) -> BalanceOf<Self::T>;
|
||||
|
||||
/// Returns the value transfered along with this call or as endowment.
|
||||
fn value_transferred(&self) -> BalanceOf<Self::T>;
|
||||
}
|
||||
|
||||
/// Loader is a companion of the `Vm` trait. It loads an appropriate abstract
|
||||
@@ -292,6 +300,7 @@ where
|
||||
&mut CallContext {
|
||||
ctx: &mut nested,
|
||||
caller: self.self_account.clone(),
|
||||
value_transferred: value,
|
||||
},
|
||||
input_data,
|
||||
empty_output_buf,
|
||||
@@ -361,6 +370,7 @@ where
|
||||
&mut CallContext {
|
||||
ctx: &mut nested,
|
||||
caller: self.self_account.clone(),
|
||||
value_transferred: endowment,
|
||||
},
|
||||
input_data,
|
||||
EmptyOutputBuf::new(),
|
||||
@@ -509,6 +519,7 @@ fn transfer<'a, T: Trait, V: Vm<T>, L: Loader<T>>(
|
||||
struct CallContext<'a, 'b: 'a, T: Trait + 'b, V: Vm<T> + 'b, L: Loader<T>> {
|
||||
ctx: &'a mut ExecutionContext<'b, T, V, L>,
|
||||
caller: T::AccountId,
|
||||
value_transferred: T::Balance,
|
||||
}
|
||||
|
||||
impl<'a, 'b: 'a, T, E, V, L> Ext for CallContext<'a, 'b, T, V, L>
|
||||
@@ -558,6 +569,14 @@ where
|
||||
fn caller(&self) -> &T::AccountId {
|
||||
&self.caller
|
||||
}
|
||||
|
||||
fn balance(&self) -> T::Balance {
|
||||
self.ctx.overlay.get_balance(&self.ctx.self_account)
|
||||
}
|
||||
|
||||
fn value_transferred(&self) -> T::Balance {
|
||||
self.value_transferred
|
||||
}
|
||||
}
|
||||
|
||||
/// These tests exercise the executive layer.
|
||||
|
||||
Reference in New Issue
Block a user