Search in sources :

Example 21 with ByteArrayWrapper

use of org.ethereum.db.ByteArrayWrapper in project rskj by rsksmart.

the class RLPTest method testEncodeSet_1.

@Test
public void testEncodeSet_1() {
    Set<ByteArrayWrapper> data = new HashSet<>();
    ByteArrayWrapper element1 = new ByteArrayWrapper(Hex.decode("1111111111111111111111111111111111111111111111111111111111111111"));
    ByteArrayWrapper element2 = new ByteArrayWrapper(Hex.decode("2222222222222222222222222222222222222222222222222222222222222222"));
    data.add(element1);
    data.add(element2);
    byte[] setEncoded = encodeSet(data);
    RLPList list = (RLPList) decode2(setEncoded).get(0);
    byte[] element1_ = list.get(0).getRLPData();
    byte[] element2_ = list.get(1).getRLPData();
    assertTrue(data.contains(wrap(element1_)));
    assertTrue(data.contains(wrap(element2_)));
}
Also used : ByteArrayWrapper(org.ethereum.db.ByteArrayWrapper) Test(org.junit.Test)

Example 22 with ByteArrayWrapper

use of org.ethereum.db.ByteArrayWrapper in project rskj by rsksmart.

the class ContractDetailsImpl method getStorage.

@Override
public synchronized Map<DataWord, DataWord> getStorage(@Nullable Collection<DataWord> keys) {
    Map<DataWord, DataWord> storage = new HashMap<>();
    if (keys == null) {
        for (ByteArrayWrapper keyBytes : this.keys) {
            DataWord key = new DataWord(keyBytes);
            DataWord value = get(key);
            // cause we keep all historical keys
            if (value != null) {
                storage.put(key, value);
            }
        }
    } else {
        for (DataWord key : keys) {
            DataWord value = get(key);
            // cause we keep all historical keys
            if (value != null) {
                storage.put(key, value);
            }
        }
    }
    return storage;
}
Also used : ByteArrayWrapper(org.ethereum.db.ByteArrayWrapper) DataWord(org.ethereum.vm.DataWord)

Example 23 with ByteArrayWrapper

use of org.ethereum.db.ByteArrayWrapper in project nuls by nuls-io.

the class RLP method encodeSet.

public static byte[] encodeSet(Set<ByteArrayWrapper> data) {
    int dataLength = 0;
    Set<byte[]> encodedElements = new HashSet<>();
    for (ByteArrayWrapper element : data) {
        byte[] encodedElement = RLP.encodeElement(element.getData());
        dataLength += encodedElement.length;
        encodedElements.add(encodedElement);
    }
    byte[] listHeader = encodeListHeader(dataLength);
    byte[] output = new byte[listHeader.length + dataLength];
    System.arraycopy(listHeader, 0, output, 0, listHeader.length);
    int cummStart = listHeader.length;
    for (byte[] element : encodedElements) {
        System.arraycopy(element, 0, output, cummStart, element.length);
        cummStart += element.length;
    }
    return output;
}
Also used : ByteArrayWrapper(org.ethereum.db.ByteArrayWrapper)

Aggregations

ByteArrayWrapper (org.ethereum.db.ByteArrayWrapper)23 Test (org.junit.Test)5 Metric (co.rsk.metrics.profilers.Metric)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 DataWord (org.ethereum.vm.DataWord)2 File (java.io.File)1 BigInteger (java.math.BigInteger)1 Path (java.nio.file.Path)1 DigestOutputStream (java.security.DigestOutputStream)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 MapSnapshot (org.ethereum.util.MapSnapshot)1