Skip to content

Commit

Permalink
Rename wsAddress parameter to connectionUri
Browse files Browse the repository at this point in the history
This is less likely to be confused with an on-chain address.
  • Loading branch information
samholmes committed Apr 5, 2024
1 parent b502e63 commit ae63dfc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/common/utxobased/engine/ServerStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export function makeServerStates(config: ServerStateConfig): ServerStates {

// Make new Blockbook instance
const blockbook = makeBlockbook({
wsAddress: uri,
connectionUri: uri,
socketEmitter,
engineEmitter,
log,
Expand Down
32 changes: 18 additions & 14 deletions src/common/utxobased/network/Blockbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,26 @@ export interface Blockbook {
}

interface BlockbookConfig {
socketEmitter: SocketEmitter
asAddress?: Cleaner<string>
connectionUri: string
engineEmitter: EngineEmitter
wsAddress: string
log: EdgeLog
walletId: string
onQueueSpaceCB: OnQueueSpaceCB
asAddress?: Cleaner<string>
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,
Expand All @@ -96,7 +96,7 @@ export function makeBlockbook(config: BlockbookConfig): Blockbook {
broadcastTx
}

const socket = makeSocket(wsAddress, {
const socket = makeSocket(connectionUri, {
healthCheck: ping,
onQueueSpaceCB,
log,
Expand All @@ -105,7 +105,7 @@ export function makeBlockbook(config: BlockbookConfig): Blockbook {
})

async function connect(): Promise<void> {
log(`connecting to blockbook socket with uri ${wsAddress}`)
log(`connecting to blockbook socket with uri ${connectionUri}`)
if (instance.isConnected) return

await socket.connect()
Expand All @@ -114,7 +114,7 @@ export function makeBlockbook(config: BlockbookConfig): Blockbook {

async function disconnect(): Promise<void> {
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

Expand Down Expand Up @@ -163,7 +163,7 @@ export function makeBlockbook(config: BlockbookConfig): Blockbook {
const socketCb = async (res: SubscribeNewBlockResponse): Promise<void> => {
engineEmitter.emit(
EngineEvent.BLOCK_HEIGHT_CHANGED,
wsAddress,
connectionUri,
res.height
)
}
Expand All @@ -180,7 +180,11 @@ export function makeBlockbook(config: BlockbookConfig): Blockbook {
deferredAddressSub: Deferred<unknown>
): void {
const socketCb = async (res: SubscribeAddressResponse): Promise<void> => {
engineEmitter.emit(EngineEvent.NEW_ADDRESS_TRANSACTION, wsAddress, res)
engineEmitter.emit(
EngineEvent.NEW_ADDRESS_TRANSACTION,
connectionUri,
res
)
}
socket.subscribe({
...subscribeAddressesMessage(addresses, asAddress),
Expand Down
16 changes: 9 additions & 7 deletions test/common/utxobased/network/Blockbook.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
Expand All @@ -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()
})
Expand Down

0 comments on commit ae63dfc

Please sign in to comment.