org.ethereum.trie.TrieImpl Java Examples

The following examples show how to use org.ethereum.trie.TrieImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Block.java    From ethereumj with MIT License 6 votes vote down vote up
private void parseTxs(byte[] expectedRoot, RLPList txReceipts) {

        this.txsState = new TrieImpl(null);
        for (int i = 0; i < txReceipts.size(); i++) {
        	RLPElement rlpTxReceipt = txReceipts.get(i);
            RLPElement txData = ((RLPList)rlpTxReceipt).get(0);
            
            // YP 4.3.1
            RLPElement pstTxState = ((RLPList)rlpTxReceipt).get(1);
            RLPElement cummGas    = ((RLPList)rlpTxReceipt).get(2);

            Transaction tx = new Transaction(txData.getRLPData());
            this.transactionsList.add(tx);
            TransactionReceipt txReceipt =
                new TransactionReceipt(tx, pstTxState.getRLPData(), cummGas.getRLPData());
            this.addTxReceipt(i, txReceipt);
        }
        String calculatedRoot = Hex.toHexString(txsState.getRootHash());
        if(!calculatedRoot.equals(Hex.toHexString(expectedRoot)))
			logger.error("Added tx receipts don't match the given txsStateRoot");
    }
 
Example #2
Source File: RepositoryRoot.java    From nuls-v2 with MIT License 5 votes vote down vote up
@Override
protected synchronized StorageCache create(byte[] key, StorageCache srcCache) {
    AccountState accountState = accountStateCache.get(key);
    Serializer<byte[], byte[]> keyCompositor = new NodeKeyCompositor(key);
    Source<byte[], byte[]> composingSrc = new SourceCodec.KeyOnly<>(trieCache, keyCompositor);
    TrieImpl storageTrie = createTrie(composingSrc, accountState == null ? null : accountState.getStateRoot());
    return new StorageCache(storageTrie);
}
 
Example #3
Source File: RepositoryRoot.java    From nuls with MIT License 5 votes vote down vote up
@Override
protected synchronized StorageCache create(byte[] key, StorageCache srcCache) {
    AccountState accountState = accountStateCache.get(key);
    Serializer<byte[], byte[]> keyCompositor = new NodeKeyCompositor(key);
    Source<byte[], byte[]> composingSrc = new SourceCodec.KeyOnly<>(trieCache, keyCompositor);
    TrieImpl storageTrie = createTrie(composingSrc, accountState == null ? null : accountState.getStateRoot());
    return new StorageCache(storageTrie);
}
 
Example #4
Source File: RepositoryImpl.java    From ethereumj with MIT License 5 votes vote down vote up
public RepositoryImpl(String blockChainDbName, String detailsDbName, String stateDbName) {
	chainDB 			= new DatabaseImpl(blockChainDbName);
    detailsDB     		= new DatabaseImpl(detailsDbName);
    contractDetailsDB 	= new TrackDatabase(detailsDB);
    stateDB 			= new DatabaseImpl(stateDbName);
    worldState 			= new TrieImpl(stateDB.getDb());
    accountStateDB 		= new TrackTrie(worldState);
}
 
Example #5
Source File: ContractDetails.java    From ethereumj with MIT License 5 votes vote down vote up
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()));
        }
        return storageTrie.getRootHash();
    }
 
Example #6
Source File: Genesis.java    From ethereumj with MIT License 5 votes vote down vote up
private Genesis() {
super(PARENT_HASH, UNCLES_HASH, COINBASE, 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 premine, 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();
	acctState.addToBalance(PREMINE_AMOUNT);
	state.update(Hex.decode(address), acctState.getEncoded());
      }
setStateRoot(state.getRootHash());
  }
 
Example #7
Source File: StateTest.java    From ethereumj with MIT License 5 votes vote down vote up
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;
    }
 
Example #8
Source File: RepositoryRoot.java    From nuls-v2 with MIT License 4 votes vote down vote up
@Override
public synchronized String dumpStateTrie() {
    return ((TrieImpl) stateTrie).dumpTrie();
}
 
Example #9
Source File: RepositoryRoot.java    From nuls-v2 with MIT License 4 votes vote down vote up
protected TrieImpl createTrie(Source<byte[], byte[]> trieCache, byte[] root) {
    return new SecureTrie(trieCache, root);
}
 
Example #10
Source File: RepositoryRoot.java    From nuls with MIT License 4 votes vote down vote up
@Override
public synchronized String dumpStateTrie() {
    return ((TrieImpl) stateTrie).dumpTrie();
}
 
Example #11
Source File: RepositoryRoot.java    From nuls with MIT License 4 votes vote down vote up
protected TrieImpl createTrie(Source<byte[], byte[]> trieCache, byte[] root) {
    return new SecureTrie(trieCache, root);
}
 
Example #12
Source File: StateTest.java    From ethereumj with MIT License 4 votes vote down vote up
@Test  // right way to calc tx trie hash
public void testCalculatePostTxState() {

    /*    txTrieHash */
    String expected = "a77691cf47bec9021d3f027fc8ef2d51b758b600a79967154354b8e37108896f";
    Transaction tx = new Transaction(
            new byte[]{},
            Hex.decode("09184E72A000"),
            Hex.decode("03E8"),
            Hex.decode("0000000000000000000000000000000000000000"),
            Hex.decode("03e8"),
            Hex.decode("60016000546006601160003960066000f261778e600054")
    );
    byte[] cowPrivKey = Hex.decode("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4");
    tx.sign(cowPrivKey);

    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);

    /* *** GROSS DATA ***

    BlockData [
      hash=22cf863ab836a6f5c29389d2e77f4792a3b3b52908c98ed14b1cbe91491a3e36
      parentHash=77ef4fdaf389dca53236bcf7f72698e154eab2828f86fbc4fc6cd9225d285c89
      unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347
      coinbase=4c5f4d519dff3c16f0d54b6866e256fbbbc1a600
      stateHash=69c21ff84a5af0b53b11c61110a16d6ad43dad37b3eb29ae8e88c936eb06456a
      txTrieHash=a77691cf47bec9021d3f027fc8ef2d51b758b600a79967154354b8e37108896f
      difficulty=3ff000
      number=1
      minGasPrice=10000000000000
      gasLimit=999023
      gasUsed=626
      timestamp=1401979976 (2014.06.05 15:52:56)
      extraData=null
      nonce=0000000000000000000000000000000000000000000000005d439960040e4505

    TransactionReceipt[
       TransactionData [ hash=1ee6fa3149a5e9c09b54009eb6e108aaa7ecd79483d57eedcf2dff93a1505588  nonce=null,
           gasPrice=09184e72a000, gas=03e8, receiveAddress=0000000000000000000000000000000000000000, value=03e8,
           data=60016000546006601160003960066000f261778e600054, signatureV=27,
           signatureR=2b379f22050e3554c3fa5423d9040bb28dcc7f905300db4e67c03bcf9b27003c,
           signatureS=59f47793e050974e6b5fca2848b19925637b883a012693b54d712f1c4f74def5
      ]
      , postTxState=7fa5bd00f6e03b5a5718560f1e25179b227167585a3c3da06a48f554365fb527
      , cumulativeGas=0272]
    ]

    +++  4c5f4d519dff3c16f0d54b6866e256fbbbc1a600:
    +++  77045e71a7a2c50903d88e564cd72fab11e82051: $[61,77,8e,60,0,54] ([])
     *   cd2a3d9f938e13cd947ec05abc7fe734df8dd826: #1 1606938044258990275541962092341162602522202987522792835300376 (-6260000000001000)
      */
}