mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-27 07:48:29 +00:00
* [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>
60 lines
1.8 KiB
Go
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)
|
|
}
|