Package org.ethereum.util

Examples of org.ethereum.util.RLPList


    }
   
    public AccountState(byte[] rlpData) {
        this.rlpEncoded = rlpData;

    RLPList items   = (RLPList) RLP.decode2(rlpEncoded).get(0);
    this.nonce = items.get(0).getRLPData() == null ? BigInteger.ZERO
        : new BigInteger(1, items.get(0).getRLPData());
    this.balance = items.get(1).getRLPData() == null ? BigInteger.ZERO
        : new BigInteger(1, items.get(1).getRLPData());
    this.stateRoot   = items.get(2).getRLPData();
    this.codeHash   = items.get(3).getRLPData();
    }
View Full Code Here


        }
        return storageTrie.getRootHash();
    }

  public void decode(byte[] rlpCode) {
    RLPList data = RLP.decode2(rlpCode);
    RLPList rlpList = (RLPList) data.get(0);

    RLPList keys = (RLPList) rlpList.get(0);
    RLPList values = (RLPList) rlpList.get(1);
    RLPElement code = (RLPElement) rlpList.get(2);

    if (keys.size() > 0) {
      storageKeys = new ArrayList<>();
      storageValues = new ArrayList<>();
    }

    for (int i = 0; i < keys.size(); ++i) {
      RLPItem rlpItem = (RLPItem) keys.get(i);
      storageKeys.add(new DataWord(rlpItem.getRLPData()));
    }

    for (int i = 0; i < values.size(); ++i) {
      RLPItem rlpItem = (RLPItem) values.get(i);
      storageValues.add(new DataWord(rlpItem.getRLPData()));
    }

    for (int i = 0; i < keys.size(); ++i) {
      DataWord key = storageKeys.get(i);
View Full Code Here

     *            - raw RLP data
     * @return rlpList
     *            - outcome of recursive RLP structure
     */
    public static RLPList decode2(byte[] msgData) {
      RLPList rlpList = new RLPList();
        fullTraverse(msgData, 0, 0, msgData.length, 1, rlpList);
        return rlpList;
    }
View Full Code Here

          byte[] rlpData = new byte[lengthOfLength + length + 1];
          System.arraycopy(msgData, pos, rlpData, 0, lengthOfLength
              + length + 1);

          RLPList newLevelList = new RLPList();
          newLevelList.setRLPData(rlpData);

          fullTraverse(msgData, level + 1, pos + lengthOfLength + 1,
              pos + lengthOfLength + length + 1, levelToIndex,
              newLevelList);
          rlpList.add(newLevelList);

          pos += lengthOfLength + length + 1;
          continue;
        }
        // It's a list with a payload less than 55 bytes
        if ((msgData[pos] & 0xFF) >= OFFSET_SHORT_LIST
            && (msgData[pos] & 0xFF) <= OFFSET_LONG_LIST) {

          byte length = (byte) ((msgData[pos] & 0xFF) - OFFSET_SHORT_LIST);

          byte[] rlpData = new byte[length + 1];
          System.arraycopy(msgData, pos, rlpData, 0, length + 1);

          RLPList newLevelList = new RLPList();
          newLevelList.setRLPData(rlpData);

          if (length > 0)
            fullTraverse(msgData, level + 1, pos + 1, pos + length
                + 1, levelToIndex, newLevelList);
          rlpList.add(newLevelList);
View Full Code Here

        this.genesisHash = genesisHash;
        this.parsed = true;
    }

    private void parse() {
        RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

        this.protocolVersion  = ((RLPItem) paramsList.get(1)).getRLPData()[0];
        byte[] networkIdBytes  = ((RLPItem) paramsList.get(2)).getRLPData();
        this.networkId      = networkIdBytes == null ? 0 : networkIdBytes[0];
        this.totalDifficulty  = ((RLPItem) paramsList.get(3)).getRLPData();
        this.bestHash       = ((RLPItem) paramsList.get(4)).getRLPData();
        this.genesisHash     = ((RLPItem) paramsList.get(5)).getRLPData();

        parsed = true;
    }
View Full Code Here

    this.reason = reason;
    parsed = true;
  }

  private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

    byte[] reasonBytes = ((RLPItem) paramsList.get(1)).getRLPData();
    if (reasonBytes == null)
      this.reason = REQUESTED;
    else
      this.reason = ReasonCode.fromInt(reasonBytes[0]);
View Full Code Here

    this.peers = peers;
    parsed = true;
  }

  private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

    peers = new LinkedHashSet<>();
    for (int i = 1; i < paramsList.size(); ++i) {
      RLPList peerParams = (RLPList) paramsList.get(i);
      byte[] ipBytes = peerParams.get(0).getRLPData();
      byte[] portBytes = peerParams.get(1).getRLPData();
      byte[] peerIdRaw = peerParams.get(2).getRLPData();

      try {
        int peerPort = ByteUtil.byteArrayToInt(portBytes);
        InetAddress address = InetAddress.getByAddress(ipBytes);
View Full Code Here

    this.blockHashes = blockHashes;
    parsed = true;
  }

  private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

    blockHashes = new ArrayList<>();
    for (int i = 1; i < paramsList.size(); ++i) {
      blockHashes.add(((RLPItem) paramsList.get(i)).getRLPData());
    }
    parsed = true;
  }
View Full Code Here

        this.encoded = RLP.encodeList(command, block, diff);
        parsed = true;
    }

  private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

        RLPList blockRLP = ((RLPList) paramsList.get(1));
        block = new Block(blockRLP.getRLPData());
        difficulty =  paramsList.get(2).getRLPData();

        parsed = true;
  }
View Full Code Here

        this.transactions = transactionList;
        parsed = true;
    }
   
    private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

    transactions = new HashSet<>();
        for (int i = 1; i < paramsList.size(); ++i) {
            RLPList rlpTxData = (RLPList) paramsList.get(i);
            Transaction tx = new Transaction(rlpTxData.getRLPData());
            transactions.add(tx);
        }
        parsed = true;
    }
View Full Code Here

TOP

Related Classes of org.ethereum.util.RLPList

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.