B2: network profile for mainnet and regtest, explicit confirmation for mainnet (ADR-58, ELC-30)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3ee60a23da
commit
9c832fd3d2
16 files changed
+261
-36
No files matched your search
+62
-4
@@ -1,10 +1,14 @@
|
||||
"""PLM mainnet params for embit, verified against PalladiumWallet/src/Core/Chain/ChainProfiles.cs.
|
||||
"""Network profiles (ADR-58): everything that differs between PLM mainnet and the regtest of the alpha.
|
||||
|
||||
Threaded explicitly through every embit call via `network=PLM_MAINNET` rather than
|
||||
registered globally, since this is a long-lived async server (embit has no
|
||||
concept of "current network" beyond what you pass in).
|
||||
A `Profile` fixes the bech32 hrp, the base58 and extended-key prefixes, the genesis hash the Electrum
|
||||
handshake expects (ELC-30), the proof-of-work floor and the BIP44 coin type. The values come from
|
||||
`palladiumcore/src/chainparams.cpp` (mainnet and `CRegTestParams`) and the PalladiumWallet chain profiles.
|
||||
The profile is threaded explicitly through every call (`network=profile.embit`), never registered globally:
|
||||
this is a long-lived server and embit has no notion of a current network beyond what it is passed.
|
||||
"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
PLM_MAINNET = {
|
||||
"name": "PLM Mainnet",
|
||||
"wif": bytes([0x80]),
|
||||
@@ -30,3 +34,57 @@ ACCOUNT_PATH = f"m/84h/{BIP44_COIN_TYPE}h/0h"
|
||||
# PLM shares Bitcoin's genesis block (palladiumcore chainparams.cpp) and its powLimit, so a
|
||||
# Bitcoin Electrum server would pass every header check; the handshake asks for this instead.
|
||||
GENESIS_HASH = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
|
||||
|
||||
MAINNET_POW_LIMIT = int("00000000" + "ff" * 28, 16)
|
||||
REGTEST_POW_LIMIT = int("7f" + "ff" * 31, 16)
|
||||
|
||||
# Bitcoin's testnet SLIP-132 variants, which Palladium's testnet and regtest share.
|
||||
PLM_REGTEST = {
|
||||
"name": "PLM Regtest",
|
||||
"wif": bytes([0xFF]),
|
||||
"p2pkh": bytes([127]),
|
||||
"p2sh": bytes([115]),
|
||||
"bech32": "rplm",
|
||||
"xprv": bytes.fromhex("04358394"),
|
||||
"xpub": bytes.fromhex("043587cf"),
|
||||
"yprv": bytes.fromhex("044a4e28"),
|
||||
"ypub": bytes.fromhex("044a5262"),
|
||||
"zprv": bytes.fromhex("045f18bc"),
|
||||
"zpub": bytes.fromhex("045f1cf6"),
|
||||
"Yprv": bytes.fromhex("024285b5"),
|
||||
"Ypub": bytes.fromhex("024289ef"),
|
||||
"Zprv": bytes.fromhex("02575048"),
|
||||
"Zpub": bytes.fromhex("02575483"),
|
||||
"bip32": 1,
|
||||
}
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Profile:
|
||||
name: str # the value of PLM_NETWORK
|
||||
embit: dict # what embit takes as `network=`
|
||||
genesis_hash: str
|
||||
pow_limit: int
|
||||
coin_type: int
|
||||
|
||||
@property
|
||||
def hrp(self) -> str:
|
||||
return self.embit["bech32"]
|
||||
|
||||
@property
|
||||
def account_path(self) -> str:
|
||||
return f"m/84h/{self.coin_type}h/0h"
|
||||
|
||||
|
||||
MAINNET = Profile("mainnet", PLM_MAINNET, GENESIS_HASH, MAINNET_POW_LIMIT, BIP44_COIN_TYPE)
|
||||
REGTEST = Profile(
|
||||
"regtest", PLM_REGTEST, "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206", REGTEST_POW_LIMIT, 1
|
||||
)
|
||||
PROFILES = {profile.name: profile for profile in (MAINNET, REGTEST)}
|
||||
|
||||
|
||||
def get_profile(name: str) -> Profile:
|
||||
try:
|
||||
return PROFILES[name]
|
||||
except KeyError:
|
||||
raise ValueError(f"unknown network {name!r}: expected one of {sorted(PROFILES)}") from None
|
||||
Reference in new issue
Block a user