use mempool.space instead of electrum
This commit is contained in:
parent
026b8138ef
commit
f0e21be318
@ -65,7 +65,7 @@ kotlin {
|
|||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("fr.acinq.lightning:lightning-kmp:1.6.2-FEECREDIT-1")
|
implementation("fr.acinq.lightning:lightning-kmp:1.6.2-FEECREDIT-2-SNAPSHOT")
|
||||||
// ktor serialization
|
// ktor serialization
|
||||||
implementation(ktor("serialization-kotlinx-json"))
|
implementation(ktor("serialization-kotlinx-json"))
|
||||||
// ktor server
|
// ktor server
|
||||||
@ -78,7 +78,6 @@ kotlin {
|
|||||||
// ktor client (needed for webhook)
|
// ktor client (needed for webhook)
|
||||||
implementation(ktor("client-core"))
|
implementation(ktor("client-core"))
|
||||||
implementation(ktor("client-content-negotiation"))
|
implementation(ktor("client-content-negotiation"))
|
||||||
implementation(ktor("client-cio"))
|
|
||||||
implementation(ktor("client-auth"))
|
implementation(ktor("client-auth"))
|
||||||
implementation(ktor("client-json"))
|
implementation(ktor("client-json"))
|
||||||
|
|
||||||
@ -90,6 +89,7 @@ kotlin {
|
|||||||
jvmMain {
|
jvmMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("app.cash.sqldelight:sqlite-driver:2.0.1")
|
implementation("app.cash.sqldelight:sqlite-driver:2.0.1")
|
||||||
|
implementation(ktor("client-okhttp"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nativeMain {
|
nativeMain {
|
||||||
@ -97,6 +97,11 @@ kotlin {
|
|||||||
implementation("app.cash.sqldelight:native-driver:2.0.1")
|
implementation("app.cash.sqldelight:native-driver:2.0.1")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
linuxMain {
|
||||||
|
dependencies {
|
||||||
|
implementation(ktor("client-curl"))
|
||||||
|
}
|
||||||
|
}
|
||||||
macosMain {
|
macosMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(ktor("client-darwin"))
|
implementation(ktor("client-darwin"))
|
||||||
|
@ -32,9 +32,8 @@ import fr.acinq.lightning.bin.db.WalletPaymentId
|
|||||||
import fr.acinq.lightning.bin.db.payments.LightningOutgoingQueries
|
import fr.acinq.lightning.bin.db.payments.LightningOutgoingQueries
|
||||||
import fr.acinq.lightning.bin.json.ApiType
|
import fr.acinq.lightning.bin.json.ApiType
|
||||||
import fr.acinq.lightning.bin.logs.FileLogWriter
|
import fr.acinq.lightning.bin.logs.FileLogWriter
|
||||||
import fr.acinq.lightning.blockchain.electrum.ElectrumClient
|
import fr.acinq.lightning.blockchain.mempool.MempoolSpaceClient
|
||||||
import fr.acinq.lightning.blockchain.electrum.ElectrumConnectionStatus
|
import fr.acinq.lightning.blockchain.mempool.MempoolSpaceWatcher
|
||||||
import fr.acinq.lightning.blockchain.electrum.ElectrumWatcher
|
|
||||||
import fr.acinq.lightning.crypto.LocalKeyManager
|
import fr.acinq.lightning.crypto.LocalKeyManager
|
||||||
import fr.acinq.lightning.db.ChannelsDb
|
import fr.acinq.lightning.db.ChannelsDb
|
||||||
import fr.acinq.lightning.db.Databases
|
import fr.acinq.lightning.db.Databases
|
||||||
@ -44,7 +43,6 @@ import fr.acinq.lightning.io.TcpSocket
|
|||||||
import fr.acinq.lightning.logging.LoggerFactory
|
import fr.acinq.lightning.logging.LoggerFactory
|
||||||
import fr.acinq.lightning.payment.LiquidityPolicy
|
import fr.acinq.lightning.payment.LiquidityPolicy
|
||||||
import fr.acinq.lightning.utils.Connection
|
import fr.acinq.lightning.utils.Connection
|
||||||
import fr.acinq.lightning.utils.ServerAddress
|
|
||||||
import fr.acinq.lightning.utils.msat
|
import fr.acinq.lightning.utils.msat
|
||||||
import fr.acinq.lightning.utils.sat
|
import fr.acinq.lightning.utils.sat
|
||||||
import fr.acinq.phoenix.db.*
|
import fr.acinq.phoenix.db.*
|
||||||
@ -92,8 +90,7 @@ class Phoenixd : CliktCommand() {
|
|||||||
private val chain by option("--chain", help = "Bitcoin chain to use").choice(
|
private val chain by option("--chain", help = "Bitcoin chain to use").choice(
|
||||||
"mainnet" to Chain.Mainnet, "testnet" to Chain.Testnet
|
"mainnet" to Chain.Mainnet, "testnet" to Chain.Testnet
|
||||||
).default(Chain.Testnet, defaultForHelp = "testnet")
|
).default(Chain.Testnet, defaultForHelp = "testnet")
|
||||||
private val customElectrumServer by option("--electrum-server", "-e", help = "Custom Electrum server")
|
private val customMempoolSpaceHost by option("--mempool-space", "-e", help = "Custom mempool.space instance")
|
||||||
.convert { it.split(":").run { ServerAddress(first(), last().toInt(), TcpSocket.TLS.DISABLED) } }
|
|
||||||
private val httpBindIp by option("--http-bind-ip", help = "Bind ip for the http api").default("127.0.0.1")
|
private val httpBindIp by option("--http-bind-ip", help = "Bind ip for the http api").default("127.0.0.1")
|
||||||
private val httpBindPort by option("--http-bind-port", help = "Bind port for the http api").int().default(9740)
|
private val httpBindPort by option("--http-bind-port", help = "Bind port for the http api").int().default(9740)
|
||||||
private val httpPassword by option("--http-password", help = "Password for the http api").defaultLazy {
|
private val httpPassword by option("--http-password", help = "Password for the http api").defaultLazy {
|
||||||
@ -194,9 +191,9 @@ class Phoenixd : CliktCommand() {
|
|||||||
if (verbose) add(CommonWriter())
|
if (verbose) add(CommonWriter())
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
val electrumServer = customElectrumServer ?: when (chain) {
|
val mempoolSpaceHost = customMempoolSpaceHost ?: when (chain) {
|
||||||
Chain.Mainnet -> ServerAddress("electrum.acinq.co", 50001, TcpSocket.TLS.DISABLED)
|
Chain.Mainnet -> "mempool.space"
|
||||||
Chain.Testnet -> ServerAddress("testnet1.electrum.acinq.co", 51001, TcpSocket.TLS.DISABLED)
|
Chain.Testnet -> "mempool.space/testnet"
|
||||||
else -> error("unsupported chain")
|
else -> error("unsupported chain")
|
||||||
}
|
}
|
||||||
val lsp = LSP.from(chain)
|
val lsp = LSP.from(chain)
|
||||||
@ -239,9 +236,10 @@ class Phoenixd : CliktCommand() {
|
|||||||
val channelsDb = SqliteChannelsDb(driver, database)
|
val channelsDb = SqliteChannelsDb(driver, database)
|
||||||
val paymentsDb = SqlitePaymentsDb(database)
|
val paymentsDb = SqlitePaymentsDb(database)
|
||||||
|
|
||||||
val electrum = ElectrumClient(scope, loggerFactory)
|
val mempoolSpace = MempoolSpaceClient(mempoolSpaceHost, loggerFactory)
|
||||||
|
val watcher = MempoolSpaceWatcher(mempoolSpace, scope, loggerFactory)
|
||||||
val peer = Peer(
|
val peer = Peer(
|
||||||
nodeParams = nodeParams, walletParams = lsp.walletParams, watcher = ElectrumWatcher(electrum, scope, loggerFactory), db = object : Databases {
|
nodeParams = nodeParams, walletParams = lsp.walletParams, client = mempoolSpace, watcher = watcher, db = object : Databases {
|
||||||
override val channels: ChannelsDb get() = channelsDb
|
override val channels: ChannelsDb get() = channelsDb
|
||||||
override val payments: PaymentsDb get() = paymentsDb
|
override val payments: PaymentsDb get() = paymentsDb
|
||||||
}, socketBuilder = TcpSocket.Builder(), scope
|
}, socketBuilder = TcpSocket.Builder(), scope
|
||||||
@ -266,16 +264,6 @@ class Phoenixd : CliktCommand() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val listeners = scope.launch {
|
val listeners = scope.launch {
|
||||||
launch {
|
|
||||||
// drop initial CLOSED event
|
|
||||||
electrum.connectionStatus.dropWhile { it is ElectrumConnectionStatus.Closed }.collect {
|
|
||||||
when (it) {
|
|
||||||
is ElectrumConnectionStatus.Connecting -> echo(yellow("connecting to electrum server..."))
|
|
||||||
is ElectrumConnectionStatus.Connected -> echo(yellow("connected to electrum server"))
|
|
||||||
is ElectrumConnectionStatus.Closed -> echo(yellow("disconnected from electrum server"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
launch {
|
launch {
|
||||||
// drop initial CLOSED event
|
// drop initial CLOSED event
|
||||||
peer.connectionState.dropWhile { it is Connection.CLOSED }.collect {
|
peer.connectionState.dropWhile { it is Connection.CLOSED }.collect {
|
||||||
@ -308,9 +296,15 @@ class Phoenixd : CliktCommand() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runBlocking {
|
val peerConnectionLoop = scope.launch {
|
||||||
electrum.connect(electrumServer, TcpSocket.Builder())
|
while (true) {
|
||||||
peer.connect(connectTimeout = 10.seconds, handshakeTimeout = 10.seconds)
|
peer.connect(connectTimeout = 10.seconds, handshakeTimeout = 10.seconds)
|
||||||
|
peer.connectionState.first { it is Connection.CLOSED }
|
||||||
|
delay(3.seconds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runBlocking {
|
||||||
peer.connectionState.first { it == Connection.ESTABLISHED }
|
peer.connectionState.first { it == Connection.ESTABLISHED }
|
||||||
peer.registerFcmToken("super-${randomBytes32().toHex()}")
|
peer.registerFcmToken("super-${randomBytes32().toHex()}")
|
||||||
peer.setAutoLiquidityParams(liquidityOptions.autoLiquidity)
|
peer.setAutoLiquidityParams(liquidityOptions.autoLiquidity)
|
||||||
@ -339,10 +333,10 @@ class Phoenixd : CliktCommand() {
|
|||||||
}
|
}
|
||||||
server.environment.monitor.subscribe(ApplicationStopPreparing) {
|
server.environment.monitor.subscribe(ApplicationStopPreparing) {
|
||||||
echo(brightYellow("shutting down..."))
|
echo(brightYellow("shutting down..."))
|
||||||
electrum.stop()
|
listeners.cancel()
|
||||||
|
peerConnectionLoop.cancel()
|
||||||
peer.disconnect()
|
peer.disconnect()
|
||||||
server.stop()
|
server.stop()
|
||||||
listeners.cancel()
|
|
||||||
exitProcess(0)
|
exitProcess(0)
|
||||||
}
|
}
|
||||||
server.environment.monitor.subscribe(ApplicationStopped) { echo(brightYellow("http server stopped")) }
|
server.environment.monitor.subscribe(ApplicationStopped) { echo(brightYellow("http server stopped")) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user