-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEnv.kt
More file actions
234 lines (198 loc) · 9.04 KB
/
Env.kt
File metadata and controls
234 lines (198 loc) · 9.04 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package to.bitkit.env
import android.os.Build
import org.lightningdevkit.ldknode.LogLevel
import org.lightningdevkit.ldknode.Network
import org.lightningdevkit.ldknode.PeerDetails
import to.bitkit.BuildConfig
import to.bitkit.ext.ensureDir
import to.bitkit.ext.parse
import to.bitkit.models.BlocktankNotificationType
import to.bitkit.utils.Logger
import java.io.File
import kotlin.io.path.Path
@Suppress("ConstPropertyName", "KotlinConstantConditions")
internal object Env {
val isDebug = BuildConfig.DEBUG
const val isE2eTest = BuildConfig.E2E
const val isGeoblockingEnabled = BuildConfig.GEO
private val e2eBackend = BuildConfig.E2E_BACKEND.lowercase()
val network = Network.valueOf(BuildConfig.NETWORK)
val locales = BuildConfig.LOCALES.split(",")
val walletSyncIntervalSecs = 10_uL // TODO review
val platform = "Android ${Build.VERSION.RELEASE} (API ${Build.VERSION.SDK_INT})"
const val version = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"
val ldkLogLevel = LogLevel.TRACE
val trustedLnPeers
get() = when (network) {
Network.BITCOIN -> listOf(Peers.mainnetLnd1, Peers.mainnetLnd3, Peers.mainnetLnd4)
Network.REGTEST -> listOf(Peers.staging)
Network.TESTNET -> listOf(Peers.staging)
else -> emptyList()
}
const val fxRateRefreshInterval: Long = 2 * 60 * 1000 // 2 minutes in milliseconds
const val fxRateStaleThreshold: Long = 10 * 60 * 1000 // 10 minutes in milliseconds
const val blocktankOrderRefreshInterval: Long = 2 * 60 * 1000 // 2 minutes in milliseconds
val pushNotificationFeatures = listOf(
BlocktankNotificationType.incomingHtlc,
BlocktankNotificationType.mutualClose,
BlocktankNotificationType.orderPaymentConfirmed,
BlocktankNotificationType.cjitPaymentArrived,
BlocktankNotificationType.wakeToTimeout,
)
const val DERIVATION_NAME = "bitkit-notifications"
const val FILE_PROVIDER_AUTHORITY = "${BuildConfig.APPLICATION_ID}.fileprovider"
const val SUPPORT_EMAIL = "support@synonym.to"
const val DEFAULT_INVOICE_MESSAGE = "Bitkit"
const val PIN_LENGTH = 4
const val PIN_ATTEMPTS = 8
// region File Paths
private lateinit var appStoragePath: String
fun initAppStoragePath(path: String) {
require(path.isNotBlank()) { "App storage path cannot be empty." }
appStoragePath = path
Logger.info("App storage path: $path")
}
val logDir: File
get() {
require(::appStoragePath.isInitialized)
return File(appStoragePath).resolve("logs").ensureDir()
}
fun ldkStoragePath(walletIndex: Int) = storagePathOf(walletIndex, network.name.lowercase(), "ldk")
fun bitkitCoreStoragePath(walletIndex: Int): String {
return storagePathOf(walletIndex, network.name.lowercase(), "core")
}
/**
* Generates the storage path for a specified wallet index, network, and directory.
*
* Output format:
*
* `appStoragePath/network/walletN/dir`
*/
private fun storagePathOf(walletIndex: Int, network: String, dir: String): String {
require(::appStoragePath.isInitialized) { "App storage path should be 'context.filesDir.absolutePath'." }
val path = Path(appStoragePath, network, "wallet$walletIndex", dir)
.toFile()
.ensureDir()
.path
Logger.debug("Using ${dir.uppercase()} storage path: $path")
return path
}
// endregion
// region Server URLs
val electrumServerUrl: String
get() {
if (isE2eTest && e2eBackend == "local") return ElectrumServers.E2E
return when (network) {
Network.REGTEST -> ElectrumServers.REGTEST
Network.TESTNET -> ElectrumServers.TESTNET
Network.BITCOIN -> ElectrumServers.BITCOIN
else -> TODO("${network.name} network not implemented")
}
}
val ldkRgsServerUrl
get() = when (network) {
Network.BITCOIN -> "https://rgs.blocktank.to/snapshot"
Network.TESTNET -> "https://rapidsync.lightningdevkit.org/testnet/snapshot"
Network.REGTEST -> "https://bitkit.stag0.blocktank.to/rgs/snapshot"
else -> null
}
val vssStoreIdPrefix get() = "bitkit_v1_${network.name.lowercase()}"
val vssServerUrl
get() = when (network) {
Network.BITCOIN -> "https://bitkit.to/vss_rs_auth"
else -> "https://bitkit.stag0.blocktank.to/vss_rs_auth"
}
val lnurlAuthServerUrl
get() = when (network) {
Network.BITCOIN -> "https://bitkit.to/lnurl_auth/auth"
else -> "https://bitkit.stag0.blocktank.to/lnurl_auth/auth"
}
val blockExplorerUrl
get() = when (network) {
Network.BITCOIN -> "https://mempool.space"
Network.SIGNET -> "https://mutinynet.com"
Network.TESTNET -> "https://mempool.space/testnet"
Network.REGTEST -> "https://mempool.bitkit.stag0.blocktank.to/"
}
val blocktankBaseUrl
get() = when (network) {
Network.BITCOIN -> "https://api1.blocktank.to"
else -> "https://api.stag0.blocktank.to"
}
val blocktankApiUrl
get() = when (network) {
Network.BITCOIN -> "$blocktankBaseUrl/api"
else -> "$blocktankBaseUrl/blocktank/api/v2"
}
val blocktankNotificationApiUrl
get() = when (network) {
Network.BITCOIN -> "$blocktankBaseUrl/api/notifications"
else -> "$blocktankBaseUrl/notifications/api"
}
val btcRatesServer
get() = when (network) {
Network.BITCOIN -> "https://blocktank.synonym.to/fx/rates/btc"
else -> "https://bitkit.stag0.blocktank.to/fx/rates/btc"
}
const val geoCheckUrl = "https://api1.blocktank.to/api/geocheck"
const val chatwootUrl = "https://synonym.to/api/chatwoot"
const val newsBaseUrl = "https://feeds.synonym.to/news-feed/api"
const val mempoolBaseUrl = "https://mempool.space/api"
const val pricesWidgetBaseUrl = "https://feeds.synonym.to/price-feed/api"
const val APP_STORE_URL = "https://apps.apple.com/app/bitkit-wallet/id6502440655"
const val PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=to.bitkit"
const val RELEASE_URL = "https://github.com/synonymdev/bitkit-android/releases/download/updater/release.json"
const val EXCHANGES_URL = "https://bitcoin.org/en/exchanges#international"
const val BTC_MAP_URL = "https://btcmap.org/map"
const val BITKIT_WEBSITE = "https://bitkit.to/"
const val SYNONYM_CONTACT = "https://synonym.to/contact"
const val SYNONYM_MEDIUM = "https://medium.com/synonym-to"
const val SYNONYM_X = "https://twitter.com/bitkitwallet/"
const val BITKIT_DISCORD = "https://discord.gg/DxTBJXvJxn"
const val BITKIT_TELEGRAM = "https://t.me/bitkitchat"
const val BITKIT_GITHUB = "https://github.com/synonymdev"
const val BITKIT_HELP_CENTER = "https://help.bitkit.to"
const val TERMS_OF_USE_URL = "https://bitkit.to/terms-of-use"
const val PRIVACY_POLICY_URL = "https://bitkit.to/privacy-policy"
const val STORING_BITCOINS_URL = "https://en.bitcoin.it/wiki/Storing_bitcoins"
const val BITREFILL_URL = "https://embed.bitrefill.com"
const val BITREFILL_APP = "Bitkit"
const val BITREFILL_REF = "AL6dyZYt"
val rnBackupServerHost: String
get() = when (network) {
Network.BITCOIN -> "https://blocktank.synonym.to/backups-ldk"
else -> "https://bitkit.stag0.blocktank.to/backups-ldk"
}
val rnBackupServerPubKey: String
get() = when (network) {
Network.BITCOIN -> "0236efd76e37f96cf2dced9d52ff84c97e5b3d4a75e7d494807291971783f38377"
else -> "02c03b8b8c1b5500b622646867d99bf91676fac0f38e2182c91a9ff0d053a21d6d"
}
// endregion
}
@Suppress("ConstPropertyName")
object TransactionDefaults {
/** Total recommended tx base fee in sats */
const val recommendedBaseFee = 256u
/**
* Minimum value in sats for an output. Outputs below the dust limit may not be processed because the fees
* required to include them in a block would be greater than the value of the transaction itself.
* */
const val dustLimit = 546u
}
object Peers {
val staging =
PeerDetails.parse("028a8910b0048630d4eb17af25668cdd7ea6f2d8ae20956e7a06e2ae46ebcb69fc@34.65.86.104:9400")
val mainnetLnd1 =
PeerDetails.parse("039b8b4dd1d88c2c5db374290cda397a8f5d79f312d6ea5d5bfdfc7c6ff363eae3@34.65.111.104:9735")
val mainnetLnd3 =
PeerDetails.parse("03816141f1dce7782ec32b66a300783b1d436b19777e7c686ed00115bd4b88ff4b@34.65.191.64:9735")
val mainnetLnd4 =
PeerDetails.parse("02a371038863605300d0b3fc9de0cf5ccb57728b7f8906535709a831b16e311187@34.65.186.40:9735")
}
private object ElectrumServers {
const val BITCOIN = "ssl://fulcrum.bitkit.blocktank.to:8900"
const val TESTNET = "ssl://electrum.blockstream.info:60002"
const val REGTEST = "tcp://34.65.252.32:18483"
const val E2E = "tcp://127.0.0.1:60001"
}