fc_rpc/eth/
format.rs

1// This file is part of Frontier.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19// Substrate
20use sc_transaction_pool_api::error::{Error as PError, IntoPoolError};
21use sp_runtime::transaction_validity::InvalidTransaction;
22// Frontier
23use fp_evm::TransactionValidationError as VError;
24
25// Formats the same way Geth node formats responses.
26pub struct Geth;
27
28impl Geth {
29	pub fn pool_error(err: impl IntoPoolError) -> String {
30		// Error strings from :
31		// https://github.com/ethereum/go-ethereum/blob/794c6133efa2c7e8376d9d141c900ea541790bce/core/error.go
32		match err.into_pool_error() {
33			Ok(PError::AlreadyImported(_)) => "already known".to_string(),
34			Ok(PError::TemporarilyBanned) => "already known".into(),
35			Ok(PError::TooLowPriority { .. }) => "replacement transaction underpriced".into(),
36			Ok(PError::InvalidTransaction(inner)) => match inner {
37				InvalidTransaction::Stale => "nonce too low".into(),
38				InvalidTransaction::Payment => "insufficient funds for gas * price + value".into(),
39				InvalidTransaction::ExhaustsResources => "exceeds block gas limit".into(),
40				InvalidTransaction::Custom(inner) => match inner.into() {
41					VError::UnknownError => "unknown error".into(),
42					VError::InvalidChainId => "invalid chain id".into(),
43					VError::InvalidSignature => "invalid sender".into(),
44					VError::GasLimitTooLow => "intrinsic gas too low".into(),
45					VError::GasLimitTooHigh => "exceeds block gas limit".into(),
46					VError::GasPriceTooLow => "gas price less than block base fee".into(),
47					VError::PriorityFeeTooHigh => {
48						"max priority fee per gas higher than max fee per gas".into()
49					}
50					VError::InvalidFeeInput => "invalid fee input".into(),
51					VError::EmptyAuthorizationList => "authorization list cannot be empty".into(),
52					VError::AuthorizationListTooLarge => "authorization list too large".into(),
53					_ => "transaction validation error".into(),
54				},
55				_ => "unknown error".into(),
56			},
57			err => format!("submit transaction to pool failed: {err:?}"),
58		}
59	}
60}