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 #2219 from bandprotocol/add-delegation
Browse files Browse the repository at this point in the history
cdb: Add delegation row in create validator handler
  • Loading branch information
taobun authored Jul 13, 2020
2 parents 64e6853 + 4a0cec4 commit 961f0e1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

### Emitter & Flusher

- (bugs) [\#2219](https://github.com/bandprotocol/bandchain/pull/2219) Add delegation row in create validator handler.
- (bugs) [\#2222](https://github.com/bandprotocol/bandchain/pull/2222) Fix account_transactions table name
- (impv) [\#2196](https://github.com/bandprotocol/bandchain/pull/2196) Fix create view table command
- (impv) [\#2186](https://github.com/bandprotocol/bandchain/pull/2186) Add temporary view tables.
Expand Down
4 changes: 2 additions & 2 deletions chain/emitter/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ func (app *App) InitChain(req abci.RequestInitChain) abci.ResponseInitChain {
var tx auth.StdTx
app.Codec().MustUnmarshalJSON(genTx, &tx)
for _, msg := range tx.Msgs {
if createMsg, ok := msg.(staking.MsgCreateValidator); ok {
app.emitSetValidator(createMsg.ValidatorAddress)
if msg, ok := msg.(staking.MsgCreateValidator); ok {
app.handleMsgCreateValidator(nil, msg, nil, nil)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions chain/emitter/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ func (app *App) emitUpdateValidatorStatus(addr sdk.ValAddress) {
func (app *App) emitDelegation(operatorAddress sdk.ValAddress, delegatorAddress sdk.AccAddress) {
delegation, found := app.StakingKeeper.GetDelegation(app.DeliverContext, delegatorAddress, operatorAddress)
if found {
info := app.DistrKeeper.GetDelegatorStartingInfo(app.DeliverContext, operatorAddress, delegatorAddress)
latestReward := app.DistrKeeper.GetValidatorHistoricalRewards(app.DeliverContext, operatorAddress, info.PreviousPeriod)
_, ratio := app.getCurrentRewardAndCurrentRatio(operatorAddress)
app.Write("SET_DELEGATION", JsDict{
"delegator_address": delegatorAddress,
"operator_address": operatorAddress,
"shares": delegation.Shares.String(),
"last_ratio": latestReward.CumulativeRewardRatio[0].Amount.String(),
"last_ratio": ratio,
})
} else {
app.Write("REMOVE_DELEGATION", JsDict{
Expand All @@ -80,6 +79,7 @@ func (app *App) handleMsgCreateValidator(
txHash []byte, msg staking.MsgCreateValidator, evMap EvMap, extra JsDict,
) {
app.emitSetValidator(msg.ValidatorAddress)
app.emitDelegation(msg.ValidatorAddress, msg.DelegatorAddress)
}

// handleMsgEditValidator implements emitter handler for MsgEditValidator.
Expand Down

0 comments on commit 961f0e1

Please sign in to comment.