diff --git a/app/ante/check_reissuance_decorator.go b/app/ante/check_reissuance_decorator.go index 138787a..2a09e4d 100644 --- a/app/ante/check_reissuance_decorator.go +++ b/app/ante/check_reissuance_decorator.go @@ -1,8 +1,6 @@ package ante import ( - "fmt" - errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/planetmint/planetmint-go/config" @@ -17,15 +15,16 @@ func NewCheckReissuanceDecorator() CheckReissuanceDecorator { } func (cmad CheckReissuanceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) { + logger := ctx.Logger() for _, msg := range tx.GetMsgs() { if sdk.MsgTypeURL(msg) == "/planetmintgo.dao.MsgReissueRDDLProposal" { MsgProposal, ok := msg.(*daotypes.MsgReissueRDDLProposal) if ok { - fmt.Println("REISSUE: receive Proposal") + logger.Debug("REISSUE: receive Proposal") conf := config.GetConfig() isValid := dao.IsValidReissuanceCommand(MsgProposal.GetTx(), conf.ReissuanceAsset, MsgProposal.GetBlockheight()) if !isValid { - fmt.Println("REISSUE: Invalid Proposal") + logger.Debug("REISSUE: Invalid Proposal") return ctx, errorsmod.Wrapf(daotypes.ErrReissuanceProposal, "error during CheckTx or ReCheckTx") } } diff --git a/app/simulation_test.go b/app/simulation_test.go index 9e6aba5..dfa36de 100644 --- a/app/simulation_test.go +++ b/app/simulation_test.go @@ -179,7 +179,7 @@ func TestAppStateDeterminism(t *testing.T) { baseapp.SetChainID(chainID), ) - fmt.Printf( + logger.Info( "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed, ) @@ -283,12 +283,12 @@ func TestAppImportExport(t *testing.T) { simtestutil.PrintStats(db) } - fmt.Printf("exporting genesis...\n") + logger.Info("exporting genesis...\n") exported, err := bApp.ExportAppStateAndValidators(false, []string{}, []string{}) require.NoError(t, err) - fmt.Printf("importing genesis...\n") + logger.Info("importing genesis...\n") newDB, newDir, _, _, err := simtestutil.SetupSimulation( config, @@ -338,7 +338,7 @@ func TestAppImportExport(t *testing.T) { newApp.ModuleManager().InitGenesis(ctxB, bApp.AppCodec(), genesisState) newApp.StoreConsensusParams(ctxB, exported.ConsensusParams) - fmt.Printf("comparing stores...\n") + logger.Info("comparing stores...\n") storeKeysPrefixes := []storeKeysPrefixes{ {bApp.GetKey(authtypes.StoreKey), newApp.GetKey(authtypes.StoreKey), [][]byte{}}, @@ -367,7 +367,7 @@ func TestAppImportExport(t *testing.T) { failedKVAs, failedKVBs := sdk.DiffKVStores(storeA, storeB, skp.Prefixes) require.Equal(t, len(failedKVAs), len(failedKVBs), "unequal sets of key-values to compare") - fmt.Printf("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B) + logger.Info("compared %d different key/value pairs between %s and %s\n", len(failedKVAs), skp.A, skp.B) require.Equal(t, 0, len(failedKVAs), simtestutil.GetSimulationLog(skp.A.Name(), bApp.SimulationManager().StoreDecoders, failedKVAs, failedKVBs)) } } @@ -439,16 +439,16 @@ func TestAppSimulationAfterImport(t *testing.T) { } if stopEarly { - fmt.Println("can't export or import a zero-validator genesis, exiting test...") + logger.Info("can't export or import a zero-validator genesis, exiting test...") return } - fmt.Printf("exporting genesis...\n") + logger.Info("exporting genesis...\n") exported, err := bApp.ExportAppStateAndValidators(true, []string{}, []string{}) require.NoError(t, err) - fmt.Printf("importing genesis...\n") + logger.Info("importing genesis...\n") newDB, newDir, _, _, err := simtestutil.SetupSimulation( config, diff --git a/util/issue_commands.go b/util/issue_commands.go index b7a692d..02c9b44 100644 --- a/util/issue_commands.go +++ b/util/issue_commands.go @@ -3,7 +3,6 @@ package util import ( "bytes" "errors" - "fmt" "os/exec" "strconv" @@ -13,9 +12,10 @@ import ( func InitRDDLReissuanceProcess(ctx sdk.Context, proposerAddress string, tx_unsigned string, blk_height int64) error { //get_last_PoPBlockHeight() // TODO: to be read form the upcoming PoP-store + logger := ctx.Logger() // Construct the command sending_validator_address := config.GetConfig().ValidatorAddress - fmt.Println("REISSUE: create Proposal") + logger.Debug("REISSUE: create Proposal") cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-proposal", "--from", sending_validator_address, "-y", proposerAddress, tx_unsigned, strconv.FormatInt(blk_height, 10)) @@ -36,9 +36,10 @@ func InitRDDLReissuanceProcess(ctx sdk.Context, proposerAddress string, tx_unsig } func SendRDDLReissuanceResult(ctx sdk.Context, proposerAddress string, txID string, blk_height uint64) error { + logger := ctx.Logger() // Construct the command sending_validator_address := config.GetConfig().ValidatorAddress - fmt.Println("REISSUE: create Result") + logger.Debug("REISSUE: create Result") cmd := exec.Command("planetmint-god", "tx", "dao", "reissue-rddl-result", "--from", sending_validator_address, "-y", proposerAddress, txID, strconv.FormatUint(blk_height, 10)) diff --git a/x/dao/abci.go b/x/dao/abci.go index b7a712e..90f3117 100644 --- a/x/dao/abci.go +++ b/x/dao/abci.go @@ -2,7 +2,6 @@ package dao import ( "encoding/hex" - "fmt" "github.com/planetmint/planetmint-go/config" "github.com/planetmint/planetmint-go/util" @@ -21,7 +20,7 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k keeper.Keeper) if isPoPHeight(req.Header.GetHeight()) && util.IsValidatorBlockProposer(ctx, proposerAddress) { blockHeight := req.Header.GetHeight() // TODO: implement PoP trigger - fmt.Println("TODO: implement PoP trigger") + logger.Info("TODO: implement PoP trigger") hexProposerAddress := hex.EncodeToString(proposerAddress) conf := config.GetConfig() tx_unsigned := GetReissuanceCommand(conf.ReissuanceAsset, blockHeight) diff --git a/x/dao/keeper/msg_server_reissue_rddl_proposal.go b/x/dao/keeper/msg_server_reissue_rddl_proposal.go index 830a1af..b96de4d 100644 --- a/x/dao/keeper/msg_server_reissue_rddl_proposal.go +++ b/x/dao/keeper/msg_server_reissue_rddl_proposal.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "fmt" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/planetmint/planetmint-go/util" @@ -11,19 +10,20 @@ import ( func (k msgServer) ReissueRDDLProposal(goCtx context.Context, msg *types.MsgReissueRDDLProposal) (*types.MsgReissueRDDLProposalResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + logger := ctx.Logger() validator_identity, valid_result := util.GetValidatorCometBFTIdentity(ctx) if valid_result && msg.Proposer == validator_identity { // 1. sign tx // 2. broadcast tx - fmt.Println("REISSUE: Asset") + logger.Debug("REISSUE: Asset") txID, err := util.ReissueAsset(msg.Tx) if err == nil { // 3. notarize result by notarizing the liquid tx-id _ = util.SendRDDLReissuanceResult(ctx, msg.GetProposer(), txID, msg.GetBlockheight()) //TODO verify and resolve error } else { - fmt.Println("REISSUE: Asset reissuance failure") + logger.Debug("REISSUE: Asset reissuance failure") } //TODO: reissuance need to be initiated otherwise } diff --git a/x/machine/keeper/msg_server_attest_machine.go b/x/machine/keeper/msg_server_attest_machine.go index 4be492a..71599d3 100644 --- a/x/machine/keeper/msg_server_attest_machine.go +++ b/x/machine/keeper/msg_server_attest_machine.go @@ -3,7 +3,6 @@ package keeper import ( "bytes" "context" - "log" "os/exec" "strings" @@ -46,7 +45,7 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach } if k.isNFTCreationRequest(msg.Machine) && util.IsValidatorBlockProposer(ctx, ctx.BlockHeader().ProposerAddress) { - _ = k.issueMachineNFT(msg.Machine) + _ = k.issueMachineNFT(ctx, msg.Machine) //TODO create NFTCreationMessage to be stored by all nodes // if err != nil { // return nil, types.ErrNFTIssuanceFailed @@ -75,8 +74,9 @@ func validateExtendedPublicKey(issuer string, cfg chaincfg.Params) bool { return isValidExtendedPublicKey } -func (k msgServer) issueNFTAsset(name string, machine_address string) (asset_id string, contract string, err error) { +func (k msgServer) issueNFTAsset(ctx sdk.Context, name string, machine_address string) (asset_id string, contract string, err error) { conf := config.GetConfig() + logger := ctx.Logger() cmdName := "poetry" cmdArgs := []string{"run", "python", "issuer_service/issue2liquid.py", name, machine_address} @@ -95,7 +95,7 @@ func (k msgServer) issueNFTAsset(name string, machine_address string) (asset_id // Execute the command err = cmd.Run() if err != nil { - log.Printf("cmd.Run() failed with %s\n", err) + logger.Error("cmd.Run() failed with %s\n", err) err = errorsmod.Wrap(types.ErrMachineNFTIssuance, stderr.String()) } else { lines := strings.Split(stdout.String(), "\n") @@ -109,8 +109,8 @@ func (k msgServer) issueNFTAsset(name string, machine_address string) (asset_id return asset_id, contract, err } -func (k msgServer) issueMachineNFT(machine *types.Machine) error { - _, _, err := k.issueNFTAsset(machine.Name, machine.Address) +func (k msgServer) issueMachineNFT(ctx sdk.Context, machine *types.Machine) error { + _, _, err := k.issueNFTAsset(ctx, machine.Name, machine.Address) return err // asset registration is not performed in case of NFT issuance for machines //asset_id, contract, err := k.issueNFTAsset(machine.Name, machine.Address)