package com.msgilligan.ethereum.rpc;

import com.msgilligan.bitcoinj.rpc.JsonRPCStatusException;
import com.msgilligan.bitcoinj.rpc.RPCClient;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;

/**
 * A partial implementation of an Ethereum RPC Client
 */
public class EthereumClient extends RPCClient {
    public static URI DEFAULT_LOCALHOST;

    static {
        try {
            DEFAULT_LOCALHOST = new URI("http://localhost:8545");
        } catch (URISyntaxException e) {
            DEFAULT_LOCALHOST = null;
        }
    }

    /**
     * Construct a JSON-RPC client from URI, username, and password
     *
     * @param server      server URI should not contain username/password
     * @param rpcuser     username for the RPC HTTP connection
     * @param rpcpassword password for the RPC HTTP connection
     */
    private EthereumClient(URI server, String rpcuser, String rpcpassword) {
        super(server, rpcuser, rpcpassword);
    }

    public EthereumClient() {
        super(DEFAULT_LOCALHOST, null, null);
    }

    public String ethProtocolVersion() throws IOException, JsonRPCStatusException {
        return this.send("eth_protocolVersion");
    }

    public long ethBlockNumber() throws IOException, JsonRPCStatusException {
        String blockNumString = this.send("eth_blockNumber");
        long blockNum = Long.decode(blockNumString);
        return blockNum;
    }

    public boolean minerStart(int numberOfThreads) throws IOException, JsonRPCStatusException {
        return this.send("miner_start", "0x" + Integer.toHexString(numberOfThreads));
    }

    public boolean minerStop() throws IOException, JsonRPCStatusException {
        return this.send("miner_stop");
    }

}

@@ -304,16 +304,216 @@
  Client%0A
+ *%0A * How to mine just a little for %22reg test mode%22 in Eth:%0A * https://github.com/ethereum/go-ethereum/wiki/bitchin-tricks%0A * See also:%0A * https://github.com/ethereum/go-ethereum/wiki/Management-APIs%0A
  */%0Apubl

Add comments (links) in Ethereum RPC Client