Search in sources :

Example 16 with AccountState

use of org.aion.mcf.core.AccountState in project aion by aionnetwork.

the class AionRepositoryDummy method setNonce.

public BigInteger setNonce(Address addr, BigInteger nonce) {
    AccountState account = getAccountState(addr);
    if (account == null) {
        account = createAccount(addr);
    }
    account.setNonce(nonce);
    worldState.put(addr.toByteArrayWrapper(), account);
    return account.getNonce();
}
Also used : AccountState(org.aion.mcf.core.AccountState)

Example 17 with AccountState

use of org.aion.mcf.core.AccountState in project aion by aionnetwork.

the class AionRepositoryDummy method addBalance.

public BigInteger addBalance(Address addr, BigInteger value) {
    AccountState account = getAccountState(addr);
    if (account == null) {
        account = createAccount(addr);
    }
    BigInteger result = account.addToBalance(value);
    worldState.put(addr.toByteArrayWrapper(), account);
    return result;
}
Also used : BigInteger(java.math.BigInteger) AccountState(org.aion.mcf.core.AccountState)

Example 18 with AccountState

use of org.aion.mcf.core.AccountState in project aion by aionnetwork.

the class AionRepositoryImpl method getAccountState.

@Override
public synchronized AccountState getAccountState(Address address) {
    // TODO
    rwLock.readLock().lock();
    try {
        AccountState result = null;
        byte[] accountData = worldState.get(address.toBytes());
        if (accountData.length != 0) {
            result = new AccountState(accountData);
            LOG.debug("New AccountSate [{}], State [{}]", address.toString(), result.toString());
        }
        return result;
    } finally {
        rwLock.readLock().unlock();
    }
}
Also used : AccountState(org.aion.mcf.core.AccountState)

Example 19 with AccountState

use of org.aion.mcf.core.AccountState in project aion by aionnetwork.

the class AionRepositoryImpl method loadAccountState.

/**
 * @implNote The loaded objects are fresh copies of the original account
 *           state and contract details.
 */
@Override
public synchronized void loadAccountState(Address address, Map<Address, AccountState> cacheAccounts, Map<Address, IContractDetails<DataWord>> cacheDetails) {
    AccountState account = getAccountState(address);
    IContractDetails<DataWord> details = getContractDetails(address);
    account = (account == null) ? new AccountState() : new AccountState(account);
    details = new ContractDetailsCacheImpl(details);
    // details.setAddress(addr);
    cacheAccounts.put(address, account);
    cacheDetails.put(address, details);
}
Also used : ContractDetailsCacheImpl(org.aion.mcf.db.ContractDetailsCacheImpl) DataWord(org.aion.mcf.vm.types.DataWord) AccountState(org.aion.mcf.core.AccountState)

Example 20 with AccountState

use of org.aion.mcf.core.AccountState in project aion by aionnetwork.

the class AionRepositoryImpl method getContractDetails.

@Override
public synchronized IContractDetails<DataWord> getContractDetails(Address address) {
    rwLock.readLock().lock();
    try {
        // That part is important cause if we have
        // to sync details storage according the trie root
        // saved in the account
        AccountState accountState = getAccountState(address);
        byte[] storageRoot = EMPTY_TRIE_HASH;
        if (accountState != null) {
            storageRoot = getAccountState(address).getStateRoot();
        }
        IContractDetails<DataWord> details = detailsDS.get(address.toBytes());
        if (details != null) {
            details = details.getSnapshotTo(storageRoot);
        }
        return details;
    } finally {
        rwLock.readLock().unlock();
    }
}
Also used : DataWord(org.aion.mcf.vm.types.DataWord) AccountState(org.aion.mcf.core.AccountState)

Aggregations

AccountState (org.aion.mcf.core.AccountState)21 DataWord (org.aion.mcf.vm.types.DataWord)10 BigInteger (java.math.BigInteger)4 Address (org.aion.base.type.Address)4 ContractDetailsCacheImpl (org.aion.mcf.db.ContractDetailsCacheImpl)3 AionGenesis (org.aion.zero.impl.AionGenesis)2 Test (org.junit.Test)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 IContractDetails (org.aion.base.db.IContractDetails)1 ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1