Ejemplo n.º 1
0
    def parse(self, raw_data):
        deserializer = Deserializer(raw_data)

        self.timestamp = deserializer.parse_u32()

        hash_count = deserializer.parse_u16()

        self.prev_hashes = []
        for i in range(0, hash_count):
            prev_hash = deserializer.read_and_move(32)
            self.prev_hashes.append(prev_hash)

        system_tx_count = deserializer.parse_u8()
        self.system_txs = []
        for i in range(0, system_tx_count):
            tx = TransactionParser.parse(
                deserializer.data
            )  # TODO: (is) Better to deserialize passing deserializer directly
            self.system_txs.append(tx)
            deserializer.read_and_move(tx.get_len() + 1)  # one byte for type

        payment_tx_count = deserializer.parse_u8()
        self.payment_txs = []
        for i in range(0, payment_tx_count):
            tx = TransactionParser.parse(
                deserializer.data
            )  # TODO: (is) Better to deserialize passing deserializer directly
            self.payment_txs.append(tx)
            deserializer.read_and_move(tx.get_len() + 1)  # one byte for type
    def parse(raw_data):
        deserializer = Deserializer(raw_data)
        tx_type = deserializer.parse_u8()
        if tx_type == Type.PUBLIC:
            tx = PublicKeyTransaction()
        elif tx_type == Type.RANDOM:
            tx = SplitRandomTransaction()
        elif tx_type == Type.PRIVATE:
            tx = PrivateKeyTransaction()
        elif tx_type == Type.COMMIT:
            tx = CommitRandomTransaction()
        elif tx_type == Type.REVEAL:
            tx = RevealRandomTransaction()

        elif tx_type == Type.STAKEHOLD:
            tx = StakeHoldTransaction()
        elif tx_type == Type.STAKERELEASE:
            tx = StakeReleaseTransaction()
        elif tx_type == Type.PENALTY:
            tx = PenaltyTransaction()

        elif tx_type == Type.NEGATIVE_GOSSIP:
            tx = NegativeGossipTransaction()
        elif tx_type == Type.POSITIVE_GOSSIP:
            tx = PositiveGossipTransaction()
        elif tx_type == Type.PENALTY_GOSSIP:
            tx = PenaltyGossipTransaction()

        elif tx_type == Type.PAYMENT:
            tx = PaymentTransaction()
        else:
            assert False, "Cannot parse unknown transaction type"
        tx.parse(deserializer.data)
        return tx
Ejemplo n.º 3
0
 def parse(self, raw_data):
     deserializer = Deserializer(raw_data)
     conflict_count = deserializer.parse_u8()
     self.conflicts = []
     for _ in range(0, conflict_count):
         conflict = deserializer.parse_hash()
         self.conflicts.append(conflict)
     self.signature = deserializer.parse_signature()
     self.len = deserializer.len
 def parse(self, raw_data):
     deserializer = Deserializer(raw_data)
     self.signature = deserializer.parse_signature()
     self.pubkey_index = deserializer.parse_u32()
     self.pieces = []
     pieces_len = deserializer.parse_u16()
     for _ in range(0, pieces_len):
         piece_size = deserializer.parse_u8()
         piece = deserializer.read_and_move(piece_size)
         self.pieces.append(piece)
     self.len = deserializer.get_len()
Ejemplo n.º 5
0
 def parse(self, raw_data):
     deserializer = Deserializer(raw_data)
     self.input = deserializer.parse_hash()
     self.number = deserializer.parse_u32() #TODO we made input number contain more bytes just for coinbase
     
     output_count = deserializer.parse_u8()
     self.outputs = []
     for _ in range(output_count):
         self.outputs.append(deserializer.parse_hash())
     
     self.amounts = []
     for _ in range(output_count): #amount count must be the same as output count
         self.amounts.append(deserializer.parse_u32())
     self.len = deserializer.len