pallet-contracts: Rent projection RPC (#4754)

* Initial approach

* Introduce the pallet-contracts-common crate

* Add rent::compute_rent_projection

* Wire everything together

* Fix build error.

* Rename EvictionDate → EvictionAt.

* Clean.

* Renaming and cleaning.

* Add documentation for rent_projection RPC.

* Add documentation for rent_projection runtime API.

* Refactor rent_budget.

Merge it with subsistence_treshold.

* Bump impl_version

* Constrain RPC impl with Block::Header::Number.

* Rename pallet-contracts-common into -primitives

* Add a comment for `compute_rent_projection` on the usage

* Small tidying
This commit is contained in:
Sergei Pepyakin
2020-01-31 15:22:25 +01:00
committed by GitHub
parent 3018bfe0e9
commit df6ef1780f
13 changed files with 339 additions and 114 deletions
+10 -11
View File
@@ -128,6 +128,7 @@ use frame_support::{
use frame_support::traits::{OnFreeBalanceZero, OnUnbalanced, Currency, Get, Time, Randomness};
use frame_system::{self as system, ensure_signed, RawOrigin, ensure_root};
use sp_core::storage::well_known_keys::CHILD_STORAGE_KEY_PREFIX;
use pallet_contracts_primitives::{RentProjection, ContractAccessError};
pub type CodeHash<T> = <T as frame_system::Trait>::Hash;
pub type TrieId = Vec<u8>;
@@ -680,14 +681,6 @@ decl_module! {
}
}
/// The possible errors that can happen querying the storage of a contract.
pub enum GetStorageError {
/// The given address doesn't point on a contract.
ContractDoesntExist,
/// The specified contract is a tombstone and thus cannot have any storage.
IsTombstone,
}
/// Public APIs provided by the contracts module.
impl<T: Trait> Module<T> {
/// Perform a call to a specified contract.
@@ -710,11 +703,11 @@ impl<T: Trait> Module<T> {
pub fn get_storage(
address: T::AccountId,
key: [u8; 32],
) -> sp_std::result::Result<Option<Vec<u8>>, GetStorageError> {
) -> sp_std::result::Result<Option<Vec<u8>>, ContractAccessError> {
let contract_info = <ContractInfoOf<T>>::get(&address)
.ok_or(GetStorageError::ContractDoesntExist)?
.ok_or(ContractAccessError::DoesntExist)?
.get_alive()
.ok_or(GetStorageError::IsTombstone)?;
.ok_or(ContractAccessError::IsTombstone)?;
let maybe_value = AccountDb::<T>::get_storage(
&DirectAccountDb,
@@ -724,6 +717,12 @@ impl<T: Trait> Module<T> {
);
Ok(maybe_value)
}
pub fn rent_projection(
address: T::AccountId,
) -> sp_std::result::Result<RentProjection<T::BlockNumber>, ContractAccessError> {
rent::compute_rent_projection::<T>(&address)
}
}
impl<T: Trait> Module<T> {