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    test_api::EmittedEvent,
20    AccountError,
21    Error,
22    OffChainError,
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            ink_engine::Error::UnregisteredChainExtension => {
43                OffChainError::UnregisteredChainExtension
44            }
45        };
46        Error::OffChain(e)
47    }
48}
49
50impl From<ink_engine::AccountError> for AccountError {
51    fn from(err: ink_engine::AccountError) -> Self {
52        match err {
53            ink_engine::AccountError::Decoding(e) => AccountError::Decoding(e),
54            ink_engine::AccountError::UnexpectedUserAccount => {
55                AccountError::UnexpectedUserAccount
56            }
57            ink_engine::AccountError::NoAccountForId(acc) => {
58                AccountError::NoAccountForId(acc)
59            }
60            ink_engine::AccountError::NoContractForId(addr) => {
61                AccountError::NoContractForId(addr)
62            }
63        }
64    }
65}
66
67impl From<ink_engine::AccountError> for Error {
68    fn from(account_error: ink_engine::AccountError) -> Self {
69        Error::OffChain(OffChainError::Account(account_error.into()))
70    }
71}