Search in sources :

Example 1 with ArgFltr

use of org.aion.api.server.types.ArgFltr in project aion by aionnetwork.

the class ApiWeb3Aion method eth_newFilter.

public RpcMsg eth_newFilter(Object _params) {
    if (!isFilterEnabled) {
        return new RpcMsg(null, RpcError.NOT_ALLOWED, "Filters over rpc disabled.");
    }
    JSONObject _filterObj;
    if (_params instanceof JSONArray) {
        _filterObj = ((JSONArray) _params).getJSONObject(0);
    } else if (_params instanceof JSONObject) {
        _filterObj = ((JSONObject) _params).getJSONObject("filter");
    } else {
        return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid parameters");
    }
    ArgFltr rf = ArgFltr.fromJSON(_filterObj);
    if (rf == null) {
        return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid filter object provided.");
    }
    FltrLg filter = createFilter(rf);
    if (filter.getFilterError() != null) {
        return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid filter object provided. " + filter.getFilterError());
    }
    // "install" the filter after populating historical data;
    // rationale: until the user gets the id back, the user should not expect the filter to be
    // "installed" anyway.
    long id = fltrIndex.getAndIncrement();
    installedFilters.put(id, filter);
    return new RpcMsg(StringUtils.toJsonHex(id));
}
Also used : ArgFltr(org.aion.api.server.types.ArgFltr) JSONObject(org.json.JSONObject) FltrLg(org.aion.api.server.types.FltrLg) JSONArray(org.json.JSONArray)

Example 2 with ArgFltr

use of org.aion.api.server.types.ArgFltr in project aion by aionnetwork.

the class ApiWeb3Aion method eth_getLogs.

public RpcMsg eth_getLogs(Object _params) {
    JSONObject _filterObj;
    if (_params instanceof JSONArray) {
        _filterObj = ((JSONArray) _params).getJSONObject(0);
    } else if (_params instanceof JSONObject) {
        _filterObj = ((JSONObject) _params).getJSONObject("filter");
    } else {
        return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid parameters");
    }
    ArgFltr rf = ArgFltr.fromJSON(_filterObj);
    if (rf == null) {
        return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid filter object provided.");
    }
    FltrLg filter = createFilter(rf);
    if (filter.getFilterError() != null) {
        return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid filter object provided. " + filter.getFilterError());
    }
    return new RpcMsg(buildFilterResponse(filter));
}
Also used : ArgFltr(org.aion.api.server.types.ArgFltr) JSONObject(org.json.JSONObject) FltrLg(org.aion.api.server.types.FltrLg) JSONArray(org.json.JSONArray)

Aggregations

ArgFltr (org.aion.api.server.types.ArgFltr)2 FltrLg (org.aion.api.server.types.FltrLg)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2