refactor(client): make {decode,format}Address() be static methods of Client
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user