planetmint-go/x/dao/keeper/msg_server_distribution_request.go
Jürgen Eckel 4f5b1e5777
Multi validator setup in test cases (#333)
* Initializing rootDir of dao and machine keeper with the home path of the validator key material
* added Block height logging of context decorator
* removed SetRoot usage
* fixed data races of the attest machine go-routine
* reproduction of the issue
* fixed testing URL issue
* refactored the machine-nft functions/mock
* fixed keeper.param read-bug that increased the gas prices in an inconsistent way
* increased the validator number to 3 for all e2e tests
* added go routine to attest machine workflow

---------

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
Co-authored-by: Julian Strobl <jmastr@mailbox.org>
Co-authored-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
2024-03-05 11:37:01 +01:00

65 lines
2.8 KiB
Go

package keeper
import (
"context"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/dao/types"
)
var (
distributionRequestTag = "distribution request: "
)
func (k msgServer) DistributionRequest(goCtx context.Context, msg *types.MsgDistributionRequest) (*types.MsgDistributionRequestResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
lastReissuance, found := k.GetLastReissuance(ctx)
if !found {
return nil, errorsmod.Wrap(types.ErrReissuanceNotFound, "for last reissuance height")
}
if lastReissuance.TxID == "" {
return nil, errorsmod.Wrap(types.ErrReissuanceTxIDMissing, "for last reissuance height")
}
util.GetAppLogger().Info(ctx, distributionRequestTag+"storing distribution: "+msg.GetDistribution().String())
k.StoreDistributionOrder(ctx, *msg.GetDistribution())
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx, k.RootDir)
if !validResult || msg.Distribution.GetProposer() != validatorIdentity {
util.GetAppLogger().Info(ctx, distributionRequestTag+"Not the proposer. valid result: %t proposer: %s validator identity: %s", validResult, msg.Distribution.GetProposer(), validatorIdentity)
return &types.MsgDistributionRequestResponse{}, nil
}
reissuanceAsset := k.GetParams(ctx).ReissuanceAsset
util.GetAppLogger().Info(ctx, distributionRequestTag+"entering asset distribution mode")
// issue 5 distributions:
earlyInvestorTx, err := util.DistributeAsset(msg.Distribution.EarlyInvAddr, msg.Distribution.EarlyInvAmount, reissuanceAsset)
if err != nil {
util.GetAppLogger().Error(ctx, distributionRequestTag+"could not distribute asset to early investors: "+err.Error())
}
investorTx, err := util.DistributeAsset(msg.Distribution.InvestorAddr, msg.Distribution.InvestorAmount, reissuanceAsset)
if err != nil {
util.GetAppLogger().Error(ctx, distributionRequestTag+"could not distribute asset to investors: "+err.Error())
}
strategicTx, err := util.DistributeAsset(msg.Distribution.StrategicAddr, msg.Distribution.StrategicAmount, reissuanceAsset)
if err != nil {
util.GetAppLogger().Error(ctx, distributionRequestTag+"could not distribute asset to strategic investments: "+err.Error())
}
popTx, err := util.DistributeAsset(msg.Distribution.PopAddr, msg.Distribution.PopAmount, reissuanceAsset)
if err != nil {
util.GetAppLogger().Error(ctx, distributionRequestTag+"could not distribute asset to PoP: "+err.Error())
}
daoTx, err := util.DistributeAsset(msg.Distribution.DaoAddr, msg.Distribution.DaoAmount, reissuanceAsset)
if err != nil {
util.GetAppLogger().Error(ctx, distributionRequestTag+"could not distribute asset to DAO: "+err.Error())
}
util.SendDistributionResult(goCtx, msg.Distribution.LastPop, daoTx, investorTx, popTx, earlyInvestorTx, strategicTx)
return &types.MsgDistributionRequestResponse{}, nil
}