diff --git a/electrumx/lib/coins.py b/electrumx/lib/coins.py index 76da297..5da2fa1 100644 --- a/electrumx/lib/coins.py +++ b/electrumx/lib/coins.py @@ -39,7 +39,7 @@ from functools import partial import base64 import electrumx.lib.util as util -from electrumx.lib.hash import Base58, hash160, double_sha256, hash_to_str +from electrumx.lib.hash import Base58, hash160, double_sha256, hash_to_hex_str from electrumx.lib.hash import HASHX_LEN from electrumx.lib.script import ScriptPubKey, OpCodes import electrumx.lib.tx as lib_tx @@ -121,7 +121,7 @@ class Coin(object): Return the block less its unspendable coinbase. ''' header = cls.block_header(block, 0) - header_hex_hash = hash_to_str(cls.header_hash(header)) + header_hex_hash = hash_to_hex_str(cls.header_hash(header)) if header_hex_hash != cls.GENESIS_HASH: raise CoinError('genesis block has hash {} expected {}' .format(header_hex_hash, cls.GENESIS_HASH)) @@ -293,8 +293,8 @@ class Coin(object): return { 'block_height': height, 'version': version, - 'prev_block_hash': hash_to_str(header[4:36]), - 'merkle_root': hash_to_str(header[36:68]), + 'prev_block_hash': hash_to_hex_str(header[4:36]), + 'merkle_root': hash_to_hex_str(header[36:68]), 'timestamp': timestamp, 'bits': bits, 'nonce': nonce, @@ -330,11 +330,11 @@ class EquihashMixin(object): return { 'block_height': height, 'version': version, - 'prev_block_hash': hash_to_str(header[4:36]), - 'merkle_root': hash_to_str(header[36:68]), + 'prev_block_hash': hash_to_hex_str(header[4:36]), + 'merkle_root': hash_to_hex_str(header[36:68]), 'timestamp': timestamp, 'bits': bits, - 'nonce': hash_to_str(header[108:140]), + 'nonce': hash_to_hex_str(header[108:140]), } @classmethod @@ -477,13 +477,13 @@ class BitcoinGold(EquihashMixin, BitcoinMixin, Coin): h = dict( block_height=height, version=struct.unpack(' 0: hashes = self.fs_block_hashes(start, count) - hex_hashes = [hash_to_str(hash) for hash in hashes] + hex_hashes = [hash_to_hex_str(hash) for hash in hashes] d_hex_hashes = await self.daemon.block_hex_hashes(start, count) n = diff_pos(hex_hashes, d_hex_hashes) if n > 0: @@ -574,8 +574,9 @@ class BlockProcessor(electrumx.server.db.DB): header_hash = coin.header_hash(block.header) if header_hash != self.tip: raise ChainError('backup block {} not tip {} at height {:,d}' - .format(hash_to_str(header_hash), - hash_to_str(self.tip), self.height)) + .format(hash_to_hex_str(header_hash), + hash_to_hex_str(self.tip), + self.height)) self.tip = coin.header_prevhash(block.header) self.backup_txs(block.transactions) self.height -= 1 @@ -718,7 +719,7 @@ class BlockProcessor(electrumx.server.db.DB): return hashX + tx_num_packed + utxo_value_packed raise ChainError('UTXO {} / {:,d} not found in "h" table' - .format(hash_to_str(tx_hash), tx_idx)) + .format(hash_to_hex_str(tx_hash), tx_idx)) def flush_utxos(self, batch): '''Flush the cached DB writes and UTXO set to the batch.''' diff --git a/electrumx/server/db.py b/electrumx/server/db.py index 256e607..2dd234a 100644 --- a/electrumx/server/db.py +++ b/electrumx/server/db.py @@ -17,7 +17,7 @@ from bisect import bisect_right from collections import namedtuple import electrumx.lib.util as util -from electrumx.lib.hash import hash_to_str, HASHX_LEN +from electrumx.lib.hash import hash_to_hex_str, HASHX_LEN from electrumx.server.storage import db_class from electrumx.server.history import History @@ -133,7 +133,7 @@ class DB(object): self.logger.info('coin: {}'.format(self.coin.NAME)) self.logger.info('network: {}'.format(self.coin.NET)) self.logger.info('height: {:,d}'.format(self.db_height)) - self.logger.info('tip: {}'.format(hash_to_str(self.db_tip))) + self.logger.info('tip: {}'.format(hash_to_hex_str(self.db_tip))) self.logger.info('tx count: {:,d}'.format(self.db_tx_count)) if self.first_sync: self.logger.info('sync time so far: {}' @@ -380,7 +380,7 @@ class DB(object): db_value = self.utxo_db.get(key) if not db_value: raise self.DBError('UTXO {} / {:,d} in one table only' - .format(hash_to_str(tx_hash), tx_idx)) + .format(hash_to_hex_str(tx_hash), tx_idx)) value, = unpack(' 4: self.logger.info('hashX {} is large: {:,d} entries across ' '{:,d} rows' - .format(hash_to_str(hashX), len(full_hist) // 4, - nrows)) + .format(hash_to_hex_str(hashX), + len(full_hist) // 4, nrows)) # Find what history needs to be written, and what keys need to # be deleted. Start by assuming all keys are to be deleted, diff --git a/electrumx/server/mempool.py b/electrumx/server/mempool.py index 2987bc5..538fc64 100644 --- a/electrumx/server/mempool.py +++ b/electrumx/server/mempool.py @@ -12,7 +12,7 @@ import itertools import time from collections import defaultdict -from electrumx.lib.hash import hash_to_str, hex_str_to_hash +from electrumx.lib.hash import hash_to_hex_str, hex_str_to_hash from electrumx.lib.util import class_logger from electrumx.server.daemon import DaemonError from electrumx.server.db import UTXO @@ -230,7 +230,7 @@ class MemPool(object): for txout in tx.outputs] # Convert the tx inputs to ([prev_hex_hash, prev_idx) pairs - txin_pairs = [(hash_to_str(txin.prev_hash), txin.prev_idx) + txin_pairs = [(hash_to_hex_str(txin.prev_hash), txin.prev_idx) for txin in tx.inputs] pending.append((tx_hash, txin_pairs, txout_pairs, tx_size)) @@ -309,7 +309,7 @@ class MemPool(object): continue tx_fee = item[2] tx = deserializer(raw_tx).read_tx() - unconfirmed = any(hash_to_str(txin.prev_hash) in self.txs + unconfirmed = any(hash_to_hex_str(txin.prev_hash) in self.txs for txin in tx.inputs) result.append((hex_hash, tx_fee, unconfirmed)) return result diff --git a/electrumx/server/session.py b/electrumx/server/session.py index 072e442..e324c59 100644 --- a/electrumx/server/session.py +++ b/electrumx/server/session.py @@ -15,7 +15,7 @@ from functools import partial from aiorpcx import ServerSession, JSONRPCAutoDetect, RPCError -from electrumx.lib.hash import sha256, hash_to_str +from electrumx.lib.hash import sha256, hash_to_hex_str import electrumx.lib.util as util from electrumx.server.daemon import DaemonError @@ -248,7 +248,7 @@ class ElectrumX(SessionBase): history = await self.controller.get_history(hashX) mempool = await self.controller.mempool_transactions(hashX) - status = ''.join('{}:{:d}:'.format(hash_to_str(tx_hash), height) + status = ''.join('{}:{:d}:'.format(hash_to_hex_str(tx_hash), height) for tx_hash, height in history) status += ''.join('{}:{:d}:'.format(hex_hash, -unconfirmed) for hex_hash, tx_fee, unconfirmed in mempool) diff --git a/query.py b/query.py index 06d983f..5bdfa8c 100755 --- a/query.py +++ b/query.py @@ -17,7 +17,7 @@ import sys from electrumx import Env from electrumx.server.db import DB -from electrumx.lib.hash import hash_to_str +from electrumx.lib.hash import hash_to_hex_str def count_entries(hist_db, utxo_db): @@ -58,11 +58,11 @@ def main(): for n, (tx_hash, height) in enumerate(bp.get_history(hashX, limit)): print('History #{:d}: hash: {} height: {:d}' - .format(n + 1, hash_to_str(tx_hash), height)) + .format(n + 1, hash_to_hex_str(tx_hash), height)) n = None for n, utxo in enumerate(bp.get_utxos(hashX, limit)): print('UTXOs #{:d}: hash: {} pos: {:d} height: {:d} value: {:d}' - .format(n + 1, hash_to_str(utxo.tx_hash), + .format(n + 1, hash_to_hex_str(utxo.tx_hash), utxo.tx_pos, utxo.height, utxo.value)) if n is None: print('No UTXOs') diff --git a/tests/server/test_compaction.py b/tests/server/test_compaction.py index 97bba7e..2d051d1 100644 --- a/tests/server/test_compaction.py +++ b/tests/server/test_compaction.py @@ -6,7 +6,7 @@ from os import environ, urandom from struct import pack import random -from electrumx.lib.hash import hash_to_str, HASHX_LEN +from electrumx.lib.hash import HASHX_LEN from electrumx.server.env import Env from electrumx.server.db import DB