Skip to content

Commit 42bd2df

Browse files
committed
revert: rename back to adapters
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 7810f4a commit 42bd2df

File tree

14 files changed

+76
-76
lines changed

14 files changed

+76
-76
lines changed

tap_core/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ pub enum Error {
3636
received_rav: ReceiptAggregateVoucher,
3737
expected_rav: ReceiptAggregateVoucher,
3838
},
39-
#[error("Error from strategy.\n Caused by: {source_error}")]
40-
StrategyError { source_error: anyhow::Error },
39+
#[error("Error from adapter.\n Caused by: {source_error}")]
40+
AdapterError { source_error: anyhow::Error },
4141
#[error("Failed to produce rav request, no valid receipts")]
4242
NoValidReceiptsForRAVRequest,
4343
#[error("Previous RAV allocation id ({prev_id}) doesn't match the allocation id from the new receipt ({new_id}).")]

tap_core/src/manager/strategy/escrow.rs renamed to tap_core/src/manager/adapters/escrow.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ use crate::{
1515
///
1616
/// This trait is designed to be implemented by users of this library who want to
1717
/// customize the management of local accounting for available escrow. The error handling is also
18-
/// customizable by defining an `StrategyError` type, which must implement both `Error`
18+
/// customizable by defining an `AdapterError` type, which must implement both `Error`
1919
/// and `Debug` from the standard library.
2020
///
2121
/// # Usage
2222
///
2323
/// The `get_available_escrow` method should be used to retrieve the local accounting
2424
/// amount of available escrow for a specified sender. Any errors during this operation
25-
/// should be captured and returned in the `StrategyError` format.
25+
/// should be captured and returned in the `AdapterError` format.
2626
///
2727
/// The `subtract_escrow` method is used to deduct a specified value from the local accounting
2828
/// of available escrow of a specified sender. Any errors during this operation should be captured
29-
/// and returned as an `StrategyError`.
29+
/// and returned as an `AdapterError`.
3030
///
3131
/// This trait is utilized by [crate::tap_manager], which relies on these
3232
/// operations for managing escrow.
@@ -41,27 +41,27 @@ pub trait EscrowHandler: Send + Sync {
4141
///
4242
/// This error type should implement the `Error` and `Debug` traits from the standard library.
4343
/// Errors of this type are returned to the user when an operation fails.
44-
type StrategyError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
44+
type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
4545

4646
/// Retrieves the local accounting amount of available escrow for a specified sender.
4747
///
4848
/// This method should be implemented to fetch the local accounting amount of available escrow for a
4949
/// specified sender from your system. Any errors that occur during this process should
50-
/// be captured and returned as an `StrategyError`.
51-
async fn get_available_escrow(&self, sender_id: Address) -> Result<u128, Self::StrategyError>;
50+
/// be captured and returned as an `AdapterError`.
51+
async fn get_available_escrow(&self, sender_id: Address) -> Result<u128, Self::AdapterError>;
5252

5353
/// Deducts a specified value from the local accounting of available escrow for a specified sender.
5454
///
5555
/// This method should be implemented to deduct a specified value from the local accounting of
5656
/// available escrow of a specified sender in your system. Any errors that occur during this
57-
/// process should be captured and returned as an `StrategyError`.
57+
/// process should be captured and returned as an `AdapterError`.
5858
async fn subtract_escrow(
5959
&self,
6060
sender_id: Address,
6161
value: u128,
62-
) -> Result<(), Self::StrategyError>;
62+
) -> Result<(), Self::AdapterError>;
6363

64-
async fn verify_signer(&self, signer_address: Address) -> Result<bool, Self::StrategyError>;
64+
async fn verify_signer(&self, signer_address: Address) -> Result<bool, Self::AdapterError>;
6565

6666
async fn check_and_reserve_escrow(
6767
&self,
File renamed without changes.

tap_core/src/manager/strategy/rav.rs renamed to tap_core/src/manager/adapters/rav.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use crate::rav::SignedRAV;
99
///
1010
/// This trait is designed to be implemented by users of this library who want to
1111
/// customize the write storage behavior of `SignedRAV` data. The error handling is also
12-
/// customizable by defining an `StrategyError` type, which must implement both `Error`
12+
/// customizable by defining an `AdapterError` type, which must implement both `Error`
1313
/// and `Debug` from the standard library.
1414
///
1515
/// # Usage
1616
///
1717
/// The `update_last_rav` method should be used to update the last validated `SignedRAV`
1818
/// in the storage managed by the adapter. Errors during this operation should be
19-
/// captured and returned in the `StrategyError` format.
19+
/// captured and returned in the `AdapterError` format.
2020
///
2121
/// This trait is utilized by [crate::tap_manager], which relies on these
2222
/// operations for working with `SignedRAV` data.
@@ -31,27 +31,27 @@ pub trait RAVStore {
3131
///
3232
/// This error type should implement the `Error` and `Debug` traits from the standard library.
3333
/// Errors of this type are returned to the user when an operation fails.
34-
type StrategyError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
34+
type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
3535

3636
/// Updates the storage with the latest validated `SignedRAV`.
3737
///
3838
/// This method should be implemented to store the most recent validated `SignedRAV` into your chosen storage system.
39-
/// Any errors that occur during this process should be captured and returned as an `StrategyError`.
40-
async fn update_last_rav(&self, rav: SignedRAV) -> Result<(), Self::StrategyError>;
39+
/// Any errors that occur during this process should be captured and returned as an `AdapterError`.
40+
async fn update_last_rav(&self, rav: SignedRAV) -> Result<(), Self::AdapterError>;
4141
}
4242

4343
/// `RAVRead` defines a trait for read storage adapters to handle `SignedRAV` data.
4444
///
4545
/// This trait is designed to be implemented by users of this library who want to
4646
/// customize the read storage behavior of `SignedRAV` data. The error handling is also
47-
/// customizable by defining an `StrategyError` type, which must implement both `Error`
47+
/// customizable by defining an `AdapterError` type, which must implement both `Error`
4848
/// and `Debug` from the standard library.
4949
///
5050
/// # Usage
5151
///
5252
/// The `last_rav` method is designed to fetch the latest `SignedRAV` from the storage.
5353
/// If there is no `SignedRAV` available, it should return `None`. Any errors during
54-
/// this operation should be captured and returned as an `StrategyError`.
54+
/// this operation should be captured and returned as an `AdapterError`.
5555
///
5656
/// This trait is utilized by [crate::tap_manager], which relies on these
5757
/// operations for working with `SignedRAV` data.
@@ -66,12 +66,12 @@ pub trait RAVRead {
6666
///
6767
/// This error type should implement the `Error` and `Debug` traits from the standard library.
6868
/// Errors of this type are returned to the user when an operation fails.
69-
type StrategyError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
69+
type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
7070

7171
/// Retrieves the latest `SignedRAV` from the storage.
7272
///
7373
/// This method should be implemented to fetch the latest `SignedRAV` from your storage system.
7474
/// If no `SignedRAV` is available, this method should return `None`.
75-
/// Any errors that occur during this process should be captured and returned as an `StrategyError`.
76-
async fn last_rav(&self) -> Result<Option<SignedRAV>, Self::StrategyError>;
75+
/// Any errors that occur during this process should be captured and returned as an `AdapterError`.
76+
async fn last_rav(&self) -> Result<Option<SignedRAV>, Self::AdapterError>;
7777
}

tap_core/src/manager/strategy/receipt.rs renamed to tap_core/src/manager/adapters/receipt.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ use crate::receipt::{Checking, ReceiptState, ReceiptWithState};
1111
///
1212
/// This trait is designed to be implemented by users of this library who want to
1313
/// customize the write storage behavior of `ReceivedReceipt` data. The error handling is also
14-
/// customizable by defining an `StrategyError` type, which must implement both `Error`
14+
/// customizable by defining an `AdapterError` type, which must implement both `Error`
1515
/// and `Debug` from the standard library.
1616
///
1717
/// # Usage
1818
///
1919
/// The `store_receipt` method should be used to store a new `ReceivedReceipt` in the storage
2020
/// managed by the adapter. It returns a unique receipt_id associated with the stored receipt.
21-
/// Any errors during this operation should be captured and returned in the `StrategyError` format.
21+
/// Any errors during this operation should be captured and returned in the `AdapterError` format.
2222
///
2323
/// The `update_receipt_by_id` method is designed to update a specific `ReceivedReceipt` identified by a unique
24-
/// receipt_id. Any errors during this operation should be captured and returned as an `StrategyError`.
24+
/// receipt_id. Any errors during this operation should be captured and returned as an `AdapterError`.
2525
///
2626
/// The `remove_receipts_in_timestamp_range` method is used to remove all `ReceivedReceipts` within a specific
27-
/// timestamp range from the storage. Any errors during this operation should be captured and returned as an `StrategyError`.
27+
/// timestamp range from the storage. Any errors during this operation should be captured and returned as an `AdapterError`.
2828
///
2929
/// This trait is utilized by [crate::tap_manager], which relies on these
3030
/// operations for working with `ReceivedReceipt` data.
@@ -39,17 +39,17 @@ pub trait ReceiptStore {
3939
///
4040
/// This error type should implement the `Error` and `Debug` traits from the standard library.
4141
/// Errors of this type are returned to the user when an operation fails.
42-
type StrategyError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
42+
type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
4343

4444
/// Stores a new `ReceivedReceipt` into the storage.
4545
///
4646
/// This method should be implemented to store a new `ReceivedReceipt` into your chosen storage system.
4747
/// It returns a unique receipt_id associated with the stored receipt. Any errors that occur during
48-
/// this process should be captured and returned as an `StrategyError`.
48+
/// this process should be captured and returned as an `AdapterError`.
4949
async fn store_receipt(
5050
&self,
5151
receipt: ReceiptWithState<Checking>,
52-
) -> Result<u64, Self::StrategyError>;
52+
) -> Result<u64, Self::AdapterError>;
5353
}
5454

5555
#[async_trait]
@@ -58,23 +58,23 @@ pub trait ReceiptDelete {
5858
///
5959
/// This error type should implement the `Error` and `Debug` traits from the standard library.
6060
/// Errors of this type are returned to the user when an operation fails.
61-
type StrategyError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
61+
type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
6262
/// Removes all `ReceivedReceipts` within a specific timestamp range from the storage.
6363
///
6464
/// This method should be implemented to remove all `ReceivedReceipts` within a specific timestamp
6565
/// range from your storage system. Any errors that occur during this process should be captured and
66-
/// returned as an `StrategyError`.
66+
/// returned as an `AdapterError`.
6767
async fn remove_receipts_in_timestamp_range<R: RangeBounds<u64> + std::marker::Send>(
6868
&self,
6969
timestamp_ns: R,
70-
) -> Result<(), Self::StrategyError>;
70+
) -> Result<(), Self::AdapterError>;
7171
}
7272

7373
/// `ReceiptRead` defines a trait for read storage adapters to manage `ReceivedReceipt` data.
7474
///
7575
/// This trait is designed to be implemented by users of this library who want to
7676
/// customize the read storage behavior of `ReceivedReceipt` data. The error handling is also
77-
/// customizable by defining an `StrategyError` type, which must implement both `Error`
77+
/// customizable by defining an `AdapterError` type, which must implement both `Error`
7878
/// and `Debug` from the standard library.
7979
///
8080
/// # Usage
@@ -88,7 +88,7 @@ pub trait ReceiptRead {
8888
///
8989
/// This error type should implement the `Error` and `Debug` traits from the standard library.
9090
/// Errors of this type are returned to the user when an operation fails.
91-
type StrategyError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
91+
type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
9292

9393
/// Retrieves all `ReceivedReceipts` within a specific timestamp range.
9494
///
@@ -110,12 +110,12 @@ pub trait ReceiptRead {
110110
/// You can use the [`safe_truncate_receipts()`] function to help with this, but feel free to
111111
/// implement a more efficient solution for your situation if you can.
112112
///
113-
/// Any errors that occur during this process should be captured and returned as an `StrategyError`.
113+
/// Any errors that occur during this process should be captured and returned as an `AdapterError`.
114114
async fn retrieve_receipts_in_timestamp_range<R: RangeBounds<u64> + std::marker::Send>(
115115
&self,
116116
timestamp_range_ns: R,
117117
limit: Option<u64>,
118-
) -> Result<Vec<ReceiptWithState<Checking>>, Self::StrategyError>;
118+
) -> Result<Vec<ReceiptWithState<Checking>>, Self::AdapterError>;
119119
}
120120

121121
/// See [`ReceiptStorageAdapter::retrieve_receipts_in_timestamp_range()`] for details.

tap_core/src/manager/context/memory.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use crate::{
5-
manager::strategy::*,
5+
manager::adapters::*,
66
rav::SignedRAV,
77
receipt::{checks::TimestampCheck, Checking, ReceiptWithState},
88
signed_message::MessageId,
@@ -23,7 +23,7 @@ use thiserror::Error;
2323
#[derive(Debug, Error)]
2424
pub enum InMemoryError {
2525
#[error("something went wrong: {error}")]
26-
StrategyError { error: String },
26+
AdapterError { error: String },
2727
}
2828

2929
#[derive(Clone)]
@@ -68,7 +68,7 @@ impl InMemoryContext {
6868
receipt_storage
6969
.get(&receipt_id)
7070
.cloned()
71-
.ok_or(InMemoryError::StrategyError {
71+
.ok_or(InMemoryError::AdapterError {
7272
error: "No receipt found with ID".to_owned(),
7373
})
7474
}
@@ -100,7 +100,7 @@ impl InMemoryContext {
100100
receipt_storage
101101
.remove(&receipt_id)
102102
.map(|_| ())
103-
.ok_or(InMemoryError::StrategyError {
103+
.ok_or(InMemoryError::AdapterError {
104104
error: "No receipt found with ID".to_owned(),
105105
})
106106
}
@@ -117,9 +117,9 @@ impl InMemoryContext {
117117

118118
#[async_trait]
119119
impl RAVStore for InMemoryContext {
120-
type StrategyError = InMemoryError;
120+
type AdapterError = InMemoryError;
121121

122-
async fn update_last_rav(&self, rav: SignedRAV) -> Result<(), Self::StrategyError> {
122+
async fn update_last_rav(&self, rav: SignedRAV) -> Result<(), Self::AdapterError> {
123123
let mut rav_storage = self.rav_storage.write().unwrap();
124124
let timestamp = rav.message.timestampNs;
125125
*rav_storage = Some(rav);
@@ -130,21 +130,21 @@ impl RAVStore for InMemoryContext {
130130

131131
#[async_trait]
132132
impl RAVRead for InMemoryContext {
133-
type StrategyError = InMemoryError;
133+
type AdapterError = InMemoryError;
134134

135-
async fn last_rav(&self) -> Result<Option<SignedRAV>, Self::StrategyError> {
135+
async fn last_rav(&self) -> Result<Option<SignedRAV>, Self::AdapterError> {
136136
Ok(self.rav_storage.read().unwrap().clone())
137137
}
138138
}
139139

140140
#[async_trait]
141141
impl ReceiptStore for InMemoryContext {
142-
type StrategyError = InMemoryError;
142+
type AdapterError = InMemoryError;
143143

144144
async fn store_receipt(
145145
&self,
146146
receipt: ReceiptWithState<Checking>,
147-
) -> Result<u64, Self::StrategyError> {
147+
) -> Result<u64, Self::AdapterError> {
148148
let mut id_pointer = self.unique_id.write().unwrap();
149149
let id_previous = *id_pointer;
150150
let mut receipt_storage = self.receipt_storage.write().unwrap();
@@ -156,12 +156,12 @@ impl ReceiptStore for InMemoryContext {
156156

157157
#[async_trait]
158158
impl ReceiptDelete for InMemoryContext {
159-
type StrategyError = InMemoryError;
159+
type AdapterError = InMemoryError;
160160

161161
async fn remove_receipts_in_timestamp_range<R: RangeBounds<u64> + std::marker::Send>(
162162
&self,
163163
timestamp_ns: R,
164-
) -> Result<(), Self::StrategyError> {
164+
) -> Result<(), Self::AdapterError> {
165165
let mut receipt_storage = self.receipt_storage.write().unwrap();
166166
receipt_storage.retain(|_, rx_receipt| {
167167
!timestamp_ns.contains(&rx_receipt.signed_receipt().message.timestamp_ns)
@@ -171,12 +171,12 @@ impl ReceiptDelete for InMemoryContext {
171171
}
172172
#[async_trait]
173173
impl ReceiptRead for InMemoryContext {
174-
type StrategyError = InMemoryError;
174+
type AdapterError = InMemoryError;
175175
async fn retrieve_receipts_in_timestamp_range<R: RangeBounds<u64> + std::marker::Send>(
176176
&self,
177177
timestamp_range_ns: R,
178178
limit: Option<u64>,
179-
) -> Result<Vec<ReceiptWithState<Checking>>, Self::StrategyError> {
179+
) -> Result<Vec<ReceiptWithState<Checking>>, Self::AdapterError> {
180180
let receipt_storage = self.receipt_storage.read().unwrap();
181181
let mut receipts_in_range: Vec<ReceiptWithState<Checking>> = receipt_storage
182182
.iter()
@@ -199,7 +199,7 @@ impl InMemoryContext {
199199
if let Some(escrow) = sender_escrow_storage.get(&sender_id) {
200200
return Ok(*escrow);
201201
}
202-
Err(InMemoryError::StrategyError {
202+
Err(InMemoryError::AdapterError {
203203
error: "No escrow exists for provided sender ID.".to_owned(),
204204
})
205205
}
@@ -225,27 +225,27 @@ impl InMemoryContext {
225225
return Ok(());
226226
}
227227
}
228-
Err(InMemoryError::StrategyError {
228+
Err(InMemoryError::AdapterError {
229229
error: "Provided value is greater than existing escrow.".to_owned(),
230230
})
231231
}
232232
}
233233

234234
#[async_trait]
235235
impl EscrowHandler for InMemoryContext {
236-
type StrategyError = InMemoryError;
237-
async fn get_available_escrow(&self, sender_id: Address) -> Result<u128, Self::StrategyError> {
236+
type AdapterError = InMemoryError;
237+
async fn get_available_escrow(&self, sender_id: Address) -> Result<u128, Self::AdapterError> {
238238
self.escrow(sender_id)
239239
}
240240
async fn subtract_escrow(
241241
&self,
242242
sender_id: Address,
243243
value: u128,
244-
) -> Result<(), Self::StrategyError> {
244+
) -> Result<(), Self::AdapterError> {
245245
self.reduce_escrow(sender_id, value)
246246
}
247247

248-
async fn verify_signer(&self, signer_address: Address) -> Result<bool, Self::StrategyError> {
248+
async fn verify_signer(&self, signer_address: Address) -> Result<bool, Self::AdapterError> {
249249
Ok(self
250250
.sender_address
251251
.map(|sender| signer_address == sender)

tap_core/src/manager/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
#[cfg(feature = "in_memory")]
1414
pub mod context;
15-
pub mod strategy;
15+
pub mod adapters;
1616
mod tap_manager;
1717

1818
pub use tap_manager::Manager;

0 commit comments

Comments
 (0)