22// SPDX-License-Identifier: Apache-2.0
33
44use std:: {
5+ marker:: PhantomData ,
56 sync:: Arc ,
67 time:: { Duration , Instant } ,
78} ;
@@ -16,7 +17,7 @@ use tap_aggregator::grpc::{
1617 tap_aggregator_client:: TapAggregatorClient , RavRequest as AggregatorRequest ,
1718} ;
1819use tap_core:: {
19- manager:: adapters:: RavRead ,
20+ manager:: adapters:: { RavRead , RavStore , ReceiptDelete , ReceiptRead } ,
2021 rav_request:: RavRequest ,
2122 receipt:: {
2223 checks:: { Check , CheckList } ,
@@ -43,7 +44,7 @@ use crate::{
4344 tap:: {
4445 context:: {
4546 checks:: { AllocationId , Signature } ,
46- TapAgentContext ,
47+ ReceiptType , TapAgentContext ,
4748 } ,
4849 signers_trimmed, TapReceipt ,
4950 } ,
@@ -100,29 +101,28 @@ pub enum RavError {
100101 Other ( #[ from] anyhow:: Error ) ,
101102}
102103
103- type TapManager = tap_core:: manager:: Manager < TapAgentContext , TapReceipt > ;
104-
105- pub enum AllocationType {
106- Legacy ,
107- Horizon ,
108- }
104+ type TapManager < T > = tap_core:: manager:: Manager < TapAgentContext < T > , TapReceipt > ;
109105
110106/// Manages unaggregated fees and the TAP lifecyle for a specific (allocation, sender) pair.
111- pub struct SenderAllocation ;
107+ pub struct SenderAllocation < T > ( PhantomData < T > ) ;
108+ impl < T : ReceiptType > Default for SenderAllocation < T > {
109+ fn default ( ) -> Self {
110+ Self ( PhantomData )
111+ }
112+ }
112113
113- pub struct SenderAllocationState {
114+ pub struct SenderAllocationState < T > {
114115 unaggregated_fees : UnaggregatedReceipts ,
115116 invalid_receipts_fees : UnaggregatedReceipts ,
116117 latest_rav : Option < SignedRav > ,
117118 pgpool : PgPool ,
118- tap_manager : TapManager ,
119+ tap_manager : TapManager < T > ,
119120 allocation_id : Address ,
120121 sender : Address ,
121122 escrow_accounts : Receiver < EscrowAccounts > ,
122123 domain_separator : Eip712Domain ,
123124 sender_account_ref : ActorRef < SenderAccountMessage > ,
124125 sender_aggregator : TapAggregatorClient < Channel > ,
125- allocation_type : AllocationType ,
126126 //config
127127 timestamp_buffer_ns : u64 ,
128128 rav_request_receipt_limit : u64 ,
@@ -157,8 +157,6 @@ pub struct SenderAllocationArgs {
157157 pub domain_separator : Eip712Domain ,
158158 pub sender_account_ref : ActorRef < SenderAccountMessage > ,
159159 pub sender_aggregator : TapAggregatorClient < Channel > ,
160- #[ builder( default = AllocationType :: Legacy ) ]
161- pub allocation_type : AllocationType ,
162160
163161 //config
164162 pub config : AllocationConfig ,
@@ -173,9 +171,16 @@ pub enum SenderAllocationMessage {
173171}
174172
175173#[ async_trait:: async_trait]
176- impl Actor for SenderAllocation {
174+ impl < T > Actor for SenderAllocation < T >
175+ where
176+ T : ReceiptType + Send + Sync + ' static ,
177+ TapAgentContext < T > : RavRead < ReceiptAggregateVoucher >
178+ + RavStore < ReceiptAggregateVoucher >
179+ + ReceiptDelete
180+ + ReceiptRead < TapReceipt > ,
181+ {
177182 type Msg = SenderAllocationMessage ;
178- type State = SenderAllocationState ;
183+ type State = SenderAllocationState < T > ;
179184 type Arguments = SenderAllocationArgs ;
180185
181186 async fn pre_start (
@@ -350,10 +355,16 @@ impl Actor for SenderAllocation {
350355 }
351356}
352357
353- impl SenderAllocationState {
358+ impl < T > SenderAllocationState < T >
359+ where
360+ T : ReceiptType + Send + Sync ,
361+ TapAgentContext < T > : RavRead < ReceiptAggregateVoucher >
362+ + RavStore < ReceiptAggregateVoucher >
363+ + ReceiptDelete
364+ + ReceiptRead < TapReceipt > ,
365+ {
354366 async fn new (
355367 SenderAllocationArgs {
356- allocation_type,
357368 pgpool,
358369 allocation_id,
359370 sender,
@@ -397,7 +408,6 @@ impl SenderAllocationState {
397408 Ok ( Self {
398409 pgpool,
399410 tap_manager,
400- allocation_type,
401411 allocation_id,
402412 sender,
403413 escrow_accounts,
@@ -1028,7 +1038,7 @@ pub mod tests {
10281038 . rav_request_receipt_limit ( rav_request_receipt_limit)
10291039 . call ( )
10301040 . await ;
1031- let actor = TestableActor :: new ( SenderAllocation ) ;
1041+ let actor = TestableActor :: new ( SenderAllocation :: default ( ) ) ;
10321042 let notify = actor. notify . clone ( ) ;
10331043
10341044 let ( allocation_ref, _join_handle) = Actor :: spawn ( None , actor, args) . await . unwrap ( ) ;
0 commit comments