Search in sources :

Example 6 with IEvent

use of org.aion.evtmgr.IEvent in project aion by aionnetwork.

the class EventMgrA0 method registerEvent.

/*
     * (non-Javadoc)
     * 
     * @see org.aion.evt.api.IEventMgr#registerEvent(java.util.List)
     */
@Override
public boolean registerEvent(List<IEvent> _evt) {
    synchronized (this) {
        for (IEvent e : _evt) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("EVTMGR.registerEvent EventType [{}] CallbackType [{}]", e.getEventType(), e.getCallbackType());
            }
            IHandler hdr = this.getHandler(e.getEventType());
            if (hdr == null) {
                if (LOG.isErrorEnabled()) {
                    LOG.error("EVTMGR.registerEvent can't find the handler base on the EventType [{}]", e.getEventType());
                }
                return false;
            }
            hdr.addEvent(e);
        }
    }
    return true;
}
Also used : IEvent(org.aion.evtmgr.IEvent) IHandler(org.aion.evtmgr.IHandler)

Example 7 with IEvent

use of org.aion.evtmgr.IEvent in project aion by aionnetwork.

the class EventMgrA0 method unregisterEvent.

/*
     * (non-Javadoc)
     * 
     * @see org.aion.evt.api.IEventMgr#unregisterEvent(java.util.List)
     */
@Override
public boolean unregisterEvent(List<IEvent> _evt) {
    synchronized (this) {
        for (IEvent e : _evt) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("EVTMGR.unregisterEvent EventType [{}]", e.getEventType());
            }
            IHandler hdr = this.getHandler(e.getEventType());
            if (hdr == null) {
                if (LOG.isErrorEnabled()) {
                    LOG.error("EVTMGR.unregisterEvent can't find the handler base on the EventType [{}]", e.getEventType());
                }
                return false;
            }
            hdr.removeEvent(e);
        }
    }
    return true;
}
Also used : IEvent(org.aion.evtmgr.IEvent) IHandler(org.aion.evtmgr.IHandler)

Example 8 with IEvent

use of org.aion.evtmgr.IEvent 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)

Example 9 with IEvent

use of org.aion.evtmgr.IEvent in project aion by aionnetwork.

the class EquihashMiner method registerMinerEvents.

/**
 * Register miner events.
 */
public void registerMinerEvents() {
    List<IEvent> evts = new ArrayList<>();
    evts.add(new EventMiner(EventMiner.CALLBACK.MININGSTARTED));
    evts.add(new EventMiner(EventMiner.CALLBACK.MININGSTOPPED));
    this.evtMgr.registerEvent(evts);
}
Also used : IEvent(org.aion.evtmgr.IEvent) EventMiner(org.aion.evtmgr.impl.evt.EventMiner)

Example 10 with IEvent

use of org.aion.evtmgr.IEvent in project aion by aionnetwork.

the class EquihashMiner method mine.

/**
 * Keeps mining until the thread is interrupted
 */
protected void mine() {
    IAionBlock block;
    byte[] nonce;
    while (!Thread.currentThread().isInterrupted()) {
        if ((block = miningBlock) == null) {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                break;
            }
        } else {
            // A new array must be created each loop
            // If reference is reused the array contents may be changed
            // before block sealed causing validation to fail
            nonce = new byte[32];
            ThreadLocalRandom.current().nextBytes(nonce);
            Solution s = miner.mine(block, nonce);
            if (s != null) {
                IEvent ev = new EventConsensus(EventConsensus.CALLBACK.ON_SOLUTION);
                ev.setFuncArgs(Collections.singletonList(s));
                evtMgr.newEvent(ev);
            }
        }
    }
}
Also used : IEvent(org.aion.evtmgr.IEvent) IAionBlock(org.aion.zero.types.IAionBlock) EventConsensus(org.aion.evtmgr.impl.evt.EventConsensus)

Aggregations

IEvent (org.aion.evtmgr.IEvent)13 EventConsensus (org.aion.evtmgr.impl.evt.EventConsensus)4 EventTx (org.aion.evtmgr.impl.evt.EventTx)4 BigInteger (java.math.BigInteger)3 EventBlock (org.aion.evtmgr.impl.evt.EventBlock)3 IHandler (org.aion.evtmgr.IHandler)2 AionBlock (org.aion.zero.impl.types.AionBlock)2 IRepositoryCache (org.aion.base.db.IRepositoryCache)1 Address (org.aion.base.type.Address)1 Solution (org.aion.equihash.Solution)1 EventMiner (org.aion.evtmgr.impl.evt.EventMiner)1 ImportResult (org.aion.mcf.core.ImportResult)1 DataWord (org.aion.mcf.vm.types.DataWord)1 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)1 IAionBlock (org.aion.zero.types.IAionBlock)1 LRUMap (org.apache.commons.collections4.map.LRUMap)1 JSONObject (org.json.JSONObject)1