Verify first bank deposit from settled ATM voucher redemption
All checks were successful
DuneRealms Web CI / web (push) Successful in 5m35s

This commit is contained in:
unimatrixgit 2026-12-05 16:46:45 +01:00
commit 79cd02f99e
4 changed files with 62 additions and 2 deletions

View file

@ -15,7 +15,7 @@ export const QUEST_GUIDANCE=Object.freeze({
'guild-travel':live('Book Spacing Guild passage in the lobby, remain online and arrive on your House world. The 100 DM fare is taken from your central personal bank account on arrival.','Lobby → Spacing Guild NPC / Imperial Codex → Spacing Guild','Confirmed destination arrival and settled passage payment'),
'citizen-introduction':live('Start this quest, then read the Imperial Citizen briefing and press I understand in your ingame mission journal. Refresh this quest after confirmation, then claim the reward. This is separate from choosing a House or completing your profile.','Imperial Codex → Mission journal → Personal Experience → Onboarding → Complete Imperial Citizen introduction → Read citizen briefing','Confirmed ingame Citizen briefing acknowledgement'),
'earned-minor':live('Receive the stated cumulative amount in DM from posted incoming bank transfers, quest rewards, wages, P&O spice payouts and Exchange sales during this season. Spending it later does not reduce your earned total. Transfers between your own accounts, refunds and pending payments do not count.','Central bank → Transactions; receive transfers, complete reward quests, earn wages or sell goods on the Exchange','Settled central-bank income, not your current balance'),
'bank-deposit':pending('Deposit physical cash into your personal central-bank account through the ingame ATM. A transfer between your own accounts is not a cash deposit.','Rihla / ATM ingame menu'),
'bank-deposit':live('Deposit physical cash at an ATM to get a RIA ID, then redeem that ID to your personal bank account. Cash pickup and bank transfers do not count.','Ingame Rihla / ATM → redeem to bank','Settled ATM voucher redemption to your bank account'),
'bank-transfer':live('Send a payment from an authorised personal bank account to another customer. Wait until it is posted; a queued payment or transfer between your own accounts does not count.','Website bank → Transfers','Posted standard or instant payment to another customer'),
'shop-purchase':live('Buy and pay for goods listed by another player on the Exchange. Browsing, publishing your own listing or withdrawing an unsold item does not count.','Ingame /exchange → Buy','Settled central-bank Exchange purchase'),
'spice-harvest':live('Personally harvest genuine raw spice from deposits on Arrakis. Buying, trading or selling spice does not count; selling your own harvest does not count it a second time.','Arrakis → Natural spice deposits','Verified native harvest receipt'),

View file

@ -33,3 +33,28 @@ export function createBankQuestActivities(central,bank,keys,{clock=Date.now}={})
return {pendingMetrics:rows.length?[]:['shop-purchase']};
};
}
const verifiedBankDeposits = `SELECT id,created_at FROM ria_cash_redemptions
WHERE owner_id=? AND player_uuid=? AND mode='bank' AND state='redeemed'
AND CAST(amount_minor AS DECIMAL(20,0))>0 AND created_at>=? AND created_at<?`;
export function createBankDepositQuestActivity(central,bank,keys,{clock=Date.now}={}){
const producer={};
const events=createPersonalActivityEvents(central,keys,{clock,authorizeProducer:async(actor,p)=>{
if(actor!==producer||p.metric!=='bank-deposit'||p.quantity!==1||p.reference!=='bank-deposit:'+p.eventId)return false;
const rows=await bank.query(verifiedBankDeposits+' AND id=?',[p.accountId,p.minecraftUuid,p.occurredAt,p.occurredAt+1,p.eventId]);
return rows.length===1;
}});
return async function collect(actor,season){
const links=await central.query('SELECT minecraft_uuid FROM site_game_links WHERE user_id=?',[actor.id]);
if(links.length!==1)return {pendingMetrics:['bank-deposit']};
const minecraftUuid=links[0].minecraft_uuid.toLowerCase();
// This receipt and its Postbank credit are committed in the same transaction.
const rows=await bank.query(verifiedBankDeposits+' ORDER BY created_at,id LIMIT 1',[actor.id,minecraftUuid,Number(season.starts_at),clock()+1]);
const receipt=rows[0];
if(!receipt)return {pendingMetrics:['bank-deposit']};
await events.record(producer,{eventId:receipt.id,accountId:actor.id,minecraftUuid,seasonId:season.season_id,
metric:'bank-deposit',quantity:1,occurredAt:Number(receipt.created_at),reference:'bank-deposit:'+receipt.id});
return {pendingMetrics:[]};
};
}

View file

@ -11,12 +11,13 @@ import {createQuestProgression} from './progression-quests.mjs';
import {createXPInstruments} from './progression-xp-instruments.mjs';
import {firstLoginState} from './first-login.mjs';
import {can} from './permissions.mjs';
import {createBankQuestActivities,bankQuestIncome} from './bank-quest-activities.mjs';
import {createBankQuestActivities,createBankDepositQuestActivity,bankQuestIncome} from './bank-quest-activities.mjs';
import {faithMultipliers,faithAward} from './faith-blessings.mjs';
const first=async(db,sql,args=[])=>{const rows=await db.query(sql,args);return rows[0]||null;};
export function createProgressionRuntime(central,bank,keys,{clock=Date.now,resolveCase=async()=>null,verifyAcquisition=(input,store=central)=>verifyDeedAcquisition(store,bank,input)}={}){
const observer=Object.freeze({internal:'progression-source-reader'});
const collectBankActivities=bank&&keys?createBankQuestActivities(central,bank,keys,{clock}):null;
const collectBankDeposit=bank&&keys?createBankDepositQuestActivity(central,bank,keys,{clock}):null;
const resolvePlayer=id=>first(central,"SELECT id,username,display_name,role FROM site_accounts WHERE id=? AND password_hash NOT LIKE '!%'",[id]);
async function authorizePlayer(actor,store){
if(typeof actor.revalidate==='function'&&(await actor.revalidate())?.id!==actor.id)return false;
@ -106,6 +107,7 @@ export function createProgressionRuntime(central,bank,keys,{clock=Date.now,resol
if(rows.length>500)throw Error('The conquest registry requires a larger reviewed window');
for(const row of rows){const receipt=JSON.parse(row.manifest_json).receipt;await quests.recordAcquisition(observer,{accountId:actor.id,kind:'clan',entityId:receipt.clanId,origin:'conquest',sourceKeyId:row.key_id});}
});
if(central.personalActivityEventsEnabled&&collectBankDeposit)await source('atm-deposits',['bank-deposit'],()=>collectBankDeposit(actor,season));
if(central.personalActivityEventsEnabled&&collectBankActivities)await source('exchange-purchases',['shop-purchase'],()=>collectBankActivities(actor,season));
if(central.personalActivityEventsEnabled)await source('personal-activity-keys',PERSONAL_ACTIVITY_METRICS,async()=>{
const proof=await activityEvidence(actor);if(!proof)return {pendingMetrics:PERSONAL_ACTIVITY_METRICS};

View file

@ -32,3 +32,36 @@ test('earned DM is cumulative settled income across personal accounts, including
assert.deepEqual(await bankQuestIncome(bank,'unknown',1000,2000),{wages:0,earned:0});
}finally{db.close();}
});
test('the first completed bank voucher redemption counts once for the current linked player',async()=>{
const {createBankDepositQuestActivity}=await import('../node/bank-quest-activities.mjs');
const f=await systemCharacterFixture(),sql=new DatabaseSync(':memory:');
try{
await initializeProgression(f.db);
await ensureProgressionPolicy(f.db,f.keys,{clock:()=>1000});
await initializePersonalActivityEvents(f.db);
const player=f.people.Member,uuid=randomUUID(),clock=()=>2000,season={season_id:'S01',starts_at:1000};
await f.db.query('UPDATE site_game_links SET minecraft_uuid=? WHERE user_id=?',[uuid,player.id]);
sql.exec('CREATE TABLE ria_cash_redemptions(id TEXT PRIMARY KEY,owner_id TEXT,player_uuid TEXT,mode TEXT,state TEXT,amount_minor TEXT,created_at INT)');
const insert=(mode,state,amount,at=1500,owner=player.id,link=uuid)=>{
const id=randomUUID();
sql.prepare('INSERT INTO ria_cash_redemptions VALUES(?,?,?,?,?,?,?)').run(id,owner,link,mode,state,amount,at);
return id;
};
insert('cash','redeemed','100');
insert('bank','prepared','100');
insert('bank','redeemed','0');
insert('bank','redeemed','100',999);
insert('bank','redeemed','100',2001);
insert('bank','redeemed','100',1500,f.people.Other.id);
insert('bank','redeemed','100',1500,player.id,randomUUID());
const bank={query:async(text,args)=>sql.prepare(text).all(...args)};
const collect=createBankDepositQuestActivity(f.db,bank,f.keys,{clock});
assert.deepEqual(await collect(player,season),{pendingMetrics:['bank-deposit']});
const id=insert('bank','redeemed','100');
assert.deepEqual(await collect(player,season),{pendingMetrics:[]});
await collect(player,season);
const proof=await verifiedPersonalActivities(f.db,f.keys,{accountId:player.id,minecraftUuid:uuid,seasonId:'S01',startsAt:1000,endsAt:100000,now:2000});
assert.equal(proof.totals.get('bank-deposit'),1);
assert.deepEqual((await f.db.query('SELECT event_id FROM jarvis_personal_activity_events')).map(row=>row.event_id),[id]);
}finally{sql.close();f.db.close();}
});