Search in sources :

Example 1 with Tx

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));
}
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)

Aggregations

CacheLoader (com.github.benmanes.caffeine.cache.CacheLoader)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 RoundingMode (java.math.RoundingMode)1 Instant (java.time.Instant)1 ZoneOffset (java.time.ZoneOffset)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Base64 (java.util.Base64)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 TimeUnit (java.util.concurrent.TimeUnit)1