Ejemplo n.º 1
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
Ejemplo n.º 2
0
    async def serialize(self):
        output = b""
        output += VarInt(len(self.inputs)).encode()
        for coin in self.inputs:
            output += coin.serialize()
        output += VarInt(len(self.outputs)).encode()
        for coin in self.outputs:
            output += coin.serialize()

        return output
Ejemplo n.º 3
0
    async def parse(self, buffer, cursor=0):
        if buffer[cursor:cursor + 4] == PLACE_HOLDER:
            return cursor + 4

        fc = VarInt()
        fc.parse(buffer, cursor)
        self.from_count = fc.value
        cursor += fc.originallyEncodedSize
        self.inputs = list()
        for i in range(self.from_count):
            coin = Coin()
            cursor = coin.parse(buffer, cursor)
            self.inputs.append(coin)

        tc = VarInt()
        tc.parse(buffer, cursor)
        self.to_count = tc.value
        cursor += tc.originallyEncodedSize
        #self.to_count = buffer[cursor]
        self.outputs = list()
        for i in range(self.to_count):
            coin = Coin()
            cursor = coin.parse(buffer, cursor)
            self.outputs.append(coin)

        return cursor
Ejemplo n.º 4
0
 async def to_buffer(cls, md):
     output = VarInt(md['count']).encode()
     for address in md['addresses']:
         output += hash_from_address(address)
     return output
Ejemplo n.º 5
0
 async def to_buffer(cls, md):
     #output = write_with_length(hash_from_address(md['address']))
     output = hash_from_address(md['address'])
     output += VarInt(md['reason']).encode()
     output += write_with_length(unhexlify(md['evidence']))
     return output