File tree 2 files changed +18
-1
lines changed
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ export class Cell {
34
34
}
35
35
36
36
/**
37
- * Helper class that deserializes a single cell from BOC in base64
37
+ * Helper function that deserializes a single cell from BOC in base64
38
38
* @param src source string
39
39
*/
40
40
static fromBase64 ( src : string ) : Cell {
@@ -45,6 +45,18 @@ export class Cell {
45
45
return parsed [ 0 ] ;
46
46
}
47
47
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
+
48
60
// Public properties
49
61
readonly type : CellType ;
50
62
readonly bits : BitString ;
Original file line number Diff line number Diff line change @@ -241,5 +241,10 @@ describe('boc', () => {
241
241
expect ( cell . toString ( ) ) . toBe ( 'x{000000E4}\n x{00000539}\n x{0000053A}' ) ;
242
242
expect ( serialized ) . toBe ( 'b5ee9c7281010301001400080e140208000000e4010200080000053900080000053a' ) ;
243
243
} ) ;
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
+ } ) ;
244
249
} ) ;
245
250
You can’t perform that action at this time.
0 commit comments