|
3 | 3 |
|
4 | 4 | use ethereum_types::Address; |
5 | 5 |
|
| 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 | +
|
6 | 30 | 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; |
9 | 36 |
|
| 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`. |
10 | 42 | 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`. |
11 | 49 | fn subtract_collateral( |
12 | 50 | &mut self, |
13 | 51 | gateway_id: Address, |
|
0 commit comments