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