async def fetch_all_asset_resources(conn):
    return await r.table('assets')\
        .filter((fetch_latest_block_num() >= r.row['start_block_num'])
                & (fetch_latest_block_num() < r.row['end_block_num']))\
        .map(lambda asset: (asset['description'] == "").branch(
            asset.without('description'), asset))\
        .map(lambda asset: (asset['rules'] == []).branch(
            asset, asset.merge(parse_rules(asset['rules']))))\
        .without('start_block_num', 'end_block_num', 'delta_id')\
        .coerce_to('array').run(conn)
Ejemplo n.º 2
0
async def fetch_all_asset_resources(conn):
    return await r.table('assets')\
        .filter((fetch_latest_block_num() >= r.row['start_block_num'])
                & (fetch_latest_block_num() < r.row['end_block_num']))\
        .map(lambda asset: (asset['description'] == "").branch(
            asset.without('description'), asset))\
        .map(lambda asset: (asset['rules'] == []).branch(
            asset, asset.merge(parse_rules(asset['rules']))))\
        .without('start_block_num', 'end_block_num', 'delta_id')\
        .coerce_to('array').run(conn)
async def fetch_asset_resource(conn, name):
    try:
        return await r.table('assets')\
            .get_all(name, index='name')\
            .max('start_block_num')\
            .do(lambda asset: (asset['description'] == "").branch(
                asset.without('description'), asset))\
            .do(lambda asset: (asset['rules'] == []).branch(
                asset, asset.merge(parse_rules(asset['rules']))))\
            .without('start_block_num', 'end_block_num', 'delta_id')\
            .run(conn)
    except ReqlNonExistenceError:
        raise ApiBadRequest("Bad Request: "
                            "No asset with the name {} exists".format(name))
Ejemplo n.º 4
0
async def fetch_asset_resource(conn, name):
    try:
        return await r.table('assets')\
            .get_all(name, index='name')\
            .max('start_block_num')\
            .do(lambda asset: (asset['description'] == "").branch(
                asset.without('description'), asset))\
            .do(lambda asset: (asset['rules'] == []).branch(
                asset, asset.merge(parse_rules(asset['rules']))))\
            .without('start_block_num', 'end_block_num', 'delta_id')\
            .run(conn)
    except ReqlNonExistenceError:
        raise ApiBadRequest(
            "Bad Request: "
            "No asset with the name {} exists".format(name))
Ejemplo n.º 5
0
async def fetch_all_offer_resources(conn, query_params):
    return await r.table('offers')\
        .filter((fetch_latest_block_num() >= r.row['start_block_num'])
                & (fetch_latest_block_num() < r.row['end_block_num']))\
        .filter(query_params)\
        .map(lambda offer: (offer['label'] == "").branch(
            offer.without('label'), offer))\
        .map(lambda offer: (offer['description'] == "").branch(
            offer.without('description'), offer))\
        .map(lambda offer: offer.merge(
            {'sourceQuantity': offer['source_quantity']}))\
        .map(lambda offer: (offer['target'] == "").branch(
            offer.without('target'), offer))\
        .map(lambda offer: (offer['target_quantity'] == "").branch(
            offer,
            offer.merge({'targetQuantity': offer['target_quantity']})))\
        .map(lambda offer: (offer['rules'] == []).branch(
            offer, offer.merge(parse_rules(offer['rules']))))\
        .without('delta_id', 'start_block_num', 'end_block_num',
                 'source_quantity', 'target_quantity')\
        .coerce_to('array').run(conn)
Ejemplo n.º 6
0
async def fetch_offer_resource(conn, offer_id):
    try:
        return await r.table('offers')\
            .get_all(offer_id, index='id')\
            .max('start_block_num')\
            .do(lambda offer: (offer['label'] == "").branch(
                offer.without('label'), offer))\
            .do(lambda offer: (offer['description'] == "").branch(
                offer.without('description'), offer))\
            .merge({'sourceQuantity': r.row['source_quantity']})\
            .do(lambda offer: (offer['target'] == "").branch(
                offer.without('target'), offer))\
            .do(lambda offer: (offer['target_quantity'] == "").branch(
                offer,
                offer.merge({'targetQuantity': offer['target_quantity']})))\
            .do(lambda offer: (offer['rules'] == []).branch(
                offer, offer.merge(parse_rules(offer['rules']))))\
            .without('delta_id', 'start_block_num', 'end_block_num',
                     'source_quantity', 'target_quantity')\
            .run(conn)
    except ReqlNonExistenceError:
        raise ApiBadRequest("No offer with the id {} exists".format(offer_id))