diff --git a/src/common/utxobased/engine/ServerStates.ts b/src/common/utxobased/engine/ServerStates.ts index 4b95bb1c..9aaa9a5e 100644 --- a/src/common/utxobased/engine/ServerStates.ts +++ b/src/common/utxobased/engine/ServerStates.ts @@ -209,7 +209,7 @@ export function makeServerStates(config: ServerStateConfig): ServerStates { // Make new Blockbook instance const blockbook = makeBlockbook({ - wsAddress: uri, + connectionUri: uri, socketEmitter, engineEmitter, log, diff --git a/src/common/utxobased/network/Blockbook.ts b/src/common/utxobased/network/Blockbook.ts index aa7764f9..72eea11a 100644 --- a/src/common/utxobased/network/Blockbook.ts +++ b/src/common/utxobased/network/Blockbook.ts @@ -61,26 +61,26 @@ export interface Blockbook { } interface BlockbookConfig { - socketEmitter: SocketEmitter + asAddress?: Cleaner + connectionUri: string engineEmitter: EngineEmitter - wsAddress: string log: EdgeLog - walletId: string onQueueSpaceCB: OnQueueSpaceCB - asAddress?: Cleaner + socketEmitter: SocketEmitter + walletId: string } export function makeBlockbook(config: BlockbookConfig): Blockbook { const { - wsAddress, - socketEmitter, + asAddress, + connectionUri, engineEmitter, log, onQueueSpaceCB, - walletId, - asAddress + socketEmitter, + walletId } = config - log(`makeBlockbook with uri ${wsAddress}`) + log(`makeBlockbook with uri ${connectionUri}`) const instance: Blockbook = { isConnected: false, @@ -96,7 +96,7 @@ export function makeBlockbook(config: BlockbookConfig): Blockbook { broadcastTx } - const socket = makeSocket(wsAddress, { + const socket = makeSocket(connectionUri, { healthCheck: ping, onQueueSpaceCB, log, @@ -105,7 +105,7 @@ export function makeBlockbook(config: BlockbookConfig): Blockbook { }) async function connect(): Promise { - log(`connecting to blockbook socket with uri ${wsAddress}`) + log(`connecting to blockbook socket with uri ${connectionUri}`) if (instance.isConnected) return await socket.connect() @@ -114,7 +114,7 @@ export function makeBlockbook(config: BlockbookConfig): Blockbook { async function disconnect(): Promise { log( - `disconnecting from blockbook socket with uri ${wsAddress}, currently connected: ${instance.isConnected}` + `disconnecting from blockbook socket with uri ${connectionUri}, currently connected: ${instance.isConnected}` ) if (!instance.isConnected) return @@ -163,7 +163,7 @@ export function makeBlockbook(config: BlockbookConfig): Blockbook { const socketCb = async (res: SubscribeNewBlockResponse): Promise => { engineEmitter.emit( EngineEvent.BLOCK_HEIGHT_CHANGED, - wsAddress, + connectionUri, res.height ) } @@ -180,7 +180,11 @@ export function makeBlockbook(config: BlockbookConfig): Blockbook { deferredAddressSub: Deferred ): void { const socketCb = async (res: SubscribeAddressResponse): Promise => { - engineEmitter.emit(EngineEvent.NEW_ADDRESS_TRANSACTION, wsAddress, res) + engineEmitter.emit( + EngineEvent.NEW_ADDRESS_TRANSACTION, + connectionUri, + res + ) } socket.subscribe({ ...subscribeAddressesMessage(addresses, asAddress), diff --git a/test/common/utxobased/network/Blockbook.spec.ts b/test/common/utxobased/network/Blockbook.spec.ts index 62726f3f..af6531da 100644 --- a/test/common/utxobased/network/Blockbook.spec.ts +++ b/test/common/utxobased/network/Blockbook.spec.ts @@ -75,12 +75,12 @@ describe('Blockbook notifications tests with dummy server', function () { }) blockbook = makeBlockbook({ - socketEmitter, + connectionUri: 'ws://localhost:8555', engineEmitter, log, - walletId: '', onQueueSpaceCB, - wsAddress: 'ws://localhost:8555' + socketEmitter, + walletId: '' }) await blockbook.connect() blockbook.isConnected.should.be.true @@ -151,7 +151,9 @@ describe('Blockbook', function () { const satoshiAddress = '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa' const engineEmitter = new EngineEmitter() const socketEmitter = new SocketEmitter() + const log = makeFakeLog() + let blockbook: Blockbook const onQueueSpaceCB = async ( @@ -162,12 +164,12 @@ describe('Blockbook', function () { beforeEach(async () => { blockbook = makeBlockbook({ - socketEmitter, + connectionUri: 'wss://btc1.trezor.io/websocket', engineEmitter, log, - wsAddress: 'wss://btc1.trezor.io/websocket', - walletId: '', - onQueueSpaceCB + onQueueSpaceCB, + socketEmitter, + walletId: '' }) await blockbook.connect() })