Ejemplo n.º 1
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'])
        return cursor, md
Ejemplo n.º 2
0
 async def from_buffer(cls, buffer, cursor=0):
     md = dict()
     md['deposit'] = struct.unpack("Q", buffer[cursor:cursor + 8])[0]
     cursor += 8
     md['agentAddress'] = buffer[cursor:cursor + ADDRESS_LENGTH]
     cursor += ADDRESS_LENGTH
     md['agentAddress'] = address_from_hash(md['agentAddress'])
     md['packingAddress'] = buffer[cursor:cursor + ADDRESS_LENGTH]
     cursor += ADDRESS_LENGTH
     md['packingAddress'] = address_from_hash(md['packingAddress'])
     md['rewardAddress'] = buffer[cursor:cursor + ADDRESS_LENGTH]
     cursor += ADDRESS_LENGTH
     md['rewardAddress'] = address_from_hash(md['rewardAddress'])
     md['commissionRate'] = struct.unpack("d", buffer[cursor:cursor + 8])[0]
     cursor += 8
     return cursor, md
Ejemplo n.º 3
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
Ejemplo n.º 4
0
 async def from_buffer(cls, buffer, cursor=0):
     md = dict()
     md['deposit'] = struct.unpack("Q", buffer[cursor:cursor + 8])[0]
     cursor += 8
     md['address'] = buffer[cursor:cursor + ADDRESS_LENGTH]
     cursor += ADDRESS_LENGTH
     md['address'] = address_from_hash(md['address'])
     md['agentHash'] = buffer[cursor:cursor + HASH_LENGTH].hex()
     cursor += HASH_LENGTH
     return cursor, md
Ejemplo n.º 5
0
    async def from_buffer(cls, buffer, cursor=0):
        md = dict()
        md['originTxHash'] = buffer[cursor:cursor + HASH_LENGTH].hex()
        cursor += HASH_LENGTH

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

        md['success'] = int(buffer[cursor])
        cursor += 1

        return cursor, md
Ejemplo 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
Ejemplo n.º 7
0
    def to_dict(self):
        val = {'value': self.na, 'lockTime': self.lockTime}
        if self.rawScript is not None:
            val['owner'] = self.rawScript.hex()

        if self.address is not None:
            val['address'] = address_from_hash(self.address)
            val['addressHash'] = self.address

        if self.fromHash is not None:
            val['fromHash'] = self.fromHash.hex()
            val['fromIndex'] = self.fromIndex

        return val
Ejemplo n.º 8
0
async def verify_signature(message):
    """ Verifies a signature of a message, return True if verified, false if not
    """
    loop = asyncio.get_event_loop()
    from aleph.web import app
    config = app.config

    sig_raw = bytes(bytearray.fromhex(message['signature']))
    sig = NulsSignature(sig_raw)
    hash = public_key_to_hash(sig.pub_key, config.nuls.chain_id.value)
    address = address_from_hash(hash)
    if address != message['sender']:
        LOGGER.warning('Received bad signature from %s for %s' %
                       (address, message['sender']))
        return False

    verification = await get_verification_buffer(message)
    try:
        result = await loop.run_in_executor(None, sig.verify, verification)
    except Exception:
        LOGGER.exception("NULS Signature verification error")
        result = False
    # result = sig.verify(verification)
    return result
Ejemplo n.º 9
0
async def get_address(pubkey, chain_id):
    phash = public_key_to_hash(pubkey, chain_id=chain_id)
    address = address_from_hash(phash)
    return address