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