Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyperblock new parameter #475

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading