From c4844429137d2f732ee49cd671c0d32377c13054 Mon Sep 17 00:00:00 2001 From: Kamil Koczurek Date: Fri, 29 Sep 2023 10:27:54 +0200 Subject: [PATCH] runtime: add convenience methods to get chain / network name --- crates/erc20_payment_lib/src/runtime.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/erc20_payment_lib/src/runtime.rs b/crates/erc20_payment_lib/src/runtime.rs index 8b74e3d8..e5489dba 100644 --- a/crates/erc20_payment_lib/src/runtime.rs +++ b/crates/erc20_payment_lib/src/runtime.rs @@ -11,7 +11,7 @@ use std::path::Path; use crate::error::{ErrorBag, PaymentError}; -use crate::setup::{ExtraOptionsForTesting, PaymentSetup}; +use crate::setup::{ChainSetup, ExtraOptionsForTesting, PaymentSetup}; use crate::config::{self, Config}; use secp256k1::SecretKey; @@ -345,7 +345,7 @@ pub struct PaymentRuntime { pub runtime_handle: JoinHandle<()>, pub setup: PaymentSetup, pub shared_state: Arc>, - pub conn: SqlitePool, + conn: SqlitePool, status_tracker: StatusTracker, config: Config, } @@ -519,7 +519,16 @@ impl PaymentRuntime { pub async fn get_status(&self) -> Vec { self.status_tracker.get_status().await } + + pub fn get_chain(&self, chain_id: i64) -> Option<&ChainSetup> { + self.setup.chain_setup.get(&chain_id) + } + + pub fn network_name(&self, chain_id: i64) -> Option<&str> { + self.get_chain(chain_id).map(|chain| chain.network.as_str()) + } } + pub async fn remove_last_unsent_transactions( conn: SqlitePool, ) -> Result, PaymentError> {