Skip to content

Commit 68f4ac7

Browse files
committed
Add new GRPC API endpoints for PLT related queries
1 parent 6a4dac7 commit 68f4ac7

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

deps/concordium-base

packages/sdk/src/grpc/GRPCClient.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import * as GRPCKernel from '../grpc-api/v2/concordium/kernel.js';
1818
import { RawModuleSchema } from '../schemaTypes.js';
1919
import { serializeAccountTransactionPayload } from '../serialization.js';
2020
import * as SDK from '../types.js';
21+
import * as PLT from '../plt/types.js';
2122
import { HexString, isRpcError } from '../types.js';
2223
import * as AccountAddress from '../types/AccountAddress.js';
2324
import * as BlockHash from '../types/BlockHash.js';
@@ -1508,6 +1509,40 @@ export class ConcordiumGRPCClient {
15081509
return { isHealthy: false, message: (e as RpcError).message };
15091510
}
15101511
}
1512+
1513+
// TODO: add example snippet
1514+
/**
1515+
* Get information about a protocol level token (PLT) at a certain block.
1516+
* This endpoint is only supported for protocol version 9 and onwards.
1517+
*
1518+
* @param tokenId the ID of the token to query information about
1519+
* @param blockHash an optional block hash to get the info from, otherwise retrieves from last finalized block.
1520+
* @returns {PLT.TokenInfo} information about the corresponding token.
1521+
*/
1522+
async getTokenInfo(tokenId: PLT.TokenId.Type, blockHash?: BlockHash.Type): Promise<PLT.TokenInfo> {
1523+
const blockHashInput = getBlockHashInput(blockHash);
1524+
const req: GRPC.TokenInfoRequest = {
1525+
tokenId: PLT.TokenId.toProto(tokenId),
1526+
blockHash: blockHashInput,
1527+
}
1528+
const res = await this.client.getTokenInfo(req);
1529+
return translate.trTokenInfo(res.response);
1530+
}
1531+
1532+
// TODO: add example snippet
1533+
/**
1534+
* Get all token IDs currently registered at a block.
1535+
* This endpoint is only supported for protocol version 9 and onwards.
1536+
*
1537+
* @param blockHash optional block hash, otherwise retrieves from last finalized block.
1538+
*
1539+
* @returns All token IDs registered at a block
1540+
*/
1541+
getTokenList(blockHash?: BlockHash.Type): AsyncIterable<PLT.TokenId.Type> {
1542+
const blockHashInput = getBlockHashInput(blockHash);
1543+
const tokenIds = this.client.getTokenList(blockHashInput).responses;
1544+
return mapStream(tokenIds, PLT.TokenId.fromProto);
1545+
}
15111546
}
15121547

15131548
/**

packages/sdk/src/grpc/translation.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,6 +2637,20 @@ export function winningBaker(winningBaker: GRPC.WinningBaker): SDK.WinningBaker
26372637
};
26382638
}
26392639

2640+
export function trTokenInfo(tokenInfo: GRPC.TokenInfo): PLT.TokenInfo {
2641+
const state: PLT.TokenState = {
2642+
decimals: unwrap(tokenInfo.tokenState?.nrOfDecimals),
2643+
issuer: AccountAddress.fromProto(unwrap(tokenInfo.tokenState?.issuer)),
2644+
moduleRef: PLT.TokenModuleReference.fromProto(unwrap(tokenInfo.tokenState?.tokenModuleRef)),
2645+
totalSupply: PLT.TokenAmount.fromProto(unwrap(tokenInfo.tokenState?.totalSupply)),
2646+
moduleState: PLT.TokenModuleState.fromProto(unwrap(tokenInfo.tokenState?.moduleState)),
2647+
};
2648+
return {
2649+
id: PLT.TokenId.fromProto(unwrap(tokenInfo.tokenId)),
2650+
state,
2651+
};
2652+
}
2653+
26402654
// ---------------------------- //
26412655
// --- V1 => V2 translation --- //
26422656
// ---------------------------- //

0 commit comments

Comments
 (0)