From e3f452f5e8740706b76ec2197d0b88593652ef60 Mon Sep 17 00:00:00 2001 From: Antonio Navarro Perez Date: Mon, 16 Sep 2024 13:34:08 +0200 Subject: [PATCH] Requested changes Signed-off-by: Antonio Navarro Perez --- backup/backup.go | 2 +- backup/backup_test.go | 4 ++-- backup/client/client.go | 7 ++++--- backup/client/http/http.go | 2 +- backup/mock_test.go | 10 +++++----- types/types.go | 2 +- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/backup/backup.go b/backup/backup.go index 59f5753..1d08049 100644 --- a/backup/backup.go +++ b/backup/backup.go @@ -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) } diff --git a/backup/backup_test.go b/backup/backup_test.go index 4448766..2624935 100644 --- a/backup/backup_test.go +++ b/backup/backup_test.go @@ -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") @@ -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") diff --git a/backup/client/client.go b/backup/client/client.go index 1038661..7e49e5d 100644 --- a/backup/client/client.go +++ b/backup/client/client.go @@ -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 { diff --git a/backup/client/http/http.go b/backup/client/http/http.go index 7c1e680..a6963ab 100644 --- a/backup/client/http/http.go +++ b/backup/client/http/http.go @@ -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) diff --git a/backup/mock_test.go b/backup/mock_test.go index 8e7ff02..a819843 100644 --- a/backup/mock_test.go +++ b/backup/mock_test.go @@ -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) { @@ -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 diff --git a/types/types.go b/types/types.go index b95ada7..e2fa1bf 100644 --- a/types/types.go +++ b/types/types.go @@ -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 }