wired
This commit is contained in:
parent
779d3204c3
commit
bbd00b3450
4 changed files with 35 additions and 21 deletions
|
|
@ -12,6 +12,7 @@ export class LiquidityProvider {
|
|||
client: ReturnType<typeof newNostrClient>
|
||||
clientCbs: Record<string, nostrCallback<any>> = {}
|
||||
clientId: string = ""
|
||||
myPub: string = ""
|
||||
log = getLogger({ component: 'liquidityProvider' })
|
||||
nostrSend: NostrSend | null = null
|
||||
ready = false
|
||||
|
|
@ -22,37 +23,48 @@ export class LiquidityProvider {
|
|||
if (!pubDestination) {
|
||||
this.log("No pub provider to liquidity provider, will not be initialized")
|
||||
}
|
||||
this.pubDestination = pubDestination
|
||||
this.client = newNostrClient({
|
||||
pubDestination: pubDestination,
|
||||
retrieveNostrUserAuth: async () => "",
|
||||
pubDestination: this.pubDestination,
|
||||
retrieveNostrUserAuth: async () => this.myPub,
|
||||
}, this.clientSend, this.clientSub)
|
||||
|
||||
const interval = setInterval(() => {
|
||||
if (this.ready) {
|
||||
this.log("ready")
|
||||
clearInterval(interval)
|
||||
this.client.GetUserInfo().then(res => {
|
||||
this.CheckUSerState()
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
CheckUSerState = async () => {
|
||||
await new Promise(res => setTimeout(res, 2000))
|
||||
this.log("ready")
|
||||
const res = await this.client.GetUserInfo()
|
||||
if (res.status === 'ERROR') {
|
||||
this.log("error getting user info", res)
|
||||
return
|
||||
}
|
||||
this.log("got user info", res)
|
||||
})
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
setClientId = (clientId: string) => {
|
||||
setNostrInfo = ({ clientId, myPub }: { myPub: string, clientId: string }) => {
|
||||
this.clientId = clientId
|
||||
if (this.nostrSend && this.pubDestination !== "") {
|
||||
this.ready = true
|
||||
}
|
||||
this.myPub = myPub
|
||||
this.setSetIfReady()
|
||||
}
|
||||
|
||||
|
||||
|
||||
attachNostrSend(f: NostrSend) {
|
||||
this.nostrSend = f
|
||||
if (this.clientId !== "" && this.pubDestination !== "") {
|
||||
this.setSetIfReady()
|
||||
}
|
||||
|
||||
setSetIfReady = () => {
|
||||
if (this.nostrSend && !!this.pubDestination && !!this.clientId && !!this.myPub) {
|
||||
this.ready = true
|
||||
this.log("ready to send to ", this.pubDestination)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ export const initMainHandler = async (log: PubLogger, mainSettings: MainSettings
|
|||
publicKey: liquidityProviderApp.publicKey,
|
||||
name: "liquidity_provider", clientId: `client_${liquidityProviderApp.appId}`
|
||||
}
|
||||
liquidityProvider.setClientId(liquidityProviderInfo.clientId)
|
||||
liquidityProvider.setNostrInfo({ clientId: liquidityProviderInfo.clientId, myPub: liquidityProviderInfo.publicKey })
|
||||
const stop = await processArgs(mainHandler)
|
||||
if (stop) {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
import { LoadTestSettingsFromEnv } from "../services/main/settings.js"
|
||||
import { BitcoinCoreWrapper } from "./bitcoinCore.js"
|
||||
import LND from '../services/lnd/lnd.js'
|
||||
import { LiquidityProvider } from "../services/lnd/liquidityProvider.js"
|
||||
|
||||
export const setupNetwork = async () => {
|
||||
const settings = LoadTestSettingsFromEnv()
|
||||
const core = new BitcoinCoreWrapper(settings)
|
||||
await core.InitAddress()
|
||||
await core.Mine(1)
|
||||
const alice = new LND(settings.lndSettings, () => { }, () => { }, () => { }, () => { })
|
||||
const bob = new LND({ ...settings.lndSettings, mainNode: settings.lndSettings.otherNode }, () => { }, () => { }, () => { }, () => { })
|
||||
const alice = new LND(settings.lndSettings, new LiquidityProvider(""), () => { }, () => { }, () => { }, () => { })
|
||||
const bob = new LND({ ...settings.lndSettings, mainNode: settings.lndSettings.otherNode }, new LiquidityProvider(""), () => { }, () => { }, () => { }, () => { })
|
||||
await tryUntil<void>(async i => {
|
||||
const peers = await alice.ListPeers()
|
||||
if (peers.peers.length > 0) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import { defaultInvoiceExpiry } from '../services/storage/paymentStorage.js'
|
|||
import SanityChecker from '../services/main/sanityChecker.js'
|
||||
import LND from '../services/lnd/lnd.js'
|
||||
import { resetDisabledLoggers } from '../services/helpers/logger.js'
|
||||
import { LiquidityProvider } from '../services/lnd/liquidityProvider.js'
|
||||
chai.use(chaiString)
|
||||
export const expect = chai.expect
|
||||
export type Describe = (message: string, failure?: boolean) => void
|
||||
|
|
@ -45,15 +46,15 @@ export const SetupTest = async (d: Describe): Promise<TestBase> => {
|
|||
const user2 = { userId: u2.info.userId, appUserIdentifier: u2.identifier, appId: app.appId }
|
||||
|
||||
|
||||
const externalAccessToMainLnd = new LND(settings.lndSettings, console.log, console.log, () => { }, () => { })
|
||||
const externalAccessToMainLnd = new LND(settings.lndSettings, new LiquidityProvider(""), console.log, console.log, () => { }, () => { })
|
||||
await externalAccessToMainLnd.Warmup()
|
||||
|
||||
const otherLndSetting = { ...settings.lndSettings, mainNode: settings.lndSettings.otherNode }
|
||||
const externalAccessToOtherLnd = new LND(otherLndSetting, console.log, console.log, () => { }, () => { })
|
||||
const externalAccessToOtherLnd = new LND(otherLndSetting, new LiquidityProvider(""), console.log, console.log, () => { }, () => { })
|
||||
await externalAccessToOtherLnd.Warmup()
|
||||
|
||||
const thirdLndSetting = { ...settings.lndSettings, mainNode: settings.lndSettings.thirdNode }
|
||||
const externalAccessToThirdLnd = new LND(thirdLndSetting, console.log, console.log, () => { }, () => { })
|
||||
const externalAccessToThirdLnd = new LND(thirdLndSetting, new LiquidityProvider(""), console.log, console.log, () => { }, () => { })
|
||||
await externalAccessToThirdLnd.Warmup()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue