Skip to content

Commit

Permalink
Merge pull request #2700 from jorgemmsilva/fix/webapi-param
Browse files Browse the repository at this point in the history
fix(webapi): get block query param correctly
  • Loading branch information
jorgemmsilva authored Jul 11, 2023
2 parents cab932b + 0df5a41 commit a8a82a9
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions packages/webapi/controllers/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion packages/webapi/controllers/chain/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 9 additions & 9 deletions packages/webapi/controllers/corecontracts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions packages/webapi/controllers/corecontracts/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
28 changes: 14 additions & 14 deletions packages/webapi/controllers/corecontracts/blocklog.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ 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)
if err != nil {
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)
Expand All @@ -75,15 +75,15 @@ 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)
if err != nil {
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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -141,20 +141,20 @@ 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)
if err != nil {
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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/webapi/controllers/corecontracts/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions packages/webapi/controllers/corecontracts/governance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit a8a82a9

Please sign in to comment.