Search in sources :

Example 36 with Address

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;
}
Also used : Address(org.aion.base.type.Address) DataWord(org.aion.mcf.vm.types.DataWord) ByteUtil.toHexString(org.aion.base.util.ByteUtil.toHexString)

Example 37 with Address

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;
}
Also used : Address(org.aion.base.type.Address) ECKey(org.aion.crypto.ECKey) ByteUtil.toHexString(org.aion.base.util.ByteUtil.toHexString)

Example 38 with Address

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);
}
Also used : Address(org.aion.base.type.Address) ByteUtil.toHexString(org.aion.base.util.ByteUtil.toHexString) IRepository(org.aion.base.db.IRepository)

Example 39 with Address

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;
}
Also used : Address(org.aion.base.type.Address) ECKey(org.aion.crypto.ECKey)

Example 40 with Address

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;
}
Also used : Address(org.aion.base.type.Address) AionTransaction(org.aion.zero.types.AionTransaction)

Aggregations

Address (org.aion.base.type.Address)61 Test (org.junit.Test)34 BigInteger (java.math.BigInteger)29 AionTransaction (org.aion.zero.types.AionTransaction)23 ITransaction (org.aion.base.type.ITransaction)14 ECKey (org.aion.crypto.ECKey)13 DataWord (org.aion.mcf.vm.types.DataWord)11 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)10 TxPoolA0 (org.aion.txpool.zero.TxPoolA0)9 IRepositoryCache (org.aion.base.db.IRepositoryCache)8 HashMap (java.util.HashMap)6 ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)5 ByteUtil.toHexString (org.aion.base.util.ByteUtil.toHexString)5 AccountState (org.aion.mcf.core.AccountState)5 AionBlock (org.aion.zero.impl.types.AionBlock)5 ArrayList (java.util.ArrayList)4 ImportResult (org.aion.mcf.core.ImportResult)4 IByteArrayKeyValueDatabase (org.aion.base.db.IByteArrayKeyValueDatabase)3 IRepository (org.aion.base.db.IRepository)3 AionContractDetailsImpl (org.aion.zero.db.AionContractDetailsImpl)3