Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move getKeys to storage #301

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions assembly/std/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ export * from './coins';
* @module Context
*/
export * from './context';

/**
* @module Storage
*/
export * from './storage';
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);
}
Loading