Skip to content

Commit e0cbb64

Browse files
galt-trCopilot
andauthored
Remove init logic from coinbase placeholder (#7)
* Remove init logic from coinbase placeholder * Update coinbase_placeholder_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 877793a commit e0cbb64

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

.golangci.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,16 @@
4444
},
4545
"linters": {
4646
"disable": [
47-
"gochecknoglobals",
4847
"gocritic",
4948
"godot",
5049
"godox",
5150
"testifylint",
5251
"revive",
53-
"gochecknoinits",
5452
"forbidigo",
5553
"err113",
5654
"errorlint",
5755
"gosec",
58-
"unused",
59-
"gomoddirectives"
56+
"unused"
6057
],
6158
"enable": [
6259
"asasalint",

coinbase_placeholder.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,17 @@ var (
2828
FrozenBytesTxHash = chainhash.Hash(FrozenBytesTxBytes)
2929
)
3030

31-
var (
32-
CoinbasePlaceholderTx *bt.Tx
33-
coinbasePlaceholderTxHash *chainhash.Hash
34-
)
35-
36-
func init() {
37-
CoinbasePlaceholderTx = bt.NewTx()
38-
CoinbasePlaceholderTx.Version = 0xFFFFFFFF
39-
CoinbasePlaceholderTx.LockTime = 0xFFFFFFFF
40-
41-
coinbasePlaceholderTxHash = CoinbasePlaceholderTx.TxIDChainHash()
31+
func generateCoinbasePlaceholderTx() *bt.Tx {
32+
tx := bt.NewTx()
33+
tx.Version = 0xFFFFFFFF
34+
tx.LockTime = 0xFFFFFFFF
35+
return tx
4236
}
4337

38+
// IsCoinbasePlaceHolderTx checks if the given transaction is a coinbase placeholder transaction.
4439
func IsCoinbasePlaceHolderTx(tx *bt.Tx) bool {
40+
coinbasePlaceholderTx := generateCoinbasePlaceholderTx()
41+
42+
coinbasePlaceholderTxHash := coinbasePlaceholderTx.TxIDChainHash()
4543
return tx.TxIDChainHash().IsEqual(coinbasePlaceholderTxHash)
4644
}

coinbase_placeholder_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import (
88
)
99

1010
func TestCoinbasePlaceholderTx(t *testing.T) {
11-
assert.True(t, IsCoinbasePlaceHolderTx(CoinbasePlaceholderTx))
12-
assert.Equal(t, CoinbasePlaceholderTx.Version, uint32(0xFFFFFFFF))
13-
assert.Equal(t, CoinbasePlaceholderTx.LockTime, uint32(0xFFFFFFFF))
14-
assert.Equal(t, CoinbasePlaceholderTx.TxIDChainHash(), coinbasePlaceholderTxHash)
11+
coinbasePlaceholderTx := generateCoinbasePlaceholderTx()
12+
coinbasePlaceholderTxHash := coinbasePlaceholderTx.TxIDChainHash()
13+
assert.True(t, IsCoinbasePlaceHolderTx(coinbasePlaceholderTx))
14+
assert.Equal(t, uint32(0xFFFFFFFF), coinbasePlaceholderTx.Version)
15+
assert.Equal(t, coinbasePlaceholderTx.LockTime, uint32(0xFFFFFFFF))
16+
assert.Equal(t, coinbasePlaceholderTx.TxIDChainHash(), coinbasePlaceholderTxHash)
1517
assert.False(t, IsCoinbasePlaceHolderTx(bt.NewTx()))
16-
assert.Equal(t, "a8502e9c08b3c851201a71d25bf29fd38a664baedb777318b12d19242f0e46ab", CoinbasePlaceholderTx.TxIDChainHash().String())
18+
assert.Equal(t, "a8502e9c08b3c851201a71d25bf29fd38a664baedb777318b12d19242f0e46ab", coinbasePlaceholderTx.TxIDChainHash().String())
1719
}

0 commit comments

Comments
 (0)