Skip to content

Commit

Permalink
Requested changes
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Navarro Perez <[email protected]>
  • Loading branch information
ajnavarro committed Sep 16, 2024
1 parent 40bab66 commit e3f452f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *Service) ExecuteBackup(ctx context.Context, cfg Config) error {
totalTxs := uint64(0)

fetchAndWrite := func(height uint64) error {
block, txErr := s.client.GetBlockTransactions(height)
block, txErr := s.client.GetBlock(height)
if txErr != nil {
return fmt.Errorf("unable to fetch block transactions, %w", txErr)
}
Expand Down
4 changes: 2 additions & 2 deletions backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestBackup_ExecuteBackup_FixedRange(t *testing.T) {
getLatestBlockNumberFn: func() (uint64, error) {
return toBlock, nil
},
getBlockTransactionsFn: func(blockNum uint64) (*client.Block, error) {
getBlockFn: func(blockNum uint64) (*client.Block, error) {
// Sanity check
if blockNum < fromBlock && blockNum > toBlock {
t.Fatal("invalid block number requested")
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestBackup_ExecuteBackup_Watch(t *testing.T) {
getLatestBlockNumberFn: func() (uint64, error) {
return toBlock, nil
},
getBlockTransactionsFn: func(blockNum uint64) (*client.Block, error) {
getBlockFn: func(blockNum uint64) (*client.Block, error) {
// Sanity check
if blockNum < fromBlock && blockNum > toBlock {
t.Fatal("invalid block number requested")
Expand Down
7 changes: 4 additions & 3 deletions backup/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ type Client interface {
// GetLatestBlockNumber returns the latest block height from the chain
GetLatestBlockNumber() (uint64, error)

// GetBlockTransactions returns the transactions contained
// within the specified block, if any
GetBlockTransactions(uint64) (*Block, error)
// GetBlock returns the transactions contained
// within the specified block, if any, apart from the block height and
// its timestamp in milliseconds.
GetBlock(uint64) (*Block, error)
}

type Block struct {

Check failure on line 18 in backup/client/client.go

View workflow job for this annotation

GitHub Actions / Go Linter / lint

fieldalignment: struct with 24 pointer bytes could be 8 (govet)
Expand Down
2 changes: 1 addition & 1 deletion backup/client/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *Client) GetLatestBlockNumber() (uint64, error) {
return uint64(status.SyncInfo.LatestBlockHeight), nil
}

func (c *Client) GetBlockTransactions(blockNum uint64) (*client.Block, error) {
func (c *Client) GetBlock(blockNum uint64) (*client.Block, error) {
// Fetch the block
blockNumInt64 := int64(blockNum)

Expand Down
10 changes: 5 additions & 5 deletions backup/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (

type (
getLatestBlockNumberDelegate func() (uint64, error)
getBlockTransactionsDelegate func(uint64) (*client.Block, error)
getBlockDelegate func(uint64) (*client.Block, error)
)

type mockClient struct {
getLatestBlockNumberFn getLatestBlockNumberDelegate
getBlockTransactionsFn getBlockTransactionsDelegate
getBlockFn getBlockDelegate
}

func (m *mockClient) GetLatestBlockNumber() (uint64, error) {
Expand All @@ -22,9 +22,9 @@ func (m *mockClient) GetLatestBlockNumber() (uint64, error) {
return 0, nil
}

func (m *mockClient) GetBlockTransactions(blockNum uint64) (*client.Block, error) {
if m.getBlockTransactionsFn != nil {
return m.getBlockTransactionsFn(blockNum)
func (m *mockClient) GetBlock(blockNum uint64) (*client.Block, error) {
if m.getBlockFn != nil {
return m.getBlockFn(blockNum)
}

return nil, nil
Expand Down
2 changes: 1 addition & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import (
type TxData struct {
Tx std.Tx `json:"tx"`
BlockNum uint64 `json:"blockNum"`
Timestamp int64 `json:"bt"`
Timestamp int64 `json:"bt"` // Timestamp contains the block creation time in unix milliseconds

Check failure on line 12 in types/types.go

View workflow job for this annotation

GitHub Actions / Go Linter / lint

json(goCamel): got 'bt' want 'timestamp' (tagliatelle)
}

0 comments on commit e3f452f

Please sign in to comment.