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;
}
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;
}
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;
}
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);
}
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);
}
}
}
}
Aggregations