use of org.aion.api.server.types.Tx in project aion by aionnetwork.
the class ApiWeb3Aion method ops_getTransactionReceiptListByBlockHash.
public RpcMsg ops_getTransactionReceiptListByBlockHash(Object _params) {
String _blockHash;
if (_params instanceof JSONArray) {
_blockHash = ((JSONArray) _params).get(0) + "";
} else if (_params instanceof JSONObject) {
_blockHash = ((JSONObject) _params).get("blockHash") + "";
} else {
return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid parameters");
}
byte[] blockHash = StringUtils.StringHexToByteArray(_blockHash);
if (blockHash.length != 32) {
return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid parameters");
}
// ok to getUnchecked() since the load() implementation does not throw checked exceptions
Block b;
try {
b = blockCache.get(ByteArrayWrapper.wrap(blockHash));
} catch (Exception e) {
// Catch errors if send an incorrect tx hash
return new RpcMsg(null, RpcError.INVALID_REQUEST, "Invalid Request " + e + " " + e.getMessage() != null ? e.getMessage() : "");
}
// cast will cause issues after the PoW refactor goes in
AionBlockchainImpl chain = (AionBlockchainImpl) this.ac.getAionHub().getBlockchain();
Function<AionTransaction, JSONObject> extractTxReceipt = t -> {
AionTxInfo info = chain.getTransactionInfoLite(t.getTransactionHash(), b.getHash());
info.setTransaction(t);
return ((new TxRecpt(b, info, 0L, true)).toJson());
};
List<JSONObject> receipts;
// use the fork-join pool to parallelize receipt retrieval if necessary
int PARALLELIZE_RECEIPT_COUNT = 20;
if (b.getTransactionsList().size() > PARALLELIZE_RECEIPT_COUNT) {
receipts = b.getTransactionsList().parallelStream().map(extractTxReceipt).collect(toList());
} else {
receipts = b.getTransactionsList().stream().map(extractTxReceipt).collect(toList());
}
return new RpcMsg(new JSONArray(receipts));
}
Aggregations