Skip to content

Commit

Permalink
[iOS #308] prepare legacy bitcoin kit remove
Browse files Browse the repository at this point in the history
  • Loading branch information
wannabit-yongjoo committed Oct 31, 2021
1 parent 76e86d2 commit 67e2207
Show file tree
Hide file tree
Showing 15 changed files with 318 additions and 354 deletions.
10 changes: 5 additions & 5 deletions Cosmos-IOS/Cosmostation/Cosmostation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
280E1F2B254AD3A80007BA7D /* ResourceChainCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 280E1F29254AD3A80007BA7D /* ResourceChainCell.xib */; };
280E6CDD2605D78900B3BCBB /* WalletPersisCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 280E6CDB2605D78900B3BCBB /* WalletPersisCell.swift */; };
280E6CDE2605D78900B3BCBB /* WalletPersisCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 280E6CDC2605D78900B3BCBB /* WalletPersisCell.xib */; };
281008482696BA27002986A6 /* OldKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 281008472696BA27002986A6 /* OldKey.swift */; };
2810084A2696D979002986A6 /* KeyFac.swift in Sources */ = {isa = PBXBuildFile; fileRef = 281008492696D979002986A6 /* KeyFac.swift */; };
28105894262EE638009244B8 /* WalletSifCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28105892262EE638009244B8 /* WalletSifCell.swift */; };
28105895262EE638009244B8 /* WalletSifCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28105893262EE638009244B8 /* WalletSifCell.xib */; };
Expand Down Expand Up @@ -355,6 +354,7 @@
285A33E724486DA20052BD3D /* HtlcResultSentCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 285A33E524486DA20052BD3D /* HtlcResultSentCell.xib */; };
285A33EA24486DB60052BD3D /* HtlcResultClaimCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 285A33E824486DB60052BD3D /* HtlcResultClaimCell.swift */; };
285A33EB24486DB60052BD3D /* HtlcResultClaimCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 285A33E924486DB60052BD3D /* HtlcResultClaimCell.xib */; };
285ADF0D272EE35F0023651F /* CKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 285ADF0C272EE35F0023651F /* CKey.swift */; };
285F8C8B25CFB21000317B30 /* OkTicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 285F8C8A25CFB21000317B30 /* OkTicker.swift */; };
285F8C8E25CFB27D00317B30 /* OkTickerList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 285F8C8D25CFB27D00317B30 /* OkTickerList.swift */; };
28617A7B243198D0006D66EA /* StepCreateCpdAmountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 28617A7A243198D0006D66EA /* StepCreateCpdAmountViewController.swift */; };
Expand Down Expand Up @@ -1299,7 +1299,6 @@
280E1F29254AD3A80007BA7D /* ResourceChainCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ResourceChainCell.xib; sourceTree = "<group>"; };
280E6CDB2605D78900B3BCBB /* WalletPersisCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletPersisCell.swift; sourceTree = "<group>"; };
280E6CDC2605D78900B3BCBB /* WalletPersisCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = WalletPersisCell.xib; sourceTree = "<group>"; };
281008472696BA27002986A6 /* OldKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OldKey.swift; sourceTree = "<group>"; };
281008492696D979002986A6 /* KeyFac.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyFac.swift; sourceTree = "<group>"; };
28105892262EE638009244B8 /* WalletSifCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletSifCell.swift; sourceTree = "<group>"; };
28105893262EE638009244B8 /* WalletSifCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = WalletSifCell.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1564,6 +1563,7 @@
285A33E524486DA20052BD3D /* HtlcResultSentCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HtlcResultSentCell.xib; sourceTree = "<group>"; };
285A33E824486DB60052BD3D /* HtlcResultClaimCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HtlcResultClaimCell.swift; sourceTree = "<group>"; };
285A33E924486DB60052BD3D /* HtlcResultClaimCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HtlcResultClaimCell.xib; sourceTree = "<group>"; };
285ADF0C272EE35F0023651F /* CKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CKey.swift; sourceTree = "<group>"; };
285F8C8A25CFB21000317B30 /* OkTicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OkTicker.swift; sourceTree = "<group>"; };
285F8C8D25CFB27D00317B30 /* OkTickerList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OkTickerList.swift; sourceTree = "<group>"; };
28617A7A243198D0006D66EA /* StepCreateCpdAmountViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StepCreateCpdAmountViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4007,14 +4007,14 @@
E17748E52282D782003D8CD1 /* BTCProtocolSerialization.m */,
E17748E22282D6AD003D8CD1 /* BTCMnemonic.h */,
E17748E12282D6AD003D8CD1 /* BTCMnemonic.m */,
281008492696D979002986A6 /* KeyFac.swift */,
E16D9B1C2248E6A60019B7BB /* WKey.swift */,
281008472696BA27002986A6 /* OldKey.swift */,
285ADF0C272EE35F0023651F /* CKey.swift */,
E1A82DE722448E940097CAEE /* WUtils.swift */,
E1A82DF62244FA750097CAEE /* UIColor.swift */,
E16FACB02361ADFA00372052 /* Bytes.swift */,
E17748D82282C612003D8CD1 /* Cosmostation-Bridging-Header.h */,
28E3E370266D033100BA89C2 /* HdacUtil.swift */,
281008492696D979002986A6 /* KeyFac.swift */,
28D765A1271585FA00730F47 /* StarnameAssets.swift */,
);
path = Utils;
Expand Down Expand Up @@ -4566,6 +4566,7 @@
28E46BE624F8FD14005CE985 /* StepOkVoteCheckViewController.swift in Sources */,
287AC5D525FDF7250070837E /* cosmos_crisis_v1beta1_genesis.pb.swift in Sources */,
28B3251F2637F80500275AED /* MemoMnemonicPopup.swift in Sources */,
285ADF0D272EE35F0023651F /* CKey.swift in Sources */,
287AC5CC25FDF7250070837E /* cosmos_mint_v1beta1_query.grpc.swift in Sources */,
28BBAAC6264945890013A555 /* WalletOkAddressCell.swift in Sources */,
287AC62E25FDF7260070837E /* htlc_htlc.pb.swift in Sources */,
Expand Down Expand Up @@ -4886,7 +4887,6 @@
287AC5C825FDF7250070837E /* cosmos_bank_v1beta1_tx.grpc.swift in Sources */,
E1827E2F225629BF00BC0350 /* ValidatorDetailHistoryEmpty.swift in Sources */,
2887BA3626DE278700CDA415 /* shentu_gov_v1alpha1_tx.grpc.swift in Sources */,
281008482696BA27002986A6 /* OldKey.swift in Sources */,
285A33E624486DA20052BD3D /* HtlcResultSentCell.swift in Sources */,
28BB2A912533DA2D00CFF097 /* AccountCell.swift in Sources */,
287AC59925FDF7250070837E /* coinswap_tx.grpc.swift in Sources */,
Expand Down
2 changes: 0 additions & 2 deletions Cosmos-IOS/Cosmostation/Cosmostation/Base/BaseConstant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ let DB_ACCOUNT_SORT_ORDER = Expression<Int64>("sortOrder")
let DB_ACCOUNT_PUSHALARM = Expression<Bool>("pushAlarm")
let DB_ACCOUNT_NEW_BIP = Expression<Bool>("newBip") //using alternative ket gen path or type(OKex)
let DB_ACCOUNT_CUSTOM_PATH = Expression<Int64>("customPath")
let DB_ACCOUNT_PUBLIC_KEY = Expression<String>("publicKey")
let DB_ACCOUNT_FULL_HD_PATH = Expression<String>("fullHdPath")

////DB for Password
//let DB_PASSWORD = Table("passwd")
Expand Down
59 changes: 9 additions & 50 deletions Cosmos-IOS/Cosmostation/Cosmostation/Base/BaseData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -809,11 +809,11 @@ final class BaseData : NSObject{
do { try self.database.run(DB_ACCOUNT.addColumn(DB_ACCOUNT_CUSTOM_PATH, defaultValue: 0)) }
catch { print(error) }

do { try self.database.run(DB_ACCOUNT.addColumn(DB_ACCOUNT_PUBLIC_KEY, defaultValue: "")) }
catch { print(error) }
do { try self.database.run(DB_ACCOUNT.addColumn(DB_ACCOUNT_FULL_HD_PATH, defaultValue: "")) }
catch { print(error) }
// do { try self.database.run(DB_ACCOUNT.addColumn(DB_ACCOUNT_PUBLIC_KEY, defaultValue: "")) }
// catch { print(error) }
//
// do { try self.database.run(DB_ACCOUNT.addColumn(DB_ACCOUNT_FULL_HD_PATH, defaultValue: "")) }
// catch { print(error) }

let createBalanceTable = DB_BALANCE.create(ifNotExists: true) { (table) in
table.column(DB_BALANCE_ID, primaryKey: true)
Expand Down Expand Up @@ -872,8 +872,7 @@ final class BaseData : NSObject{
accountBD[DB_ACCOUNT_BASECHAIN], accountBD[DB_ACCOUNT_HAS_PRIVATE], accountBD[DB_ACCOUNT_RESOURCE], accountBD[DB_ACCOUNT_FROM_MNEMONIC],
accountBD[DB_ACCOUNT_PATH], accountBD[DB_ACCOUNT_IS_VALIDATOR], accountBD[DB_ACCOUNT_SEQUENCE_NUMBER], accountBD[DB_ACCOUNT_ACCOUNT_NUMBER],
accountBD[DB_ACCOUNT_FETCH_TIME], accountBD[DB_ACCOUNT_M_SIZE], accountBD[DB_ACCOUNT_IMPORT_TIME], accountBD[DB_ACCOUNT_LAST_TOTAL],
accountBD[DB_ACCOUNT_SORT_ORDER], accountBD[DB_ACCOUNT_PUSHALARM], accountBD[DB_ACCOUNT_NEW_BIP], accountBD[DB_ACCOUNT_CUSTOM_PATH],
accountBD[DB_ACCOUNT_PUBLIC_KEY], accountBD[DB_ACCOUNT_FULL_HD_PATH]);
accountBD[DB_ACCOUNT_SORT_ORDER], accountBD[DB_ACCOUNT_PUSHALARM], accountBD[DB_ACCOUNT_NEW_BIP], accountBD[DB_ACCOUNT_CUSTOM_PATH]);
account.setBalances(selectBalanceById(accountId: account.account_id))
result.append(account);
}
Expand Down Expand Up @@ -926,8 +925,7 @@ final class BaseData : NSObject{
accountBD[DB_ACCOUNT_BASECHAIN], accountBD[DB_ACCOUNT_HAS_PRIVATE], accountBD[DB_ACCOUNT_RESOURCE], accountBD[DB_ACCOUNT_FROM_MNEMONIC],
accountBD[DB_ACCOUNT_PATH], accountBD[DB_ACCOUNT_IS_VALIDATOR], accountBD[DB_ACCOUNT_SEQUENCE_NUMBER], accountBD[DB_ACCOUNT_ACCOUNT_NUMBER],
accountBD[DB_ACCOUNT_FETCH_TIME], accountBD[DB_ACCOUNT_M_SIZE], accountBD[DB_ACCOUNT_IMPORT_TIME], accountBD[DB_ACCOUNT_LAST_TOTAL],
accountBD[DB_ACCOUNT_SORT_ORDER], accountBD[DB_ACCOUNT_PUSHALARM], accountBD[DB_ACCOUNT_NEW_BIP], accountBD[DB_ACCOUNT_CUSTOM_PATH],
accountBD[DB_ACCOUNT_PUBLIC_KEY], accountBD[DB_ACCOUNT_FULL_HD_PATH])
accountBD[DB_ACCOUNT_SORT_ORDER], accountBD[DB_ACCOUNT_PUSHALARM], accountBD[DB_ACCOUNT_NEW_BIP], accountBD[DB_ACCOUNT_CUSTOM_PATH])
account.setBalances(selectBalanceById(accountId: account.account_id))
if (!ChainType.IS_SUPPORT_CHAIN(account.account_base_chain)) {
if (selectAllAccounts().count > 0) {
Expand All @@ -953,8 +951,7 @@ final class BaseData : NSObject{
accountBD[DB_ACCOUNT_BASECHAIN], accountBD[DB_ACCOUNT_HAS_PRIVATE], accountBD[DB_ACCOUNT_RESOURCE], accountBD[DB_ACCOUNT_FROM_MNEMONIC],
accountBD[DB_ACCOUNT_PATH], accountBD[DB_ACCOUNT_IS_VALIDATOR], accountBD[DB_ACCOUNT_SEQUENCE_NUMBER], accountBD[DB_ACCOUNT_ACCOUNT_NUMBER],
accountBD[DB_ACCOUNT_FETCH_TIME], accountBD[DB_ACCOUNT_M_SIZE], accountBD[DB_ACCOUNT_IMPORT_TIME], accountBD[DB_ACCOUNT_LAST_TOTAL],
accountBD[DB_ACCOUNT_SORT_ORDER], accountBD[DB_ACCOUNT_PUSHALARM], accountBD[DB_ACCOUNT_NEW_BIP], accountBD[DB_ACCOUNT_CUSTOM_PATH],
accountBD[DB_ACCOUNT_PUBLIC_KEY], accountBD[DB_ACCOUNT_FULL_HD_PATH])
accountBD[DB_ACCOUNT_SORT_ORDER], accountBD[DB_ACCOUNT_PUSHALARM], accountBD[DB_ACCOUNT_NEW_BIP], accountBD[DB_ACCOUNT_CUSTOM_PATH])
}
return nil
} catch {
Expand All @@ -971,8 +968,7 @@ final class BaseData : NSObject{
accountBD[DB_ACCOUNT_BASECHAIN], accountBD[DB_ACCOUNT_HAS_PRIVATE], accountBD[DB_ACCOUNT_RESOURCE], accountBD[DB_ACCOUNT_FROM_MNEMONIC],
accountBD[DB_ACCOUNT_PATH], accountBD[DB_ACCOUNT_IS_VALIDATOR], accountBD[DB_ACCOUNT_SEQUENCE_NUMBER], accountBD[DB_ACCOUNT_ACCOUNT_NUMBER],
accountBD[DB_ACCOUNT_FETCH_TIME], accountBD[DB_ACCOUNT_M_SIZE], accountBD[DB_ACCOUNT_IMPORT_TIME], accountBD[DB_ACCOUNT_LAST_TOTAL],
accountBD[DB_ACCOUNT_SORT_ORDER], accountBD[DB_ACCOUNT_PUSHALARM], accountBD[DB_ACCOUNT_NEW_BIP], accountBD[DB_ACCOUNT_CUSTOM_PATH],
accountBD[DB_ACCOUNT_PUBLIC_KEY], accountBD[DB_ACCOUNT_FULL_HD_PATH])
accountBD[DB_ACCOUNT_SORT_ORDER], accountBD[DB_ACCOUNT_PUSHALARM], accountBD[DB_ACCOUNT_NEW_BIP], accountBD[DB_ACCOUNT_CUSTOM_PATH])
}
return nil
} catch {
Expand Down Expand Up @@ -1095,17 +1091,6 @@ final class BaseData : NSObject{
}
}

public func updateKeyWay(_ account: Account?, _ publicKey: String, _ fullPath: String) {
let target = DB_ACCOUNT.filter(DB_ACCOUNT_ID == account!.account_id)
do {
try database.run(target.update(DB_ACCOUNT_PUBLIC_KEY <- publicKey))
try database.run(target.update(DB_ACCOUNT_FULL_HD_PATH <- fullPath))
} catch {
print(error)
}

}

public func updateSortOrder(_ accounts: Array<Account>) {
for account in accounts {
let target = DB_ACCOUNT.filter(DB_ACCOUNT_ID == account.account_id)
Expand Down Expand Up @@ -1136,32 +1121,6 @@ final class BaseData : NSObject{
}
}

public func onCheckKeyWayUpdated() -> Bool {
for account in selectAllAccounts() {
if (account.account_has_private == true && account.account_full_hd_path.isEmpty == true) {
return true
}
}
return false
}

public func upgradeKeyWay() {
for account in selectAllAccounts() {
if (account.account_has_private == true && account.account_full_hd_path.isEmpty == true) {
let words = KeychainWrapper.standard.string(forKey: account.account_uuid.sha1())?.trimmingCharacters(in: .whitespacesAndNewlines).components(separatedBy: " ")
let privateKey = WKey.getHDKeyFromWords(words!, account)
let privateKeyResult = KeychainWrapper.standard.set(privateKey.raw.hexEncodedString(), forKey: account.getPrivateKeySha1(), withAccessibility: .afterFirstUnlockThisDeviceOnly)
let fullPath = WUtils.getChainCustomPathS(WUtils.getChainType(account.account_base_chain)!,
account.account_new_bip44,
Int(account.account_custom_path),
Int(account.account_path)!)
if (privateKeyResult) {
self.updateKeyWay(account, privateKey.publicKey.data.hexEncodedString(), fullPath)
}
}
}
}

public func hasPassword() -> Bool{
if(KeychainWrapper.standard.hasValue(forKey: "password")) {
return true;
Expand Down
25 changes: 0 additions & 25 deletions Cosmos-IOS/Cosmostation/Cosmostation/Base/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,6 @@ class BaseViewController: UIViewController {

}

public func showDBWaittingAlert() {
let attributedTitle = NSAttributedString(string: "DB Upgrade", attributes: [
NSAttributedString.Key.font : UIFont.systemFont(ofSize: 18),
NSAttributedString.Key.foregroundColor : UIColor.white
])
let attributedMsg = NSAttributedString(string: "\n\n\n\nPlease Wait\n(Do not close)", attributes: [
NSAttributedString.Key.font : UIFont.systemFont(ofSize: 15),
NSAttributedString.Key.foregroundColor : UIColor.white
])
waitAlert = UIAlertController(title: "", message: "", preferredStyle: .alert)
waitAlert!.setValue(attributedTitle, forKey: "attributedTitle")
waitAlert!.setValue(attributedMsg, forKey: "attributedMessage")
let image = LoadingImageView(frame: CGRect(x: 0, y: 0, width: 58, height: 58))
waitAlert!.view.addSubview(image)
image.translatesAutoresizingMaskIntoConstraints = false
waitAlert!.view.addConstraint(NSLayoutConstraint(item: image, attribute: .centerX, relatedBy: .equal, toItem: waitAlert!.view, attribute: .centerX, multiplier: 1, constant: 0))
waitAlert!.view.addConstraint(NSLayoutConstraint(item: image, attribute: .centerY, relatedBy: .equal, toItem: waitAlert!.view, attribute: .centerY, multiplier: 1, constant: 0))
waitAlert!.view.addConstraint(NSLayoutConstraint(item: image, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 58.0))
waitAlert!.view.addConstraint(NSLayoutConstraint(item: image, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 58.0))
WUtils.clearBackgroundColor(of: waitAlert!.view)
self.present(waitAlert!, animated: true, completion: nil)
image.onStartAnimation()

}

public func hideWaittingAlert() {
if (waitAlert != nil) {
waitAlert?.dismiss(animated: true, completion: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,9 @@ class CreateViewController: BaseViewController, PasswordViewDelegate{
resource = resource + " " + word
}
let mnemonoicResult = KeychainWrapper.standard.set(resource, forKey: newAccount.account_uuid.sha1(), withAccessibility: .afterFirstUnlockThisDeviceOnly)
let privateKey = WKey.getHDKeyFromWords(self.mnemonicWords!, newAccount)
let privateKeyResult = KeychainWrapper.standard.set(privateKey.raw.hexEncodedString(), forKey: newAccount.getPrivateKeySha1(), withAccessibility: .afterFirstUnlockThisDeviceOnly)

var insertResult :Int64 = -1
if (mnemonoicResult && privateKeyResult) {
if (mnemonoicResult) {
newAccount.account_has_private = true
newAccount.account_from_mnemonic = true
newAccount.account_m_size = 24
Expand All @@ -230,8 +228,6 @@ class CreateViewController: BaseViewController, PasswordViewDelegate{
newAccount.account_new_bip44 = true
}
newAccount.account_sort_order = 9999
newAccount.account_public_key = privateKey.publicKey.data.hexEncodedString()
newAccount.account_full_hd_path = WUtils.getChainBasePathS(chain, 0)
insertResult = BaseData.instance.insertAccount(newAccount)

if (insertResult < 0) {
Expand All @@ -242,7 +238,7 @@ class CreateViewController: BaseViewController, PasswordViewDelegate{

DispatchQueue.main.async(execute: {
self.hideWaittingAlert()
if (mnemonoicResult && privateKeyResult && insertResult > 0) {
if (mnemonoicResult && insertResult > 0) {
var hiddenChains = BaseData.instance.userHideChains()
if (hiddenChains.contains(chain)) {
if let position = hiddenChains.firstIndex { $0 == chain } {
Expand Down
Loading

0 comments on commit 67e2207

Please sign in to comment.