Rename struct pack/unpack to reflect endianess
This commit is contained in:
parent
ea627db837
commit
fa0a58a280
@ -31,8 +31,8 @@ from collections import namedtuple
|
|||||||
|
|
||||||
from electrumx.lib.hash import sha256, double_sha256, hash_to_hex_str
|
from electrumx.lib.hash import sha256, double_sha256, hash_to_hex_str
|
||||||
from electrumx.lib.util import (
|
from electrumx.lib.util import (
|
||||||
cachedproperty, unpack_int32_from, unpack_int64_from,
|
cachedproperty, unpack_le_int32_from, unpack_le_int64_from,
|
||||||
unpack_uint16_from, unpack_uint32_from, unpack_uint64_from,
|
unpack_le_uint16_from, unpack_le_uint32_from, unpack_le_uint64_from,
|
||||||
pack_le_int32, pack_varint, pack_le_uint32, pack_le_uint32, pack_le_int64,
|
pack_le_int32, pack_varint, pack_le_uint32, pack_le_uint32, pack_le_int64,
|
||||||
pack_varbytes,
|
pack_varbytes,
|
||||||
)
|
)
|
||||||
@ -185,27 +185,27 @@ class Deserializer(object):
|
|||||||
return self._read_le_uint64()
|
return self._read_le_uint64()
|
||||||
|
|
||||||
def _read_le_int32(self):
|
def _read_le_int32(self):
|
||||||
result, = unpack_int32_from(self.binary, self.cursor)
|
result, = unpack_le_int32_from(self.binary, self.cursor)
|
||||||
self.cursor += 4
|
self.cursor += 4
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _read_le_int64(self):
|
def _read_le_int64(self):
|
||||||
result, = unpack_int64_from(self.binary, self.cursor)
|
result, = unpack_le_int64_from(self.binary, self.cursor)
|
||||||
self.cursor += 8
|
self.cursor += 8
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _read_le_uint16(self):
|
def _read_le_uint16(self):
|
||||||
result, = unpack_uint16_from(self.binary, self.cursor)
|
result, = unpack_le_uint16_from(self.binary, self.cursor)
|
||||||
self.cursor += 2
|
self.cursor += 2
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _read_le_uint32(self):
|
def _read_le_uint32(self):
|
||||||
result, = unpack_uint32_from(self.binary, self.cursor)
|
result, = unpack_le_uint32_from(self.binary, self.cursor)
|
||||||
self.cursor += 4
|
self.cursor += 4
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _read_le_uint64(self):
|
def _read_le_uint64(self):
|
||||||
result, = unpack_uint64_from(self.binary, self.cursor)
|
result, = unpack_le_uint64_from(self.binary, self.cursor)
|
||||||
self.cursor += 8
|
self.cursor += 8
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
@ -330,24 +330,24 @@ def protocol_version(client_req, min_tuple, max_tuple):
|
|||||||
return result, client_min
|
return result, client_min
|
||||||
|
|
||||||
|
|
||||||
structi = Struct('<i')
|
struct_le_i = Struct('<i')
|
||||||
structq = Struct('<q')
|
struct_le_q = Struct('<q')
|
||||||
structH = Struct('<H')
|
struct_le_H = Struct('<H')
|
||||||
structI = Struct('<I')
|
struct_le_I = Struct('<I')
|
||||||
structQ = Struct('<Q')
|
struct_le_Q = Struct('<Q')
|
||||||
structB = Struct('B')
|
structB = Struct('B')
|
||||||
|
|
||||||
unpack_int32_from = structi.unpack_from
|
unpack_le_int32_from = struct_le_i.unpack_from
|
||||||
unpack_int64_from = structq.unpack_from
|
unpack_le_int64_from = struct_le_q.unpack_from
|
||||||
unpack_uint16_from = structH.unpack_from
|
unpack_le_uint16_from = struct_le_H.unpack_from
|
||||||
unpack_uint32_from = structI.unpack_from
|
unpack_le_uint32_from = struct_le_I.unpack_from
|
||||||
unpack_uint64_from = structQ.unpack_from
|
unpack_le_uint64_from = struct_le_Q.unpack_from
|
||||||
|
|
||||||
pack_le_int32 = structi.pack
|
pack_le_int32 = struct_le_i.pack
|
||||||
pack_le_int64 = structq.pack
|
pack_le_int64 = struct_le_q.pack
|
||||||
pack_le_uint16 = structH.pack
|
pack_le_uint16 = struct_le_H.pack
|
||||||
pack_le_uint32 = structI.pack
|
pack_le_uint32 = struct_le_I.pack
|
||||||
pack_le_uint64 = structQ.pack
|
pack_le_uint64 = struct_le_Q.pack
|
||||||
pack_byte = structB.pack
|
pack_byte = structB.pack
|
||||||
|
|
||||||
hex_to_bytes = bytes.fromhex
|
hex_to_bytes = bytes.fromhex
|
||||||
|
|||||||
@ -18,7 +18,7 @@ from time import strptime
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from electrumx.lib.util import int_to_varint, hex_to_bytes, class_logger, \
|
from electrumx.lib.util import int_to_varint, hex_to_bytes, class_logger, \
|
||||||
unpack_uint16_from
|
unpack_le_uint16_from
|
||||||
from electrumx.lib.hash import hex_str_to_hash, hash_to_hex_str
|
from electrumx.lib.hash import hex_str_to_hash, hash_to_hex_str
|
||||||
from electrumx.lib.tx import DeserializerDecred
|
from electrumx.lib.tx import DeserializerDecred
|
||||||
from aiorpcx import JSONRPC
|
from aiorpcx import JSONRPC
|
||||||
@ -384,7 +384,7 @@ class DecredDaemon(Daemon):
|
|||||||
raw_blocks.append(raw_block)
|
raw_blocks.append(raw_block)
|
||||||
# Check if previous block is valid
|
# Check if previous block is valid
|
||||||
prev = self.prev_hex_hash(raw_block)
|
prev = self.prev_hex_hash(raw_block)
|
||||||
votebits = unpack_uint16_from(raw_block[100:102])[0]
|
votebits = unpack_le_uint16_from(raw_block[100:102])[0]
|
||||||
valid_tx_tree[prev] = self.is_valid_tx_tree(votebits)
|
valid_tx_tree[prev] = self.is_valid_tx_tree(votebits)
|
||||||
|
|
||||||
processed_raw_blocks = []
|
processed_raw_blocks = []
|
||||||
|
|||||||
@ -208,17 +208,17 @@ def test_protocol_version():
|
|||||||
|
|
||||||
def test_unpackers():
|
def test_unpackers():
|
||||||
b = bytes(range(256))
|
b = bytes(range(256))
|
||||||
assert util.unpack_int32_from(b, 0) == (50462976,)
|
assert util.unpack_le_int32_from(b, 0) == (50462976,)
|
||||||
assert util.unpack_int32_from(b, 42) == (757869354,)
|
assert util.unpack_le_int32_from(b, 42) == (757869354,)
|
||||||
assert util.unpack_int64_from(b, 0) == (506097522914230528,)
|
assert util.unpack_le_int64_from(b, 0) == (506097522914230528,)
|
||||||
assert util.unpack_int64_from(b, 42) == (3544384782113450794,)
|
assert util.unpack_le_int64_from(b, 42) == (3544384782113450794,)
|
||||||
|
|
||||||
assert util.unpack_uint16_from(b, 0) == (256,)
|
assert util.unpack_le_uint16_from(b, 0) == (256,)
|
||||||
assert util.unpack_uint16_from(b, 42) == (11050,)
|
assert util.unpack_le_uint16_from(b, 42) == (11050,)
|
||||||
assert util.unpack_uint32_from(b, 0) == (50462976,)
|
assert util.unpack_le_uint32_from(b, 0) == (50462976,)
|
||||||
assert util.unpack_uint32_from(b, 42) == (757869354,)
|
assert util.unpack_le_uint32_from(b, 42) == (757869354,)
|
||||||
assert util.unpack_uint64_from(b, 0) == (506097522914230528,)
|
assert util.unpack_le_uint64_from(b, 0) == (506097522914230528,)
|
||||||
assert util.unpack_uint64_from(b, 42) == (3544384782113450794,)
|
assert util.unpack_le_uint64_from(b, 42) == (3544384782113450794,)
|
||||||
|
|
||||||
def test_hex_transforms():
|
def test_hex_transforms():
|
||||||
h = "AABBCCDDEEFF"
|
h = "AABBCCDDEEFF"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user