Search in sources :

Example 1 with Solution

use of org.aion.equihash.Solution in project aion by aionnetwork.

the class ApiWeb3Aion method stratum_submitblock.

public Object stratum_submitblock(Object nce, Object soln, Object hdrHash, Object ts) {
    JSONObject obj = new JSONObject();
    if (nce != null && soln != null && hdrHash != null && ts != null && !nce.equals(null) && !soln.equals(null) && !hdrHash.equals(null) && !ts.equals(null)) {
        templateMapLock.writeLock().lock();
        AionBlock bestBlock = templateMap.get(hdrHash + "");
        if (bestBlock != null) {
            IEvent ev = new EventConsensus(EventConsensus.CALLBACK.ON_SOLUTION);
            ev.setFuncArgs(Collections.singletonList(new Solution(bestBlock, hexStringToBytes(nce + ""), hexStringToBytes(soln + ""), Long.parseLong(ts + "", 16))));
            evtMgr.newEvent(ev);
            LOG.info("block submitted via api <num={}, hash={}, diff={}, tx={}>", bestBlock.getNumber(), // LogUtil.toHexF8(newBlock.getHash()),
            bestBlock.getShortHash(), bestBlock.getHeader().getDifficultyBI().toString(), bestBlock.getTransactionsList().size());
            templateMap.clear();
        }
        templateMapLock.writeLock().unlock();
        // TODO: Simplified response for now, need to provide better feedback to caller in next update
        obj.put("result", true);
    } else {
        obj.put("message", "success");
        obj.put("code", -1);
    }
    return obj;
}
Also used : JSONObject(org.json.JSONObject) IEvent(org.aion.evtmgr.IEvent) EventConsensus(org.aion.evtmgr.impl.evt.EventConsensus) Solution(org.aion.equihash.Solution) AionBlock(org.aion.zero.impl.types.AionBlock)

Aggregations

Solution (org.aion.equihash.Solution)1 IEvent (org.aion.evtmgr.IEvent)1 EventConsensus (org.aion.evtmgr.impl.evt.EventConsensus)1 AionBlock (org.aion.zero.impl.types.AionBlock)1 JSONObject (org.json.JSONObject)1