Skip to content

Commit b1d940e

Browse files
authored
Merge pull request #157 from semiotic-ai/142-document-receipt-checks-adapter-trait-exhaustively-in-code
docs(adapter): adds docs to receipt checks adapter
2 parents a2bf88a + 399ddd9 commit b1d940e

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed
Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,54 @@
11
// Copyright 2023-, Semiotic AI, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use crate::{eip_712_signed_message::EIP712SignedMessage, tap_receipt::Receipt};
45
use ethereum_types::Address;
56

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]
729
830
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.
936
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.
1042
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.
1147
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.
1253
fn is_valid_gateway_id(&self, gateway_id: Address) -> bool;
1354
}

0 commit comments

Comments
 (0)