|
1 | 1 | // Copyright 2023-, Semiotic AI, Inc. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
| 4 | +use crate::{eip_712_signed_message::EIP712SignedMessage, tap_receipt::Receipt}; |
4 | 5 | use ethereum_types::Address; |
5 | 6 |
|
6 | | -use crate::{eip_712_signed_message::EIP712SignedMessage, tap_receipt::Receipt}; |
| 7 | +/// `ReceiptChecksAdapter` defines a trait for adapters to handle checks related to TAP receipts. |
| 8 | +/// |
| 9 | +/// This trait is designed to be implemented by users of this library who want to |
| 10 | +/// customize the checks done on TAP receipts. This includes ensuring the receipt is unique, |
| 11 | +/// verifying the allocation ID, the value and the gateway ID. |
| 12 | +/// |
| 13 | +/// # Usage |
| 14 | +/// |
| 15 | +/// The `is_unique` method should be used to check if the given receipt is unique in the system. |
| 16 | +/// |
| 17 | +/// The `is_valid_allocation_id` method should verify if the allocation ID is valid. |
| 18 | +/// |
| 19 | +/// The `is_valid_value` method should confirm the value of the receipt is valid for the given query ID. |
| 20 | +/// |
| 21 | +/// The `is_valid_gateway_id` method should confirm the gateway ID is valid. |
| 22 | +/// |
| 23 | +/// This trait is utilized by [crate::tap_manager], which relies on these |
| 24 | +/// operations for managing TAP receipts. |
| 25 | +/// |
| 26 | +/// # Example |
| 27 | +/// |
| 28 | +/// For example code see [crate::adapters::receipt_checks_adapter_mock] |
7 | 29 |
|
8 | 30 | pub trait ReceiptChecksAdapter { |
| 31 | + /// Checks if the given receipt is unique in the system. |
| 32 | + /// |
| 33 | + /// This method should be implemented to verify the uniqueness of a given receipt in your system. Keep in mind that |
| 34 | + /// the receipt likely will be in storage when this check is performed so the receipt id should be used to check |
| 35 | + /// for uniqueness. |
9 | 36 | fn is_unique(&self, receipt: &EIP712SignedMessage<Receipt>, receipt_id: u64) -> bool; |
| 37 | + |
| 38 | + /// Verifies if the allocation ID is valid. |
| 39 | + /// |
| 40 | + /// This method should be implemented to validate the given allocation ID is a valid allocation for the indexer. Valid is defined as |
| 41 | + /// an allocation ID that is owned by the indexer and still available for redeeming. |
10 | 42 | fn is_valid_allocation_id(&self, allocation_id: Address) -> bool; |
| 43 | + |
| 44 | + /// Confirms the value of the receipt is valid for the given query ID. |
| 45 | + /// |
| 46 | + /// This method should be implemented to confirm the validity of the given value for a specific query ID. |
11 | 47 | fn is_valid_value(&self, value: u128, query_id: u64) -> bool; |
| 48 | + |
| 49 | + /// Confirms the gateway ID is valid. |
| 50 | + /// |
| 51 | + /// This method should be implemented to validate the given gateway ID is one associated with a gateway the indexer considers valid. |
| 52 | + /// The provided gateway ID is the address of the gateway that is recovered from the signature of the receipt. |
12 | 53 | fn is_valid_gateway_id(&self, gateway_id: Address) -> bool; |
13 | 54 | } |
0 commit comments