Skip to content

Commit

Permalink
Add contract event to database
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Oct 15, 2024
1 parent df047ad commit 8f8eecc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 10 additions & 13 deletions backend-rust/migrations/0001_initialize.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ CREATE TABLE contracts(
CREATE TABLE module_contract_link_events(
-- An index/id for this event (row number).
index
BIGINT
SERIAL
BIGSERIAL
PRIMARY KEY
NOT NULL,
-- Event index of the event.
Expand All @@ -338,18 +337,17 @@ CREATE TABLE module_contract_link_events(
-- True if contract gets linked to the given module, false if contract gets unlinked to the given module.
is_linked
BOOLEAN
NOT NULL,
NOT NULL

-- TODO: link_action = int? source = int?
)
);

-- Every successful event associated to a contract.
-- TODO: add index over the contract (index,subindex)
CREATE TABLE contract_events(
CREATE TABLE contract_events (
-- An index/id for this event (row number).
index
BIGINT
SERIAL
BIGSERIAL
PRIMARY KEY
NOT NULL,
-- Transaction index including the event.
Expand All @@ -367,18 +365,17 @@ CREATE TABLE contract_events(
-- Contract subindex that event is associated with.
contract_sub_index
BIGINT
NOT NULL,
NOT NULL

-- TODO: source = int?
)
);

-- Every rejected event associated to a contract.
-- TODO: add index over the contract (index,subindex)
CREATE TABLE contract_reject_events(
-- An index/id for this event (row number).
index
BIGINT
SERIAL
BIGSERIAL
PRIMARY KEY
NOT NULL,
-- Transaction index including the event.
Expand All @@ -396,10 +393,10 @@ CREATE TABLE contract_reject_events(
-- Contract subindex that event is associated with.
contract_sub_index
BIGINT
NOT NULL,
NOT NULL

-- TODO: source = int?
)
);

CREATE OR REPLACE FUNCTION block_added_notify_trigger_function() RETURNS trigger AS $trigger$
DECLARE
Expand Down
20 changes: 20 additions & 0 deletions backend-rust/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,26 @@ impl PreparedContractInitialized {
)
.execute(tx.as_mut())
.await?;

// TODO: fix event index.
sqlx::query!(
r#"INSERT INTO contract_events (
transaction_index,
event_index,
contract_index,
contract_sub_index
)
VALUES (
$1, $2, $3, $4
)"#,
self.tx_index,
0i64,
self.index,
self.sub_index
)
.execute(tx.as_mut())
.await?;

Ok(())
}
}

0 comments on commit 8f8eecc

Please sign in to comment.