Ejemplo n.º 1
0
 def test_blocklocator_deserialize(self):
     loc, cursor = BlockLocatorSerializer().deserialize(
         decodehexstr(
             "0100000005a329e1166037b2ea0cfbef5060c011c1cbbd37ad047a47b62d3dae020000000070bdb41302a622800ddfb2b3ebdd937fdca812ec8a7ab90ef250410700000000398052b24b2cc45ef953222e23880d25c3df95a913e72e9b015b34250000000066739a04b15f117929b581f6fe0ba2906bc4323829400f949086bb7d0000000008b067b31dc139ee8e7a76a4f2cfcca477c4c06e1ef89f4ae308951907000000"
         ))
     self.assertEquals(
         loc,
         BlockLocator(
             version=1,
             blockhashlist=[
                 Uint256.from_hexstr(
                     "0000000002ae3d2db6477a04ad37bdcbc111c06050effb0ceab2376016e129a3"
                 ),
                 Uint256.from_hexstr(
                     "00000000074150f20eb97a8aec12a8dc7f93ddebb3b2df0d8022a60213b4bd70"
                 ),
                 Uint256.from_hexstr(
                     "0000000025345b019b2ee713a995dfc3250d88232e2253f95ec42c4bb2528039"
                 ),
                 Uint256.from_hexstr(
                     "000000007dbb8690940f40293832c46b90a20bfef681b52979115fb1049a7366"
                 ),
                 Uint256.from_hexstr(
                     "00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"
                 )
             ]))
Ejemplo n.º 2
0
class GetheadersMessageSerializer(Serializer):
    GETHEADERS = Structure([BlockLocatorSerializer(), Uint256Serializer()])

    def serialize(self, getheaders_msg):
        return (self.GETHEADERS.serialize(
            [getheaders_msg.blocklocator, getheaders_msg.hash_stop]))

    def deserialize(self, data, cursor=0):
        (blocklocator,
         hash_stop), cursor = self.GETHEADERS.deserialize(data, cursor)
        return (GetheadersMessage(blocklocator, hash_stop), cursor)
Ejemplo n.º 3
0
class GetblocksMessageSerializer(Serializer):
    GETBLOCKS = Structure([BlockLocatorSerializer(),
                           Uint256Serializer("stop")], "getblocks")
    
    def serialize(self, getblocks_msg):
        return (self.GETBLOCKS.serialize([getblocks_msg.block_locator,
                                          getblocks_msg.hash_stop]))

    def deserialize(self, data, cursor=0):
        (block_locator, hash_stop), cursor = self.GETBLOCKS.deserialize(data, cursor)
        return (GetblocksMessage(block_locator, hash_stop), cursor)
Ejemplo n.º 4
0
 def set_blocklocator(self, blocklocator):
     serializer = BlockLocatorSerializer()
     self.db["\x09bestblock"] = serializer.serialize(blocklocator)
Ejemplo n.º 5
0
 def get_block_locator(self):
     if self.db.has_key("\x09bestblock"):
         serializer = BlockLocatorSerializer()
         block_locator, cursor = serializer.deserialize(
             self.db["\x09bestblock"], 0)
         return block_locator
Ejemplo n.º 6
0
 def set_blocklocator(self, blocklocator):
     serializer = BlockLocatorSerializer()
     self.db["\x09bestblock"] = serializer.serialize(blocklocator)
Ejemplo n.º 7
0
 def get_block_locator(self):
     if self.db.has_key("\x09bestblock"):
         serializer = BlockLocatorSerializer()
         block_locator, cursor = serializer.deserialize(self.db["\x09bestblock"], 0)
         return block_locator