Package org.ethereum.core

Examples of org.ethereum.core.AccountState


    // 1) print account address
    ret = "Account: " + Hex.toHexString(account) + "\n";
   
    //2) print state
        Repository repository = UIEthereumManager.ethereum.getRepository();
    AccountState state = repository.getAccountState(account);
    if(state != null)
      ret += state.toString() + "\n";
   
    //3) print storage
    ContractDetails contractDetails = repository.getContractDetails(account);
    if(contractDetails != null) {
      Map<DataWord, DataWord> accountStorage = contractDetails.getStorage();
View Full Code Here


  public void test1() {

    String addr = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826";
        Repository repository = worldManager.getRepository();

        AccountState createdState = repository.createAccount(Hex.decode(addr));
        AccountState fetchedState = repository.getAccountState(Hex.decode(addr));
        assertEquals(createdState.getEncoded(), fetchedState.getEncoded());
  }
View Full Code Here

        byte[] code0 = repository.getCode(Hex.decode(addr));
        repository.createAccount(Hex.decode(addr));
        repository.saveCode(Hex.decode(addr), Hex.decode(codeString));
        byte[] code1 = repository.getCode(Hex.decode(addr));
        AccountState accountState = repository.getAccountState(Hex.decode(addr));

        assertTrue(code0 == null);
        assertEquals(codeString, Hex.toHexString(code1));
        assertEquals(codeHash, Hex.toHexString(accountState.getCodeHash()));
    }
View Full Code Here

        Repository repository = worldManager.getRepository();

        byte[] code0 = repository.getCode(addr);
        repository.createAccount(addr);
        byte[] code1 = repository.getCode(addr);
        AccountState accountState = repository.getAccountState(addr);
        assertTrue(code0 == null);
        assertNull(code1);
        assertArrayEquals(EMPTY_DATA_HASH, accountState.getCodeHash());
    }
View Full Code Here

        DataWord fetchedValue1 = repository.getStorageValue(addr, key1);
        DataWord fetchedValue2 = repository.getStorageValue(addr, key2);
        DataWord fetchedValue3 = repository.getStorageValue(addr, key3);

        AccountState accountState = repository.getAccountState(addr);
        String stateRoot = Hex.toHexString(accountState.getStateRoot());

        assertEquals(value1, fetchedValue1);
        assertEquals(value2, fetchedValue2);
        assertEquals(value3, fetchedValue3);
        assertEquals(expectedStorageHash, stateRoot);
View Full Code Here

        byte[] contractAddrB = Hex.decode(contractAddr);
        byte[] callerAddrB = Hex.decode(callerAddr);
        byte[] codeB = Hex.decode(code);

        byte[] codeKey = HashUtil.sha3(codeB);
        AccountState accountState = new AccountState();
        accountState.setCodeHash(codeKey);

        ProgramInvokeMockImpl pi =  new ProgramInvokeMockImpl();
        pi.setOwnerAddress(contractAddrB);
        Repository repository = pi.getRepository();
View Full Code Here

        DBIterator i = repository.getAccountsIterator();
        while(i.hasNext()) {
          DataClass dc = new DataClass();
          dc.address = i.next().getKey();
         
          AccountState state = repository.getAccountState(dc.address);
          dc.accountState = state;
         
          adapter.addDataPiece(dc);
        }
      }
View Full Code Here

  public void testGetEncoded() {
    String expected = "f85e809"
        + "a0100000000000000000000000000000000000000000000000000"
        + "a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
        + "a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470";
    AccountState acct = new AccountState(BigInteger.ZERO, BigInteger.valueOf(2).pow(200));
    assertEquals(expected, Hex.toHexString(acct.getEncoded()));
  }
View Full Code Here

        String expected = "6ae5f47b0cc54ca33b4a46537f6cf6673f9138e876f3ac5a33dde173efe28236";

        // Get and update sender in world state
        byte[] cowAddress = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");
        byte[] rlpEncodedState = trie.get(cowAddress);
        AccountState account_1 = new AccountState(rlpEncodedState);
        account_1.addToBalance(new BigInteger("-6260000000001000"));
        account_1.incrementNonce();
        trie.update(cowAddress, account_1.getEncoded());

        // Add contract to world state
        byte[] codeData = Hex.decode("61778e600054");
        AccountState account_2 = new AccountState(BigInteger.ZERO, BigInteger.valueOf(1000));
        account_2.setCodeHash(HashUtil.sha3(codeData));
        byte[] contractAddress = Hex.decode("77045e71a7a2c50903d88e564cd72fab11e82051"); // generated based on sender + nonce
        trie.update(contractAddress, account_2.getEncoded());

//        this is saved in the db
//        trie.update(HashUtil.sha3(codeData), codeData);

        // Update miner in world state
        byte[] minerAddress = Hex.decode("4c5f4d519dff3c16f0d54b6866e256fbbbc1a600");
        AccountState account_3 = new AccountState(BigInteger.ZERO, new BigInteger("1506260000000000000"));
        trie.update(minerAddress, account_3.getEncoded());
       
        assertEquals(expected,  Hex.toHexString(trie.getRootHash()));


        /* *** GROSS DATA ***
 
View Full Code Here

    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

TOP

Related Classes of org.ethereum.core.AccountState

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.