Make HASHX_LEN a global, not a coin property
This commit is contained in:
parent
56de4dea67
commit
77051f83a4
13
lib/coins.py
13
lib/coins.py
@ -39,7 +39,7 @@ from functools import partial
|
|||||||
import base64
|
import base64
|
||||||
|
|
||||||
import lib.util as util
|
import lib.util as util
|
||||||
from lib.hash import Base58, hash160, double_sha256, hash_to_str
|
from lib.hash import Base58, hash160, double_sha256, hash_to_str, HASHX_LEN
|
||||||
from lib.script import ScriptPubKey, OpCodes
|
from lib.script import ScriptPubKey, OpCodes
|
||||||
import lib.tx as lib_tx
|
import lib.tx as lib_tx
|
||||||
from server.block_processor import BlockProcessor
|
from server.block_processor import BlockProcessor
|
||||||
@ -63,7 +63,6 @@ class Coin(object):
|
|||||||
RPC_URL_REGEX = re.compile('.+@(\[[0-9a-fA-F:]+\]|[^:]+)(:[0-9]+)?')
|
RPC_URL_REGEX = re.compile('.+@(\[[0-9a-fA-F:]+\]|[^:]+)(:[0-9]+)?')
|
||||||
VALUE_PER_COIN = 100000000
|
VALUE_PER_COIN = 100000000
|
||||||
CHUNK_SIZE = 2016
|
CHUNK_SIZE = 2016
|
||||||
HASHX_LEN = 11
|
|
||||||
BASIC_HEADER_SIZE = 80
|
BASIC_HEADER_SIZE = 80
|
||||||
STATIC_BLOCK_HEADERS = True
|
STATIC_BLOCK_HEADERS = True
|
||||||
SESSIONCLS = ElectrumX
|
SESSIONCLS = ElectrumX
|
||||||
@ -135,7 +134,7 @@ class Coin(object):
|
|||||||
'''
|
'''
|
||||||
if script and script[0] == OP_RETURN:
|
if script and script[0] == OP_RETURN:
|
||||||
return None
|
return None
|
||||||
return sha256(script).digest()[:cls.HASHX_LEN]
|
return sha256(script).digest()[:HASHX_LEN]
|
||||||
|
|
||||||
@util.cachedproperty
|
@util.cachedproperty
|
||||||
def address_handlers(cls):
|
def address_handlers(cls):
|
||||||
@ -1660,7 +1659,7 @@ class Xuez(Coin):
|
|||||||
GENESIS_HASH = ('000000e1febc39965b055e8e0117179a'
|
GENESIS_HASH = ('000000e1febc39965b055e8e0117179a'
|
||||||
'4d18e24e7aaa0c69864c4054b4f29445')
|
'4d18e24e7aaa0c69864c4054b4f29445')
|
||||||
|
|
||||||
|
|
||||||
TX_COUNT = 30000
|
TX_COUNT = 30000
|
||||||
TX_COUNT_HEIGHT = 15000
|
TX_COUNT_HEIGHT = 15000
|
||||||
TX_PER_BLOCK = 1
|
TX_PER_BLOCK = 1
|
||||||
@ -1679,7 +1678,7 @@ class Xuez(Coin):
|
|||||||
version, = struct.unpack('<I', header[:4])
|
version, = struct.unpack('<I', header[:4])
|
||||||
|
|
||||||
import xevan_hash
|
import xevan_hash
|
||||||
|
|
||||||
if version == 1 :
|
if version == 1 :
|
||||||
return xevan_hash.getPoWHash(header[:80])
|
return xevan_hash.getPoWHash(header[:80])
|
||||||
else:
|
else:
|
||||||
@ -1698,7 +1697,7 @@ class Xuez(Coin):
|
|||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
'bits': bits,
|
'bits': bits,
|
||||||
'nonce': nonce,
|
'nonce': nonce,
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
return {
|
return {
|
||||||
'block_height': height,
|
'block_height': height,
|
||||||
@ -1709,4 +1708,4 @@ class Xuez(Coin):
|
|||||||
'bits': bits,
|
'bits': bits,
|
||||||
'nonce': nonce,
|
'nonce': nonce,
|
||||||
'nAccumulatorCheckpoint': hash_to_str(header[80:112]),
|
'nAccumulatorCheckpoint': hash_to_str(header[80:112]),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,7 @@ _sha256 = hashlib.sha256
|
|||||||
_sha512 = hashlib.sha512
|
_sha512 = hashlib.sha512
|
||||||
_new_hash = hashlib.new
|
_new_hash = hashlib.new
|
||||||
_new_hmac = hmac.new
|
_new_hmac = hmac.new
|
||||||
|
HASHX_LEN = 11
|
||||||
|
|
||||||
|
|
||||||
def sha256(x):
|
def sha256(x):
|
||||||
|
|||||||
@ -18,7 +18,7 @@ from collections import defaultdict
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from server.daemon import DaemonError
|
from server.daemon import DaemonError
|
||||||
from lib.hash import hash_to_str
|
from lib.hash import hash_to_str, HASHX_LEN
|
||||||
from lib.util import chunks, formatted_time
|
from lib.util import chunks, formatted_time
|
||||||
import server.db
|
import server.db
|
||||||
|
|
||||||
@ -606,7 +606,7 @@ class BlockProcessor(server.db.DB):
|
|||||||
spend_utxo = self.spend_utxo
|
spend_utxo = self.spend_utxo
|
||||||
script_hashX = self.coin.hashX_from_script
|
script_hashX = self.coin.hashX_from_script
|
||||||
touched = self.touched
|
touched = self.touched
|
||||||
undo_entry_len = 12 + self.coin.HASHX_LEN
|
undo_entry_len = 12 + HASHX_LEN
|
||||||
|
|
||||||
for tx, tx_hash in reversed(txs):
|
for tx, tx_hash in reversed(txs):
|
||||||
for idx, txout in enumerate(tx.outputs):
|
for idx, txout in enumerate(tx.outputs):
|
||||||
|
|||||||
@ -20,7 +20,7 @@ from functools import partial
|
|||||||
import pylru
|
import pylru
|
||||||
|
|
||||||
from aiorpcx import RPCError, TaskSet, _version
|
from aiorpcx import RPCError, TaskSet, _version
|
||||||
from lib.hash import double_sha256, hash_to_str, hex_str_to_hash
|
from lib.hash import double_sha256, hash_to_str, hex_str_to_hash, HASHX_LEN
|
||||||
from lib.peer import Peer
|
from lib.peer import Peer
|
||||||
from lib.server_base import ServerBase
|
from lib.server_base import ServerBase
|
||||||
import lib.util as util
|
import lib.util as util
|
||||||
@ -633,7 +633,7 @@ class Controller(ServerBase):
|
|||||||
try:
|
try:
|
||||||
bin_hash = hex_str_to_hash(scripthash)
|
bin_hash = hex_str_to_hash(scripthash)
|
||||||
if len(bin_hash) == 32:
|
if len(bin_hash) == 32:
|
||||||
return bin_hash[:self.coin.HASHX_LEN]
|
return bin_hash[:HASHX_LEN]
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
raise RPCError(BAD_REQUEST, f'{scripthash} is not a valid script hash')
|
raise RPCError(BAD_REQUEST, f'{scripthash} is not a valid script hash')
|
||||||
|
|||||||
@ -18,7 +18,7 @@ from bisect import bisect_left, bisect_right
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
import lib.util as util
|
import lib.util as util
|
||||||
from lib.hash import hash_to_str
|
from lib.hash import hash_to_str, HASHX_LEN
|
||||||
from server.storage import db_class
|
from server.storage import db_class
|
||||||
|
|
||||||
|
|
||||||
@ -609,7 +609,7 @@ class DB(object):
|
|||||||
hist_map = {}
|
hist_map = {}
|
||||||
hist_list = []
|
hist_list = []
|
||||||
|
|
||||||
key_len = self.coin.HASHX_LEN + 2
|
key_len = HASHX_LEN + 2
|
||||||
write_size = 0
|
write_size = 0
|
||||||
for key, hist in self.hist_db.iterator(prefix=prefix):
|
for key, hist in self.hist_db.iterator(prefix=prefix):
|
||||||
# Ignore non-history entries
|
# Ignore non-history entries
|
||||||
|
|||||||
@ -6,7 +6,7 @@ from os import environ, urandom
|
|||||||
from struct import pack
|
from struct import pack
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from lib.hash import hash_to_str
|
from lib.hash import hash_to_str, HASHX_LEN
|
||||||
from server.env import Env
|
from server.env import Env
|
||||||
from server.db import DB
|
from server.db import DB
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ from server.db import DB
|
|||||||
def create_histories(db, hashX_count=100):
|
def create_histories(db, hashX_count=100):
|
||||||
'''Creates a bunch of random transaction histories, and write them
|
'''Creates a bunch of random transaction histories, and write them
|
||||||
to disk in a series of small flushes.'''
|
to disk in a series of small flushes.'''
|
||||||
hashXs = [urandom(db.coin.HASHX_LEN) for n in range(hashX_count)]
|
hashXs = [urandom(HASHX_LEN) for n in range(hashX_count)]
|
||||||
mk_array = lambda : array.array('I')
|
mk_array = lambda : array.array('I')
|
||||||
histories = {hashX : mk_array() for hashX in hashXs}
|
histories = {hashX : mk_array() for hashX in hashXs}
|
||||||
this_history = defaultdict(mk_array)
|
this_history = defaultdict(mk_array)
|
||||||
@ -42,7 +42,7 @@ def check_hashX_compaction(db):
|
|||||||
db.max_hist_row_entries = 40
|
db.max_hist_row_entries = 40
|
||||||
row_size = db.max_hist_row_entries * 4
|
row_size = db.max_hist_row_entries * 4
|
||||||
full_hist = array.array('I', range(100)).tobytes()
|
full_hist = array.array('I', range(100)).tobytes()
|
||||||
hashX = urandom(db.coin.HASHX_LEN)
|
hashX = urandom(HASHX_LEN)
|
||||||
pairs = ((1, 20), (26, 50), (56, 30))
|
pairs = ((1, 20), (26, 50), (56, 30))
|
||||||
|
|
||||||
cum = 0
|
cum = 0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user