Skip to content

Commit

Permalink
Merge pull request #280 from Concordium/fix-type-module-list
Browse files Browse the repository at this point in the history
Use ModuleReference in GetModuleList
  • Loading branch information
limemloh authored Oct 6, 2023
2 parents a04323c + 1a35f73 commit 9eff2ce
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions examples/client/getModuleList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseEndpoint } from '../shared/util.js';
import { BlockHash, HexString } from '@concordium/web-sdk';
import { BlockHash, ModuleReference } from '@concordium/web-sdk';
import { ConcordiumGRPCNodeClient } from '@concordium/web-sdk/nodejs';
import { credentials } from '@grpc/grpc-js';

Expand Down Expand Up @@ -54,12 +54,12 @@ const client = new ConcordiumGRPCNodeClient(
cli.flags.block === undefined
? undefined
: BlockHash.fromHexString(cli.flags.block);
const moduleRefs: AsyncIterable<HexString> =
const moduleRefs: AsyncIterable<ModuleReference.Type> =
client.getModuleList(blockHash);
// #endregion documentation-snippet

// Prints module references
for await (const moduleRef of moduleRefs) {
console.log(moduleRef);
console.log(ModuleReference.toHexString(moduleRef));
}
})();
10 changes: 5 additions & 5 deletions packages/sdk/src/grpc/GRPCClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ export class ConcordiumGRPCClient {
*
* @param blockHash an optional block hash to get the accounts at, otherwise retrieves from last finalized block.
* @param abortSignal an optional AbortSignal to close the stream.
* @returns an async iterable of account addresses represented as Base58 encoded strings.
* @returns an async iterable of account addresses.
*/
getAccountList(
blockHash?: BlockHash.Type,
Expand All @@ -692,16 +692,16 @@ export class ConcordiumGRPCClient {
*
* @param blockHash an optional block hash to get the contract modules at, otherwise retrieves from last finalized block.
* @param abortSignal an optional AbortSignal to close the stream.
* @returns an async iterable of contract module references, represented as hex strings.
* @returns an async iterable of contract module references.
*/
getModuleList(
blockHash?: BlockHash.Type,
abortSignal?: AbortSignal
): AsyncIterable<HexString> {
): AsyncIterable<ModuleReference.Type> {
const opts = { abort: abortSignal };
const hash = getBlockHashInput(blockHash);
const asyncIter = this.client.getModuleList(hash, opts).responses;
return mapStream(asyncIter, translate.unwrapValToHex);
return mapStream(asyncIter, ModuleReference.fromProto);
}

/**
Expand All @@ -714,7 +714,7 @@ export class ConcordiumGRPCClient {
* @param maxAmountOfAncestors the maximum amount of ancestors as a bigint.
* @param blockHash a optional block hash to get the ancestors at, otherwise retrieves from last finalized block.
* @param abortSignal an optional AbortSignal to close the stream.
* @returns an async iterable of ancestors' block hashes as hex strings.
* @returns an async iterable of ancestors' block hashes.
*/
getAncestors(
maxAmountOfAncestors: bigint,
Expand Down
9 changes: 9 additions & 0 deletions packages/sdk/src/types/ModuleReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ export function fromHexString(moduleRef: HexString) {
);
}

/**
* Get the module reference bytes encoded as hex.
* @param {ModuleReference} moduleReference The module reference.
* @returns {HexString} String with hex encoding.
*/
export function toHexString(moduleReference: ModuleReference): HexString {
return moduleReference.moduleRef;
}

/**
* Convert module reference from its protobuf encoding.
* @param {Proto.ModuleRef} moduleReference The module reference in protobuf.
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/test/client/resources/expectedJsons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ export const accountList: AccountAddress.Type[] = [
'4EJJ1hVhbVZT2sR9xPzWUwFcJWK3fPX54z94zskTozFVk8Xd4L',
].map(AccountAddress.fromBase58);

export const moduleList = [
export const moduleList: ModuleReference.Type[] = [
'67d568433bd72e4326241f262213d77f446db8ba03dfba351ae35c1b2e7e5109',
'6f0524700ed808a8fe0d7e23014c5138e4fac1fd8ec85c5e3591096f48609206',
'ceb018e4cd3456c0ccc0bca14285a69fd55f4cb09c322195d49c5c22f85930fe',
];
].map(ModuleReference.fromHexString);

export const ancestorList: BlockHash.Type[] = [
'fe88ff35454079c3df11d8ae13d5777babd61f28be58494efe51b6593e30716e',
Expand Down

0 comments on commit 9eff2ce

Please sign in to comment.