v1.47.0: dibujo del flujo de la transacción
Entradas y salidas con grosor proporcional al importe, la transacción como un solo nudo (la cadena no dice qué entrada paga qué salida) y la comisión aparte; marcas sacadas del análisis (cambio y pago probables, polvo, OP_RETURN, vuelta a la misma dirección, tuya, entidad); enlaces deterministas de Boltzmann si ya se calcularon; «+N más» por encima de 12 filas; accesible y con vista en lista. Sustituye al dibujo del cambio. tests/test35.js. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L5npnUYgSPkAaHkdaeUqBr
This commit is contained in:
+130
-27
@@ -8,41 +8,141 @@
|
||||
return <svg width={s} height={s} style={{flexShrink:0}}><circle cx={s/2} cy={s/2} r={r} fill="none" stroke={C.border} strokeWidth={6}/><circle cx={s/2} cy={s/2} r={r} fill="none" stroke={color} strokeWidth={6} strokeDasharray={`${fill} ${circ}`} strokeLinecap="round" transform={`rotate(-90 ${s/2} ${s/2})`}/><text x={s/2} y={s/2+1} textAnchor="middle" dominantBaseline="middle" fill={color} fontSize={centerSize} fontFamily={C.mono} fontWeight="700" letterSpacing="0.05em">{centerText}</text></svg>;
|
||||
}
|
||||
|
||||
// Dibujo de las pistas del cambio (v1.31): cada salida en su caja y, debajo,
|
||||
// las pistas que apuntan a ella. Así se ve de un vistazo si coinciden, se
|
||||
// contradicen o solo hay una — lo que más cuesta entender del análisis.
|
||||
function DiagramaCambio({ tx, pistas }) {
|
||||
// Las pistas del cambio, en texto (v1.31; dibujo hasta la v1.46.0). Desde
|
||||
// la v1.47.0 el dibujo es el del flujo de la transacción, arriba, que
|
||||
// marca el cambio en su salida; aquí queda a qué salida apunta cada pista
|
||||
// y por qué se da (o no) por bueno.
|
||||
function PistasCambio({ tx, pistas }) {
|
||||
if (!pistas || !tx || !Array.isArray(tx.vout)) return null;
|
||||
const { votos = [], reutiliza = null, index = null, conflicto = false } = pistas;
|
||||
if (!votos.length && reutiliza == null) return null;
|
||||
const NOMBRE = { formato: "mismo formato que las entradas", redondo: "la otra salida es cifra redonda (suele ser el pago)" };
|
||||
const salidas = tx.vout.map((o, i) => ({ o, i })).filter(({ o }) => !(o.scriptpubkey_type === "op_return" || (o.scriptpubkey || "").startsWith("6a")));
|
||||
if (salidas.length > 4) return null;
|
||||
const veredicto = reutiliza != null ? "Una salida vuelve a la dirección que gasta: eso decide por sí solo."
|
||||
: conflicto ? "Las pistas apuntan a salidas distintas: se contradicen y no se señala ninguna."
|
||||
: votos.length >= 2 ? "Las dos pistas apuntan a la misma salida: por eso se da como probable."
|
||||
: "Solo hay una pista: no basta para afirmar cuál es el cambio.";
|
||||
const filas = [];
|
||||
if (reutiliza != null) filas.push([reutiliza, "vuelve a la dirección que gasta"]);
|
||||
votos.forEach(v => filas.push([v.idx, PISTA_FLUJO[v.señal] || v.señal]));
|
||||
return (
|
||||
<div style={{marginTop:10,padding:"10px 12px",background:C.bg,border:`1px solid ${C.border}`,borderRadius:6}}>
|
||||
<div style={{fontSize:"0.58rem",color:C.t2,fontFamily:C.mono,letterSpacing:"0.12em",marginBottom:8}}>PISTAS · A QUÉ SALIDA APUNTA CADA UNA<NotaDesdeCero/></div>
|
||||
<div style={{display:"grid",gridTemplateColumns:`repeat(${salidas.length},minmax(0,1fr))`,gap:8}}>
|
||||
{salidas.map(({ o, i }) => {
|
||||
const aqui = votos.filter(v => v.idx === i).map(v => NOMBRE[v.señal] || v.señal);
|
||||
if (reutiliza === i) aqui.unshift("vuelve a la dirección que gasta");
|
||||
const marcada = index === i;
|
||||
return (
|
||||
<div key={i} style={{padding:"8px",border:`1px solid ${marcada?C.amber:C.borderBright}`,borderRadius:6,background:marcada?C.amberMuted:"none",minWidth:0}}>
|
||||
<div style={{fontSize:"0.62rem",color:C.t1,fontFamily:C.mono,fontWeight:700}}>Salida {i}{marcada?" · cambio":""}</div>
|
||||
<div style={{fontSize:"0.6rem",color:C.t2,fontFamily:C.mono,marginTop:2,wordBreak:"break-word"}}>{fmtBtc(o.value)}</div>
|
||||
<div style={{fontSize:"0.56rem",color:C.t3,fontFamily:C.mono,marginTop:2}}>{formatoDir(o.scriptpubkey_type)}</div>
|
||||
<div style={{marginTop:6,display:"flex",flexDirection:"column",gap:3}}>
|
||||
{aqui.length ? aqui.map((t, k) => <div key={k} style={{fontSize:"0.58rem",color:C.amber,lineHeight:1.35}}>← {t}</div>)
|
||||
: <div style={{fontSize:"0.58rem",color:C.t3}}>ninguna pista</div>}
|
||||
</div>
|
||||
</div>);
|
||||
})}
|
||||
</div>
|
||||
<div style={{marginTop:8,fontSize:"0.64rem",color:C.t1,lineHeight:1.5}}>{veredicto}</div>
|
||||
<div style={{fontSize:"0.58rem",color:C.t2,fontFamily:C.mono,letterSpacing:"0.12em",marginBottom:6}}>PISTAS · A QUÉ SALIDA APUNTA CADA UNA<NotaDesdeCero/></div>
|
||||
{filas.map(([i, t], k) => (
|
||||
<div key={k} style={{fontSize:"0.64rem",color:C.t1,fontFamily:C.mono,lineHeight:1.6}}>
|
||||
<span style={{color:index===i?C.amber:C.t1,fontWeight:700}}>Salida {i}</span>{tx.vout[i]?<span style={{color:C.t2}}> ({fmtBtc(tx.vout[i].value)})</span>:null} ← {t}
|
||||
</div>))}
|
||||
<div style={{marginTop:6,fontSize:"0.64rem",color:C.t1,lineHeight:1.5}}>{veredicto} <span style={{color:C.t2}}>En el dibujo del flujo, arriba, la salida señalada va marcada.</span></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Dibujo del flujo de la transacción (v1.47.0). La geometría y las marcas
|
||||
// salen de geometriaFlujo (17-flujo.js); aquí solo se pinta. Plegable:
|
||||
// abierto en escritorio, plegado en móvil.
|
||||
function DiagramaFlujo({ tx, analysis, myAddr, bz }) {
|
||||
const isMobile = useIsMobile();
|
||||
const [abierto, setAbierto] = useState(!isMobile);
|
||||
const [verLista, setVerLista] = useState(false);
|
||||
const caja = useRef(null);
|
||||
const [ancho, setAncho] = useState(null);
|
||||
useEffect(() => {
|
||||
const el = caja.current;
|
||||
if (!el) return;
|
||||
const medir = () => { const w = el.clientWidth; if (w) setAncho(w); };
|
||||
medir();
|
||||
if (typeof ResizeObserver === "undefined") { window.addEventListener("resize", medir); return () => window.removeEventListener("resize", medir); }
|
||||
const ro = new ResizeObserver(medir); ro.observe(el);
|
||||
return () => ro.disconnect();
|
||||
}, [abierto]);
|
||||
const w = ancho || (isMobile ? 340 : 760);
|
||||
const g = useMemo(() => (tx && analysis) ? geometriaFlujo(tx, analysis, {
|
||||
ancho: w, movil: w < 600,
|
||||
esMia: typeof myAddr === "function" ? myAddr : null,
|
||||
entidadDe: a => (a && typeof ENTITY_INDEX !== "undefined" && ENTITY_INDEX.get(a)) || null,
|
||||
boltzmann: bz,
|
||||
}) : null, [tx, analysis, w, myAddr, bz]);
|
||||
if (!g) return null;
|
||||
const col = t => C[t] || C.t2;
|
||||
const tonoFila = f => {
|
||||
const ids = f.marcas.map(m => m.id);
|
||||
if (ids.includes("cambio")) return C.amber;
|
||||
if (ids.includes("tuya") || ids.includes("ficticia")) return ids.includes("ficticia") ? C.amber : C.green;
|
||||
if (ids.includes("pago")) return C.blue;
|
||||
if (ids.includes("op_return")) return C.t3;
|
||||
if (f.grupo || f.lado === "comision") return C.t3;
|
||||
return C.t2;
|
||||
};
|
||||
const fs = g.movil ? 9.5 : 10;
|
||||
const titulo = f => [
|
||||
f.coinbase ? f.nombre : f.grupo ? `${f.nombre} (${f.indices.join(", ")})` : f.nombre,
|
||||
f.importe,
|
||||
f.direccion ? `${f.direccion} — ${f.formato}` : f.dirTxt,
|
||||
...f.marcas.map(m => `${m.texto}: ${m.detalle}`),
|
||||
].filter(Boolean).join("\n");
|
||||
const etiqueta = (f, k) => (
|
||||
<text key={"t"+k} x={f.xEtiq} textAnchor={f.ancla} fontFamily={C.mono} fontSize={fs}>
|
||||
{f.lineas.map((linea, n) => (
|
||||
<tspan key={n} x={f.xEtiq} y={f.yEtiq + g.lineaAlto * (n + 0.78)}>
|
||||
{linea.map((p, q) => (
|
||||
<React.Fragment key={q}>
|
||||
{q > 0 && <tspan fill={C.t3}> · </tspan>}
|
||||
{p.letra && <tspan fill={C.purple} fontWeight="700">{p.letra} </tspan>}
|
||||
<tspan fill={col(p.tono)} fontWeight={p.negrita || p.marca ? 700 : 400}>{p.t}</tspan>
|
||||
</React.Fragment>))}
|
||||
</tspan>))}
|
||||
</text>
|
||||
);
|
||||
const derecha = [...g.salidas, ...(g.comision ? [g.comision] : [])];
|
||||
const textoFila = f => [f.nombre, f.importe, f.direccion || f.dirTxt, ...(f.extra ? [f.extra] : [])].filter(Boolean).join(" · ") + (f.marcas.length ? " — " + f.marcas.map(m => m.texto).join(", ") : "");
|
||||
return (
|
||||
<div style={{marginBottom:10}}>
|
||||
<button onClick={()=>setAbierto(!abierto)} aria-expanded={abierto} style={{
|
||||
width:"100%",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8,
|
||||
padding:"10px 14px",background:C.bgCard,border:`1px solid ${abierto?C.purple+"60":C.border}`,
|
||||
borderRadius:abierto?"6px 6px 0 0":6,cursor:"pointer",color:C.purple,fontFamily:C.mono,fontSize:"0.68rem",fontWeight:700,
|
||||
letterSpacing:"0.1em",textTransform:"uppercase",textAlign:"left",
|
||||
}}>
|
||||
<span>Flujo de la transacción{g.simulada?" · simulación":""}</span>
|
||||
<span style={{fontSize:"0.7rem"}}>{abierto?"▲":"▼"}</span>
|
||||
</button>
|
||||
{abierto&&(
|
||||
<div style={{background:C.bgCard,border:`1px solid ${C.purple}30`,borderTop:"none",borderRadius:"0 0 6px 6px",padding:isMobile?"10px 8px":"12px 14px"}}>
|
||||
{g.simulada&&<div style={{marginBottom:8,fontSize:"0.6rem",fontFamily:C.mono,color:C.amber,fontWeight:700,letterSpacing:"0.08em"}}>SIMULACIÓN · no es una transacción real; el cambio y la comisión son estimados</div>}
|
||||
<div ref={caja} style={{width:"100%"}}>
|
||||
<svg role="img" aria-label={g.aria} width={g.ancho} height={g.alto} viewBox={`0 0 ${g.ancho} ${g.alto}`} style={{display:"block",maxWidth:"100%",overflow:"visible"}}>
|
||||
<text x={g.columnas.xIn + 10} y={11} textAnchor="end" fontFamily={C.mono} fontSize={9} fill={C.t2} letterSpacing="0.1em">{g.coinbase?"ORIGEN":"ENTRADAS"}</text>
|
||||
<text x={g.columnas.xOut} y={11} textAnchor="start" fontFamily={C.mono} fontSize={9} fill={C.t2} letterSpacing="0.1em">SALIDAS</text>
|
||||
{g.entradas.map((f,k)=><path key={"bi"+k} d={f.banda} fill={C.t2} fillOpacity={0.22}/>)}
|
||||
{derecha.map((f,k)=>f.lado==="comision"
|
||||
? <path key={"bo"+k} d={f.banda} fill={C.t3} fillOpacity={0.25} stroke={C.t3} strokeWidth={0.8} strokeDasharray="3 2"/>
|
||||
: <path key={"bo"+k} d={f.banda} fill={tonoFila(f)} fillOpacity={f.grupo?0.18:0.3}/>)}
|
||||
{g.enlaces.map((e,k)=><path key={"en"+k} d={e.d} fill="none" stroke={C.amber} strokeWidth={1.6} strokeDasharray="5 3"/>)}
|
||||
<rect x={g.nudo.x} y={g.nudo.y} width={g.nudo.ancho} height={Math.max(2,g.nudo.alto)} rx={2} fill={C.purple}/>
|
||||
{[...g.entradas, ...derecha].map((f,k)=>(
|
||||
<g key={"f"+k}>
|
||||
<title>{titulo(f)}</title>
|
||||
<rect x={f.x} y={f.y} width={f.ancho} height={f.alto} rx={1.5} fill={f.lado==="entrada"&&!f.coinbase?(f.marcas.some(m=>m.id==="tuya")?C.green:f.grupo?C.t3:C.t2):f.coinbase?C.amber:tonoFila(f)}/>
|
||||
{etiqueta(f,k)}
|
||||
</g>))}
|
||||
</svg>
|
||||
</div>
|
||||
<div style={{marginTop:8,fontSize:"0.64rem",color:C.t2,lineHeight:1.6}}>
|
||||
El grosor es el importe. La cadena no dice qué entrada paga qué salida: solo que todas las entradas juntas pagan todas las salidas.{g.coinbase?" Aquí no hay entradas: son monedas nuevas que crea el minero (subsidio más comisiones del bloque).":""} Se cuentan desde 0.
|
||||
</div>
|
||||
{g.letras.length>0&&<div style={{marginTop:4,fontSize:"0.6rem",color:C.t2,fontFamily:C.mono,lineHeight:1.6}}>{g.letras.map((l,k)=><span key={l.letra} style={{whiteSpace:"nowrap"}}>{k>0?" · ":""}<b style={{color:C.purple}}>{l.letra}</b> {l.formato}</span>)}</div>}
|
||||
{g.notas.map((n,k)=><div key={k} style={{marginTop:4,fontSize:"0.64rem",color:C.t1,lineHeight:1.5}}>{n}</div>)}
|
||||
<div style={{marginTop:6,display:"flex",gap:10,alignItems:"center",flexWrap:"wrap"}}>
|
||||
<button onClick={()=>setVerLista(!verLista)} aria-expanded={verLista} style={{background:"none",border:"none",padding:"4px 0",color:C.purple,fontFamily:C.mono,fontSize:"0.64rem",cursor:"pointer",minHeight:isMobile?36:undefined}}>
|
||||
{verLista?"▲":"▼"} Ver como lista
|
||||
</button>
|
||||
{!isMobile&&<span style={{fontSize:"0.6rem",color:C.t3}}>Pasa el ratón por una fila para ver la dirección entera y el porqué de cada marca.</span>}
|
||||
</div>
|
||||
{verLista&&(
|
||||
<div style={{marginTop:4,display:"flex",flexDirection:"column",gap:2,fontFamily:C.mono,fontSize:"0.62rem",color:C.t1,lineHeight:1.5}}>
|
||||
{[...g.entradas, ...derecha].map((f,k)=><div key={k} style={{wordBreak:"break-word"}}>{textoFila(f)}</div>)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -261,7 +361,7 @@
|
||||
{expanded===check.id&&(
|
||||
<div style={{padding:"0 14px 12px 14px",borderTop:`1px solid ${C.border}`}}>
|
||||
<div style={{fontSize:"0.7rem",color:C.t2,lineHeight:1.6,paddingTop:10}}>{check.detail}</div>
|
||||
{check.id==="change_detection"&&tx&&<DiagramaCambio tx={tx} pistas={check.pistas}/>}
|
||||
{check.id==="change_detection"&&tx&&<PistasCambio tx={tx} pistas={check.pistas}/>}
|
||||
{check.id==="coinjoin"&&bz&&bz.completo&&(
|
||||
<div style={{marginTop:6,fontSize:"0.66rem",color:C.t2,lineHeight:1.6}}>Contando solo los importes (entropía de Boltzmann): {resumenBoltzmann(bz).titulo.replace(/^Esta transacción admite /,"")}.</div>
|
||||
)}
|
||||
@@ -468,6 +568,9 @@
|
||||
{lm.otros.length>0&&<div style={{marginTop:8,fontSize:"0.64rem",color:C.t2,lineHeight:1.5}}>Además, {ajena?"expone a quien interviene":"te expone"} algo que decidió otro: {lm.otros.join(" · ")}.</div>}
|
||||
</div>); })()}
|
||||
|
||||
{/* Flujo de la transacción (v1.47.0): arriba de las señales. */}
|
||||
{tx&&<DiagramaFlujo tx={tx} analysis={analysis} myAddr={myAddr} bz={bz}/>}
|
||||
|
||||
{/* Informe narrativo — colapsable */}
|
||||
<div style={{marginBottom:10}}>
|
||||
<button onClick={()=>setShowReport(!showReport)} style={{
|
||||
|
||||
Reference in New Issue
Block a user