Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tables, emitter, flusher for group module #322

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,13 @@ func NewBandApp(
app.MintKeeper,
app.DistrKeeper,
app.GovKeeper,
app.GroupKeeper,
app.OracleKeeper,
app.ICAHostKeeper,
app.IBCKeeper.ClientKeeper,
app.IBCKeeper.ConnectionKeeper,
app.IBCKeeper.ChannelKeeper,
keys[group.StoreKey],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need to add just use storekey of group module directly?

Copy link
Contributor

@colmazia colmazia Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function that query proposal by voting period end is private so I have to use the storekey to query

emitterFlag,
false,
))
Expand Down
72 changes: 72 additions & 0 deletions flusher/flusher/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,78 @@ def Column(*args, **kwargs):
Column("last_update", CustomDateTime, index=True),
)


"""
This section is mainly for tables of Group module
"""

groups = sa.Table(
"groups",
metadata,
Column("id", sa.Integer, primary_key=True),
Column("version", sa.Integer, index=True),
Column("admin", sa.String, sa.ForeignKey("accounts.address")),
Column("metadata", sa.String),
Column("total_weight", sa.BigInteger),
Column("created_at", CustomDateTime),
)

group_members = sa.Table(
"group_members",
metadata,
Column("group_id", sa.Integer, sa.ForeignKey("groups.id"), primary_key=True),
Column("account_id", sa.Integer, sa.ForeignKey("accounts.id"), primary_key=True),
Column("weight", sa.BigInteger),
Column("metadata", sa.String),
Column("added_at", CustomDateTime),
)

group_policies = sa.Table(
"group_policies",
metadata,
Column("address", sa.String, primary_key=True),
Column("type", sa.String),
Column("group_id", sa.Integer, sa.ForeignKey("groups.id")),
Column("admin", sa.String, sa.ForeignKey("accounts.address")),
Column("metadata", sa.String),
Column("version", sa.Integer),
Column("decision_policy", sa.JSON),
Column("created_at", CustomDateTime),
)

group_proposals = sa.Table(
"group_proposals",
metadata,
Column("id", sa.Integer, primary_key=True),
Column("group_policy_address", sa.String, sa.ForeignKey("group_policies.address")),
Column("metadata", sa.String),
Column("proposers", sa.String),
Column("submit_time", CustomDateTime),
Column("group_id", sa.Integer, sa.ForeignKey("groups.id")),
Column("group_version", sa.Integer, index=True),
Column("group_policy_version", sa.Integer, index=True),
Column("status", sa.String),
Column("yes_vote", sa.BigInteger, nullable=True),
Column("no_vote", sa.BigInteger, nullable=True),
Column("no_with_veto_vote", sa.BigInteger, nullable=True),
Column("abstain_vote", sa.BigInteger, nullable=True),
Column("voting_period_end", CustomDateTime),
Column("executor_result", sa.String),
Column("messages", sa.JSON),
Column("title", sa.String),
Column("summary", sa.String),
)

group_votes = sa.Table(
"group_votes",
metadata,
Column("group_proposal_id", sa.Integer, sa.ForeignKey("group_proposals.id"), primary_key=True),
Column("voter_id", sa.Integer, sa.ForeignKey("accounts.id"), primary_key=True),
Column("option", sa.String),
Column("metadata", sa.String),
Column("submit_time", CustomDateTime),
)

relayer_tx_stat_days = sa.Table(
"relayer_tx_stat_days",
metadata,
Expand Down
49 changes: 49 additions & 0 deletions flusher/flusher/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
counterparty_chains,
connections,
channels,
groups,
group_members,
group_policies,
group_proposals,
group_votes,
relayer_tx_stat_days,
)

Expand Down Expand Up @@ -85,6 +90,9 @@ def get_data_source_id(self, id):
def get_oracle_script_id(self, id):
return self.conn.execute(select([oracle_scripts.c.id]).where(oracle_scripts.c.id == id)).scalar()

def get_group_id_from_policy_address(self, address):
return self.conn.execute(select([group_policies.c.group_id]).where(group_policies.c.address == address)).scalar()

def get_ibc_received_txs(self, date, port, channel, address):
msg = {"date": date, "port": port, "channel": channel, "address": address}
condition = True
Expand Down Expand Up @@ -140,6 +148,47 @@ def handle_new_data_source(self, msg):
self.conn.execute(data_sources.insert(), msg)
self.init_data_source_request_count(msg["id"])

def handle_new_group(self, msg):
self.conn.execute(groups.insert(), msg)

def handle_new_group_member(self, msg):
msg["account_id"] = self.get_account_id(msg["address"])
del msg["address"]
self.conn.execute(group_members.insert(), msg)

def handle_new_group_policy(self, msg):
self.get_account_id(msg["address"])
self.conn.execute(group_policies.insert(), msg)

def handle_new_group_proposal(self, msg):
msg["group_id"] = self.get_group_id_from_policy_address(msg["group_policy_address"])
self.conn.execute(group_proposals.insert(), msg)

def handle_new_group_vote(self, msg):
msg["voter_id"] = self.get_account_id(msg["voter_address"])
del msg["voter_address"]
self.conn.execute(group_votes.insert(), msg)

def handle_update_group(self, msg):
self.conn.execute(groups.update().where(groups.c.id == msg["id"]).values(**msg))

def handle_remove_group_member(self, msg):
account_id = self.get_account_id(msg["address"])
self.conn.execute(group_members.delete().where((group_members.c.group_id == msg["group_id"]) & (group_members.c.account_id == account_id)))

def handle_remove_group_members_by_group_id(self, msg):
self.conn.execute(group_members.delete().where(group_members.c.group_id == msg["group_id"]))

def handle_update_group_policy(self, msg):
self.conn.execute(group_policies.update().where(group_policies.c.address == msg["address"]).values(**msg))

def handle_update_group_proposal(self, msg):
msg["group_id"] = self.get_group_id_from_policy_address(msg["group_policy_address"])
self.conn.execute(group_proposals.update().where(group_proposals.c.id == msg["id"]).values(**msg))

def handle_update_group_proposal_by_id(self, msg):
self.conn.execute(group_proposals.update().where(group_proposals.c.id == msg["id"]).values(**msg))

def handle_set_data_source(self, msg):
msg["transaction_id"] = self.get_transaction_id(msg["tx_hash"])
del msg["tx_hash"]
Expand Down
120 changes: 120 additions & 0 deletions hasura/hasura-metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,34 @@
table:
name: deposits
schema: public
- name: group_members
using:
foreign_key_constraint_on:
column: account_id
colmazia marked this conversation as resolved.
Show resolved Hide resolved
table:
name: group_members
schema: public
- name: group_policies
using:
foreign_key_constraint_on:
column: admin
colmazia marked this conversation as resolved.
Show resolved Hide resolved
table:
name: group_policies
schema: public
- name: group_votes
using:
foreign_key_constraint_on:
column: voter_id
RogerKSI marked this conversation as resolved.
Show resolved Hide resolved
table:
name: group_votes
schema: public
- name: groups
using:
foreign_key_constraint_on:
column: admin
table:
name: groups
schema: public
- name: proposals
using:
foreign_key_constraint_on:
Expand Down Expand Up @@ -290,6 +318,98 @@
- name: transaction
using:
foreign_key_constraint_on: tx_id
- table:
name: group_members
schema: public
object_relationships:
- name: account
using:
foreign_key_constraint_on: account_id
- name: group
using:
foreign_key_constraint_on: group_id
- table:
name: group_policies
schema: public
object_relationships:
- name: account
using:
foreign_key_constraint_on: admin
- name: group
using:
foreign_key_constraint_on: group_id
array_relationships:
- name: group_proposals
using:
foreign_key_constraint_on:
column: group_policy_address
table:
name: group_proposals
schema: public
- table:
name: group_proposals
schema: public
object_relationships:
- name: group
using:
foreign_key_constraint_on: group_id
- name: group_policy
using:
foreign_key_constraint_on: group_policy_address
- name: group_vote
using:
foreign_key_constraint_on:
column: group_proposal_id
table:
name: group_votes
schema: public
array_relationships:
- name: group_votes
using:
foreign_key_constraint_on:
column: group_proposal_id
table:
name: group_votes
schema: public
- table:
name: group_votes
schema: public
object_relationships:
- name: account
using:
foreign_key_constraint_on: voter_id
- name: group_proposal
using:
foreign_key_constraint_on: group_proposal_id
- table:
name: groups
schema: public
object_relationships:
- name: account
using:
foreign_key_constraint_on: admin
array_relationships:
- name: group_members
using:
foreign_key_constraint_on:
column: group_id
table:
name: group_members
schema: public
- name: group_policies
using:
foreign_key_constraint_on:
column: group_id
table:
name: group_policies
schema: public
- name: group_proposals
using:
foreign_key_constraint_on:
column: group_id
table:
name: group_proposals
schema: public
- table:
name: historical_bonded_token_on_validators
schema: public
Expand Down
Loading
Loading