diff --git a/client/src/controllers/TxStream.js b/client/src/controllers/TxStream.js index 2fab946..fcc18cb 100644 --- a/client/src/controllers/TxStream.js +++ b/client/src/controllers/TxStream.js @@ -121,14 +121,19 @@ class TxStream { } async fetchBlock (id, calledOnLoad) { + if (!id) return if (id !== lastBlockSeen) { - console.log('downloading block', id) - const response = await fetch(`${this.apiUri}/block/${id}`, { - method: 'GET' - }) - let blockData = await response.json() - console.log('downloaded block', id) - window.dispatchEvent(new CustomEvent('bitcoin_block', { detail: { block: blockData, realtime: !calledOnLoad} })) + try { + console.log('downloading block', id) + const response = await fetch(`${this.apiUri}/api/block/${id}`, { + method: 'GET' + }) + let blockData = await response.json() + console.log('downloaded block', id) + window.dispatchEvent(new CustomEvent('bitcoin_block', { detail: { block: blockData, realtime: !calledOnLoad} })) + } catch (err) { + console.log("failed to download block ", id) + } } else { console.log('already seen block ', lastBlockSeen) } diff --git a/client/src/stores.js b/client/src/stores.js index 704479d..2cffd8c 100644 --- a/client/src/stores.js +++ b/client/src/stores.js @@ -1,5 +1,5 @@ import { writable, derived } from 'svelte/store' -import { spring } from 'svelte/motion'; +import { tweened } from 'svelte/motion'; import { makePollStore } from './utils/pollStore.js' import LocaleCurrency from 'locale-currency' import { currencies } from './utils/fx.js' @@ -82,7 +82,7 @@ export const devEvents = writable({ export const txCount = createCounter() export const lastBlockId = writable(null) -export const mempoolCount = spring(0) +export const mempoolCount = tweened(0) export const mempoolScreenHeight = writable(0) export const frameRate = writable(null) export const avgFrameRate = writable(null) diff --git a/docker-compose.yml b/docker-compose.yml index 7bf56ef..85d0f7e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,6 +24,7 @@ services: BITCOIN_HOST: "172.17.0.1" BITCOIN_ZMQ_RAWBLOCK_PORT: "29000" BITCOIN_ZMQ_RAWTX_PORT: "29001" + BITCOIN_ZMQ_SEQUENCE_PORT: "29002" BITCOIN_RPC_PORT: "8332" BITCOIN_RPC_USER: "bitcoin" BITCOIN_RPC_PASS: "correcthorsebatterystaple" diff --git a/server/README.md b/server/README.md index 8d88f02..1efd335 100644 --- a/server/README.md +++ b/server/README.md @@ -27,6 +27,7 @@ The API server expects the following environment variables to be set: | BITCOIN_HOST | Bitcoin node host address | | BITCOIN_ZMQ_RAWBLOCK_PORT | Bitcoin node ZMQ port for block events (to match `zmqpubrawblock` in bitcoin.conf) | | BITCOIN_ZMQ_RAWTX_PORT | Bitcoin node ZMQ port for transaction events (to match `zmqpubrawtx` in bitcoin.conf) | +| BITCOIN_ZMQ_SEQUENCE_PORT | Bitcoin node ZMQ port for sequence events (to match `zmqpubsequence` in bitcoin.conf) | | BITCOIN_RPC_PORT | Bitcoin node RPC port | | either | | | BITCOIN_RPC_USER | Bitcoin node RPC user | diff --git a/server/bitfeed.service b/server/bitfeed.service index 89830c0..aa96fb6 100644 --- a/server/bitfeed.service +++ b/server/bitfeed.service @@ -14,6 +14,12 @@ Environment=LANG=en_US.UTF-8 Environment=PORT= Environment=BITCOIN_RPC_USER= Environment=BITCOIN_RPC_PASS= +Environment=BITCOIN_HOST= +Environment=BITCOIN_RPC_PORT= +Environment=BITCOIN_ZMQ_RAWBLOCK_PORT= +Environment=BITCOIN_ZMQ_RAWTX_PORT= +Environment=BITCOIN_ZMQ_SEQUENCE_PORT= + WorkingDirectory=/server diff --git a/server/lib/router.ex b/server/lib/router.ex index ee9f0ba..d2f24e0 100644 --- a/server/lib/router.ex +++ b/server/lib/router.ex @@ -12,7 +12,7 @@ defmodule BitcoinStream.Router do json_decoder: Jason plug :dispatch - match "/block/:hash" do + match "/api/block/:hash" do case get_block(hash) do {:ok, block} -> put_resp_header(conn, "cache-control", "public, max-age=604800, immutable")