示例#1
0
  @Test
  public void testAdd2() {
    byte[] two = new byte[32];
    two[31] = (byte) 0xff; // 0x000000000000000000000000000000000000000000000000000000000000ff

    DataWord x = new DataWord(two);
    x.add(new DataWord(two));
    System.out.println(Hex.toHexString(x.getData()));

    DataWord y = new DataWord(two);
    y.add2(new DataWord(two));
    System.out.println(Hex.toHexString(y.getData()));
  }
示例#2
0
  @Test
  public void testMul() {
    byte[] one = new byte[32];
    one[31] = 0x1; // 0x0000000000000000000000000000000000000000000000000000000000000001

    byte[] two = new byte[32];
    two[11] = 0x1; // 0x0000000000000000000000010000000000000000000000000000000000000000

    DataWord x = new DataWord(one); // System.out.println(x.value());
    DataWord y = new DataWord(two); // System.out.println(y.value());
    x.mul(y);
    assertEquals(32, y.getData().length);
    assertEquals(
        "0000000000000000000000010000000000000000000000000000000000000000",
        Hex.toHexString(y.getData()));
  }
示例#3
0
  @Test
  public void testAdd3() {
    byte[] three = new byte[32];
    for (int i = 0; i < three.length; i++) {
      three[i] = (byte) 0xff;
    }

    DataWord x = new DataWord(three);
    x.add(new DataWord(three));
    assertEquals(32, x.getData().length);
    System.out.println(Hex.toHexString(x.getData()));

    // FAIL
    //		DataWord y = new DataWord(three);
    //		y.add2(new DataWord(three));
    //		System.out.println(Hex.toHexString(y.getData()));
  }
示例#4
0
  @Test
  public void testMod() {
    String expected = "000000000000000000000000000000000000000000000000000000000000001a";

    byte[] one = new byte[32];
    one[31] = 0x1e; // 0x000000000000000000000000000000000000000000000000000000000000001e

    byte[] two = new byte[32];
    for (int i = 0; i < two.length; i++) {
      two[i] = (byte) 0xff;
    }
    two[31] = 0x56; // 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff56

    DataWord x = new DataWord(one); // System.out.println(x.value());
    DataWord y = new DataWord(two); // System.out.println(y.value());
    y.mod(x);
    assertEquals(32, y.getData().length);
    assertEquals(expected, Hex.toHexString(y.getData()));
  }
  @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();
  }
  @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);
  }
 @Override
 public byte[] getStorageSlot(byte[] slot) {
   DataWord ret =
       getBlockchain().getRepository().getContractDetails(contractAddr).get(new DataWord(slot));
   return ret.getData();
 }