Esempio n. 1
0
    def FromTrimmedData(data, index):
        """
        Deserialize into a Header object from the provided data.

        Args:
            data (bytes):
            index: UNUSED

        Returns:
            Header:
        """
        header = Header()

        ms = StreamManager.GetStream(data)

        reader = BinaryReader(ms)
        header.DeserializeUnsigned(reader)
        reader.ReadByte()

        witness = Witness()
        witness.Deserialize(reader)
        header.Script = witness

        StreamManager.ReleaseStream(ms)

        return header
Esempio n. 2
0
    def FromTrimmedData(byts):
        """
        Deserialize a block from raw bytes.

        Args:
            byts:

        Returns:
            Block:
        """
        block = Block()
        block.__is_trimmed = True
        ms = StreamManager.GetStream(byts)
        reader = BinaryReader(ms)

        block.DeserializeUnsigned(reader)
        reader.ReadByte()
        witness = Witness()
        witness.Deserialize(reader)
        block.Script = witness

        bc = GetBlockchain()
        tx_list = []
        for tx_hash in reader.ReadHashes():
            tx = bc.GetTransaction(tx_hash)[0]
            if not tx:
                raise Exception("Could not find transaction!\n Are you running code against a valid Blockchain instance?\n Tests that accesses transactions or size of a block but inherit from NeoTestCase instead of BlockchainFixtureTestCase will not work.")
            tx_list.append(tx)

        block.Transactions = tx_list

        StreamManager.ReleaseStream(ms)

        return block
Esempio n. 3
0
    def DeserializeFrom(reader):
        ttype = reader.ReadByte()
        tx = None

        from neo.Core.TX.RegisterTransaction import RegisterTransaction
        from neo.Core.TX.IssueTransaction import IssueTransaction
        from neo.Core.TX.ClaimTransaction import ClaimTransaction
        from neo.Core.TX.MinerTransaction import MinerTransaction

        if ttype == int.from_bytes(TransactionType.RegisterTransaction,
                                   'little'):
            tx = RegisterTransaction()
        elif ttype == int.from_bytes(TransactionType.MinerTransaction,
                                     'little'):
            tx = MinerTransaction()
        elif ttype == int.from_bytes(TransactionType.IssueTransaction,
                                     'little'):
            tx = IssueTransaction()
        elif ttype == int.from_bytes(TransactionType.ClaimTransaction,
                                     'little'):
            tx = ClaimTransaction()

        tx.DeserializeUnsignedWithoutType(reader)

        try:
            witness = Witness()
            witness.Deserialize(reader)
            tx.scripts = [witness]
        except Exception as e:
            pass

        tx.OnDeserialized()

        return tx
Esempio n. 4
0
    def FromTrimmedData(byts, index=None, transaction_method=None):
        """
        Deserialize a block from raw bytes.

        Args:
            byts:
            index: UNUSED
            transaction_method: UNUSED

        Returns:
            Block:
        """
        block = Block()
        block.__is_trimmed = True
        ms = StreamManager.GetStream(byts)
        reader = BinaryReader(ms)

        block.DeserializeUnsigned(reader)
        reader.ReadByte()
        witness = Witness()
        witness.Deserialize(reader)
        block.witness = witness

        block.Transactions = reader.ReadHashes()

        StreamManager.ReleaseStream(ms)

        return block
Esempio n. 5
0
    def FromTrimmedData(byts):
        """
        Deserialize a block from raw bytes.

        Args:
            byts:

        Returns:
            Block:
        """
        block = Block()
        block.__is_trimmed = True
        ms = StreamManager.GetStream(byts)
        reader = BinaryReader(ms)

        block.DeserializeUnsigned(reader)
        reader.ReadByte()
        witness = Witness()
        witness.Deserialize(reader)
        block.Script = witness

        block.Transactions = reader.ReadHashes()

        StreamManager.ReleaseStream(ms)

        return block
Esempio n. 6
0
    def Deserialize(self, reader):
        self.DeserializeUnsigned(reader)
        byt = reader.ReadByte()
        if int(byt) != 1:
            raise Exception('Incorrect format')

        witness = Witness()
        witness.Deserialize(reader)
        self.Script = witness
Esempio n. 7
0
    def DeserializeFrom(reader):
        """
        Deserialize full object.

        Args:
            reader (neo.IO.BinaryReader):

        Returns:
            Transaction:
        """
        ttype = reader.ReadByte()
        tx = None

        from neo.Core.TX.RegisterTransaction import RegisterTransaction
        from neo.Core.TX.IssueTransaction import IssueTransaction
        from neo.Core.TX.ClaimTransaction import ClaimTransaction
        from neo.Core.TX.MinerTransaction import MinerTransaction
        from neo.Core.TX.PublishTransaction import PublishTransaction
        from neo.Core.TX.InvocationTransaction import InvocationTransaction
        from neo.Core.TX.EnrollmentTransaction import EnrollmentTransaction
        from neo.Core.TX.StateTransaction import StateTransaction

        if ttype == int.from_bytes(TransactionType.RegisterTransaction, 'little'):
            tx = RegisterTransaction()
        elif ttype == int.from_bytes(TransactionType.MinerTransaction, 'little'):
            tx = MinerTransaction()
        elif ttype == int.from_bytes(TransactionType.IssueTransaction, 'little'):
            tx = IssueTransaction()
        elif ttype == int.from_bytes(TransactionType.ClaimTransaction, 'little'):
            tx = ClaimTransaction()
        elif ttype == int.from_bytes(TransactionType.PublishTransaction, 'little'):
            tx = PublishTransaction()
        elif ttype == int.from_bytes(TransactionType.InvocationTransaction, 'little'):
            tx = InvocationTransaction()
        elif ttype == int.from_bytes(TransactionType.EnrollmentTransaction, 'little'):
            tx = EnrollmentTransaction()
        elif ttype == int.from_bytes(TransactionType.StateTransaction, 'little'):
            tx = StateTransaction()
        else:
            tx = Transaction()
            tx.Type = ttype

        tx.DeserializeUnsignedWithoutType(reader)

        tx.scripts = []
        byt = reader.ReadVarInt()

        if byt > 0:
            for i in range(0, byt):
                witness = Witness()
                witness.Deserialize(reader)

                tx.scripts.append(witness)

        tx.OnDeserialized()

        return tx
Esempio n. 8
0
    def DeserializeFrom(self, reader):
        """
        Deserialize full object.

        Args:
            reader (neo.IO.BinaryReader):
        """
        ttype = reader.ReadByte()

        if ttype == int.from_bytes(TransactionType.RegisterTransaction,
                                   'little'):
            self.Type = TransactionType.RegisterTransaction
        elif ttype == int.from_bytes(TransactionType.MinerTransaction,
                                     'little'):
            self.Type = TransactionType.MinerTransaction
        elif ttype == int.from_bytes(TransactionType.IssueTransaction,
                                     'little'):
            self.Type = TransactionType.IssueTransaction
        elif ttype == int.from_bytes(TransactionType.ClaimTransaction,
                                     'little'):
            self.Type = TransactionType.ClaimTransaction
        elif ttype == int.from_bytes(TransactionType.PublishTransaction,
                                     'little'):
            self.Type = TransactionType.PublishTransaction
        elif ttype == int.from_bytes(TransactionType.InvocationTransaction,
                                     'little'):
            self.Type = TransactionType.InvocationTransaction
        elif ttype == int.from_bytes(TransactionType.EnrollmentTransaction,
                                     'little'):
            self.Type = TransactionType.EnrollmentTransaction
        elif ttype == int.from_bytes(TransactionType.StateTransaction,
                                     'little'):
            self.Type = TransactionType.StateTransaction
        else:
            self.Type = ttype

        self.DeserializeUnsignedWithoutType(reader)

        self.scripts = []
        byt = reader.ReadVarInt()

        if byt > 0:
            for i in range(0, byt):
                witness = Witness()
                witness.Deserialize(reader)

                self.scripts.append(witness)

        self.OnDeserialized()
Esempio n. 9
0
    def Deserialize(self, reader):
        """
        Deserialize full object.

        Args:
            reader (neo.IO.BinaryReader):
        """
        self.DeserializeUnsigned(reader)
        byt = reader.ReadByte()
        if int(byt) != 1:
            raise Exception('Incorrect format')

        witness = Witness()
        witness.Deserialize(reader)
        self.Script = witness
Esempio n. 10
0
    def FromTrimmedData(data, index):

        header = Header()

        ms = MemoryStream(data)

        reader = BinaryReader(ms)

        header.DeserializeUnsigned(reader)
        reader.ReadByte()

        witness = Witness()
        witness.Deserialize(reader)
        header.Script = witness

        return header
Esempio n. 11
0
    def FromTrimmedData(data, index):

        header = Header()

        ms = StreamManager.GetStream(data)

        reader = BinaryReader(ms)
        header.DeserializeUnsigned(reader)
        reader.ReadByte()

        witness = Witness()
        witness.Deserialize(reader)
        header.Script = witness

        StreamManager.ReleaseStream(ms)

        return header
Esempio n. 12
0
    def FromTrimmedData(byts, index, transaction_method=None):

        block = Block()
        block.__is_trimmed = True
        ms = StreamManager.GetStream(byts)
        reader = BinaryReader(ms)

        block.DeserializeUnsigned(reader)
        reader.ReadByte()
        witness = Witness()
        witness.Deserialize(reader)
        block.witness = witness

        block.Transactions = reader.ReadHashes()

        StreamManager.ReleaseStream(ms)

        return block