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

Reuse rpcv6 BlockWithTxHashes for v7 #2449

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 2 additions & 9 deletions rpc/v7/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ type BlockWithTxs struct {
Transactions []*Transaction `json:"transactions"`
}

// https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L1109
type BlockWithTxHashes struct {
Status rpcv6.BlockStatus `json:"status,omitempty"`
rpcv6.BlockHeader
TxnHashes []*felt.Felt `json:"transactions"`
}

type TransactionWithReceipt struct {
Transaction *Transaction `json:"transaction"`
Receipt *TransactionReceipt `json:"receipt"`
Expand All @@ -93,7 +86,7 @@ type BlockWithReceipts struct {
//
// It follows the specification defined here:
// https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L11
func (h *Handler) BlockWithTxHashes(id BlockID) (*BlockWithTxHashes, *jsonrpc.Error) {
func (h *Handler) BlockWithTxHashes(id BlockID) (*rpcv6.BlockWithTxHashes, *jsonrpc.Error) {
block, rpcErr := h.blockByID(&id)
if rpcErr != nil {
return nil, rpcErr
Expand All @@ -109,7 +102,7 @@ func (h *Handler) BlockWithTxHashes(id BlockID) (*BlockWithTxHashes, *jsonrpc.Er
return nil, rpcErr
}

return &BlockWithTxHashes{
return &rpcv6.BlockWithTxHashes{
Status: status,
BlockHeader: adaptBlockHeader(block.Header),
TxnHashes: txnHashes,
Expand Down
6 changes: 3 additions & 3 deletions rpc/v7/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestBlockWithTxHashes(t *testing.T) {
require.NoError(t, err)
latestBlockHash := latestBlock.Hash

checkBlock := func(t *testing.T, b *rpcv7.BlockWithTxHashes) {
checkBlock := func(t *testing.T, b *rpcv6.BlockWithTxHashes) {
t.Helper()
assert.Equal(t, latestBlock.Hash, b.Hash)
assert.Equal(t, latestBlock.GlobalStateRoot, b.NewRoot)
Expand All @@ -147,7 +147,7 @@ func TestBlockWithTxHashes(t *testing.T) {
}
}

checkLatestBlock := func(t *testing.T, b *rpcv7.BlockWithTxHashes) {
checkLatestBlock := func(t *testing.T, b *rpcv6.BlockWithTxHashes) {
t.Helper()
if latestBlock.Hash != nil {
assert.Equal(t, latestBlock.Number, *b.Number)
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestBlockWithTxs(t *testing.T) {
require.NoError(t, err)
latestBlockHash := latestBlock.Hash

checkLatestBlock := func(t *testing.T, blockWithTxHashes *rpcv7.BlockWithTxHashes, blockWithTxs *rpcv7.BlockWithTxs) {
checkLatestBlock := func(t *testing.T, blockWithTxHashes *rpcv6.BlockWithTxHashes, blockWithTxs *rpcv7.BlockWithTxs) {
t.Helper()
assert.Equal(t, blockWithTxHashes.BlockHeader, blockWithTxs.BlockHeader)
assert.Equal(t, len(blockWithTxHashes.TxnHashes), len(blockWithTxs.Transactions))
Expand Down
Loading