From f8d40718153da5210ba1edecd484b9d1e0a1a55c Mon Sep 17 00:00:00 2001 From: vaibhavjindal29 Date: Tue, 29 Mar 2022 17:41:23 +0530 Subject: [PATCH 1/2] initial --- checkpoint/client/rest/query.go | 57 ++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/checkpoint/client/rest/query.go b/checkpoint/client/rest/query.go index 1cd94657b..40cd02a7d 100644 --- a/checkpoint/client/rest/query.go +++ b/checkpoint/client/rest/query.go @@ -406,15 +406,45 @@ func latestCheckpointHandlerFunc(cliCtx context.CLIContext) http.HandlerFunc { return } + var checkpoint1 hmTypes.Checkpoint + json.Unmarshal(res, &checkpoint1) + + checkpointTemp := &CheckpointTemp{ + ID: ackCount, + Proposer: checkpoint1.Proposer, + StartBlock: checkpoint1.StartBlock, + EndBlock: checkpoint1.EndBlock, + RootHash: checkpoint1.RootHash, + BorChainID: checkpoint1.BorChainID, + TimeStamp: checkpoint1.TimeStamp, + } + + resNew, err := json.Marshal(checkpointTemp) + if err != nil { + hmRest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + } + // error if no checkpoint found - if ok := hmRest.ReturnNotFoundIfNoContent(w, res, "No checkpoint found"); !ok { + if ok := hmRest.ReturnNotFoundIfNoContent(w, resNew, "No checkpoint found"); !ok { return } cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) + rest.PostProcessResponse(w, cliCtx, resNew) } } + +//Temporary Checkpoint struct to store the Checkpoint ID +type CheckpointTemp struct { + ID uint64 `json:"id"` + Proposer hmTypes.HeimdallAddress `json:"proposer"` + StartBlock uint64 `json:"start_block"` + EndBlock uint64 `json:"end_block"` + RootHash hmTypes.HeimdallHash `json:"root_hash"` + BorChainID string `json:"bor_chain_id"` + TimeStamp uint64 `json:"timestamp"` +} + // get checkpoint by checkppint number from store func checkpointByNumberHandlerFunc(cliCtx context.CLIContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { @@ -444,12 +474,31 @@ func checkpointByNumberHandlerFunc(cliCtx context.CLIContext) http.HandlerFunc { return } + var checkpoint1 hmTypes.Checkpoint + json.Unmarshal(res, &checkpoint1) + + checkpointTemp := &CheckpointTemp{ + ID: number, + Proposer: checkpoint1.Proposer, + StartBlock: checkpoint1.StartBlock, + EndBlock: checkpoint1.EndBlock, + RootHash: checkpoint1.RootHash, + BorChainID: checkpoint1.BorChainID, + TimeStamp: checkpoint1.TimeStamp, + } + + resNew, err := json.Marshal(checkpointTemp) + if err != nil { + hmRest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) + } + // check content - if ok := hmRest.ReturnNotFoundIfNoContent(w, res, "No checkpoint found"); !ok { + if ok := hmRest.ReturnNotFoundIfNoContent(w, resNew, "No checkpoint found"); !ok { return } cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, res) + rest.PostProcessResponse(w, cliCtx, resNew) + } } From b71652fecf1ecb834e6e85809215e2caa4708202 Mon Sep 17 00:00:00 2001 From: vaibhavjindal29 Date: Mon, 4 Apr 2022 00:46:57 +0530 Subject: [PATCH 2/2] Changes --- checkpoint/client/cli/query.go | 6 ++-- checkpoint/client/rest/query.go | 55 ++++++++++++++++----------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/checkpoint/client/cli/query.go b/checkpoint/client/cli/query.go index 072a305f1..b302dc7d3 100644 --- a/checkpoint/client/cli/query.go +++ b/checkpoint/client/cli/query.go @@ -35,7 +35,7 @@ func GetQueryCmd(cdc *codec.Codec) *cobra.Command { GetQueryParams(cdc), GetCheckpointBuffer(cdc), GetLastNoACK(cdc), - GetHeaderFromIndex(cdc), + GetCheckpointByNumber(cdc), GetCheckpointCount(cdc), )..., ) @@ -132,10 +132,10 @@ func GetLastNoACK(cdc *codec.Codec) *cobra.Command { } // GetHeaderFromIndex get checkpoint given header index -func GetHeaderFromIndex(cdc *codec.Codec) *cobra.Command { +func GetCheckpointByNumber(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "header", - Short: "get checkpoint (header) from index", + Short: "get checkpoint (header) by number", RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) headerNumber := viper.GetUint64(FlagHeaderNumber) diff --git a/checkpoint/client/rest/query.go b/checkpoint/client/rest/query.go index 40cd02a7d..51c2ce94f 100644 --- a/checkpoint/client/rest/query.go +++ b/checkpoint/client/rest/query.go @@ -406,36 +406,35 @@ func latestCheckpointHandlerFunc(cliCtx context.CLIContext) http.HandlerFunc { return } - var checkpoint1 hmTypes.Checkpoint - json.Unmarshal(res, &checkpoint1) - - checkpointTemp := &CheckpointTemp{ + var checkpointUnmarshal hmTypes.Checkpoint + json.Unmarshal(res, &checkpointUnmarshal) + + checkpointWithID := &CheckpointWithID{ ID: ackCount, - Proposer: checkpoint1.Proposer, - StartBlock: checkpoint1.StartBlock, - EndBlock: checkpoint1.EndBlock, - RootHash: checkpoint1.RootHash, - BorChainID: checkpoint1.BorChainID, - TimeStamp: checkpoint1.TimeStamp, + Proposer: checkpointUnmarshal.Proposer, + StartBlock: checkpointUnmarshal.StartBlock, + EndBlock: checkpointUnmarshal.EndBlock, + RootHash: checkpointUnmarshal.RootHash, + BorChainID: checkpointUnmarshal.BorChainID, + TimeStamp: checkpointUnmarshal.TimeStamp, } - resNew, err := json.Marshal(checkpointTemp) + resWithID, err := json.Marshal(checkpointWithID) if err != nil { hmRest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) } // error if no checkpoint found - if ok := hmRest.ReturnNotFoundIfNoContent(w, resNew, "No checkpoint found"); !ok { + if ok := hmRest.ReturnNotFoundIfNoContent(w, resWithID, "No checkpoint found"); !ok { return } cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, resNew) + rest.PostProcessResponse(w, cliCtx, resWithID) } } - //Temporary Checkpoint struct to store the Checkpoint ID -type CheckpointTemp struct { +type CheckpointWithID struct { ID uint64 `json:"id"` Proposer hmTypes.HeimdallAddress `json:"proposer"` StartBlock uint64 `json:"start_block"` @@ -474,30 +473,30 @@ func checkpointByNumberHandlerFunc(cliCtx context.CLIContext) http.HandlerFunc { return } - var checkpoint1 hmTypes.Checkpoint - json.Unmarshal(res, &checkpoint1) - - checkpointTemp := &CheckpointTemp{ + var checkpointUnmarshal hmTypes.Checkpoint + json.Unmarshal(res, &checkpointUnmarshal) + + checkpointWithID := &CheckpointWithID{ ID: number, - Proposer: checkpoint1.Proposer, - StartBlock: checkpoint1.StartBlock, - EndBlock: checkpoint1.EndBlock, - RootHash: checkpoint1.RootHash, - BorChainID: checkpoint1.BorChainID, - TimeStamp: checkpoint1.TimeStamp, + Proposer: checkpointUnmarshal.Proposer, + StartBlock: checkpointUnmarshal.StartBlock, + EndBlock: checkpointUnmarshal.EndBlock, + RootHash: checkpointUnmarshal.RootHash, + BorChainID: checkpointUnmarshal.BorChainID, + TimeStamp: checkpointUnmarshal.TimeStamp, } - resNew, err := json.Marshal(checkpointTemp) + resWithID, err := json.Marshal(checkpointWithID) if err != nil { hmRest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) } // check content - if ok := hmRest.ReturnNotFoundIfNoContent(w, resNew, "No checkpoint found"); !ok { + if ok := hmRest.ReturnNotFoundIfNoContent(w, resWithID, "No checkpoint found"); !ok { return } cliCtx = cliCtx.WithHeight(height) - rest.PostProcessResponse(w, cliCtx, resNew) + rest.PostProcessResponse(w, cliCtx, resWithID) } }