Skip to content

Commit 8eaea68

Browse files
committed
Stop Local LND daemon on LocalLnd instance remove. Start LocalLnd syncrhonously
1 parent a8f6914 commit 8eaea68

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

LightningKit/Kit.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ public class Kit {
182182

183183
// LocalLnd methods
184184

185-
public func start(password: String) -> Single<Void> {
185+
public func start(password: String) {
186186
guard let localNode = lndNode as? LocalLnd else {
187-
return Single.just(Void())
187+
return
188188
}
189189

190-
return localNode.startAndUnlock(password: password)
190+
localNode.startAndUnlock(password: password)
191191
}
192192

193193
public func create(password: String) -> Single<[String]> {

LightningKit/Local/LocalLnd.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import SwiftProtobuf
55
class LocalLnd: ILndNode {
66
class NodeNotRetained: Error {}
77

8+
deinit {
9+
LndmobileStopDaemon(try! Lnrpc_StopRequest().serializedData(), VoidResponseCallback(emitter: nil))
10+
}
11+
812
private let filesDir: String
913
private let disposeBag = DisposeBag()
1014

@@ -216,18 +220,19 @@ class LocalLnd: ILndNode {
216220
}
217221
}
218222

219-
func startAndUnlock(password: String) -> Single<Void> {
223+
func startAndUnlock(password: String) {
220224
start()
221225
.flatMap { [weak self] _ in
222226
var request = Lnrpc_UnlockWalletRequest()
223227
request.walletPassword = Data(Array(password.utf8))
224228

225229
return self?.unlockWalletSingle(request: request) ?? Single.error(NodeNotRetained())
226230
}
227-
.do(
228-
onSuccess: { [weak self] _ in self?.scheduleStatusUpdates() },
231+
.subscribe(
232+
onSuccess: { [weak self] in self?.scheduleStatusUpdates() },
229233
onError: { [weak self] in self?.status = .error($0) }
230234
)
235+
.disposed(by: disposeBag)
231236
}
232237

233238
func createWalletSingle(password: String) -> Single<[String]> {

0 commit comments

Comments
 (0)