Skip to content

Commit

Permalink
Merge pull request #661 from BoltzExchange/update-zmq
Browse files Browse the repository at this point in the history
Update ZeroMQ
  • Loading branch information
michael1011 authored Sep 7, 2024
2 parents b4c4447 + a98a871 commit aae5253
Show file tree
Hide file tree
Showing 5 changed files with 1,070 additions and 336 deletions.
2 changes: 1 addition & 1 deletion lib/Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const unblindOutput = (
asset = output.asset;

// Remove the un-confidential prefix
asset = asset.slice(1, asset.length);
asset = asset.subarray(1, asset.length);
}

asset = reverseBuffer(asset);
Expand Down
8 changes: 4 additions & 4 deletions lib/chain/ZmqClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AsyncLock from 'async-lock';
import { Transaction, crypto } from 'bitcoinjs-lib';
import { Transaction as LiquidTransaction } from 'liquidjs-lib';
import zmq, { Socket } from 'zeromq';
import { Socket, socket as openSocket } from 'zeromq/v5-compat';
import { parseTransaction } from '../Core';
import Logger from '../Logger';
import {
Expand Down Expand Up @@ -241,13 +241,13 @@ class ZmqClient<T extends SomeTransaction> extends TypedEventEmitter<{

socket.on('message', async (_, rawBlock: Buffer) => {
const previousBlockHash = getHexString(
reverseBuffer(rawBlock.slice(4, 36)),
reverseBuffer(rawBlock.subarray(4, 36)),
);

// To get the hash of a block one has to get the header (first 80 bytes),
// hash it twice with SHA256 and reverse the resulting Buffer
const hash = getHexString(
reverseBuffer(crypto.sha256(crypto.sha256(rawBlock.slice(0, 80)))),
reverseBuffer(crypto.sha256(crypto.sha256(rawBlock.subarray(0, 80)))),
);

this.blockHandleLock.acquire(
Expand Down Expand Up @@ -392,7 +392,7 @@ class ZmqClient<T extends SomeTransaction> extends TypedEventEmitter<{
);

return new Promise<Socket>((resolve, reject) => {
const socket = zmq.socket('sub').monitor();
const socket = openSocket('sub').monitor(0, 0);
this.sockets.push(socket);

const timeoutHandle = setTimeout(
Expand Down
Loading

0 comments on commit aae5253

Please sign in to comment.