Search in sources :

Example 41 with AccountState

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();
}
Also used : AccountState(org.ethereum.core.AccountState)

Example 42 with AccountState

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;
}
Also used : AccountState(org.ethereum.core.AccountState)

Example 43 with AccountState

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();
}
Also used : RskAddress(co.rsk.core.RskAddress) AccountState(org.ethereum.core.AccountState) Map(java.util.Map)

Example 44 with AccountState

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;
}
Also used : Coin(co.rsk.core.Coin) AccountState(org.ethereum.core.AccountState)

Example 45 with AccountState

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;
}
Also used : AccountState(org.ethereum.core.AccountState)

Aggregations

AccountState (org.ethereum.core.AccountState)46 Test (org.junit.Test)20 RskAddress (co.rsk.core.RskAddress)12 BigInteger (java.math.BigInteger)11 Coin (co.rsk.core.Coin)10 Transaction (org.ethereum.core.Transaction)10 Repository (org.ethereum.core.Repository)7 ContractDetails (org.ethereum.db.ContractDetails)7 Program (org.ethereum.vm.program.Program)5 ProgramInvokeMockImpl (org.ethereum.vm.program.invoke.ProgramInvokeMockImpl)5 Ignore (org.junit.Ignore)5 RskSystemProperties (co.rsk.config.RskSystemProperties)3 TrieImplHashTest (co.rsk.trie.TrieImplHashTest)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ECKey (org.ethereum.crypto.ECKey)3 RepositoryImpl (co.rsk.db.RepositoryImpl)2 TxsPerAccount (co.rsk.net.handler.TxsPerAccount)2 TrieStoreImpl (co.rsk.trie.TrieStoreImpl)2 HashMapDB (org.ethereum.datasource.HashMapDB)2