planetmint-go/util/issue_commands.go
Julian Strobl f18d4542e2
Merge release_0_5 branch (#202)
* Fix liuqid notarization (#191)

* Fix liuqid notarization - 2nd part (#193)

* fixed missing unmarshaling
* fixed message formatting issue

* fixed config parsing issue (#194)

* [util] Supply fees

But only where we want to see the transaction succeed. The other ones we
let in a broken state.

* Added logger a logger struct to log with a TAG (#198)

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
Signed-off-by: Julian Strobl <jmastr@mailbox.org>
Co-authored-by: Jürgen Eckel <eckelj@users.noreply.github.com>
2023-11-28 10:22:39 +01:00

75 lines
3.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 buildSignBroadcastTx(goCtx context.Context, sendingValidatorAddress string, msg sdk.Msg) (err error) {
ctx := sdk.UnwrapSDKContext(goCtx)
addr := sdk.MustAccAddressFromBech32(sendingValidatorAddress)
txJSON, err := lib.BuildUnsignedTx(goCtx, addr, msg)
if err != nil {
return
}
GetAppLogger().Info(ctx, "broadcast tx: "+txJSON)
_, err = lib.BroadcastTxWithFileLock(goCtx, addr, msg)
return
}
func InitRDDLReissuanceProcess(goCtx context.Context, proposerAddress string, txUnsigned string, blockHeight int64) (err error) {
ctx := sdk.UnwrapSDKContext(goCtx)
// get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store
sendingValidatorAddress := config.GetConfig().ValidatorAddress
GetAppLogger().Info(ctx, "create Reissuance Proposal")
msg := daotypes.NewMsgReissueRDDLProposal(sendingValidatorAddress, proposerAddress, txUnsigned, blockHeight)
err = buildSignBroadcastTx(goCtx, sendingValidatorAddress, msg)
return
}
func SendRDDLReissuanceResult(goCtx context.Context, proposerAddress string, txID string, blockHeight int64) (err error) {
ctx := sdk.UnwrapSDKContext(goCtx)
sendingValidatorAddress := config.GetConfig().ValidatorAddress
GetAppLogger().Info(ctx, "create Reissuance Result")
msg := daotypes.NewMsgReissueRDDLResult(sendingValidatorAddress, proposerAddress, txID, blockHeight)
err = buildSignBroadcastTx(goCtx, sendingValidatorAddress, msg)
return
}
func SendRDDLDistributionRequest(goCtx context.Context, distribution daotypes.DistributionOrder) (err error) {
ctx := sdk.UnwrapSDKContext(goCtx)
sendingValidatorAddress := config.GetConfig().ValidatorAddress
GetAppLogger().Info(ctx, "create Distribution Request")
msg := daotypes.NewMsgDistributionRequest(sendingValidatorAddress, &distribution)
err = buildSignBroadcastTx(goCtx, sendingValidatorAddress, msg)
return
}
func SendRDDLDistributionResult(goCtx context.Context, lastPoP string, daoTxID string, invTxID string, popTxID string) (err error) {
ctx := sdk.UnwrapSDKContext(goCtx)
sendingValidatorAddress := config.GetConfig().ValidatorAddress
GetAppLogger().Info(ctx, "create Distribution Result")
iLastPoP, err := strconv.ParseInt(lastPoP, 10, 64)
if err != nil {
return
}
msg := daotypes.NewMsgDistributionResult(sendingValidatorAddress, iLastPoP, daoTxID, invTxID, popTxID)
err = buildSignBroadcastTx(goCtx, sendingValidatorAddress, msg)
return
}
func SendLiquidAssetRegistration(goCtx context.Context, notarizedAsset machinetypes.LiquidAsset) (err error) {
ctx := sdk.UnwrapSDKContext(goCtx)
sendingValidatorAddress := config.GetConfig().ValidatorAddress
GetAppLogger().Info(ctx, "create Liquid Asset Registration")
msg := machinetypes.NewMsgNotarizeLiquidAsset(sendingValidatorAddress, &notarizedAsset)
err = buildSignBroadcastTx(goCtx, sendingValidatorAddress, msg)
return
}