-
Notifications
You must be signed in to change notification settings - Fork 9
/
DispatchActivity.kt
60 lines (49 loc) · 2.04 KB
/
DispatchActivity.kt
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
package com.example.umlandowallet
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.example.umlandowallet.data.OnchainWallet
import com.example.umlandowallet.utils.LDKTAG
import java.io.File
class DispatchActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Global.homeDir = filesDir.absolutePath + "/uMlando"
val directory = File(Global.homeDir)
if(!directory.exists()) {
directory.mkdir()
}
// Initialize the LDK data directory if necessary.
Global.homeDir += "/" + "ldk-data"
val ldkDataDirectory = File(Global.homeDir)
if(!ldkDataDirectory.exists()) {
ldkDataDirectory.mkdir()
Log.i(LDKTAG, "Creating directory at $ldkDataDirectory")
}
val latestBlockHeight = OnchainWallet.getHeight()
val latestBlockHash = OnchainWallet.getBlockHash(latestBlockHeight)
var serializedChannelManager = ""
var serializedChannelMonitors = ""
var monitors = arrayOf<String>()
File(Global.homeDir).walk().forEach {
if(it.name.startsWith(Global.prefixChannelManager)) {
serializedChannelManager = it.absoluteFile.readText(Charsets.UTF_8)
}
if(it.name.startsWith(Global.prefixChannelMonitor)) {
val serializedMonitor = it.absoluteFile.readText(Charsets.UTF_8)
monitors = monitors.plus(serializedMonitor)
}
}
serializedChannelMonitors = monitors.joinToString(separator = ",")
Log.i(TAG, "Successfully created/restored wallet with mnemonic ${OnchainWallet.recoveryPhrase()}")
start(
OnchainWallet.getLdkEntropy(),
latestBlockHeight.toInt(),
latestBlockHash,
serializedChannelManager,
serializedChannelMonitors
)
startActivity(Intent(this, MainActivity::class.java))
}
}