Skip to content

Commit 0a7ed7b

Browse files
authored
Merge branch 'rc/spica-patch-relayedv3' into relayedv3
2 parents 6705362 + ffc3f61 commit 0a7ed7b

File tree

7 files changed

+29
-15
lines changed

7 files changed

+29
-15
lines changed

api/groups/urlParams.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ func parseBlockQueryOptions(c *gin.Context) (common.BlockQueryOptions, error) {
2323
return common.BlockQueryOptions{}, err
2424
}
2525

26-
options := common.BlockQueryOptions{WithTransactions: withTxs, WithLogs: withLogs}
26+
forHyperblock, err := parseBoolUrlParam(c, common.UrlParameterForHyperblock)
27+
if err != nil {
28+
return common.BlockQueryOptions{}, err
29+
}
30+
31+
options := common.BlockQueryOptions{WithTransactions: withTxs, WithLogs: withLogs, ForHyperblock: forHyperblock}
2732
return options, nil
2833
}
2934

api/groups/urlParams_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212
)
1313

1414
func TestParseBlockQueryOptions(t *testing.T) {
15-
options, err := parseBlockQueryOptions(createDummyGinContextWithQuery("withTxs=true&withLogs=true"))
15+
options, err := parseBlockQueryOptions(createDummyGinContextWithQuery("withTxs=true&withLogs=true&forHyperblock=true"))
1616
require.Nil(t, err)
17-
require.Equal(t, common.BlockQueryOptions{WithTransactions: true, WithLogs: true}, options)
17+
require.Equal(t, common.BlockQueryOptions{WithTransactions: true, WithLogs: true, ForHyperblock: true}, options)
1818

1919
options, err = parseBlockQueryOptions(createDummyGinContextWithQuery("withTxs=true"))
2020
require.Nil(t, err)
21-
require.Equal(t, common.BlockQueryOptions{WithTransactions: true, WithLogs: false}, options)
21+
require.Equal(t, common.BlockQueryOptions{WithTransactions: true, WithLogs: false, ForHyperblock: false}, options)
2222

2323
options, err = parseBlockQueryOptions(createDummyGinContextWithQuery("withTxs=foobar"))
2424
require.NotNil(t, err)

cmd/proxy/config/swagger/openapi.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@
645645
}
646646
}
647647
},
648-
"/block/{shard}/by-nonce/{nonce}?withTxs=true": {
648+
"/block/{shard}/by-nonce/{nonce}?withTxs=true&withLogs=true&forHyperblock=true": {
649649
"get": {
650650
"tags": [
651651
"block"
@@ -725,7 +725,7 @@
725725
}
726726
}
727727
},
728-
"/block/{shard}/by-hash/{hash}?withTxs=true": {
728+
"/block/{shard}/by-hash/{hash}?withTxs=true&withLogs=true&forHyperblock=true": {
729729
"get": {
730730
"tags": [
731731
"block"

common/options.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const (
1313
UrlParameterWithTransactions = "withTxs"
1414
// UrlParameterWithLogs represents the name of an URL parameter
1515
UrlParameterWithLogs = "withLogs"
16+
// UrlParameterForHyperblock represents the name of an URL parameter
17+
UrlParameterForHyperblock = "forHyperblock"
1618
// UrlParameterNotarizedAtSource represents the name of an URL parameter
1719
UrlParameterNotarizedAtSource = "notarizedAtSource"
1820
// UrlParameterOnFinalBlock represents the name of an URL parameter
@@ -55,6 +57,7 @@ const (
5557
type BlockQueryOptions struct {
5658
WithTransactions bool
5759
WithLogs bool
60+
ForHyperblock bool
5861
}
5962

6063
// HyperblockQueryOptions holds options for hyperblock queries
@@ -100,6 +103,9 @@ func BuildUrlWithBlockQueryOptions(path string, options BlockQueryOptions) strin
100103
if options.WithLogs {
101104
query.Set(UrlParameterWithLogs, "true")
102105
}
106+
if options.ForHyperblock {
107+
query.Set(UrlParameterForHyperblock, "true")
108+
}
103109

104110
u.RawQuery = query.Encode()
105111
return u.String()

common/options_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ func TestBuildUrlWithBlockQueryOptions_ShouldWork(t *testing.T) {
2222
builtUrl = BuildUrlWithBlockQueryOptions("/block/by-nonce/15", BlockQueryOptions{
2323
WithTransactions: true,
2424
WithLogs: true,
25+
ForHyperblock: true,
2526
})
2627
parsed, err := url.Parse(builtUrl)
2728
require.Nil(t, err)
2829
require.Equal(t, "/block/by-nonce/15", parsed.Path)
2930
require.Equal(t, "true", parsed.Query().Get("withTxs"))
3031
require.Equal(t, "true", parsed.Query().Get("withLogs"))
32+
require.Equal(t, "true", parsed.Query().Get("forHyperblock"))
3133
}
3234

3335
func TestBuildUrlWithAccountQueryOptions_ShouldWork(t *testing.T) {

process/blockProcessor.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const (
3737

3838
// BlockProcessor handles blocks retrieving
3939
type BlockProcessor struct {
40-
proc Processor
40+
proc Processor
4141
}
4242

4343
// NewBlockProcessor will create a new block processor
@@ -47,11 +47,10 @@ func NewBlockProcessor(proc Processor) (*BlockProcessor, error) {
4747
}
4848

4949
return &BlockProcessor{
50-
proc: proc,
50+
proc: proc,
5151
}, nil
5252
}
5353

54-
5554
// GetBlockByHash will return the block based on its hash
5655
func (bp *BlockProcessor) GetBlockByHash(shardID uint32, hash string, options common.BlockQueryOptions) (*data.BlockApiResponse, error) {
5756
observers, err := bp.getObserversOrFullHistoryNodes(shardID)
@@ -120,6 +119,7 @@ func (bp *BlockProcessor) GetHyperBlockByHash(hash string, options common.Hyperb
120119
blockQueryOptions := common.BlockQueryOptions{
121120
WithTransactions: true,
122121
WithLogs: options.WithLogs,
122+
ForHyperblock: true,
123123
}
124124

125125
metaBlockResponse, err := bp.GetBlockByHash(core.MetachainShardId, hash, blockQueryOptions)
@@ -186,6 +186,7 @@ func (bp *BlockProcessor) GetHyperBlockByNonce(nonce uint64, options common.Hype
186186
blockQueryOptions := common.BlockQueryOptions{
187187
WithTransactions: true,
188188
WithLogs: options.WithLogs,
189+
ForHyperblock: true,
189190
}
190191

191192
metaBlockResponse, err := bp.GetBlockByNonce(core.MetachainShardId, nonce, blockQueryOptions)

process/blockProcessor_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ func TestBlockProcessor_GetHyperBlockByNonceWithAlteredAccounts(t *testing.T) {
11741174
switch callGetEndpointCt {
11751175
case 0:
11761176
require.Equal(t, &data.BlockApiResponse{}, value)
1177-
require.Equal(t, "/block/by-nonce/4?withTxs=true", path)
1177+
require.Equal(t, "/block/by-nonce/4?forHyperblock=true&withTxs=true", path)
11781178

11791179
ret := value.(*data.BlockApiResponse)
11801180
ret.Code = data.ReturnCodeSuccess
@@ -1193,7 +1193,7 @@ func TestBlockProcessor_GetHyperBlockByNonceWithAlteredAccounts(t *testing.T) {
11931193
}
11941194
case 1:
11951195
require.Equal(t, &data.BlockApiResponse{}, value)
1196-
require.Equal(t, "/block/by-hash/hash1?withTxs=true", path)
1196+
require.Equal(t, "/block/by-hash/hash1?forHyperblock=true&withTxs=true", path)
11971197

11981198
ret := value.(*data.BlockApiResponse)
11991199
ret.Code = data.ReturnCodeSuccess
@@ -1207,7 +1207,7 @@ func TestBlockProcessor_GetHyperBlockByNonceWithAlteredAccounts(t *testing.T) {
12071207
ret.Data.Accounts = []*alteredAccount.AlteredAccount{alteredAcc1}
12081208
case 3:
12091209
require.Equal(t, &data.BlockApiResponse{}, value)
1210-
require.Equal(t, "/block/by-hash/hash2?withTxs=true", path)
1210+
require.Equal(t, "/block/by-hash/hash2?forHyperblock=true&withTxs=true", path)
12111211

12121212
ret := value.(*data.BlockApiResponse)
12131213
ret.Code = data.ReturnCodeSuccess
@@ -1291,7 +1291,7 @@ func TestBlockProcessor_GetHyperBlockByHashWithAlteredAccounts(t *testing.T) {
12911291
switch callGetEndpointCt {
12921292
case 0:
12931293
require.Equal(t, &data.BlockApiResponse{}, value)
1294-
require.Equal(t, "/block/by-hash/abcdef?withTxs=true", path)
1294+
require.Equal(t, "/block/by-hash/abcdef?forHyperblock=true&withTxs=true", path)
12951295

12961296
ret := value.(*data.BlockApiResponse)
12971297
ret.Code = data.ReturnCodeSuccess
@@ -1310,7 +1310,7 @@ func TestBlockProcessor_GetHyperBlockByHashWithAlteredAccounts(t *testing.T) {
13101310
}
13111311
case 1:
13121312
require.Equal(t, &data.BlockApiResponse{}, value)
1313-
require.Equal(t, "/block/by-hash/hash1?withTxs=true", path)
1313+
require.Equal(t, "/block/by-hash/hash1?forHyperblock=true&withTxs=true", path)
13141314

13151315
ret := value.(*data.BlockApiResponse)
13161316
ret.Code = data.ReturnCodeSuccess
@@ -1324,7 +1324,7 @@ func TestBlockProcessor_GetHyperBlockByHashWithAlteredAccounts(t *testing.T) {
13241324
ret.Data.Accounts = []*alteredAccount.AlteredAccount{alteredAcc1}
13251325
case 3:
13261326
require.Equal(t, &data.BlockApiResponse{}, value)
1327-
require.Equal(t, "/block/by-hash/hash2?withTxs=true", path)
1327+
require.Equal(t, "/block/by-hash/hash2?forHyperblock=true&withTxs=true", path)
13281328

13291329
ret := value.(*data.BlockApiResponse)
13301330
ret.Code = data.ReturnCodeSuccess

0 commit comments

Comments
 (0)