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_)));
}
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;
}
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;
}
Aggregations