diff --git a/util/issue_commands.go b/util/issue_commands.go new file mode 100644 index 0000000..907db8b --- /dev/null +++ b/util/issue_commands.go @@ -0,0 +1,40 @@ +package util + +import ( + "fmt" + "os/exec" + "strconv" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func InitRDDLReissuanceProcess(ctx sdk.Context, proposerAddress string, blk_height int64) error { + tx_unsigned, err := GetUnsignedReissuanceTransaction() + //blk_height := 0 //get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store + + // Construct the command + cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-proposal", hexProposerAddress, tx_unsigned, strconv.FormatInt(blk_height, 10)) + + // Start the command in a non-blocking way + err = cmd.Start() + if err != nil { + fmt.Printf("Error starting command: %s\n", err) + } else { + fmt.Println("Command started in background") + } + return err +} + +func SendRDDLReissuanceResult(ctx sdk.Context, proposerAddress string, txID string, blk_height uint64) error { + // Construct the command + cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-result", hexProposerAddress, txID, strconv.FormatInt(blk_height, 10)) + + // Start the command in a non-blocking way + err := cmd.Start() + if err != nil { + fmt.Printf("Error starting command: %s\n", err) + } else { + fmt.Println("Command started in background") + } + return err +} diff --git a/x/dao/abci.go b/x/dao/abci.go index 5d0cbec..add6fc5 100644 --- a/x/dao/abci.go +++ b/x/dao/abci.go @@ -3,8 +3,6 @@ package dao import ( "encoding/hex" "fmt" - "os/exec" - "strconv" "github.com/planetmint/planetmint-go/config" "github.com/planetmint/planetmint-go/util" @@ -19,34 +17,18 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) proposerAddress := req.Header.GetProposerAddress() // Check if node is block proposer + if isPoPHeight(req.Header.GetHeight()) && util.IsValidatorBlockProposer(ctx, proposerAddress) { // TODO: implement PoP trigger fmt.Println("TODO: implement PoP trigger") - err := initRDDLReissuanceProcess(ctx, proposerAddress, req.Header.GetHeight()) + hexProposerAddress := hex.EncodeToString(proposerAddress) + err := util.InitRDDLReissuanceProcess(ctx, hexProposerAddress, req.Header.GetHeight()) if err != nil { logger.Error("error while issuing RDDL", err) } } } -func initRDDLReissuanceProcess(ctx sdk.Context, proposerAddress []byte, blk_height int64) error { - tx_unsigned, err := util.GetUnsignedReissuanceTransaction() - //blk_height := 0 //get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store - hexProposerAddress := hex.EncodeToString(proposerAddress) - - // Construct the command - cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-proposal", hexProposerAddress, tx_unsigned, strconv.FormatInt(blk_height, 10)) - - // Start the command in a non-blocking way - err = cmd.Start() - if err != nil { - fmt.Printf("Error starting command: %s\n", err) - } else { - fmt.Println("Command started in background") - } - return err -} - func isPoPHeight(height int64) bool { cfg := config.GetConfig() return height%int64(cfg.PoPEpochs) == 0 diff --git a/x/dao/keeper/msg_server_reissue_rddl_proposal.go b/x/dao/keeper/msg_server_reissue_rddl_proposal.go index 59623df..f6585a0 100644 --- a/x/dao/keeper/msg_server_reissue_rddl_proposal.go +++ b/x/dao/keeper/msg_server_reissue_rddl_proposal.go @@ -15,7 +15,10 @@ func (k msgServer) ReissueRDDLProposal(goCtx context.Context, msg *types.MsgReis if valid_result && msg.Proposer == validator_identity { // 1. sign tx // 2. broadcast tx + + txID := "asdlkufzaoisdfpoajf" // 3. notarize result by notarizing the liquid tx-id + util.SendRDDLReissuanceResult(ctx, msg.GetProposer(), txID, msg.GetBlockheight()) } var reissuance types.Reissuance