use of org.aion.base.type.Address in project aion by aionnetwork.
the class ApiWeb3Aion method eth_getStorageAt.
public Object eth_getStorageAt(String _address, String _storageIndex, Object _bnOrId) {
Address address = new Address(_address);
String bnOrId = "latest";
if (_bnOrId != null && !_bnOrId.equals(null))
bnOrId = _bnOrId + "";
DataWord key = DataWord.ZERO;
try {
key = new DataWord(ByteUtil.hexStringToBytes(_storageIndex));
} catch (Exception e) {
// invalid key
LOG.debug("eth_getStorageAt: invalid storageIndex. Must be <= 16 bytes.");
return null;
}
DataWord storageValue = (DataWord) getRepoByJsonBlockId(bnOrId).getStorageValue(address, key);
return storageValue != null ? TypeConverter.toJsonHex(storageValue.getData()) : null;
}
use of org.aion.base.type.Address in project aion by aionnetwork.
the class ApiWeb3Aion method eth_sign.
public Object eth_sign(String _address, String _message) {
Address address = Address.wrap(_address);
ECKey key = getAccountKey(address.toString());
if (key == null)
return null;
// Message starts with Unicode Character 'END OF MEDIUM' (U+0019)
String message = "\u0019Aion Signed Message:\n" + _message.length() + _message;
byte[] messageHash = HashUtil.keccak256(message.getBytes());
String signature = TypeConverter.toJsonHex(key.sign(messageHash).getSignature());
return signature;
}
use of org.aion.base.type.Address in project aion by aionnetwork.
the class ApiWeb3Aion method eth_getCode.
public Object eth_getCode(String _address, Object _bnOrId) {
Address address = new Address(_address);
String bnOrId = "latest";
if (_bnOrId != null && !_bnOrId.equals(null))
bnOrId = _bnOrId + "";
IRepository repo = getRepoByJsonBlockId(bnOrId);
// invalid bnOrId
if (repo == null)
return null;
byte[] code = repo.getCode(address);
return TypeConverter.toJsonHex(code);
}
use of org.aion.base.type.Address in project aion by aionnetwork.
the class ApiWeb3Aion method eth_sendTransaction.
public Object eth_sendTransaction(JSONObject _tx) {
ArgTxCall txParams = ArgTxCall.fromJSON(_tx, getRecommendedNrgPrice(), getDefaultNrgLimit());
// check for unlocked account
Address address = txParams.getFrom();
ECKey key = getAccountKey(address.toString());
// TODO: send json-rpc error code + message
if (key == null)
return null;
if (txParams != null) {
byte[] response = sendTransaction(txParams);
return TypeConverter.toJsonHex(response);
}
return null;
}
use of org.aion.base.type.Address in project aion by aionnetwork.
the class NrgBlockPriceStrategy method getBlkPrice.
// notion of "block price" = lowest gas price for all transactions in a block, exluding miner's own transactions
// returns null if block is empty, invalid input, block filled only with miner's own transactions
private Long getBlkPrice(AionBlock blk) {
if (blk == null)
return null;
List<AionTransaction> txns = blk.getTransactionsList();
Address coinbase = blk.getCoinbase();
// there is nothing stopping nrg price to be 0. don't explicitly enforce non-zero nrg.
Long minNrg = null;
for (AionTransaction txn : txns) {
if (coinbase.compareTo(txn.getSignature().getPubkey(null)) != 0) {
long nrg = txn.getNrgPrice();
if (minNrg == null || nrg < minNrg)
minNrg = nrg;
}
}
return minNrg;
}
Aggregations