tconstants.py - electrum - Electrum Bitcoin wallet
HTML git clone https://git.parazyd.org/electrum
DIR Log
DIR Files
DIR Refs
DIR Submodules
---
tconstants.py (5246B)
---
1 # -*- coding: utf-8 -*-
2 #
3 # Electrum - lightweight Bitcoin client
4 # Copyright (C) 2018 The Electrum developers
5 #
6 # Permission is hereby granted, free of charge, to any person
7 # obtaining a copy of this software and associated documentation files
8 # (the "Software"), to deal in the Software without restriction,
9 # including without limitation the rights to use, copy, modify, merge,
10 # publish, distribute, sublicense, and/or sell copies of the Software,
11 # and to permit persons to whom the Software is furnished to do so,
12 # subject to the following conditions:
13 #
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 # SOFTWARE.
25
26 import os
27 import json
28
29 from .util import inv_dict
30 from . import bitcoin
31
32
33 def read_json(filename, default):
34 path = os.path.join(os.path.dirname(__file__), filename)
35 try:
36 with open(path, 'r') as f:
37 r = json.loads(f.read())
38 except:
39 r = default
40 return r
41
42
43 GIT_REPO_URL = "https://github.com/spesmilo/electrum"
44 GIT_REPO_ISSUES_URL = "https://github.com/spesmilo/electrum/issues"
45 BIP39_WALLET_FORMATS = read_json('bip39_wallet_formats.json', [])
46
47
48 class AbstractNet:
49
50 BLOCK_HEIGHT_FIRST_LIGHTNING_CHANNELS = 0
51
52 @classmethod
53 def max_checkpoint(cls) -> int:
54 return max(0, len(cls.CHECKPOINTS) * 2016 - 1)
55
56 @classmethod
57 def rev_genesis_bytes(cls) -> bytes:
58 return bytes.fromhex(bitcoin.rev_hex(cls.GENESIS))
59
60
61 class BitcoinMainnet(AbstractNet):
62
63 TESTNET = False
64 WIF_PREFIX = 0x80
65 ADDRTYPE_P2PKH = 0
66 ADDRTYPE_P2SH = 5
67 SEGWIT_HRP = "bc"
68 GENESIS = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
69 DEFAULT_PORTS = {'t': '50001', 's': '50002'}
70 DEFAULT_SERVERS = read_json('servers.json', {})
71 CHECKPOINTS = read_json('checkpoints.json', [])
72 BLOCK_HEIGHT_FIRST_LIGHTNING_CHANNELS = 497000
73
74 XPRV_HEADERS = {
75 'standard': 0x0488ade4, # xprv
76 'p2wpkh-p2sh': 0x049d7878, # yprv
77 'p2wsh-p2sh': 0x0295b005, # Yprv
78 'p2wpkh': 0x04b2430c, # zprv
79 'p2wsh': 0x02aa7a99, # Zprv
80 }
81 XPRV_HEADERS_INV = inv_dict(XPRV_HEADERS)
82 XPUB_HEADERS = {
83 'standard': 0x0488b21e, # xpub
84 'p2wpkh-p2sh': 0x049d7cb2, # ypub
85 'p2wsh-p2sh': 0x0295b43f, # Ypub
86 'p2wpkh': 0x04b24746, # zpub
87 'p2wsh': 0x02aa7ed3, # Zpub
88 }
89 XPUB_HEADERS_INV = inv_dict(XPUB_HEADERS)
90 BIP44_COIN_TYPE = 0
91 LN_REALM_BYTE = 0
92 LN_DNS_SEEDS = [
93 'nodes.lightning.directory.',
94 'lseed.bitcoinstats.com.',
95 ]
96
97
98 class BitcoinTestnet(AbstractNet):
99
100 TESTNET = True
101 WIF_PREFIX = 0xef
102 ADDRTYPE_P2PKH = 111
103 ADDRTYPE_P2SH = 196
104 SEGWIT_HRP = "tb"
105 GENESIS = "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"
106 DEFAULT_PORTS = {'t': '51001', 's': '51002'}
107 DEFAULT_SERVERS = read_json('servers_testnet.json', {})
108 CHECKPOINTS = read_json('checkpoints_testnet.json', [])
109
110 XPRV_HEADERS = {
111 'standard': 0x04358394, # tprv
112 'p2wpkh-p2sh': 0x044a4e28, # uprv
113 'p2wsh-p2sh': 0x024285b5, # Uprv
114 'p2wpkh': 0x045f18bc, # vprv
115 'p2wsh': 0x02575048, # Vprv
116 }
117 XPRV_HEADERS_INV = inv_dict(XPRV_HEADERS)
118 XPUB_HEADERS = {
119 'standard': 0x043587cf, # tpub
120 'p2wpkh-p2sh': 0x044a5262, # upub
121 'p2wsh-p2sh': 0x024289ef, # Upub
122 'p2wpkh': 0x045f1cf6, # vpub
123 'p2wsh': 0x02575483, # Vpub
124 }
125 XPUB_HEADERS_INV = inv_dict(XPUB_HEADERS)
126 BIP44_COIN_TYPE = 1
127 LN_REALM_BYTE = 1
128 LN_DNS_SEEDS = [ # TODO investigate this again
129 #'test.nodes.lightning.directory.', # times out.
130 #'lseed.bitcoinstats.com.', # ignores REALM byte and returns mainnet peers...
131 ]
132
133
134 class BitcoinRegtest(BitcoinTestnet):
135
136 SEGWIT_HRP = "bcrt"
137 GENESIS = "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"
138 DEFAULT_SERVERS = read_json('servers_regtest.json', {})
139 CHECKPOINTS = []
140 LN_DNS_SEEDS = []
141
142
143 class BitcoinSimnet(BitcoinTestnet):
144
145 WIF_PREFIX = 0x64
146 ADDRTYPE_P2PKH = 0x3f
147 ADDRTYPE_P2SH = 0x7b
148 SEGWIT_HRP = "sb"
149 GENESIS = "683e86bd5c6d110d91b94b97137ba6bfe02dbbdb8e3dff722a669b5d69d77af6"
150 DEFAULT_SERVERS = read_json('servers_regtest.json', {})
151 CHECKPOINTS = []
152 LN_DNS_SEEDS = []
153
154
155 # don't import net directly, import the module instead (so that net is singleton)
156 net = BitcoinMainnet
157
158 def set_simnet():
159 global net
160 net = BitcoinSimnet
161
162 def set_mainnet():
163 global net
164 net = BitcoinMainnet
165
166 def set_testnet():
167 global net
168 net = BitcoinTestnet
169
170
171 def set_regtest():
172 global net
173 net = BitcoinRegtest