planetmint-go/util/issue_commands.go
Lorenz Herzberger 94830df5fc
184 implement staged claim (#190)
* adjust issuePoPRewards to mint stagedCRDDL
* add GetChallengeRange
* add resolveStagedClaims on ReissueRDDLResult msg
* move claim resolve to distribution result
* add StagedDenom and ClaimDenom to config
* added the prepare4linting.sh script
* renamed PoPEpochs to PopEpochs
* renamed DistributionAddressPoP to DistributionAddressPop
* added config value ReIssuanceEpochs
* detached the re-issuance from the distribution process and schedule them independently
* changed logging messages
* added an explicit util/kv_serialize.go file to have all KV serialization done
* switched to Bigendian serialization of int64 to have the ordered list on the kvstore
* added ComputeReIssuanceValue to enable re-issuances once a day or defined by ReIssuanceEpoch
* integrated a ReIssuanceValue computation test case
* adjusted the challenges test cases to be epoch-dependent
* added ReIssuances per ReIssuanceEpoch
* extended the Reissue message
* checking ReIssuanceProposal in the ante handler
* added precision setter for the UINT to RDDL token converter (and test cases)
* add e2e test case for pop rewards


Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
Co-authored-by: Jürgen Eckel <juergen@riddleandcode.com>
2023-12-05 10:51:06 +01:00

94 lines
4.1 KiB
Go

package util
import (
"context"
"strconv"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/config"
"github.com/planetmint/planetmint-go/lib"
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
)
func setRPCConfig(goCtx context.Context) {
rpcConf := lib.GetConfig()
ctx := sdk.UnwrapSDKContext(goCtx)
rpcConf.SetChainID(ctx.ChainID())
}
func buildSignBroadcastTx(goCtx context.Context, loggingContext string, sendingValidatorAddress string, msg sdk.Msg) {
go func() {
setRPCConfig(goCtx)
ctx := sdk.UnwrapSDKContext(goCtx)
addr := sdk.MustAccAddressFromBech32(sendingValidatorAddress)
txJSON, err := lib.BuildUnsignedTx(addr, msg)
if err != nil {
GetAppLogger().Error(ctx, loggingContext+" build unsigned tx failed: "+err.Error())
return
}
GetAppLogger().Info(ctx, loggingContext+" unsigned tx: "+txJSON)
_, err = lib.BroadcastTxWithFileLock(addr, msg)
if err != nil {
GetAppLogger().Error(ctx, loggingContext+" broadcast tx failed: "+err.Error())
return
}
GetAppLogger().Info(ctx, loggingContext+" broadcast tx succeeded")
}()
}
func SendInitReissuance(goCtx context.Context, proposerAddress string, txUnsigned string, blockHeight int64,
firstIncludedPop int64, lastIncludedPop int64) {
ctx := sdk.UnwrapSDKContext(goCtx)
// get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store
sendingValidatorAddress := config.GetConfig().ValidatorAddress
GetAppLogger().Info(ctx, "create re-issuance proposal")
msg := daotypes.NewMsgReissueRDDLProposal(sendingValidatorAddress, proposerAddress, txUnsigned, blockHeight,
firstIncludedPop, lastIncludedPop)
buildSignBroadcastTx(goCtx, "initializing RDDL re-issuance", sendingValidatorAddress, msg)
}
func SendReissuanceResult(goCtx context.Context, proposerAddress string, txID string, blockHeight int64) {
ctx := sdk.UnwrapSDKContext(goCtx)
sendingValidatorAddress := config.GetConfig().ValidatorAddress
GetAppLogger().Info(ctx, "create re-issuance result")
msg := daotypes.NewMsgReissueRDDLResult(sendingValidatorAddress, proposerAddress, txID, blockHeight)
buildSignBroadcastTx(goCtx, "sending the re-issuance result", sendingValidatorAddress, msg)
}
func SendDistributionRequest(goCtx context.Context, distribution daotypes.DistributionOrder) {
ctx := sdk.UnwrapSDKContext(goCtx)
sendingValidatorAddress := config.GetConfig().ValidatorAddress
GetAppLogger().Info(ctx, "create Distribution Request")
msg := daotypes.NewMsgDistributionRequest(sendingValidatorAddress, &distribution)
buildSignBroadcastTx(goCtx, "sending the distribution request", sendingValidatorAddress, msg)
}
func SendDistributionResult(goCtx context.Context, lastPoP string, daoTxID string, invTxID string, popTxID string) {
ctx := sdk.UnwrapSDKContext(goCtx)
sendingValidatorAddress := config.GetConfig().ValidatorAddress
GetAppLogger().Info(ctx, "create Distribution Result")
iLastPoP, err := strconv.ParseInt(lastPoP, 10, 64)
if err != nil {
ctx.Logger().Error("Distribution Result: preparation failed ", err.Error())
return
}
msg := daotypes.NewMsgDistributionResult(sendingValidatorAddress, iLastPoP, daoTxID, invTxID, popTxID)
buildSignBroadcastTx(goCtx, "send distribution result", sendingValidatorAddress, msg)
}
func SendLiquidAssetRegistration(goCtx context.Context, notarizedAsset machinetypes.LiquidAsset) {
ctx := sdk.UnwrapSDKContext(goCtx)
sendingValidatorAddress := config.GetConfig().ValidatorAddress
GetAppLogger().Info(ctx, "create Liquid Asset Registration")
msg := machinetypes.NewMsgNotarizeLiquidAsset(sendingValidatorAddress, &notarizedAsset)
buildSignBroadcastTx(goCtx, "Liquid Asset Registration:", sendingValidatorAddress, msg)
}
func SendInitPoP(goCtx context.Context, proposer string, challenger string, challengee string, blockHeight int64) {
ctx := sdk.UnwrapSDKContext(goCtx)
sendingValidatorAddress := config.GetConfig().ValidatorAddress
GetAppLogger().Info(ctx, "create Init PoP message")
msg := daotypes.NewMsgInitPop(sendingValidatorAddress, proposer, challenger, challengee, blockHeight)
buildSignBroadcastTx(goCtx, "Init PoP:", sendingValidatorAddress, msg)
}