11// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22// SPDX-License-Identifier: Apache-2.0
33
4- //! injects allocation id in extensions
5- //! - check if allocation id already exists
6- //! - else, try to fetch allocation id from deployment_id and allocations watcher
7- //! - execute query
8- //!
9- //! Needs signed receipt Extension to be added OR deployment id
10-
114use std:: collections:: HashMap ;
125
136use alloy:: primitives:: Address ;
@@ -20,6 +13,7 @@ use tap_core::receipt::SignedReceipt;
2013use thegraph_core:: DeploymentId ;
2114use tokio:: sync:: watch;
2215
16+ /// The current query Allocation Id address
2317#[ derive( Clone ) ]
2418pub struct Allocation ( pub Address ) ;
2519
@@ -29,11 +23,18 @@ impl From<Allocation> for String {
2923 }
3024}
3125
26+ /// State to be used by allocation middleware
3227#[ derive( Clone ) ]
3328pub struct AllocationState {
29+ /// watcher that maps deployment ids to allocation ids
3430 pub deployment_to_allocation : watch:: Receiver < HashMap < DeploymentId , Address > > ,
3531}
3632
33+ /// Injects allocation id in extensions
34+ /// - check if allocation id already exists
35+ /// - else, try to fetch allocation id from deployment_id to allocations map
36+ ///
37+ /// Requires signed receipt Extension to be added OR deployment id
3738pub async fn allocation_middleware (
3839 State ( my_state) : State < AllocationState > ,
3940 mut request : Request ,
0 commit comments