"""Builds mainnet copies of the pool and explorer (from the earlier test-network pool/explorer sources; inputs untouched). Every edit must match exactly once.""" import os, re, json, hashlib HERE = os.path.dirname(os.path.abspath(__file__)); OUT = os.path.join(HERE, "release") import importlib.util as u s = u.spec_from_file_location("n", os.path.join(OUT, "eddycoin_node.py")); N = u.module_from_spec(s); s.loader.exec_module(N) def build(src, edits): for a, b in edits: assert src.count(a) == 1, (src.count(a), a[:90]); src = src.replace(a, b) return src pool = open(os.environ.get("EDDY_TESTNET_POOL_SRC", "testnet/eddycoin_pool.py"), encoding="utf-8").read() pool = build(pool, [ ('Test coin only (EDDY testnet sandbox).', 'Eddycoin mainnet (eddycoin-mainnet-1). Fee address must never be an old (denylisted) testnet key.'), ('POOL_VERSION = "pool-1.0"\nNETWORK = "eddycoin-testnet-sandbox"', 'POOL_VERSION = "pool-2.0-mainnet"\nNETWORK = "eddycoin-mainnet-1"\nGENESIS_ID = "%s"' % N.GENESIS_ID), ('"node": "http://127.0.0.1:8770", "listen": "127.0.0.1", "port": 8771,', '"node": "http://127.0.0.1:8773", "listen": "127.0.0.1", "port": 8774,'), ('"fee_bps": 200, "fee_address": "SET-FEE-ADDRESS",', '"fee_bps": 0, "fee_address": "", "denylist": "",'), (' hd = "EDDY-%s-BLOCK|v1|', ' hd = "EDDY1-%s-BLOCK|v1|'), ('("EDDY-TX|v1|" + canon(', '("EDDY1-TX|v1|" + canon('), ('k.sign(("EDDY-TX-SIG|v1|" + t["txid"])', 'k.sign(("EDDY1-TX-SIG|v1|" + t["txid"])'), (''' pool = Pool(cfg, PoolWallet(cfg["wallet_file"], cfg["wallet_password_file"]))''', ''' pw = PoolWallet(cfg["wallet_file"], cfg["wallet_password_file"]) # mainnet startup checks: node must be eddycoin-mainnet-1 with our genesis; pool wallet + fee address must not be old (denylisted) keys dl = json.load(open(cfg["denylist"])) if cfg.get("denylist") else None if dl is None: raise SystemExit("REFUSING TO START: config 'denylist' (old_key_denylist.json) is required on mainnet") bad = set(dl.get("addresses", [])) | set(dl.get("superseded_v2_addresses", [])) if pw.address in bad or (cfg.get("fee_address") and cfg["fee_address"] in bad): raise SystemExit("REFUSING TO START: pool wallet or fee address is an OLD denylisted key") for i in range(60): try: with urllib.request.urlopen(cfg["node"].rstrip("/") + "/api/node/info", timeout=10) as f: ni = json.loads(f.read()) break except Exception: time.sleep(5) else: raise SystemExit("REFUSING TO START: node %s unreachable" % cfg["node"]) if ni.get("network") != NETWORK or ni.get("genesis") != GENESIS_ID: raise SystemExit("REFUSING TO START: node is not on %s / genesis %s" % (NETWORK, GENESIS_ID[:12])) pool = Pool(cfg, pw)'''), ('"pool": POOL_VERSION, "network": NETWORK, "address": self.addr, "fee_bps": self.fee_bps, "fee_percent": self.fee_bps / 100, "scheme": "PPLNS (per lane)",', '"pool": POOL_VERSION, "network": NETWORK, "address": self.addr, "fee_bps": self.fee_bps, "fee_percent": self.fee_bps / 100, "fee_address": self.fee_target(), "scheme": "PPLNS (per lane)",'), ('· fee %(fee)s %% · PPLNS · min payout %(minp)s EDDY · test coin only

', '· pool fee %(fee)s %% of each pool block reward (to %(feeaddr)s) · PPLNS · min payout %(minp)s EDDY · network eddycoin-mainnet-1 (LIVE)

'), ('"fee": pool.fee_bps / 100, "minp": fmt(pool.cfg["min_payout"])}', '"fee": "%g" % (pool.fee_bps / 100), "feeaddr": pool.fee_target() or "not set", "minp": fmt(pool.cfg["min_payout"])}'), ]) assert "EDDY-TX" not in pool and "EDDY-%s-BLOCK" not in pool and "testnet-sandbox" not in pool assert '"EDDY-ADDR|v1|"' in pool open(os.path.join(OUT, "eddycoin_pool.py"), "w", encoding="utf-8").write(pool) EX_OLD_FB = """ for src, url in (("oracle-node-api", CFG["node_url"] + "/api/export"), ("cloudflare-api", CFG["cf_url"] + "/api/export")):""" EX_NEW_FB = """ for src, url in (("oracle-node-api", CFG["node_url"] + "/api/export"),) + ((("cloudflare-api", CFG["cf_url"] + "/api/export"),) if CFG["cf_url"] else ()):""" EX_OLD_CF = """ def poll_cf(self): try:""" EX_NEW_CF = """ def poll_cf(self): if not CFG["cf_url"]: # mainnet: no Cloudflare chain self.cf = {"ok": False, "err": "not used on mainnet", "t": now_ms()}; return try:""" ex = open(os.environ.get("EDDY_TESTNET_EXPLORER_SRC", "testnet/eddycoin_explorer.py"), encoding="utf-8").read() ex = build(ex, [ ('CFG = {"port": 8772, "listen": "127.0.0.1", "chain_file": "/var/lib/eddycoin/data/chain.json", "node_url": "http://127.0.0.1:8770",\n "pool_url": "http://127.0.0.1:8771", "pool_db": "/var/lib/eddycoin-pool/pool.db",', 'CFG = {"port": 8775, "listen": "127.0.0.1", "chain_file": "/var/lib/eddycoin-mainnet/data/chain.json", "node_url": "http://127.0.0.1:8773",\n "pool_url": "http://127.0.0.1:8774", "pool_db": "/var/lib/eddycoin-mainnet-pool/pool.db",'), ('"network": "eddycoin-testnet-sandbox"', '"network": "eddycoin-mainnet-1"'), ('"cf_url": "https://eddycoin-demo.pages.dev",\n "db": "/var/lib/eddycoin-explorer/history.db",', '"cf_url": "",\n "db": "/var/lib/eddycoin-mainnet-explorer/history.db",'), ('"origins": ["https://eddycoin-demo.pages.dev"], "dash_html": "/opt/eddycoin/explorer_dashboard.html", "services": ["eddycoin", "eddycoin-pool", "eddycoin-explorer", "caddy"]}', '"origins": ["https://eddycoin.pages.dev"], "dash_html": "/opt/eddycoin-mainnet/explorer_dashboard.html", "services": ["eddycoin-mainnet", "eddycoin-mainnet-pool", "eddycoin-mainnet-explorer", "caddy"]}'), (EX_OLD_FB, EX_NEW_FB), (EX_OLD_CF, EX_NEW_CF), ]) assert "testnet-sandbox" not in ex open(os.path.join(OUT, "eddycoin_explorer.py"), "w", encoding="utf-8").write(ex) print("pool", hashlib.sha256(pool.encode()).hexdigest()[:16], "explorer", hashlib.sha256(ex.encode()).hexdigest()[:16])