Skip to content

Commit 68e1b7c

Browse files
committed
feat: Cell.fromHex
1 parent 8d6a6a0 commit 68e1b7c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/boc/Cell.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class Cell {
3434
}
3535

3636
/**
37-
* Helper class that deserializes a single cell from BOC in base64
37+
* Helper function that deserializes a single cell from BOC in base64
3838
* @param src source string
3939
*/
4040
static fromBase64(src: string): Cell {
@@ -45,6 +45,18 @@ export class Cell {
4545
return parsed[0];
4646
}
4747

48+
/**
49+
* Helper function that deserializes a single cell from BOC in hex
50+
* @param src source string
51+
*/
52+
static fromHex(src: string): Cell {
53+
let parsed = Cell.fromBoc(Buffer.from(src, 'hex'));
54+
if (parsed.length !== 1) {
55+
throw new Error("Deserialized more than one cell");
56+
}
57+
return parsed[0];
58+
}
59+
4860
// Public properties
4961
readonly type: CellType;
5062
readonly bits: BitString;

src/boc/cell/serialization.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,10 @@ describe('boc', () => {
241241
expect(cell.toString()).toBe('x{000000E4}\n x{00000539}\n x{0000053A}');
242242
expect(serialized).toBe('b5ee9c7281010301001400080e140208000000e4010200080000053900080000053a');
243243
});
244+
245+
it('should deserialize cell from hex', () => {
246+
let cell = Cell.fromHex('b5ee9c7241010201000d00010800000001010008000000027d4b3cf8');
247+
expect(cell.toString()).toBe('x{00000001}\n x{00000002}');
248+
});
244249
});
245250

0 commit comments

Comments
 (0)