Skip to content

Commit f6e28ae

Browse files
committed
feat: added support for versioned blockId validation
Ticket: COIN-6858
1 parent baa03cd commit f6e28ae

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

modules/sdk-coin-canton/src/lib/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ export class Utils implements BaseUtils {
2525
/** @inheritdoc */
2626
isValidBlockId(hash: string): boolean {
2727
// In canton, there is no block hash, we store the height as the _id (hash)
28-
const blockHeight = Number(hash);
28+
// this will be of the form, <blockHeight>_<version>
29+
const [height] = hash.split('_');
30+
const blockHeight = Number(height);
2931
return !isNaN(blockHeight) && blockHeight > 0;
3032
}
3133

modules/sdk-coin-canton/test/resources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export const CANTON_ADDRESSES = {
100100

101101
export const CANTON_BLOCK_HEIGHT = {
102102
VALID_HASH: '123456',
103+
VALID_HASH_WITH_VERSION: '123456_5.1.0',
103104
INVALID_BLOCK_HASH: 'xyz',
104105
NEGATIVE_BLOCK_HASH: '-100',
105106
};

modules/sdk-coin-canton/test/unit/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ describe('Canton Util', function () {
162162
assert.strictEqual(isValid, true);
163163
});
164164

165+
it('should return true when the block hash has version', function () {
166+
const isValid = utils.isValidBlockId(CANTON_BLOCK_HEIGHT.VALID_HASH_WITH_VERSION);
167+
should.exist(isValid);
168+
assert.strictEqual(isValid, true);
169+
});
170+
165171
it('should return false when the block hash is not a number', function () {
166172
const isValid = utils.isValidBlockId(CANTON_BLOCK_HEIGHT.INVALID_BLOCK_HASH);
167173
should.exist(isValid);

0 commit comments

Comments
 (0)