Created
February 27, 2023 06:03
-
-
Save imksoo/9d601973b1898a9cd18200d209316971 to your computer and use it in GitHub Desktop.
Script to duplicate past events(kind1) between relay servers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const srcRelay = 'wss://relay.snort.social' | |
const dstRelay = 'wss://relay-jp.nostr.wirednet.jp' | |
const authors = ['634bd19e5c87db216555c814bf88e66ace175805291a6be90b15ac3b2247da9b'] | |
let srcSocket | |
let dstSocket | |
if (typeof (WebSocket) === 'undefined') { | |
const WebSocket = require('websocket').w3cwebsocket | |
srcSocket = new WebSocket(srcRelay) | |
dstSocket = new WebSocket(dstRelay) | |
} else { | |
srcSocket = new WebSocket(srcRelay) | |
dstSocket = new WebSocket(dstRelay) | |
} | |
dstSocket.onopen = () => { | |
console.log('Destination Websocket is open.') | |
srcSocket.onopen = () => { | |
console.log('Source Websocket is open.') | |
srcSocket.send(JSON.stringify(['REQ', crypto.randomUUID(), { | |
authors, | |
kinds: [1], | |
until: (new Date()) / 1000, | |
limit: 1 | |
}])) | |
} | |
} | |
dstSocket.onmessage = (message) => { | |
console.log('Destination Websocket: ', message) | |
} | |
srcSocket.onmessage = (message) => { | |
const event = JSON.parse(message.data) | |
if (event[0] === 'EOSE') { | |
srcSocket.send(JSON.stringify(['CLOSE', event[1]])) | |
} else if (event.length < 3) { | |
srcSocket.close() | |
} else { | |
const e = event[2] | |
console.log(e) | |
dstSocket.send(JSON.stringify(['EVENT', e])) | |
srcSocket.send(JSON.stringify(['REQ', crypto.randomUUID(), { | |
authors, | |
kinds: [1], | |
until: e.created_at, | |
limit: 1 | |
}])) | |
} | |
} | |
dstSocket.onclose = () => { | |
console.log('Destination Websocket is closed.') | |
} | |
dstSocket.onerror = (e) => { | |
console.log('Destination Websocket encountered error: ', e.message, e.stack) | |
} | |
srcSocket.onclose = () => { | |
console.log('Source Websocket is closed.') | |
} | |
srcSocket.onerror = (e) => { | |
console.log('Source Websocket encountered error: ', e.message, e.stack) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment