Package org.ethereum.core

Examples of org.ethereum.core.AccountState


      blockNode.put("prevhash", "0x" + Hex.toHexString(block.getParentHash()));
       
        ObjectNode statesNode = blockNode.objectNode();
        for (ByteArrayWrapper key : keys) {
            byte[] keyBytes = key.getData();
            AccountState    accountState    = repository.getAccountState(keyBytes);
            ContractDetails details  = repository.getContractDetails(keyBytes);
            JSONHelper.dumpState(statesNode, Hex.toHexString(keyBytes), accountState, details);
        }      
        blockNode.put("state", statesNode);
       
View Full Code Here


        logger.trace("createAccount: [{}]", Hex.toHexString(addr)) ;
      this.validateAddress(addr);
           
        // 1. Save AccountState
        AccountState state =  new AccountState();
        accountStateDB.update(addr, state.getEncoded());
       
        ContractDetails details = new ContractDetails();
        contractDetailsDB.put(addr, details.getEncoded());
       
        if (logger.isDebugEnabled())
View Full Code Here

            logger.debug("Found account state RLP: [{}]", Hex.toHexString(accountStateRLP));

        if (accountStateRLP == null || accountStateRLP.length == 0)
            return null;

        AccountState state =  new AccountState(accountStateRLP);
        return state;
    }
View Full Code Here

    return details;
  }

  public BigInteger addBalance(byte[] addr, BigInteger value) {
     
    AccountState state = getAccountState(addr);

        if (state == null)
            state = createAccount(addr);
       
    BigInteger newBalance = state.addToBalance(value);

    if (logger.isDebugEnabled())
      logger.debug("Changing balance: \n account:\t [{}]\n new balance:\t [{}]\n delta:\t\t [{}]",
          Hex.toHexString(addr), newBalance.toString(), value);

    accountStateDB.update(addr, state.getEncoded());
    return newBalance;
  }
View Full Code Here

    accountStateDB.update(addr, state.getEncoded());
    return newBalance;
  }

    public BigInteger getBalance(byte[] addr) {
        AccountState state = getAccountState(addr);
        if (state == null) return BigInteger.ZERO;
        return state.getBalance();
    }
View Full Code Here

        if (state == null) return BigInteger.ZERO;
        return state.getBalance();
    }

    public BigInteger getNonce(byte[] addr) {
        AccountState state = getAccountState(addr);
        if (state == null) return BigInteger.ZERO;
        return state.getNonce();
    }
View Full Code Here

        if (state == null) return BigInteger.ZERO;
        return state.getNonce();
    }

    public BigInteger increaseNonce(byte[] addr) {
        AccountState state = getAccountState(addr);
        if (state == null) return BigInteger.ZERO;
        state.incrementNonce();

        if (logger.isDebugEnabled())
            logger.debug("Increment nonce:\n account:\t [{}]\n new nonce:\t [{}]",
                    Hex.toHexString(addr), state.getNonce().longValue());

        accountStateDB.update(addr, state.getEncoded());
        return state.getNonce();
    }
View Full Code Here

    }

  public void addStorageRow(byte[] addr, DataWord key, DataWord value) {

        if (key == null) return;
        AccountState      state = getAccountState(addr);
        ContractDetails   details = getContractDetails(addr);

        if (state == null || details == null) return;
        details.put(key, value);

        byte[] storageHash = details.getStorageHash();
        state.setStateRoot(storageHash);

        if (logger.isDebugEnabled())
            logger.debug("Storage key/value saved:\n account:\t [{}]\n key:\t\t [{}]\n value:\t\t [{}]\n new hash:\t [{}]",
                    Hex.toHexString(addr),
                    Hex.toHexString(key.getNoLeadZeroesData()),
                    Hex.toHexString(value.getNoLeadZeroesData()),
                    Hex.toHexString(storageHash));

        accountStateDB.update(addr, state.getEncoded());
        contractDetailsDB.put(addr, details.getEncoded());
    }
View Full Code Here

    public DataWord getStorageValue(byte[] addr, DataWord key) {

        if (key == null) return null;

        AccountState state = getAccountState(addr);
        if (state == null) return null;

        ContractDetails details = getContractDetails(addr);
        DataWord value = details.get(key);
View Full Code Here

    }

    public void saveCode(byte[] addr, byte[] code) {
     
      if (code == null) return;
        AccountState state = getAccountState(addr);
        if (state == null) return;
       
        if (logger.isDebugEnabled())
            logger.debug("Saving code: \n address:\t [{}], \n code:\t\t [{}]",
                    Hex.toHexString(addr),
                    Hex.toHexString(code));

        ContractDetails details = getContractDetails(addr);
        details.setCode(code);

        byte[] codeHash = HashUtil.sha3(code);
        state.setCodeHash(codeHash);

        accountStateDB.update(addr, state.getEncoded());
        contractDetailsDB.put(addr, details.getEncoded());
       
        if (logger.isDebugEnabled())
            logger.debug("Code saved: \n accountstate:\t [{}]\n codeHash:\t [{}]\n details RLP:\t [{}]",
                    Hex.toHexString(state.getEncoded()),
                    Hex.toHexString(codeHash),
                    Hex.toHexString(details.getEncoded()));
    }
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.