Search in sources :

Example 1 with AionTxReceipt

use of org.aion.zero.types.AionTxReceipt in project aion by aionnetwork.

the class ApiAion method doCall.

public byte[] doCall(ArgTxCall _params) {
    AionTransaction tx = new AionTransaction(_params.getNonce().toByteArray(), _params.getTo(), _params.getValue().toByteArray(), _params.getData(), _params.getNrg(), _params.getNrgPrice());
    AionTxReceipt rec = this.ac.callConstant(tx, this.ac.getAionHub().getBlockchain().getBestBlock());
    return rec.getExecutionResult();
}
Also used : AionTransaction(org.aion.zero.types.AionTransaction) AionTxReceipt(org.aion.zero.types.AionTxReceipt)

Example 2 with AionTxReceipt

use of org.aion.zero.types.AionTxReceipt 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();
}
Also used : AionTransaction(org.aion.zero.types.AionTransaction) AionTxReceipt(org.aion.zero.types.AionTxReceipt)

Example 3 with AionTxReceipt

use of org.aion.zero.types.AionTxReceipt in project aion by aionnetwork.

the class ApiAion0 method onBlock.

protected void onBlock(AionBlockSummary cbs) {
    Set<Long> keys = installedFilters.keySet();
    for (Long key : keys) {
        Fltr fltr = installedFilters.get(key);
        if (fltr.isExpired()) {
            LOG.debug("<fltr key={} expired removed>", key);
            installedFilters.remove(key);
        } else {
            List<AionTxReceipt> txrs = cbs.getReceipts();
            if (fltr.getType() == Fltr.Type.EVENT && !Optional.ofNullable(txrs).orElse(Collections.emptyList()).isEmpty()) {
                FltrCt _fltr = (FltrCt) fltr;
                for (AionTxReceipt txr : txrs) {
                    AionTransaction tx = txr.getTransaction();
                    Address contractAddress = Optional.ofNullable(tx.getTo()).orElse(tx.getContractAddress());
                    Integer cnt = 0;
                    txr.getLogInfoList().forEach(bi -> bi.getTopics().forEach(lg -> {
                        if (_fltr.isFor(contractAddress, ByteUtil.toHexString(lg))) {
                            IBlock<AionTransaction, ?> blk = (cbs).getBlock();
                            List<AionTransaction> txList = blk.getTransactionsList();
                            int insideCnt = 0;
                            for (AionTransaction t : txList) {
                                if (Arrays.equals(t.getHash(), tx.getHash())) {
                                    break;
                                }
                                insideCnt++;
                            }
                            EvtContract ec = new EvtContract(bi.getAddress().toBytes(), bi.getData(), blk.getHash(), blk.getNumber(), cnt, ByteUtil.toHexString(lg), false, insideCnt, tx.getHash());
                            _fltr.add(ec);
                        }
                    }));
                }
            }
        }
    }
}
Also used : AionBlock(org.aion.zero.impl.types.AionBlock) java.util(java.util) Version(org.aion.zero.impl.Version) LRUMap(org.apache.commons.collections4.map.LRUMap) org.aion.base.type(org.aion.base.type) ByteBuffer(java.nio.ByteBuffer) org.aion.api.server.types(org.aion.api.server.types) Abi(org.aion.solidity.Abi) IAionChain(org.aion.zero.impl.blockchain.IAionChain) AionTxReceipt(org.aion.zero.types.AionTxReceipt) INode(org.aion.p2p.INode) BigInteger(java.math.BigInteger) IApiAion(org.aion.api.server.IApiAion) ApiAion(org.aion.api.server.ApiAion) IHandler(org.aion.evtmgr.IHandler) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ApiUtil(org.aion.api.server.ApiUtil) LongStream(java.util.stream.LongStream) TypeConverter(org.aion.base.util.TypeConverter) EventTx(org.aion.evtmgr.impl.evt.EventTx) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) EventCallback(org.aion.evtmgr.impl.callback.EventCallback) ByteString(com.google.protobuf.ByteString) EquihashMiner(org.aion.equihash.EquihashMiner) AionHub(org.aion.zero.impl.AionHub) Keystore(org.aion.mcf.account.Keystore) Entry(java.util.Map.Entry) ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) AionTxInfo(org.aion.zero.impl.types.AionTxInfo) Hex(org.aion.base.util.Hex) AionTransaction(org.aion.zero.types.AionTransaction) JSONArray(org.json.JSONArray) ByteUtil(org.aion.base.util.ByteUtil) AionTransaction(org.aion.zero.types.AionTransaction) BigInteger(java.math.BigInteger) AionTxReceipt(org.aion.zero.types.AionTxReceipt)

Example 4 with AionTxReceipt

use of org.aion.zero.types.AionTxReceipt in project aion by aionnetwork.

the class AionTxReceiptTest method testSerialization.

@Test
public void testSerialization() {
    AionTxReceipt receipt = new AionTxReceipt();
    receipt.setError("");
    receipt.setExecutionResult(HashUtil.h256(EMPTY_BYTE_ARRAY));
    List<Log> infos = new ArrayList<>();
    receipt.setLogs(infos);
    receipt.setPostTxState(HashUtil.h256(EMPTY_BYTE_ARRAY));
    byte[] encoded = receipt.getEncoded();
    AionTxReceipt resp = new AionTxReceipt(encoded);
    assertThat(resp.getExecutionResult(), is(equalTo(receipt.getExecutionResult())));
    assertThat(resp.getBloomFilter(), is(equalTo(receipt.getBloomFilter())));
    assertThat(resp.getError(), is(equalTo(receipt.getError())));
}
Also used : Log(org.aion.mcf.vm.types.Log) ArrayList(java.util.ArrayList) AionTxReceipt(org.aion.zero.types.AionTxReceipt) Test(org.junit.Test)

Example 5 with AionTxReceipt

use of org.aion.zero.types.AionTxReceipt in project aion by aionnetwork.

the class FltrLg method onBlock.

// -------------------------------------------------------------------------------
@Override
public boolean onBlock(IBlockSummary bs) {
    List<AionTxReceipt> receipts = ((AionBlockSummary) bs).getReceipts();
    IBlock blk = bs.getBlock();
    if (matchBloom(new Bloom(((IAionBlock) blk).getLogBloom()))) {
        int txIndex = 0;
        for (AionTxReceipt receipt : receipts) {
            ITransaction tx = receipt.getTransaction();
            if (matchesContractAddress(tx.getTo().toBytes())) {
                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, receipt.getTransaction(), logIndex, true)));
                        }
                        logIndex++;
                    }
                }
            }
            txIndex++;
        }
    }
    return true;
}
Also used : AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) Log(org.aion.mcf.vm.types.Log) Bloom(org.aion.mcf.vm.types.Bloom) IAionBlock(org.aion.zero.types.IAionBlock) AionTxReceipt(org.aion.zero.types.AionTxReceipt)

Aggregations

AionTxReceipt (org.aion.zero.types.AionTxReceipt)11 AionTransaction (org.aion.zero.types.AionTransaction)6 ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)3 Bloom (org.aion.mcf.vm.types.Bloom)3 Log (org.aion.mcf.vm.types.Log)3 AionBlock (org.aion.zero.impl.types.AionBlock)2 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)2 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)2 Test (org.junit.Test)2 ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 BigInteger (java.math.BigInteger)1 ByteBuffer (java.nio.ByteBuffer)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 Collectors (java.util.stream.Collectors)1 LongStream (java.util.stream.LongStream)1 ApiAion (org.aion.api.server.ApiAion)1