You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Retrieve onchain feerate when we connect to an electrum server
When we connect to an electrum sever we perform a "handshake" that includes exchanging protocol version messages and
retrieving the server's current tip, and now we also retrieve onchain fees.
We also add an extra, optional CoroutineExceptionHandler to ElectrumClient's constructor, which can be used for testing or to specify a different
behaviour to the one that is currently hard-coded.
Since this is done during the connection handshake, errors will be caught by the corouting exception handler that
we use in the client and will not crash the application.
"blockchain.estimatefee"->"""{"jsonrpc": "2.0", "error": {"code": 42, "message": "$myCustomError"}, "id": 2}"""// we return an error, as if estimatefee had failed
val myErrorHandler =CoroutineExceptionHandler { _, e ->
226
+
logger.error(e) { "error caught in custom exception handler" }
227
+
errorFlow.value = e
228
+
}
229
+
230
+
runBlocking(Dispatchers.IO) {
231
+
withTimeout(15.seconds) {
232
+
val builder =MyBuilder()
233
+
// from Kotlin's documentation:
234
+
// all children coroutines (coroutines created in the context of another Job) delegate handling of their exceptions to their parent coroutine, which
235
+
// also delegates to the parent, and so on until the root, so the CoroutineExceptionHandler installed in their context is never used
236
+
// => here we need to create a new root scope otherwise our exception handler will not be used
237
+
val client =ElectrumClient(builder, GlobalScope, LoggerFactory.default, myErrorHandler)
238
+
client.connect(ServerAddress("my-test-node", 50002, TcpSocket.TLS.DISABLED)) // address and port do not matter, but we cannot use TLS (not implemented, see above)
// if we use runBlocking's scope, our exception handler will not be used
244
+
errorFlow.value =null
245
+
val error = assertFails {
246
+
withTimeout(15.seconds) {
247
+
val builder =MyBuilder()
248
+
val client =ElectrumClient(builder, this, LoggerFactory.default, myErrorHandler)
249
+
client.connect(ServerAddress("my-test-node", 50002, TcpSocket.TLS.DISABLED)) // address and port do not matter, but we cannot use TLS (not implemented, see above)
0 commit comments