Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2475 from bandprotocol/related-os-ds
Browse files Browse the repository at this point in the history
cdb: Related data source and oracle script
  • Loading branch information
Benzbeeb authored Aug 19, 2020
2 parents a1f32e5 + 7ca900e commit 5136aa7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

### Emitter & Flusher

- (impv) [\#2475](https://github.com/bandprotocol/bandchain/pull/2475) Add related data source and oracle script table.
- (impv) [\#2450](https://github.com/bandprotocol/bandchain/pull/2450) Add request count 1day view table.

### Scan
Expand Down
7 changes: 7 additions & 0 deletions flusher/flusher/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,10 @@ def Column(*args, **kwargs):
Column("answer", CustomVoteOption),
Column("tx_id", sa.Integer, sa.ForeignKey("transactions.id")),
)

related_data_source_oracle_scripts = sa.Table(
"related_data_source_oracle_scripts",
metadata,
Column("data_source_id", sa.Integer, sa.ForeignKey("data_sources.id"), primary_key=True),
Column("oracle_script_id", sa.Integer, sa.ForeignKey("oracle_scripts.id"), primary_key=True),
)
16 changes: 16 additions & 0 deletions flusher/flusher/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
proposals,
deposits,
votes,
related_data_source_oracle_scripts,
)


Expand Down Expand Up @@ -103,7 +104,22 @@ def handle_update_request(self, msg):
condition = (col == msg[col.name]) & condition
self.conn.execute(requests.update().where(condition).values(**msg))

def handle_update_related_ds_os(self, msg):
self.conn.execute(
insert(related_data_source_oracle_scripts)
.values(**msg)
.on_conflict_do_nothing(constraint="related_data_source_oracle_scripts_pkey")
)

def handle_new_raw_request(self, msg):
self.handle_update_related_ds_os(
{
"oracle_script_id": self.conn.execute(
select([requests.c.oracle_script_id]).where(accounts.c.id == msg["request_id"])
).scalar(),
"data_source_id": msg["data_source_id"],
}
)
self.conn.execute(raw_requests.insert(), msg)

def handle_new_val_request(self, msg):
Expand Down

0 comments on commit 5136aa7

Please sign in to comment.