forked from unimatrix/web
Verify Rihla backing and inventory receipt access at startup
This commit is contained in:
parent
ce449ea196
commit
6260892c8b
2 changed files with 47 additions and 12 deletions
|
|
@ -45,7 +45,9 @@ export async function openRihlaCashReceiptReader(bank,nativePool,inventoryDataba
|
|||
const table=await bank.first('SELECT ENGINE engine FROM information_schema.TABLES WHERE TABLE_SCHEMA=? AND TABLE_NAME=?',
|
||||
[schema,'dune_exchange_inventory_ops']);
|
||||
if(table?.engine!=='InnoDB')fail('Rihla transactional inventory receipts are unavailable.');
|
||||
return (tx,id)=>tx.first('SELECT actor_uuid,kind,fingerprint,listing_id,created_at FROM `'+schema+'`.dune_exchange_inventory_ops WHERE id=?',[id]);
|
||||
const sql='SELECT actor_uuid,kind,fingerprint,listing_id,created_at FROM `'+schema+'`.dune_exchange_inventory_ops WHERE id=?';
|
||||
await bank.first(sql,['00000000-0000-0000-0000-000000000000']);
|
||||
return (tx,id)=>tx.first(sql,[id]);
|
||||
}
|
||||
|
||||
export function createRihlaCashLedger(bank,{readReceipt,postbank,clock=Date.now}={}){
|
||||
|
|
|
|||
|
|
@ -24,6 +24,12 @@ export function createRihlaPostbank(bank,{authority,backingSystemKey,clock=Date.
|
|||
account.type_code==='999'&&account.client_number===null&&account.package_id===null;
|
||||
const orderId=(purpose,requestId)=>creditID('rihla:'+purpose+':'+requestId);
|
||||
|
||||
async function verifyConfiguration(){
|
||||
const rows=await bank.query('SELECT * FROM pb_accounts WHERE system_key IN (?,?)',[backingSystemKey,taxTreasury]);
|
||||
if(!rows.some(backing)||!rows.some(row=>row.system_key===taxTreasury&&row.state==='active'))
|
||||
throw Error('Active Rihla backing and tax treasury are required.');
|
||||
}
|
||||
|
||||
async function balance(actor){
|
||||
const rights=await authority(actor,{bank});
|
||||
const rows=await bank.query(cashAccounts+" WHERE e.kind='person' AND e.external_key=? ORDER BY a.id",[actor.id]);
|
||||
|
|
@ -88,5 +94,5 @@ export function createRihlaPostbank(bank,{authority,backingSystemKey,clock=Date.
|
|||
if(fee>0n)await post(tax,fee,'-tax','Rihla settlement fee');
|
||||
}
|
||||
|
||||
return {balance,reserve,settle,payFromBacking};
|
||||
return {verifyConfiguration,balance,reserve,settle,payFromBacking};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff