Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
30e3681
[core] remove get_runtime_storage and invoke_runtime
Robbepop Jul 23, 2020
6ab2037
[core] invalidate all implementations and usages of ext functions
Robbepop Jul 23, 2020
cfb45b7
[core] adjust ext_ functions in ext.rs
Robbepop Jul 23, 2020
7d375cb
[core] add ReturnFlags to public API
Robbepop Jul 23, 2020
a94c397
[core] remove off-chain impls for get_runtime_storage and invoke_runtime
Robbepop Jul 23, 2020
f69bd94
[core] rename ext::ext_input -> ext::input
Robbepop Jul 23, 2020
bcce3b5
[core] change return type of get_contract_storage
Robbepop Jul 23, 2020
7a66772
[core] add conversion from ext::Error to EnvError
Robbepop Jul 23, 2020
c38648f
[core] on-chain: add new utilities for static buffer modifications
Robbepop Jul 23, 2020
4d6444b
[core] add impls for on-chain property getters
Robbepop Jul 23, 2020
a30387e
[core] remove no longer needed utiltiy function
Robbepop Jul 23, 2020
3061018
[core] on-chain: new impl for invoke_contract and eval_contract
Robbepop Jul 23, 2020
6db759c
[core] on-chain: new impl for get_contract_storage
Robbepop Jul 23, 2020
efff63f
[core] on-chain: new impl for decode_input
Robbepop Jul 23, 2020
4de4c3f
[core] on-chain: new impl for output
Robbepop Jul 23, 2020
fcb3965
[core] on-chain: new impl for instantiate_contract
Robbepop Jul 23, 2020
753732b
[core] on-chain: remove unused API
Robbepop Jul 24, 2020
3a0fd5c
[core] on-chain: move EncodeScope and ScopedBuffer to buffer.rs
Robbepop Jul 24, 2020
88eb1d7
[core] on-chain: implement rest of the on-chain API
Robbepop Jul 24, 2020
7a79031
[core] add ScopedBuffer::take_bytes
Robbepop Jul 24, 2020
f98500e
[core] Add Env::call_chain_extension trait method
Robbepop Jul 24, 2020
bc476eb
[core] remove unused helper methods
Robbepop Jul 24, 2020
7bd94e2
[core] on-chain: simplify static buffer
Robbepop Jul 24, 2020
a375469
[core] add env::call_chain_extension public API
Robbepop Jul 24, 2020
b535def
[core] rename Env::output -> return_value
Robbepop Jul 24, 2020
03e252d
[core] off-chain: adjust a bunch of off-chain methods to new interfaces
Robbepop Jul 24, 2020
fc5a9a5
[core] off-chain: adjust get_contract_storage return type
Robbepop Jul 24, 2020
559bb83
[core] off-chain: remove RuntimeCallHandler and RuntimeStorage facili…
Robbepop Jul 24, 2020
4bd3d1f
[core] off-chain: adjust some tests
Robbepop Jul 24, 2020
184bcee
[core] off-chain: remove OffCall utility type
Robbepop Jul 24, 2020
89318e8
[core] off-chain: implement chain extension handler
Robbepop Jul 24, 2020
c6fb977
[core] adjust panic message
Robbepop Jul 24, 2020
51ec933
[core] apply rustfmt
Robbepop Jul 24, 2020
a223d09
[core] apply clippy suggestion
Robbepop Jul 24, 2020
57a9eec
[core] off-chain: re-export ChainExtension and ChainSpec types from t…
Robbepop Jul 24, 2020
3839a5f
[core] on-chain: retain panic messages
Robbepop Jul 24, 2020
2d4af76
[core] rename ext_ to seal_ for all on-chain functions
Robbepop Aug 24, 2020
a1f3ce1
[alloc] fix some warnings and add some minor comments
Robbepop Aug 24, 2020
49f0e66
[core] add wasm_import_module = "seal0"
Robbepop Aug 24, 2020
71acbf5
[core] introduce new Seal error codes
Robbepop Aug 25, 2020
45d58b4
[core] directly return ReturnCode from C-FII
Robbepop Aug 25, 2020
df9ba20
[core] make transfer return Result
Robbepop Aug 25, 2020
91e5025
[core] improve some doc comments
Robbepop Aug 25, 2020
515fecf
rename some old errors to their new names
Robbepop Aug 25, 2020
294fe0b
[core] remove unused env errors and rename some off-chain errors
Robbepop Aug 25, 2020
9e90b61
[core] fix bug in ReturnFlags::set_reverted (formerly known as set_tr…
Robbepop Aug 25, 2020
8ee6899
[core] avoid From impl for () for OffChainError
Robbepop Aug 25, 2020
48bae3a
[lang] adjust lang layer for changes in core
Robbepop Aug 25, 2020
e3b8a3e
[core] turn redundant asserts into debug_assert
Robbepop Aug 25, 2020
4b6c243
[core] be more strict when handling ext::get_storage error
Robbepop Aug 25, 2020
bde67f7
[core] implement clippy suggestion
Robbepop Aug 25, 2020
fcd8cca
[examples] remove no longer useful runtime-storage contract
Robbepop Aug 25, 2020
c71223f
[core] disable chain extensions by default
Robbepop Aug 25, 2020
526075d
[lang] apply clippy suggestion to use matches! macro
Robbepop Aug 25, 2020
e14e378
[core] fix docs for ext_return
Robbepop Aug 25, 2020
8a18087
[core] fix return type of api::return_value
Robbepop Aug 25, 2020
a69bac1
[core] fix doc comment of Env::return_value
Robbepop Aug 25, 2020
08981a1
Merge branch 'sync-substrate-rc5' of github.com:paritytech/ink into s…
Robbepop Aug 25, 2020
fcedd58
[core] introduce RawReturnCode as a layer between Seal error codes an…
Robbepop Aug 25, 2020
52a3fbc
[alloc] make #[alloc_error_handler] private
Robbepop Aug 25, 2020
b6d2145
[alloc, core] move alloc_handler from ink_alloc to ink_core
Robbepop Aug 25, 2020
03e3108
[core] replace useless intermediate ReturnCode type
Robbepop Aug 25, 2020
ddce2f7
[core] rename RawReturnCode -> ReturnCode
Robbepop Aug 25, 2020
5b7d672
[core] apply rustfmt
Robbepop Aug 25, 2020
fc11ce4
[core] apply rustfmt
Robbepop Aug 25, 2020
d22b2cd
[core] off-chain: rename invoke -> eval for chain extension calling
Robbepop Aug 25, 2020
8c84b1d
[core] use Ptr32 and Ptr32Mut to encapsulate pointer -> u32 conversions
Robbepop Aug 25, 2020
402728d
[core] make new Ptr32 and Ptr32Mut abstractions more type safe
Robbepop Aug 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[core] off-chain: adjust a bunch of off-chain methods to new interfaces
  • Loading branch information
Robbepop committed Jul 24, 2020
commit 03e252d714236638edad4f80f48b52e1c155564c
80 changes: 52 additions & 28 deletions core/src/env/engine/off_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ use crate::env::{
EnvError,
EnvTypes,
Result,
ReturnFlags,
Topics,
TypedEnv,
};
use ink_primitives::Key;
use core::convert::TryInto;
use ink_primitives::Key;
use num_traits::Bounded;

impl EnvInstance {
Expand Down Expand Up @@ -100,14 +101,15 @@ impl Env for EnvInstance {
})
}

fn output<R>(&mut self, return_value: &R)
fn return_value<R>(&mut self, flags: ReturnFlags, return_value: &R) -> !
where
R: scale::Encode,
{
let ctx = self
.exec_context_mut()
.expect("uninitialized execution context");
ctx.output = Some(return_value.encode());
std::process::exit(flags.into_u32() as i32)
}

fn println(&mut self, content: &str) {
Expand All @@ -129,6 +131,46 @@ impl Env for EnvInstance {
fn hash_sha2_256(input: &[u8], output: &mut [u8; 32]) {
hashing::sha2_256(input, output)
}

fn call_chain_extension<I, O>(&mut self, func_id: u32, input: &I) -> Result<O>
where
I: scale::Encode,
O: scale::Decode,
{
unimplemented!(
"calling chain extensions is not supported in the off-chain environment"
)
}
}

impl EnvInstance {
fn transfer_impl<T>(&mut self, destination: T::AccountId, value: T::Balance) -> Result<()>
where
T: EnvTypes,
{
let src_id = self.account_id::<T>()?;
let src_value = self
.accounts
.get_account::<T>(&src_id)
.expect("account of executed contract must exist")
.balance::<T>()?;
if src_value < value {
return Err(EnvError::TransferCallFailed)
}
let dst_value = self
.accounts
.get_or_create_account::<T>(&destination)
.balance::<T>()?;
self.accounts
.get_account_mut::<T>(&src_id)
.expect("account of executed contract must exist")
.set_balance::<T>(src_value - value)?;
self.accounts
.get_account_mut::<T>(&destination)
.expect("the account must exist already or has just been created")
.set_balance::<T>(dst_value + value)?;
Ok(())
}
}

impl TypedEnv for EnvInstance {
Expand All @@ -149,14 +191,16 @@ impl TypedEnv for EnvInstance {
}

/// Emulates gas price calculation
fn gas_price<T: EnvTypes>(&mut self, gas: u64) -> Result<T::Balance> {
fn weight_to_fee<T: EnvTypes>(&mut self, gas: u64) -> Result<T::Balance> {
use crate::env::arithmetic::Saturating as _;

let gas_price = self.chain_spec
let gas_price = self
.chain_spec
.gas_price::<T>()
.map_err(|_| scale::Error::from("could not decode gas price"))?;

Ok(gas_price.saturating_mul(gas.try_into().unwrap_or_else(|_| Bounded::max_value())))
Ok(gas_price
.saturating_mul(gas.try_into().unwrap_or_else(|_| Bounded::max_value())))
}

fn gas_left<T: EnvTypes>(&mut self) -> Result<T::Balance> {
Expand Down Expand Up @@ -289,32 +333,12 @@ impl TypedEnv for EnvInstance {
unimplemented!("off-chain environment does not support contract restoration")
}

fn transfer<T>(&mut self, destination: T::AccountId, value: T::Balance) -> Result<()>
fn transfer<T>(&mut self, destination: T::AccountId, value: T::Balance)
where
T: EnvTypes,
{
let src_id = self.account_id::<T>()?;
let src_value = self
.accounts
.get_account::<T>(&src_id)
.expect("account of executed contract must exist")
.balance::<T>()?;
if src_value < value {
return Err(EnvError::TransferCallFailed)
}
let dst_value = self
.accounts
.get_or_create_account::<T>(&destination)
.balance::<T>()?;
self.accounts
.get_account_mut::<T>(&src_id)
.expect("account of executed contract must exist")
.set_balance::<T>(src_value - value)?;
self.accounts
.get_account_mut::<T>(&destination)
.expect("the account must exist already or has just been created")
.set_balance::<T>(dst_value + value)?;
Ok(())
self.transfer_impl::<T>(destination, value)
.expect("encountered invalid transfer call")
}

fn random<T>(&mut self, subject: &[u8]) -> Result<T::Hash>
Expand Down