use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class RepositoryImpl method getCode.
@Override
public synchronized byte[] getCode(RskAddress addr) {
if (!isExist(addr)) {
return EMPTY_BYTE_ARRAY;
}
AccountState account = getAccountState(addr);
if (account.isHibernated()) {
return EMPTY_BYTE_ARRAY;
}
byte[] codeHash = account.getCodeHash();
if (Arrays.equals(codeHash, EMPTY_DATA_HASH)) {
return EMPTY_BYTE_ARRAY;
}
ContractDetails details = getContractDetails(addr);
return (details == null) ? null : details.getCode();
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class RepositoryImpl method getContractDetails.
@Override
public synchronized ContractDetails getContractDetails(RskAddress addr) {
// That part is important cause if we have
// to sync details storage according the trie root
// saved in the account
AccountState accountState = getAccountState(addr);
byte[] storageRoot = EMPTY_TRIE_HASH;
if (accountState != null) {
storageRoot = getAccountState(addr).getStateRoot();
}
ContractDetails details = detailsDataStore.get(addr);
if (details != null) {
details = details.getSnapshotTo(storageRoot);
}
return details;
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class RepositoryImpl method updateBatch.
@Override
public synchronized void updateBatch(Map<RskAddress, AccountState> stateCache, Map<RskAddress, ContractDetails> detailsCache) {
logger.debug("updatingBatch: detailsCache.size: {}", detailsCache.size());
for (Map.Entry<RskAddress, AccountState> entry : stateCache.entrySet()) {
RskAddress addr = entry.getKey();
AccountState accountState = entry.getValue();
ContractDetails contractDetails = detailsCache.get(addr);
if (accountState.isDeleted()) {
delete(addr);
logger.debug("delete: [{}]", addr);
} else {
if (!contractDetails.isDirty()) {
continue;
}
ContractDetailsCacheImpl contractDetailsCache = (ContractDetailsCacheImpl) contractDetails;
if (contractDetailsCache.getOriginalContractDetails() == null) {
ContractDetails originalContractDetails = new ContractDetailsImpl(config);
originalContractDetails.setAddress(addr.getBytes());
contractDetailsCache.setOriginalContractDetails(originalContractDetails);
contractDetailsCache.commit();
}
contractDetails = contractDetailsCache.getOriginalContractDetails();
updateContractDetails(addr, contractDetails);
if (!Arrays.equals(accountState.getCodeHash(), EMPTY_TRIE_HASH)) {
accountState.setStateRoot(contractDetails.getStorageHash());
}
updateAccountState(addr, accountState);
}
}
logger.debug("updated: detailsCache.size: {}", detailsCache.size());
stateCache.clear();
detailsCache.clear();
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class RepositoryImpl method addBalance.
@Override
public synchronized Coin addBalance(RskAddress addr, Coin value) {
AccountState account = getAccountStateOrCreateNew(addr);
Coin result = account.addToBalance(value);
updateAccountState(addr, account);
return result;
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class RepositoryImpl method getAccountState.
@Override
public synchronized AccountState getAccountState(RskAddress addr) {
AccountState result = null;
byte[] accountData = null;
accountData = this.trie.get(addr.getBytes());
if (accountData != null && accountData.length != 0) {
result = new AccountState(accountData);
}
return result;
}
Aggregations