diff --git a/api/groups/urlParams.go b/api/groups/urlParams.go index 1aa3c140..98ba22ed 100644 --- a/api/groups/urlParams.go +++ b/api/groups/urlParams.go @@ -23,7 +23,12 @@ func parseBlockQueryOptions(c *gin.Context) (common.BlockQueryOptions, error) { return common.BlockQueryOptions{}, err } - options := common.BlockQueryOptions{WithTransactions: withTxs, WithLogs: withLogs} + forHyperblock, err := parseBoolUrlParam(c, common.UrlParameterForHyperblock) + if err != nil { + return common.BlockQueryOptions{}, err + } + + options := common.BlockQueryOptions{WithTransactions: withTxs, WithLogs: withLogs, ForHyperblock: forHyperblock} return options, nil } diff --git a/api/groups/urlParams_test.go b/api/groups/urlParams_test.go index 9eb17614..3892c02b 100644 --- a/api/groups/urlParams_test.go +++ b/api/groups/urlParams_test.go @@ -12,13 +12,13 @@ import ( ) func TestParseBlockQueryOptions(t *testing.T) { - options, err := parseBlockQueryOptions(createDummyGinContextWithQuery("withTxs=true&withLogs=true")) + options, err := parseBlockQueryOptions(createDummyGinContextWithQuery("withTxs=true&withLogs=true&forHyperblock=true")) require.Nil(t, err) - require.Equal(t, common.BlockQueryOptions{WithTransactions: true, WithLogs: true}, options) + require.Equal(t, common.BlockQueryOptions{WithTransactions: true, WithLogs: true, ForHyperblock: true}, options) options, err = parseBlockQueryOptions(createDummyGinContextWithQuery("withTxs=true")) require.Nil(t, err) - require.Equal(t, common.BlockQueryOptions{WithTransactions: true, WithLogs: false}, options) + require.Equal(t, common.BlockQueryOptions{WithTransactions: true, WithLogs: false, ForHyperblock: false}, options) options, err = parseBlockQueryOptions(createDummyGinContextWithQuery("withTxs=foobar")) require.NotNil(t, err) diff --git a/cmd/proxy/config/swagger/openapi.json b/cmd/proxy/config/swagger/openapi.json index 8d3b7497..af5937f5 100644 --- a/cmd/proxy/config/swagger/openapi.json +++ b/cmd/proxy/config/swagger/openapi.json @@ -645,7 +645,7 @@ } } }, - "/block/{shard}/by-nonce/{nonce}?withTxs=true": { + "/block/{shard}/by-nonce/{nonce}?withTxs=true&withLogs=true&forHyperblock=true": { "get": { "tags": [ "block" @@ -725,7 +725,7 @@ } } }, - "/block/{shard}/by-hash/{hash}?withTxs=true": { + "/block/{shard}/by-hash/{hash}?withTxs=true&withLogs=true&forHyperblock=true": { "get": { "tags": [ "block" diff --git a/common/options.go b/common/options.go index b39df0f6..e6b861e0 100644 --- a/common/options.go +++ b/common/options.go @@ -13,6 +13,8 @@ const ( UrlParameterWithTransactions = "withTxs" // UrlParameterWithLogs represents the name of an URL parameter UrlParameterWithLogs = "withLogs" + // UrlParameterForHyperblock represents the name of an URL parameter + UrlParameterForHyperblock = "forHyperblock" // UrlParameterNotarizedAtSource represents the name of an URL parameter UrlParameterNotarizedAtSource = "notarizedAtSource" // UrlParameterOnFinalBlock represents the name of an URL parameter @@ -55,6 +57,7 @@ const ( type BlockQueryOptions struct { WithTransactions bool WithLogs bool + ForHyperblock bool } // HyperblockQueryOptions holds options for hyperblock queries @@ -100,6 +103,9 @@ func BuildUrlWithBlockQueryOptions(path string, options BlockQueryOptions) strin if options.WithLogs { query.Set(UrlParameterWithLogs, "true") } + if options.ForHyperblock { + query.Set(UrlParameterForHyperblock, "true") + } u.RawQuery = query.Encode() return u.String() diff --git a/common/options_test.go b/common/options_test.go index c70524e4..1a1a6258 100644 --- a/common/options_test.go +++ b/common/options_test.go @@ -22,12 +22,14 @@ func TestBuildUrlWithBlockQueryOptions_ShouldWork(t *testing.T) { builtUrl = BuildUrlWithBlockQueryOptions("/block/by-nonce/15", BlockQueryOptions{ WithTransactions: true, WithLogs: true, + ForHyperblock: true, }) parsed, err := url.Parse(builtUrl) require.Nil(t, err) require.Equal(t, "/block/by-nonce/15", parsed.Path) require.Equal(t, "true", parsed.Query().Get("withTxs")) require.Equal(t, "true", parsed.Query().Get("withLogs")) + require.Equal(t, "true", parsed.Query().Get("forHyperblock")) } func TestBuildUrlWithAccountQueryOptions_ShouldWork(t *testing.T) { diff --git a/process/blockProcessor.go b/process/blockProcessor.go index 63dfaedd..f70e438a 100644 --- a/process/blockProcessor.go +++ b/process/blockProcessor.go @@ -37,7 +37,7 @@ const ( // BlockProcessor handles blocks retrieving type BlockProcessor struct { - proc Processor + proc Processor } // NewBlockProcessor will create a new block processor @@ -47,11 +47,10 @@ func NewBlockProcessor(proc Processor) (*BlockProcessor, error) { } return &BlockProcessor{ - proc: proc, + proc: proc, }, nil } - // GetBlockByHash will return the block based on its hash func (bp *BlockProcessor) GetBlockByHash(shardID uint32, hash string, options common.BlockQueryOptions) (*data.BlockApiResponse, error) { observers, err := bp.getObserversOrFullHistoryNodes(shardID) @@ -120,6 +119,7 @@ func (bp *BlockProcessor) GetHyperBlockByHash(hash string, options common.Hyperb blockQueryOptions := common.BlockQueryOptions{ WithTransactions: true, WithLogs: options.WithLogs, + ForHyperblock: true, } metaBlockResponse, err := bp.GetBlockByHash(core.MetachainShardId, hash, blockQueryOptions) @@ -186,6 +186,7 @@ func (bp *BlockProcessor) GetHyperBlockByNonce(nonce uint64, options common.Hype blockQueryOptions := common.BlockQueryOptions{ WithTransactions: true, WithLogs: options.WithLogs, + ForHyperblock: true, } metaBlockResponse, err := bp.GetBlockByNonce(core.MetachainShardId, nonce, blockQueryOptions) diff --git a/process/blockProcessor_test.go b/process/blockProcessor_test.go index 2451f03b..e9740d83 100644 --- a/process/blockProcessor_test.go +++ b/process/blockProcessor_test.go @@ -1174,7 +1174,7 @@ func TestBlockProcessor_GetHyperBlockByNonceWithAlteredAccounts(t *testing.T) { switch callGetEndpointCt { case 0: require.Equal(t, &data.BlockApiResponse{}, value) - require.Equal(t, "/block/by-nonce/4?withTxs=true", path) + require.Equal(t, "/block/by-nonce/4?forHyperblock=true&withTxs=true", path) ret := value.(*data.BlockApiResponse) ret.Code = data.ReturnCodeSuccess @@ -1193,7 +1193,7 @@ func TestBlockProcessor_GetHyperBlockByNonceWithAlteredAccounts(t *testing.T) { } case 1: require.Equal(t, &data.BlockApiResponse{}, value) - require.Equal(t, "/block/by-hash/hash1?withTxs=true", path) + require.Equal(t, "/block/by-hash/hash1?forHyperblock=true&withTxs=true", path) ret := value.(*data.BlockApiResponse) ret.Code = data.ReturnCodeSuccess @@ -1207,7 +1207,7 @@ func TestBlockProcessor_GetHyperBlockByNonceWithAlteredAccounts(t *testing.T) { ret.Data.Accounts = []*alteredAccount.AlteredAccount{alteredAcc1} case 3: require.Equal(t, &data.BlockApiResponse{}, value) - require.Equal(t, "/block/by-hash/hash2?withTxs=true", path) + require.Equal(t, "/block/by-hash/hash2?forHyperblock=true&withTxs=true", path) ret := value.(*data.BlockApiResponse) ret.Code = data.ReturnCodeSuccess @@ -1291,7 +1291,7 @@ func TestBlockProcessor_GetHyperBlockByHashWithAlteredAccounts(t *testing.T) { switch callGetEndpointCt { case 0: require.Equal(t, &data.BlockApiResponse{}, value) - require.Equal(t, "/block/by-hash/abcdef?withTxs=true", path) + require.Equal(t, "/block/by-hash/abcdef?forHyperblock=true&withTxs=true", path) ret := value.(*data.BlockApiResponse) ret.Code = data.ReturnCodeSuccess @@ -1310,7 +1310,7 @@ func TestBlockProcessor_GetHyperBlockByHashWithAlteredAccounts(t *testing.T) { } case 1: require.Equal(t, &data.BlockApiResponse{}, value) - require.Equal(t, "/block/by-hash/hash1?withTxs=true", path) + require.Equal(t, "/block/by-hash/hash1?forHyperblock=true&withTxs=true", path) ret := value.(*data.BlockApiResponse) ret.Code = data.ReturnCodeSuccess @@ -1324,7 +1324,7 @@ func TestBlockProcessor_GetHyperBlockByHashWithAlteredAccounts(t *testing.T) { ret.Data.Accounts = []*alteredAccount.AlteredAccount{alteredAcc1} case 3: require.Equal(t, &data.BlockApiResponse{}, value) - require.Equal(t, "/block/by-hash/hash2?withTxs=true", path) + require.Equal(t, "/block/by-hash/hash2?forHyperblock=true&withTxs=true", path) ret := value.(*data.BlockApiResponse) ret.Code = data.ReturnCodeSuccess