Skip to content

Commit 1cb87e2

Browse files
committed
refactor: add deployment_to_allocation monitor
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 92c6e35 commit 1cb87e2

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use std::collections::HashMap;
5+
use thegraph_core::{Address, DeploymentId};
6+
use tokio::sync::watch::Receiver;
7+
8+
use indexer_allocation::Allocation;
9+
use indexer_watcher::map_watcher;
10+
11+
/// An always up-to-date list of attestation signers, one for each of the indexer's allocations.
12+
pub fn deployment_to_allocation(
13+
indexer_allocations_rx: Receiver<HashMap<Address, Allocation>>,
14+
) -> Receiver<HashMap<DeploymentId, Address>> {
15+
map_watcher(indexer_allocations_rx, move |allocation| {
16+
allocation
17+
.iter()
18+
.map(|(address, allocation)| (allocation.subgraph_deployment.id, *address))
19+
.collect()
20+
})
21+
}

crates/monitor/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
mod allocations;
55
mod attestation;
66
mod client;
7+
mod deployment_to_allocation;
78
mod dispute_manager;
89
mod escrow_accounts;
910

1011
pub use crate::{
1112
allocations::indexer_allocations,
1213
attestation::attestation_signers,
1314
client::{DeploymentDetails, SubgraphClient},
15+
deployment_to_allocation::deployment_to_allocation,
1416
dispute_manager::dispute_manager,
1517
escrow_accounts::{escrow_accounts, EscrowAccounts, EscrowAccountsError},
1618
};

0 commit comments

Comments
 (0)