Esempio n. 1
0
 def parse(self, buffer, cursor=0):
     pos, self.public_key = read_by_length(buffer, cursor=cursor)
     cursor += pos
     self.sign_alg_type = buffer[cursor]
     cursor += 1
     pos, self.sign_bytes = read_by_length(buffer, cursor=cursor)
     cursor += pos
Esempio n. 2
0
    async def from_buffer(cls, buffer, cursor=0):
        md = dict()
        pos, md['address'] = read_by_length(buffer, cursor)
        cursor += pos

        pos, md['alias'] = read_by_length(buffer, cursor)
        cursor += pos
        md['alias'] = md['alias'].decode('utf-8')
        return cursor, md
Esempio n. 3
0
    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
Esempio n. 4
0
 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
Esempio n. 5
0
    async def from_buffer(cls, buffer, cursor=0):
        md = dict()
        md['result'] = None  # This should be populated elsewhere

        md['sender'] = buffer[cursor:cursor + ADDRESS_LENGTH]
        cursor += ADDRESS_LENGTH
        md['sender'] = address_from_hash(md['sender'])

        md['contractAddress'] = buffer[cursor:cursor + ADDRESS_LENGTH]
        cursor += ADDRESS_LENGTH
        md['contractAddress'] = address_from_hash(md['contractAddress'])

        md['value'] = struct.unpack("q", buffer[cursor:cursor + 8])[0]
        cursor += 8
        md['gasLimit'] = struct.unpack("q", buffer[cursor:cursor + 8])[0]
        cursor += 8
        md['price'] = struct.unpack("q", buffer[cursor:cursor + 8])[0]
        cursor += 8

        pos, md['methodName'] = read_by_length(buffer, cursor=cursor)
        md['methodName'] = md['methodName'].decode('utf-8')
        cursor += pos
        pos, md['methodDesc'] = read_by_length(buffer, cursor=cursor)
        md['methodDesc'] = md['methodDesc'].decode('utf-8')
        cursor += pos
        argslen = int(buffer[cursor])
        cursor += 1
        args = []
        for i in range(argslen):
            arglen = int(buffer[cursor])
            cursor += 1
            arg = []
            for j in range(arglen):
                pos, argcontent = read_by_length(buffer, cursor=cursor)
                cursor += pos
                try:
                    argcontent = argcontent.decode('utf-8')
                except UnicodeDecodeError:
                    LOGGER.warning(
                        "Unicode decode error here, passing raw value.")
                arg.append(argcontent)

            args.append(arg)

        md['args'] = args
        return cursor, md
Esempio n. 6
0
 async def from_buffer(cls, buffer, cursor=0):
     md = dict()
     #pos, md['address'] = read_by_length(buffer, cursor)
     #cursor += pos
     md['address'] = buffer[cursor:cursor + ADDRESS_LENGTH]
     cursor += ADDRESS_LENGTH
     md['address'] = address_from_hash(md['address'])
     md['reason'] = buffer[cursor]
     cursor += 1
     pos, md['evidence'] = read_by_length(buffer, cursor)
     cursor += pos
     md['evidence'] = md['evidence'].hex()
     return cursor, md
Esempio n. 7
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
Esempio n. 8
0
    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
Esempio n. 9
0
 async def from_buffer(cls, buffer, cursor=0):
     md = dict()
     pos, md['logicData'] = read_by_length(buffer, cursor)
     cursor += pos
     md['logicData'] = md['logicData'].hex()
     return cursor, md