use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class RepositoryTrack method addBalance.
@Override
public Coin addBalance(RskAddress addr, Coin value) {
synchronized (repository) {
AccountState accountState = getAccountState(addr);
if (accountState == null) {
accountState = createAccount(addr);
}
getContractDetails(addr).setDirty(true);
Coin newBalance = accountState.addToBalance(value);
logger.trace("adding to balance addr: [{}], balance: [{}], delta: [{}]", addr, newBalance, value);
return newBalance;
}
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class RepositoryTrack method getAccountState.
@Override
public AccountState getAccountState(RskAddress addr) {
synchronized (repository) {
AccountState accountState = cacheAccounts.get(addr);
if (accountState == null) {
repository.loadAccount(addr, cacheAccounts, cacheDetails);
accountState = cacheAccounts.get(addr);
}
return accountState;
}
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class RepositoryTrack method increaseNonce.
@Override
public BigInteger increaseNonce(RskAddress addr) {
synchronized (repository) {
AccountState accountState = getAccountState(addr);
if (accountState == null) {
accountState = createAccount(addr);
}
getContractDetails(addr).setDirty(true);
BigInteger saveNonce = accountState.getNonce();
accountState.incrementNonce();
logger.trace("increase nonce addr: [{}], from: [{}], to: [{}]", addr, saveNonce, accountState.getNonce());
return accountState.getNonce();
}
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class RepositoryTrack method createAccount.
@Override
public AccountState createAccount(RskAddress addr) {
synchronized (repository) {
logger.trace("createAccount: [{}]", addr);
AccountState accountState = new AccountState();
cacheAccounts.put(addr, accountState);
ContractDetails contractDetails = new ContractDetailsCacheImpl(null);
contractDetails.setDirty(true);
cacheDetails.put(addr, contractDetails);
return accountState;
}
}
use of org.ethereum.core.AccountState in project rskj by rsksmart.
the class NetworkStateExporterTest method testContracts.
@Test
public void testContracts() throws Exception {
Repository repository = new RepositoryImpl(config, new TrieStoreImpl(new HashMapDB()));
String address1String = "1000000000000000000000000000000000000000";
RskAddress addr1 = new RskAddress(address1String);
repository.createAccount(addr1);
repository.addBalance(addr1, Coin.valueOf(1L));
repository.increaseNonce(addr1);
ContractDetails contractDetails = new co.rsk.db.ContractDetailsImpl(config);
contractDetails.setCode(new byte[] { 1, 2, 3, 4 });
contractDetails.put(DataWord.ZERO, DataWord.ONE);
contractDetails.putBytes(DataWord.ONE, new byte[] { 5, 6, 7, 8 });
repository.updateContractDetails(addr1, contractDetails);
AccountState accountState = repository.getAccountState(addr1);
accountState.setStateRoot(contractDetails.getStorageHash());
repository.updateAccountState(addr1, accountState);
Map result = writeAndReadJson(repository);
Assert.assertEquals(1, result.keySet().size());
Map address1Value = (Map) result.get(address1String);
Assert.assertEquals(3, address1Value.keySet().size());
Assert.assertEquals("1", address1Value.get("balance"));
Assert.assertEquals("1", address1Value.get("nonce"));
Map contract = (Map) address1Value.get("contract");
Assert.assertEquals(2, contract.keySet().size());
Assert.assertEquals("01020304", contract.get("code"));
Map data = (Map) contract.get("data");
Assert.assertEquals(2, data.keySet().size());
Assert.assertEquals("01", data.get(Hex.toHexString(DataWord.ZERO.getData())));
Assert.assertEquals("05060708", data.get(Hex.toHexString(DataWord.ONE.getData())));
}
Aggregations