Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions crates/tap-agent/src/agent/sender_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,14 @@ where
escrow_accounts.clone(),
)),
];
let context = TapAgentContext::new(
pgpool.clone(),
allocation_id,
config.indexer_address,
sender,
escrow_accounts.clone(),
);
let context = TapAgentContext::builder()
.pgpool(pgpool.clone())
.allocation_id(allocation_id)
.indexer_address(config.indexer_address)
.sender(sender)
.escrow_accounts(escrow_accounts.clone())
.build();

let latest_rav = context.last_rav().await.unwrap_or_default();
let tap_manager = TapManager::new(
domain_separator.clone(),
Expand Down
27 changes: 5 additions & 22 deletions crates/tap-agent/src/tap/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,36 +152,19 @@ impl NetworkVersion for Horizon {
/// Context used by [tap_core::manager::Manager] that enables certain helper methods
///
/// This context is implemented for PostgresSQL
#[derive(Clone)]
#[derive(Clone, bon::Builder)]
pub struct TapAgentContext<T> {
pgpool: PgPool,
#[cfg_attr(test, builder(default = crate::test::ALLOCATION_ID_0))]
allocation_id: Address,
#[cfg_attr(test, builder(default = test_assets::TAP_SENDER.1))]
sender: Address,
#[cfg_attr(test, builder(default = crate::test::INDEXER.1))]
indexer_address: Address,
escrow_accounts: Receiver<EscrowAccounts>,
/// We use phantom data as a marker since it's
/// only used to define what methods are available
/// for each type of network
#[builder(default = PhantomData)]
Copy link

@Veetaha Veetaha Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using #[builder(skip)] for PhantomData fields to avoid generating setters for this field at all.

_phantom: PhantomData<T>,
}

/// Allow any [NetworkVersion] to create a new context
impl<T: NetworkVersion> TapAgentContext<T> {
/// Creates a TapContext
pub fn new(
pgpool: PgPool,
allocation_id: Address,
indexer_address: Address,
sender: Address,
escrow_accounts: Receiver<EscrowAccounts>,
) -> Self {
Self {
pgpool,
allocation_id,
indexer_address,
sender,
escrow_accounts,
_phantom: PhantomData,
}
}
}
26 changes: 10 additions & 16 deletions crates/tap-agent/src/tap/context/rav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ mod test {
use rstest::rstest;
use sqlx::PgPool;
use tap_core::signed_message::Eip712SignedMessage;
use test_assets::{TAP_SENDER as SENDER, TAP_SIGNER as SIGNER};
use test_assets::TAP_SIGNER as SIGNER;
use tokio::sync::watch;

use super::*;
use crate::{
tap::context::NetworkVersion,
test::{CreateRav, ALLOCATION_ID_0, INDEXER},
test::{CreateRav, ALLOCATION_ID_0},
};

#[derive(Debug)]
Expand All @@ -351,23 +351,17 @@ mod test {
const VALUE_AGGREGATE: u128 = u128::MAX;

async fn legacy_adapter(pgpool: PgPool) -> TapAgentContext<Legacy> {
TapAgentContext::new(
pgpool,
ALLOCATION_ID_0,
INDEXER.1,
SENDER.1,
watch::channel(EscrowAccounts::default()).1,
)
TapAgentContext::builder()
.pgpool(pgpool)
.escrow_accounts(watch::channel(EscrowAccounts::default()).1)
.build()
}

async fn horizon_adapter(pgpool: PgPool) -> TapAgentContext<Horizon> {
TapAgentContext::new(
pgpool,
ALLOCATION_ID_0,
INDEXER.1,
SENDER.1,
watch::channel(EscrowAccounts::default()).1,
)
TapAgentContext::builder()
.pgpool(pgpool)
.escrow_accounts(watch::channel(EscrowAccounts::default()).1)
.build()
}

/// Insert a single receipt and retrieve it from the database using the adapter.
Expand Down
24 changes: 9 additions & 15 deletions crates/tap-agent/src/tap/context/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ mod test {
use tokio::sync::watch::{self, Receiver};

use super::*;
use crate::test::{store_receipt, CreateReceipt, INDEXER, SENDER_2};
use crate::test::{store_receipt, CreateReceipt, SENDER_2};

const ALLOCATION_ID_IRRELEVANT: Address = ALLOCATION_ID_1;

Expand All @@ -427,26 +427,20 @@ mod test {
pgpool: PgPool,
escrow_accounts: Receiver<EscrowAccounts>,
) -> TapAgentContext<Legacy> {
TapAgentContext::new(
pgpool.clone(),
ALLOCATION_ID_0,
INDEXER.1,
SENDER.1,
escrow_accounts,
)
TapAgentContext::builder()
.pgpool(pgpool)
.escrow_accounts(escrow_accounts)
.build()
}

async fn horizon_adapter(
pgpool: PgPool,
escrow_accounts: Receiver<EscrowAccounts>,
) -> TapAgentContext<Horizon> {
TapAgentContext::new(
pgpool,
ALLOCATION_ID_0,
INDEXER.1,
SENDER.1,
escrow_accounts,
)
TapAgentContext::builder()
.pgpool(pgpool)
.escrow_accounts(escrow_accounts)
.build()
}

/// Insert a single receipt and retrieve it from the database using the adapter.
Expand Down