Skip to content

Commit c273929

Browse files
committed
add handler for job_revise_rate_cancelled
1 parent 219c1d1 commit c273929

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

contracts/indexer/oyster/evm/src/handlers/job_closed.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ mod tests {
256256
))
257257
);
258258

259+
assert_eq!(rate_revisions::table.count().get_result(conn), Ok(0));
260+
259261
// log under test
260262
let log = Log {
261263
block_hash: Some(keccak256!("some block").into()),
@@ -839,6 +841,8 @@ mod tests {
839841
])
840842
);
841843

844+
assert_eq!(rate_revisions::table.count().get_result(conn), Ok(0));
845+
842846
// log under test
843847
let log = Log {
844848
block_hash: Some(keccak256!("some block").into()),
Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
1+
use alloy::hex::ToHexExt;
12
use alloy::rpc::types::Log;
2-
use anyhow::Result;
3-
use diesel::PgConnection;
3+
use anyhow::{Context, Result};
4+
use diesel::{ExpressionMethods, PgConnection, RunQueryDsl};
5+
use indexer_framework::schema::revise_rate_requests;
46
use tracing::warn;
57
use tracing::{info, instrument};
68

79
#[instrument(level = "info", skip_all, parent = None, fields(block = log.block_number, idx = log.log_index))]
8-
pub fn handle_job_revise_rate_cancelled(_conn: &mut PgConnection, log: Log) -> Result<()> {
10+
pub fn handle_job_revise_rate_cancelled(conn: &mut PgConnection, log: Log) -> Result<()> {
911
info!(?log, "processing");
1012

11-
// while we do have enough context here to handle this properly,
12-
// JobClosed makes us handle LockDeleted
13-
// which also more or less handles this
13+
let id = log.topics()[1].encode_hex_with_prefix();
1414

15-
info!("empty impl, supposed to be handled by LockDeleted");
15+
info!(id, "cancelling job rate revision");
16+
17+
// target sql:
18+
// DELETE FROM revise_rate_requests
19+
// WHERE id = "<id>";
20+
let count = diesel::delete(revise_rate_requests::table)
21+
.filter(revise_rate_requests::id.eq(&id))
22+
.execute(conn)
23+
.context("failed to delete revise rate request")?;
24+
25+
if count != 1 {
26+
// !!! should never happen
27+
// the only real condition is when the request does not exist or is already deleted
28+
// it is not a critical error, we can just move on
29+
warn!("did not expect to find a non existent request when cancelling job rate revision");
30+
}
31+
32+
info!(id, "deleted revise rate request");
1633

1734
Ok(())
1835
}
36+
37+
// TODO: add tests

0 commit comments

Comments
 (0)