Search in sources :

Example 6 with TxRecpt

use of org.aion.api.server.types.TxRecpt 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));
}
Also used : Arrays(java.util.Arrays) ApiTxResponse(org.aion.api.server.ApiTxResponse) ArgTxCall(org.aion.api.server.types.ArgTxCall) Seal(org.aion.zero.impl.types.BlockHeader.Seal) ListIterator(java.util.ListIterator) FltrTx(org.aion.api.server.types.FltrTx) Version(org.aion.zero.impl.Version) Tx(org.aion.api.server.types.Tx) NodeWrapper(org.aion.zero.impl.sync.NodeWrapper) LRUMap(org.apache.commons.collections4.map.LRUMap) CfgApiZmq(org.aion.zero.impl.config.CfgApiZmq) AionTxReceipt(org.aion.base.AionTxReceipt) AionImpl(org.aion.zero.impl.blockchain.AionImpl) FltrBlk(org.aion.api.server.types.FltrBlk) CfgApiNrg(org.aion.zero.impl.config.CfgApiNrg) BigDecimal(java.math.BigDecimal) JSONObject(org.json.JSONObject) AddressUtils(org.aion.util.types.AddressUtils) Map(java.util.Map) BigInteger(java.math.BigInteger) MiningBlock(org.aion.zero.impl.types.MiningBlock) ZoneOffset(java.time.ZoneOffset) Block(org.aion.zero.impl.types.Block) AionAddress(org.aion.types.AionAddress) RoundingMode(java.math.RoundingMode) FltrLg(org.aion.api.server.types.FltrLg) HexConvert.hexStringToBytes(org.aion.util.types.HexConvert.hexStringToBytes) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) Fltr(org.aion.api.server.types.Fltr) Keystore(org.aion.zero.impl.keystore.Keystore) MiningBlockHeader(org.aion.zero.impl.types.MiningBlockHeader) Instant(java.time.Instant) ByteUtil(org.aion.util.bytes.ByteUtil) EventCallback(org.aion.evtmgr.impl.callback.EventCallback) TxRecpt(org.aion.api.server.types.TxRecpt) HashUtil(org.aion.crypto.HashUtil) TransactionTypes(org.aion.base.TransactionTypes) Base64(java.util.Base64) List(java.util.List) StringUtils(org.aion.util.string.StringUtils) CfgNet(org.aion.zero.impl.config.CfgNet) Entry(java.util.Map.Entry) Optional(java.util.Optional) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) Hex.toHexString(org.aion.util.conversions.Hex.toHexString) SyncInfo(org.aion.api.server.types.SyncInfo) ECKey(org.aion.crypto.ECKey) CfgAion(org.aion.zero.impl.config.CfgAion) BlockContext(org.aion.zero.impl.types.BlockContext) ArgFltr(org.aion.api.server.types.ArgFltr) CfgApiRpc(org.aion.zero.impl.config.CfgApiRpc) AccountState(org.aion.base.AccountState) CacheLoader(com.github.benmanes.caffeine.cache.CacheLoader) HashMap(java.util.HashMap) CfgApi(org.aion.zero.impl.config.CfgApi) CfgNetP2p(org.aion.zero.impl.config.CfgNetP2p) Function(java.util.function.Function) NumericalValue(org.aion.api.server.types.NumericalValue) ArrayList(java.util.ArrayList) DataWord(org.aion.util.types.DataWord) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) AccountManager(org.aion.api.server.account.AccountManager) IEventMgr(org.aion.evtmgr.IEventMgr) CfgTx(org.aion.zero.impl.config.CfgTx) IAionChain(org.aion.zero.impl.blockchain.IAionChain) StakingBlock(org.aion.zero.impl.types.StakingBlock) CfgSsl(org.aion.zero.impl.config.CfgSsl) CfgSync(org.aion.zero.impl.config.CfgSync) LinkedList(java.util.LinkedList) CfgEnergyStrategy(org.aion.zero.impl.config.CfgEnergyStrategy) ApiAion(org.aion.api.server.ApiAion) IHandler(org.aion.evtmgr.IHandler) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) Blk(org.aion.api.server.types.Blk) BLOCKS_QUERY_MAX(org.aion.api.server.types.FltrLg.BLOCKS_QUERY_MAX) Evt(org.aion.api.server.types.Evt) Log(org.aion.types.Log) ImportResult(org.aion.zero.impl.core.ImportResult) CompiledContr(org.aion.api.server.types.CompiledContr) AionBlockchainImpl(org.aion.zero.impl.blockchain.AionBlockchainImpl) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) EMPTY_BYTE_ARRAY(org.aion.util.bytes.ByteUtil.EMPTY_BYTE_ARRAY) CfgConsensusUnity(org.aion.zero.impl.config.CfgConsensusUnity) AionTxInfo(org.aion.zero.impl.types.AionTxInfo) StakingBlockHeader(org.aion.zero.impl.types.StakingBlockHeader) AionTransaction(org.aion.base.AionTransaction) Collections(java.util.Collections) JSONArray(org.json.JSONArray) AionTxInfo(org.aion.zero.impl.types.AionTxInfo) JSONArray(org.json.JSONArray) AionTransaction(org.aion.base.AionTransaction) Hex.toHexString(org.aion.util.conversions.Hex.toHexString) TxRecpt(org.aion.api.server.types.TxRecpt) JSONObject(org.json.JSONObject) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) StakingBlock(org.aion.zero.impl.types.StakingBlock) AionBlockchainImpl(org.aion.zero.impl.blockchain.AionBlockchainImpl)

Example 7 with TxRecpt

use of org.aion.api.server.types.TxRecpt in project aion by aionnetwork.

the class ApiWeb3Aion method eth_getTransactionReceipt.

public RpcMsg eth_getTransactionReceipt(Object _params) {
    String _hash;
    if (_params instanceof JSONArray) {
        _hash = ((JSONArray) _params).get(0) + "";
    } else if (_params instanceof JSONObject) {
        _hash = ((JSONObject) _params).get("hash") + "";
    } else {
        return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid parameters");
    }
    byte[] txHash = StringUtils.StringHexToByteArray(_hash);
    TxRecpt r = getTransactionReceipt(txHash);
    if (r == null) {
        return new RpcMsg(// json rpc spec: 'or null when no receipt was found'
        JSONObject.NULL);
    }
    return new RpcMsg(r.toJson());
}
Also used : TxRecpt(org.aion.api.server.types.TxRecpt) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Hex.toHexString(org.aion.util.conversions.Hex.toHexString)

Example 8 with TxRecpt

use of org.aion.api.server.types.TxRecpt in project aion by aionnetwork.

the class ApiWeb3Aion method ops_getTransactionReceiptByTransactionHash.

/**
 * This function runs in ~ 30ms Is an order of magnitude slower than
 * ops_getTransactionReceiptByTransactionAndBlockHash
 */
public RpcMsg ops_getTransactionReceiptByTransactionHash(Object _params) {
    String _transactionHash;
    if (_params instanceof JSONArray) {
        _transactionHash = ((JSONArray) _params).get(0) + "";
    } else if (_params instanceof JSONObject) {
        _transactionHash = ((JSONObject) _params).get("transactionHash") + "";
    } else {
        return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid parameters");
    }
    byte[] transactionHash = StringUtils.StringHexToByteArray(_transactionHash);
    AionTxInfo info = this.ac.getAionHub().getBlockchain().getTransactionInfo(transactionHash);
    if (info == null) {
        return new RpcMsg(JSONObject.NULL);
    }
    Block block = blockCache.get(ByteArrayWrapper.wrap(info.getBlockHash()));
    return new RpcMsg((new TxRecpt(block, info, 0L, true)).toJson());
}
Also used : TxRecpt(org.aion.api.server.types.TxRecpt) JSONObject(org.json.JSONObject) AionTxInfo(org.aion.zero.impl.types.AionTxInfo) JSONArray(org.json.JSONArray) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) StakingBlock(org.aion.zero.impl.types.StakingBlock) Hex.toHexString(org.aion.util.conversions.Hex.toHexString)

Example 9 with TxRecpt

use of org.aion.api.server.types.TxRecpt in project aion by aionnetwork.

the class ApiAion method getTransactionByBlockHashAndIndex.

protected TransactionWithBlockInfo getTransactionByBlockHashAndIndex(byte[] hash, long index) {
    Block pBlk = this.getBlockByHash(hash);
    if (pBlk == null) {
        if (LOG.isErrorEnabled()) {
            LOG.error("ApiAion.getTransactionByBlockHashAndIndex - can't find the block by the block hash");
        }
        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!");
        }
        return null;
    }
    TxRecpt receipt = this.getTransactionReceipt(tx.getTransactionHash());
    // TODO
    if (receipt == null) {
        throw new NullPointerException();
    }
    return new TransactionWithBlockInfo(tx, pBlk.getHash(), pBlk.getNumber(), index, receipt.nrgUsed);
}
Also used : TxRecpt(org.aion.api.server.types.TxRecpt) EventBlock(org.aion.evtmgr.impl.evt.EventBlock) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) AionTransaction(org.aion.base.AionTransaction)

Aggregations

TxRecpt (org.aion.api.server.types.TxRecpt)9 Block (org.aion.zero.impl.types.Block)7 MiningBlock (org.aion.zero.impl.types.MiningBlock)7 AionTransaction (org.aion.base.AionTransaction)6 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)5 JSONArray (org.json.JSONArray)5 EventBlock (org.aion.evtmgr.impl.evt.EventBlock)4 Hex.toHexString (org.aion.util.conversions.Hex.toHexString)4 StakingBlock (org.aion.zero.impl.types.StakingBlock)4 JSONObject (org.json.JSONObject)4 AionBlockchainImpl (org.aion.zero.impl.blockchain.AionBlockchainImpl)3 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Optional (java.util.Optional)2