use of org.aion.base.type.Address in project aion by aionnetwork.
the class ApiAion method estimateNrg.
// TODO: refactor these ad-hoc transaction creations - violates DRY and is messy
public long estimateNrg(ArgTxCall _params) {
if (_params == null) {
throw new NullPointerException();
}
Address from = _params.getFrom();
if (from.equals(Address.EMPTY_ADDRESS())) {
LOG.error("<send-transaction msg=invalid-from-address>");
return -1L;
}
ECKey key = this.getAccountKey(from.toString());
if (key == null) {
LOG.error("<send-transaction msg=account-not-found>");
return -1L;
}
try {
// Transaction is executed as local transaction, no need to retrieve the real nonce.
byte[] nonce = BigInteger.ZERO.toByteArray();
AionTransaction tx = new AionTransaction(nonce, _params.getTo(), _params.getValue().toByteArray(), _params.getData(), _params.getNrg(), _params.getNrgPrice());
tx.sign(key);
return this.ac.estimateTxNrg(tx, this.ac.getAionHub().getBlockchain().getBestBlock());
} catch (Exception ex) {
return -1L;
}
}
use of org.aion.base.type.Address in project aion by aionnetwork.
the class ApiAion method createContract.
public ContractCreateResult createContract(ArgTxCall _params) {
Address from = _params.getFrom();
if (from == null || from.equals(Address.EMPTY_ADDRESS())) {
return null;
}
ECKey key = this.getAccountKey(from.toString());
if (key == null) {
LOG.debug("ApiAion.createContract - null key");
return null;
} else {
try {
synchronized (pendingState) {
byte[] nonce = !(_params.getNonce().equals(BigInteger.ZERO)) ? _params.getNonce().toByteArray() : pendingState.bestNonce(Address.wrap(key.getAddress())).toByteArray();
AionTransaction tx = new AionTransaction(nonce, from, null, _params.getValue().toByteArray(), _params.getData(), _params.getNrg(), _params.getNrgPrice());
tx.sign(key);
pendingState.addPendingTransaction(tx);
ContractCreateResult c = new ContractCreateResult();
c.address = tx.getContractAddress();
c.transId = tx.getHash();
return c;
}
} catch (Exception ex) {
LOG.error("ApiAion.createContract - exception: [{}]", ex.getMessage());
return null;
}
}
}
use of org.aion.base.type.Address in project aion by aionnetwork.
the class ApiWeb3Aion method eth_getTransactionCount.
public Object eth_getTransactionCount(String _address, Object _bnOrId) {
Address address = new Address(_address);
String bnOrId = "latest";
if (_bnOrId != null && !_bnOrId.equals(null))
bnOrId = _bnOrId + "";
return TypeConverter.toJsonHex(getRepoByJsonBlockId(bnOrId).getNonce(address));
}
use of org.aion.base.type.Address in project aion by aionnetwork.
the class ApiWeb3Aion method eth_getBalance.
public Object eth_getBalance(String _address, Object _bnOrId) throws Exception {
Address address = new Address(_address);
String bnOrId = "latest";
if (_bnOrId != null && !_bnOrId.equals(null))
bnOrId = _bnOrId + "";
BigInteger balance = getRepoByJsonBlockId(bnOrId).getBalance(address);
return TypeConverter.toJsonHex(balance);
}
use of org.aion.base.type.Address in project aion by aionnetwork.
the class A0BlockHeader method fromRLP.
/**
* Construct a block header from RLP
*
* @param rlpHeader
* @param isUnsafe
* @return
*/
public static A0BlockHeader fromRLP(RLPList rlpHeader, boolean isUnsafe) throws Exception {
Builder builder = new Builder();
if (isUnsafe) {
builder.fromUnsafeSource();
}
builder.withParentHash(rlpHeader.get(RPL_BH_PARENTHASH).getRLPData());
builder.withCoinbase(new Address(rlpHeader.get(RPL_BH_COINBASE).getRLPData()));
builder.withStateRoot(rlpHeader.get(RPL_BH_STATEROOT).getRLPData());
byte[] txTrieRoot = rlpHeader.get(RPL_BH_TXTRIE).getRLPData();
if (txTrieRoot != null) {
builder.withTxTrieRoot(txTrieRoot);
}
byte[] receiptTrieRoot = rlpHeader.get(RPL_BH_RECEIPTTRIE).getRLPData();
if (receiptTrieRoot != null) {
builder.withReceiptTrieRoot(receiptTrieRoot);
}
builder.withLogsBloom(rlpHeader.get(RPL_BH_LOGSBLOOM).getRLPData());
builder.withDifficulty(rlpHeader.get(RPL_BH_DIFFICULTY).getRLPData());
byte[] nrBytes = rlpHeader.get(RPL_BH_NUMBER).getRLPData();
byte[] tsBytes = rlpHeader.get(RPL_BH_TIMESTAMP).getRLPData();
if (nrBytes != null) {
builder.withNumber(nrBytes);
}
if (tsBytes != null) {
builder.withTimestamp(tsBytes);
}
builder.withExtraData(rlpHeader.get(RPL_BH_EXTRADATA).getRLPData());
builder.withNonce(rlpHeader.get(RPL_BH_NONCE).getRLPData());
builder.withSolution(rlpHeader.get(RPL_BH_SOLUTION).getRLPData());
byte[] energyConsumedBytes = rlpHeader.get(RPL_BH_NRG_CONSUMED).getRLPData();
byte[] energyLimitBytes = rlpHeader.get(RPL_BH_NRG_LIMIT).getRLPData();
if (energyConsumedBytes != null) {
builder.withEnergyConsumed(energyConsumedBytes);
}
if (energyLimitBytes != null) {
builder.withEnergyLimit(energyLimitBytes);
}
return builder.build();
}
Aggregations