Search in sources :

Example 1 with AccountState

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;
}
Also used : DataWord(org.aion.mcf.vm.types.DataWord) AccountState(org.aion.mcf.core.AccountState)

Example 2 with 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);
}
Also used : Address(org.aion.base.type.Address) BigInteger(java.math.BigInteger) AccountState(org.aion.mcf.core.AccountState) AionGenesis(org.aion.zero.impl.AionGenesis) Test(org.junit.Test)

Example 3 with AccountState

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));
}
Also used : Address(org.aion.base.type.Address) BigInteger(java.math.BigInteger) AccountState(org.aion.mcf.core.AccountState) AionGenesis(org.aion.zero.impl.AionGenesis) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with AccountState

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

Example 5 with AccountState

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;
}
Also used : DataWord(org.aion.mcf.vm.types.DataWord) AccountState(org.aion.mcf.core.AccountState)

Aggregations

AccountState (org.aion.mcf.core.AccountState)21 DataWord (org.aion.mcf.vm.types.DataWord)10 BigInteger (java.math.BigInteger)4 Address (org.aion.base.type.Address)4 ContractDetailsCacheImpl (org.aion.mcf.db.ContractDetailsCacheImpl)3 AionGenesis (org.aion.zero.impl.AionGenesis)2 Test (org.junit.Test)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 IContractDetails (org.aion.base.db.IContractDetails)1 ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1