Skip to content

Commit

Permalink
feat: updates to proposals table
Browse files Browse the repository at this point in the history
  • Loading branch information
wgwz committed Jul 11, 2023
1 parent 70b21af commit 2a652d9
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 21 deletions.
78 changes: 63 additions & 15 deletions index_proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def fetch_proposal(height, proposal_id):
headers={"x-cosmos-block-height": str(height)},
)
resp.raise_for_status()
return resp.json()
return resp.json()["proposal"]


def _index_proposals(pg_conn, _client, _chain_num):
Expand All @@ -34,24 +34,72 @@ def _index_proposals(pg_conn, _client, _chain_num):
(_, _, _, _, key, value, _, _) = entry
value = value.strip('"')
normalize[key] = value
normalize["metadata"] = fetch_proposal(
proposal = fetch_proposal(
normalize["block_height"] - 1, normalize["proposal_id"]
)
row = (
normalize["type"],
normalize["block_height"],
normalize["tx_idx"],
normalize["msg_idx"],
normalize["chain_num"],
normalize["timestamp"],
proposal["id"],
proposal["status"],
proposal["group_policy_address"],
proposal["metadata"],
proposal["proposers"],
proposal["submit_time"],
proposal["group_version"],
proposal["group_policy_version"],
Json(proposal["final_tally_result"]),
proposal["voting_period_end"],
proposal["executor_result"],
Json(proposal["messages"]),
)
insert_text = textwrap.dedent("""
INSERT INTO proposals (
type,
block_height,
tx_idx,
msg_idx,
chain_num,
timestamp,
proposal_id,
status,
group_policy_address,
metadata,
proposers,
submit_time,
group_version,
group_policy_version,
final_tally_result,
voting_period_end,
executor_result,
messages
) VALUES (
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s,
%s
);""").strip("\n")
with pg_conn.cursor() as _cur:
row = (
normalize["type"],
normalize["proposal_id"],
normalize["status"],
normalize["tally_result"],
normalize["timestamp"],
normalize["block_height"],
normalize["chain_num"],
normalize["tx_idx"],
normalize["msg_idx"],
Json(normalize["metadata"]),
)
_cur.execute(
"INSERT INTO proposals (type, proposal_id, status, tally_result, timestamp, block_height, chain_num, tx_idx, msg_idx, metadata) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
insert_text,
row,
)
logger.debug(_cur.statusmessage)
Expand Down
22 changes: 16 additions & 6 deletions sql/V1_5__add_proposals_table.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
CREATE TABLE IF NOT EXISTS
proposals (
TYPE TEXT NOT NULL,
proposal_id BIGINT NOT NULL,
status TEXT NOT NULL,
tally_result JSONB NOT NULL,
metadata JSONB NOT NULL,
TIMESTAMP timestamptz,
block_height BIGINT NOT NULL,
chain_num SMALLINT NOT NULL,
tx_idx SMALLINT NOT NULL,
msg_idx SMALLINT NOT NULL,
chain_num SMALLINT NOT NULL,
TIMESTAMP timestamptz,

proposal_id BIGINT NOT NULL,
status TEXT NOT NULL,
group_policy_address TEXT NOT NULL,
metadata TEXT NOT NULL,
proposers TEXT[] NOT NULL,
submit_time timestamptz,
group_version BIGINT NOT NULL,
group_policy_version BIGINT NOT NULL,
final_tally_result JSONB NOT NULL,
voting_period_end timestamptz NOT NULL,
executor_result TEXT NOT NULL,
messages JSONB NOT NULL,

PRIMARY KEY (
chain_num,
block_height,
Expand Down

0 comments on commit 2a652d9

Please sign in to comment.