Search in sources :

Example 36 with AionTransaction

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

the class ApiAion0 method createBlockMsg.

private byte[] createBlockMsg(AionBlock blk) {
    if (blk == null) {
        return ApiUtil.toReturnHeader(getApiVersion(), Message.Retcode.r_fail_function_arguments_VALUE);
    } else {
        List<ByteString> al = new ArrayList<>();
        for (AionTransaction tx : blk.getTransactionsList()) {
            al.add(ByteString.copyFrom(tx.getHash()));
        }
        BigInteger td = this.ac.getBlockchain().getTotalDifficultyByHash(Hash256.wrap(blk.getHash()));
        Message.rsp_getBlock rsp = getRsp_getBlock(blk, al, td);
        byte[] retHeader = ApiUtil.toReturnHeader(getApiVersion(), Message.Retcode.r_success_VALUE);
        return ApiUtil.combineRetMsg(retHeader, rsp.toByteArray());
    }
}
Also used : ByteString(com.google.protobuf.ByteString) BigInteger(java.math.BigInteger) AionTransaction(org.aion.zero.types.AionTransaction)

Example 37 with AionTransaction

use of org.aion.zero.types.AionTransaction 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 38 with AionTransaction

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

the class AionTransactionTest method testTransactionCost.

@Test
public void testTransactionCost() {
    byte[] nonce = DataWord.ONE.getData();
    byte[] from = RandomUtils.nextBytes(20);
    byte[] to = RandomUtils.nextBytes(Address.ADDRESS_LEN);
    byte[] value = DataWord.ONE.getData();
    byte[] data = RandomUtils.nextBytes(128);
    long nrg = new DataWord(1000L).longValue();
    long nrgPrice = DataWord.ONE.longValue();
    AionTransaction tx = new AionTransaction(nonce, Address.wrap(to), value, data, nrg, nrgPrice);
    long expected = 21000;
    for (byte b : data) {
        expected += (b == 0) ? 4 : 64;
    }
    assertEquals(expected, tx.transactionCost(1));
}
Also used : DataWord(org.aion.mcf.vm.types.DataWord) AionTransaction(org.aion.zero.types.AionTransaction) Test(org.junit.Test)

Example 39 with AionTransaction

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

the class AionTransactionTest method testSerializationZero.

@Test
public void testSerializationZero() {
    byte[] nonce = RandomUtils.nextBytes(16);
    Address to = Address.wrap(RandomUtils.nextBytes(32));
    byte[] value = RandomUtils.nextBytes(16);
    byte[] data = RandomUtils.nextBytes(64);
    long nrg = 0;
    long nrgPrice = 0;
    byte type = 0;
    AionTransaction tx = new AionTransaction(nonce, to, value, data, nrg, nrgPrice, type);
    tx.sign(ECKeyFac.inst().create());
    AionTransaction tx2 = new AionTransaction(tx.getEncoded());
    assertTransactionEquals(tx, tx2);
}
Also used : Address(org.aion.base.type.Address) AionTransaction(org.aion.zero.types.AionTransaction) Test(org.junit.Test)

Example 40 with AionTransaction

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

the class AionTransactionTest method testTransactionCost2.

@Test
public void testTransactionCost2() {
    byte[] nonce = DataWord.ONE.getData();
    byte[] from = RandomUtils.nextBytes(Address.ADDRESS_LEN);
    Address to = Address.EMPTY_ADDRESS();
    byte[] value = DataWord.ONE.getData();
    byte[] data = RandomUtils.nextBytes(128);
    long nrg = new DataWord(1000L).longValue();
    long nrgPrice = DataWord.ONE.longValue();
    AionTransaction tx = new AionTransaction(nonce, to, value, data, nrg, nrgPrice);
    long expected = 200000 + 21000;
    for (byte b : data) {
        expected += (b == 0) ? 4 : 64;
    }
    assertEquals(expected, tx.transactionCost(1));
}
Also used : Address(org.aion.base.type.Address) DataWord(org.aion.mcf.vm.types.DataWord) AionTransaction(org.aion.zero.types.AionTransaction) Test(org.junit.Test)

Aggregations

AionTransaction (org.aion.zero.types.AionTransaction)75 Test (org.junit.Test)44 BigInteger (java.math.BigInteger)30 ITransaction (org.aion.base.type.ITransaction)26 Address (org.aion.base.type.Address)23 TxPoolA0 (org.aion.txpool.zero.TxPoolA0)21 AionBlock (org.aion.zero.impl.types.AionBlock)17 ArrayList (java.util.ArrayList)16 ECKey (org.aion.crypto.ECKey)12 AionTxReceipt (org.aion.zero.types.AionTxReceipt)7 TxRecpt (org.aion.api.server.types.TxRecpt)4 ImportResult (org.aion.mcf.core.ImportResult)4 AionTxInfo (org.aion.zero.impl.types.AionTxInfo)4 ByteString (com.google.protobuf.ByteString)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ByteBuffer (java.nio.ByteBuffer)2 java.util (java.util)2 Entry (java.util.Map.Entry)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 Collectors (java.util.stream.Collectors)2