VBBShop hooks (inert until configured, nothing deployed): GET /api/my/voucher signs an EIP-712 sponsor voucher with KEEPER_KEY when the hub lookup names the member's network sponsor (new optional sponsor field; none or self = no voucher); shop.js watcher reads Purchase logs (CONTRACT_ADDRESS + CHAIN_RPC, confirmed blocks, 1,000-block ranges) and credits packs once per txHash:logIndex, dedupe marks saved in vbb.json with the credits; admin status shows the watcher, never the key. Packages page stays coming soon. Smoke 117/117 (fake chain + voucher checks)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// 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.
|
||||
// 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';
|
||||
@@ -17,6 +18,7 @@ const store = require('./store');
|
||||
const loop = require('./loop');
|
||||
const safety = require('./safety');
|
||||
const networksso = require('./networksso');
|
||||
const shop = require('./shop');
|
||||
|
||||
const PUB = path.join(__dirname, 'public');
|
||||
const UPL = path.join(C.dataDir, 'uploads');
|
||||
@@ -89,7 +91,7 @@ async function netMember(q) {
|
||||
try { const ac = new AbortController(); setTimeout(() => ac.abort(), 4000).unref();
|
||||
const qs = q.u ? 'u=' + encodeURIComponent(q.u) : 'a=' + encodeURIComponent(q.a);
|
||||
const j = await (await fetch(C.networkLookupUrl + '?' + qs, { signal: ac.signal })).json();
|
||||
if (j && ADDR_RE.test(j.address || '') && j.username) m = { address: j.address.toLowerCase(), username: String(j.username) }; } catch (e) { return null; }
|
||||
if (j && ADDR_RE.test(j.address || '') && j.username) m = { address: j.address.toLowerCase(), username: String(j.username), sponsor: ADDR_RE.test(j.sponsor || '') ? j.sponsor.toLowerCase() : null }; } catch (e) { return null; }
|
||||
netCache.set(k, { at: Date.now(), m }); if (netCache.size > 20000) netCache.clear();
|
||||
return m;
|
||||
}
|
||||
@@ -292,6 +294,14 @@ const server = http.createServer(async (req, res) => {
|
||||
const me = s.address;
|
||||
if (!store.member(me)) signedIn(me, { via: 'wallet' });
|
||||
if (p === '/api/my' && req.method === 'GET') { await verifyNet(me); const m = store.member(me); const granted = grantDaily(m); m.lastSeen = Date.now(); return json(res, 200, Object.assign(myData(me), { grantedNow: granted })); }
|
||||
// sponsor voucher for VBBShop.buy: only when the hub knows this member's network sponsor (a wallet that is not their own)
|
||||
if (p === '/api/my/voucher' && req.method === 'GET') {
|
||||
if (limited(req, 'voucher', 60, 3600000)) return json(res, 429, { error: 'Too many requests this hour.' });
|
||||
if (!shop.voucherOn()) return json(res, 200, { voucher: null, why: 'off' });
|
||||
const n = await netMember({ a: me }).catch(() => null); const sp = n && n.address === me ? n.sponsor : null;
|
||||
if (!sp || sp === me) return json(res, 200, { voucher: null, why: 'no-sponsor' });
|
||||
return json(res, 200, { voucher: await shop.voucher(me, sp) });
|
||||
}
|
||||
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.' }); }
|
||||
@@ -333,7 +343,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, docstore: docstore.view() });
|
||||
members: store.members().length, banners: S.banners.length, visitsKept: store.visits().length, shop: shop.view(), docstore: docstore.view() });
|
||||
}
|
||||
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();
|
||||
@@ -363,6 +373,7 @@ function saveUpload(owner, buf, ext) {
|
||||
store.load();
|
||||
loop.init({ onCycle: (b, e) => console.log('cycle', 'banner #' + b.id, e.views + ' network views recorded') });
|
||||
store.pruneVisits(); loop.rebuildIndex();
|
||||
shop.init(C); // inert without CONTRACT_ADDRESS + CHAIN_RPC (watcher) / KEEPER_KEY (vouchers)
|
||||
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