mirror of
https://github.com/tompro/sattle.git
synced 2026-10-26 01:49:58 +00:00
Formatting
This commit is contained in:
@@ -4,36 +4,37 @@
|
||||
// importing the service module never opens (or even references) a
|
||||
// WebSocket.
|
||||
|
||||
import type {Filter as NostrFilter} from 'nostr-tools/filter'
|
||||
import type { Filter as NostrFilter } from 'nostr-tools/filter';
|
||||
|
||||
import type {NostrEvent} from './protocol'
|
||||
import type { NostrEvent } from './protocol';
|
||||
|
||||
export type {NostrFilter}
|
||||
export type { NostrFilter };
|
||||
|
||||
export type NwcSubscription = {
|
||||
close: () => void
|
||||
}
|
||||
close: () => void;
|
||||
};
|
||||
|
||||
export type NwcTransport = {
|
||||
publish: (relays: string[], event: NostrEvent) => Promise<void>
|
||||
publish: (relays: string[], event: NostrEvent) => Promise<void>;
|
||||
subscribe: (
|
||||
relays: string[],
|
||||
filter: NostrFilter,
|
||||
onEvent: (event: NostrEvent) => void,
|
||||
) => NwcSubscription
|
||||
}
|
||||
) => NwcSubscription;
|
||||
};
|
||||
|
||||
export const defaultNwcTransport = async (): Promise<NwcTransport> => {
|
||||
const {SimplePool} = await import('nostr-tools/pool')
|
||||
const pool = new SimplePool()
|
||||
const { SimplePool } = await import('nostr-tools/pool');
|
||||
const pool = new SimplePool();
|
||||
return {
|
||||
publish: async (relays, event) => {
|
||||
const results = await Promise.allSettled(pool.publish(relays, event))
|
||||
const results = await Promise.allSettled(pool.publish(relays, event));
|
||||
// one honest relay accepting is enough - same rule as the backup
|
||||
if (!results.some((r) => r.status === 'fulfilled')) {
|
||||
throw new Error('No relay accepted the event.')
|
||||
throw new Error('No relay accepted the event.');
|
||||
}
|
||||
},
|
||||
subscribe: (relays, filter, onEvent) => pool.subscribeMany(relays, filter, {onevent: onEvent}),
|
||||
}
|
||||
}
|
||||
subscribe: (relays, filter, onEvent) =>
|
||||
pool.subscribeMany(relays, filter, { onevent: onEvent }),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user