From d610337d78d9a4478240f3e88baa1adbb2684b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBelaszczyk?= Date: Mon, 2 Sep 2024 16:30:28 +0200 Subject: [PATCH] Optional payout address --- relayer/relayer/src/config.rs | 2 +- relayer/relayer/src/main.rs | 48 ++++++++++++++++++++++------------- relayer/scripts/entrypoint.sh | 3 --- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/relayer/relayer/src/config.rs b/relayer/relayer/src/config.rs index 1311643c..f69ec63c 100644 --- a/relayer/relayer/src/config.rs +++ b/relayer/relayer/src/config.rs @@ -98,7 +98,7 @@ pub struct Config { pub sync_step: u32, #[arg(long)] - pub payout_address: String, + pub payout_address: Option, #[arg(long, default_value = "redis://127.0.0.1:6379")] pub redis_node: String, diff --git a/relayer/relayer/src/main.rs b/relayer/relayer/src/main.rs index 8f5bd984..ef960661 100644 --- a/relayer/relayer/src/main.rs +++ b/relayer/relayer/src/main.rs @@ -191,6 +191,33 @@ async fn create_eth_connections( )) } +async fn set_payout_account( + config: &Config, + azero_signed_connection: &AzeroConnectionWithSigner, + payout_address: &str, +) -> Result<(), RelayerError> { + let most_azero = MostInstance::new( + &config.azero_contract_address, + &config.azero_contract_metadata, + config.azero_ref_time_limit, + config.azero_proof_size_limit, + )?; + + let current_committee_id = most_azero + .current_committee_id(azero_signed_connection.as_connection()) + .await?; + most_azero + .set_payout_account( + &azero_signed_connection, + current_committee_id, + AccountId::from_string(payout_address) + .map_err(|why| AzeroContractError::NotAccountId(why.to_string()))?, + ) + .await?; + + Ok(()) +} + #[tokio::main] async fn main() -> Result<(), RelayerError> { let config = Arc::new(Config::parse()); @@ -269,24 +296,9 @@ async fn run_relayer( create_eth_connections(&config, persistent_eth_connection).await?; info!("Established connection to the Ethereum node"); - let most_azero = MostInstance::new( - &config.azero_contract_address, - &config.azero_contract_metadata, - config.azero_ref_time_limit, - config.azero_proof_size_limit, - )?; - - let current_committee_id = most_azero - .current_committee_id(azero_connection.as_connection()) - .await?; - most_azero - .set_payout_account( - &azero_signed_connection, - current_committee_id, - AccountId::from_string(&config.payout_address) - .map_err(|why| AzeroContractError::NotAccountId(why.to_string()))?, - ) - .await?; + if let Some(payout_address) = &config.payout_address { + set_payout_account(&config, &azero_signed_connection, payout_address).await?; + } // Create channels let (eth_events_sender, eth_events_receiver) = mpsc::channel::(1); diff --git a/relayer/scripts/entrypoint.sh b/relayer/scripts/entrypoint.sh index 7aa4558a..7bd9ce61 100755 --- a/relayer/scripts/entrypoint.sh +++ b/relayer/scripts/entrypoint.sh @@ -146,9 +146,6 @@ fi if [[ -n "${PAYOUT_ADDRESS}" ]]; then ARGS+=(--payout-address=${PAYOUT_ADDRESS}) -else - echo "Payout address required but not provided." 1>&2 - exit 1 fi if [[ "${REDIS_AZERO_BLOCK_KEY}" =~ ^[a-z0-9_]+$ ]]; then