hopr_db_api/
logs.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
use async_trait::async_trait;

use hopr_crypto_types::prelude::Hash;
use hopr_primitive_types::prelude::{Address, SerializableLog};

use crate::errors::Result;

#[async_trait]
pub trait HoprDbLogOperations {
    /// Ensures that logs in this database have been created by scanning the given contract address
    /// and their corresponding topics. If the log DB is empty, the given addresses and topics
    /// are used to prime the table.
    ///
    /// # Arguments
    /// * `contract_address_topics` - list of topics for a contract address. There may be multiple topics
    /// with the same contract address.
    ///
    /// # Returns
    /// A `Result` which is `Ok(())` if the database contains correct log data,
    /// or it has been primed successfully. An `Err` is returned otherwise.
    async fn ensure_logs_origin(&self, contract_address_topics: Vec<(Address, Hash)>) -> Result<()>;

    /// Stores a single log entry in the database.
    ///
    /// # Arguments
    ///
    /// * `log` - The log entry to store, of type `SerializableLog`.
    ///
    /// # Returns
    ///
    /// A `Result` which is `Ok(())` if the operation succeeds or an error if it fails.
    async fn store_log<'a>(&'a self, log: SerializableLog) -> Result<()>;

    /// Stores multiple log entries in the database.
    ///
    /// # Arguments
    ///
    /// * `logs` - A vector of log entries to store, each of type `SerializableLog`.
    ///
    /// # Returns
    ///
    /// A `Result` containing a vector of `Result<()>`, each representing the result of storing an individual log entry.
    async fn store_logs(&self, logs: Vec<SerializableLog>) -> Result<Vec<Result<()>>>;

    /// Retrieves a specific log entry from the database.
    ///
    /// # Arguments
    ///
    /// * `block_number` - The block number of the log entry.
    /// * `tx_index` - The transaction index of the log entry.
    /// * `log_index` - The log index of the log entry.
    ///
    /// # Returns
    ///
    /// A `Result` containing the `SerializableLog` if the operation succeeds or an error if it fails.
    async fn get_log(&self, block_number: u64, tx_index: u64, log_index: u64) -> Result<SerializableLog>;

    /// Retrieves multiple log entries from the database.
    ///
    /// # Arguments
    ///
    /// * `block_number` - An optional block number filter.
    /// * `block_offset` - An optional block offset filter.
    ///
    /// # Returns
    ///
    /// A `Result` containing a `Vec` of `SerializableLog` entries if the operation succeeds or an error if it fails.
    async fn get_logs<'a>(
        &'a self,
        block_number: Option<u64>,
        block_offset: Option<u64>,
    ) -> Result<Vec<SerializableLog>>;

    /// Retrieves the count of log entries from the database.
    ///
    /// # Arguments
    ///
    /// * `block_number` - An optional block number filter.
    /// * `block_offset` - An optional block offset filter.
    ///
    /// # Returns
    ///
    /// A `Result` containing the count of log entries if the operation succeeds or an error if it fails.
    async fn get_logs_count(&self, block_number: Option<u64>, block_offset: Option<u64>) -> Result<u64>;

    /// Retrieves block numbers of log entries from the database.
    ///
    /// # Arguments
    ///
    /// * `block_number` - An optional block number filter.
    /// * `block_offset` - An optional block offset filter.
    /// * `processed` - An optional processed filter.
    ///
    /// # Returns
    ///
    /// A `Result` containing a `Vec` of block numbers if the operation succeeds or an error if it fails.
    async fn get_logs_block_numbers<'a>(
        &'a self,
        block_number: Option<u64>,
        block_offset: Option<u64>,
        processed: Option<bool>,
    ) -> Result<Vec<u64>>;

    /// Marks a specific log entry as processed.
    ///
    /// # Arguments
    ///
    /// * `log` - The log entry to mark as processed, of type `SerializableLog`.
    ///
    /// # Returns
    ///
    /// A `Result` which is `Ok(())` if the operation succeeds or an error if it fails.
    async fn set_log_processed(&self, log: SerializableLog) -> Result<()>;

    /// Marks multiple log entries as processed.
    ///
    /// # Arguments
    ///
    /// * `block_number` - An optional block number filter.
    /// * `block_offset` - An optional block offset filter.
    ///
    /// # Returns
    ///
    /// A `Result` which is `Ok(())` if the operation succeeds or an error if it fails.
    async fn set_logs_processed(&self, block_number: Option<u64>, block_offset: Option<u64>) -> Result<()>;

    /// Marks multiple log entries as unprocessed.
    ///
    /// # Arguments
    ///
    /// * `block_number` - An optional block number filter.
    /// * `block_offset` - An optional block offset filter.
    ///
    /// # Returns
    ///
    /// A `Result` which is `Ok(())` if the operation succeeds or an error if it fails.
    async fn set_logs_unprocessed(&self, block_number: Option<u64>, block_offset: Option<u64>) -> Result<()>;

    /// Retrieves the last checksummed log entry from the database.
    ///
    /// # Returns
    ///
    /// A `Result` containing an `Option<SerializableLog>` if the operation succeeds or an error if it fails.
    async fn get_last_checksummed_log(&self) -> Result<Option<SerializableLog>>;

    /// Updates checksums for log entries in the database.
    ///
    /// # Returns
    ///
    /// A `Result` which is `Ok(Hash)` if the operation succeeds or an error if it fails.
    async fn update_logs_checksums(&self) -> Result<Hash>;
}