planetmint-go/util/issue_commands.go
Lorenz Herzberger a38fe781ba
187 implement rddl claim (#298)
* ignite scaffold map redeem-claim amount issued:bool --module dao --index beneficiary,liquid-tx-hash

* revert: remove autogenerated delete redeem claim logic

* fix: replace deprecated autogenerated sdkerrors with errorsmod

* refactor: rename issued to confirmed on redeem claim

* feat: add claim address param

* test: add test for restricted msg UpdateRedeemClaim

* refactor: update redeem claim key creation and messages

* feat: add SendUpdateRedeemCLaim to util

* feat: add RedeemClaimDecorator for ante package

* ignite scaffold message confirm-redeem-claim id:uint beneficiary:string --module dao

* feat: add handleConfirmRedeemClaim to ante handler

* feat: add handleUpdateRedeemClaim to ante handler

* feat: implement ConfirmRedeemClaim msg handler

* test: add redeem claim test and adjust e2e test suite

* fix: make use of uint to rddl string util in CreateRedeemClaim

* fix: linter and staticcheck errors

* ignite scaffold query redeem-claim-by-liquid-tx-hash liquid-tx-hash --response redeem-claim:RedeemClaim --module dao

* feat: add RedeemClaimByLiquidTXHash store capabilities

* test: add QueryRedeemClaimByLiquidTxHash to e2e test suite

* feat: add RedeemClaimDecorator to ante handler chain

* fix: remove redundant planetmint-go from service path

* fix: linter and staticcheck errors

* fix: go vet errors

* fix: remove unused autogenerated simulation

* fix: broken simulation

* fix: openapi.yml

* revert: remove autogenerated redundant test file that causes data race on pipeline

* feat: burn claim on CreateRedeemClaim

* fix: linter error

* test: fix mock bankkeeper for msg server test

* fix: reissuance test if statement

* chore: removed TODO comment

* fix: typo in redeem claim error msg

* revert: remove autogenerated genesis state

* fix: dao module simulation

* revert: remove unused function

* fix: linter errors

* fix: linter error

---------

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
2024-02-01 09:57:58 +01:00

101 lines
4.5 KiB
Go

package util
import (
"context"
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"
"sigs.k8s.io/yaml"
)
func buildSignBroadcastTx(goCtx context.Context, loggingContext string, sendingValidatorAddress string, msg sdk.Msg) {
ctx := sdk.UnwrapSDKContext(goCtx)
GetAppLogger().Info(ctx, loggingContext+": "+msg.String())
go func() {
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().Debug(ctx, loggingContext+" unsigned tx: "+txJSON)
out, err := lib.BroadcastTxWithFileLock(addr, msg)
if err != nil {
GetAppLogger().Error(ctx, loggingContext+" broadcast tx failed: "+err.Error())
return
}
txResponse, err := lib.GetTxResponseFromOut(out)
if err != nil {
GetAppLogger().Error(ctx, loggingContext+" getting tx response from out failed: "+err.Error())
return
}
if txResponse.Code == 0 {
GetAppLogger().Info(ctx, loggingContext+" broadcast tx succeeded")
return
}
txResponseJSON, err := yaml.YAMLToJSON([]byte(txResponse.String()))
if err != nil {
GetAppLogger().Error(ctx, loggingContext+" converting tx response from yaml to json failed: "+err.Error())
return
}
GetAppLogger().Error(ctx, loggingContext+" broadcast tx failed: "+string(txResponseJSON))
}()
}
func SendInitReissuance(goCtx context.Context, proposerAddress string, txUnsigned string, blockHeight int64,
firstIncludedPop int64, lastIncludedPop int64) {
// get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store
sendingValidatorAddress := config.GetConfig().ValidatorAddress
msg := daotypes.NewMsgReissueRDDLProposal(sendingValidatorAddress, proposerAddress, txUnsigned, blockHeight,
firstIncludedPop, lastIncludedPop)
loggingContext := "reissuance proposal"
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
}
func SendReissuanceResult(goCtx context.Context, proposerAddress string, txID string, blockHeight int64) {
sendingValidatorAddress := config.GetConfig().ValidatorAddress
msg := daotypes.NewMsgReissueRDDLResult(sendingValidatorAddress, proposerAddress, txID, blockHeight)
loggingContext := "reissuance result"
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
}
func SendDistributionRequest(goCtx context.Context, distribution daotypes.DistributionOrder) {
sendingValidatorAddress := config.GetConfig().ValidatorAddress
msg := daotypes.NewMsgDistributionRequest(sendingValidatorAddress, &distribution)
loggingContext := "distribution request"
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
}
func SendDistributionResult(goCtx context.Context, lastPoP int64, daoTxID string, invTxID string,
popTxID string, earlyInvestorTxID string, strategicTxID string) {
sendingValidatorAddress := config.GetConfig().ValidatorAddress
msg := daotypes.NewMsgDistributionResult(sendingValidatorAddress, lastPoP, daoTxID, invTxID, popTxID, earlyInvestorTxID, strategicTxID)
loggingContext := "distribution result"
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
}
func SendLiquidAssetRegistration(goCtx context.Context, notarizedAsset machinetypes.LiquidAsset) {
sendingValidatorAddress := config.GetConfig().ValidatorAddress
msg := machinetypes.NewMsgNotarizeLiquidAsset(sendingValidatorAddress, &notarizedAsset)
loggingContext := "notarize liquid asset"
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
}
func SendInitPoP(goCtx context.Context, proposer string, challenger string, challengee string, blockHeight int64) {
sendingValidatorAddress := config.GetConfig().ValidatorAddress
msg := daotypes.NewMsgInitPop(sendingValidatorAddress, proposer, challenger, challengee, blockHeight)
loggingContext := "PoP"
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
}
func SendUpdateRedeemClaim(goCtx context.Context, beneficiary string, id uint64, txID string) {
sendingValidatorAddress := config.GetConfig().ValidatorAddress
msg := daotypes.NewMsgUpdateRedeemClaim(sendingValidatorAddress, beneficiary, txID, id)
loggingContext := "redeem claim"
buildSignBroadcastTx(goCtx, loggingContext, sendingValidatorAddress, msg)
}