aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/utils.js35
-rw-r--r--routes/assets.js3
-rw-r--r--routes/liquid/receive.js7
3 files changed, 40 insertions, 5 deletions
diff --git a/lib/utils.js b/lib/utils.js
index 004ca7ac..1ff24c67 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -55,3 +55,38 @@ export const fail = msg => {
export const SATS = 100000000;
export const toSats = n => Math.round(n * SATS);
+
+export const getBlockHeight = message => {
+ let buffer = Buffer.from(message, "hex");
+ if (buffer.length < 80) throw new Error("Buffer too small (< 80 bytes)");
+
+ let offset = 0;
+ const readSlice = n => {
+ offset += n;
+ return buffer.slice(offset - n, offset);
+ };
+
+ const readUInt32 = () => {
+ const i = buffer.readUInt32LE(offset);
+ offset += 4;
+ return i;
+ };
+
+ const readUInt8 = () => {
+ const i = buffer.readUInt8(offset);
+ offset += 1;
+ return i;
+ };
+
+ const readVarInt = () => {
+ const vi = varuint.decode(buffer, offset);
+ offset += varuint.decode.bytes;
+ return vi;
+ };
+
+ readUInt32();
+ readSlice(32);
+ readSlice(32);
+ readUInt32();
+ return readUInt32();
+};
diff --git a/routes/assets.js b/routes/assets.js
index 22bf71d0..8140b179 100644
--- a/routes/assets.js
+++ b/routes/assets.js
@@ -7,6 +7,9 @@ import { auth } from "$lib/passport";
import axios from "axios";
import crypto from "crypto";
import fs from "fs";
+import { err, l } from "$lib/logging";
+import lq from "$lib/liquid";
+import { SATS } from "$lib/utils";
let fetchAssets;
(fetchAssets = async () => {
diff --git a/routes/liquid/receive.js b/routes/liquid/receive.js
index f3b8397f..480677de 100644
--- a/routes/liquid/receive.js
+++ b/routes/liquid/receive.js
@@ -1,6 +1,6 @@
import db from "$db";
import config from "$config";
-import { toSats } from "$lib/utils";
+import { getBlockHeight, getUser, toSats } from "$lib/utils";
import { emit } from "$lib/sockets";
import store from "$lib/store";
import { sendLiquid } from "$routes/liquid/send";
@@ -14,7 +14,6 @@ import bitcoin from "bitcoinjs-lib";
import liquidJs from "liquidjs-lib";
import { l, err, warn } from "$lib/logging";
import lq from "$lib/liquid";
-import { getUser } from "$lib/utils";
const { Block, networks, Transaction } = liquidJs;
@@ -224,11 +223,9 @@ zmqRawBlock.on("message", async (topic, message, sequence) => {
where: { confirmed: 0 }
});
- const block = Block.fromHex(message.toString("hex"), true);
-
let hash, json;
- hash = await lq.getBlockHash(block.blockHeight);
+ hash = await lq.getBlockHash(getBlockHeight(message));
json = await lq.getBlock(hash, 2);
json.tx.map(async tx => {