def __init__(self, flags=0):
     self.BLOCKHEADER = Structure([
         Field("<I", "version"),
         Uint256Serializer("hash_prev"),
         Uint256Serializer("hash_merkle"),
         Field("<I", "time"),
         Field("<I", "bits"),
         Field("<I", "nonce")
     ], "txindex")
class BlockIndexSerializer():
    BLOCKINDEX = Structure([Field("<I", "version"),
                            Uint256Serializer("hash_next"),
                            Field("<I", "file"),
                            Field("<I", "blockpos"),
                            Field("<I", "height"),
                            BlockheaderSerializer()], "txindex")
    
    def __init__(self):
        pass
        
    def serialize(self, blockindex_obj):
        return (self.BLOCKINDEX.serialize([blockindex_obj.version,
                                           blockindex_obj.hash_next,
                                           blockindex_obj.file,
                                           blockindex_obj.blockpos,
                                           blockindex_obj.height,
                                           blockindex_obj.blockheader]))

    def deserialize(self, data, cursor=0):
        result, cursor = self.BLOCKINDEX.deserialize(data, cursor)
        (version, hash_next, file, blockpos, height, blockheader) = result
        return (DbBlockIndex(version, hash_next, file, blockpos, height, blockheader), cursor)

        
Beispiel #3
0
 def __init__(self, bsddb_env, filename):
     self.bsddb_env = bsddb_env
     self.filename = filename
     self.varstr_serializer = VarstrSerializer()
     self.uint256_serializer = Uint256Serializer("")
     self.wallet_tx_serializer = WalletTxSerializer()
     self.master_key_serializer = MasterKeySerializer()
     self.reset_wallet()
     self.db = bsddb.db.DB(self.bsddb_env.dbenv)
     self.dbflags = bsddb.db.DB_THREAD
Beispiel #4
0
 def test_uint256_deserialize(self):
     uint256, _ = Uint256Serializer().deserialize(
         decodehexstr(
             "6a921ac1ae5e23610d07d2b2a9377fbc3c3bb233e900aa1a5bc40f5562a19d0d"
         ))
     self.assertEquals(
         uint256,
         Uint256.from_hexstr(
             "0d9da162550fc45b1aaa00e933b23b3cbc7f37a9b2d2070d61235eaec11a926a"
         ))
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)
Beispiel #6
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)
Beispiel #7
0
class MerkleTxSerializer(Serializer):
    MERKLE_TX = Structure([
        TxSerializer(),
        Uint256Serializer(),
        VarsizelistSerializer(VarintSerializer(), Uint256Serializer()),
        Field("<I", "nindex")
    ], "tx")

    def get_size(self, tx):
        return (self.MERKLE_TX.get_size(
            [tx.tx, tx.blockhash, tx.merkle_branch, tx.nindex]))

    def serialize(self, tx):
        return (self.MERKLE_TX.serialize(
            [tx.tx, tx.blockhash, tx.merkle_branch, tx.nindex]))

    def deserialize(self, data, cursor=0):
        (tx, blockhash, merkle_branch,
         nindex), cursor = self.MERKLE_TX.deserialize(data, cursor)
        return (MerkleTx(tx, blockhash, merkle_branch, nindex), cursor)
Beispiel #8
0
class OutpointSerializer(Serializer):
    OUTPOINT = Structure([Uint256Serializer("hash"),
                          Field("<I","index")], "outpoint")

    def get_size(self, outpoint):
        return (self.OUTPOINT.get_size([outpoint.hash, outpoint.index]))
    
    def serialize(self, outpoint):
        return (self.OUTPOINT.serialize([outpoint.hash, outpoint.index]))

    def deserialize(self, data, cursor=0):
        (hash, index), cursor = self.OUTPOINT.deserialize(data, cursor)
        return (Outpoint(hash, index), cursor)
Beispiel #9
0
class InvitemSerializer(Serializer):
    INVITEM_ENC = Structure(
        [Field("<I", "type"), Uint256Serializer("hash")], "getblocks")

    def get_size(self, invitem):
        return (self.INVITEM_ENC.get_size(invitem.type, invitem.hash))

    def serialize(self, invitem):
        return (self.INVITEM_ENC.serialize([invitem.type, invitem.hash]))

    def deserialize(self, data, cursor=0):
        (type, hash), cursor = self.INVITEM_ENC.deserialize(data, cursor)
        if (type not in INV_ITEMS):
            raise FormatErrorException("Unknown inventory item")
        return (Invitem(type, hash), cursor)
 def __init__(self, flags=0):
     self.BLOCKLOCATOR = Structure([Field("<I", "version"),  
                                   VarsizelistSerializer(VarintSerializer("count"), Uint256Serializer("locator"))])