mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'zapsplit-conf' into 'main'
Remove `@/config.ts` import from utils/zap-split.ts See merge request soapbox-pub/ditto!697
This commit is contained in:
commit
bebc7dc897
4 changed files with 28 additions and 16 deletions
|
|
@ -202,7 +202,7 @@ const pgstore = new DittoPgStore({
|
|||
const pool = new DittoPool({ conf, relay: pgstore });
|
||||
const relay = new DittoRelayStore({ db, conf, relay: pgstore });
|
||||
|
||||
await seedZapSplits(relay);
|
||||
await seedZapSplits({ conf, relay });
|
||||
|
||||
if (conf.firehoseEnabled) {
|
||||
startFirehose({
|
||||
|
|
|
|||
|
|
@ -186,7 +186,8 @@ const zapSplitSchema = z.record(
|
|||
);
|
||||
|
||||
export const updateZapSplitsController: AppController = async (c) => {
|
||||
const { conf, relay } = c.var;
|
||||
const { conf } = c.var;
|
||||
|
||||
const body = await parseBody(c.req.raw);
|
||||
const result = zapSplitSchema.safeParse(body);
|
||||
|
||||
|
|
@ -196,7 +197,7 @@ export const updateZapSplitsController: AppController = async (c) => {
|
|||
|
||||
const adminPubkey = await conf.signer.getPublicKey();
|
||||
|
||||
const dittoZapSplit = await getZapSplits(relay, adminPubkey);
|
||||
const dittoZapSplit = await getZapSplits(adminPubkey, c.var);
|
||||
if (!dittoZapSplit) {
|
||||
return c.json({ error: 'Zap split not activated, restart the server.' }, 404);
|
||||
}
|
||||
|
|
@ -223,7 +224,8 @@ export const updateZapSplitsController: AppController = async (c) => {
|
|||
const deleteZapSplitSchema = z.array(n.id()).min(1);
|
||||
|
||||
export const deleteZapSplitsController: AppController = async (c) => {
|
||||
const { conf, relay } = c.var;
|
||||
const { conf } = c.var;
|
||||
|
||||
const body = await parseBody(c.req.raw);
|
||||
const result = deleteZapSplitSchema.safeParse(body);
|
||||
|
||||
|
|
@ -233,7 +235,7 @@ export const deleteZapSplitsController: AppController = async (c) => {
|
|||
|
||||
const adminPubkey = await conf.signer.getPublicKey();
|
||||
|
||||
const dittoZapSplit = await getZapSplits(relay, adminPubkey);
|
||||
const dittoZapSplit = await getZapSplits(adminPubkey, c.var);
|
||||
if (!dittoZapSplit) {
|
||||
return c.json({ error: 'Zap split not activated, restart the server.' }, 404);
|
||||
}
|
||||
|
|
@ -253,9 +255,9 @@ export const deleteZapSplitsController: AppController = async (c) => {
|
|||
};
|
||||
|
||||
export const getZapSplitsController: AppController = async (c) => {
|
||||
const { conf, relay } = c.var;
|
||||
const { conf } = c.var;
|
||||
|
||||
const dittoZapSplit: DittoZapSplits | undefined = await getZapSplits(relay, await conf.signer.getPublicKey()) ?? {};
|
||||
const dittoZapSplit: DittoZapSplits | undefined = await getZapSplits(await conf.signer.getPublicKey(), c.var) ?? {};
|
||||
if (!dittoZapSplit) {
|
||||
return c.json({ error: 'Zap split not activated, restart the server.' }, 404);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ const createStatusController: AppController = async (c) => {
|
|||
if (conf.zapSplitsEnabled) {
|
||||
const meta = n.json().pipe(n.metadata()).catch({}).parse(author?.content);
|
||||
const lnurl = getLnurl(meta);
|
||||
const dittoZapSplit = await getZapSplits(relay, await conf.signer.getPublicKey());
|
||||
const dittoZapSplit = await getZapSplits(await conf.signer.getPublicKey(), c.var);
|
||||
if (lnurl && dittoZapSplit) {
|
||||
const totalSplit = Object.values(dittoZapSplit).reduce((total, { weight }) => total + weight, 0);
|
||||
for (const zapPubkey in dittoZapSplit) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { Conf } from '@/config.ts';
|
||||
import { NSchema as n, NStore } from '@nostrify/nostrify';
|
||||
import { nostrNow } from '@/utils.ts';
|
||||
import { percentageSchema } from '@/schema.ts';
|
||||
|
||||
import type { DittoConf } from '@ditto/conf';
|
||||
|
||||
type Pubkey = string;
|
||||
type ExtraMessage = string;
|
||||
/** Number from 1 to 100, stringified. */
|
||||
|
|
@ -12,11 +13,18 @@ export type DittoZapSplits = {
|
|||
[key: Pubkey]: { weight: splitPercentages; message: ExtraMessage };
|
||||
};
|
||||
|
||||
interface GetZapSplitsOpts {
|
||||
conf: DittoConf;
|
||||
relay: NStore;
|
||||
}
|
||||
|
||||
/** Gets zap splits from NIP-78 in DittoZapSplits format. */
|
||||
export async function getZapSplits(store: NStore, pubkey: string): Promise<DittoZapSplits | undefined> {
|
||||
export async function getZapSplits(pubkey: string, opts: GetZapSplitsOpts): Promise<DittoZapSplits | undefined> {
|
||||
const { relay } = opts;
|
||||
|
||||
const zapSplits: DittoZapSplits = {};
|
||||
|
||||
const [event] = await store.query([{
|
||||
const [event] = await relay.query([{
|
||||
authors: [pubkey],
|
||||
kinds: [30078],
|
||||
'#d': ['pub.ditto.zapSplits'],
|
||||
|
|
@ -36,15 +44,17 @@ export async function getZapSplits(store: NStore, pubkey: string): Promise<Ditto
|
|||
return zapSplits;
|
||||
}
|
||||
|
||||
export async function seedZapSplits(store: NStore) {
|
||||
const zapSplit: DittoZapSplits | undefined = await getZapSplits(store, await Conf.signer.getPublicKey());
|
||||
export async function seedZapSplits(opts: GetZapSplitsOpts): Promise<void> {
|
||||
const { conf, relay } = opts;
|
||||
|
||||
const pubkey = await conf.signer.getPublicKey();
|
||||
const zapSplit: DittoZapSplits | undefined = await getZapSplits(pubkey, opts);
|
||||
|
||||
if (!zapSplit) {
|
||||
const dittoPubkey = '781a1527055f74c1f70230f10384609b34548f8ab6a0a6caa74025827f9fdae5';
|
||||
const dittoMsg = 'Official Ditto Account';
|
||||
|
||||
const signer = Conf.signer;
|
||||
const event = await signer.signEvent({
|
||||
const event = await conf.signer.signEvent({
|
||||
content: '',
|
||||
created_at: nostrNow(),
|
||||
kind: 30078,
|
||||
|
|
@ -54,6 +64,6 @@ export async function seedZapSplits(store: NStore) {
|
|||
],
|
||||
});
|
||||
|
||||
await store.event(event);
|
||||
await relay.event(event);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue