Search in sources :

Example 1 with AionTxInfo

use of org.aion.zero.impl.types.AionTxInfo in project aion by aionnetwork.

the class AionBlockchainImpl method getTransactionInfo.

@Override
public /* NOTE: only returns receipts from the main chain
     */
AionTxInfo getTransactionInfo(byte[] hash) {
    List<AionTxInfo> infos = transactionStore.get(hash);
    if (infos == null || infos.isEmpty()) {
        return null;
    }
    AionTxInfo txInfo = null;
    if (infos.size() == 1) {
        txInfo = infos.get(0);
    } else {
        // pick up the receipt from the block on the main chain
        for (AionTxInfo info : infos) {
            AionBlock block = getBlockStore().getBlockByHash(info.getBlockHash());
            if (block == null)
                continue;
            AionBlock mainBlock = getBlockStore().getChainBlockByNumber(block.getNumber());
            if (mainBlock == null)
                continue;
            if (FastByteComparisons.equal(info.getBlockHash(), mainBlock.getHash())) {
                txInfo = info;
                break;
            }
        }
    }
    if (txInfo == null) {
        LOG.warn("Can't find block from main chain for transaction " + Hex.toHexString(hash));
        return null;
    }
    AionTransaction tx = this.getBlockByHash(txInfo.getBlockHash()).getTransactionsList().get(txInfo.getIndex());
    txInfo.setTransaction(tx);
    return txInfo;
}
Also used : AionTxInfo(org.aion.zero.impl.types.AionTxInfo) AionBlock(org.aion.zero.impl.types.AionBlock)

Example 2 with AionTxInfo

use of org.aion.zero.impl.types.AionTxInfo in project aion by aionnetwork.

the class AionPendingStateImpl method clearPending.

// @SuppressWarnings("unchecked")
// @Deprecated
// private void clearPending(IAionBlock block, List<AionTxReceipt> receipts) {
// 
// List<AionTransaction> txList = block.getTransactionsList();
// 
// if (LOG.isDebugEnabled()) {
// LOG.debug("clearPending block#[{}] tx#[{}]", block.getNumber(), txList.size());
// }
// 
// if (!txList.isEmpty()) {
// List<AionTransaction> txn = this.txPool.remove(txList);
// 
// int cnt = 0;
// for (AionTransaction tx : txn) {
// if (LOG.isTraceEnabled()) {
// LOG.trace("Clear pending transaction, hash: [{}]", Hex.toHexString(tx.getHash()));
// }
// 
// AionTxReceipt receipt;
// if (receipts != null) {
// receipt = receipts.get(cnt);
// } else {
// AionTxInfo info = getTransactionInfo(tx.getHash(), block.getHash());
// receipt = info.getReceipt();
// }
// fireTxUpdate(receipt, PendingTransactionState.INCLUDED, block);
// cnt++;
// }
// }
// }
@SuppressWarnings("unchecked")
private void clearPending(IAionBlock block, List<AionTxReceipt> receipts) {
    List<AionTransaction> txList = block.getTransactionsList();
    Map<Address, BigInteger> accountNonce = new HashMap<>();
    if (txList != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("clearPending block#[{}] tx#[{}]", block.getNumber(), txList.size());
        }
        for (AionTransaction tx : txList) {
            if (accountNonce.get(tx.getFrom()) != null) {
                continue;
            }
            if (LOG.isTraceEnabled()) {
                LOG.trace("clear address {}", tx.getFrom().toString());
            }
            accountNonce.put(tx.getFrom(), this.repository.getNonce(tx.getFrom()));
        }
    }
    if (!accountNonce.isEmpty()) {
        this.txPool.remove(accountNonce);
        int cnt = 0;
        for (AionTransaction tx : txList) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Clear pending transaction, hash: [{}]", Hex.toHexString(tx.getHash()));
            }
            AionTxReceipt receipt;
            if (receipts != null) {
                receipt = receipts.get(cnt);
            } else {
                AionTxInfo info = getTransactionInfo(tx.getHash(), block.getHash());
                receipt = info.getReceipt();
            }
            fireTxUpdate(receipt, PendingTransactionState.INCLUDED, block);
            cnt++;
        }
    }
}
Also used : AionTxInfo(org.aion.zero.impl.types.AionTxInfo) BigInteger(java.math.BigInteger)

Example 3 with AionTxInfo

use of org.aion.zero.impl.types.AionTxInfo 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);
}
Also used : TxRecpt(org.aion.api.server.types.TxRecpt) AionTxInfo(org.aion.zero.impl.types.AionTxInfo) AionTransaction(org.aion.zero.types.AionTransaction) AionBlock(org.aion.zero.impl.types.AionBlock)

Example 4 with AionTxInfo

use of org.aion.zero.impl.types.AionTxInfo in project aion by aionnetwork.

the class ApiWeb3Aion method eth_getTransactionByHash.

public Object eth_getTransactionByHash(String _txHash) {
    byte[] txHash = ByteUtil.hexStringToBytes(_txHash);
    if (_txHash == null || txHash == null)
        return null;
    AionTxInfo txInfo = this.ac.getAionHub().getBlockchain().getTransactionInfo(txHash);
    if (txInfo == null)
        return null;
    AionBlock b = this.ac.getBlockchain().getBlockByHash(txInfo.getBlockHash());
    if (b == null)
        return null;
    return Tx.InfoToJSON(txInfo, b);
}
Also used : AionTxInfo(org.aion.zero.impl.types.AionTxInfo) AionBlock(org.aion.zero.impl.types.AionBlock)

Example 5 with AionTxInfo

use of org.aion.zero.impl.types.AionTxInfo in project aion by aionnetwork.

the class FltrLg method onBlock.

// inelegant (distributing chain singleton ref. into here), tradeoff for efficiency and ease of impl.
// rationale: this way, we only retrieve logs from DB for transactions that the bloom
// filter gives a positive match for;
public boolean onBlock(IAionBlock blk, IAionBlockchain chain) {
    if (matchBloom(new Bloom(blk.getLogBloom()))) {
        int txIndex = 0;
        for (ITransaction txn : blk.getTransactionsList()) {
            if (matchesContractAddress(txn.getTo().toBytes())) {
                // now that we know that our filter might match with some logs in this transaction, go ahead
                // and retrieve the txReceipt from the chain
                AionTxInfo txInfo = chain.getTransactionInfo(txn.getHash());
                AionTxReceipt receipt = txInfo.getReceipt();
                if (matchBloom(receipt.getBloomFilter())) {
                    int logIndex = 0;
                    for (Log logInfo : receipt.getLogInfoList()) {
                        if (matchBloom(logInfo.getBloom()) && matchesExactly(logInfo)) {
                            add(new EvtLg(new TxRecptLg(logInfo, blk, txIndex, txn, logIndex, true)));
                        }
                        logIndex++;
                    }
                }
            }
            txIndex++;
        }
    }
    return true;
}
Also used : AionTxInfo(org.aion.zero.impl.types.AionTxInfo) Log(org.aion.mcf.vm.types.Log) Bloom(org.aion.mcf.vm.types.Bloom) AionTxReceipt(org.aion.zero.types.AionTxReceipt)

Aggregations

AionTxInfo (org.aion.zero.impl.types.AionTxInfo)9 AionBlock (org.aion.zero.impl.types.AionBlock)4 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)2 AionTransaction (org.aion.zero.types.AionTransaction)2 BigInteger (java.math.BigInteger)1 TxRecpt (org.aion.api.server.types.TxRecpt)1 Bloom (org.aion.mcf.vm.types.Bloom)1 Log (org.aion.mcf.vm.types.Log)1 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)1 AionTxReceipt (org.aion.zero.types.AionTxReceipt)1