Search in sources :

Example 1 with CommandPowBty

use of org.xel.computation.CommandPowBty in project elastic-core-maven by OrdinaryDude.

the class SubmitSolution method processRequest.

@Override
protected JSONStreamAware processRequest(final HttpServletRequest req) throws NxtException {
    final long workId = ParameterParser.getUnsignedLong(req, "work_id", true);
    byte[] data = ParameterParser.getBytes(req, "data", false);
    final byte[] multiplicator = ParameterParser.getBytes(req, "multiplicator", true);
    int storageId = ParameterParser.getInt(req, "storage_id", 0, Integer.MAX_VALUE, true);
    if (data == null || data.length == 0)
        storageId = -1;
    final boolean is_pow = ParameterParser.getBooleanByString(req, "is_pow", true);
    if (is_pow)
        data = new byte[0];
    byte[] hash = ParameterParser.getBytes(req, "hash", false);
    Work w = Work.getWork(workId);
    if (w == null || w.isClosed()) {
        return JSONResponses.ERROR_WORK_INCORRECT;
    }
    CommandPowBty work = new CommandPowBty(workId, is_pow, multiplicator, hash, data, storageId, w.getCurrentRound());
    try {
        MessageEncoder.push(work, ParameterParser.getSecretPhrase(req, true));
        return JSONResponses.EVERYTHING_ALRIGHT;
    } catch (IOException e) {
        Logger.logInfoMessage("Work " + String.valueOf(w.getId()) + " submission failed. IO Exception");
        return JSONResponses.ERROR_INCORRECT_REQUEST;
    } catch (NxtException.ValidationException e) {
        Logger.logInfoMessage("Work " + String.valueOf(w.getId()) + " submission failed: " + e.getMessage());
        JSONObject response = new JSONObject();
        response.put("errorCode", 6009);
        response.put("errorDescription", e.getMessage());
        return response;
    }
}
Also used : JSONObject(org.json.simple.JSONObject) CommandPowBty(org.xel.computation.CommandPowBty) CommandCancelWork(org.xel.computation.CommandCancelWork) Work(org.xel.Work) NxtException(org.xel.NxtException) IOException(java.io.IOException)

Example 2 with CommandPowBty

use of org.xel.computation.CommandPowBty in project elastic-core-maven by OrdinaryDude.

the class WorkTest method newWorkTestWithEnoughPOWs.

@Test
public void newWorkTestWithEnoughPOWs() throws NxtException, IOException {
    redeemPubkeyhash();
    String code = readFile("src/test/testfiles/btc.epl", Charset.forName("UTF-8"));
    CommandNewWork work = new CommandNewWork(10, (short) 100, 1000001, 1000001, 10, 10, code.getBytes());
    MessageEncoder.push(work, AbstractForgingTest.testForgingSecretPhrase);
    // Mine a bit so the work gets confirmed
    AbstractBlockchainTest.forgeNumberOfBlocks(1, AbstractForgingTest.testForgingSecretPhrase);
    long id = 0;
    Work w;
    try (DbIterator<Work> wxx = Work.getActiveWork()) {
        w = wxx.next();
        id = w.getId();
    }
    // Test work db table
    Assert.assertEquals(1, Work.getCount());
    Assert.assertEquals(1, Work.getActiveCount());
    byte[] m = new byte[32];
    byte[] m2 = new byte[32];
    byte[] testarray = new byte[32 * 4];
    for (int i = 0; i < 25; ++i) {
        m[0] = (byte) (m[0] + 1);
        CommandPowBty pow = new CommandPowBty(id, true, m, new byte[16], testarray, 0, w.getCurrentRound());
        m2[0] = (byte) (m2[0] + 2);
        m2[1] = 1;
        CommandPowBty pow2 = new CommandPowBty(id, true, m2, new byte[16], testarray, 0, w.getCurrentRound());
        try {
            MessageEncoder.push(pow, AbstractForgingTest.testForgingSecretPhrase);
        } catch (Exception e) {
            Logger.logDebugMessage("Could not push POW: " + e.getMessage());
        }
        try {
            MessageEncoder.push(pow2, AbstractForgingTest.testForgingSecretPhrase);
        } catch (Exception e) {
            Logger.logDebugMessage("Could not push POW: " + e.getMessage());
        }
        // Mine a bit so the work times out
        AbstractBlockchainTest.forgeNumberOfBlocks(1, AbstractForgingTest.testForgingSecretPhrase);
    }
    AbstractBlockchainTest.forgeNumberOfBlocks(6, AbstractForgingTest.testForgingSecretPhrase);
    // After getting enough Pow work must be closed
    // Test work db table
    Assert.assertEquals(1, Work.getCount());
    Assert.assertEquals(0, Work.getActiveCount());
}
Also used : CommandNewWork(org.xel.computation.CommandNewWork) CommandPowBty(org.xel.computation.CommandPowBty) CommandNewWork(org.xel.computation.CommandNewWork) CommandCancelWork(org.xel.computation.CommandCancelWork) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)2 CommandCancelWork (org.xel.computation.CommandCancelWork)2 CommandPowBty (org.xel.computation.CommandPowBty)2 JSONObject (org.json.simple.JSONObject)1 Test (org.junit.Test)1 NxtException (org.xel.NxtException)1 Work (org.xel.Work)1 CommandNewWork (org.xel.computation.CommandNewWork)1