Skip to content

Instantly share code, notes, and snippets.

@dicarlo2
Created June 18, 2019 03:45
Show Gist options
  • Save dicarlo2/d9ec8592d453ec334a8fbd341a592772 to your computer and use it in GitHub Desktop.
Save dicarlo2/d9ec8592d453ec334a8fbd341a592772 to your computer and use it in GitHub Desktop.
const getStorageItemKeyMin = ({ hash, prefix }: StorageItemsKey): Buffer => {
if (hash === undefined || hash.length === 0) {
return bytewise.encode(bytewise.sorts.array.bound.lower([storageItemKeyPrefix]));
}
if (prefix === undefined || prefix.length === 0) {
return bytewise.encode(bytewise.sorts.array.bound.lower([storageItemKeyPrefix, common.uInt160ToBuffer(hash)]));
}
return bytewise.encode(
bytewise.sorts.array.bound.lower([
storageItemKeyPrefix,
common.uInt160ToBuffer(hash),
bytewise.sorts.binary.bound.lower(prefix),
]),
);
};
const getStorageItemKeyMax = ({ hash, prefix }: StorageItemsKey): Buffer => {
if (hash === undefined || hash.length === 0) {
return bytewise.encode(bytewise.sorts.array.bound.upper([storageItemKeyPrefix]));
}
if (prefix === undefined || prefix.length === 0) {
return bytewise.encode(bytewise.sorts.array.bound.upper([storageItemKeyPrefix, common.uInt160ToBuffer(hash)]));
}
return bytewise.encode(
bytewise.sorts.array.bound.upper([
storageItemKeyPrefix,
common.uInt160ToBuffer(hash),
bytewise.sorts.binary.bound.upper(prefix),
]),
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment