planetmint-go/x/dao/abci.go
Julian Strobl 5b25d4cefc
Improve linter setup (#186)
* [linter] Add `musttag`

Enforce field tags in (un)marshaled structs.

* [linter] Add `nestif`

Reports deeply nested if statements.

* [linter] Add `noctx`

Finds sending http request without context.Context.

* [linter] Add `paralleltest`

Paralleltest detects missing usage of t.Parallel() method in your Go
test.

* [linter] Add `tagalign`

Check that struct tags are well aligned.

* [linter] Add `tagliatelle`

Checks the struct tags.

* [linter] Add `whitespace`

Tool for detection of leading and trailing whitespace.

* [paralleltest] Exclude files bc of data race in tests

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
2023-11-17 10:56:25 +01:00

60 lines
1.8 KiB
Go

package dao
import (
"encoding/hex"
"github.com/planetmint/planetmint-go/config"
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/dao/keeper"
abci "github.com/cometbft/cometbft/abci/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) {
logger := ctx.Logger()
proposerAddress := req.Header.GetProposerAddress()
// Check if node is block proposer
// take the following actions only once, that's why we filter for the Block Proposer
if !util.IsValidatorBlockProposer(ctx, proposerAddress) {
return
}
blockHeight := req.Header.GetHeight()
if isPoPHeight(blockHeight) {
logger.Debug("TODO: implement PoP trigger")
hexProposerAddress := hex.EncodeToString(proposerAddress)
conf := config.GetConfig()
txUnsigned := keeper.GetReissuanceCommand(conf.ReissuanceAsset, blockHeight)
err := util.InitRDDLReissuanceProcess(ctx, hexProposerAddress, txUnsigned, blockHeight)
if err != nil {
logger.Error("error while initializing RDDL issuance", err)
}
}
if isDistributionHeight(blockHeight) {
// initialize the distribution message
distribution, err := k.GetDistributionForReissuedTokens(ctx, blockHeight)
if err != nil {
logger.Error("error while computing the RDDL distribution ", err)
}
err = util.SendRDDLDistributionRequest(ctx, distribution)
if err != nil {
logger.Error("sending the distribution request failed")
}
}
}
func isPoPHeight(height int64) bool {
cfg := config.GetConfig()
return height%int64(cfg.PoPEpochs) == 0
}
func isDistributionHeight(height int64) bool {
cfg := config.GetConfig()
return height%int64(cfg.DistributionEpochs) == 0
}
func EndBlocker(ctx sdk.Context, _ abci.RequestEndBlock, k keeper.Keeper) {
k.DistributeCollectedFees(ctx)
}