This commit is contained in:
hatim boufnichel 2024-04-24 20:49:25 +02:00
parent 4abff88a6e
commit ab22757952
2 changed files with 38 additions and 14 deletions

View file

@ -374,13 +374,23 @@ export default class {
const abortController = new AbortController()
const req = OpenChannelReq(destination, closeAddress, fundingAmount, pushSats)
const stream = this.lightning.openChannel(req, { abort: abortController.signal })
stream.responses.onMessage(message => {
console.log("message", message)
})
stream.responses.onError(error => {
console.log("error", error)
return new Promise((res, rej) => {
stream.responses.onMessage(message => {
console.log("message", message)
switch (message.update.oneofKind) {
case 'chanPending':
abortController.abort()
res(Buffer.from(message.pendingChanId).toString('base64'))
break
default:
abortController.abort()
rej("unexpected state response: " + message.update.oneofKind)
}
})
stream.responses.onError(error => {
console.log("error", error)
rej(error)
})
})
}
}

View file

@ -34,25 +34,39 @@ export const setupNetwork = async () => {
}
const sendBalancingPayment = async (instances: LndInstances) => {
const invoice = await instances.dave.NewInvoice(20_000_000, "balancing_payment", 3600)
const payment = await instances.bob.PayInvoice(invoice.payRequest, 0, 500_000)
const invoice = await instances.dave.NewInvoice(5_000_000, "balancing_payment", 3600)
const payment = await instances.bob.PayInvoice(invoice.payRequest, 0, 100_000)
console.log({ payment })
}
const openChannels = async (core: BitcoinCoreWrapper, instances: LndInstances, info: InstancesInfo, addresses: Addresses) => {
await instances.bob.OpenChannel(info.carol.pubkey, addresses.bob, 50_000_000, 0)
await instances.carol.OpenChannel(info.alice.pubkey, addresses.carol, 50_000_000, 0)
await instances.alice.OpenChannel(info.dave.pubkey, addresses.alice, 50_000_000, 0)
await slowMine(core, 10)
await openChannel(instances.bob, info.carol.pubkey, addresses.bob)
await openChannel(instances.carol, info.alice.pubkey, addresses.carol)
await openChannel(instances.alice, info.dave.pubkey, addresses.alice)
await slowMine(core, 6)
}
const openChannel = async (instance: LND, to: string, closeAddr: string) => {
for (let i = 0; i < 10; i++) {
try {
await instance.OpenChannel(to, closeAddr, 10_000_000, 0)
console.log("success opening channel")
break
} catch (e) {
await new Promise((resolve) => setTimeout(resolve, 1000))
console.log("error opening channel", e)
}
}
throw new Error("could not open channel after 10 tries")
}
const sendCoinsToAddresses = async (core: BitcoinCoreWrapper, addresses: Addresses) => {
await core.SendToAddress(addresses.alice, 10)
await core.SendToAddress(addresses.bob, 10)
await core.SendToAddress(addresses.carol, 10)
await core.SendToAddress(addresses.dave, 10)
await slowMine(core, 10)
await core.Mine(6)
}
const slowMine = async (core: BitcoinCoreWrapper, blocks: number) => {