use of org.aion.mcf.core.AccountState in project aion by aionnetwork.
the class AbstractRepositoryCache method createAccount.
@Override
public synchronized AccountState createAccount(Address address) {
AccountState accountState = new AccountState();
cachedAccounts.put(address, accountState);
// TODO: unify contract details initialization from Impl and Track
IContractDetails<DataWord> contractDetails = new ContractDetailsCacheImpl(null);
// TODO: refactor to use makeDirty() from AbstractState
contractDetails.setDirty(true);
cachedDetails.put(address, contractDetails);
return accountState;
}
use of org.aion.mcf.core.AccountState in project aion by aionnetwork.
the class GenesisSpecificationTest method defaultGenesisBlockTest.
/**
* Test that the default genesis block built from the builder produces the
* correct genesis specs
*/
@Test
public void defaultGenesisBlockTest() {
AionGenesis.Builder genesisBuilder = new AionGenesis.Builder();
AionGenesis genesis = genesisBuilder.build();
assertThat(genesis.getParentHash()).isEqualTo(AionGenesis.GENESIS_PARENT_HASH);
assertThat(genesis.getCoinbase()).isEqualTo(AionGenesis.GENESIS_COINBASE);
assertThat(genesis.getDifficulty()).isEqualTo(AionGenesis.GENESIS_DIFFICULTY);
assertThat(genesis.getDifficultyBI()).isEqualTo(new BigInteger(1, AionGenesis.GENESIS_DIFFICULTY));
assertThat(genesis.getLogBloom()).isEqualTo(AionGenesis.GENESIS_LOGSBLOOM);
assertThat(genesis.getTimestamp()).isEqualTo(AionGenesis.GENESIS_TIMESTAMP);
assertThat(genesis.getNrgConsumed()).isEqualTo(0);
assertThat(genesis.getNrgLimit()).isEqualTo(AionGenesis.GENESIS_ENERGY_LIMIT);
assertThat(genesis.getTxTrieRoot()).isEqualTo(HashUtil.EMPTY_TRIE_HASH);
assertThat(genesis.getReceiptsRoot()).isEqualTo(HashUtil.EMPTY_TRIE_HASH);
assertThat(genesis.getCumulativeDifficulty()).isEqualTo(new BigInteger(1, AionGenesis.GENESIS_DIFFICULTY));
assertThat(genesis.getTransactionsList().isEmpty()).isEqualTo(true);
Map<Address, AccountState> premined = genesis.getPremine();
Set<Address> keySet = premined.keySet();
// default set
Set<Address> defaultKeySet = AionGenesis.GENESIS_PREMINE.keySet();
assertThat(defaultKeySet.equals(keySet)).isEqualTo(true);
}
use of org.aion.mcf.core.AccountState in project aion by aionnetwork.
the class GenesisSpecificationTest method overrideGenesisBlockTest.
/**
* Test that the genesis block can be overrode by certain configuration
* options that correspond to the options provided by
* {@link AionGenesis.Builder}
*/
@Test
public void overrideGenesisBlockTest() {
AionGenesis.Builder genesisBuilder = new AionGenesis.Builder();
// values to override defaults with
byte[] overrideHash = ByteUtil.hexStringToBytes("DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF");
byte[] overrideAddress = ByteUtil.hexStringToBytes("DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF");
BigInteger overrideValue = BigInteger.valueOf(1337);
AccountState defaultAccountState = new AccountState(overrideValue, overrideValue);
HashSet<Address> accountStateSet = new HashSet<>();
accountStateSet.add(Address.wrap(overrideHash));
genesisBuilder.withParentHash(overrideHash).withCoinbase(Address.wrap(overrideAddress)).withDifficulty(overrideValue.toByteArray()).withEnergyLimit(overrideValue.longValue()).withExtraData(overrideHash).withNonce(overrideHash).withNumber(overrideValue.longValue()).withTimestamp(overrideValue.longValue()).addPreminedAccount(Address.wrap(overrideAddress), defaultAccountState);
AionGenesis genesis = genesisBuilder.build();
assertThat(genesis.getParentHash()).isEqualTo(overrideHash);
assertThat(genesis.getCoinbase().toBytes()).isEqualTo(overrideAddress);
assertThat(genesis.getDifficulty()).isEqualTo(overrideValue.toByteArray());
assertThat(genesis.getDifficultyBI()).isEqualTo(overrideValue);
assertThat(genesis.getTimestamp()).isEqualTo(overrideValue.longValue());
assertThat(genesis.getNrgConsumed()).isEqualTo(0);
assertThat(genesis.getNrgLimit()).isEqualTo(overrideValue.longValue());
assertThat(genesis.getTxTrieRoot()).isEqualTo(HashUtil.EMPTY_TRIE_HASH);
assertThat(genesis.getReceiptsRoot()).isEqualTo(HashUtil.EMPTY_TRIE_HASH);
assertThat(genesis.getCumulativeDifficulty()).isEqualTo(overrideValue);
assertThat(genesis.getTransactionsList().isEmpty()).isEqualTo(true);
assertThat(genesis.getPremine().keySet().equals(accountStateSet));
}
use of org.aion.mcf.core.AccountState in project aion by aionnetwork.
the class AionImpl method getAccountState.
@Override
public Optional<AccountState> getAccountState(Address address) {
try {
byte[] stateRoot = this.aionHub.getBlockchain().getBestBlock().getStateRoot();
AccountState account = (AccountState) this.aionHub.getRepository().getSnapshotTo(stateRoot).getAccountState(address);
if (account == null)
return Optional.empty();
return Optional.of(account);
} catch (Exception e) {
LOG.debug("query request failed", e);
return Optional.empty();
}
}
use of org.aion.mcf.core.AccountState in project aion by aionnetwork.
the class AionRepositoryDummy method createAccount.
public AccountState createAccount(Address addr) {
AccountState accountState = new AccountState();
worldState.put(addr.toByteArrayWrapper(), accountState);
IContractDetails<DataWord> contractDetails = this.cfg.contractDetailsImpl();
detailsDB.put(addr.toByteArrayWrapper(), contractDetails);
return accountState;
}
Aggregations