Skip to content

Commit

Permalink
Fix solar
Browse files Browse the repository at this point in the history
  • Loading branch information
bokoto000 committed Nov 16, 2023
1 parent cb369d0 commit f1d4228
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ public RuntimePointerSize extDefaultChildStorageReadVersion1(RuntimePointerSize
int offset) {
byte[] childStorageKey = hostApi.getDataFromMemory(childStorageKeyPointer);
byte[] key = hostApi.getDataFromMemory(keyPointer);
String childStorageRepositoryKey = new String(Bytes.concat(childStorageKey, key));

byte[] value = (byte[]) repository.find(new String(Bytes.concat(childStorageKey, key))).orElse(null);
byte[] value = (byte[]) repository.find(childStorageRepositoryKey).orElse(null);

if (value == null) {
return hostApi.writeDataToMemory(scaleEncodedOption(null));
Expand Down Expand Up @@ -150,8 +151,9 @@ public void extDefaultChildStorageSetVersion1(RuntimePointerSize childStorageKey
byte[] childStorageKey = hostApi.getDataFromMemory(childStorageKeyPointer);
byte[] key = hostApi.getDataFromMemory(keyPointer);
byte[] value = hostApi.getDataFromMemory(valuePointer);
String childStorageRepositoryKey = new String(Bytes.concat(childStorageKey, key));

repository.save(new String(Bytes.concat(childStorageKey, key)), value);
repository.save(childStorageRepositoryKey, value);
}

/**
Expand All @@ -164,8 +166,9 @@ public void extDefaultChildStorageClearVersion1(RuntimePointerSize childStorageK
RuntimePointerSize keyPointer) {
byte[] childStorageKey = hostApi.getDataFromMemory(childStorageKeyPointer);
byte[] key = hostApi.getDataFromMemory(keyPointer);
String childStorageRepositoryKey = new String(Bytes.concat(childStorageKey, key));

repository.delete(new String(Bytes.concat(childStorageKey, key)));
repository.delete(childStorageRepositoryKey);
}

/**
Expand All @@ -178,8 +181,9 @@ public void extDefaultChildStorageClearPrefixVersion1(RuntimePointerSize childSt
RuntimePointerSize prefixPointer) {
byte[] childStorageKey = hostApi.getDataFromMemory(childStorageKeyPointer);
byte[] prefix = hostApi.getDataFromMemory(prefixPointer);
String childStorageRepositoryKey = new String(Bytes.concat(childStorageKey, prefix));

repository.deleteByPrefix(new String(Bytes.concat(childStorageKey, prefix)), null);
repository.deleteByPrefix(childStorageRepositoryKey, null);
}

/**
Expand All @@ -199,12 +203,13 @@ public RuntimePointerSize extDefaultChildStorageClearPrefixVersion2(RuntimePoint
RuntimePointerSize limitPointer) {
byte[] childStorageKey = hostApi.getDataFromMemory(childStorageKeyPointer);
byte[] prefix = hostApi.getDataFromMemory(prefixPointer);
String childStorageRepositoryKey = new String(Bytes.concat(childStorageKey, prefix));

byte[] limitBytes = hostApi.getDataFromMemory(limitPointer);
Long limit = new ScaleCodecReader(limitBytes).readOptional(ScaleCodecReader.UINT32).orElse(null);

DeleteByPrefixResult result =
repository.deleteByPrefix(new String(Bytes.concat(childStorageKey, prefix)), limit);
repository.deleteByPrefix(childStorageRepositoryKey, limit);

return hostApi.writeDataToMemory(result.scaleEncoded());
}
Expand All @@ -220,7 +225,8 @@ public int extDefaultChildStorageExistsVersion1(RuntimePointerSize childStorageK
RuntimePointerSize keyPointer) {
byte[] childStorageKey = hostApi.getDataFromMemory(childStorageKeyPointer);
byte[] key = hostApi.getDataFromMemory(keyPointer);
return repository.find(new String(Bytes.concat(childStorageKey, key))).isPresent() ? 1 : 0;
String childStorageRepositoryKey = new String(Bytes.concat(childStorageKey, key));
return repository.find(childStorageRepositoryKey).isPresent() ? 1 : 0;
}

/**
Expand All @@ -234,7 +240,9 @@ public RuntimePointerSize extDefaultChildStorageGetVersion1(RuntimePointerSize c
RuntimePointerSize keyPointer) {
byte[] childStorageKey = hostApi.getDataFromMemory(childStorageKeyPointer);
byte[] key = hostApi.getDataFromMemory(keyPointer);
byte[] value = (byte[]) repository.find(new String(Bytes.concat(childStorageKey, key))).orElse(null);
String childStorageRepositoryKey = new String(Bytes.concat(childStorageKey, key));
byte[] value = (byte[]) repository
.find(childStorageRepositoryKey).orElse(null);

return hostApi.writeDataToMemory(scaleEncodedOption(value));
}
Expand Down

0 comments on commit f1d4228

Please sign in to comment.