Seed zap splits when Storages.db is first accessed

This commit is contained in:
Alex Gleason 2024-07-29 15:59:29 -05:00
parent 31f5254fb3
commit 37f229408c
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 9 additions and 11 deletions

View file

@ -1,7 +1,6 @@
// Starts up applications required to run before the HTTP server is on. // Starts up applications required to run before the HTTP server is on.
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { seedZapSplits } from '@/utils/zap-split.ts';
import { cron } from '@/cron.ts'; import { cron } from '@/cron.ts';
import { startFirehose } from '@/firehose.ts'; import { startFirehose } from '@/firehose.ts';
@ -12,5 +11,3 @@ if (Conf.firehoseEnabled) {
if (Conf.cronEnabled) { if (Conf.cronEnabled) {
cron(); cron();
} }
await seedZapSplits();

View file

@ -7,6 +7,7 @@ import { SearchStore } from '@/storages/search-store.ts';
import { InternalRelay } from '@/storages/InternalRelay.ts'; import { InternalRelay } from '@/storages/InternalRelay.ts';
import { NPool, NRelay1 } from '@nostrify/nostrify'; import { NPool, NRelay1 } from '@nostrify/nostrify';
import { getRelays } from '@/utils/outbox.ts'; import { getRelays } from '@/utils/outbox.ts';
import { seedZapSplits } from '@/utils/zap-split.ts';
export class Storages { export class Storages {
private static _db: Promise<EventsDB> | undefined; private static _db: Promise<EventsDB> | undefined;
@ -20,7 +21,9 @@ export class Storages {
if (!this._db) { if (!this._db) {
this._db = (async () => { this._db = (async () => {
const kysely = await DittoDB.getInstance(); const kysely = await DittoDB.getInstance();
return new EventsDB(kysely); const store = new EventsDB(kysely);
await seedZapSplits(store);
return store;
})(); })();
} }
return this._db; return this._db;

View file

@ -1,10 +1,8 @@
import { AdminSigner } from '@/signers/AdminSigner.ts'; import { AdminSigner } from '@/signers/AdminSigner.ts';
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { handleEvent } from '@/pipeline.ts';
import { NSchema as n, NStore } from '@nostrify/nostrify'; import { NSchema as n, NStore } from '@nostrify/nostrify';
import { nostrNow } from '@/utils.ts'; import { nostrNow } from '@/utils.ts';
import { percentageSchema } from '@/schema.ts'; import { percentageSchema } from '@/schema.ts';
import { Storages } from '@/storages.ts';
type Pubkey = string; type Pubkey = string;
type ExtraMessage = string; type ExtraMessage = string;
@ -39,11 +37,10 @@ export async function getZapSplits(store: NStore, pubkey: string): Promise<Ditto
return zapSplits; return zapSplits;
} }
export async function seedZapSplits() { export async function seedZapSplits(store: NStore) {
const store = await Storages.admin(); const zapSplit: DittoZapSplits | undefined = await getZapSplits(store, Conf.pubkey);
const zap_split: DittoZapSplits | undefined = await getZapSplits(store, Conf.pubkey); if (!zapSplit) {
if (!zap_split) {
const dittoPubkey = '781a1527055f74c1f70230f10384609b34548f8ab6a0a6caa74025827f9fdae5'; const dittoPubkey = '781a1527055f74c1f70230f10384609b34548f8ab6a0a6caa74025827f9fdae5';
const dittoMsg = 'Official Ditto Account'; const dittoMsg = 'Official Ditto Account';
@ -57,6 +54,7 @@ export async function seedZapSplits() {
['p', dittoPubkey, '5', dittoMsg], ['p', dittoPubkey, '5', dittoMsg],
], ],
}); });
await handleEvent(event, AbortSignal.timeout(5000));
await store.event(event);
} }
} }