Search in sources :

Example 1 with ContractDetailsImpl

use of co.rsk.db.ContractDetailsImpl in project rskj by rsksmart.

the class AccountBuilder method build.

public static StateWrap build(AccountTck account) {
    ContractDetailsImpl details = new ContractDetailsImpl(new RskSystemProperties());
    details.setCode(parseData(account.getCode()));
    details.setStorage(convertStorage(account.getStorage()));
    AccountState state = new AccountState();
    state.addToBalance(new Coin(unifiedNumericToBigInteger(account.getBalance())));
    state.setNonce(unifiedNumericToBigInteger(account.getNonce()));
    state.setStateRoot(details.getStorageHash());
    state.setCodeHash(HashUtil.keccak256(details.getCode()));
    return new StateWrap(state, details);
}
Also used : Coin(co.rsk.core.Coin) ContractDetailsImpl(co.rsk.db.ContractDetailsImpl) AccountState(org.ethereum.core.AccountState) RskSystemProperties(co.rsk.config.RskSystemProperties)

Example 2 with ContractDetailsImpl

use of co.rsk.db.ContractDetailsImpl in project rskj by rsksmart.

the class DetailsDataStoreTest method test1.

@Test
public void test1() {
    DatabaseImpl db = new DatabaseImpl(new HashMapDB());
    DetailsDataStore dds = new DetailsDataStore(config, db);
    RskAddress c_key = new RskAddress("0000000000000000000000000000000000001a2b");
    byte[] code = Hex.decode("60606060");
    byte[] key = Hex.decode("11");
    byte[] value = Hex.decode("aa");
    ContractDetails contractDetails = new ContractDetailsImpl(config);
    contractDetails.setAddress(randomAddress().getBytes());
    contractDetails.setCode(code);
    contractDetails.put(new DataWord(key), new DataWord(value));
    dds.update(c_key, contractDetails);
    ContractDetails contractDetails_ = dds.get(c_key);
    String encoded1 = Hex.toHexString(contractDetails.getEncoded());
    String encoded2 = Hex.toHexString(contractDetails_.getEncoded());
    assertEquals(encoded1, encoded2);
    dds.flush();
    contractDetails_ = dds.get(c_key);
    encoded2 = Hex.toHexString(contractDetails_.getEncoded());
    assertEquals(encoded1, encoded2);
}
Also used : ContractDetailsImpl(co.rsk.db.ContractDetailsImpl) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 3 with ContractDetailsImpl

use of co.rsk.db.ContractDetailsImpl in project rskj by rsksmart.

the class ContractDetailsMapper method mapFromContract.

public ContractDetails mapFromContract(Contract contract) {
    ContractDetails contractDetails;
    contractDetails = new ContractDetailsImpl(config);
    if (contract.getCode() != null) {
        contractDetails.setCode(Hex.decode(contract.getCode()));
    }
    for (String key : contract.getData().keySet()) {
        String value = contract.getData().get(key);
        contractDetails.putBytes(new DataWord(Hex.decode(key)), Hex.decode(value));
    }
    return contractDetails;
}
Also used : ContractDetailsImpl(co.rsk.db.ContractDetailsImpl) DataWord(org.ethereum.vm.DataWord) ContractDetails(org.ethereum.db.ContractDetails)

Example 4 with ContractDetailsImpl

use of co.rsk.db.ContractDetailsImpl in project rskj by rsksmart.

the class DetailsDataStoreTest method test2.

@Test
public void test2() {
    DatabaseImpl db = new DatabaseImpl(new HashMapDB());
    DetailsDataStore dds = new DetailsDataStore(config, db);
    RskAddress c_key = new RskAddress("0000000000000000000000000000000000001a2b");
    byte[] code = Hex.decode("60606060");
    byte[] key = Hex.decode("11");
    byte[] value = Hex.decode("aa");
    ContractDetails contractDetails = new ContractDetailsImpl(config);
    contractDetails.setCode(code);
    contractDetails.setAddress(randomAddress().getBytes());
    contractDetails.put(new DataWord(key), new DataWord(value));
    dds.update(c_key, contractDetails);
    ContractDetails contractDetails_ = dds.get(c_key);
    String encoded1 = Hex.toHexString(contractDetails.getEncoded());
    String encoded2 = Hex.toHexString(contractDetails_.getEncoded());
    assertEquals(encoded1, encoded2);
    dds.remove(c_key);
    contractDetails_ = dds.get(c_key);
    assertNull(contractDetails_);
    dds.flush();
    contractDetails_ = dds.get(c_key);
    assertNull(contractDetails_);
}
Also used : ContractDetailsImpl(co.rsk.db.ContractDetailsImpl) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Example 5 with ContractDetailsImpl

use of co.rsk.db.ContractDetailsImpl in project rskj by rsksmart.

the class DetailsDataStoreTest method test3.

@Test
public void test3() {
    DatabaseImpl db = new DatabaseImpl(new HashMapDB());
    DetailsDataStore dds = new DetailsDataStore(config, db);
    RskAddress c_key = new RskAddress("0000000000000000000000000000000000001a2b");
    byte[] code = Hex.decode("60606060");
    byte[] key = Hex.decode("11");
    byte[] value = Hex.decode("aa");
    ContractDetails contractDetails = new ContractDetailsImpl(config);
    contractDetails.setCode(code);
    contractDetails.put(new DataWord(key), new DataWord(value));
    dds.update(c_key, contractDetails);
    ContractDetails contractDetails_ = dds.get(c_key);
    String encoded1 = Hex.toHexString(contractDetails.getEncoded());
    String encoded2 = Hex.toHexString(contractDetails_.getEncoded());
    assertEquals(encoded1, encoded2);
    dds.remove(c_key);
    dds.update(c_key, contractDetails);
    contractDetails_ = dds.get(c_key);
    encoded2 = Hex.toHexString(contractDetails_.getEncoded());
    assertEquals(encoded1, encoded2);
    dds.flush();
    contractDetails_ = dds.get(c_key);
    encoded2 = Hex.toHexString(contractDetails_.getEncoded());
    assertEquals(encoded1, encoded2);
}
Also used : ContractDetailsImpl(co.rsk.db.ContractDetailsImpl) RskAddress(co.rsk.core.RskAddress) DataWord(org.ethereum.vm.DataWord) HashMapDB(org.ethereum.datasource.HashMapDB) Test(org.junit.Test)

Aggregations

ContractDetailsImpl (co.rsk.db.ContractDetailsImpl)5 DataWord (org.ethereum.vm.DataWord)4 RskAddress (co.rsk.core.RskAddress)3 HashMapDB (org.ethereum.datasource.HashMapDB)3 Test (org.junit.Test)3 RskSystemProperties (co.rsk.config.RskSystemProperties)1 Coin (co.rsk.core.Coin)1 AccountState (org.ethereum.core.AccountState)1 ContractDetails (org.ethereum.db.ContractDetails)1