-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathElectrumServer.kt
More file actions
76 lines (65 loc) · 2.2 KB
/
ElectrumServer.kt
File metadata and controls
76 lines (65 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Copyright 2021-2023 thunderbiscuit and contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the ./LICENSE file.
*/
package com.goldenraven.devkitwallet.domain
import android.util.Log
import org.bitcoindevkit.Blockchain
import org.bitcoindevkit.BlockchainConfig
import org.bitcoindevkit.ElectrumConfig
private const val TAG = "ElectrumServer"
class ElectrumServer {
private var useDefaultElectrum: Boolean = true
private var default: Blockchain
private var custom: Blockchain? = null
private var customElectrumURL: String
private val defaultElectrumURL = "ssl://electrum.blockstream.info:60002"
init {
val blockchainConfig = BlockchainConfig.Electrum(ElectrumConfig(
url = defaultElectrumURL,
socks5 = null,
retry = 5u,
timeout = null,
stopGap = 10u,
validateDomain = true
))
customElectrumURL = ""
default = Blockchain(blockchainConfig)
}
val server: Blockchain
get() = if (useDefaultElectrum) this.default else this.custom!!
// if you're looking to test different public Electrum servers we recommend these 3:
// ssl://electrum.blockstream.info:60002
// tcp://electrum.blockstream.info:60001
// tcp://testnet.aranguren.org:51001
fun createCustomElectrum(electrumURL: String) {
customElectrumURL = electrumURL
val blockchainConfig = BlockchainConfig.Electrum(ElectrumConfig(
url = customElectrumURL,
socks5 = null,
retry = 5u,
timeout = null,
stopGap = 10u,
validateDomain = true
))
custom = Blockchain(blockchainConfig)
useCustomElectrum()
Log.i(TAG, "New Electrum Server URL : $customElectrumURL")
}
fun useCustomElectrum() {
useDefaultElectrum = false
}
fun useDefaultElectrum() {
useDefaultElectrum = true
}
fun isElectrumServerDefault(): Boolean {
return useDefaultElectrum
}
fun getElectrumURL(): String {
return if (useDefaultElectrum) {
defaultElectrumURL
} else {
customElectrumURL
}
}
}