diff --git a/.zed/settings.json b/.zed/settings.json index 0ec3f89ec..391fdabca 100644 --- a/.zed/settings.json +++ b/.zed/settings.json @@ -15,8 +15,8 @@ "**/modern-screenshot/*/index.mjs", "**/solidjs-signals/*/dist/prod.js", "uFuzzy.mjs", - "lightweight-charts.standalone.production.mjs", + "lightweight-charts.standalone.production.mjs" // "scripts/packages", - "dist" + // "dist" ] } diff --git a/Cargo.toml b/Cargo.toml index 4577ac48c..108e53172 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -90,4 +90,3 @@ ci = "github" allow-dirty = ["ci"] installers = [] targets = ["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu"] -rust-toolchain-version = "1.89" diff --git a/crates/brk_computer/src/blks.rs b/crates/brk_computer/src/blks.rs index cc60872ab..606cb4187 100644 --- a/crates/brk_computer/src/blks.rs +++ b/crates/brk_computer/src/blks.rs @@ -3,7 +3,7 @@ use std::path::Path; use brk_error::Result; use brk_indexer::Indexer; use brk_parser::Parser; -use brk_structs::{BlkPosition, Height, StoredU32, TxIndex, Version}; +use brk_structs::{BlkPosition, Height, TxIndex, Version}; use vecdb::{ AnyCollectableVec, AnyIterableVec, AnyStoredVec, AnyVec, CompressedVec, Database, Exit, GenericStoredVec, PAGE_SIZE, VecIterator, @@ -16,9 +16,7 @@ pub struct Vecs { db: Database, pub height_to_position: CompressedVec, - pub height_to_len: CompressedVec, pub txindex_to_position: CompressedVec, - pub txindex_to_len: CompressedVec, } impl Vecs { @@ -34,13 +32,11 @@ impl Vecs { "position", version + Version::TWO, )?, - height_to_len: CompressedVec::forced_import(&db, "len", version + Version::TWO)?, txindex_to_position: CompressedVec::forced_import( &db, "position", version + Version::TWO, )?, - txindex_to_len: CompressedVec::forced_import(&db, "len", version + Version::TWO)?, db, }; @@ -104,9 +100,6 @@ impl Vecs { exit, )?; - self.height_to_len - .forced_push_at(height, block.metadata().len().into(), exit)?; - let txindex = height_to_first_txindex_iter.unwrap_get_inner(height); block.tx_metadata().iter().enumerate().try_for_each( @@ -117,8 +110,6 @@ impl Vecs { metadata.position(), exit, )?; - self.txindex_to_len - .forced_push_at(txindex, metadata.len().into(), exit)?; Ok(()) }, )?; @@ -126,18 +117,14 @@ impl Vecs { if *height % 1_000 == 0 { let _lock = exit.lock(); self.height_to_position.flush()?; - self.height_to_len.flush()?; self.txindex_to_position.flush()?; - self.txindex_to_len.flush()?; } Ok(()) })?; let _lock = exit.lock(); self.height_to_position.flush()?; - self.height_to_len.flush()?; self.txindex_to_position.flush()?; - self.txindex_to_len.flush()?; Ok(()) } @@ -146,9 +133,7 @@ impl Vecs { Box::new( [ &self.height_to_position as &dyn AnyCollectableVec, - &self.height_to_len, &self.txindex_to_position, - &self.txindex_to_len, ] .into_iter(), ) diff --git a/crates/brk_server/src/api/mod.rs b/crates/brk_server/src/api/mod.rs index 81d24ba34..27172d43a 100644 --- a/crates/brk_server/src/api/mod.rs +++ b/crates/brk_server/src/api/mod.rs @@ -12,7 +12,6 @@ use axum::{ routing::get, }; use bitcoin::{Address, Network, Transaction, consensus::Decodable}; -use bitcoincore_rpc::bitcoin; use brk_interface::{IdParam, Index, PaginatedIndexParam, PaginationParam, Params, ParamsOpt}; use brk_parser::XORIndex; use brk_structs::{ @@ -182,7 +181,7 @@ impl ApiRoutes for Router { let computer = interface.computer(); let position = computer.blks.txindex_to_position.iter().unwrap_get_inner(txindex); - let len = computer.blks.txindex_to_len.iter().unwrap_get_inner(txindex); + let len = indexer.vecs.txindex_to_total_size.iter().unwrap_get_inner(txindex); let blk_index_to_blk_path = parser.blk_index_to_blk_path(); diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index b67e7d534..000000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,2 +0,0 @@ -[toolchain] -channel = "1.89.0" diff --git a/websites/bitview/scripts/chart.js b/websites/bitview/scripts/core/chart.js similarity index 99% rename from websites/bitview/scripts/chart.js rename to websites/bitview/scripts/core/chart.js index b0f8733cc..29fe2830f 100644 --- a/websites/bitview/scripts/chart.js +++ b/websites/bitview/scripts/core/chart.js @@ -1,6 +1,6 @@ // @ts-check -/** @import { IChartApi, ISeriesApi as _ISeriesApi, SeriesDefinition, SingleValueData as _SingleValueData, CandlestickData as _CandlestickData, BaselineData as _BaselineData, HistogramData as _HistogramData, SeriesType, IPaneApi, LineSeriesPartialOptions as _LineSeriesPartialOptions, HistogramSeriesPartialOptions as _HistogramSeriesPartialOptions, BaselineSeriesPartialOptions as _BaselineSeriesPartialOptions, CandlestickSeriesPartialOptions as _CandlestickSeriesPartialOptions, WhitespaceData, DeepPartial, ChartOptions, Time, LineData as _LineData } from './packages/lightweight-charts/5.0.8/dist/typings' */ +/** @import { IChartApi, ISeriesApi as _ISeriesApi, SeriesDefinition, SingleValueData as _SingleValueData, CandlestickData as _CandlestickData, BaselineData as _BaselineData, HistogramData as _HistogramData, SeriesType, IPaneApi, LineSeriesPartialOptions as _LineSeriesPartialOptions, HistogramSeriesPartialOptions as _HistogramSeriesPartialOptions, BaselineSeriesPartialOptions as _BaselineSeriesPartialOptions, CandlestickSeriesPartialOptions as _CandlestickSeriesPartialOptions, WhitespaceData, DeepPartial, ChartOptions, Time, LineData as _LineData } from '../packages/lightweight-charts/5.0.8/dist/typings' */ /** * @typedef {[number, number, number, number]} OHLCTuple @@ -46,7 +46,7 @@ import { LineSeries, BaselineSeries, // } from "./5.0.8/dist/lightweight-charts.standalone.development.mjs"; -} from "./packages/lightweight-charts/5.0.8/dist/lightweight-charts.standalone.production.mjs"; +} from "../packages/lightweight-charts/5.0.8/dist/lightweight-charts.standalone.production.mjs"; const oklchToRGBA = createOklchToRGBA(); diff --git a/websites/bitview/scripts/core/colors.js b/websites/bitview/scripts/core/colors.js new file mode 100644 index 000000000..09850a92d --- /dev/null +++ b/websites/bitview/scripts/core/colors.js @@ -0,0 +1,120 @@ +/** + * @import { Accessor } from "../packages/solidjs-signals/wrapper"; + */ + +const globalComputedStyle = getComputedStyle(window.document.documentElement); + +/** + * @param {Accessor} dark + */ +export function createColors(dark) { + /** + * @param {string} color + */ + function getColor(color) { + return globalComputedStyle.getPropertyValue(`--${color}`); + } + function red() { + return getColor("red"); + } + function orange() { + return getColor("orange"); + } + function amber() { + return getColor("amber"); + } + function yellow() { + return getColor("yellow"); + } + function avocado() { + return getColor("avocado"); + } + function lime() { + return getColor("lime"); + } + function green() { + return getColor("green"); + } + function emerald() { + return getColor("emerald"); + } + function teal() { + return getColor("teal"); + } + function cyan() { + return getColor("cyan"); + } + function sky() { + return getColor("sky"); + } + function blue() { + return getColor("blue"); + } + function indigo() { + return getColor("indigo"); + } + function violet() { + return getColor("violet"); + } + function purple() { + return getColor("purple"); + } + function fuchsia() { + return getColor("fuchsia"); + } + function pink() { + return getColor("pink"); + } + function rose() { + return getColor("rose"); + } + function gray() { + return getColor("gray"); + } + + /** + * @param {string} property + */ + function getLightDarkValue(property) { + const value = globalComputedStyle.getPropertyValue(property); + const [light, _dark] = value.slice(11, -1).split(", "); + return dark() ? _dark : light; + } + + function textColor() { + return getLightDarkValue("--color"); + } + function borderColor() { + return getLightDarkValue("--border-color"); + } + + return { + default: textColor, + gray, + border: borderColor, + + red, + orange, + amber, + yellow, + avocado, + lime, + green, + emerald, + teal, + cyan, + sky, + blue, + indigo, + violet, + purple, + fuchsia, + pink, + rose, + }; +} +/** + * @typedef {ReturnType} Colors + * @typedef {Colors["orange"]} Color + * @typedef {keyof Colors} ColorName + */ diff --git a/websites/bitview/scripts/core/dom.js b/websites/bitview/scripts/core/dom.js new file mode 100644 index 000000000..e69de29bb diff --git a/websites/bitview/scripts/core/elements.js b/websites/bitview/scripts/core/elements.js new file mode 100644 index 000000000..e530a8eb3 --- /dev/null +++ b/websites/bitview/scripts/core/elements.js @@ -0,0 +1,28 @@ +/** + * @param {string} id + */ +function getElementById(id) { + const element = window.document.getElementById(id); + if (!element) throw `Element with id = "${id}" should exist`; + return element; +} + +export default { + head: window.document.getElementsByTagName("head")[0], + body: window.document.body, + main: getElementById("main"), + aside: getElementById("aside"), + asideLabel: getElementById("aside-selector-label"), + navLabel: getElementById(`nav-selector-label`), + searchLabel: getElementById(`search-selector-label`), + search: getElementById("search"), + nav: getElementById("nav"), + searchInput: /** @type {HTMLInputElement} */ (getElementById("search-input")), + searchResults: getElementById("search-results"), + selectors: getElementById("frame-selectors"), + style: getComputedStyle(window.document.documentElement), + charts: getElementById("charts"), + table: getElementById("table"), + explorer: getElementById("explorer"), + simulation: getElementById("simulation"), +}; diff --git a/websites/bitview/scripts/core/env.js b/websites/bitview/scripts/core/env.js new file mode 100644 index 000000000..9c38acef6 --- /dev/null +++ b/websites/bitview/scripts/core/env.js @@ -0,0 +1,24 @@ +const localhost = window.location.hostname === "localhost"; +const standalone = + "standalone" in window.navigator && !!window.navigator.standalone; +const userAgent = navigator.userAgent.toLowerCase(); +const isChrome = userAgent.includes("chrome"); +const safari = userAgent.includes("safari"); +const safariOnly = safari && !isChrome; +const macOS = userAgent.includes("mac os"); +const iphone = userAgent.includes("iphone"); +const ipad = userAgent.includes("ipad"); +const ios = iphone || ipad; + +export default { + standalone, + userAgent, + isChrome, + safari, + safariOnly, + macOS, + iphone, + ipad, + ios, + localhost, +}; diff --git a/websites/bitview/scripts/core/options/full.js b/websites/bitview/scripts/core/options/full.js new file mode 100644 index 000000000..7f6986e16 --- /dev/null +++ b/websites/bitview/scripts/core/options/full.js @@ -0,0 +1,371 @@ +import { createPartialOptions } from "./partial"; + +/** + * @param {Object} args + * @param {Colors} args.colors + * @param {Signals} args.signals + * @param {Env} args.env + * @param {Utilities} args.utils + * @param {VecIdToIndexes} args.vecIdToIndexes + * @param {Pools} args.pools + * @param {Signal} args.qrcode + */ +export function initOptions({ + colors, + signals, + env, + utils, + qrcode, + vecIdToIndexes, + pools, +}) { + const LS_SELECTED_KEY = `selected_path`; + + const urlPath_ = window.document.location.pathname + .split("/") + .filter((v) => v); + const urlPath = urlPath_.length ? urlPath_ : undefined; + const savedPath = /** @type {string[]} */ ( + JSON.parse(utils.storage.read(LS_SELECTED_KEY) || "[]") || [] + ).filter((v) => v); + console.log(savedPath); + + /** @type {Signal