From e9f78e2feceeb1da85b82c2a9e185c96216f2f12 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 23:01:42 -0500 Subject: [PATCH] Miner: show the earned card when a block is accepted Upstream WikiDeck/wikideck#12. After a block is accepted the miner prints the card's title, URL, extract, rarity, proof-derived stats and the at-mint Wikipedia scores, instead of only the block number and NFT id. Co-Authored-By: Claude Opus 5.5 --- server/testnet/miner.ts | 3 ++- server/testnet/reward.ts | 19 +++++++++++++++++++ tests/miner-reward.test.ts | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 server/testnet/reward.ts create mode 100644 tests/miner-reward.test.ts diff --git a/server/testnet/miner.ts b/server/testnet/miner.ts index a2372f9..5891b0f 100644 --- a/server/testnet/miner.ts +++ b/server/testnet/miner.ts @@ -7,6 +7,7 @@ import { blockClaimMessage, CONSENSUS, NETWORK, type MiningTemplate, type Testne import { CHAIN_ID, sha256, miningBlob, mintId, blockSchema } from './consensus.ts'; import { RandomX } from './randomx.ts'; import { assertLaunchAllowed } from '../launch.ts'; +import { rewardSummary } from './reward.ts'; assertLaunchAllowed(); @@ -79,7 +80,7 @@ try { const signature = Buffer.from(await crypto.subtle.sign({name:'ECDSA',hash:'SHA-256'},wallet.privateKey,new TextEncoder().encode(blockClaimMessage(hash)))).toString('base64'); const block: TestnetBlock = { ...header, hash, tokenId:mintId(header), powHash:result.hash, signature, transactions:template.transactions }; blockSchema.parse(block); - try { await api('/api/blocks',block); accepted++; console.log(`Accepted block #${header.height} · NFT ${block.tokenId} · ${accepted}/${limit}`); } + try { await api('/api/blocks',block); accepted++; console.log(`\nAccepted block #${header.height} · ${accepted}/${limit}\n${rewardSummary(block)}`); } catch (e) { console.error((e as Error).message); } solved = true; } else { diff --git a/server/testnet/reward.ts b/server/testnet/reward.ts new file mode 100644 index 0000000..530a629 --- /dev/null +++ b/server/testnet/reward.ts @@ -0,0 +1,19 @@ +import { rarity, stats } from '../../shared/protocol.ts'; +import type { TestnetBlock } from '../../shared/testnet.ts'; + +/** Human-readable summary of the card a miner just earned (upstream WikiDeck/wikideck#12). */ +export function rewardSummary(block: Pick): string { + const { article } = block; + const s = stats(block.powHash); + const snap = block.statsSnapshot?.stats; + const extract = article.extract.length > 160 ? `${article.extract.slice(0, 157).trimEnd()}…` : article.extract; + const lines = [ + `You earned a ${rarity(block.powHash)} card: ${article.title}`, + ` ${article.url}`, + ` ${extract}`, + ` Power ${s.power} · Defense ${s.defense} · Knowledge ${s.knowledge}`, + ]; + if (snap) lines.push(` At mint: attention ${snap.attention ?? '—'} · depth ${snap.depth} · reach ${snap.reach}`); + lines.push(` Block #${block.height} · NFT ${block.tokenId}`); + return lines.join('\n'); +} diff --git a/tests/miner-reward.test.ts b/tests/miner-reward.test.ts new file mode 100644 index 0000000..a4029f5 --- /dev/null +++ b/tests/miner-reward.test.ts @@ -0,0 +1,20 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { rewardSummary } from '../server/testnet/reward.ts'; +import { rarity, stats } from '../shared/protocol.ts'; + +test('miner reward summary names the earned card, its rarity and stats', () => { + const powHash = '000eca7498a26d1908613726da6e869d7c9c936f4a461cb439ef24672b9a0008'; + const text = rewardSummary({ height: 42, tokenId: 'abc123', powHash, + article: { pageId: 1, title: 'Ada Lovelace', extract: 'x'.repeat(300), url: 'https://en.wikipedia.org/wiki/Ada_Lovelace', + revisionId: 1, source: 'live', category: 'People' }, + statsSnapshot: { capturedAt: '2026-11-16T00:00:00Z', revisionId: 1, pageBytes: 1, languageCount: 1, languagesTruncated: false, + pageviews: { status: 'unavailable' } as never, stats: { attention: null, depth: 50, reach: 7 } } }); + const s = stats(powHash); + assert.match(text, new RegExp(`You earned a ${rarity(powHash)} card: Ada Lovelace`)); + assert.match(text, /https:\/\/en\.wikipedia\.org\/wiki\/Ada_Lovelace/); + assert.match(text, new RegExp(`Power ${s.power} · Defense ${s.defense} · Knowledge ${s.knowledge}`)); + assert.match(text, /attention — · depth 50 · reach 7/); + assert.match(text, /Block #42 · NFT abc123/); + assert.ok(text.split('\n')[2].length < 170, 'long extracts are truncated'); +});