Skip to content

Commit 1ed2e29

Browse files
committed
♻️ Split shared session
1 parent 7f52c61 commit 1ed2e29

17 files changed

+242
-224
lines changed

contrib/query.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,34 @@
77
# See the file "LICENCE" for information about the copyright
88
# and warranty status of this software.
99

10-
'''Script to query the database for debugging purposes.
10+
"""Script to query the database for debugging purposes.
1111
1212
Not currently documented; might become easier to use in future.
13-
'''
13+
"""
1414

1515
import argparse
1616
import asyncio
1717

18-
from electrumx import Env
19-
from electrumx.server.db import DB
2018
from electrumx.lib.hash import hash_to_hex_str, Base58Error
19+
from electrumx.server.db import DB
20+
from electrumx.server.env import Env
21+
from electrumx.server.history import History
2122

2223

23-
async def print_stats(hist_db, utxo_db):
24-
count = 0
25-
for key in utxo_db.iterator(prefix=b'u', include_value=False):
26-
count += 1
27-
print(f'UTXO count: {utxos}')
24+
async def print_stats(hist_db: History, utxo_db):
25+
utxo_count = 0
26+
for _ in utxo_db.iterator(prefix=b'u', include_value=False):
27+
utxo_count += 1
28+
print(f'UTXO count: {utxo_count}')
2829

29-
count = 0
30-
for key in utxo_db.iterator(prefix=b'h', include_value=False):
31-
count += 1
32-
print(f'HashX count: {count}')
30+
hash_count = 0
31+
for _ in utxo_db.iterator(prefix=b'h', include_value=False):
32+
hash_count += 1
33+
print(f'HashX count: {hash_count}')
3334

3435
hist = 0
3536
hist_len = 0
36-
for key, value in hist_db.iterator(prefix=b'H'):
37+
for key, value in hist_db.db.iterator(prefix=b'H'):
3738
hist += 1
3839
hist_len += len(value) // 4
3940
print(f'History rows {hist:,d} entries {hist_len:,d}')
@@ -64,7 +65,7 @@ async def query(args):
6465
await db.open_for_serving()
6566

6667
if not args.scripts:
67-
await print_stats(db.hist_db, db.utxo_db)
68+
await print_stats(db.history, db.utxo_db)
6869
return
6970
limit = args.limit
7071
for arg in args.scripts:
@@ -97,15 +98,16 @@ def main():
9798
parser = argparse.ArgumentParser(
9899
'query.py',
99100
description='Invoke with COIN and DB_DIRECTORY set in the '
100-
'environment as they would be invoking electrumx_server'
101+
'environment as they would be invoking electrumx_server'
101102
)
102103
parser.add_argument('-l', '--limit', metavar='limit', type=int,
103104
default=10, help=f'maximum number of entries to '
104-
f'return (default: {default_limit})')
105+
f'return (default: {default_limit})')
105106
parser.add_argument('scripts', nargs='*', default=[], type=str,
106107
help='hex scripts to query')
107108
args = parser.parse_args()
108109
asyncio.run(query(args))
109110

111+
110112
if __name__ == '__main__':
111113
main()

electrumx/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +0,0 @@
1-
__version__ = "1.16.0"
2-
version = f'ElectrumX {__version__}'
3-
version_short = __version__
4-
5-
from electrumx.server.controller import Controller
6-
from electrumx.server.env import Env

electrumx/lib/atomicals_blueprint_builder.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,15 @@ def validate_ft_transfer_has_no_inflation(self, atomical_id_to_expected_outs_map
595595
input_value = ft_info['value']
596596
if sum_out_value and sum_out_value > input_value:
597597
atomical_id_compact = location_id_bytes_to_compact(atomical_id)
598-
raise AtomicalsTransferBlueprintBuilderError(f'validate_ft_transfer_has_no_inflation: Fatal error the output sum of outputs is greater than input sum for Atomical: atomical_id={atomical_id_compact} input_value={input_value} sum_out_value={sum_out_value} {hash_to_hex_str(tx_hash)} ft_atomicals={ft_atomicals}')
598+
raise AtomicalsTransferBlueprintBuilderError(
599+
'validate_ft_transfer_has_no_inflation: '
600+
'Fatal error the output sum of outputs is greater than input sum for Atomical: '
601+
f'atomical_id={atomical_id_compact} '
602+
f'input_value={input_value} '
603+
f'sum_out_value={sum_out_value} '
604+
f'{hash_to_hex_str(self.tx_hash)} '
605+
f'ft_atomicals={ft_atomicals}'
606+
)
599607

600608
def is_split_operation(self):
601609
return is_split_operation(self.operations_found_at_inputs)

electrumx/lib/coins.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
import electrumx.lib.tx_axe as lib_tx_axe
4949
import electrumx.server.block_processor as block_proc
5050
import electrumx.server.daemon as daemon
51-
from electrumx.server.session import (ElectrumX, DashElectrumX,
52-
SmartCashElectrumX, AuxPoWElectrumX,
53-
NameIndexElectrumX, NameIndexAuxPoWElectrumX)
51+
from electrumx.server.session.electrumx_session import (ElectrumX, DashElectrumX,
52+
SmartCashElectrumX, AuxPoWElectrumX,
53+
NameIndexElectrumX, NameIndexAuxPoWElectrumX)
5454

5555

5656
@dataclass
@@ -65,8 +65,19 @@ class CoinError(Exception):
6565
'''Exception raised for coin-related errors.'''
6666

6767

68-
class Coin:
69-
'''Base class of coin hierarchy.'''
68+
class CoinHeaderHashMixin:
69+
@classmethod
70+
def header_hash(cls, header):
71+
"""Given a header return hash"""
72+
return double_sha256(header)
73+
74+
75+
class CoinShortNameMixin:
76+
SHORTNAME: str
77+
78+
79+
class Coin(CoinHeaderHashMixin, CoinShortNameMixin):
80+
"""Base class of coin hierarchy."""
7081

7182
REORG_LIMIT = 200
7283
# Not sure if these are coin-specific
@@ -225,11 +236,6 @@ def privkey_WIF(cls, privkey_bytes, compressed):
225236
payload.append(0x01)
226237
return cls.ENCODE_CHECK(payload)
227238

228-
@classmethod
229-
def header_hash(cls, header):
230-
'''Given a header return hash'''
231-
return double_sha256(header)
232-
233239
@classmethod
234240
def header_prevhash(cls, header):
235241
'''Given a header return previous hash'''
@@ -328,7 +334,7 @@ def block_header(cls, block, height):
328334
return deserializer.read_header(cls.BASIC_HEADER_SIZE)
329335

330336

331-
class ScryptMixin:
337+
class ScryptMixin(CoinHeaderHashMixin):
332338

333339
DESERIALIZER = lib_tx.DeserializerTxTime
334340
HEADER_HASH = None
@@ -357,7 +363,7 @@ class KomodoMixin:
357363
DESERIALIZER = lib_tx.DeserializerZcash
358364

359365

360-
class BitcoinMixin:
366+
class BitcoinMixin(CoinShortNameMixin):
361367
SHORTNAME = "BTC"
362368
NET = "mainnet"
363369
XPUB_VERBYTES = bytes.fromhex("0488b21e")
@@ -845,7 +851,7 @@ def hashX_from_script(cls, script):
845851
return super().hashX_from_script(address_script)
846852

847853

848-
class BitcoinTestnetMixin:
854+
class BitcoinTestnetMixin(CoinShortNameMixin):
849855
SHORTNAME = "XTN"
850856
NET = "testnet"
851857
XPUB_VERBYTES = bytes.fromhex("043587cf")

0 commit comments

Comments
 (0)