use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class ApiAion method getTransactionByBlockNumberAndIndex.
public AionTransaction getTransactionByBlockNumberAndIndex(long blkNr, long index) {
AionBlock pBlk = this.getBlock(blkNr);
if (pBlk == null) {
if (LOG.isErrorEnabled()) {
LOG.error("ApiAion.getTransactionByBlockNumberAndIndex - can't find the block by the block number");
}
return null;
}
List<AionTransaction> txList = pBlk.getTransactionsList();
AionTransaction tx = txList.get((int) index);
if (tx == null) {
if (LOG.isErrorEnabled()) {
LOG.error("Can't find the transaction by the txIndex");
}
return null;
}
TxRecpt receipt = this.getTransactionReceipt(tx.getHash());
// The receipt shouldn't be null!
if (receipt == null) {
throw new NullPointerException();
}
tx.rlpParse();
tx.setBlockNumber(pBlk.getNumber());
tx.setBlockHash(pBlk.getHash());
tx.setTxIndexInBlock(index);
tx.setNrgConsume(receipt.nrgUsed);
return tx;
}
use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class ApiAion method estimateGas.
public long estimateGas(ArgTxCall params) {
AionTransaction tx = new AionTransaction(params.getNonce().toByteArray(), params.getTo(), params.getValue().toByteArray(), params.getData(), params.getNrg(), params.getNrgPrice());
AionTxReceipt receipt = this.ac.callConstant(tx, this.ac.getAionHub().getBlockchain().getBestBlock());
return receipt.getEnergyUsed();
}
use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class AionBlockLoader method loadBlocks.
public void loadBlocks() {
exec1 = new ExecutorPipeline<AionBlock, AionBlock>(8, 1000, true, new Functional.Function<AionBlock, AionBlock>() {
@Override
public AionBlock apply(AionBlock b) {
for (AionTransaction tx : b.getTransactionsList()) {
tx.getFrom();
}
return b;
}
}, new Functional.Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) {
logger.error("Unhandled exception: ", throwable);
}
});
exec2 = exec1.add(1, 1000, new Functional.Consumer<AionBlock>() {
@Override
public void accept(AionBlock block) {
try {
blockWork(block);
} catch (Exception e) {
e.printStackTrace();
}
}
});
try {
exec1.join();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
blockchain.flush();
}
use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class PendingTxCache method findSeqTx.
private List<AionTransaction> findSeqTx(BigInteger bn, Address addr) {
List<AionTransaction> rtn = new ArrayList<>();
rtn.add(cacheTxMap.get(addr).get(bn));
boolean foundNext = true;
while (foundNext) {
bn = bn.add(BigInteger.ONE);
AionTransaction nextTx = cacheTxMap.get(addr).get(bn);
if (nextTx == null) {
foundNext = false;
} else {
rtn.add(cacheTxMap.get(addr).get(bn));
}
}
return rtn;
}
use of org.aion.zero.types.AionTransaction in project aion by aionnetwork.
the class ApiAion method getTransactionReceipt.
/* NOTE: only use this if you need receipts for one or small number transactions in a block.
* (since there is n^2 work happening here to compute cumulative nrg)
* For use cases where you need all the transaction receipts in a block, please use a different
* strategy,
*/
public TxRecpt getTransactionReceipt(byte[] txHash) {
if (txHash == null) {
if (LOG.isErrorEnabled()) {
LOG.error("<get-transaction-receipt msg=tx-hash-null>");
}
return null;
}
AionTxInfo txInfo = this.ac.getAionHub().getBlockchain().getTransactionInfo(txHash);
if (txInfo == null) {
if (LOG.isErrorEnabled()) {
LOG.error("<get-transaction-receipt msg=tx-info-null>");
}
return null;
}
AionBlock block = this.ac.getAionHub().getBlockchain().getBlockByHash(txInfo.getBlockHash());
if (block == null) {
if (LOG.isErrorEnabled()) {
LOG.error("<get-transaction-receipt msg=block-null>");
}
return null;
}
// need to return txes only from main chain
AionBlock mainBlock = this.ac.getAionHub().getBlockchain().getBlockByNumber(block.getNumber());
if (!Arrays.equals(block.getHash(), mainBlock.getHash())) {
LOG.debug("<get-transaction-receipt msg=hash-not-match>");
return null;
}
// @Jay
// TODO : think the good way to calculate the cumulated nrg use
long cumulateNrg = 0L;
for (AionTransaction atx : block.getTransactionsList()) {
// @Jay: This should not happen!
byte[] hash = atx.getHash();
if (hash == null) {
throw new NullPointerException();
}
AionTxInfo info = this.ac.getAionHub().getBlockchain().getTransactionInfo(hash);
// @Jay: This should not happen!
if (info == null) {
throw new NullPointerException();
}
cumulateNrg += info.getReceipt().getEnergyUsed();
if (Arrays.equals(txHash, hash)) {
break;
}
}
return new TxRecpt(block, txInfo, cumulateNrg, true);
}
Aggregations