コード例 #1
0
  @Override
  public void put(DataWord key, DataWord value) {

    if (value.equals(DataWord.ZERO)) {
      storage.remove(key);
    } else {

      storage.put(key, value);
    }

    this.setDirty(true);
  }
コード例 #2
0
  @Override
  public byte[] getStorageHash() {

    SecureTrie storageTrie = new SecureTrie(null);

    for (DataWord key : storage.keySet()) {

      DataWord value = storage.get(key);

      storageTrie.update(key.getData(), RLP.encodeElement(value.getNoLeadZeroesData()));
    }

    return storageTrie.getRootHash();
  }
コード例 #3
0
  @Override
  public DataWord get(DataWord key) {

    DataWord value = storage.get(key);
    if (value != null) value = value.clone();
    return value;
  }
コード例 #4
0
  @Override
  public void setStorage(List<DataWord> storageKeys, List<DataWord> storageValues) {

    for (int i = 0; i < storageKeys.size(); ++i) {

      DataWord key = storageKeys.get(i);
      DataWord value = storageKeys.get(i);

      storage.put(key, value);
    }
  }
コード例 #5
0
  @Override
  public byte[] getEncoded() {

    byte[][] keys = new byte[storage.size()][];
    byte[][] values = new byte[storage.size()][];

    int i = 0;
    for (DataWord key : storage.keySet()) {

      DataWord value = storage.get(key);

      keys[i] = RLP.encodeElement(key.getData());
      values[i] = RLP.encodeElement(value.getNoLeadZeroesData());

      ++i;
    }

    byte[] rlpKeysList = RLP.encodeList(keys);
    byte[] rlpValuesList = RLP.encodeList(values);
    byte[] rlpCode = RLP.encodeElement(code);

    return RLP.encodeList(rlpKeysList, rlpValuesList, rlpCode);
  }
コード例 #6
0
  @Override
  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 = rlpList.get(2);

    for (int i = 0; i < keys.size(); ++i) {

      RLPItem key = (RLPItem) keys.get(i);
      RLPItem value = (RLPItem) values.get(i);

      storage.put(new DataWord(key.getRLPData()), new DataWord(value.getRLPData()));
    }

    this.code = (code.getRLPData() == null) ? ByteUtil.EMPTY_BYTE_ARRAY : code.getRLPData();
  }