mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +00:00
srml-contract: Extract schedule (#1044)
* Rename Config → Schedule. * Fetch and pass config. * Integrate config everywhere. * <<<E as Ext>::T as Trait> → <<E::T as Trait> * Update roots * Cache existential_deposit * Update COMPLEXITY.md * Update roots.
This commit is contained in:
committed by
Gav Wood
parent
367c99b2bb
commit
1f0f3c8f6b
@@ -14,14 +14,13 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use super::{MaxDepth, ContractAddressFor, Module, Trait, Event, RawEvent};
|
||||
use super::{ContractAddressFor, Trait, Event, RawEvent, Config};
|
||||
use account_db::{AccountDb, OverlayAccountDb};
|
||||
use gas::GasMeter;
|
||||
use vm;
|
||||
|
||||
use rstd::prelude::*;
|
||||
use runtime_primitives::traits::{Zero, CheckedAdd, CheckedSub};
|
||||
use runtime_support::StorageValue;
|
||||
use balances::{self, EnsureAccountLiquid};
|
||||
|
||||
// TODO: Add logs
|
||||
@@ -38,6 +37,7 @@ pub struct ExecutionContext<'a, T: Trait + 'a> {
|
||||
pub overlay: OverlayAccountDb<'a, T>,
|
||||
pub depth: usize,
|
||||
pub events: Vec<Event<T>>,
|
||||
pub config: &'a Config<T>,
|
||||
}
|
||||
|
||||
impl<'a, T: Trait> ExecutionContext<'a, T> {
|
||||
@@ -51,12 +51,11 @@ impl<'a, T: Trait> ExecutionContext<'a, T> {
|
||||
data: &[u8],
|
||||
output_data: &mut Vec<u8>,
|
||||
) -> Result<CallReceipt, &'static str> {
|
||||
if self.depth == <MaxDepth<T>>::get() as usize {
|
||||
if self.depth == self.config.max_depth as usize {
|
||||
return Err("reached maximum depth, cannot make a call");
|
||||
}
|
||||
|
||||
let call_base_fee = <Module<T>>::call_base_fee();
|
||||
if gas_meter.charge(call_base_fee).is_out_of_gas() {
|
||||
if gas_meter.charge(self.config.call_base_fee).is_out_of_gas() {
|
||||
return Err("not enough gas to pay base call fee");
|
||||
}
|
||||
|
||||
@@ -70,6 +69,7 @@ impl<'a, T: Trait> ExecutionContext<'a, T> {
|
||||
self_account: dest.clone(),
|
||||
depth: self.depth + 1,
|
||||
events: Vec::new(),
|
||||
config: self.config,
|
||||
};
|
||||
|
||||
if value > T::Balance::zero() {
|
||||
@@ -92,7 +92,7 @@ impl<'a, T: Trait> ExecutionContext<'a, T> {
|
||||
ctx: &mut nested,
|
||||
_caller: caller,
|
||||
},
|
||||
&::vm::Config::default(),
|
||||
&self.config.schedule,
|
||||
gas_meter,
|
||||
).map_err(|_| "vm execute returned error while call")?;
|
||||
}
|
||||
@@ -114,12 +114,11 @@ impl<'a, T: Trait> ExecutionContext<'a, T> {
|
||||
init_code: &[u8],
|
||||
data: &[u8],
|
||||
) -> Result<CreateReceipt<T>, &'static str> {
|
||||
if self.depth == <MaxDepth<T>>::get() as usize {
|
||||
if self.depth == self.config.max_depth as usize {
|
||||
return Err("reached maximum depth, cannot create");
|
||||
}
|
||||
|
||||
let create_base_fee = <Module<T>>::create_base_fee();
|
||||
if gas_meter.charge(create_base_fee).is_out_of_gas() {
|
||||
if gas_meter.charge(self.config.create_base_fee).is_out_of_gas() {
|
||||
return Err("not enough gas to pay base create fee");
|
||||
}
|
||||
|
||||
@@ -138,6 +137,7 @@ impl<'a, T: Trait> ExecutionContext<'a, T> {
|
||||
self_account: dest.clone(),
|
||||
depth: self.depth + 1,
|
||||
events: Vec::new(),
|
||||
config: self.config,
|
||||
};
|
||||
|
||||
if endowment > T::Balance::zero() {
|
||||
@@ -160,7 +160,7 @@ impl<'a, T: Trait> ExecutionContext<'a, T> {
|
||||
ctx: &mut nested,
|
||||
_caller: caller,
|
||||
},
|
||||
&::vm::Config::default(),
|
||||
&self.config.schedule,
|
||||
gas_meter,
|
||||
).map_err(|_| "vm execute returned error while create")?;
|
||||
|
||||
@@ -213,14 +213,15 @@ fn transfer<'a, T: Trait>(
|
||||
// `contract_create` will be `false` but `would_create` will be `true`.
|
||||
let would_create = to_balance.is_zero();
|
||||
|
||||
let fee: T::Balance = if contract_create {
|
||||
<Module<T>>::contract_fee()
|
||||
} else {
|
||||
if would_create {
|
||||
<balances::Module<T>>::creation_fee()
|
||||
} else {
|
||||
<balances::Module<T>>::transfer_fee()
|
||||
}
|
||||
let fee: T::Balance = match (contract_create, would_create) {
|
||||
// If this function is called from `CREATE` routine, then we always
|
||||
// charge contract account creation fee.
|
||||
(true, _) => ctx.config.contract_account_create_fee,
|
||||
|
||||
// Otherwise the fee depends on whether we create a new account or transfer
|
||||
// to an existing one.
|
||||
(false, true) => ctx.config.account_create_fee,
|
||||
(false, false) => ctx.config.transfer_fee,
|
||||
};
|
||||
|
||||
if gas_meter.charge_by_balance(fee).is_out_of_gas() {
|
||||
@@ -233,7 +234,7 @@ fn transfer<'a, T: Trait>(
|
||||
Some(b) => b,
|
||||
None => return Err("balance too low to send value"),
|
||||
};
|
||||
if would_create && value < <balances::Module<T>>::existential_deposit() {
|
||||
if would_create && value < ctx.config.existential_deposit {
|
||||
return Err("value too low to create account");
|
||||
}
|
||||
<T as balances::Trait>::EnsureAccountLiquid::ensure_account_liquid(transactor)?;
|
||||
|
||||
Reference in New Issue
Block a user