Skip to content

Commit

Permalink
move getKeys to storage
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjah committed Oct 3, 2023
1 parent 07f82a1 commit 8ff7070
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
32 changes: 0 additions & 32 deletions assembly/std/op-datastore/op-datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,6 @@
import { env } from '../../env';
import { derKeys } from './util';

/**
* Retrieves all the keys from the operation datastore.
*
* @param prefix - the serialized prefix to filter the keys (optional)
*
* @returns - a list of keys (e.g. a list of byte array)
*
*/
export function getKeys(
prefix: StaticArray<u8> = new StaticArray<u8>(0),
): Array<StaticArray<u8>> {
let keysSer = env.getKeys(prefix);
return derKeys(keysSer);
}

/**
* Retrieves all the keys from the operation datastore from a remote address.
*
* @param address - the address in the datastore
* @param prefix - the prefix to filter the keys (optional)
*
* @returns - a list of key (e.g. a list of byte array)
*
*/
export function getKeysOf(
address: string,
prefix: StaticArray<u8> = new StaticArray<u8>(0),
): Array<StaticArray<u8>> {
let keysSer = env.getKeysOf(address, prefix);
return derKeys(keysSer);
}

/**
* Checks if a given serialized 'key' is present in the operation datastore.
*
Expand Down
33 changes: 33 additions & 0 deletions assembly/std/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import { env } from '../env';
import { Address } from './address';
import { Args, bytesToString, stringToBytes } from '@massalabs/as-types';
import { derKeys } from './op-datastore';

/**
* Converts the given value to a StaticArray<u8> to match the expected format for datastore operations.
Expand Down Expand Up @@ -313,3 +314,35 @@ export function has<T>(key: T): bool {
export function hasOf<T>(address: Address, key: T): bool {
return env.hasOf(address.toString(), toDatastoreFormat(key));
}

/**
* Retrieves all the keys from the datastore.
*
* @param prefix - the serialized prefix to filter the keys (optional)
*
* @returns - a list of keys (e.g. a list of byte array)
*
*/
export function getKeys(
prefix: StaticArray<u8> = new StaticArray<u8>(0),
): Array<StaticArray<u8>> {
let keysSer = env.getKeys(prefix);
return derKeys(keysSer);
}

/**
* Retrieves all the keys from the datastore from a remote address.
*
* @param address - the address in the datastore
* @param prefix - the prefix to filter the keys (optional)
*
* @returns - a list of key (e.g. a list of byte array)
*
*/
export function getKeysOf(
address: string,
prefix: StaticArray<u8> = new StaticArray<u8>(0),
): Array<StaticArray<u8>> {
let keysSer = env.getKeysOf(address, prefix);
return derKeys(keysSer);
}

0 comments on commit 8ff7070

Please sign in to comment.