Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a693a0b
Add `engine` crate
cmichi Feb 25, 2021
e3ea5e4
Add `env_types` crate
cmichi Feb 25, 2021
eff3ada
Adapt `env`, `lang` and `storage`
cmichi Feb 25, 2021
da08ba7
Adapt examples
cmichi Feb 25, 2021
def45c2
Adapt CI
cmichi Mar 2, 2021
3956a2c
Symlink license and readme
cmichi Mar 2, 2021
a0012e9
Throw `TypedEncoded` out of `engine`
cmichi Mar 3, 2021
606c69b
Improve Erc20
cmichi Mar 3, 2021
6850b4b
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi Mar 3, 2021
9c5f2ba
Bump versions to rc3
cmichi Mar 3, 2021
cc8143d
Fix clippy error: Manual implementation of `Option::map` (#717)
Mar 5, 2021
edab873
Implement comments
cmichi Mar 5, 2021
340185d
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi Mar 16, 2021
cb54a77
Fix yml
cmichi Mar 16, 2021
0e0c044
Improve structure
cmichi Mar 16, 2021
be2b598
Add tests
cmichi Mar 18, 2021
02be20c
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi Mar 19, 2021
46adef3
Fix function signature
cmichi Mar 22, 2021
1caada4
Get rid of `engine`s singleton
cmichi Apr 1, 2021
8a2831a
Revert instantiate stuff
cmichi Apr 13, 2021
c8117a9
Implement review comments
cmichi Apr 12, 2021
da71eea
Make `Storage` non-generic
cmichi Apr 13, 2021
b8ba878
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi Apr 13, 2021
b81e4c2
Improve API for emmitted events
cmichi Apr 13, 2021
bff4609
Migrate to `panic_any`
cmichi Apr 15, 2021
655b425
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi Apr 15, 2021
63da646
Clean up import
cmichi Apr 15, 2021
813301e
Import `panic_any`
cmichi Apr 15, 2021
c651d53
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi Apr 28, 2021
8391f8c
Implement comments
cmichi Apr 28, 2021
863628d
Fix param
cmichi Apr 28, 2021
b5c3688
Use type
cmichi Apr 29, 2021
eafe7ac
Store balances in chain storage
cmichi Apr 29, 2021
8f64f38
Fix tests
cmichi Apr 29, 2021
68734c8
Use individual storage per contract
cmichi Apr 29, 2021
35dd9e6
Implement comments
cmichi May 4, 2021
8fec9ae
Merge branch 'master' into cmichi-implement-new-offchain-engine-mvp
cmichi May 10, 2021
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
Throw TypedEncoded out of engine
  • Loading branch information
cmichi committed Mar 3, 2021
commit a0012e967a60320f4a88a44a31cc6e5669e6cfeb
8 changes: 4 additions & 4 deletions crates/engine/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::test_api::Error;

use super::{
exec_context::OffChainError,
typed_encoded::TypedEncodedError,
types::OffAccountId,
};

Expand All @@ -25,7 +24,8 @@ use derive_more::From;
/// Errors encountered upon interacting with the accounts database.
#[derive(Debug, From, PartialEq, Eq)]
pub enum AccountError {
TypedEncoded(TypedEncodedError),
// TODO Decoding(scale::Error),
DecodingFailed,
#[from(ignore)]
UnexpectedUserAccount,
#[from(ignore)]
Expand All @@ -39,7 +39,7 @@ impl From<AccountError> for Error {
}

impl From<scale::Error> for AccountError {
fn from(err: scale::Error) -> Self {
AccountError::TypedEncoded(err.into())
fn from(_err: scale::Error) -> Self {
AccountError::DecodingFailed
}
}
12 changes: 9 additions & 3 deletions crates/engine/src/exec_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use super::{
accounts::AccountError,
typed_encoded::TypedEncodedError,
types::OffAccountId,
Environment,
};
Expand All @@ -24,7 +23,6 @@ use derive_more::From;
#[derive(Debug, From, PartialEq, Eq)]
pub enum OffChainError {
Account(AccountError),
TypedEncoded(TypedEncodedError),
#[from(ignore)]
UninitializedBlocks,
#[from(ignore)]
Expand All @@ -51,6 +49,14 @@ impl ExecContext {
where
T: Environment,
{
self.callee.decode().map_err(Into::into)
// TODO type hell
let callee: Vec<u8> = self.callee.clone();
let res: std::result::Result<T::AccountId, scale::Error> =
scale::Decode::decode(&mut &callee[..]);
let res: std::result::Result<T::AccountId, AccountError> =
res.map_err(AccountError::from);
let res: std::result::Result<T::AccountId, OffChainError> =
res.map_err(Into::into);
res
}
}
11 changes: 8 additions & 3 deletions crates/engine/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ thread_local!(
EnvInstance {
storage: HashMap::new(),
emitted_events: Vec::new(),
caller: Vec::new(),
exec_context: None,
count_reads: 0,
count_writes: 0,
caller: vec![0x01; 32],
}
)
);
Expand Down Expand Up @@ -287,9 +287,14 @@ impl_seal_wrapper_for! {
pub fn caller(output: &mut &mut [u8]) {
ENV_INSTANCE.with(|instance| {
let instance = &mut instance.borrow_mut();
let caller = instance.caller.clone();
let caller = instance
.exec_context
.as_ref()
.expect("uninitialized context")
.caller
.clone();
output[..caller.len()].copy_from_slice(&caller[..]);
extract_from_slice(output, 32);
extract_from_slice(output, caller.len());
});
}

Expand Down
1 change: 0 additions & 1 deletion crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ mod exec_context;
pub mod ext;
mod hashing;
pub mod test_api;
mod typed_encoded;
mod types;

pub use test_api::{
Expand Down
25 changes: 18 additions & 7 deletions crates/engine/src/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::{
},
ext,
ext::ENV_INSTANCE,
typed_encoded::TypedEncoded,
Environment,
};

Expand Down Expand Up @@ -169,8 +168,8 @@ where
let instance = &mut instance.borrow_mut();
let alice: T::AccountId = default_accounts::<T>().expect("default").alice;
instance.exec_context = Some(ExecContext {
callee: TypedEncoded::new(&alice),
caller: TypedEncoded::new(&alice),
callee: scale::Encode::encode(&alice),
caller: scale::Encode::encode(&alice),
});
instance.emitted_events = Vec::new();
instance.count_reads = 0;
Expand All @@ -196,8 +195,8 @@ where
instance
.exec_context
.as_mut()
.expect("unitialized context")
.caller = TypedEncoded::new(&caller);
.expect("uninitialized context")
.caller = scale::Encode::encode(&caller);
})
}
/// Returns the total number of reads and writes of the contract's storage.
Expand Down Expand Up @@ -251,10 +250,22 @@ where
T: Environment,
{
ENV_INSTANCE.with(|instance| {
// TODO type hell
let instance = &mut instance.borrow();
let cont = instance.exec_context.as_ref().expect("no exec context");
let callee = cont.callee.decode()?;
Ok(callee)
let res: std::result::Result<T::AccountId, scale::Error> =
scale::Decode::decode(&mut &cont.callee[..]);
let res: std::result::Result<T::AccountId, super::accounts::AccountError> =
res.map_err(super::accounts::AccountError::from);
let callee: std::result::Result<T::AccountId, OffChainError> =
res.map_err(Into::into);
let callee: std::result::Result<
T::AccountId,
ink_env_types::Error<OffChainError>,
> = callee.map_err(|offchainerr| {
ink_env_types::Error::<OffChainError>::OffChain(offchainerr)
});
callee
})
}

Expand Down
Loading