fp_evm/account_provider.rs
1// This file is part of Frontier.
2
3// Copyright (c) Humanode Core.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Custom account provider logic.
19
20use sp_runtime::traits::AtLeast32Bit;
21
22/// The account provider interface abstraction layer.
23///
24/// Expose account related logic that `pallet_evm` required to control accounts existence
25/// in the network and their transactions uniqueness. By default, the pallet operates native
26/// system accounts records that `frame_system` provides.
27///
28/// The interface allow any custom account provider logic to be used instead of
29/// just using `frame_system` account provider. The accounts records should store nonce value
30/// for each account at least.
31pub trait AccountProvider {
32 /// The account identifier type.
33 ///
34 /// Represent the account itself in accounts records.
35 type AccountId;
36
37 /// Account nonce type.
38 ///
39 /// The number that helps to ensure that each transaction in the network is unique
40 /// for particular account.
41 type Nonce: AtLeast32Bit;
42
43 /// Creates a new account in accounts records.
44 ///
45 /// The account associated with new created address EVM.
46 fn create_account(who: &Self::AccountId);
47
48 /// Removes an account from accounts records.
49 ///
50 /// The account associated with removed address from EVM.
51 fn remove_account(who: &Self::AccountId);
52
53 /// Return current account nonce value.
54 ///
55 /// Used to represent account basic information in EVM format.
56 fn account_nonce(who: &Self::AccountId) -> Self::Nonce;
57
58 /// Increment a particular account's nonce value.
59 ///
60 /// Incremented with each new transaction submitted by the account.
61 fn inc_account_nonce(who: &Self::AccountId);
62}