Skip to content

Commit 5934113

Browse files
committed
docs(adapters): adds docs to collateral adapter
Signed-off-by: Bryan Cole <[email protected]>
1 parent cdd2bb4 commit 5934113

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

tap_core/src/adapters/collateral_adapter.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,49 @@
33

44
use ethereum_types::Address;
55

6+
/// `CollateralAdapter` defines a trait for adapters to handle collateral related operations.
7+
///
8+
/// This trait is designed to be implemented by users of this library who want to
9+
/// customize the management of local accounting for available collateral. The error handling is also
10+
/// customizable by defining an `AdapterError` type, which must implement both `Error`
11+
/// and `Debug` from the standard library.
12+
///
13+
/// # Usage
14+
///
15+
/// The `get_available_collateral` method should be used to retrieve the local accounting
16+
/// amount of available collateral for a specified gateway. Any errors during this operation
17+
/// should be captured and returned in the `AdapterError` format.
18+
///
19+
/// The `subtract_collateral` method is used to deduct a specified value from the local accounting
20+
/// of available collateral of a specified gateway. Any errors during this operation should be captured
21+
/// and returned as an `AdapterError`.
22+
///
23+
/// This trait is utilized by [crate::tap_manager], which relies on these
24+
/// operations for managing collateral.
25+
///
26+
/// # Example
27+
///
28+
/// For example code see [crate::adapters::collateral_adapter_mock]
29+
630
pub trait CollateralAdapter {
7-
/// User defined error type;
8-
type AdapterError: std::error::Error + std::fmt::Debug;
31+
/// Defines the user-specified error type.
32+
///
33+
/// This error type should implement the `Error` and `Debug` traits from the standard library.
34+
/// Errors of this type are returned to the user when an operation fails.
35+
type AdapterError: std::error::Error + std::fmt::Debug + Send + Sync + 'static;
936

37+
/// Retrieves the local accounting amount of available collateral for a specified gateway.
38+
///
39+
/// This method should be implemented to fetch the local accounting amount of available collateral for a
40+
/// specified gateway from your system. Any errors that occur during this process should
41+
/// be captured and returned as an `AdapterError`.
1042
fn get_available_collateral(&self, gateway_id: Address) -> Result<u128, Self::AdapterError>;
43+
44+
/// Deducts a specified value from the local accounting of available collateral for a specified gateway.
45+
///
46+
/// This method should be implemented to deduct a specified value from the local accounting of
47+
/// available collateral of a specified gateway in your system. Any errors that occur during this
48+
/// process should be captured and returned as an `AdapterError`.
1149
fn subtract_collateral(
1250
&mut self,
1351
gateway_id: Address,

0 commit comments

Comments
 (0)