Rename struct pack/unpack to reflect endianess

This commit is contained in:
John L. Jegutanis 2018-08-13 14:44:07 +02:00
parent ea627db837
commit fa0a58a280
4 changed files with 34 additions and 34 deletions

View File

@ -31,8 +31,8 @@ from collections import namedtuple
from electrumx.lib.hash import sha256, double_sha256, hash_to_hex_str
from electrumx.lib.util import (
cachedproperty, unpack_int32_from, unpack_int64_from,
unpack_uint16_from, unpack_uint32_from, unpack_uint64_from,
cachedproperty, unpack_le_int32_from, unpack_le_int64_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_varbytes,
)
@ -185,27 +185,27 @@ class Deserializer(object):
return self._read_le_uint64()
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
return result
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
return result
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
return result
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
return result
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
return result

View File

@ -330,24 +330,24 @@ def protocol_version(client_req, min_tuple, max_tuple):
return result, client_min
structi = Struct('<i')
structq = Struct('<q')
structH = Struct('<H')
structI = Struct('<I')
structQ = Struct('<Q')
struct_le_i = Struct('<i')
struct_le_q = Struct('<q')
struct_le_H = Struct('<H')
struct_le_I = Struct('<I')
struct_le_Q = Struct('<Q')
structB = Struct('B')
unpack_int32_from = structi.unpack_from
unpack_int64_from = structq.unpack_from
unpack_uint16_from = structH.unpack_from
unpack_uint32_from = structI.unpack_from
unpack_uint64_from = structQ.unpack_from
unpack_le_int32_from = struct_le_i.unpack_from
unpack_le_int64_from = struct_le_q.unpack_from
unpack_le_uint16_from = struct_le_H.unpack_from
unpack_le_uint32_from = struct_le_I.unpack_from
unpack_le_uint64_from = struct_le_Q.unpack_from
pack_le_int32 = structi.pack
pack_le_int64 = structq.pack
pack_le_uint16 = structH.pack
pack_le_uint32 = structI.pack
pack_le_uint64 = structQ.pack
pack_le_int32 = struct_le_i.pack
pack_le_int64 = struct_le_q.pack
pack_le_uint16 = struct_le_H.pack
pack_le_uint32 = struct_le_I.pack
pack_le_uint64 = struct_le_Q.pack
pack_byte = structB.pack
hex_to_bytes = bytes.fromhex

View File

@ -18,7 +18,7 @@ from time import strptime
import aiohttp
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.tx import DeserializerDecred
from aiorpcx import JSONRPC
@ -384,7 +384,7 @@ class DecredDaemon(Daemon):
raw_blocks.append(raw_block)
# Check if previous block is valid
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)
processed_raw_blocks = []

View File

@ -208,17 +208,17 @@ def test_protocol_version():
def test_unpackers():
b = bytes(range(256))
assert util.unpack_int32_from(b, 0) == (50462976,)
assert util.unpack_int32_from(b, 42) == (757869354,)
assert util.unpack_int64_from(b, 0) == (506097522914230528,)
assert util.unpack_int64_from(b, 42) == (3544384782113450794,)
assert util.unpack_le_int32_from(b, 0) == (50462976,)
assert util.unpack_le_int32_from(b, 42) == (757869354,)
assert util.unpack_le_int64_from(b, 0) == (506097522914230528,)
assert util.unpack_le_int64_from(b, 42) == (3544384782113450794,)
assert util.unpack_uint16_from(b, 0) == (256,)
assert util.unpack_uint16_from(b, 42) == (11050,)
assert util.unpack_uint32_from(b, 0) == (50462976,)
assert util.unpack_uint32_from(b, 42) == (757869354,)
assert util.unpack_uint64_from(b, 0) == (506097522914230528,)
assert util.unpack_uint64_from(b, 42) == (3544384782113450794,)
assert util.unpack_le_uint16_from(b, 0) == (256,)
assert util.unpack_le_uint16_from(b, 42) == (11050,)
assert util.unpack_le_uint32_from(b, 0) == (50462976,)
assert util.unpack_le_uint32_from(b, 42) == (757869354,)
assert util.unpack_le_uint64_from(b, 0) == (506097522914230528,)
assert util.unpack_le_uint64_from(b, 42) == (3544384782113450794,)
def test_hex_transforms():
h = "AABBCCDDEEFF"