use of co.rsk.trie.Trie in project rskj by rsksmart.
the class TrieImplHashTest method sonWithSiblingAndOnlyOneGrandsonShouldBringSameHashBaseCase.
@Test
public void sonWithSiblingAndOnlyOneGrandsonShouldBringSameHashBaseCase() {
Trie trie1 = new TrieImpl().put("roosevalt", "4243".getBytes()).put("rooseval_", "424344".getBytes()).put("roosevaltroosevalt", "42434445".getBytes()).delete("roosevalt");
Trie trie2 = new TrieImpl().put("rooseval_", "424344".getBytes()).put("roosevaltroosevalt", "42434445".getBytes());
Assert.assertTrue(Arrays.equals(trie1.get("rooseval_"), "424344".getBytes()));
Assert.assertTrue(Arrays.equals(trie1.get("roosevaltroosevalt"), "42434445".getBytes()));
Assert.assertNull(trie1.get("roosevalt"));
Assert.assertEquals(trie1.getHash(), trie2.getHash());
}
use of co.rsk.trie.Trie in project rskj by rsksmart.
the class FreeBlock method getTxTrie.
public static Trie getTxTrie(List<Transaction> transactions) {
if (transactions == null) {
return new TrieImpl();
}
Trie txsState = new TrieImpl();
for (int i = 0; i < transactions.size(); i++) {
Transaction transaction = transactions.get(i);
txsState = txsState.put(RLP.encodeInt(i), transaction.getEncoded());
}
return txsState;
}
use of co.rsk.trie.Trie in project rskj by rsksmart.
the class DoPrune method processBlocks.
public void processBlocks(long from, TrieImpl sourceTrie, RskAddress contractAddress, TrieStore targetStore) {
long n = from;
if (n <= 0) {
n = 1;
}
while (true) {
List<Block> blocks = this.blockchain.getBlocksByNumber(n);
if (blocks.isEmpty()) {
break;
}
for (Block b : blocks) {
byte[] stateRoot = b.getStateRoot();
logger.info("Block height {} State root {}", b.getNumber(), Hex.toHexString(stateRoot));
Repository repo = this.blockchain.getRepository();
repo.syncToRoot(stateRoot);
logger.info("Repo root {}", Hex.toHexString(repo.getRoot()));
AccountState accountState = repo.getAccountState(contractAddress);
Keccak256 trieRoot = new Keccak256(accountState.getStateRoot());
logger.info("Trie root {}", trieRoot);
Trie contractStorage = sourceTrie.getSnapshotTo(trieRoot);
contractStorage.copyTo(targetStore);
logger.info("Trie root {}", contractStorage.getHash());
}
n++;
}
}
use of co.rsk.trie.Trie in project rskj by rsksmart.
the class Block method getTxTrie.
public static Trie getTxTrie(List<Transaction> transactions) {
if (transactions == null) {
return new TrieImpl();
}
Trie txsState = new TrieImpl();
for (int i = 0; i < transactions.size(); i++) {
Transaction transaction = transactions.get(i);
txsState = txsState.put(RLP.encodeInt(i), transaction.getEncoded());
}
return txsState;
}
use of co.rsk.trie.Trie in project rskj by rsksmart.
the class ContractDetailsCacheImpl method getStorageHash.
@Override
public byte[] getStorageHash() {
// todo: unsupported
Trie storageTrie = new TrieImpl(null, true);
for (DataWord key : storage.keySet()) {
DataWord value = storage.get(key);
storageTrie = storageTrie.put(key.getData(), RLP.encodeElement(value.getNoLeadZeroesData()));
}
for (DataWord key : bytesStorage.keySet()) {
byte[] value = bytesStorage.get(key);
storageTrie = storageTrie.put(key.getData(), RLP.encodeElement(value));
}
return storageTrie.getHash().getBytes();
}
Aggregations