def parse(self, buffer, cursor=0): pos, owner = read_by_length(buffer, cursor) cursor += pos if len(owner) == (HASH_LENGTH + 1): val = (len(owner) - HASH_LENGTH) if (val > 1): fc = VarInt() fc.parse(owner, HASH_LENGTH) self.fromIndex = fc.value assert fc.originallyEncodedSize == val else: self.fromIndex = owner[-1] self.fromHash = owner[:HASH_LENGTH] elif len(owner) == ADDRESS_LENGTH: self.address = owner else: # ok, we have some script here self.rawScript = owner # tentative fix for now... Ugly. self.address = owner[2:ADDRESS_LENGTH + 2] # it's either 2 or 3. # print(address_from_hash(owner[3:ADDRESS_LENGTH+3])) self.na = struct.unpack("Q", buffer[cursor:cursor + 8])[0] cursor += 8 self.lockTime = readUint48(buffer, cursor) cursor += 6 return cursor
async def parse_extend(self, extend): cursor = 0 self.roundIndex = struct.unpack("I", extend[cursor:cursor + 4])[0] cursor += 4 self.consensusMemberCount = struct.unpack("H", extend[cursor:cursor + 2])[0] cursor += 2 self.roundStartTime = readUint48(extend, cursor) cursor += 6 self.packingIndexOfRound = struct.unpack("H", extend[cursor:cursor + 2])[0] cursor += 2 if len(extend) > cursor: self.mainVersion = struct.unpack("i", extend[cursor:cursor + 4])[0] cursor += 4 self.currentVersion = struct.unpack("i", extend[cursor:cursor + 4])[0] cursor += 4 self.percent = struct.unpack("H", extend[cursor:cursor + 2])[0] cursor += 2 self.delay = struct.unpack("I", extend[cursor:cursor + 4])[0] cursor += 4 pos, self.stateRoot = read_by_length(extend, cursor, check_size=True) cursor += pos
async def parse(self, buffer, cursor=0): self.preHash = NulsDigestData(data=buffer) cursor += self.preHash.size self.merkleHash = NulsDigestData(data=buffer[cursor:]) cursor += self.merkleHash.size self.time = readUint48(buffer, cursor) cursor += 6 self.height, self.txCount = struct.unpack("II", buffer[cursor:cursor + 8]) cursor += 8 pos, self.extend = read_by_length(buffer, cursor, check_size=True) cursor += pos #await self.prepare_hash() await self.parse_extend(self.extend) self.scriptSig = P2PKHScriptSig(data=buffer[cursor:]) cursor += self.scriptSig.size self.raw_data = buffer[:cursor] return cursor
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