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

cdb: Handle all resolve proposal status #2246

Merged
merged 5 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

### Emitter & Flusher

- (feat) [\#2246](https://github.com/bandprotocol/bandchain/pull/2246) Implement handle all resolve proposal status.
- (feat) [\#2242](https://github.com/bandprotocol/bandchain/pull/2242) Implement handle MsgVote for emitter and flusher.
- (feat) [\#2241](https://github.com/bandprotocol/bandchain/pull/2241) Implement handle MsgDeposit for emitter and flusher.
- (impv) [\#2240](https://github.com/bandprotocol/bandchain/pull/2240) Emit Kafka msg for staking genesis state.
Expand Down
7 changes: 7 additions & 0 deletions chain/emitter/bank.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package emitter

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank"
)

Expand All @@ -19,3 +20,9 @@ func (app *App) handleMsgMultiSend(
app.AddAccountsInTx(output.Address)
}
}

func (app *App) handleEventTypeTransfer(evMap EvMap) {
if recipient, err := sdk.AccAddressFromBech32(evMap[bank.EventTypeTransfer+"."+bank.AttributeKeyRecipient][0]); err == nil {
app.AddAccountsInBlock(recipient)
}
}
22 changes: 22 additions & 0 deletions chain/emitter/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov/types"
)

var (
EventTypeInactiveProposal = types.EventTypeInactiveProposal
EventTypeActiveProposal = types.EventTypeActiveProposal
StatusInactive = 6
)

func (app *App) emitSetDeposit(txHash []byte, id uint64, depositor sdk.AccAddress) {
deposit, _ := app.GovKeeper.GetDeposit(app.DeliverContext, id, depositor)
app.Write("SET_DEPOSIT", JsDict{
Expand Down Expand Up @@ -69,3 +75,19 @@ func (app *App) handleMsgVote(
"tx_hash": txHash,
})
}

func (app *App) handleEventInactiveProposal(evMap EvMap) {
app.Write("UPDATE_PROPOSAL", JsDict{
"id": atoi(evMap[types.EventTypeInactiveProposal+"."+types.AttributeKeyProposalID][0]),
"status": StatusInactive,
})
}

func (app *App) handleEventTypeActiveProposal(evMap EvMap) {
id := uint64(atoi(evMap[types.EventTypeActiveProposal+"."+types.AttributeKeyProposalID][0]))
proposal, _ := app.GovKeeper.GetProposal(app.DeliverContext, id)
app.Write("UPDATE_PROPOSAL", JsDict{
"id": id,
"status": int(proposal.Status),
})
}
6 changes: 6 additions & 0 deletions chain/emitter/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func (app *App) handleBeginBlockEndBlockEvent(event abci.Event) {
app.handleEventDeactivate(evMap)
case EventTypeCompleteUnbonding:
app.handleEventTypeCompleteUnbonding(evMap)
case EventTypeInactiveProposal:
app.handleEventInactiveProposal(evMap)
case EventTypeActiveProposal:
app.handleEventTypeActiveProposal(evMap)
case bank.EventTypeTransfer:
app.handleEventTypeTransfer(evMap)
default:
break
}
Expand Down
1 change: 1 addition & 0 deletions flusher/flusher/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ProposalStatus(enum.Enum):
Passed = 3
Rejected = 4
Failed = 5
Inactive = 6


class VoteOption(enum.Enum):
Expand Down
15 changes: 9 additions & 6 deletions flusher/flusher/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ def handle_new_transaction(self, msg):
)

def handle_set_account(self, msg):
self.conn.execute(
insert(accounts)
.values(**msg)
.on_conflict_do_update(index_elements=[accounts.c.address], set_=msg)
)
id = self.get_account_id(msg["address"])
if id is None:
self.conn.execute(accounts.insert(), msg)
else:
condition = True
for col in accounts.primary_key.columns.values():
condition = (col == msg[col.name]) & condition
self.conn.execute(accounts.update().where(condition).values(**msg))

def handle_set_data_source(self, msg):
if msg["tx_hash"] is not None:
Expand Down Expand Up @@ -201,7 +204,7 @@ def handle_set_vote(self, msg):
self.conn.execute(
insert(votes).values(**msg).on_conflict_do_update(constraint="votes_pkey", set_=msg)
)

def handle_update_proposal(self, msg):
condition = True
for col in proposals.primary_key.columns.values():
Expand Down