-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: impl blacklist/whitelist middleware (#5)
* done * clean up code * improve tests * add more tests, polish code and fix `enabled` * update demo config * clean up tests
- Loading branch information
Showing
12 changed files
with
800 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::utils::AddressRule; | ||
use async_trait::async_trait; | ||
use serde::Deserialize; | ||
|
||
use super::{Extension, ExtensionRegistry}; | ||
|
||
/// The address whitelist for `eth_call/eth_sendRawTransaction` rpc. | ||
#[derive(Deserialize, Debug, Clone)] | ||
pub struct WhitelistConfig { | ||
#[serde(default)] | ||
pub eth_call: Vec<AddressRule>, | ||
#[serde(default)] | ||
pub tx: Vec<AddressRule>, | ||
} | ||
|
||
/// The address blacklist for `eth_call/eth_sendRawTransaction` rpc. | ||
#[derive(Deserialize, Debug, Clone)] | ||
pub struct BlacklistConfig { | ||
#[serde(default)] | ||
pub eth_call: Vec<AddressRule>, | ||
#[serde(default)] | ||
pub tx: Vec<AddressRule>, | ||
} | ||
|
||
pub struct Whitelist { | ||
pub config: WhitelistConfig, | ||
} | ||
|
||
pub struct BlackList { | ||
pub config: BlacklistConfig, | ||
} | ||
|
||
#[async_trait] | ||
impl Extension for Whitelist { | ||
type Config = WhitelistConfig; | ||
|
||
async fn from_config(config: &Self::Config, _registry: &ExtensionRegistry) -> Result<Self, anyhow::Error> { | ||
Ok(Self { config: config.clone() }) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Extension for BlackList { | ||
type Config = BlacklistConfig; | ||
|
||
async fn from_config(config: &Self::Config, _registry: &ExtensionRegistry) -> Result<Self, anyhow::Error> { | ||
Ok(Self { config: config.clone() }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.