Search in sources :

Example 21 with AccountState

use of org.ethereum.core.AccountState in project rskj by rsksmart.

the class RepositoryImpl method loadAccount.

@Override
public synchronized void loadAccount(RskAddress addr, Map<RskAddress, AccountState> cacheAccounts, Map<RskAddress, ContractDetails> cacheDetails) {
    AccountState account = getAccountState(addr);
    ContractDetails details = getContractDetails(addr);
    account = (account == null) ? new AccountState() : account.clone();
    details = new ContractDetailsCacheImpl(details);
    cacheAccounts.put(addr, account);
    cacheDetails.put(addr, details);
}
Also used : AccountState(org.ethereum.core.AccountState)

Example 22 with AccountState

use of org.ethereum.core.AccountState in project rskj by rsksmart.

the class RepositoryImpl method hibernate.

@Override
public synchronized void hibernate(RskAddress addr) {
    AccountState account = getAccountStateOrCreateNew(addr);
    account.hibernate();
    updateAccountState(addr, account);
}
Also used : AccountState(org.ethereum.core.AccountState)

Example 23 with AccountState

use of org.ethereum.core.AccountState in project rskj by rsksmart.

the class RepositoryImpl method createAccount.

@Override
public synchronized AccountState createAccount(RskAddress addr) {
    AccountState accountState = new AccountState();
    updateAccountState(addr, accountState);
    updateContractDetails(addr, new ContractDetailsImpl(config));
    return accountState;
}
Also used : AccountState(org.ethereum.core.AccountState)

Example 24 with AccountState

use of org.ethereum.core.AccountState in project rskj by rsksmart.

the class RepositoryImpl method increaseNonce.

@Override
public synchronized BigInteger increaseNonce(RskAddress addr) {
    AccountState account = getAccountStateOrCreateNew(addr);
    account.incrementNonce();
    updateAccountState(addr, account);
    return account.getNonce();
}
Also used : AccountState(org.ethereum.core.AccountState)

Example 25 with AccountState

use of org.ethereum.core.AccountState in project rskj by rsksmart.

the class TxBuilder method simulateTxs.

public void simulateTxs() {
    key = ECKey.fromPrivate(privateKeyBytes);
    new Thread() {

        @Override
        public void run() {
            try {
                Thread.sleep(60000);
                while (blockProcessor.hasBetterBlockToSync()) {
                    Thread.sleep(60000);
                }
                SecureRandom random = new SecureRandom();
                RskAddress addr = new RskAddress(key.getAddress());
                AccountState accountState = repository.getAccountState(addr);
                BigInteger nonce = accountState.getNonce();
                while (!stop) {
                    if ((random.nextInt() % 10) == 0) {
                        nonce = repository.getAccountState(addr).getNonce();
                    }
                    TxBuilder.this.createNewTx(nonce);
                    Thread.sleep(random.nextInt(51000));
                    nonce = nonce.add(BigInteger.ONE);
                }
            } catch (InterruptedException e) {
                logger.error("TxBuild Thread was interrupted", e);
                Thread.currentThread().interrupt();
                return;
            }
        }
    }.start();
}
Also used : RskAddress(co.rsk.core.RskAddress) SecureRandom(java.security.SecureRandom) BigInteger(java.math.BigInteger) 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