From f4c0817131e45091b2421876bd6c15f45789899a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daria=20Dziuba=C5=82towska?= Date: Tue, 21 Nov 2023 15:58:45 +0100 Subject: [PATCH] Address comments --- components/restapi/core/accounts.go | 10 +++++----- components/restapi/core/component.go | 6 +++--- pkg/restapi/restapi.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/components/restapi/core/accounts.go b/components/restapi/core/accounts.go index 6a4bff320..0efcdbb59 100644 --- a/components/restapi/core/accounts.go +++ b/components/restapi/core/accounts.go @@ -32,14 +32,14 @@ func congestionByAccountAddress(c echo.Context) (*apimodels.CongestionResponse, } hrp := deps.Protocol.CommittedAPI().ProtocolParameters().Bech32HRP() - address, err := httpserver.ParseBech32AddressParam(c, hrp, restapipkg.ParameterAddress) + address, err := httpserver.ParseBech32AddressParam(c, hrp, restapipkg.ParameterBech32Address) if err != nil { return nil, err } accountAddress, ok := address.(*iotago.AccountAddress) if !ok { - return nil, ierrors.Wrapf(echo.ErrInternalServerError, "failed to assert account address %s", c.Param(restapipkg.ParameterAddress)) + return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "address %s is not an account address", c.Param(restapipkg.ParameterBech32Address)) } accountID := accountAddress.AccountID() @@ -116,14 +116,14 @@ func validators(c echo.Context) (*apimodels.ValidatorsResponse, error) { func validatorByAccountAddress(c echo.Context) (*apimodels.ValidatorResponse, error) { hrp := deps.Protocol.CommittedAPI().ProtocolParameters().Bech32HRP() - address, err := httpserver.ParseBech32AddressQueryParam(c, hrp, restapipkg.ParameterAddress) + address, err := httpserver.ParseBech32AddressParam(c, hrp, restapipkg.ParameterBech32Address) if err != nil { - return nil, ierrors.Wrapf(err, "failed to parse account address %s", c.Param(restapipkg.ParameterAddress)) + return nil, err } accountAddress, ok := address.(*iotago.AccountAddress) if !ok { - return nil, ierrors.Wrapf(echo.ErrInternalServerError, "failed to assert account address %s", c.Param(restapipkg.ParameterAddress)) + return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "address %s is not an account address", c.Param(restapipkg.ParameterBech32Address)) } latestCommittedSlot := deps.Protocol.MainEngineInstance().SyncManager.LatestCommitment().Slot() diff --git a/components/restapi/core/component.go b/components/restapi/core/component.go index 92c69fe39..a36c8bd30 100644 --- a/components/restapi/core/component.go +++ b/components/restapi/core/component.go @@ -112,10 +112,10 @@ const ( RouteCommitmentByIndexUTXOChanges = "/commitments/by-index/:" + restapipkg.ParameterSlotIndex + "/utxo-changes" // RouteCongestion is the route for getting the current congestion state and all account related useful details as block issuance credits. - // GET returns the congestion state related to the specified account. (optional query parameters: "commitmentID" to specify the used commitment) + // GET returns the congestion state related to the specified account address. (optional query parameters: "commitmentID" to specify the used commitment) // MIMEApplicationJSON => json. // MIMEApplicationVendorIOTASerializerV2 => bytes. - RouteCongestion = "/accounts/:" + restapipkg.ParameterAddress + "/congestion" + RouteCongestion = "/accounts/:" + restapipkg.ParameterBech32Address + "/congestion" // RouteValidators is the route for getting informations about the current validators. // GET returns the paginated response with the list of validators. @@ -127,7 +127,7 @@ const ( // GET returns the validator details. // MIMEApplicationJSON => json. // MIMEApplicationVendorIOTASerializerV2 => bytes. - RouteValidatorsAccount = "/validators/:" + restapipkg.ParameterAddress + RouteValidatorsAccount = "/validators/:" + restapipkg.ParameterBech32Address // RouteRewards is the route for getting the rewards for staking or delegation based on staking account or delegation output. // Rewards are decayed up to returned epochEnd index. diff --git a/pkg/restapi/restapi.go b/pkg/restapi/restapi.go index cd094afa4..4c7f3de96 100644 --- a/pkg/restapi/restapi.go +++ b/pkg/restapi/restapi.go @@ -27,8 +27,8 @@ const ( // ParameterCommitmentID is used to identify a slot commitment by its ID. ParameterCommitmentID = "commitmentID" - // ParameterAddress is used to identify an account by its address. - ParameterAddress = "address" + // ParameterBech32Address is used to to represent bech32 address. + ParameterBech32Address = "bech32Address" // ParameterPeerID is used to identify a peer. ParameterPeerID = "peerID"