mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00

* [lib] Refactor `getClientContextAndTxFactory()` So that we can pass the account number and sequence number from outside. * [lib] Add `BroadcastTxWithFileLock()` This implements "offline mode" via RPC, but instead of keeping track of the sequence numbers, we write them into a file and lock them. This way, we can synchronize multiple processes using the same address, trying to send transactions simultaneously. // Closes https://github.com/rddl-network/issues/issues/46 Signed-off-by: Julian Strobl <jmastr@mailbox.org> * [lib] Introduce variable for error * [lib] Improve error handling in `broadcastTx()` * Use `BroadcastTxWithFileLock()` // See https://github.com/rddl-network/issues/issues/46 --------- Signed-off-by: Julian Strobl <jmastr@mailbox.org>
70 lines
2.7 KiB
Go
70 lines
2.7 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"
|
|
)
|
|
|
|
func buildSignBroadcastTx(goCtx context.Context, sendingValidatorAddress string, msg sdk.Msg) (err error) {
|
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
|
logger := ctx.Logger()
|
|
addr := sdk.MustAccAddressFromBech32(sendingValidatorAddress)
|
|
txJSON, err := lib.BuildUnsignedTx(goCtx, addr, msg)
|
|
if err != nil {
|
|
return
|
|
}
|
|
logger.Debug("REISSUE: 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
|
|
logger := ctx.Logger()
|
|
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
|
logger.Debug("REISSUE: 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)
|
|
logger := ctx.Logger()
|
|
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
|
logger.Debug("REISSUE: 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)
|
|
logger := ctx.Logger()
|
|
sendingValidatorAddress := config.GetConfig().ValidatorAddress
|
|
logger.Debug("REISSUE: 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)
|
|
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(goCtx, sendingValidatorAddress, msg)
|
|
return
|
|
}
|