Files
planetmint-go/x/dao/keeper/msg_server_distribution_request.go
Jürgen Eckel a982abecf5 Distribute assets (#162)
* distributed & result msgs
* added DistributionResult
* added RDDL token conversion methods
* set proper validatoraddress within the testcases for e2e/dao
* set proper root dir for test cases
* fixed some wordings
---------

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
2023-11-15 13:31:20 +01:00

44 lines
1.7 KiB
Go

package keeper
import (
"context"
"strconv"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/util"
"github.com/planetmint/planetmint-go/x/dao/types"
)
func (k msgServer) DistributionRequest(goCtx context.Context, msg *types.MsgDistributionRequest) (*types.MsgDistributionRequestResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
validatorIdentity, validResult := util.GetValidatorCometBFTIdentity(ctx)
if validResult && msg.Distribution.GetProposer() == validatorIdentity {
// issue three distributions:
investorTx, err := util.DistributeAsset(msg.Distribution.InvestorAddr, msg.Distribution.InvestorAmount)
if err != nil {
ctx.Logger().Error("Distribution Request: could not distribute asset to Investors: ", err.Error())
}
popTx, err := util.DistributeAsset(msg.Distribution.PopAddr, msg.Distribution.PopAmount)
if err != nil {
ctx.Logger().Error("Distribution Request: could not distribute asset to PoP: ", err.Error())
}
daoTx, err := util.DistributeAsset(msg.Distribution.DaoAddr, msg.Distribution.DaoAmount)
if err != nil {
ctx.Logger().Error("Distribution Request: could not distribute asset to DAO: ", err.Error())
}
msg.Distribution.InvestorTxID = investorTx
msg.Distribution.PopTxID = popTx
msg.Distribution.DaoTxID = daoTx
lastPopString := strconv.FormatInt(msg.Distribution.LastPop, 10)
err = util.SendRDDLDistributionResult(ctx, lastPopString, daoTx, investorTx, popTx)
if err != nil {
ctx.Logger().Error("Distribution Request: could not send distribution result ", err.Error())
}
}
k.StoreDistributionOrder(ctx, *msg.GetDistribution())
return &types.MsgDistributionRequestResponse{}, nil
}