@trezor/blockchain-link
Advanced tools
Comparing version 2.1.14 to 2.1.15
@@ -1,2 +0,2 @@ | ||
import { BaseWorker } from '../base'; | ||
import { BaseWorker } from '../baseWorker'; | ||
import { BlockbookAPI } from './websocket'; | ||
@@ -3,0 +3,0 @@ import type * as MessageTypes from '@trezor/blockchain-link-types/lib/messages'; |
@@ -28,3 +28,3 @@ "use strict"; | ||
const constants_1 = require("@trezor/blockchain-link-types/lib/constants"); | ||
const base_1 = require("../base"); | ||
const baseWorker_1 = require("../baseWorker"); | ||
const websocket_1 = require("./websocket"); | ||
@@ -372,3 +372,3 @@ const utils = __importStar(require("@trezor/blockchain-link-utils/lib/blockbook")); | ||
}; | ||
class BlockbookWorker extends base_1.BaseWorker { | ||
class BlockbookWorker extends baseWorker_1.BaseWorker { | ||
cleanup() { | ||
@@ -427,3 +427,3 @@ if (this.api) { | ||
exports.default = Blockbook; | ||
if (base_1.CONTEXT === 'worker') { | ||
if (baseWorker_1.CONTEXT === 'worker') { | ||
const module = new BlockbookWorker(); | ||
@@ -430,0 +430,0 @@ onmessage = module.messageHandler.bind(module); |
import WebSocket from 'ws'; | ||
import { Deferred } from '@trezor/utils/lib/createDeferred'; | ||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter'; | ||
import type { BlockNotification, MempoolTransactionNotification, AddressNotification, Send, FiatRatesNotification } from '@trezor/blockchain-link-types/lib/blockbook'; | ||
import type { GetFiatRatesForTimestamps, GetFiatRatesTickersList, GetCurrentFiatRates } from '@trezor/blockchain-link-types/lib/messages'; | ||
import type { AccountInfoParams, EstimateFeeParams, AccountBalanceHistoryParams } from '@trezor/blockchain-link-types/lib/params'; | ||
interface Subscription { | ||
id: string; | ||
type: 'notification' | 'block' | 'mempool' | 'fiatRates'; | ||
callback: (result: any) => void; | ||
} | ||
interface Options { | ||
url: string; | ||
timeout?: number; | ||
pingTimeout?: number; | ||
keepAlive?: boolean; | ||
agent?: WebSocket.ClientOptions['agent']; | ||
headers?: WebSocket.ClientOptions['headers']; | ||
} | ||
import { BaseWebsocket } from '../baseWebsocket'; | ||
interface BlockbookEvents { | ||
@@ -25,28 +11,7 @@ block: BlockNotification; | ||
fiatRates: FiatRatesNotification; | ||
error: string; | ||
disconnected: undefined; | ||
} | ||
export declare class BlockbookAPI extends TypedEmitter<BlockbookEvents> { | ||
options: Options; | ||
ws: WebSocket | undefined; | ||
messageID: number; | ||
messages: Deferred<any>[]; | ||
subscriptions: Subscription[]; | ||
pingTimeout: ReturnType<typeof setTimeout> | undefined; | ||
connectionTimeout: ReturnType<typeof setTimeout> | undefined; | ||
constructor(options: Options); | ||
setConnectionTimeout(): void; | ||
clearConnectionTimeout(): void; | ||
setPingTimeout(): void; | ||
private rejectAllPending; | ||
onTimeout(): void; | ||
onPing(): Promise<void>; | ||
onError(): void; | ||
export declare class BlockbookAPI extends BaseWebsocket<BlockbookEvents> { | ||
protected createWebsocket(): WebSocket; | ||
protected ping(): Promise<import("@trezor/blockchain-link-types/lib/blockbook-api").WsBlockHashRes>; | ||
send: Send; | ||
onmessage(message: string): void; | ||
private connectPromise; | ||
connect(): Promise<void>; | ||
init(): void; | ||
disconnect(): void; | ||
isConnected(): boolean; | ||
getServerInfo(): Promise<import("@trezor/blockchain-link-types/lib/blockbook-api").WsInfoRes>; | ||
@@ -65,3 +30,2 @@ getBlockHash(block: number): Promise<import("@trezor/blockchain-link-types/lib/blockbook-api").WsBlockHashRes>; | ||
getFiatRatesTickersList(payload: GetFiatRatesTickersList['payload']): Promise<import("@trezor/blockchain-link-types/lib/blockbook").AvailableCurrencies>; | ||
private removeSubscription; | ||
subscribeAddresses(addresses: string[]): Promise<import("@trezor/blockchain-link-types/lib/blockbook").Subscribe>; | ||
@@ -83,6 +47,4 @@ unsubscribeAddresses(): Promise<import("@trezor/blockchain-link-types/lib/blockbook").Subscribe> | { | ||
}; | ||
private onClose; | ||
dispose(): void; | ||
} | ||
export {}; | ||
//# sourceMappingURL=websocket.d.ts.map |
@@ -8,123 +8,10 @@ "use strict"; | ||
const ws_1 = __importDefault(require("ws")); | ||
const createDeferred_1 = require("@trezor/utils/lib/createDeferred"); | ||
const typedEventEmitter_1 = require("@trezor/utils/lib/typedEventEmitter"); | ||
const errors_1 = require("@trezor/blockchain-link-types/lib/constants/errors"); | ||
const DEFAULT_TIMEOUT = 20 * 1000; | ||
const DEFAULT_PING_TIMEOUT = 50 * 1000; | ||
class BlockbookAPI extends typedEventEmitter_1.TypedEmitter { | ||
constructor(options) { | ||
super(); | ||
this.messageID = 0; | ||
this.messages = []; | ||
this.subscriptions = []; | ||
this.send = (method, params = {}) => { | ||
const { ws } = this; | ||
if (!ws) | ||
throw new errors_1.CustomError('websocket_not_initialized'); | ||
const id = this.messageID.toString(); | ||
const dfd = (0, createDeferred_1.createDeferred)(id); | ||
const req = { | ||
id, | ||
method, | ||
params, | ||
}; | ||
this.messageID++; | ||
this.messages.push(dfd); | ||
this.setConnectionTimeout(); | ||
this.setPingTimeout(); | ||
ws.send(JSON.stringify(req)); | ||
return dfd.promise; | ||
}; | ||
this.options = options; | ||
const baseWebsocket_1 = require("../baseWebsocket"); | ||
class BlockbookAPI extends baseWebsocket_1.BaseWebsocket { | ||
constructor() { | ||
super(...arguments); | ||
this.send = (method, params = {}) => this.sendMessage({ method, params }); | ||
} | ||
setConnectionTimeout() { | ||
this.clearConnectionTimeout(); | ||
this.connectionTimeout = setTimeout(this.onTimeout.bind(this), this.options.timeout || DEFAULT_TIMEOUT); | ||
} | ||
clearConnectionTimeout() { | ||
if (this.connectionTimeout) { | ||
clearTimeout(this.connectionTimeout); | ||
this.connectionTimeout = undefined; | ||
} | ||
} | ||
setPingTimeout() { | ||
if (this.pingTimeout) { | ||
clearTimeout(this.pingTimeout); | ||
} | ||
this.pingTimeout = setTimeout(this.onPing.bind(this), this.options.pingTimeout || DEFAULT_PING_TIMEOUT); | ||
} | ||
rejectAllPending(code, message) { | ||
this.messages.forEach(m => m.reject(new errors_1.CustomError(code, message))); | ||
this.messages = []; | ||
} | ||
onTimeout() { | ||
const { ws } = this; | ||
if (!ws) | ||
return; | ||
if (ws.listenerCount('open') > 0) { | ||
ws.emit('error', new errors_1.CustomError('websocket_timeout')); | ||
try { | ||
ws.close(); | ||
} | ||
catch (error) { | ||
} | ||
} | ||
else { | ||
this.rejectAllPending('websocket_timeout'); | ||
ws.close(); | ||
} | ||
} | ||
async onPing() { | ||
if (this.ws && this.isConnected()) { | ||
try { | ||
if (this.subscriptions.length > 0 || this.options.keepAlive) { | ||
await this.getBlockHash(1); | ||
} | ||
else { | ||
this.ws.close(); | ||
} | ||
} | ||
catch (error) { | ||
} | ||
} | ||
} | ||
onError() { | ||
this.onClose(); | ||
} | ||
onmessage(message) { | ||
try { | ||
const resp = JSON.parse(message); | ||
const { id, data } = resp; | ||
const dfd = this.messages.find(m => m.id === id); | ||
if (dfd) { | ||
if (data.error) { | ||
dfd.reject(new errors_1.CustomError('websocket_error_message', data.error.message)); | ||
} | ||
else { | ||
dfd.resolve(data); | ||
} | ||
this.messages.splice(this.messages.indexOf(dfd), 1); | ||
} | ||
else { | ||
const subs = this.subscriptions.find(s => s && s.id === id); | ||
if (subs) { | ||
subs.callback(data); | ||
} | ||
} | ||
} | ||
catch (error) { | ||
} | ||
if (this.messages.length === 0) { | ||
this.clearConnectionTimeout(); | ||
} | ||
this.setPingTimeout(); | ||
} | ||
async connect() { | ||
var _a; | ||
if (this.connectPromise) { | ||
return this.connectPromise; | ||
} | ||
if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING) { | ||
await new Promise(resolve => this.once('disconnected', resolve)); | ||
} | ||
createWebsocket() { | ||
let { url } = this.options; | ||
@@ -134,5 +21,2 @@ if (typeof url !== 'string') { | ||
} | ||
if (url.startsWith('https')) { | ||
url = url.replace('https', 'wss'); | ||
} | ||
if (url.startsWith('http')) { | ||
@@ -145,44 +29,10 @@ url = url.replace('http', 'ws'); | ||
} | ||
this.setConnectionTimeout(); | ||
const dfd = (0, createDeferred_1.createDeferred)(-1); | ||
this.connectPromise = dfd.promise; | ||
const ws = new ws_1.default(url, { | ||
return new ws_1.default(url, { | ||
agent: this.options.agent, | ||
headers: Object.assign({ Origin: 'https://node.trezor.io', 'User-Agent': 'Trezor Suite' }, this.options.headers), | ||
}); | ||
ws.once('error', error => { | ||
this.onClose(); | ||
dfd.reject(new errors_1.CustomError('websocket_runtime_error', error.message)); | ||
}); | ||
ws.on('open', () => { | ||
this.init(); | ||
dfd.resolve(); | ||
}); | ||
this.ws = ws; | ||
return dfd.promise.finally(() => { | ||
this.connectPromise = undefined; | ||
}); | ||
} | ||
init() { | ||
const { ws } = this; | ||
if (!ws || !this.isConnected()) { | ||
throw Error('Blockbook websocket init cannot be called'); | ||
} | ||
this.clearConnectionTimeout(); | ||
ws.removeAllListeners(); | ||
ws.on('error', this.onError.bind(this)); | ||
ws.on('message', this.onmessage.bind(this)); | ||
ws.on('close', () => { | ||
this.onClose(); | ||
this.emit('disconnected'); | ||
}); | ||
ping() { | ||
return this.getBlockHash(1); | ||
} | ||
disconnect() { | ||
var _a; | ||
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.close(); | ||
} | ||
isConnected() { | ||
var _a; | ||
return ((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN; | ||
} | ||
getServerInfo() { | ||
@@ -227,19 +77,5 @@ return this.send('getInfo'); | ||
} | ||
removeSubscription(type) { | ||
const index = this.subscriptions.findIndex(s => s.type === type); | ||
if (index >= 0) { | ||
this.subscriptions.splice(index, 1); | ||
} | ||
return index; | ||
} | ||
subscribeAddresses(addresses) { | ||
this.removeSubscription('notification'); | ||
const id = this.messageID.toString(); | ||
this.subscriptions.push({ | ||
id, | ||
type: 'notification', | ||
callback: (result) => { | ||
this.emit('notification', result); | ||
}, | ||
}); | ||
this.addSubscription('notification', result => this.emit('notification', result)); | ||
return this.send('subscribeAddresses', { addresses }); | ||
@@ -249,17 +85,7 @@ } | ||
const index = this.removeSubscription('notification'); | ||
if (index >= 0) { | ||
return this.send('unsubscribeAddresses'); | ||
} | ||
return { subscribed: false }; | ||
return index >= 0 ? this.send('unsubscribeAddresses') : { subscribed: false }; | ||
} | ||
subscribeBlock() { | ||
this.removeSubscription('block'); | ||
const id = this.messageID.toString(); | ||
this.subscriptions.push({ | ||
id, | ||
type: 'block', | ||
callback: (result) => { | ||
this.emit('block', result); | ||
}, | ||
}); | ||
this.addSubscription('block', result => this.emit('block', result)); | ||
return this.send('subscribeNewBlock'); | ||
@@ -269,17 +95,7 @@ } | ||
const index = this.removeSubscription('block'); | ||
if (index >= 0) { | ||
return this.send('unsubscribeNewBlock'); | ||
} | ||
return { subscribed: false }; | ||
return index >= 0 ? this.send('unsubscribeNewBlock') : { subscribed: false }; | ||
} | ||
subscribeFiatRates(currency) { | ||
this.removeSubscription('fiatRates'); | ||
const id = this.messageID.toString(); | ||
this.subscriptions.push({ | ||
id, | ||
type: 'fiatRates', | ||
callback: (result) => { | ||
this.emit('fiatRates', result); | ||
}, | ||
}); | ||
this.addSubscription('fiatRates', result => this.emit('fiatRates', result)); | ||
return this.send('subscribeFiatRates', { currency }); | ||
@@ -289,17 +105,7 @@ } | ||
const index = this.removeSubscription('fiatRates'); | ||
if (index >= 0) { | ||
return this.send('unsubscribeFiatRates'); | ||
} | ||
return { subscribed: false }; | ||
return index >= 0 ? this.send('unsubscribeFiatRates') : { subscribed: false }; | ||
} | ||
subscribeMempool() { | ||
this.removeSubscription('mempool'); | ||
const id = this.messageID.toString(); | ||
this.subscriptions.push({ | ||
id, | ||
type: 'mempool', | ||
callback: result => { | ||
this.emit('mempool', result); | ||
}, | ||
}); | ||
this.addSubscription('mempool', result => this.emit('mempool', result)); | ||
return this.send('subscribeNewTransaction'); | ||
@@ -309,27 +115,6 @@ } | ||
const index = this.removeSubscription('mempool'); | ||
if (index >= 0) { | ||
return this.send('unsubscribeNewTransaction'); | ||
} | ||
return { subscribed: false }; | ||
return index >= 0 ? this.send('unsubscribeNewTransaction') : { subscribed: false }; | ||
} | ||
onClose() { | ||
var _a; | ||
if (this.pingTimeout) { | ||
clearTimeout(this.pingTimeout); | ||
} | ||
if (this.connectionTimeout) { | ||
clearTimeout(this.connectionTimeout); | ||
} | ||
if (this.isConnected()) { | ||
this.disconnect(); | ||
} | ||
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.removeAllListeners(); | ||
this.rejectAllPending('websocket_runtime_error', 'Websocket closed unexpectedly'); | ||
} | ||
dispose() { | ||
this.onClose(); | ||
this.removeAllListeners(); | ||
} | ||
} | ||
exports.BlockbookAPI = BlockbookAPI; | ||
//# sourceMappingURL=websocket.js.map |
@@ -1,2 +0,2 @@ | ||
import { BaseWorker } from '../base'; | ||
import { BaseWorker } from '../baseWorker'; | ||
import { BlockfrostAPI } from './websocket'; | ||
@@ -3,0 +3,0 @@ import type * as MessageTypes from '@trezor/blockchain-link-types/lib/messages'; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const constants_1 = require("@trezor/blockchain-link-types/lib/constants"); | ||
const base_1 = require("../base"); | ||
const baseWorker_1 = require("../baseWorker"); | ||
const websocket_1 = require("./websocket"); | ||
@@ -234,3 +234,3 @@ const blockfrost_1 = require("@trezor/blockchain-link-utils/lib/blockfrost"); | ||
}; | ||
class BlockfrostWorker extends base_1.BaseWorker { | ||
class BlockfrostWorker extends baseWorker_1.BaseWorker { | ||
cleanup() { | ||
@@ -289,3 +289,3 @@ if (this.api) { | ||
exports.default = Blockfrost; | ||
if (base_1.CONTEXT === 'worker') { | ||
if (baseWorker_1.CONTEXT === 'worker') { | ||
const module = new BlockfrostWorker(); | ||
@@ -292,0 +292,0 @@ onmessage = module.messageHandler.bind(module); |
import WebSocket from 'ws'; | ||
import { Deferred } from '@trezor/utils/lib/createDeferred'; | ||
import { TypedEmitter } from '@trezor/utils/lib/typedEventEmitter'; | ||
import type { Send, BlockContent, BlockfrostTransaction } from '@trezor/blockchain-link-types/lib/blockfrost'; | ||
import type { AccountInfoParams, EstimateFeeParams, AccountBalanceHistoryParams } from '@trezor/blockchain-link-types/lib/params'; | ||
interface Subscription { | ||
id: string; | ||
type: 'block' | 'notification'; | ||
callback: (result: any) => void; | ||
} | ||
interface Options { | ||
url: string; | ||
timeout?: number; | ||
pingTimeout?: number; | ||
keepAlive?: boolean; | ||
agent?: WebSocket.ClientOptions['agent']; | ||
} | ||
export declare interface BlockfrostEvents { | ||
import { BaseWebsocket } from '../baseWebsocket'; | ||
interface BlockfrostEvents { | ||
block: BlockContent; | ||
notification: BlockfrostTransaction; | ||
error: string; | ||
disconnected: undefined; | ||
} | ||
export declare class BlockfrostAPI extends TypedEmitter<BlockfrostEvents> { | ||
options: Options; | ||
ws: WebSocket | undefined; | ||
messageID: number; | ||
messages: Deferred<any>[]; | ||
subscriptions: Subscription[]; | ||
pingTimeout: ReturnType<typeof setTimeout> | undefined; | ||
connectionTimeout: ReturnType<typeof setTimeout> | undefined; | ||
constructor(options: Options); | ||
setConnectionTimeout(): void; | ||
clearConnectionTimeout(): void; | ||
setPingTimeout(): void; | ||
private rejectAllPending; | ||
onTimeout(): void; | ||
onPing(): Promise<void>; | ||
onError(): void; | ||
export declare class BlockfrostAPI extends BaseWebsocket<BlockfrostEvents> { | ||
protected createWebsocket(): WebSocket; | ||
protected ping(): Promise<BlockContent>; | ||
send: Send; | ||
onmessage(message: string): void; | ||
connect(): Promise<void>; | ||
init(): void; | ||
disconnect(): void; | ||
isConnected(): boolean; | ||
getServerInfo(): Promise<import("@trezor/blockchain-link-types/lib/blockfrost").ServerInfo>; | ||
@@ -62,5 +29,4 @@ getBlockHash(number: number): Promise<BlockContent>; | ||
}; | ||
dispose(): void; | ||
} | ||
export {}; | ||
//# sourceMappingURL=websocket.d.ts.map |
@@ -8,155 +8,17 @@ "use strict"; | ||
const ws_1 = __importDefault(require("ws")); | ||
const createDeferred_1 = require("@trezor/utils/lib/createDeferred"); | ||
const typedEventEmitter_1 = require("@trezor/utils/lib/typedEventEmitter"); | ||
const errors_1 = require("@trezor/blockchain-link-types/lib/constants/errors"); | ||
const DEFAULT_TIMEOUT = 20 * 1000; | ||
const DEFAULT_PING_TIMEOUT = 50 * 1000; | ||
class BlockfrostAPI extends typedEventEmitter_1.TypedEmitter { | ||
constructor(options) { | ||
super(); | ||
this.messageID = 0; | ||
this.messages = []; | ||
this.subscriptions = []; | ||
this.send = (command, params = {}) => { | ||
const { ws } = this; | ||
if (!ws) | ||
throw new errors_1.CustomError('websocket_not_initialized'); | ||
const id = this.messageID.toString(); | ||
const dfd = (0, createDeferred_1.createDeferred)(id); | ||
const req = { | ||
id, | ||
command, | ||
params, | ||
}; | ||
this.messageID++; | ||
this.messages.push(dfd); | ||
this.setConnectionTimeout(); | ||
this.setPingTimeout(); | ||
ws.send(JSON.stringify(req)); | ||
return dfd.promise; | ||
}; | ||
this.options = options; | ||
const baseWebsocket_1 = require("../baseWebsocket"); | ||
class BlockfrostAPI extends baseWebsocket_1.BaseWebsocket { | ||
constructor() { | ||
super(...arguments); | ||
this.send = (command, params = {}) => this.sendMessage({ command, params }); | ||
} | ||
setConnectionTimeout() { | ||
this.clearConnectionTimeout(); | ||
this.connectionTimeout = setTimeout(this.onTimeout.bind(this), this.options.timeout || DEFAULT_TIMEOUT); | ||
} | ||
clearConnectionTimeout() { | ||
if (this.connectionTimeout) { | ||
clearTimeout(this.connectionTimeout); | ||
this.connectionTimeout = undefined; | ||
} | ||
} | ||
setPingTimeout() { | ||
if (this.pingTimeout) { | ||
clearTimeout(this.pingTimeout); | ||
} | ||
this.pingTimeout = setTimeout(this.onPing.bind(this), this.options.pingTimeout || DEFAULT_PING_TIMEOUT); | ||
} | ||
rejectAllPending(code, message) { | ||
this.messages.forEach(m => m.reject(new errors_1.CustomError(code, message))); | ||
this.messages = []; | ||
} | ||
onTimeout() { | ||
const { ws } = this; | ||
if (!ws) | ||
return; | ||
if (ws.listenerCount('open') > 0) { | ||
ws.emit('error', 'Websocket timeout'); | ||
try { | ||
ws.close(); | ||
} | ||
catch (error) { | ||
} | ||
} | ||
else { | ||
this.rejectAllPending('websocket_timeout'); | ||
ws.close(); | ||
} | ||
} | ||
async onPing() { | ||
if (this.ws && this.isConnected()) { | ||
try { | ||
if (this.subscriptions.length > 0 || this.options.keepAlive) { | ||
await this.getBlockHash(1); | ||
} | ||
else { | ||
this.ws.close(); | ||
} | ||
} | ||
catch (error) { | ||
} | ||
} | ||
} | ||
onError() { | ||
this.dispose(); | ||
} | ||
onmessage(message) { | ||
try { | ||
const resp = JSON.parse(message); | ||
const { id, data } = resp; | ||
const dfd = this.messages.find(m => m.id === id); | ||
if (dfd) { | ||
if (data.error) { | ||
dfd.reject(new errors_1.CustomError('websocket_error_message', data.error.message)); | ||
} | ||
else { | ||
dfd.resolve(data); | ||
} | ||
this.messages.splice(this.messages.indexOf(dfd), 1); | ||
} | ||
else { | ||
const subs = this.subscriptions.find(s => s && s.id === id); | ||
if (subs) { | ||
subs.callback(data); | ||
} | ||
} | ||
} | ||
catch (error) { | ||
} | ||
if (this.messages.length === 0) { | ||
this.clearConnectionTimeout(); | ||
} | ||
this.setPingTimeout(); | ||
} | ||
connect() { | ||
createWebsocket() { | ||
const { url } = this.options; | ||
this.setConnectionTimeout(); | ||
const dfd = (0, createDeferred_1.createDeferred)(-1); | ||
const ws = new ws_1.default(url, { | ||
return new ws_1.default(url, { | ||
agent: this.options.agent, | ||
}); | ||
ws.once('error', error => { | ||
this.dispose(); | ||
dfd.reject(new errors_1.CustomError('websocket_runtime_error', error.message)); | ||
}); | ||
ws.on('open', () => { | ||
this.init(); | ||
dfd.resolve(); | ||
}); | ||
this.ws = ws; | ||
return dfd.promise; | ||
} | ||
init() { | ||
const { ws } = this; | ||
if (!ws || !this.isConnected()) { | ||
throw Error('Blockfrost websocket init cannot be called'); | ||
} | ||
this.clearConnectionTimeout(); | ||
ws.removeAllListeners(); | ||
ws.on('error', this.onError.bind(this)); | ||
ws.on('message', this.onmessage.bind(this)); | ||
ws.on('close', () => { | ||
this.emit('disconnected'); | ||
this.dispose(); | ||
}); | ||
ping() { | ||
return this.getBlockHash(1); | ||
} | ||
disconnect() { | ||
var _a; | ||
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.close(); | ||
} | ||
isConnected() { | ||
var _a; | ||
return ((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN; | ||
} | ||
getServerInfo() { | ||
@@ -187,68 +49,21 @@ return this.send('GET_SERVER_INFO'); | ||
subscribeBlock() { | ||
const index = this.subscriptions.findIndex(s => s.type === 'block'); | ||
if (index >= 0) { | ||
this.subscriptions.splice(index, 1); | ||
} | ||
const id = this.messageID.toString(); | ||
this.subscriptions.push({ | ||
id, | ||
type: 'block', | ||
callback: (result) => { | ||
this.emit('block', result); | ||
}, | ||
}); | ||
this.removeSubscription('block'); | ||
this.addSubscription('block', result => this.emit('block', result)); | ||
return this.send('SUBSCRIBE_BLOCK'); | ||
} | ||
subscribeAddresses(addresses) { | ||
const index = this.subscriptions.findIndex(s => s.type === 'notification'); | ||
if (index >= 0) { | ||
this.subscriptions.splice(index, 1); | ||
} | ||
const id = this.messageID.toString(); | ||
this.subscriptions.push({ | ||
id, | ||
type: 'notification', | ||
callback: (result) => { | ||
this.emit('notification', result); | ||
}, | ||
}); | ||
this.removeSubscription('notification'); | ||
this.addSubscription('notification', result => this.emit('notification', result)); | ||
return this.send('SUBSCRIBE_ADDRESS', { addresses }); | ||
} | ||
unsubscribeBlock() { | ||
const index = this.subscriptions.findIndex(s => s.type === 'block'); | ||
if (index >= 0) { | ||
this.subscriptions.splice(index, 1); | ||
return this.send('UNSUBSCRIBE_BLOCK'); | ||
} | ||
return { | ||
subscribed: false, | ||
}; | ||
const index = this.removeSubscription('block'); | ||
return index >= 0 ? this.send('UNSUBSCRIBE_BLOCK') : { subscribed: false }; | ||
} | ||
unsubscribeAddresses() { | ||
const index = this.subscriptions.findIndex(s => s.type === 'notification'); | ||
if (index >= 0) { | ||
this.subscriptions.splice(index, 1); | ||
return this.send('UNSUBSCRIBE_ADDRESS'); | ||
} | ||
return { | ||
subscribed: false, | ||
}; | ||
const index = this.removeSubscription('notification'); | ||
return index >= 0 ? this.send('UNSUBSCRIBE_ADDRESS') : { subscribed: false }; | ||
} | ||
dispose() { | ||
var _a; | ||
if (this.pingTimeout) { | ||
clearTimeout(this.pingTimeout); | ||
} | ||
if (this.connectionTimeout) { | ||
clearTimeout(this.connectionTimeout); | ||
} | ||
if (this.isConnected()) { | ||
this.disconnect(); | ||
} | ||
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.removeAllListeners(); | ||
this.rejectAllPending('websocket_runtime_error', 'Websocket closed unexpectedly'); | ||
this.removeAllListeners(); | ||
} | ||
} | ||
exports.BlockfrostAPI = BlockfrostAPI; | ||
//# sourceMappingURL=websocket.js.map |
@@ -1,2 +0,2 @@ | ||
import { BaseWorker } from '../base'; | ||
import { BaseWorker } from '../baseWorker'; | ||
import type { ElectrumClient } from './client/electrum'; | ||
@@ -3,0 +3,0 @@ import { Message } from '@trezor/blockchain-link-types/lib/messages'; |
@@ -28,3 +28,3 @@ "use strict"; | ||
const constants_1 = require("@trezor/blockchain-link-types/lib/constants"); | ||
const base_1 = require("../base"); | ||
const baseWorker_1 = require("../baseWorker"); | ||
const M = __importStar(require("./methods")); | ||
@@ -118,3 +118,3 @@ const L = __importStar(require("./listeners")); | ||
}; | ||
class ElectrumWorker extends base_1.BaseWorker { | ||
class ElectrumWorker extends baseWorker_1.BaseWorker { | ||
constructor() { | ||
@@ -181,3 +181,3 @@ super(); | ||
exports.default = Electrum; | ||
if (base_1.CONTEXT === 'worker') { | ||
if (baseWorker_1.CONTEXT === 'worker') { | ||
const module = new ElectrumWorker(); | ||
@@ -184,0 +184,0 @@ onmessage = module.messageHandler.bind(module); |
@@ -1,2 +0,2 @@ | ||
import type { BaseWorker } from '../../base'; | ||
import type { BaseWorker } from '../../baseWorker'; | ||
import type { ElectrumAPI } from '@trezor/blockchain-link-types/lib/electrum'; | ||
@@ -3,0 +3,0 @@ export declare const blockListener: (worker: BaseWorker<ElectrumAPI>) => { |
@@ -1,2 +0,2 @@ | ||
import type { BaseWorker } from '../../base'; | ||
import type { BaseWorker } from '../../baseWorker'; | ||
import type { ElectrumAPI } from '@trezor/blockchain-link-types/lib/electrum'; | ||
@@ -3,0 +3,0 @@ import type { Subscribe, Unsubscribe } from '@trezor/blockchain-link-types/lib/messages'; |
import { RippleAPI } from 'ripple-lib'; | ||
import { BaseWorker } from '../base'; | ||
import { BaseWorker } from '../baseWorker'; | ||
import type * as MessageTypes from '@trezor/blockchain-link-types/lib/messages'; | ||
@@ -4,0 +4,0 @@ declare class RippleWorker extends BaseWorker<RippleAPI> { |
@@ -34,3 +34,3 @@ "use strict"; | ||
const constants_1 = require("@trezor/blockchain-link-types/lib/constants"); | ||
const base_1 = require("../base"); | ||
const baseWorker_1 = require("../baseWorker"); | ||
const utils = __importStar(require("@trezor/blockchain-link-utils/lib/ripple")); | ||
@@ -359,3 +359,3 @@ const DEFAULT_TIMEOUT = 20 * 1000; | ||
}; | ||
class RippleWorker extends base_1.BaseWorker { | ||
class RippleWorker extends baseWorker_1.BaseWorker { | ||
cleanup() { | ||
@@ -445,3 +445,3 @@ if (this.pingTimeout) { | ||
exports.default = Ripple; | ||
if (base_1.CONTEXT === 'worker') { | ||
if (baseWorker_1.CONTEXT === 'worker') { | ||
const module = new RippleWorker(); | ||
@@ -448,0 +448,0 @@ onmessage = module.messageHandler.bind(module); |
{ | ||
"name": "@trezor/blockchain-link", | ||
"version": "2.1.14", | ||
"version": "2.1.15", | ||
"author": "Trezor <info@trezor.io>", | ||
@@ -70,6 +70,6 @@ "homepage": "https://github.com/trezor/trezor-suite/tree/develop/packages/blockchain-link", | ||
"dependencies": { | ||
"@trezor/blockchain-link-types": "1.0.3", | ||
"@trezor/blockchain-link-utils": "1.0.4", | ||
"@trezor/utils": "9.0.10", | ||
"@trezor/utxo-lib": "1.0.8", | ||
"@trezor/blockchain-link-types": "1.0.4", | ||
"@trezor/blockchain-link-utils": "1.0.5", | ||
"@trezor/utils": "9.0.11", | ||
"@trezor/utxo-lib": "1.0.9", | ||
"@types/web": "^0.0.100", | ||
@@ -76,0 +76,0 @@ "bignumber.js": "^9.1.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90
176675
4168
+ Added@trezor/blockchain-link-types@1.0.4(transitive)
+ Added@trezor/blockchain-link-utils@1.0.5(transitive)
+ Added@trezor/utils@9.0.11(transitive)
+ Added@trezor/utxo-lib@1.0.9(transitive)
- Removed@trezor/blockchain-link-types@1.0.3(transitive)
- Removed@trezor/blockchain-link-utils@1.0.4(transitive)
- Removed@trezor/utils@9.0.10(transitive)
- Removed@trezor/utxo-lib@1.0.8(transitive)
Updated@trezor/utils@9.0.11
Updated@trezor/utxo-lib@1.0.9