File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Slice } from '@ton/core'
2+
3+ const CHANGE_NUMBER_NOTIFICATION_EVENT_CODE = 0x5c690c2f
4+
5+
6+
7+ const hexToString = ( hexString : string ) : string => {
8+ const hex = hexString . toString ( )
9+ let resultString = ''
10+ for ( let i = 0 ; i < hex . length ; i += 2 ) {
11+ resultString += String . fromCharCode ( parseInt ( hex . slice ( i , i + 2 ) , 16 ) )
12+ }
13+ return resultString
14+ }
15+
16+ export const extractEventFromMessage = ( message : Slice ) : { event : number } | { error : string } => {
17+ const operationCode = message . loadUint ( 32 )
18+ let event = 0
19+
20+ if ( operationCode === CHANGE_NUMBER_NOTIFICATION_EVENT_CODE ) {
21+ const eventString = hexToString ( message . loadUintBig ( 13 * 8 ) . toString ( 16 ) ! )
22+ if ( eventString === 'ChangedNumber' ) {
23+ event = message . loadUint ( 8 )
24+ } else {
25+ return { error : 'Unsupported slice format' }
26+ }
27+ }
28+ return { event }
29+ }
You can’t perform that action at this time.
0 commit comments