/*
 * Created by Michael Carrara <michael.carrara@breadwallet.com> on 7/1/19.
 * Copyright (c) 2019 Breadwinner AG.  All right reserved.
*
 * See the LICENSE file at the project root for license information.
 * See the CONTRIBUTORS file at the project root for a list of contributors.
 */
package com.breadwallet.crypto.blockchaindb.apis.brd;

import com.breadwallet.crypto.blockchaindb.errors.QueryError;
import com.breadwallet.crypto.utility.CompletionHandler;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import org.json.JSONObject;

public class EthBlockApi {

    private final BrdApiClient client;

    public EthBlockApi(BrdApiClient client) {
        this.client = client;
    }

    public void getBlockNumberAsEth(String networkName, int rid, CompletionHandler<String, QueryError> handler) {
        JSONObject json = new JSONObject(ImmutableMap.of(
                "jsonrpc", "2.0",
                "method", "eth_blockNumber",
                "params", ImmutableList.of(),
                "id", rid
        ));

        client.sendJsonRequest(networkName, json, handler);
    }
}

@@ -399,16 +399,84 @@
 yError;%0A
+import com.breadwallet.crypto.blockchaindb.errors.QueryNoDataError;%0A
 import c
@@ -524,16 +524,16 @@
 andler;%0A
-
 import c
@@ -1186,23 +1186,730 @@
 , json, 
-handler
+new CompletionHandler%3CString, QueryError%3E() %7B%0A            @Override%0A            public void handleData(String data) %7B%0A                // If we get a successful response, but the provided blocknumber is %220%22 then%0A                // that indicates that the JSON-RPC node is syncing.  Thus, if %220%22 transform%0A                // to a .failure%0A                if (!%220%22.equals(data) && !%220x%22.equals(data)) %7B%0A                    handler.handleData(data);%0A                %7D else %7B%0A                    handler.handleError(new QueryNoDataError());%0A                %7D%0A            %7D%0A%0A            @Override%0A            public void handleError(QueryError error) %7B%0A                handler.handleError(error);%0A            %7D%0A        %7D
 );%0A    %7D

Update Java handling of eth_blockNumber RPC result