From 0df5a41667cf3bb96f570e57b34dc322f2a92ceb Mon Sep 17 00:00:00 2001 From: Jorge Silva Date: Tue, 11 Jul 2023 14:38:52 +0100 Subject: [PATCH] fix(webapi): get block query param correctly --- packages/webapi/controllers/chain/chain.go | 4 +-- .../webapi/controllers/chain/contracts.go | 2 +- .../controllers/corecontracts/accounts.go | 18 ++++++------ .../webapi/controllers/corecontracts/blob.go | 6 ++-- .../controllers/corecontracts/blocklog.go | 28 +++++++++---------- .../controllers/corecontracts/errors.go | 2 +- .../controllers/corecontracts/governance.go | 6 ++-- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/packages/webapi/controllers/chain/chain.go b/packages/webapi/controllers/chain/chain.go index 378276f344..c693d2a296 100644 --- a/packages/webapi/controllers/chain/chain.go +++ b/packages/webapi/controllers/chain/chain.go @@ -50,7 +50,7 @@ func (c *Controller) getChainInfo(e echo.Context) error { return err } - chainInfo, err := c.chainService.GetChainInfoByChainID(chainID, e.Param(params.ParamBlockIndexOrTrieRoot)) + chainInfo, err := c.chainService.GetChainInfoByChainID(chainID, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if errors.Is(err, interfaces.ErrChainNotFound) { return e.NoContent(http.StatusNotFound) } else if err != nil { @@ -59,7 +59,7 @@ func (c *Controller) getChainInfo(e echo.Context) error { evmChainID := uint16(0) if chainInfo.IsActive { - evmChainID, err = c.chainService.GetEVMChainID(chainID, e.Param(params.ParamBlockIndexOrTrieRoot)) + evmChainID, err = c.chainService.GetEVMChainID(chainID, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return err } diff --git a/packages/webapi/controllers/chain/contracts.go b/packages/webapi/controllers/chain/contracts.go index 05bc210479..e606427969 100644 --- a/packages/webapi/controllers/chain/contracts.go +++ b/packages/webapi/controllers/chain/contracts.go @@ -17,7 +17,7 @@ func (c *Controller) getContracts(e echo.Context) error { return err } - contracts, err := c.chainService.GetContracts(chainID, e.Param(params.ParamBlockIndexOrTrieRoot)) + contracts, err := c.chainService.GetContracts(chainID, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return err } diff --git a/packages/webapi/controllers/corecontracts/accounts.go b/packages/webapi/controllers/corecontracts/accounts.go index 00536067c5..f031f5a937 100644 --- a/packages/webapi/controllers/corecontracts/accounts.go +++ b/packages/webapi/controllers/corecontracts/accounts.go @@ -19,7 +19,7 @@ func (c *Controller) getAccounts(e echo.Context) error { return c.handleViewCallError(err, chainID) } - accounts, err := corecontracts.GetAccounts(ch, e.Param(params.ParamBlockIndexOrTrieRoot)) + accounts, err := corecontracts.GetAccounts(ch, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -41,7 +41,7 @@ func (c *Controller) getTotalAssets(e echo.Context) error { return c.handleViewCallError(err, chainID) } - assets, err := corecontracts.GetTotalAssets(ch, e.Param(params.ParamBlockIndexOrTrieRoot)) + assets, err := corecontracts.GetTotalAssets(ch, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -65,7 +65,7 @@ func (c *Controller) getAccountBalance(e echo.Context) error { return err } - assets, err := corecontracts.GetAccountBalance(ch, agentID, e.Param(params.ParamBlockIndexOrTrieRoot)) + assets, err := corecontracts.GetAccountBalance(ch, agentID, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -89,7 +89,7 @@ func (c *Controller) getAccountNFTs(e echo.Context) error { return err } - nfts, err := corecontracts.GetAccountNFTs(ch, agentID, e.Param(params.ParamBlockIndexOrTrieRoot)) + nfts, err := corecontracts.GetAccountNFTs(ch, agentID, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -115,7 +115,7 @@ func (c *Controller) getAccountFoundries(e echo.Context) error { return err } - foundries, err := corecontracts.GetAccountFoundries(ch, agentID, e.Param(params.ParamBlockIndexOrTrieRoot)) + foundries, err := corecontracts.GetAccountFoundries(ch, agentID, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -136,7 +136,7 @@ func (c *Controller) getAccountNonce(e echo.Context) error { return err } - nonce, err := corecontracts.GetAccountNonce(ch, agentID, e.Param(params.ParamBlockIndexOrTrieRoot)) + nonce, err := corecontracts.GetAccountNonce(ch, agentID, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -159,7 +159,7 @@ func (c *Controller) getNFTData(e echo.Context) error { return err } - nftData, err := corecontracts.GetNFTData(ch, *nftID, e.Param(params.ParamBlockIndexOrTrieRoot)) + nftData, err := corecontracts.GetNFTData(ch, *nftID, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -175,7 +175,7 @@ func (c *Controller) getNativeTokenIDRegistry(e echo.Context) error { return c.handleViewCallError(err, chainID) } - registries, err := corecontracts.GetNativeTokenIDRegistry(ch, e.Param(params.ParamBlockIndexOrTrieRoot)) + registries, err := corecontracts.GetNativeTokenIDRegistry(ch, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -202,7 +202,7 @@ func (c *Controller) getFoundryOutput(e echo.Context) error { return err } - foundryOutput, err := corecontracts.GetFoundryOutput(ch, uint32(serialNumber), e.Param(params.ParamBlockIndexOrTrieRoot)) + foundryOutput, err := corecontracts.GetFoundryOutput(ch, uint32(serialNumber), e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } diff --git a/packages/webapi/controllers/corecontracts/blob.go b/packages/webapi/controllers/corecontracts/blob.go index 0e7d20b9ef..2175a16239 100644 --- a/packages/webapi/controllers/corecontracts/blob.go +++ b/packages/webapi/controllers/corecontracts/blob.go @@ -27,7 +27,7 @@ func (c *Controller) listBlobs(e echo.Context) error { return c.handleViewCallError(err, chainID) } - blobList, err := corecontracts.ListBlobs(ch, e.Param(params.ParamBlockIndexOrTrieRoot)) + blobList, err := corecontracts.ListBlobs(ch, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -63,7 +63,7 @@ func (c *Controller) getBlobValue(e echo.Context) error { fieldKey := e.Param(params.ParamFieldKey) - blobValueBytes, err := corecontracts.GetBlobValue(ch, *blobHash, fieldKey, e.Param(params.ParamBlockIndexOrTrieRoot)) + blobValueBytes, err := corecontracts.GetBlobValue(ch, *blobHash, fieldKey, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -92,7 +92,7 @@ func (c *Controller) getBlobInfo(e echo.Context) error { return err } - blobInfo, ok, err := corecontracts.GetBlobInfo(ch, *blobHash, e.Param(params.ParamBlockIndexOrTrieRoot)) + blobInfo, ok, err := corecontracts.GetBlobInfo(ch, *blobHash, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } diff --git a/packages/webapi/controllers/corecontracts/blocklog.go b/packages/webapi/controllers/corecontracts/blocklog.go index f1796f4333..8f4b8b8aa1 100644 --- a/packages/webapi/controllers/corecontracts/blocklog.go +++ b/packages/webapi/controllers/corecontracts/blocklog.go @@ -47,7 +47,7 @@ func (c *Controller) getBlockInfo(e echo.Context) error { blockIndex := e.Param(params.ParamBlockIndex) if blockIndex == "" { - blockInfo, err = corecontracts.GetLatestBlockInfo(ch, e.Param(params.ParamBlockIndexOrTrieRoot)) + blockInfo, err = corecontracts.GetLatestBlockInfo(ch, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) } else { var blockIndexNum uint64 blockIndexNum, err = strconv.ParseUint(e.Param(params.ParamBlockIndex), 10, 64) @@ -55,7 +55,7 @@ func (c *Controller) getBlockInfo(e echo.Context) error { return apierrors.InvalidPropertyError(params.ParamBlockIndex, err) } - blockInfo, err = corecontracts.GetBlockInfo(ch, uint32(blockIndexNum), e.Param(params.ParamBlockIndexOrTrieRoot)) + blockInfo, err = corecontracts.GetBlockInfo(ch, uint32(blockIndexNum), e.QueryParam(params.ParamBlockIndexOrTrieRoot)) } if err != nil { return c.handleViewCallError(err, chainID) @@ -75,7 +75,7 @@ func (c *Controller) getRequestIDsForBlock(e echo.Context) error { blockIndex := e.Param(params.ParamBlockIndex) if blockIndex == "" { - requestIDs, err = corecontracts.GetRequestIDsForLatestBlock(ch, e.Param(params.ParamBlockIndexOrTrieRoot)) + requestIDs, err = corecontracts.GetRequestIDsForLatestBlock(ch, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) } else { var blockIndexNum uint64 blockIndexNum, err = params.DecodeUInt(e, params.ParamBlockIndex) @@ -83,7 +83,7 @@ func (c *Controller) getRequestIDsForBlock(e echo.Context) error { return err } - requestIDs, err = corecontracts.GetRequestIDsForBlock(ch, uint32(blockIndexNum), e.Param(params.ParamBlockIndexOrTrieRoot)) + requestIDs, err = corecontracts.GetRequestIDsForBlock(ch, uint32(blockIndexNum), e.QueryParam(params.ParamBlockIndexOrTrieRoot)) } if err != nil { @@ -111,7 +111,7 @@ func GetRequestReceipt(e echo.Context, c interfaces.ChainService) error { return err } - receipt, err := corecontracts.GetRequestReceipt(ch, requestID, e.Param(params.ParamBlockIndexOrTrieRoot)) + receipt, err := corecontracts.GetRequestReceipt(ch, requestID, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { panic(err) } @@ -141,12 +141,12 @@ func (c *Controller) getRequestReceiptsForBlock(e echo.Context) error { if blockIndex == "" { var blockInfo *blocklog.BlockInfo - blockInfo, err = corecontracts.GetLatestBlockInfo(ch, e.Param(params.ParamBlockIndexOrTrieRoot)) + blockInfo, err = corecontracts.GetLatestBlockInfo(ch, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } - blocklogReceipts, err = corecontracts.GetRequestReceiptsForBlock(ch, blockInfo.BlockIndex(), e.Param(params.ParamBlockIndexOrTrieRoot)) + blocklogReceipts, err = corecontracts.GetRequestReceiptsForBlock(ch, blockInfo.BlockIndex(), e.QueryParam(params.ParamBlockIndexOrTrieRoot)) } else { var blockIndexNum uint64 blockIndexNum, err = params.DecodeUInt(e, params.ParamBlockIndex) @@ -154,7 +154,7 @@ func (c *Controller) getRequestReceiptsForBlock(e echo.Context) error { return err } - blocklogReceipts, err = corecontracts.GetRequestReceiptsForBlock(ch, uint32(blockIndexNum), e.Param(params.ParamBlockIndexOrTrieRoot)) + blocklogReceipts, err = corecontracts.GetRequestReceiptsForBlock(ch, uint32(blockIndexNum), e.QueryParam(params.ParamBlockIndexOrTrieRoot)) } if err != nil { return c.handleViewCallError(err, chainID) @@ -184,7 +184,7 @@ func (c *Controller) getIsRequestProcessed(e echo.Context) error { return err } - requestProcessed, err := corecontracts.IsRequestProcessed(ch, requestID, e.Param(params.ParamBlockIndexOrTrieRoot)) + requestProcessed, err := corecontracts.IsRequestProcessed(ch, requestID, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -222,17 +222,17 @@ func (c *Controller) getBlockEvents(e echo.Context) error { return err } - events, err = corecontracts.GetEventsForBlock(ch, uint32(blockIndexNum), e.Param(params.ParamBlockIndexOrTrieRoot)) + events, err = corecontracts.GetEventsForBlock(ch, uint32(blockIndexNum), e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } } else { - blockInfo, err := corecontracts.GetLatestBlockInfo(ch, e.Param(params.ParamBlockIndexOrTrieRoot)) + blockInfo, err := corecontracts.GetLatestBlockInfo(ch, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } - events, err = corecontracts.GetEventsForBlock(ch, blockInfo.BlockIndex(), e.Param(params.ParamBlockIndexOrTrieRoot)) + events, err = corecontracts.GetEventsForBlock(ch, blockInfo.BlockIndex(), e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -250,7 +250,7 @@ func (c *Controller) getContractEvents(e echo.Context) error { return err } - events, err := corecontracts.GetEventsForContract(ch, contractHname, e.Param(params.ParamBlockIndexOrTrieRoot)) + events, err := corecontracts.GetEventsForContract(ch, contractHname, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -267,7 +267,7 @@ func (c *Controller) getRequestEvents(e echo.Context) error { return err } - events, err := corecontracts.GetEventsForRequest(ch, requestID, e.Param(params.ParamBlockIndexOrTrieRoot)) + events, err := corecontracts.GetEventsForRequest(ch, requestID, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } diff --git a/packages/webapi/controllers/corecontracts/errors.go b/packages/webapi/controllers/corecontracts/errors.go index 2bffff8f48..097f7f09e9 100644 --- a/packages/webapi/controllers/corecontracts/errors.go +++ b/packages/webapi/controllers/corecontracts/errors.go @@ -29,7 +29,7 @@ func (c *Controller) getErrorMessageFormat(e echo.Context) error { return err } - messageFormat, err := corecontracts.ErrorMessageFormat(ch, contractHname, uint16(errorID), e.Param(params.ParamBlockIndexOrTrieRoot)) + messageFormat, err := corecontracts.ErrorMessageFormat(ch, contractHname, uint16(errorID), e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } diff --git a/packages/webapi/controllers/corecontracts/governance.go b/packages/webapi/controllers/corecontracts/governance.go index d4c60fb964..7cfd76898b 100644 --- a/packages/webapi/controllers/corecontracts/governance.go +++ b/packages/webapi/controllers/corecontracts/governance.go @@ -36,7 +36,7 @@ func (c *Controller) getChainInfo(e echo.Context) error { return c.handleViewCallError(err, chainID) } - chainInfo, err := corecontracts.GetChainInfo(ch, e.Param(params.ParamBlockIndexOrTrieRoot)) + chainInfo, err := corecontracts.GetChainInfo(ch, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -52,7 +52,7 @@ func (c *Controller) getChainOwner(e echo.Context) error { return c.handleViewCallError(err, chainID) } - chainOwner, err := corecontracts.GetChainOwner(ch, e.Param(params.ParamBlockIndexOrTrieRoot)) + chainOwner, err := corecontracts.GetChainOwner(ch, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) } @@ -70,7 +70,7 @@ func (c *Controller) getAllowedStateControllerAddresses(e echo.Context) error { return c.handleViewCallError(err, chainID) } - addresses, err := corecontracts.GetAllowedStateControllerAddresses(ch, e.Param(params.ParamBlockIndexOrTrieRoot)) + addresses, err := corecontracts.GetAllowedStateControllerAddresses(ch, e.QueryParam(params.ParamBlockIndexOrTrieRoot)) if err != nil { return c.handleViewCallError(err, chainID) }