Beispiel #1
0
def map_fulfillment_data(data_hash, bounty_id, fulfillment_id):
    ipfs_hash = data_hash
    if len(ipfs_hash) != 46 or not ipfs_hash.startswith('Qm'):
        logger.error(
            'Data Hash Incorrect for fulfillment on bounty: {:d} fulfillment: {:d}'.format(
                bounty_id, fulfillment_id))
        data_JSON = "{}"
    else:
        data_JSON = ipfs.cat(ipfs_hash)
    if len(ipfs_hash) == 0:
        ipfs_hash = 'invalid'

    data = json.loads(data_JSON)
    metadata = data.pop('meta', {})
    if 'payload' in data:
        data = data.get('payload')
    data_fulfiller = data.get('fulfiller', {})
    plucked_data = pluck(data, fulfillment_data_keys)

    return {
        'data_json': str(data_JSON),
        'data': ipfs_hash,
        'data_fulfiller': data_fulfiller,
        'fulfiller_name': data_fulfiller.get('name', ''),
        'fulfiller_email': data_fulfiller.get('email', '') or data.get('contact', ''),
        'fulfiller_githubUsername': data_fulfiller.get('githubUsername', ''),
        'fulfiller_address': data_fulfiller.get('address', ''),
        **plucked_data,
        **metadata,
    }
Beispiel #2
0
def map_fulfillment_data(data_hash, bounty_id, fulfillment_id,
                         contract_version):
    ipfs_hash = data_hash
    if len(ipfs_hash) != 46 or not ipfs_hash.startswith('Qm'):
        logger.error(
            'Data Hash Incorrect for fulfillment on bounty: {:d} fulfillment: {:d}'
            .format(bounty_id, fulfillment_id))
        data_JSON = "{}"
    else:
        try:
            data_JSON = ipfs.cat(ipfs_hash)
        except StatusError as e:
            if e.original.response.status_code == 504:
                logger.warning(
                    'Timeout for bounty id {}, trying old IPFS Node'.format(
                        bounty_id))
                old_ipfs = ipfsapi.connect(
                    host='https://ipfs.bounties.network', port='443')
                data_JSON = old_ipfs.cat(ipfs_hash)
            else:
                raise e

    if len(ipfs_hash) == 0:
        ipfs_hash = 'invalid'

    data = json.loads(data_JSON)
    metadata = data.pop('meta', {})
    if 'payload' in data:
        data = data.get('payload')
    data_fulfiller = data.get('fulfiller', {})
    plucked_data = pluck(data, fulfillment_data_keys)

    return {
        'data_json':
        str(data_JSON),
        'data':
        ipfs_hash,
        'data_fulfiller':
        data_fulfiller,
        'fulfiller_name':
        data_fulfiller.get('name', ''),
        'fulfiller_email':
        data_fulfiller.get('email', '') or data.get('contact', ''),
        'fulfiller_githubUsername':
        data_fulfiller.get('githubUsername', ''),
        'fulfiller_address':
        data_fulfiller.get('address', ''),
        **plucked_data,
        **metadata,
    }