Skip to content

Commit

Permalink
Optional payout address
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejzelaszczyk committed Sep 2, 2024
1 parent c6b7b1c commit d610337
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion relayer/relayer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub struct Config {
pub sync_step: u32,

#[arg(long)]
pub payout_address: String,
pub payout_address: Option<String>,

#[arg(long, default_value = "redis://127.0.0.1:6379")]
pub redis_node: String,
Expand Down
48 changes: 30 additions & 18 deletions relayer/relayer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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::<EthMostEvents>(1);
Expand Down
3 changes: 0 additions & 3 deletions relayer/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d610337

Please sign in to comment.