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