refactor(client): make {decode,format}Address() be static methods of Client

This commit is contained in:
utf
2023-12-30 12:15:49 +01:00
parent ee6368e274
commit b9b14791e1
2 changed files with 10 additions and 11 deletions
+10
View File
@@ -10,10 +10,20 @@ import {
KeepAlive
} from './Protocol.js'
import { EventEmitter } from 'events'
import Long from 'long'
const WebSocket = (typeof window === 'undefined' ? import('ws'): window.WebSocket)
export class Client extends EventEmitter {
static formatAddress(address) {
const int = BigInt(address)
return int.toString(16).padStart(16, '0').match(/.{1,4}/g).join(':')
}
static decodeAddress(address) {
return Long.fromString(BigInt('0x' + address.replace(/:/g, '')).toString(10))
}
#gateway
#ws
#id
-11
View File
@@ -1,13 +1,2 @@
import Long from 'long'
import { Client } from './Client.js'
export function formatAddress(address) {
const int = BigInt(address)
return int.toString(16).padStart(16, '0').match(/.{1,4}/g).join(':')
}
export function decodeAddress(address) {
return Long.fromString(BigInt('0x' + address.replace(/:/g, '')).toString(10))
}
export { Client }