Search in sources :

Example 1 with EventConsensus

use of org.aion.evtmgr.impl.evt.EventConsensus in project aion by aionnetwork.

the class SyncMgr method setupEventHandler.

private void setupEventHandler() {
    List<IEvent> events = new ArrayList<>();
    events.add(new EventConsensus(EventConsensus.CALLBACK.ON_SYNC_DONE));
    this.evtMgr.registerEvent(events);
}
Also used : IEvent(org.aion.evtmgr.IEvent) ArrayList(java.util.ArrayList) EventConsensus(org.aion.evtmgr.impl.evt.EventConsensus)

Example 2 with EventConsensus

use of org.aion.evtmgr.impl.evt.EventConsensus in project aion by aionnetwork.

the class AbstractHandlerTest method testRemoveEvent.

@Test
public void testRemoveEvent() {
    AbstractHandler handler = new BlockHandler();
    handler.addEvent(new EventConsensus(EventConsensus.CALLBACK.ON_BLOCK_TEMPLATE));
    boolean res = handler.removeEvent(new EventBlock(EventBlock.CALLBACK.ONTRACE0));
    assertFalse(res);
    boolean res2 = handler.removeEvent(null);
    assertFalse(res2);
    boolean res3 = handler.removeEvent(new EventConsensus(EventConsensus.CALLBACK.ON_BLOCK_TEMPLATE));
    assertTrue(res3);
}
Also used : EventBlock(org.aion.evtmgr.impl.evt.EventBlock) BlockHandler(org.aion.evtmgr.impl.handler.BlockHandler) EventConsensus(org.aion.evtmgr.impl.evt.EventConsensus) Test(org.junit.Test)

Example 3 with EventConsensus

use of org.aion.evtmgr.impl.evt.EventConsensus in project aion by aionnetwork.

the class EventExecuteServiceTest method testEES.

@Test
public void testEES() {
    eventExecuteService.setFilter(getFilter());
    eventExecuteService.add(new EventDummy());
    eventExecuteService.add(new EventTx(EventTx.CALLBACK.PENDINGTXSTATECHANGE0));
    eventExecuteService.add(new EventBlock(EventBlock.CALLBACK.ONBLOCK0));
    eventExecuteService.add(new EventMiner(EventMiner.CALLBACK.MININGSTARTED));
    eventExecuteService.add(new EventConsensus(EventConsensus.CALLBACK.ON_SYNC_DONE));
    eventExecuteService.take();
    eventExecuteService.take();
    eventExecuteService.take();
    eventExecuteService.take();
    eventExecuteService.take();
}
Also used : EventTx(org.aion.evtmgr.impl.evt.EventTx) EventBlock(org.aion.evtmgr.impl.evt.EventBlock) EventConsensus(org.aion.evtmgr.impl.evt.EventConsensus) EventDummy(org.aion.evtmgr.impl.evt.EventDummy) EventMiner(org.aion.evtmgr.impl.evt.EventMiner) Test(org.junit.Test)

Example 4 with EventConsensus

use of org.aion.evtmgr.impl.evt.EventConsensus in project aion by aionnetwork.

the class AbstractEventTest method testHashCode.

@Test
public void testHashCode() {
    EventBlock eventBlock1 = new EventBlock(EventBlock.CALLBACK.ONBLOCK0);
    EventBlock eventBlock2 = new EventBlock(EventBlock.CALLBACK.ONBEST0);
    EventConsensus eventConsensus1 = new EventConsensus(EventConsensus.CALLBACK.ON_SYNC_DONE);
    EventConsensus eventConsensus2 = new EventConsensus(EventConsensus.CALLBACK.ON_BLOCK_TEMPLATE);
    // check the hash codes
    System.out.println(eventBlock1.hashCode());
    System.out.println(eventBlock2.hashCode());
    System.out.println(eventConsensus1.hashCode());
    System.out.println(eventConsensus2.hashCode());
}
Also used : EventBlock(org.aion.evtmgr.impl.evt.EventBlock) EventConsensus(org.aion.evtmgr.impl.evt.EventConsensus) Test(org.junit.Test)

Example 5 with EventConsensus

use of org.aion.evtmgr.impl.evt.EventConsensus 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

EventConsensus (org.aion.evtmgr.impl.evt.EventConsensus)9 IEvent (org.aion.evtmgr.IEvent)4 EventBlock (org.aion.evtmgr.impl.evt.EventBlock)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 EventDummy (org.aion.evtmgr.impl.evt.EventDummy)2 BlockHandler (org.aion.evtmgr.impl.handler.BlockHandler)2 MiningBlock (org.aion.zero.impl.types.MiningBlock)2 AionTransaction (org.aion.base.AionTransaction)1 Solution (org.aion.equihash.Solution)1 EventMiner (org.aion.evtmgr.impl.evt.EventMiner)1 EventTx (org.aion.evtmgr.impl.evt.EventTx)1 AionBlock (org.aion.zero.impl.types.AionBlock)1 Block (org.aion.zero.impl.types.Block)1 JSONObject (org.json.JSONObject)1