diff --git a/client/src/models/TxBlockScene.js b/client/src/models/TxBlockScene.js index a2967bf..cea3593 100644 --- a/client/src/models/TxBlockScene.js +++ b/client/src/models/TxBlockScene.js @@ -1,4 +1,12 @@ import TxMondrianPoolScene from './TxMondrianPoolScene.js' +import { settings } from '../stores.js' +import { logTxSize, byteTxSize } from '../utils/misc.js' +import config from '../config.js' + +let settingsValue +settings.subscribe(v => { + settingsValue = v +}) export default class TxBlockScene extends TxMondrianPoolScene { constructor ({ width, height, unit = 4, padding = 1, blockId, controller, heightStore, colorMode }) { @@ -47,6 +55,12 @@ export default class TxBlockScene extends TxMondrianPoolScene { this.resetLayout() } + // calculates and returns the size of the tx in multiples of the grid size + txSize (tx={ value: 1, vbytes: 1 }) { + if (settingsValue.vbytes) return byteTxSize(tx.vbytes, Math.Infinity) + else return logTxSize(tx.value, Math.Infinity) + } + setTxOnScreen (tx, pixelPosition) { if (!tx.view.initialised) { tx.view.update({ diff --git a/server/lib/mempool.ex b/server/lib/mempool.ex index 4ae7b45..8c9ecdc 100644 --- a/server/lib/mempool.ex +++ b/server/lib/mempool.ex @@ -498,7 +498,6 @@ defmodule BitcoinStream.Mempool do end end - defp cache_spend(txid, index, input) do :ets.insert(:spend_cache, {[input.prev_txid, input.prev_vout], [txid, index]}) end diff --git a/server/lib/router.ex b/server/lib/router.ex index 21aa207..adddee0 100644 --- a/server/lib/router.ex +++ b/server/lib/router.ex @@ -65,7 +65,7 @@ defmodule BitcoinStream.Router do |> send_resp(200, spends) _ -> Logger.debug("Error getting tx spends"); - send_resp(conn, 404, "Transaction not found") + send_resp(conn, 200, "[]") end end diff --git a/server/lib/spend_index.ex b/server/lib/spend_index.ex index 0c11095..87db187 100644 --- a/server/lib/spend_index.ex +++ b/server/lib/spend_index.ex @@ -22,7 +22,7 @@ defmodule BitcoinStream.Index.Spend do Process.send_after(self(), :sync, 2000); {:ok, [dbref, indexed, false]} else - {:ok, nil} + {:ok, [nil, indexed, false]} end end @@ -57,7 +57,7 @@ defmodule BitcoinStream.Index.Spend do @impl true def handle_call({:get_tx_spends, txid}, _from, [dbref, indexed, done]) do - case get_transaction_spends(dbref, txid) do + case get_transaction_spends(dbref, txid, (indexed != nil)) do {:ok, spends} -> {:reply, {:ok, spends}, [dbref, indexed, done]} @@ -207,7 +207,7 @@ defmodule BitcoinStream.Index.Spend do defp index_block_inputs(dbref, batch, txns) do spends = index_txs(txns, %{}); Enum.each(spends, fn {binid, outputs} -> - case get_chain_spends(dbref, binid) do + case get_chain_spends(dbref, binid, true) do false -> Logger.error("uninitialised tx in input index: #{Base.encode16(binid, [case: :lower])}") :ok @@ -296,8 +296,8 @@ defmodule BitcoinStream.Index.Spend do end end - defp get_chain_spends(dbref, binary_txid) do - case :rocksdb.get(dbref, binary_txid, []) do + defp get_chain_spends(dbref, binary_txid, use_index) do + case (if use_index do :rocksdb.get(dbref, binary_txid, []) else :not_found end) do {:ok, spends} -> spends @@ -337,9 +337,9 @@ defmodule BitcoinStream.Index.Spend do unpack_spends(bin, []) end - defp get_transaction_spends(dbref, txid) do + defp get_transaction_spends(dbref, txid, use_index) do binary_txid = Base.decode16!(txid, [case: :lower]); - chain_spends = get_chain_spends(dbref, binary_txid); + chain_spends = get_chain_spends(dbref, binary_txid, use_index); spend_list = unpack_spends(chain_spends); spend_list = add_mempool_spends(txid, spend_list); {:ok, spend_list} @@ -380,7 +380,7 @@ defmodule BitcoinStream.Index.Spend do defp drop_block_inputs(dbref, batch, txns) do spends = index_txs(txns, %{}); Enum.each(spends, fn {binid, outputs} -> - case get_chain_spends(dbref, binid) do + case get_chain_spends(dbref, binid, true) do false -> Logger.error("uninitialised tx in input index: #{Base.encode16(binid, [case: :lower])}") :ok