mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-29 01:12:31 +00:00

* Move `encoding.go` to lib to avoid import cycle * [lib] Add `SetEncodingConfig` to avoid import cycle ``` package github.com/planetmint/planetmint-go/app imports github.com/planetmint/planetmint-go/app/ante imports github.com/planetmint/planetmint-go/x/dao imports github.com/planetmint/planetmint-go/util imports github.com/planetmint/planetmint-go/app: import cycle not allowed ``` * Use RPC instead of `exec.Command(...)` // Closes #152 Signed-off-by: Julian Strobl <jmastr@mailbox.org>
64 lines
2.4 KiB
Go
64 lines
2.4 KiB
Go
package util
|
|
|
|
import (
|
|
"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"
|
|
)
|
|
|
|
func buildSignBroadcastTx(ctx sdk.Context, sendingValidatorAddress string, msg sdk.Msg) (err error) {
|
|
logger := ctx.Logger()
|
|
addr := sdk.MustAccAddressFromBech32(sendingValidatorAddress)
|
|
txBytes, txJSON, err := lib.BuildAndSignTx(addr, msg)
|
|
if err != nil {
|
|
return
|
|
}
|
|
logger.Debug("REISSUE: tx: " + txJSON)
|
|
_, err = lib.BroadcastTx(txBytes)
|
|
return
|
|
}
|
|
|
|
func InitRDDLReissuanceProcess(ctx sdk.Context, proposerAddress string, txUnsigned string, blockHeight int64) (err error) {
|
|
//get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store
|
|
logger := ctx.Logger()
|
|
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
|
logger.Debug("REISSUE: create Reissuance Proposal")
|
|
msg := daotypes.NewMsgReissueRDDLProposal(sendingValidatorAddress, proposerAddress, txUnsigned, blockHeight)
|
|
err = buildSignBroadcastTx(ctx, sendingValidatorAddress, msg)
|
|
return
|
|
}
|
|
|
|
func SendRDDLReissuanceResult(ctx sdk.Context, proposerAddress string, txID string, blockHeight int64) (err error) {
|
|
logger := ctx.Logger()
|
|
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
|
logger.Debug("REISSUE: create Reissuance Result")
|
|
msg := daotypes.NewMsgReissueRDDLResult(sendingValidatorAddress, proposerAddress, txID, blockHeight)
|
|
err = buildSignBroadcastTx(ctx, sendingValidatorAddress, msg)
|
|
return
|
|
}
|
|
|
|
func SendRDDLDistributionRequest(ctx sdk.Context, distribution daotypes.DistributionOrder) (err error) {
|
|
logger := ctx.Logger()
|
|
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
|
logger.Debug("REISSUE: create Distribution Request")
|
|
msg := daotypes.NewMsgDistributionRequest(sendingValidatorAddress, &distribution)
|
|
err = buildSignBroadcastTx(ctx, sendingValidatorAddress, msg)
|
|
return
|
|
}
|
|
|
|
func SendRDDLDistributionResult(ctx sdk.Context, lastPoP string, daoTxID string, invTxID string, popTxID string) (err error) {
|
|
logger := ctx.Logger()
|
|
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
|
logger.Debug("REISSUE: create Distribution Result")
|
|
iLastPoP, err := strconv.ParseInt(lastPoP, 10, 64)
|
|
if err != nil {
|
|
return
|
|
}
|
|
msg := daotypes.NewMsgDistributionResult(sendingValidatorAddress, iLastPoP, daoTxID, invTxID, popTxID)
|
|
err = buildSignBroadcastTx(ctx, sendingValidatorAddress, msg)
|
|
return
|
|
}
|