VBB purchases live + weekly prize payouts (Marty 2026-11-14: "why does it say 'coming soon' on all the stuff in it? Shouldn't it all be live already?")
Buying (VBBShop 0x36F6...07D7): Packages page has live Buy buttons for the 10 and 40 credit packs (USD price + live POL from quoteWei, SafePal or any other crypto wallet, one-time, never a subscription, where the payment goes); My Banners has "Add the banner look ($2)" on each waiting or in-loop banner (SKU 3, ref = banner id) and a 40-character teaser editor once it has the look. POST /api/my/order builds the member's buy() call on the server (fresh keeper voucher when the hub knows their sponsor, else no sponsor); the page checks the connected wallet is the member's VBB account (explains how to switch if not), checks the balance, sends with Polygon's fee floor (/api/gas), waits on /api/tx, nudges the watcher (/api/my/paid) and polls until the credits or the look arrive. Public: /api/quote, /api/gas, /api/tx/<hash>; /api/config has shop {live, contract} + explorer. The banner look on the loop: double border + star, hover teaser (always shown on touch screens; default = the link's site). Only Tokens still says coming soon. wallet.js gains sendTx/waitTx/balance (DLB flow).
Weekly prize payouts (prize.js): each Central-time week's pot = 10% of its VBBShop sales (usdCents of Purchase events by block time), $20 floor (company top-up shown to admin), $50 cap internal, half per board, 50/30/20. Every Monday the app prepares last week's plan (winners, wallets, USD; POL quoted live from the Chainlink feed the contract uses). /admin "Approve and pay" (two clicks): refuses unless PRIZE_KEY is the contract's prizeWallet(), the feed is fresh and the wallet holds the POL + gas (says how much more to send); then once per week (docstore.claim in MySQL + plan status), consecutive nonces, each hash saved as sent, stops at the first unclear send (never auto-retried), receipts watched. Ties: earlier to reach the count wins (leaderboards use the same rule). A winner that cannot be paid (the prize or company wallet) is skipped and the rest move up; an unfilled place stays in the prize wallet. /leaders shows past winners with transaction links. Posts nothing anywhere. Compose passes PRIZE_KEY.
Tests: smoke 192/192 (stand-in chain answers quoteWei + receipts: quote, order calldata + voucher, look purchase, teaser, prizes API, UI Buy buttons). New qa/chain.mjs on a local anvil with the real VBBShop + mock feed: buy -> Purchase -> credits, voucher binds sponsor, 30/10/60 split, overpay refunded, banner look; prize prepare -> short refusal -> pay 6 transfers exact POL -> paid once: 29/29. common.js?v=3, vbb.css?v=4.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// Viral Banner Blitz web app (viralbannerblitz.com rebuild, "VBB"). Plain Node http server, no framework (the InstantAdPay and
|
||||
// Downline Banners pattern). v1 is off-chain: no contract, no prices, no money.
|
||||
// VBBShop hooks (shop.js): GET /api/my/voucher signs a sponsor voucher; the purchase watcher credits packs. Both inert until configured.
|
||||
// Downline Banners pattern). Purchases are live through VBBShop (2026-11-14): POST /api/my/order builds the member's buy() call
|
||||
// (with a fresh sponsor voucher when the hub knows their sponsor), the member's wallet sends it, the purchase watcher (shop.js)
|
||||
// credits packs and banner looks. Weekly prize payouts: prize.js (prepared automatically, paid only on an admin's approval).
|
||||
// Pages: / (splash: the loop, the next-shift bar, the queue), /my (My Banners), /leaders, /how, /packages, /admin.
|
||||
// Engine: loop.js. Data: store.js on docstore.js (MySQL when DOCSTORE_URL is set). Checks: safety.js. Network sign-in: networksso.js.
|
||||
'use strict';
|
||||
@@ -21,6 +22,7 @@ const networksso = require('./networksso');
|
||||
const shop = require('./shop');
|
||||
const promokit = require('./promokit'); // promo kit feed /api/promo-kit + the /promote page (2026-11-14)
|
||||
const hubreport = require('./hubreport'); // network hub report by wallet (off unless HUB_ENABLED)
|
||||
const prize = require('./prize');
|
||||
|
||||
const PUB = path.join(__dirname, 'public');
|
||||
const UPL = path.join(C.dataDir, 'uploads');
|
||||
@@ -160,7 +162,8 @@ function grantDaily(m) {
|
||||
}
|
||||
function myData(addr) {
|
||||
const m = store.member(addr);
|
||||
const banners = store.bannersOf(addr).slice().reverse().map(b => Object.assign({ id: b.id, img: b.img, link: b.link, createdAt: b.createdAt, cycledAt: b.cycledAt || null, clicks: b.clicks || 0 }, loop.placeOf(b)));
|
||||
const banners = store.bannersOf(addr).slice().reverse().map(b => Object.assign({ id: b.id, img: b.img, link: b.link, createdAt: b.createdAt, cycledAt: b.cycledAt || null, clicks: b.clicks || 0,
|
||||
look: !!b.look, teaser: b.look ? (b.teaser || '') : '', teaserDefault: loop.hostOf(b.link) }, loop.placeOf(b)));
|
||||
const rewards = store.ledger().filter(e => e.owner === m.address);
|
||||
const shareName = m.username || m.address;
|
||||
return { address: m.address, username: m.username, credits: m.credits, freeCreditCap: C.freeCreditCap, freeToday: m.freeDay === store.ctDay(), netVerified: netVerified(m),
|
||||
@@ -261,18 +264,30 @@ const server = http.createServer(async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
// this week's prize pot. v1 takes no payments, so week sales are 0 and the pot sits at the floor until the contract step.
|
||||
function prizes(weekSalesUsd = 0) {
|
||||
const z = C.prizePot; const pot = Math.min(z.capUsd, Math.max(z.floorUsd, weekSalesUsd * z.pct / 100));
|
||||
const board = pot / 2, r2 = x => Math.round(x * 100) / 100, per = z.places.map(x => r2(board * x / 100));
|
||||
return { pot: r2(pot), atFloor: pot <= z.floorUsd, visitors: per, sources: per };
|
||||
}
|
||||
// this week's prize pot from this week's VBBShop sales (prize.js); the cap is never shown
|
||||
function prizes() { const z = prize.pot(store.ctWeek()); return { pot: z.potUsd, atFloor: z.atFloor, visitors: z.places, sources: z.places }; }
|
||||
// -- public API
|
||||
if (p === '/api/config' && req.method === 'GET') {
|
||||
return json(res, 200, { site: C.site, siteName: C.siteName, chainId: C.chainId, chainName: C.chainName, rpc: C.publicRpc, walletConnectProjectId: C.walletConnectProjectId,
|
||||
loopSize: C.loopSize, perShift: C.perShift, viewsPerCycle: C.viewsPerCycle, visitSeconds: C.visitSeconds, freeCreditCap: C.freeCreditCap, maxQueued: C.maxQueuedPerMember,
|
||||
freeCreditsPerDay: C.freeCreditsPerDay, packs: C.packs, lookUsd: C.lookUsd, prizes: prizes(), sso: networksso.enabled() });
|
||||
freeCreditsPerDay: C.freeCreditsPerDay, packs: C.packs, lookUsd: C.lookUsd, lookSku: C.lookSku, prizes: prizes(), sso: networksso.enabled(),
|
||||
shop: { live: shop.watching(), contract: shop.watching() ? C.contractAddress : null }, explorer: C.explorer });
|
||||
}
|
||||
// buying: the live price, gas fees for the wallet, and the confirmation wait (the Downline Banners endpoints)
|
||||
if (p === '/api/quote' && req.method === 'GET') {
|
||||
if (!shop.watching()) return json(res, 503, { error: 'Purchases are not open.' });
|
||||
if (limited(req, 'quote', 600, 3600000)) return json(res, 429, { error: 'Too many requests this hour.' });
|
||||
const sku = Number(u.searchParams.get('sku')), qty = Number(u.searchParams.get('qty') || 1);
|
||||
if (!validSku(sku) || !Number.isInteger(qty) || qty < 1 || qty > (sku === C.lookSku ? 1 : 10)) return json(res, 400, { error: 'Unknown package.' });
|
||||
try { return json(res, 200, Object.assign({ usd: skuUsd(sku) * qty }, await shop.quote(sku, qty))); } catch (e) { return json(res, 503, { error: 'Price unavailable right now. Try again in a minute.' }); }
|
||||
}
|
||||
if (p === '/api/gas' && req.method === 'GET') { try { return json(res, 200, shop.watching() ? await shop.fees() : {}); } catch (e) { return json(res, 200, {}); } }
|
||||
if (/^\/api\/tx\/0x[0-9a-fA-F]{64}$/.test(p) && req.method === 'GET') {
|
||||
if (!shop.watching() || limited(req, 'tx', 1200, 3600000)) return json(res, 200, { found: false });
|
||||
try { return json(res, 200, await shop.receipt(p.slice(8))); } catch (e) { return json(res, 200, { found: false }); }
|
||||
}
|
||||
// past weeks' prize winners with their transactions (paid weeks only)
|
||||
if (p === '/api/prizes' && req.method === 'GET') return json(res, 200, { current: prizes(), week: store.ctWeek(), past: prize.history(12), explorer: C.explorer }, { 'Cache-Control': 'public, max-age=30' });
|
||||
if (p === '/api/splash' && req.method === 'GET') return json(res, 200, loop.view(24), { 'Cache-Control': 'no-store' });
|
||||
if (p === '/api/leaders' && req.method === 'GET') {
|
||||
const out = loop.leaders(null, 10);
|
||||
@@ -355,6 +370,40 @@ const server = http.createServer(async (req, res) => {
|
||||
if (!sp || sp === me) return json(res, 200, { voucher: null, why: 'no-sponsor' });
|
||||
return json(res, 200, { voucher: await shop.voucher(me, sp) });
|
||||
}
|
||||
// a purchase: the buy() call for the member's own wallet. Packs: SKUs from config. Banner look: one of their own banners that
|
||||
// is waiting or in the loop and has no look yet (ref = the banner id). A fresh sponsor voucher when the hub knows the sponsor.
|
||||
if (p === '/api/my/order' && req.method === 'POST') {
|
||||
if (!shop.watching()) return json(res, 503, { error: 'Purchases are not open yet.' });
|
||||
if (limited(req, 'order', 60, 3600000)) return json(res, 429, { error: 'Too many requests this hour.' });
|
||||
const b = await readBody(req); const sku = Number(b.sku); const qty = Number(b.qty || 1); let ref = 0;
|
||||
if (!validSku(sku)) return json(res, 400, { error: 'Unknown package.' });
|
||||
if (sku === C.lookSku) {
|
||||
const bn = store.banner(b.ref);
|
||||
if (!bn || bn.owner !== me) return json(res, 400, { error: 'That banner is not yours.' });
|
||||
if (bn.look) return json(res, 400, { error: 'That banner already has the look.' });
|
||||
if (bn.state === 'cycled') return json(res, 400, { error: 'That banner has already cycled. Add the look to a banner that is waiting or in the loop.' });
|
||||
if (qty !== 1) return json(res, 400, { error: 'One look per banner.' });
|
||||
ref = bn.id;
|
||||
} else if (!Number.isInteger(qty) || qty < 1 || qty > 10) return json(res, 400, { error: 'Pick 1 to 10 packs.' });
|
||||
let v = null, why = null;
|
||||
if (shop.voucherOn()) {
|
||||
const h = await hubSponsorWallet(me).catch(() => ({ ok: false }));
|
||||
if (!h.ok) why = 'hub-unavailable'; else if (!h.sponsor || h.sponsor === me) why = 'no-sponsor'; else v = await shop.voucher(me, h.sponsor);
|
||||
} else why = 'off';
|
||||
try { return json(res, 200, Object.assign({ buyer: me, usd: skuUsd(sku) * qty, sku, qty, ref, why }, await shop.order(me, sku, qty, ref, v))); }
|
||||
catch (e) { return json(res, 503, { error: 'Price unavailable right now. Try again in a minute.' }); }
|
||||
}
|
||||
// the member's transaction confirmed: scan the chain now (credits still wait for the confirmations)
|
||||
if (p === '/api/my/paid' && req.method === 'POST') { shop.nudge(); return json(res, 200, { ok: true, confirmations: C.shopConfirmations }); }
|
||||
// the hover teaser of a banner with the look: up to 40 characters of plain text ('' = the link's site)
|
||||
const tm = /^\/api\/my\/banners\/(\d{1,9})\/teaser$/.exec(p);
|
||||
if (tm && req.method === 'POST') {
|
||||
const bn = store.banner(tm[1]); if (!bn || bn.owner !== me) return json(res, 404, { error: 'Not found' });
|
||||
if (!bn.look) return json(res, 400, { error: 'Add the banner look first.' });
|
||||
const t = String((await readBody(req)).teaser || '').replace(/[\u0000-\u001f\u007f<>]/g, '').replace(/\s+/g, ' ').trim();
|
||||
if (t.length > 40) return json(res, 400, { error: 'Keep the teaser to 40 characters.' });
|
||||
bn.teaser = t; store.saveBanner(bn); return json(res, 200, { ok: true, teaser: t || loop.hostOf(bn.link) });
|
||||
}
|
||||
if (p === '/api/my/upload' && req.method === 'POST') {
|
||||
if (limited(req, 'upload', 40, 3600000)) return json(res, 429, { error: 'Too many uploads this hour.' });
|
||||
let buf; try { buf = await readRaw(req, safety.MAX_UPLOAD + 1); } catch (e) { return json(res, 400, { error: 'The file is over 100 KB.' }); }
|
||||
@@ -396,7 +445,7 @@ const server = http.createServer(async (req, res) => {
|
||||
queue: { length: S.queue.length, next: S.queue.slice(0, 20) }, progress: S.progress, held: S.progress >= C.perShift && !S.queue.length,
|
||||
today: { visits: t.visits || 0, shifts: t.shifts || 0, cycles: t.cycles || 0, posts: t.posts || 0, clicks: t.clicks || 0 },
|
||||
totals: S.totals, ledger: { entries: L.length, views: L.reduce((x, e) => x + e.views, 0), viewsByStatus: byStatus, credited: 0 },
|
||||
members: store.members().length, banners: S.banners.length, visitsKept: store.visits().length, shop: shop.view(), hub: hubreport.view(), hubLookup: hubpeople.view(), docstore: docstore.view(), oldrefs: Object.keys(oldRefMap()).length });
|
||||
members: store.members().length, banners: S.banners.length, visitsKept: store.visits().length, shop: shop.view(), prize: prize.view(), hub: hubreport.view(), hubLookup: hubpeople.view(), docstore: docstore.view(), oldrefs: Object.keys(oldRefMap()).length });
|
||||
}
|
||||
// old username -> network username map for the old-link redirects: { oldrefs: { old: network } } replaces the whole map
|
||||
if (p === '/api/admin/oldrefs' && req.method === 'POST') {
|
||||
@@ -406,6 +455,18 @@ const server = http.createServer(async (req, res) => {
|
||||
fs.writeFileSync(path.join(C.dataDir, 'oldrefs.json'), JSON.stringify(o)); oldRefs = { at: 0, map: {} };
|
||||
return json(res, 200, { ok: true, total: Object.keys(o).length, skipped: Object.keys(b.oldrefs).length - Object.keys(o).length });
|
||||
}
|
||||
// weekly prize payouts: plans (newest first) with a live quote for the ones waiting, prepare, approve and pay
|
||||
if (p === '/api/admin/prizes' && req.method === 'GET') {
|
||||
const list = prize.plans().slice(0, 20); const out = [];
|
||||
for (const pl of list) out.push(Object.assign({}, pl, pl.status === 'prepared' ? { quote: await prize.quotePlan(pl) } : {}));
|
||||
return json(res, 200, { week: store.ctWeek(), lastWeek: prize.prevWeek(store.ctWeek()), current: prize.pot(store.ctWeek()), weeks: out, prize: prize.view(), explorer: C.explorer });
|
||||
}
|
||||
if (p === '/api/admin/prizes/prepare' && req.method === 'POST') { const b = await readBody(req); const r = prize.prepare(String(b.week || prize.prevWeek(store.ctWeek())), true); return json(res, r.error ? 400 : 200, r); }
|
||||
if (p === '/api/admin/prizes/pay' && req.method === 'POST') {
|
||||
const b = await readBody(req); const wk = String(b.week || '');
|
||||
if (!wk || b.confirm !== wk) return json(res, 400, { error: 'Send {week, confirm: week} to approve.' });
|
||||
const r = await prize.pay(wk); return json(res, r.error ? 400 : 200, r);
|
||||
}
|
||||
if (p === '/api/admin/ledger' && req.method === 'GET') {
|
||||
const n = Math.min(2000, Math.max(1, Number(u.searchParams.get('n')) || 200)); const L = store.ledger();
|
||||
const per = {}; for (const e of L) { const k = e.owner; const r = per[k] || (per[k] = { address: k, username: e.username, cycles: 0, views: 0 }); r.cycles++; r.views += e.views; if (e.username) r.username = e.username; }
|
||||
@@ -423,6 +484,8 @@ const server = http.createServer(async (req, res) => {
|
||||
if (!res.headersSent) json(res, 500, { error: 'Server error' });
|
||||
}
|
||||
});
|
||||
const validSku = sku => sku === C.lookSku || C.packs.some(x => x.sku === sku);
|
||||
const skuUsd = sku => sku === C.lookSku ? C.lookUsd : (C.packs.find(x => x.sku === sku) || {}).usd || 0;
|
||||
function saveUpload(owner, buf, ext) {
|
||||
const name = owner.slice(2, 10) + '-' + crypto.randomBytes(6).toString('hex') + ext;
|
||||
fs.writeFileSync(path.join(UPL, name), buf); // uploads stay files on the volume (docstore keeps the uploads folder on disk)
|
||||
@@ -437,6 +500,7 @@ function saveUpload(owner, buf, ext) {
|
||||
store.pruneVisits(); loop.rebuildIndex();
|
||||
hubreport.init({ dataDir: C.dataDir, purchases: () => Object.entries((store.state() || {}).purchases || {}).map(([key, x]) => Object.assign({ key }, x)) });
|
||||
shop.init(C); // inert without CONTRACT_ADDRESS + CHAIN_RPC (watcher) / KEEPER_KEY (vouchers)
|
||||
prize.init(C); // prepares last week's payout plan; pays only on an admin's approval (PRIZE_KEY)
|
||||
setInterval(() => { if (store.pruneVisits()) loop.rebuildIndex(); }, 3600000).unref();
|
||||
server.listen(C.port, () => console.log('Viral Banner Blitz on :' + C.port + ' loop ' + C.loopSize + ', ' + C.perShift + ' visitors per shift, store: ' + (docstore.isOn() ? 'MySQL documents' : 'files (prototype mode)')));
|
||||
})().catch(e => { console.error('start failed:', e.message); process.exit(1); });
|
||||
|
||||
Reference in New Issue
Block a user