Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Hemis Support #274

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ unittests_task:
- pip install git+https://github.com/bitcoinplusorg/x13-hash
- pip install xevan_hash
- pip install quark_hash
- pip install algomodule
- pip install groestlcoin_hash
- pip install x16r_hash
- pip install pycryptodomex
Expand Down
80 changes: 79 additions & 1 deletion electrumx/lib/coins.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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 @@ -4239,3 +4239,81 @@ class FerriteTestnet(Ferrite):
'enode2.ferritecoin.org s t',
'enode3.ferritecoin.org s t',
]


class Hemis(Coin):
NAME = "Hemis"
SHORTNAME = "HMS"
NET = "mainnet"
XPUB_VERBYTES = bytes.fromhex("A0F2F5F3")
XPRV_VERBYTES = bytes.fromhex("A0F3F1FB")
GENESIS_HASH = '000000956c582b70df5d2c9b4b83d05b5331978e40d639739bdc96c29e156ce7'
P2PKH_VERBYTE = bytes.fromhex("28")
P2SH_VERBYTE = bytes.fromhex("0D")
WIF_BYTE = bytes.fromhex("D4")
DESERIALIZER = lib_tx.DeserializerPIVX
TX_COUNT_HEIGHT = 569399
TX_COUNT = 2157510
TX_PER_BLOCK = 1
STATIC_BLOCK_HEADERS = False
RPC_PORT = 51473
REORG_LIMIT = 100
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.'''
print("Debugging - Processing block height:", height)
hypermoist marked this conversation as resolved.
Show resolved Hide resolved
if height <= 499:
return cls.BASIC_HEADER_SIZE
elif height == 500:
return cls.EXPANDED_HEADER
elif height == 501:
return cls.BASIC_HEADER_SIZE
else:
return cls.EXPANDED_HEADER

@classmethod
def header_hash(cls, header):
'''Given a header return the hash.'''
version, = struct.unpack('<I', header[:4])
if version < 5:
import algomodule
return algomodule._quark_hash(header)
else:
return super().header_hash(header)


class HemisTestnet(Hemis):
SHORTNAME = "tHMS"
NET = "testnet"
XPUB_VERBYTES = bytes.fromhex("3A8061A0")
XPRV_VERBYTES = bytes.fromhex("3A805837")
GENESIS_HASH = '000000798b274f80ef80da249806ed8d86dec9338a58b34073b7014096e3d0c5'
P2PKH_VERBYTE = bytes.fromhex("8B")
P2SH_VERBYTE = bytes.fromhex("13")
WIF_BYTE = bytes.fromhex("EF")
DESERIALIZER = lib_tx.DeserializerPIVX
TX_COUNT_HEIGHT = 8000
TX_COUNT = 10000
TX_PER_BLOCK = 1
RPC_PORT = 51475
REORG_LIMIT = 1000
STATIC_BLOCK_HEADERS = False
EXPANDED_HEADER = 112

@classmethod
def static_header_len(cls, height):
'''Given a header height return its length.'''
print("Debugging - Processing block height:", height)
hypermoist marked this conversation as resolved.
Show resolved Hide resolved
if height <= 499:
return cls.BASIC_HEADER_SIZE
elif height == 500:
return cls.EXPANDED_HEADER
elif height == 501:
return cls.BASIC_HEADER_SIZE
else:
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):
hypermoist marked this conversation as resolved.
Show resolved Hide resolved
'''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()
hypermoist marked this conversation as resolved.
Show resolved Hide resolved
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))
hypermoist marked this conversation as resolved.
Show resolved Hide resolved
self.bump_cost(cost)
return result
26 changes: 26 additions & 0 deletions tests/blocks/hemis_mainnet_300000.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"hash": "c07c17b024bc7436112ae15b67567d9b4f36c18681c22621f3c9c5d6915336b9",
"confirmations": 35683,
"size": 485,
"height": 300000,
"version": 11,
"merkleroot": "d9e4c5799c9117edd741905eb4dc446632cc086aac9b335cb4d59be1791ae4cc",
"acc_checkpoint": "0000000000000000000000000000000000000000000000000000000000000000",
"finalsaplingroot": "3e49b5f954aa9d3545bc6c37744661eea48d7c34e3000d82b7f0010c30f4c2fb",
"tx": [
"e49a0ef015323b1dfda41043c908c1ddb6fcf328dc247d356ed4a3ee25920501",
"8e21adfbab34795cc3cf6b1e68f0fbb668e543516d158996411e76be83acfb33"
],
"time": 1724105355,
"mediantime": 1724105010,
"nonce": 0,
"bits": "1b3da7c3",
"difficulty": 1062.925321539171,
"chainwork": "00000000000000000000000000000000000000000000000011d7a4eb61d88179",
"previousblockhash": "52348e3dd43969f222dad3aba6406fe0b031532482bdd553a1901ee075be5221",
"nextblockhash": "55e4c9dac5fdc6784931004ff140f6eba204c32006df44fd58ccdd96e90c0b8b",
"stakeModifier": "c4b8c37b4b2e63838eeadf03962dbb740073ed5202cbf4da3633a3720fdd82c9",
"hashProofOfStake": "00011838f8d02c19af00f40369d8ceb8a3e5af6e987440207b0fa317eab82e2f",
"chainlock": false,
"block": "0b0000002152be75e01e90a153d5bd82245331b0e06f40a6abd3da22f26939d43d8e3452cce41a79e19bd5b45c339bac6a08cc326644dcb45e9041d7ed17919c79c5e4d98bc2c366c3a73d1b00000000fbc2f4300c01f0b7820d00e3347c8da4ee614674376cbc45359daa54f9b5493e0201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0503e0930400ffffffff010000000000000000000000000001000000010c9c71dad0ab4c258f8b85af6a31e806cddec7ab9d8deba6f81efd58bbebf8de010000006b483045022100cc52ae93c117c81506bfad96fdebd7b990caf520784c36cb2264f5b02e3efbf102200a610bc6f055d8c79b16d82ceb26afbb2c5d4be5d6dc096b7cebb8f3234dfbc2012103454f1ac69a5e256b0d9d32e2d444cc6103bba25110292fa59829ed282e3ada4affffffff03000000000000000000a696be69030000001976a914f1067cb2e9bf79374a00abefcdcdbdfba82f928a88ac0fe68911000000001976a91415f2fe51d779d6d0e9eec72801e885073442c55d88ac00000000473045022100f4cc127138256e67789fbdae2e634ce9e2adb5b8f56312ea0a9814507e480f9902201775bd235d6304e4622a81d89d36247b984a6ff314e3f5aa8153dcdaf21294e3"
}