I'm trying to copy a function from the frontier pallet(fc_rpc::format::Formatter), I copied it to a file and imported that. frontier-752fb1c28a6c675a/ea37e8f/client/rpc/src/format.rs It's the same code:
use pallet_ethereum::TransactionValidationError as VError;
use sc_transaction_pool_api::error::{Error as PError, IntoPoolError};
use sp_runtime::transaction_validity::InvalidTransaction;
pub trait Formatter: Send + Sync + 'static {
fn pool_error(err: impl IntoPoolError) -> String;
}
// Formatter keeping the same output as before the introduction of this
// formatter design.
pub struct Legacy;
impl Formatter for Legacy {
fn pool_error(err: impl IntoPoolError) -> String {
format!("submit transaction to pool failed: {:?}", err)
}
}
// Formats the same way Geth node formats responses.
pub struct Geth;
impl Formatter for Geth {
fn pool_error(err: impl IntoPoolError) -> String {
// Error strings from :
// https://github.com/ethereum/go-ethereum/blob/794c6133efa2c7e8376d9d141c900ea541790bce/core/error.go
match err.into_pool_error() {
Ok(PError::AlreadyImported(_)) => "already known".to_string(),
// In Frontier the only case there is a `TemporarilyBanned` is because
// the same transaction was received before and returned
// `InvalidTransaction::Stale`. Thus we return the same error.
Ok(PError::TemporarilyBanned) => "nonce too low".into(),
Ok(PError::TooLowPriority { .. }) => "replacement transaction underpriced".into(),
Ok(PError::InvalidTransaction(inner)) => match inner {
InvalidTransaction::Stale => "nonce too low".into(),
InvalidTransaction::Payment => "insufficient funds for gas * price + value".into(),
InvalidTransaction::ExhaustsResources => "gas limit reached".into(),
InvalidTransaction::Custom(inner) => match inner.into() {
VError::UnknownError => "unknown error".into(),
VError::InvalidChainId => "invalid chain id".into(),
VError::InvalidSignature => "invalid sender".into(),
VError::GasLimitTooLow => "intrinsic gas too low".into(),
VError::GasLimitTooHigh => "exceeds block gas limit".into(),
VError::InsufficientFundsForTransfer => {
"insufficient funds for transfer".into()
}
},
_ => "unknown error".into(),
},
err @ _ => format!("submit transaction to pool failed: {:?}", err),
}
}
}
How can I allow fc_rpc::format::Formatter to be the same type as the local instance of Formatter?
Shouldn't it be possible to do this with a similar statement like this:
dyn fc_rpc::format::Formatter: Formatter,
This is the error i'm getting:
error[E0277]: the trait bound `Geth: fc_rpc::format::Formatter` is not satisfied
--> node/rpc/src/lib.rs:255:17
|
255 | io.extend_with(EthApiServer::to_delegate(EthApi::new(
| ____________________^
256 | | client.clone(),
257 | | pool.clone(),
258 | | graph.clone(),
... |
269 | | fee_history_cache,
270 | | )));
| |______^ the trait `fc_rpc::format::Formatter` is not implemented for `Geth`
|
note: required by a bound in `fc_rpc::EthApi`
--> /home/filip/.cargo/git/checkouts/frontier-752fb1c28a6c675a/ea37e8f/client/rpc/src/eth.rs:65:72
|
65 | pub struct EthApi<B: BlockT, C, P, CT, BE, H: ExHashT, A: ChainApi, F: Formatter> {
| ^^^^^^^^^ required by this bound in `fc_rpc::EthApi`
error[E0277]: the trait bound `Geth: fc_rpc::format::Formatter` is not satisfied
--> node/rpc/src/lib.rs:255:2
|
255 | / io.extend_with(EthApiServer::to_delegate(EthApi::new(
256 | | client.clone(),
257 | | pool.clone(),
258 | | graph.clone(),
... |
269 | | fee_history_cache,
270 | | )));
| |_______^ the trait `fc_rpc::format::Formatter` is not implemented for `Geth`
|
note: required by a bound in `fc_rpc::EthApi`
--> /home/filip/.cargo/git/checkouts/frontier-752fb1c28a6c675a/ea37e8f/client/rpc/src/eth.rs:65:72
|
65 | pub struct EthApi<B: BlockT, C, P, CT, BE, H: ExHashT, A: ChainApi, F: Formatter> {
| ^^^^^^^^^ required by this bound in `fc_rpc::EthApi`
Check out the code: git clone -b erup-5-latest https://github.com/edgeware-network/edgeware-node