ink_env/engine/off_chain/
types.rs

1// Copyright (C) Use Ink (UK) Ltd.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Contains the necessary conversions from `ink_engine` types to types
16//! of this crate.
17
18use super::{
19    AccountError,
20    Error,
21    OffChainError,
22    test_api::EmittedEvent,
23};
24
25impl From<ink_engine::test_api::EmittedEvent> for EmittedEvent {
26    fn from(evt: ink_engine::test_api::EmittedEvent) -> Self {
27        EmittedEvent {
28            topics: evt.topics,
29            data: evt.data,
30        }
31    }
32}
33
34impl From<ink_engine::Error> for Error {
35    fn from(err: ink_engine::Error) -> Self {
36        let e = match err {
37            ink_engine::Error::Account(acc) => OffChainError::Account(acc.into()),
38            ink_engine::Error::UninitializedBlocks => OffChainError::UninitializedBlocks,
39            ink_engine::Error::UninitializedExecutionContext => {
40                OffChainError::UninitializedExecutionContext
41            }
42        };
43        Error::OffChain(e)
44    }
45}
46
47impl From<ink_engine::AccountError> for AccountError {
48    fn from(err: ink_engine::AccountError) -> Self {
49        match err {
50            ink_engine::AccountError::Decoding(e) => AccountError::Decoding(e),
51            ink_engine::AccountError::UnexpectedUserAccount => {
52                AccountError::UnexpectedUserAccount
53            }
54            ink_engine::AccountError::NoAccountForId(acc) => {
55                AccountError::NoAccountForId(acc)
56            }
57            ink_engine::AccountError::NoContractForId(addr) => {
58                AccountError::NoContractForId(addr)
59            }
60        }
61    }
62}
63
64impl From<ink_engine::AccountError> for Error {
65    fn from(account_error: ink_engine::AccountError) -> Self {
66        Error::OffChain(OffChainError::Account(account_error.into()))
67    }
68}