Search in sources :

Example 41 with AionTransaction

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

the class Tx method InfoToJSON.

public static Object InfoToJSON(AionTxInfo info, AionBlock b) {
    if (info == null)
        return null;
    AionTxReceipt receipt = info.getReceipt();
    if (receipt == null)
        return null;
    AionTransaction tx = receipt.getTransaction();
    return (AionTransactionToJSON(tx, b, info.getIndex()));
}
Also used : AionTransaction(org.aion.zero.types.AionTransaction) AionTxReceipt(org.aion.zero.types.AionTxReceipt)

Example 42 with AionTransaction

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

the class Blk method AionBlockToJson.

public static Object AionBlockToJson(AionBlock block, BigInteger totalDifficulty, boolean fullTransaction) {
    if (block == null)
        return null;
    JSONObject obj = new JSONObject();
    obj.put("number", block.getNumber());
    obj.put("hash", TypeConverter.toJsonHex(block.getHash()));
    obj.put("parentHash", TypeConverter.toJsonHex(block.getParentHash()));
    obj.put("logsBloom", TypeConverter.toJsonHex(block.getLogBloom()));
    obj.put("transactionsRoot", TypeConverter.toJsonHex(block.getTxTrieRoot()));
    obj.put("stateRoot", TypeConverter.toJsonHex(block.getStateRoot()));
    obj.put("receiptsRoot", TypeConverter.toJsonHex(block.getReceiptsRoot() == null ? new byte[0] : block.getReceiptsRoot()));
    obj.put("difficulty", TypeConverter.toJsonHex(block.getDifficulty()));
    obj.put("totalDifficulty", TypeConverter.toJsonHex(totalDifficulty));
    // TODO: this is coinbase, miner, or minerAddress?
    obj.put("miner", TypeConverter.toJsonHex(block.getCoinbase().toString()));
    obj.put("timestamp", TypeConverter.toJsonHex(block.getTimestamp()));
    obj.put("nonce", TypeConverter.toJsonHex(block.getNonce()));
    obj.put("solution", TypeConverter.toJsonHex(block.getHeader().getSolution()));
    obj.put("gasUsed", TypeConverter.toJsonHex(block.getHeader().getEnergyConsumed()));
    obj.put("gasLimit", TypeConverter.toJsonHex(block.getHeader().getEnergyLimit()));
    obj.put("nrgUsed", TypeConverter.toJsonHex(block.getHeader().getEnergyConsumed()));
    obj.put("nrgLimit", TypeConverter.toJsonHex(block.getHeader().getEnergyLimit()));
    // 
    obj.put("extraData", TypeConverter.toJsonHex(block.getExtraData()));
    obj.put("size", new NumericalValue(block.getEncoded().length).toHexString());
    JSONArray jsonTxs = new JSONArray();
    List<AionTransaction> txs = block.getTransactionsList();
    for (int i = 0; i < txs.size(); i++) {
        AionTransaction tx = txs.get(i);
        if (fullTransaction) {
            JSONObject jsonTx = new JSONObject();
            jsonTx.put("contractAddress", (tx.getContractAddress() != null) ? TypeConverter.toJsonHex(tx.getContractAddress().toString()) : null);
            jsonTx.put("hash", TypeConverter.toJsonHex(tx.getHash()));
            jsonTx.put("transactionIndex", i);
            jsonTx.put("value", TypeConverter.toJsonHex(tx.getValue()));
            jsonTx.put("nrg", tx.getNrg());
            jsonTx.put("nrgPrice", TypeConverter.toJsonHex(tx.getNrgPrice()));
            jsonTx.put("gas", tx.getNrg());
            jsonTx.put("gasPrice", TypeConverter.toJsonHex(tx.getNrgPrice()));
            jsonTx.put("nonce", ByteUtil.byteArrayToLong(tx.getNonce()));
            jsonTx.put("from", TypeConverter.toJsonHex(tx.getFrom().toString()));
            jsonTx.put("to", TypeConverter.toJsonHex(tx.getTo().toString()));
            jsonTx.put("timestamp", ByteUtil.byteArrayToLong(tx.getTimeStamp()));
            jsonTx.put("input", TypeConverter.toJsonHex(tx.getData()));
            jsonTx.put("blockNumber", block.getNumber());
            jsonTxs.put(jsonTx);
        } else {
            jsonTxs.put(TypeConverter.toJsonHex(tx.getHash()));
        }
    }
    obj.put("transactions", jsonTxs);
    return obj;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) AionTransaction(org.aion.zero.types.AionTransaction)

Example 43 with AionTransaction

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

the class ApiWeb3Aion method eth_getTransactionByBlockNumberAndIndex.

public Object eth_getTransactionByBlockNumberAndIndex(String _bnOrId, String _index) {
    Long bn = parseBnOrId(_bnOrId);
    if (bn == null || bn < 0)
        return null;
    AionBlock b = this.ac.getBlockchain().getBlockByNumber(bn);
    if (b == null)
        return null;
    List<AionTransaction> txs = b.getTransactionsList();
    int idx = Integer.decode(_index);
    if (idx >= txs.size())
        return null;
    return Tx.AionTransactionToJSON(txs.get(idx), b, idx);
}
Also used : AionTransaction(org.aion.zero.types.AionTransaction) AionBlock(org.aion.zero.impl.types.AionBlock)

Example 44 with AionTransaction

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

the class ApiWeb3Aion method eth_getTransactionByBlockHashAndIndex.

public Object eth_getTransactionByBlockHashAndIndex(String _blockHash, String _index) {
    byte[] hash = ByteUtil.hexStringToBytes(_blockHash);
    if (_blockHash == null || hash == null)
        return null;
    AionBlock b = this.ac.getBlockchain().getBlockByHash(hash);
    if (b == null)
        return null;
    List<AionTransaction> txs = b.getTransactionsList();
    int idx = Integer.decode(_index);
    if (idx >= txs.size())
        return null;
    return Tx.AionTransactionToJSON(txs.get(idx), b, idx);
}
Also used : AionTransaction(org.aion.zero.types.AionTransaction) AionBlock(org.aion.zero.impl.types.AionBlock)

Example 45 with AionTransaction

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

the class ApiWeb3Aion method eth_call.

public Object eth_call(JSONObject _tx, Object _bnOrId) {
    ArgTxCall txParams = ArgTxCall.fromJSON(_tx, getRecommendedNrgPrice(), getDefaultNrgLimit());
    String bnOrId = "latest";
    if (_bnOrId != null && !_bnOrId.equals(null))
        bnOrId = _bnOrId + "";
    Long bn = parseBnOrId(bnOrId);
    if (bn == null || bn < 0)
        return null;
    AionTransaction tx = new AionTransaction(txParams.getNonce().toByteArray(), txParams.getTo(), txParams.getValue().toByteArray(), txParams.getData(), txParams.getNrg(), txParams.getNrgPrice());
    AionBlock b = this.ac.getBlockchain().getBlockByNumber(bn);
    AionTxReceipt receipt = this.ac.callConstant(tx, b);
    return TypeConverter.toJsonHex(receipt.getExecutionResult());
}
Also used : AionTransaction(org.aion.zero.types.AionTransaction) ByteUtil.toHexString(org.aion.base.util.ByteUtil.toHexString) AionTxReceipt(org.aion.zero.types.AionTxReceipt) AionBlock(org.aion.zero.impl.types.AionBlock)

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