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

added support for peercoin v3 transactions #147

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions electrumx/lib/coins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1707,15 +1707,13 @@ class Peercoin(Coin):
WIF_BYTE = bytes.fromhex("b7")
GENESIS_HASH = ('0000000032fe677166d54963b62a4677'
'd8957e87c508eaa4fd7eb1c880cd27e3')
DESERIALIZER = lib_tx.DeserializerTxTimeSegWit
DAEMON = daemon.FakeEstimateFeeDaemon
ESTIMATE_FEE = 0.001
RELAY_FEE = 0.01
DESERIALIZER = lib_tx.DeserializerPeercoin
TX_COUNT = 1691771
TX_COUNT_HEIGHT = 455409
TX_PER_BLOCK = 4
RPC_PORT = 9902
REORG_LIMIT = 5000
ESTIMATE_FEE = 0.01

PEERS = [
"electrum.peercoinexplorer.net s"
Expand Down
77 changes: 77 additions & 0 deletions electrumx/lib/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,83 @@ def read_tx(self):
return TxTime(version, time, inputs, outputs, locktime)


class DeserializerPeercoin(DeserializerTxTime):
def _get_version(self):
result, = unpack_le_int32_from(self.binary, self.cursor)
return result

def _read_witness(self, fields):
read_witness_field = self._read_witness_field
return [read_witness_field() for _ in range(fields)]

def _read_witness_field(self):
read_varbytes = self._read_varbytes
return [read_varbytes() for _ in range(self._read_varint())]

def read_tx_no_segwit(self):
version = self._read_le_int32()
if version < 3:
time = self._read_le_uint32()
else:
time = 0
inputs = self._read_inputs()
outputs = self._read_outputs()
locktime = self._read_le_uint32()

return TxTime(version, time, inputs, outputs, locktime)

def _read_tx_parts(self):
'''Return a (deserialized TX, tx_hash, vsize) tuple.'''
start = self.cursor
tx_version = self._get_version()
if tx_version < 3:
marker = self.binary[self.cursor + 8]
else:
marker = self.binary[self.cursor + 4]
if marker:
tx = self.read_tx_no_segwit()
tx_hash = self.TX_HASH_FN(self.binary[start:self.cursor])
return tx, tx_hash, self.binary_length

version = self._read_le_int32()
if version < 3:
time = self._read_le_uint32()
else:
time = 0
orig_ser = self.binary[start:self.cursor]

marker = self._read_byte()
flag = self._read_byte()

start = self.cursor
inputs = self._read_inputs()
outputs = self._read_outputs()
orig_ser += self.binary[start:self.cursor]

base_size = self.cursor - start
witness = self._read_witness(len(inputs))

start = self.cursor
locktime = self._read_le_uint32()
vsize = (3 * base_size + self.binary_length) // 4
orig_ser += self.binary[start:self.cursor]

return TxTimeSegWit(
version, time, marker, flag, inputs, outputs, witness, locktime),\
self.TX_HASH_FN(orig_ser), vsize

def read_tx(self):
return self._read_tx_parts()[0]

def read_tx_and_hash(self):
tx, tx_hash, vsize = self._read_tx_parts()
return tx, tx_hash

def read_tx_and_vsize(self):
tx, tx_hash, vsize = self._read_tx_parts()
return tx, vsize


class DeserializerVerge(Deserializer):
def read_tx(self):
version = self._read_le_int32()
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import setuptools
version = '1.16.0'
version = '1.17.1'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please undo this change


setuptools.setup(
name='e-x',
Expand All @@ -10,7 +10,7 @@
'plyvel', 'pylru', 'aiohttp>=3.3,<4'],
extras_require={
'rapidjson': ['python-rapidjson>=0.4.1,<2.0'],
'rocksdb': ['python-rocksdb>=0.6.9'],
'rocksdb': ['python-rocksdb-static'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? this affects bitcoin users too, so needs proper justification

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the only way I could get it to be installed. Does the python-rocksdb package still work for you?
twmht/python-rocksdb#102

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well it works for the CI on current master.
but I guess it might be compiling against older rocksdb

Nevertheless, please open a separate PR (or issue) for the rocksdb change. It does not belong in this PR.

'ujson': ['ujson>=2.0.0,<4.0.0'],
'uvloop': ['uvloop>=0.14'],
# For various coins
Expand Down
33 changes: 33 additions & 0 deletions tests/blocks/peercointestnet_testnet_447435.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"hash": "9290230cc04c97193329fd91428feda621043d2d7a85b6cc07d8e3f33b664f03",
"confirmations": 3,
"strippedsize": 643,
"size": 643,
"weight": 2572,
"height": 447435,
"version": 3,
"versionHex": "00000003",
"merkleroot": "b96bca2c399f0098b7adfe7d7dfd253e0b62c445309ee8ffea7d25d3b8d19509",
"tx": [
"98c24be762d392fa4931943b2bb76a2ec5bba0c4b33ed6a5387cdf5120d73da8",
"fe73e9ba7fed816ca3f4f38c7318af1167b5c3e22d7ad211567c35c6b61584f0",
"2643399777227af3e56264e9b7e10d392366d55c4b43fbd49ab8d30383aab86d"
],
"time": 1630670342,
"mediantime": 1630666476,
"nonce": 0,
"bits": "1c198d92",
"difficulty": 10.01823673358246,
"mint": 22.005286,
"chainwork": "000000000000000000000000000000000000000000000000008f5b02c39b8fb0",
"nTx": 3,
"previousblockhash": "47ec01035c1a0e7f9c5a546663e339a21d53e3a9c38ca5bf2a9189c7aeff63f0",
"nextblockhash": "86ff472e31375142b07a14c47d487d65e71a17eeb9ff04adcdfb326f06201779",
"flags": "proof-of-stake stake-modifier",
"proofhash": "0000008a51dfb4ebdab640f385f994bd4e3ab32a7bfefb9b063279d6e8e80e19",
"entropybit": 1,
"modifier": "4773822002f7601c",
"modifierchecksum": "aaf73fd7",
"block": "03000000f063ffaec789912abfa58cc3a9e3531da239e36366545a9c7f0e1a5c0301ec470995d1b8d3257deaffe89e3045c4620b3e25fd7d7dfeadb798009f392cca6bb9060e3261928d191c000000000301000000060e32610001010000000000000000000000000000000000000000000000000000000000000000ffffffff0603cbd3060101ffffffff020000000000000000000000000000000000266a24aa21a9edafb6e45993bd8b6a631f177eab298ec58fea32bab934ff26acd59b555fae19d8012000000000000000000000000000000000000000000000000000000000000000000000000001000000060e3261016860fa200ec0723a34ada91401ff4a4033ada4dcc8504d4c42ec18680d9ef2000200000048473044022064d25c34537034b5197cd67cb6dd3d5908a83c99fddfc9f1e2fb4017098b4e6d02207edcd9a976c9a69427d6ced00003286c8e1fd083c913cccaa4d2a07c1a0296a401ffffffff0200000000000000000092f12403000000002321021fa0e5559f9209109186940589c6a77e5ad19d700958b5f7223bc0707d6fcf14ac000000000300000001202c08a0d8a1c6dbd6935586cfeb1f61a8db09b21d91863375c1aa0595225c4701000000484730440220327b9a2bc78f1a009a3f6d84f83c0a69f560af1e66ac0b7becaa783859f5c9b70220275cf4fe3f50c4eb1134052d7858e206086ef232e8414d1b97cb58f96cce010901feffffff0158bd8910000000001976a914ef3f4461e03bb661dc168413ca480e9be197e12988accad30600473045022100a97494f3151092702e5dbf47e938c1205137aa149cf7e6287926f227189fa8a5022006eb15f10a809dc4894ef882be1ac6c66f6aa0107aa836d589a789cf40800628",
"blocksignature": "3045022100a97494f3151092702e5dbf47e938c1205137aa149cf7e6287926f227189fa8a5022006eb15f10a809dc4894ef882be1ac6c66f6aa0107aa836d589a789cf40800628"
}
40 changes: 40 additions & 0 deletions tests/transactions/peercointestnet_testnet_929023.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"blockhash": "9290230cc04c97193329fd91428feda621043d2d7a85b6cc07d8e3f33b664f03",
"blocktime": 1630670342,
"confirmations": 2,
"hash": "2643399777227af3e56264e9b7e10d392366d55c4b43fbd49ab8d30383aab86d",
"hex": "0300000001202c08a0d8a1c6dbd6935586cfeb1f61a8db09b21d91863375c1aa0595225c4701000000484730440220327b9a2bc78f1a009a3f6d84f83c0a69f560af1e66ac0b7becaa783859f5c9b70220275cf4fe3f50c4eb1134052d7858e206086ef232e8414d1b97cb58f96cce010901feffffff0158bd8910000000001976a914ef3f4461e03bb661dc168413ca480e9be197e12988accad30600",
"locktime": 447434,
"size": 157,
"time": 1630670342,
"txid": "2643399777227af3e56264e9b7e10d392366d55c4b43fbd49ab8d30383aab86d",
"version": 3,
"vin": [
{
"scriptSig": {
"asm": "30440220327b9a2bc78f1a009a3f6d84f83c0a69f560af1e66ac0b7becaa783859f5c9b70220275cf4fe3f50c4eb1134052d7858e206086ef232e8414d1b97cb58f96cce0109[ALL]",
"hex": "4730440220327b9a2bc78f1a009a3f6d84f83c0a69f560af1e66ac0b7becaa783859f5c9b70220275cf4fe3f50c4eb1134052d7858e206086ef232e8414d1b97cb58f96cce010901"
},
"sequence": 4294967294,
"txid": "475c229505aac1753386911db209dba8611febcf865593d6dbc6a1d8a0082c20",
"vout": 1
}
],
"vout": [
{
"n": 0,
"scriptPubKey": {
"addresses": [
"n3Kyan5GXUFp8jvo3t3Fu8Ry8LN4qWeR3c"
],
"asm": "OP_DUP OP_HASH160 ef3f4461e03bb661dc168413ca480e9be197e129 OP_EQUALVERIFY OP_CHECKSIG",
"hex": "76a914ef3f4461e03bb661dc168413ca480e9be197e12988ac",
"reqSigs": 1,
"type": "pubkeyhash"
},
"value": 277462360
}
],
"vsize": 157,
"weight": 628
}