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);
}
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);
}
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;
}
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_);
}
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);
}
Aggregations