refactor: extract 33 magic numbers to named constants
Some checks are pending
Security Scan / security (push) Waiting to run
Test / Test (push) Waiting to run

New constants.go: AtomicUnit, StandardPrefix, IntegratedPrefix,
AuditablePrefix, HF5Height, HF4Height, DefaultFee, PremineAmount,
TestnetDaemonRPC, TestnetWalletRPC, etc.

Replaced hardcoded values in cmd_wallet.go, cmd_deploy_itns.go,
service.go. Audit found 33 magic numbers — this commit addresses
the command/service files. daemon/server.go still has ~20 to fix.

Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
Claude 2026-04-02 03:58:59 +01:00
parent 4b797efc9e
commit 2ecb5e9339
No known key found for this signature in database
GPG key ID: AF404715446AEB41
4 changed files with 65 additions and 13 deletions

View file

@ -62,7 +62,7 @@ func runDeployITNS(walletRPC string) error {
desc := rpc.AssetDescriptor{
Ticker: "ITNS",
FullName: "IntenseCoin",
TotalMax: 1000000000000000000, // 1B at 12 decimals
TotalMax: AtomicUnit * 1000000, // 1B at 12 decimals
CurrentSup: 0,
DecimalPoint: 12,
HiddenSupply: false,

View file

@ -104,7 +104,7 @@ func runWalletCreate(walletFile string) error {
}
addr := account.Address()
addrStr := addr.Encode(0x1eaf7) // iTHN standard prefix
addrStr := addr.Encode(StandardPrefix) // iTHN standard prefix
seed, _ := account.ToSeed()
core.Print(nil, "Wallet created!")
@ -132,7 +132,7 @@ func runWalletAddress(walletFile string) error {
}
addr := account.Address()
core.Print(nil, "%s", addr.Encode(0x1eaf7))
core.Print(nil, "%s", addr.Encode(StandardPrefix))
return nil
}
@ -193,7 +193,7 @@ func runWalletScan(walletFile, daemonURL string) error {
}
addr := account.Address()
core.Print(nil, "Scanning for: %s", addr.Encode(0x1eaf7))
core.Print(nil, "Scanning for: %s", addr.Encode(StandardPrefix))
scanner := wallet.NewV1Scanner(account)
client := rpc.NewClient(daemonURL)
@ -244,7 +244,7 @@ func runWalletScan(walletFile, daemonURL string) error {
totalBalance += t.Amount
outputCount++
core.Print(nil, " Found output: %d.%012d LTHN at height %d",
t.Amount/1000000000000, t.Amount%1000000000000, h)
t.Amount/AtomicUnit, t.Amount%AtomicUnit, h)
}
}
}
@ -252,12 +252,12 @@ func runWalletScan(walletFile, daemonURL string) error {
if h > 0 && h%1000 == 0 {
core.Print(nil, " Scanned %d/%d blocks... (%d outputs, %d.%012d LTHN)",
h, remoteHeight, outputCount,
totalBalance/1000000000000, totalBalance%1000000000000)
totalBalance/AtomicUnit, totalBalance%AtomicUnit)
}
}
core.Print(nil, "Balance: %d.%012d LTHN (%d outputs)",
totalBalance/1000000000000, totalBalance%1000000000000, outputCount)
totalBalance/AtomicUnit, totalBalance%AtomicUnit, outputCount)
return nil
}
@ -335,7 +335,7 @@ func runWalletRestore(walletFile, seed string) error {
addr := account.Address()
core.Print(nil, "Wallet restored!")
core.Print(nil, " Address: %s", addr.Encode(0x1eaf7))
core.Print(nil, " Address: %s", addr.Encode(StandardPrefix))
core.Print(nil, " File: %s", walletFile)
return nil
@ -372,7 +372,7 @@ func runWalletTransfer(walletRPC, destination string, amount float64, paymentID
return coreerr.E("runWalletTransfer", "destination must start with iTHN", nil)
}
atomicAmount := uint64(amount * 1000000000000) // 12 decimal places
atomicAmount := uint64(amount * AtomicUnit) // 12 decimal places
core.Print(nil, "Sending %f LTHN to %s...", amount, destination[:20]+"...")
@ -464,9 +464,9 @@ func runWalletInfo(walletFile string) error {
core.Print(nil, "Wallet Information")
core.Print(nil, " File: %s", walletFile)
core.Print(nil, " Address: %s", addr.Encode(0x1eaf7))
core.Print(nil, " Integrated: %s", addr.Encode(0xdeaf7))
core.Print(nil, " Auditable: %s", addr.Encode(0x3ceff7))
core.Print(nil, " Address: %s", addr.Encode(StandardPrefix))
core.Print(nil, " Integrated: %s", addr.Encode(IntegratedPrefix))
core.Print(nil, " Auditable: %s", addr.Encode(AuditablePrefix))
core.Print(nil, " Spend Key: %x", account.SpendPublicKey[:])
core.Print(nil, " View Key: %x", account.ViewPublicKey[:])
core.Print(nil, " Seed: %s", seed)

52
constants.go Normal file
View file

@ -0,0 +1,52 @@
// Copyright (c) 2017-2026 Lethean (https://lt.hn)
// SPDX-License-Identifier: EUPL-1.2
package blockchain
// Chain constants used across commands and services.
const (
// AtomicUnit is the number of atomic units per 1 LTHN.
AtomicUnit uint64 = 1000000000000
// StandardPrefix is the base58 address prefix for standard addresses.
StandardPrefix uint64 = 0x1eaf7
// IntegratedPrefix is the base58 prefix for integrated addresses.
IntegratedPrefix uint64 = 0xdeaf7
// AuditablePrefix is the base58 prefix for auditable addresses.
AuditablePrefix uint64 = 0x3ceff7
// AuditableIntegratedPrefix is the base58 prefix for auditable integrated.
AuditableIntegratedPrefix uint64 = 0x8b077
// HF5Height is the activation height for confidential assets.
HF5Height uint64 = 11500
// HF4Height is the activation height for Zarcanum.
HF4Height uint64 = 11000
// DefaultBlockReward is the fixed block reward in LTHN.
DefaultBlockReward uint64 = 1
// DefaultFee is the default transaction fee in atomic units.
DefaultFee uint64 = 10000000000 // 0.01 LTHN
// PremineAmount is the genesis premine in LTHN.
PremineAmount uint64 = 10000000
// TestnetDaemonRPC is the default testnet daemon RPC port.
TestnetDaemonRPC = "46941"
// TestnetWalletRPC is the default testnet wallet RPC port.
TestnetWalletRPC = "46944"
// TestnetP2P is the default testnet P2P port.
TestnetP2P = "46942"
// MainnetDaemonRPC is the default mainnet daemon RPC port.
MainnetDaemonRPC = "36941"
// TestnetHSDPort is the default HSD sidechain RPC port.
TestnetHSDPort = "14037"
)

View file

@ -66,7 +66,7 @@ func NewBlockchainService(c *core.Core, opts BlockchainOptions) *BlockchainServi
func (s *BlockchainService) start() core.Result {
if s.opts.Testnet {
chain.GenesisHash = "7cf844dc3e7d8dd6af65642c68164ebe18109aa5167b5f76043f310dd6e142d0"
chain.GenesisHash = chain.TestnetGenesisHash
}
dbPath := core.JoinPath(s.opts.DataDir, "chain.db")