-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathallocation_eligible.rs
47 lines (43 loc) · 1.25 KB
/
allocation_eligible.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
// SPDX-License-Identifier: Apache-2.0
use std::collections::HashMap;
use anyhow::anyhow;
use indexer_allocation::Allocation;
use tap_core::receipt::{
checks::{Check, CheckError, CheckResult},
state::Checking,
ReceiptWithState,
};
use thegraph_core::alloy::primitives::Address;
use tokio::sync::watch::Receiver;
pub struct AllocationEligible {
indexer_allocations: Receiver<HashMap<Address, Allocation>>,
}
impl AllocationEligible {
pub fn new(indexer_allocations: Receiver<HashMap<Address, Allocation>>) -> Self {
Self {
indexer_allocations,
}
}
}
#[async_trait::async_trait]
impl Check for AllocationEligible {
async fn check(
&self,
_: &tap_core::receipt::Context,
receipt: &ReceiptWithState<Checking>,
) -> CheckResult {
let allocation_id = receipt.signed_receipt().message.allocation_id;
if !self
.indexer_allocations
.borrow()
.contains_key(&allocation_id)
{
return Err(CheckError::Failed(anyhow!(
"Receipt allocation ID `{}` is not eligible for this indexer",
allocation_id
)));
}
Ok(())
}
}