Ejemplo n.º 1
0
 async def serialize(self):
     output = b""
     output += struct.pack("H", self.type)
     output += writeUint48(self.time)
     output += write_with_length(self.remark)
     output += await self._write_data()
     output += await self.coin_data.serialize()
     output += self.scriptSig is not None and write_with_length(
         self.scriptSig) or PLACE_HOLDER
     return output
Ejemplo n.º 2
0
    def get_hash(self):
        if self.hash_varint:
            values = bytes((self.type,)) \
                    + bytes((255,)) + writeUint64(self.time)
        else:
            values = struct.pack("H", self.type) \
                    + writeUint48(self.time)

        values += write_with_length(self.remark) \
                + self._write_data() \
                + self.coin_data.serialize()

        hash_bytes = hash_twice(values)
        hash = NulsDigestData(data=hash_bytes, alg_type=0)
        return hash
Ejemplo n.º 3
0
    def serialize(self):
        output = b""
        if self.rawScript is not None:
            output += write_with_length(self.rawScript)
        elif self.fromHash is not None:
            output += write_with_length(self.fromHash +
                                        bytes([self.fromIndex]))
        elif self.address is not None:
            output += write_with_length(self.address)
        else:
            raise ValueError(
                "Either fromHash and fromId should be set or address.")

        output += struct.pack("Q", self.na)
        output += writeUint48(self.lockTime)
        return output
Ejemplo n.º 4
0
    async def serialize(self, for_hash=False, tx_count=None):
        if tx_count is None:
            tx_count = self.txCount

        out = bytes()
        out += self._prepare(self.preHash)
        out += self._prepare(self.merkleHash)
        out += writeUint48(self.time)
        out += struct.pack("II", self.height, tx_count)
        out += write_with_length(self.extend)
        if for_hash:
            out += self._prepare(None)
        else:
            out += self._prepare(self.scriptSig)

        return out
Ejemplo n.º 5
0
    async def parse(self, buffer, cursor=0):
        st_cursor = cursor
        self.type = struct.unpack("H", buffer[cursor:cursor + 2])[0]
        cursor += 2
        self.time = readUint48(buffer, cursor)
        cursor += 6

        st2_cursor = cursor

        pos, self.remark = read_by_length(buffer, cursor, check_size=True)
        cursor += pos

        cursor = await self._parse_data(buffer, cursor)

        self.coin_data = CoinData()
        cursor = await self.coin_data.parse(buffer, cursor)
        med_cursor = cursor

        if self.hash_varint:
            values = bytes((self.type,)) \
                    + bytes((255,)) + writeUint64(self.time)
        else:
            values = struct.pack("H", self.type) \
                    + writeUint48(self.time)

        values += buffer[st2_cursor:med_cursor]

        self.hash_bytes = hash_twice(values)
        self.hash = NulsDigestData(data=self.hash_bytes, alg_type=0)

        pos, self.scriptSig = read_by_length(buffer, cursor, check_size=True)
        cursor += pos
        end_cursor = cursor
        self.size = end_cursor - st_cursor

        return cursor