Skip to content

Commit

Permalink
feat: Hemis
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedbodi committed May 3, 2024
1 parent 1144701 commit 7d35034
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
11 changes: 7 additions & 4 deletions electrumx/lib/coins.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import electrumx.server.daemon as daemon
from electrumx.server.session import (ElectrumX, DashElectrumX,
SmartCashElectrumX, AuxPoWElectrumX,
NameIndexElectrumX, NameIndexAuxPoWElectrumX)
NameIndexElectrumX, NameIndexAuxPoWElectrumX, HemisElectrumX)


@dataclass
Expand Down Expand Up @@ -4238,6 +4238,8 @@ class Hemis(Coin):
EXPANDED_HEADER = 112
SAPLING_START_HEIGHT = 502
BLOCK_VERSION = 11
SESSIONCLS = HemisElectrumX

@classmethod
def static_header_len(cls, height):
'''Given a header height return its length.'''
Expand All @@ -4256,10 +4258,11 @@ def header_hash(cls, header):
'''Given a header return the hash.'''
version, = struct.unpack('<I', header[:4])
if version < 5:
import quark_hash
return quark_hash.getPoWHash(header)
import algomodule
return algomodule._quark_hash(header)
else:
return super().header_hash(header)

class HemisTestnet(Hemis):
SHORTNAME = "tHMS"
NET = "testnet"
Expand Down Expand Up @@ -4289,4 +4292,4 @@ def static_header_len(cls, height):
elif height == 501:
return cls.BASIC_HEADER_SIZE
else:
return cls.EXPANDED_HEADER
return cls.EXPANDED_HEADER
26 changes: 26 additions & 0 deletions electrumx/server/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1884,3 +1884,29 @@ async def name_get_value_proof(self, scripthash, cp_height=0):

class NameIndexAuxPoWElectrumX(NameIndexElectrumX, AuxPoWElectrumX):
pass

class HemisElectrumX(ElectrumX):
async def block_headers(self, start_height, count, cp_height=0):
'''Return count concatenated block headers as hex for the main chain;
starting at start_height.
start_height and count must be non-negative integers. At most
MAX_CHUNK_SIZE headers will be returned.
'''
start_height = non_negative_integer(start_height)
count = non_negative_integer(count)
cp_height = non_negative_integer(cp_height)
cost = count / 50

max_size = self.MAX_CHUNK_SIZE
count = min(count, max_size)
result = {'headers': [], 'count': count, 'max': max_size}
for x in range(0, count):
raw_header_hex = (await self.session_mgr.raw_header(start_height + x)).hex()
result['headers'].append(raw_header_hex)
if count and cp_height:
cost += 1.0
last_height = start_height + count - 1
result.updaate(await self._merkle_proof(cp_height, last_height))
self.bump_cost(cost)
return result

0 comments on commit 7d35034

Please sign in to comment.