mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-09-14 12:20:10 +00:00

* refactor: improve logging - Introduce logger tags - Log variable contents - Fix testing logger to support string formatting * refactor: set logging context And move logging into function. Signed-off-by: Julian Strobl <jmastr@mailbox.org>
58 lines
2.3 KiB
Go
58 lines
2.3 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)
|
|
if validResult && msg.Distribution.GetProposer() == validatorIdentity {
|
|
util.GetAppLogger().Info(ctx, distributionRequestTag+"entering asset distribution mode")
|
|
// issue three distributions:
|
|
investorTx, err := util.DistributeAsset(msg.Distribution.InvestorAddr, msg.Distribution.InvestorAmount)
|
|
if err != nil {
|
|
util.GetAppLogger().Error(ctx, distributionRequestTag+"could not distribute asset to Investors: ", err.Error())
|
|
}
|
|
popTx, err := util.DistributeAsset(msg.Distribution.PopAddr, msg.Distribution.PopAmount)
|
|
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)
|
|
if err != nil {
|
|
util.GetAppLogger().Error(ctx, distributionRequestTag+"could not distribute asset to DAO: ", err.Error())
|
|
}
|
|
|
|
msg.Distribution.InvestorTxID = investorTx
|
|
msg.Distribution.PopTxID = popTx
|
|
msg.Distribution.DaoTxID = daoTx
|
|
util.SendDistributionResult(goCtx, msg.Distribution.LastPop, daoTx, investorTx, popTx)
|
|
} else {
|
|
util.GetAppLogger().Error(ctx, distributionRequestTag+"failed. valid result: %v proposer: %s validator identity: %s", validResult, msg.Distribution.GetProposer(), validatorIdentity)
|
|
}
|
|
|
|
return &types.MsgDistributionRequestResponse{}, nil
|
|
}
|