scanCount = (int) ((9 * scanCount) + (scanCount / time * targetRoundTime)) / 10;
config.setScanCount(scanCount);
}
private Work fetchWork(Config config) throws IOException, JSONException {
JSONObject getwork = new JSONObject();
getwork.put("method", "getwork");
getwork.put("params", new JSONArray());
getwork.put("id", 0);
URL url = new URL(config.getJsonRpcServer());
URLFetchService ufs = URLFetchServiceFactory.getURLFetchService();
HTTPRequest req = new HTTPRequest(url, HTTPMethod.POST);
req.setPayload(getwork.toString().getBytes());
req.addHeader(new HTTPHeader("Authorization", config.getAuth()));
HTTPResponse resp = ufs.fetch(req);
String content = new String(resp.getContent());
if (resp.getResponseCode() != 200) {
throw new IOException( //
"fetchWork Error: " + resp.getResponseCode() + " "
+ content);
}
JSONObject respwork = new JSONObject(content);
Object errorP = respwork.get("error");
if (errorP != JSONObject.NULL) {
JSONObject error = (JSONObject) errorP;
throw new IOException( //
"fetchWork Error: " + error.getString("message") //
+ " (" + error.getInt("code") + ")");
}
JSONObject result = respwork.getJSONObject("result");
Work work = new Work( //
result.getString("data"), //
result.getString("hash1"), //
result.getString("target"), //
result.getString("midstate"));
return work;
}