Search in sources :

Example 1 with SecureTrie

use of org.aion.mcf.trie.SecureTrie in project aion by aionnetwork.

the class TrieTestWithRootHashValues method testSecureTrie.

@Test
public void testSecureTrie() {
    Trie trie = new SecureTrie(mockDb);
    byte[] k1 = "do".getBytes();
    byte[] v1 = "verb".getBytes();
    byte[] k2 = "ether".getBytes();
    byte[] v2 = "wookiedoo".getBytes();
    byte[] k3 = "horse".getBytes();
    byte[] v3 = "stallion".getBytes();
    byte[] k4 = "shaman".getBytes();
    byte[] v4 = "horse".getBytes();
    byte[] k5 = "doge".getBytes();
    byte[] v5 = "coin".getBytes();
    byte[] k6 = "ether".getBytes();
    byte[] v6 = "".getBytes();
    byte[] k7 = "dog".getBytes();
    byte[] v7 = "puppy".getBytes();
    byte[] k8 = "shaman".getBytes();
    byte[] v8 = "".getBytes();
    trie.update(k1, v1);
    trie.update(k2, v2);
    trie.update(k3, v3);
    trie.update(k4, v4);
    trie.update(k5, v5);
    trie.update(k6, v6);
    trie.update(k7, v7);
    trie.update(k8, v8);
    byte[] root = trie.getRootHash();
    System.out.println("root: " + Hex.toHexString(root));
    Assert.assertEquals("29b235a58c3c25ab83010c327d5932bcf05324b7d6b1185e650798034783ca9d", Hex.toHexString(root));
}
Also used : Trie(org.aion.mcf.trie.Trie) SecureTrie(org.aion.mcf.trie.SecureTrie) SecureTrie(org.aion.mcf.trie.SecureTrie) Test(org.junit.Test)

Example 2 with SecureTrie

use of org.aion.mcf.trie.SecureTrie in project aion by aionnetwork.

the class ContractDetailsCacheImpl method getStorageHash.

@Override
public byte[] getStorageHash() {
    // todo: unsupported
    SecureTrie storageTrie = new SecureTrie(null);
    for (DataWord key : storage.keySet()) {
        DataWord value = storage.get(key);
        storageTrie.update(key.getData(), RLP.encodeElement(value.getNoLeadZeroesData()));
    }
    return storageTrie.getRootHash();
}
Also used : DataWord(org.aion.mcf.vm.types.DataWord) SecureTrie(org.aion.mcf.trie.SecureTrie)

Example 3 with SecureTrie

use of org.aion.mcf.trie.SecureTrie in project aion by aionnetwork.

the class AionContractDetailsImpl method getSnapshotTo.

@Override
public IContractDetails<DataWord> getSnapshotTo(byte[] hash) {
    IByteArrayKeyValueStore keyValueDataSource = this.storageTrie.getCache().getDb();
    SecureTrie snapStorage = wrap(hash).equals(wrap(EMPTY_TRIE_HASH)) ? new SecureTrie(keyValueDataSource, "".getBytes()) : new SecureTrie(keyValueDataSource, hash);
    snapStorage.withPruningEnabled(storageTrie.isPruningEnabled());
    snapStorage.setCache(this.storageTrie.getCache());
    AionContractDetailsImpl details = new AionContractDetailsImpl(this.address, snapStorage, getCodes());
    details.externalStorage = this.externalStorage;
    details.externalStorageDataSource = this.externalStorageDataSource;
    details.keys = this.keys;
    details.dataSource = dataSource;
    return details;
}
Also used : SecureTrie(org.aion.mcf.trie.SecureTrie) IByteArrayKeyValueStore(org.aion.base.db.IByteArrayKeyValueStore)

Aggregations

SecureTrie (org.aion.mcf.trie.SecureTrie)3 IByteArrayKeyValueStore (org.aion.base.db.IByteArrayKeyValueStore)1 Trie (org.aion.mcf.trie.Trie)1 DataWord (org.aion.mcf.vm.types.DataWord)1 Test (org.junit.Test)1