Skip to content

Commit

Permalink
Merge branch 'rc/spica-patch-relayedv3' into relayedv3
Browse files Browse the repository at this point in the history
  • Loading branch information
sstanculeanu authored Jan 9, 2025
2 parents 6705362 + ffc3f61 commit 0a7ed7b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
7 changes: 6 additions & 1 deletion api/groups/urlParams.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions api/groups/urlParams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/proxy/config/swagger/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions common/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,6 +57,7 @@ const (
type BlockQueryOptions struct {
WithTransactions bool
WithLogs bool
ForHyperblock bool
}

// HyperblockQueryOptions holds options for hyperblock queries
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions common/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions process/blockProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (

// BlockProcessor handles blocks retrieving
type BlockProcessor struct {
proc Processor
proc Processor
}

// NewBlockProcessor will create a new block processor
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions process/blockProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0a7ed7b

Please sign in to comment.