-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a migrating service to a new VWS endpoint
- Loading branch information
1 parent
41dccaa
commit 59c0e4a
Showing
6 changed files
with
167 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// WalletManagerProtocol.swift | ||
// VergeiOS | ||
// | ||
// Created by Swen van Zanten on 26/10/2019. | ||
// Copyright © 2019 Verge Currency. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol WalletManagerProtocol { | ||
func joinWallet(createWallet: Bool, completion: @escaping (_ error: Error?) -> Void) | ||
func createWallet(completion: @escaping (_ error: Error?) -> Void) | ||
func synchronizeWallet(completion: @escaping (_ error: Error?) -> Void) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// WalletManager.swift | ||
// VergeiOS | ||
// | ||
// Created by Swen van Zanten on 26/10/2019. | ||
// Copyright © 2019 Verge Currency. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class WalletManager: WalletManagerProtocol { | ||
let walletClient: WalletClientProtocol | ||
let walletTicker: WalletTicker | ||
let applicationRepository: ApplicationRepository | ||
|
||
let walletName = "ioswallet" | ||
let copayerName = "iosuser" | ||
let walletM = 1 | ||
let walletN = 1 | ||
|
||
init(walletClient: WalletClientProtocol, walletTicker: WalletTicker, applicationRepository: ApplicationRepository) { | ||
self.walletClient = walletClient | ||
self.walletTicker = walletTicker | ||
self.applicationRepository = applicationRepository | ||
} | ||
|
||
func joinWallet(createWallet: Bool = true, completion: @escaping (_ error: Error?) -> Void = { _ in }) { | ||
self.walletTicker.stop() | ||
|
||
self.walletClient.joinWallet(walletIdentifier: self.applicationRepository.walletId!) { error in | ||
if error == nil { | ||
return DispatchQueue.main.async { | ||
self.walletTicker.start() | ||
completion(nil) | ||
} | ||
} | ||
|
||
if !createWallet { | ||
return | ||
} | ||
|
||
print("Joining wallet failed... trying to create a new wallet") | ||
|
||
return self.createWallet(completion: completion) | ||
} | ||
} | ||
|
||
func createWallet(completion: @escaping (_ error: Error?) -> Void = { _ in }) { | ||
self.walletTicker.stop() | ||
|
||
self.walletClient.createWallet( | ||
walletName: self.walletName, | ||
copayerName: self.copayerName, | ||
m: self.walletM, | ||
n: self.walletN, | ||
options: nil | ||
) { error, secret in | ||
if (error != nil || secret == nil) { | ||
DispatchQueue.main.async { | ||
completion(error) | ||
} | ||
|
||
return print(error ?? "") | ||
} | ||
|
||
self.joinWallet(createWallet: false, completion: completion) | ||
} | ||
} | ||
|
||
func synchronizeWallet(completion: @escaping (_ error: Error?) -> Void = { _ in }) { | ||
self.walletClient.scanAddresses(completion: completion) | ||
} | ||
} |