From b9b14791e1b19c200a4597a2bab7b89031b4abb2 Mon Sep 17 00:00:00 2001 From: utf Date: Sat, 30 Dec 2023 12:15:49 +0100 Subject: [PATCH] refactor(client): make {decode,format}Address() be static methods of Client --- src/Client.js | 10 ++++++++++ src/index.js | 11 ----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Client.js b/src/Client.js index afd60ba..00f5e12 100644 --- a/src/Client.js +++ b/src/Client.js @@ -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 diff --git a/src/index.js b/src/index.js index def7557..51e37f8 100644 --- a/src/index.js +++ b/src/index.js @@ -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 }