use of org.aion.zero.impl.types.AionBlock in project aion by aionnetwork.
the class ApiWeb3Aion method getRepoByJsonBlockId.
// --------------------------------------------------------------------
// Helper Functions
// --------------------------------------------------------------------
private IRepository getRepoByJsonBlockId(String _bnOrId) {
Long bn = parseBnOrId(_bnOrId);
// if you passed in an invalid bnOrId, pending or it's an error
if (bn == null || bn < 0)
return null;
AionBlock b = this.ac.getBlockchain().getBlockByNumber(bn);
if (b == null)
return null;
return ac.getRepository().getSnapshotTo(b.getStateRoot());
}
use of org.aion.zero.impl.types.AionBlock in project aion by aionnetwork.
the class ApiWeb3Aion method stratum_getmininginfo.
public Object stratum_getmininginfo() {
AionBlock bestBlock = getBestBlock();
JSONObject obj = new JSONObject();
obj.put("blocks", bestBlock.getNumber());
obj.put("currentblocksize", 0);
obj.put("currentblocktx", bestBlock.getTransactionsList().size());
obj.put("difficulty", 3368767.14053294);
obj.put("errors", "");
obj.put("genproclimit", -1);
obj.put("hashespersec", 0);
obj.put("pooledtx", 0);
obj.put("testnet", false);
return obj;
}
use of org.aion.zero.impl.types.AionBlock in project aion by aionnetwork.
the class ApiWeb3Aion method stratum_getHeaderByBlockNumber.
public Object stratum_getHeaderByBlockNumber(Object _blockNum) {
JSONObject obj = new JSONObject();
if (_blockNum != null && !_blockNum.equals(null)) {
String bnStr = _blockNum + "";
try {
int bnInt = Integer.decode(bnStr);
AionBlock block = getBlockRaw(bnInt);
if (block != null) {
A0BlockHeader header = block.getHeader();
// 0 = success
obj.put("code", 0);
obj.put("nonce", toHexString(header.getNonce()));
obj.put("solution", toHexString(header.getSolution()));
obj.put("headerHash", toHexString(HashUtil.h256(header.getHeaderBytes(false))));
obj.putOpt("blockHeader", header.toJSON());
} else {
obj.put("message", "Fail - Unable to find block" + bnStr);
obj.put("code", -2);
}
} catch (Exception e) {
obj.put("message", bnStr + " must be an integer value");
obj.put("code", -3);
}
} else {
obj.put("message", "Missing block number");
obj.put("code", -1);
}
return obj;
}
use of org.aion.zero.impl.types.AionBlock in project aion by aionnetwork.
the class ApiWeb3Aion method getTransactionsByBlockId.
private List<AionTransaction> getTransactionsByBlockId(String id) {
Long bn = parseBnOrId(id);
if (bn == null || bn < 0)
return null;
AionBlock b = this.ac.getBlockchain().getBlockByNumber(bn);
if (b == null)
return null;
return b.getTransactionsList();
}
use of org.aion.zero.impl.types.AionBlock in project aion by aionnetwork.
the class ApiWeb3Aion method stratum_getblocktemplate.
public Object stratum_getblocktemplate() {
// TODO: Change this to a synchronized map implementation mapping
// block hashes to the block. Allow multiple block templates at same height.
templateMapLock.writeLock().lock();
AionBlock bestBlock = getBlockTemplate();
// have switch branches, abandon current work to start on new branch
if (!templateMap.keySet().isEmpty()) {
if (templateMap.get(templateMap.keySet().iterator().next()).getNumber() < bestBlock.getNumber()) {
// Found a higher block, clear any remaining cached entries and start on new height
templateMap.clear();
}
}
templateMap.put(toHexString(bestBlock.getHeader().getStaticHash()), bestBlock);
JSONObject coinbaseaux = new JSONObject();
coinbaseaux.put("flags", "062f503253482f");
JSONObject obj = new JSONObject();
obj.put("previousblockhash", toHexString(bestBlock.getParentHash()));
obj.put("height", bestBlock.getNumber());
obj.put("target", toHexString(BigInteger.valueOf(2).pow(256).divide(new BigInteger(bestBlock.getHeader().getDifficulty())).toByteArray()));
obj.put("transactions", new JSONArray());
obj.putOpt("blockHeader", bestBlock.getHeader().toJSON());
obj.put("coinbaseaux", coinbaseaux);
obj.put("headerHash", toHexString(bestBlock.getHeader().getStaticHash()));
templateMapLock.writeLock().unlock();
return obj;
}
Aggregations