Skip to content

Commit

Permalink
Use dev or prod relays.
Browse files Browse the repository at this point in the history
  • Loading branch information
chmac committed Aug 9, 2024
1 parent 7f6ee15 commit d19865c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const OPEN_LOCATION_CODE_NAMESPACE_TAG = "open-location-code";
export const MAP_NOTE_KIND = 397;
export const MAP_NOTE_REPOST_KIND = 30398;
export const DEFAULT_RELAYS = [
"wss://relay.primal.net",
"wss://relay.damus.io",
"wss://relay.primal.net",
"wss://nostr.manasiwibi.com",
];
export const DEV_RELAYS = ["wss://nos.lol"];
Expand Down
23 changes: 17 additions & 6 deletions validation/repost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@ type VerifiedEvent = nostrTools.VerifiedEvent;
type Tags = string[][];

import {
DEFAULT_RELAYS,
DEV_RELAYS,
MAP_NOTE_KIND,
MAP_NOTE_REPOST_KIND,
} from "../common/constants.ts";
import { DEV_PUBKEY } from "../common/constants.ts";
import { validateEvent } from "./validate.ts";

const RELAY = DEV_RELAYS[0];
async function getRelay(
isDev: true | undefined
): Promise<nostrToolsRelay.Relay> {
const relayUrl = isDev ? DEV_RELAYS[0] : DEFAULT_RELAYS[0];

console.log(`connecting to ${RELAY}…`);
const relay = await Relay.connect(RELAY);
console.log(`connected to ${relay.url}`);
console.log(`#nadQka Connecting to ${relayUrl}`);
const relay = await Relay.connect(relayUrl);
console.log(`#CmJWu4 Connected to ${relay.url}`);
return relay;
}

async function publishEvent(event: VerifiedEvent) {
async function publishEvent(
relay: nostrToolsRelay.Relay,
event: VerifiedEvent
) {
await relay.publish(event);
}

Expand Down Expand Up @@ -71,6 +80,8 @@ function createFilter(isDev: true | undefined): nostrTools.Filter {
}

export async function repost(privateKey: Uint8Array, isDev: true | undefined) {
const relay = await getRelay(isDev);

const filter = createFilter(isDev);

const oneose = isDev
Expand All @@ -91,7 +102,7 @@ export async function repost(privateKey: Uint8Array, isDev: true | undefined) {
return;
}
const repostedEvent = generateRepostedEvent(event, privateKey);
publishEvent(repostedEvent);
publishEvent(relay, repostedEvent);
},
oneose,
});
Expand Down

0 comments on commit d19865c

Please sign in to comment.