global: opreturn part 5

This commit is contained in:
nym21
2026-07-19 18:19:48 +02:00
parent 0fc61d7932
commit 3af673132a
10 changed files with 523 additions and 454 deletions
+176 -80
View File
@@ -1,7 +1,7 @@
import { colors } from "../../utils/colors.js";
import { brk } from "../../utils/client.js";
import { Unit } from "../../utils/units.js";
import { chartsFromCount, line } from "../series.js";
import { chartsFromCount, line, percentRatio } from "../series.js";
import { groupedWindowsCumulative } from "../shared.js";
const TYPE_DEFINITIONS = /** @type {const} */ ([
@@ -32,9 +32,9 @@ const TYPE_DEFINITIONS = /** @type {const} */ ([
const METRICS = /** @type {const} */ ([
{
key: "carrierTxCount",
key: "txCount",
name: "Transactions",
title: "Carrier Transaction Count",
title: "Transaction Count",
unit: Unit.count,
},
{
@@ -44,24 +44,32 @@ const METRICS = /** @type {const} */ ([
unit: Unit.count,
},
{
key: "carrierVsize",
name: "vBytes",
title: "Carrier Transaction vBytes",
unit: Unit.vb,
},
{
key: "postOpReturnBytes",
name: "Data",
key: "dataBytes",
name: "Data Bytes",
title: "Data Bytes",
unit: Unit.bytes,
},
{
key: "txVsize",
name: "Transaction vSize",
title: "Transaction vSize",
unit: Unit.vb,
},
]);
/** @typedef {(typeof brk.series.opReturn.byKind)[keyof typeof brk.series.opReturn.byKind]} OpReturnMetrics */
/**
* @typedef {Object} OpReturnEntry
* @property {string} name
* @property {Color} color
* @property {boolean} [defaultActive]
* @property {OpReturnMetrics} pattern
*/
/**
* @param {Object} args
* @param {readonly { name: string, color: Color, defaultActive: boolean, pattern: OpReturnMetrics }[]} args.list
* @param {readonly OpReturnEntry[]} args.list
* @param {string} args.category
* @returns {PartialOptionsTree}
*/
@@ -82,23 +90,123 @@ function createComparisons({ list, category }) {
}));
}
/**
* @param {Object} args
* @param {OpReturnMetrics} args.pattern
* @param {string} args.name
* @param {Color} args.color
* @returns {PartialOptionsTree}
*/
function createMetrics({ pattern, name, color }) {
return METRICS.map((metric) => ({
name: metric.name,
tree: chartsFromCount({
pattern: pattern[metric.key],
metric: `OP_RETURN ${name} ${metric.title}`,
unit: metric.unit,
color,
}),
}));
}
/**
* @param {Object} args
* @param {readonly OpReturnEntry[]} args.list
* @param {string} args.category
* @param {string} [args.subject]
* @returns {PartialOptionsTree}
*/
function createShares({ list, category, subject }) {
const shares = /** @type {const} */ ([
{
key: "dataShare",
name: "OP_RETURN Share",
title: subject
? `Cumulative ${subject} Share of OP_RETURN Data`
: `Cumulative OP_RETURN Data Share by ${category}`,
},
{
key: "chainShare",
name: "Blockchain Share",
title: subject
? `Cumulative ${subject} OP_RETURN Data Share of Blockchain`
: `Cumulative Blockchain Share by OP_RETURN ${category}`,
},
]);
return shares.map(({ key, name: shareName, title }) => ({
name: shareName,
title,
bottom: list.flatMap(({ name, color, defaultActive, pattern }) =>
percentRatio({
pattern: pattern[key],
name,
color,
defaultActive,
}),
),
}));
}
/**
* @param {Object} args
* @param {readonly OpReturnEntry[]} args.list
* @param {string} args.name
* @param {string} args.category
* @returns {PartialOptionsGroup}
*/
function createBreakdown({ name, list, category }) {
return {
name,
tree: [
{
name: "Compare",
tree: [
...createComparisons({ list, category }),
...createShares({ list, category }),
],
},
...list.map(({ name, color, pattern }) => ({
name,
tree: [
...createMetrics({ pattern, name, color }),
...createShares({
list: [{ name, color, pattern }],
category,
subject: name,
}),
],
})),
],
};
}
/** @returns {PartialOptionsGroup} */
export function createOpReturnSection() {
const opReturn = brk.series.opReturn;
const outputCount = brk.series.outputs.byType.outputCount.opReturn;
const types = TYPE_DEFINITIONS.map((type, index) => ({
...type,
color: colors.at(index, TYPE_DEFINITIONS.length),
pattern: opReturn.byKind[type.key],
}));
const policies = [
const policyClassifications = [
{
name: "Standard",
color: colors.profit,
defaultActive: true,
pattern: opReturn.policy.standard,
pattern: opReturn.policy.preV30Standard,
},
{
name: "Oversized",
name: "Nonstandard",
color: colors.loss,
defaultActive: true,
pattern: opReturn.policy.preV30Nonstandard,
},
];
const nonstandardReasons = [
{
name: "Over 82 Bytes",
color: colors.loss,
defaultActive: true,
pattern: opReturn.policy.oversized,
@@ -109,82 +217,70 @@ export function createOpReturnSection() {
defaultActive: true,
pattern: opReturn.policy.multiple,
},
{
name: "Pre-v30 Nonstandard",
color: colors.gray,
defaultActive: true,
pattern: opReturn.policy.preV30Nonstandard,
},
];
return {
name: "OP_RETURN",
tree: [
{
name: "Total",
tree: [
{
name: "Transactions",
tree: chartsFromCount({
pattern: opReturn.total.carrierTxCount,
metric: "OP_RETURN Carrier Transaction Count",
unit: Unit.count,
color: colors.scriptType.opReturn,
}),
},
{
name: "vBytes",
tree: chartsFromCount({
pattern: opReturn.total.carrierVsize,
metric: "OP_RETURN Carrier Transaction vBytes",
unit: Unit.vb,
color: colors.scriptType.opReturn,
}),
},
{
name: "Data",
tree: chartsFromCount({
pattern: opReturn.total.postOpReturnBytes,
metric: "OP_RETURN Data Bytes",
unit: Unit.bytes,
color: colors.scriptType.opReturn,
}),
},
{
name: "Share",
title: "Cumulative OP_RETURN Data Share of Blockchain Size",
bottom: [
line({
series: opReturn.total.dataShare.percent,
name: "OP_RETURN Data",
color: colors.scriptType.opReturn,
unit: Unit.percentage,
}),
],
},
],
name: "Transactions",
tree: chartsFromCount({
pattern: opReturn.total.txCount,
metric: "OP_RETURN Transaction Count",
unit: Unit.count,
color: colors.scriptType.opReturn,
}),
},
{
name: "Type",
tree: createComparisons({ list: types, category: "Type" }),
name: "Outputs",
tree: chartsFromCount({
pattern: outputCount,
metric: "OP_RETURN Output Count",
unit: Unit.count,
color: colors.scriptType.opReturn,
}),
},
{
name: "Policy",
name: "Data Bytes",
tree: chartsFromCount({
pattern: opReturn.total.dataBytes,
metric: "OP_RETURN Data Bytes",
unit: Unit.bytes,
color: colors.scriptType.opReturn,
}),
},
{
name: "Transaction vSize",
tree: chartsFromCount({
pattern: opReturn.total.txVsize,
metric: "OP_RETURN Transaction vSize",
unit: Unit.vb,
color: colors.scriptType.opReturn,
}),
},
{
name: "Blockchain Share",
title: "Cumulative OP_RETURN Data Share of Blockchain Size",
bottom: percentRatio({
pattern: opReturn.total.chainShare,
name: "OP_RETURN Data",
color: colors.scriptType.opReturn,
}),
},
createBreakdown({ name: "Types", list: types, category: "Type" }),
{
name: "Pre-v30 Policy",
tree: [
{
name: "Share",
title: "Cumulative OP_RETURN Data Share of Blockchain Size by Policy",
bottom: policies.map(({ name, color, defaultActive, pattern }) =>
line({
series: pattern.dataShare.percent,
name,
color,
defaultActive,
unit: Unit.percentage,
}),
),
},
...createComparisons({ list: policies, category: "Policy" }),
createBreakdown({
name: "Classification",
list: policyClassifications,
category: "Pre-v30 Policy",
}),
createBreakdown({
name: "Nonstandard Reasons",
list: nonstandardReasons,
category: "Pre-v30 Nonstandard Reason",
}),
],
},
],