From 77843124733b456a179ebc8a13ddc00c733b4124 Mon Sep 17 00:00:00 2001 From: Chris Marslender Date: Sat, 23 Nov 2024 17:40:31 -0600 Subject: [PATCH] Add IsTransactionBlock helper (#180) * Add IsTransactionBlock helper * Fmt --- pkg/config/env_test.go | 6 +++--- pkg/types/block.go | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/config/env_test.go b/pkg/config/env_test.go index 1de7f73..2cd4902 100644 --- a/pkg/config/env_test.go +++ b/pkg/config/env_test.go @@ -112,7 +112,7 @@ func TestChiaConfig_SetFieldByPath_Lists(t *testing.T) { // First reset defaultConfig.Seeder.StaticPeers = []string{} assert.Equal(t, []string{}, defaultConfig.Seeder.StaticPeers) - err = defaultConfig.SetFieldByPath([]string{"seeder", "static_peers"}, []string{"node-test.chia.net","node-test-2.chia.net"}) + err = defaultConfig.SetFieldByPath([]string{"seeder", "static_peers"}, []string{"node-test.chia.net", "node-test-2.chia.net"}) assert.NoError(t, err) assert.Equal(t, []string{"node-test.chia.net", "node-test-2.chia.net"}, defaultConfig.Seeder.StaticPeers) @@ -126,8 +126,8 @@ func TestChiaConfig_SetFieldByPath_Lists(t *testing.T) { defaultConfig.FullNode.FullNodePeers = []config.Peer{} assert.Equal(t, []config.Peer{}, defaultConfig.FullNode.FullNodePeers) err = defaultConfig.SetFieldByPath([]string{"full_node", "full_node_peers"}, []config.Peer{ - {Host: "testnode.example.com",Port:1234}, - {Host:"testnode2.example.com",Port:5678}, + {Host: "testnode.example.com", Port: 1234}, + {Host: "testnode2.example.com", Port: 5678}, }) assert.NoError(t, err) assert.Equal(t, []config.Peer{ diff --git a/pkg/types/block.go b/pkg/types/block.go index 93747df..f58a209 100644 --- a/pkg/types/block.go +++ b/pkg/types/block.go @@ -41,6 +41,14 @@ type BlockRecord struct { SubEpochSummaryIncluded mo.Option[SubEpochSummary] `json:"sub_epoch_summary_included"` } +// IsTransactionBlock returns true if the block is considered a transaction block +// Only transaction blocks have timestamps +// Also matches how chia determines what is a transaction block +// https://github.com/Chia-Network/chia-blockchain/blob/dfaf70895a0923d5ac60774dd1d64a200f445e6a/chia/consensus/block_record.py#L31 +func (b *BlockRecord) IsTransactionBlock() bool { + return b.Timestamp.IsPresent() +} + // FullBlock a full block // https://github.com/Chia-Network/chia_rs/blob/main/crates/chia-protocol/src/fullblock.rs#L13 type FullBlock struct {