Skip to content

Commit ef9f1ef

Browse files
committed
refactor: add types to monitor
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 40e7612 commit ef9f1ef

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

crates/monitor/src/allocations.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ use std::{
1212
};
1313
use tokio::sync::watch::Receiver;
1414

15+
pub type AllocationWatcher = Receiver<HashMap<Address, Allocation>>;
16+
1517
/// An always up-to-date list of an indexer's active and recently closed allocations.
1618
pub async fn indexer_allocations(
1719
network_subgraph: &'static SubgraphClient,
1820
indexer_address: Address,
1921
interval: Duration,
2022
recently_closed_allocation_buffer: Duration,
21-
) -> anyhow::Result<Receiver<HashMap<Address, Allocation>>> {
23+
) -> anyhow::Result<AllocationWatcher> {
2224
new_watcher(interval, move || async move {
2325
get_allocations(
2426
network_subgraph,

crates/monitor/src/attestation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ use thegraph_core::{Address, ChainId};
1111
use tokio::sync::watch::Receiver;
1212
use tracing::warn;
1313

14+
pub type AttestationWatcher = Receiver<HashMap<Address, AttestationSigner>>;
15+
1416
/// An always up-to-date list of attestation signers, one for each of the indexer's allocations.
1517
pub fn attestation_signers(
1618
indexer_allocations_rx: Receiver<HashMap<Address, Allocation>>,
1719
indexer_mnemonic: Mnemonic,
1820
chain_id: ChainId,
1921
dispute_manager_rx: Receiver<Address>,
20-
) -> Receiver<HashMap<Address, AttestationSigner>> {
22+
) -> AttestationWatcher {
2123
let attestation_signers_map: &'static Mutex<HashMap<Address, AttestationSigner>> =
2224
Box::leak(Box::new(Mutex::new(HashMap::new())));
2325
let indexer_mnemonic = Arc::new(indexer_mnemonic.to_string());

crates/monitor/src/deployment_to_allocation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ use tokio::sync::watch::Receiver;
88
use indexer_allocation::Allocation;
99
use indexer_watcher::map_watcher;
1010

11+
pub type DeploymentToAllocationWatcher = Receiver<HashMap<DeploymentId, Address>>;
12+
1113
/// Watcher of indexer allocation
1214
/// returning a map of subgraph deployment to allocation id
1315
pub fn deployment_to_allocation(
1416
indexer_allocations_rx: Receiver<HashMap<Address, Allocation>>,
15-
) -> Receiver<HashMap<DeploymentId, Address>> {
17+
) -> DeploymentToAllocationWatcher {
1618
map_watcher(indexer_allocations_rx, move |allocation| {
1719
allocation
1820
.iter()

crates/monitor/src/dispute_manager.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ use indexer_watcher::new_watcher;
99
use std::time::Duration;
1010
use tokio::sync::watch::Receiver;
1111

12+
pub type DisputeManagerWatcher = Receiver<Address>;
13+
1214
pub async fn dispute_manager(
1315
network_subgraph: &'static SubgraphClient,
1416
interval: Duration,
15-
) -> anyhow::Result<Receiver<Address>> {
17+
) -> anyhow::Result<DisputeManagerWatcher> {
1618
new_watcher(interval, move || async move {
1719
let response = network_subgraph
1820
.query::<DisputeManager, _>(dispute_manager::Variables {})

crates/monitor/src/escrow_accounts.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ impl EscrowAccounts {
8787
}
8888
}
8989

90+
pub type EscrowAccountsWatcher = Receiver<EscrowAccounts>;
91+
9092
pub async fn escrow_accounts(
9193
escrow_subgraph: &'static SubgraphClient,
9294
indexer_address: Address,
9395
interval: Duration,
9496
reject_thawing_signers: bool,
95-
) -> Result<Receiver<EscrowAccounts>, anyhow::Error> {
97+
) -> Result<EscrowAccountsWatcher, anyhow::Error> {
9698
indexer_watcher::new_watcher(interval, move || {
9799
get_escrow_accounts(escrow_subgraph, indexer_address, reject_thawing_signers)
98100
})

crates/monitor/src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ mod dispute_manager;
99
mod escrow_accounts;
1010

1111
pub use crate::{
12-
allocations::indexer_allocations,
13-
attestation::attestation_signers,
12+
allocations::{indexer_allocations, AllocationWatcher},
13+
attestation::{attestation_signers, AttestationWatcher},
1414
client::{DeploymentDetails, SubgraphClient},
15-
deployment_to_allocation::deployment_to_allocation,
16-
dispute_manager::dispute_manager,
17-
escrow_accounts::{escrow_accounts, EscrowAccounts, EscrowAccountsError},
15+
deployment_to_allocation::{deployment_to_allocation, DeploymentToAllocationWatcher},
16+
dispute_manager::{dispute_manager, DisputeManagerWatcher},
17+
escrow_accounts::{
18+
escrow_accounts, EscrowAccounts, EscrowAccountsError, EscrowAccountsWatcher,
19+
},
1820
};

0 commit comments

Comments
 (0)