Skip to content

Commit d655473

Browse files
committed
update block header fields
1 parent b56b045 commit d655473

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

block/header.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ const (
1717

1818
// Header represents a Bitcoin block header (80 bytes)
1919
type Header struct {
20-
Version int32 `json:"version"` // 4 bytes - Block version
21-
PrevBlock chainhash.Hash `json:"prevBlock"` // 32 bytes - Previous block hash
22-
MerkleRoot chainhash.Hash `json:"merkleRoot"` // 32 bytes - Merkle root hash
23-
Timestamp uint32 `json:"timestamp"` // 4 bytes - Block timestamp (Unix time)
24-
Bits uint32 `json:"bits"` // 4 bytes - Difficulty target
25-
Nonce uint32 `json:"nonce"` // 4 bytes - Nonce
20+
Version int32 `json:"version"` // 4 bytes - Block version
21+
PrevHash chainhash.Hash `json:"previousHash"` // 32 bytes - Previous block hash
22+
MerkleRoot chainhash.Hash `json:"merkleRoot"` // 32 bytes - Merkle root hash
23+
Timestamp uint32 `json:"time"` // 4 bytes - Block timestamp (Unix time)
24+
Bits uint32 `json:"bits"` // 4 bytes - Difficulty target
25+
Nonce uint32 `json:"nonce"` // 4 bytes - Nonce
2626
}
2727

2828
// NewHeaderFromBytes creates a BlockHeader from an 80-byte slice
@@ -40,7 +40,7 @@ func NewHeaderFromBytes(data []byte) (*Header, error) {
4040
}
4141

4242
// Read previous block hash (32 bytes)
43-
if _, err := io.ReadFull(r, h.PrevBlock[:]); err != nil {
43+
if _, err := io.ReadFull(r, h.PrevHash[:]); err != nil {
4444
return nil, fmt.Errorf("failed to read prev block hash: %w", err)
4545
}
4646

@@ -85,7 +85,7 @@ func (h *Header) Bytes() []byte {
8585
_ = binary.Write(buf, binary.LittleEndian, h.Version)
8686

8787
// Write previous block hash (32 bytes)
88-
buf.Write(h.PrevBlock[:])
88+
buf.Write(h.PrevHash[:])
8989

9090
// Write merkle root (32 bytes)
9191
buf.Write(h.MerkleRoot[:])
@@ -115,5 +115,5 @@ func (h *Header) Hash() chainhash.Hash {
115115
// String returns a string representation of the header
116116
func (h *Header) String() string {
117117
return fmt.Sprintf("Header{Hash: %s, PrevBlock: %s, Height: ?, Bits: %d}",
118-
h.Hash().String(), h.PrevBlock.String(), h.Bits)
118+
h.Hash().String(), h.PrevHash.String(), h.Bits)
119119
}

block/header_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestHeaderPrevBlockAndMerkleRoot(t *testing.T) {
105105
t.Fatalf("NewHeaderFromHex() error = %v", err)
106106
}
107107

108-
prevBlockStr := header.PrevBlock.String()
108+
prevBlockStr := header.PrevHash.String()
109109
if prevBlockStr != expectedPrevBlock {
110110
t.Errorf("PrevBlock = %s, want %s", prevBlockStr, expectedPrevBlock)
111111
}

0 commit comments

Comments
 (0)