Package org.ethereum.trie

Examples of org.ethereum.trie.TrieImpl$ScanAction


   
    public RepositoryImpl(String detailsDbName, String stateDbName) {
        detailsDB         = new DatabaseImpl(detailsDbName);
        contractDetailsDB   = new TrackDatabase(detailsDB);
        stateDB       = new DatabaseImpl(stateDbName);
        worldState       = new TrieImpl(stateDB.getDb());
        accountStateDB     = new TrackTrie(worldState);
    }
View Full Code Here


    public void reset(){
        close();
        detailsDB         = new DatabaseImpl("details");
        contractDetailsDB   = new TrackDatabase(detailsDB);
        stateDB       = new DatabaseImpl("state");
        worldState       = new TrieImpl(stateDB.getDb());
        accountStateDB     = new TrackTrie(worldState);
    }
View Full Code Here

  private Genesis() {
    super(PARENT_HASH, UNCLES_HASH, COINBASE, LOG_BLOOM, DIFFICULTY,
        NUMBER, MIN_GAS_PRICE, GAS_LIMIT, GAS_USED, TIMESTAMP,
        EXTRA_DATA, NONCE, null, null);
   
    Trie state = new TrieImpl(null);
        // The proof-of-concept series include a development pre-mine, making the state root hash
        // some value stateRoot. The latest documentation should be consulted for the value of the state root.
    for (String address : premine) {
      AccountState acctState = new AccountState(BigInteger.ZERO, PREMINE_AMOUNT);
      state.update(Hex.decode(address), acctState.getEncoded());
        }

    setStateRoot(state.getRootHash());
    }
View Full Code Here

        this.rlpEncoded = null;
    }

    public byte[] getStorageHash() {

      storageTrie = new TrieImpl(null);
        // calc the trie for root hash
        for (int i = 0; i < storageKeys.size(); ++i){
      storageTrie.update(storageKeys.get(i).getData(), RLP
          .encodeElement(storageValues.get(i).getNoLeadZeroesData()));
        }
View Full Code Here

    }


    private void parseTxs(byte[] expectedRoot, RLPList txTransactions) {

        this.txsState = new TrieImpl(null);
        for (int i = 0; i < txTransactions.size(); i++) {
          RLPElement transactionRaw = txTransactions.get(i);
            this.transactionsList.add(new Transaction(transactionRaw.getRLPData()));
            this.txsState.update(RLP.encodeInt(i) , transactionRaw.getRLPData());
        }
View Full Code Here

        byte[] postTxState = Hex.decode("7fa5bd00f6e03b5a5718560f1e25179b227167585a3c3da06a48f554365fb527");
        byte[] cumGas      = Hex.decode("0272");

        TransactionReceipt tr = new TransactionReceipt(tx, postTxState, cumGas);

        Trie trie = new TrieImpl(new MockDB());
        trie.update(RLP.encodeInt(0), tr.getEncoded());
        String txTrieRoot = Hex.toHexString(trie.getRootHash());
        assertEquals(expected, txTrieRoot);
    }
View Full Code Here


    @Test
    public void testRollbackTrie() throws URISyntaxException, IOException {

        TrieImpl trieSingle = new TrieImpl(mockDb);

        URL massiveUpload_1 = ClassLoader
                .getSystemResource("trie/massive-upload.dmp");

        File file = new File(massiveUpload_1.toURI());
        List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);

        List<byte[]> roots = new ArrayList<>();
        Map<String, String> trieDumps = new HashMap<>();

        for (int i = 0; i < 100; ++i){

            String[] keyVal= strData.get(i).split("=");

            if (keyVal[0].equals("*"))
                trieSingle.delete(keyVal[1].trim());
            else
                trieSingle.update(keyVal[0].trim(), keyVal[1].trim());

            byte[] hash = trieSingle.getRootHash();
            roots.add(hash);

            String key =  Hex.toHexString(hash);
            String dump = trieSingle.getTrieDump();
            trieDumps.put(key, dump);
        }

        // compare all 100 rollback dumps and
        // the originaly saved dumps
        for (int i = 1; i < roots.size(); ++i){

            byte[] root = roots.get(i);
            logger.info("rollback over root : {}", Hex.toHexString(root) );

            trieSingle.setRoot(root);
            String currDump = trieSingle.getTrieDump();
            String originDump = trieDumps.get(Hex.toHexString(root));
//            System.out.println(currDump);
            Assert.assertEquals(currDump, originDump);
        }

View Full Code Here

        assertEquals(expected, Hex.toHexString(trie.getRootHash()));
    }

    private Trie generateGenesisState() {

        Trie trie = new TrieImpl(new MockDB());
        for (String address : Genesis.getPremine()) {
            AccountState acct = new AccountState(BigInteger.ZERO, BigInteger.valueOf(2).pow(200));
            trie.update(Hex.decode(address), acct.getEncoded());     
    }
        return trie;
    }
View Full Code Here

    }


    @Test
    public void testGetFromRootNode() {
        TrieImpl trie1 = new TrieImpl(mockDb);
        trie1.update(cat, LONG_STRING);
        trie1.sync();
        TrieImpl trie2 = new TrieImpl(mockDb, trie1.getRootHash());
        assertEquals(LONG_STRING, new String(trie2.get(cat)));
    }
View Full Code Here

        byte[] val1 = Hex.decode("947e70f9460402290a3e487dae01f610a1a8218fda");
        byte[] val2 = Hex.decode("40");
        byte[] val3 = Hex.decode("94412e0c4f0102f3f0ac63f0a125bce36ca75d4e0d");
        byte[] val4 = Hex.decode("01");

        TrieImpl storage = new TrieImpl(new MockDB());
        storage.update(key1, val1);
        storage.update(key2, val2);
        storage.update(key3, val3);
        storage.update(key4, val4);

        String hash = Hex.toHexString(storage.getRootHash());

        System.out.println(hash);
        Assert.assertEquals("517eaccda568f3fa24915fed8add49d3b743b3764c0bc495b19a47c54dbc3d62", hash);
    }
View Full Code Here

TOP

Related Classes of org.ethereum.trie.TrieImpl$ScanAction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.