Compare commits

...
Author SHA1 Message Date
claudeandClaude Opus 5.5 e9f78e2fec 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 <noreply@anthropic.com>
2026-11-16 23:01:42 -05:00
3 changed files with 41 additions and 1 deletions
+2 -1
View File
@@ -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 {
+19
View File
@@ -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<TestnetBlock, 'height' | 'tokenId' | 'powHash' | 'article' | 'statsSnapshot'>): 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');
}
+20
View File
@@ -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');
});