-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature add program gas station #395
base: develop
Are you sure you want to change the base?
Changes from 13 commits
36f4267
65cb293
72ca2c8
9a32ac4
20ee799
6161fcc
7e3c365
15f4b76
a18dfef
7bc4d70
b21d662
490f16e
9f48a31
3761db1
b7bed61
723331b
d5cd1fe
3b53bad
0331138
f25aa85
cabfaf1
4674bb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,6 +190,8 @@ pub struct EvmBridge { | |
pool: EthPool<SystemClock>, | ||
min_gas_price: U256, | ||
whitelist: Vec<TxFilter>, | ||
gas_station_program_id: Option<Pubkey>, | ||
redirect_to_proxy_filters: Vec<EvmContractToPayerKeys>, | ||
} | ||
|
||
impl EvmBridge { | ||
|
@@ -237,13 +239,24 @@ impl EvmBridge { | |
pool, | ||
min_gas_price, | ||
whitelist: vec![], | ||
gas_station_program_id: None, | ||
redirect_to_proxy_filters: vec![], | ||
} | ||
} | ||
|
||
fn set_whitelist(&mut self, whitelist: Vec<TxFilter>) { | ||
self.whitelist = whitelist; | ||
} | ||
|
||
fn set_redirect_to_proxy_filters( | ||
&mut self, | ||
gas_station_program_id: Pubkey, | ||
redirect_to_proxy_filters: Vec<EvmContractToPayerKeys>, | ||
) { | ||
self.gas_station_program_id = Some(gas_station_program_id); | ||
self.redirect_to_proxy_filters = redirect_to_proxy_filters; | ||
} | ||
|
||
/// Wrap evm tx into solana, optionally add meta keys, to solana signature. | ||
async fn send_tx( | ||
&self, | ||
|
@@ -990,6 +1003,43 @@ pub(crate) fn from_client_error(client_error: ClientError) -> evm_rpc::Error { | |
} | ||
} | ||
|
||
#[derive(thiserror::Error, Debug, PartialEq)] | ||
pub enum ParseEvmContractToPayerKeysError { | ||
#[error("Evm contract string is invalid")] | ||
InvalidEvmContract, | ||
#[error("Input format is invalid, provide string of the next format: \"<evm contract address>:<payer pubkey>\"")] | ||
InvalidFormat, | ||
#[error("Invalid pubkey")] | ||
InvalidPubkey, | ||
} | ||
|
||
#[derive(Debug)] | ||
struct EvmContractToPayerKeys { | ||
contract: Address, | ||
payer: Pubkey, | ||
storage_acc: Pubkey, | ||
} | ||
|
||
impl FromStr for EvmContractToPayerKeys { | ||
type Err = ParseEvmContractToPayerKeysError; | ||
|
||
fn from_str(s: &str) -> StdResult<Self, Self::Err> { | ||
let (addr, keys) = s | ||
.split_once(':') | ||
.ok_or(ParseEvmContractToPayerKeysError::InvalidFormat)?; | ||
let (key1, key2) = keys | ||
.split_once(':') | ||
.ok_or(ParseEvmContractToPayerKeysError::InvalidFormat)?; | ||
let contract = Address::from_str(addr) | ||
.map_err(|_| ParseEvmContractToPayerKeysError::InvalidEvmContract)?; | ||
let payer = Pubkey::from_str(key1) | ||
.map_err(|_| ParseEvmContractToPayerKeysError::InvalidPubkey)?; | ||
let storage_acc = Pubkey::from_str(key2) | ||
.map_err(|_| ParseEvmContractToPayerKeysError::InvalidPubkey)?; | ||
Ok(Self { contract, payer, storage_acc }) | ||
} | ||
} | ||
|
||
#[derive(Debug, structopt::StructOpt)] | ||
struct Args { | ||
keyfile: Option<String>, | ||
|
@@ -1016,6 +1066,11 @@ struct Args { | |
|
||
#[structopt(long = "whitelist-path")] | ||
whitelist_path: Option<String>, | ||
|
||
#[structopt(long = "gas-station")] | ||
gas_station_program_id: Option<Pubkey>, | ||
#[structopt(long = "redirect-to-proxy")] | ||
redirect_contracts_to_proxy: Option<Vec<EvmContractToPayerKeys>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we use Vec without option? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed option |
||
} | ||
|
||
impl Args { | ||
|
@@ -1110,6 +1165,10 @@ async fn main(args: Args) -> StdResult<(), Box<dyn std::error::Error>> { | |
min_gas_price, | ||
); | ||
meta.set_whitelist(whitelist); | ||
if let Some(redirect_list) = args.redirect_contracts_to_proxy { | ||
let gas_station_program_id = args.gas_station_program_id.expect("gas-station program id is missing"); | ||
meta.set_redirect_to_proxy_filters(gas_station_program_id, redirect_list); | ||
} | ||
let meta = Arc::new(meta); | ||
|
||
let mut io = MetaIoHandler::with_middleware(ProxyMiddleware {}); | ||
|
@@ -1283,6 +1342,8 @@ mod tests { | |
pool: EthPool::new(SystemClock), | ||
min_gas_price: 0.into(), | ||
whitelist: vec![], | ||
gas_station_program_id: None, | ||
redirect_to_proxy_filters: vec![], | ||
}); | ||
|
||
let rpc = BridgeErpcImpl {}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gas_station ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed payer to gas_station_payer, removed address/key names