Skip to content

Commit

Permalink
Merge pull request #29 from soramitsu/feature/singleton
Browse files Browse the repository at this point in the history
Use a singleton data manager in framework
  • Loading branch information
Satoshi Kaji authored Oct 1, 2016
2 parents ef16ea1 + e0ed2c7 commit 8eefc84
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ playground.xcworkspace
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
Pods/

# Carthage
#
Expand Down
2 changes: 1 addition & 1 deletion Example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ playground.xcworkspace
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
Pods/

# Carthage
#
Expand Down
48 changes: 48 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
747816EB1D9FA5BA00394583 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 747816E61D9FA5BA00394583 /* IrohaSwift.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 7471C8641D8D942300C151E8;
remoteInfo = IrohaSwift;
};
747816ED1D9FA5BA00394583 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 747816E61D9FA5BA00394583 /* IrohaSwift.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 7471C86E1D8D942300C151E8;
remoteInfo = IrohaSwiftTests;
};
74F1E37B1D8DA6900035760E /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 74F1E35E1D8DA68F0035760E /* Project object */;
Expand Down Expand Up @@ -76,6 +90,7 @@
7473E7BE1D966DFB0093C872 /* Pods_Example.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Pods_Example.framework; path = "Build/Products/Debug-iphonesimulator/Pods_Example.framework"; sourceTree = "<group>"; };
7473E7C11D966E300093C872 /* KeychainAccess.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = KeychainAccess.framework; path = "Build/Products/Debug-iphonesimulator/KeychainAccess/KeychainAccess.framework"; sourceTree = "<group>"; };
7473E7C31D966E330093C872 /* SwiftyJSON.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftyJSON.framework; path = "Build/Products/Debug-iphonesimulator/SwiftyJSON/SwiftyJSON.framework"; sourceTree = "<group>"; };
747816E61D9FA5BA00394583 /* IrohaSwift.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = IrohaSwift.xcodeproj; path = ../IrohaSwift.xcodeproj; sourceTree = "<group>"; };
748A95DD1D93CBAC003524FF /* QRGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QRGenerator.swift; sourceTree = "<group>"; };
748A95E11D93E16B003524FF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
748A95E31D94D69A003524FF /* TransactionHistoryDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransactionHistoryDataManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -135,6 +150,15 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
747816E71D9FA5BA00394583 /* Products */ = {
isa = PBXGroup;
children = (
747816EC1D9FA5BA00394583 /* IrohaSwift.framework */,
747816EE1D9FA5BA00394583 /* IrohaSwiftTests.xctest */,
);
name = Products;
sourceTree = "<group>";
};
74C519321D91660E005A335D /* Controller */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -224,6 +248,7 @@
A28707194C83EE4F15A70E42 /* Frameworks */ = {
isa = PBXGroup;
children = (
747816E61D9FA5BA00394583 /* IrohaSwift.xcodeproj */,
74A8F0A81D982580008CCF51 /* IrohaSwift.framework */,
7473E7C31D966E330093C872 /* SwiftyJSON.framework */,
7473E7C11D966E300093C872 /* KeychainAccess.framework */,
Expand Down Expand Up @@ -344,6 +369,12 @@
mainGroup = 74F1E35D1D8DA68F0035760E;
productRefGroup = 74F1E3671D8DA68F0035760E /* Products */;
projectDirPath = "";
projectReferences = (
{
ProductGroup = 747816E71D9FA5BA00394583 /* Products */;
ProjectRef = 747816E61D9FA5BA00394583 /* IrohaSwift.xcodeproj */;
},
);
projectRoot = "";
targets = (
74F1E3651D8DA68F0035760E /* Example */,
Expand All @@ -353,6 +384,23 @@
};
/* End PBXProject section */

/* Begin PBXReferenceProxy section */
747816EC1D9FA5BA00394583 /* IrohaSwift.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
path = IrohaSwift.framework;
remoteRef = 747816EB1D9FA5BA00394583 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
747816EE1D9FA5BA00394583 /* IrohaSwiftTests.xctest */ = {
isa = PBXReferenceProxy;
fileType = wrapper.cfbundle;
path = IrohaSwiftTests.xctest;
remoteRef = 747816ED1D9FA5BA00394583 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
74F1E3641D8DA68F0035760E /* Resources */ = {
isa = PBXResourcesBuildPhase;
Expand Down
2 changes: 1 addition & 1 deletion Example/Example/AccountInfoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AccountInfoViewController: UIViewController {
self.navigationController?.navigationBar.tintColor = UIColor.white
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]

let qrString = KeychainManager.sharedManager.keychain["publicKeyQ"]
let qrString = KeychainManager.sharedManager.keychain["publicKey"]
QRImage.image = createQRCode(message: qrString!)
}

Expand Down
13 changes: 10 additions & 3 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
//

import UIKit
import IrohaSwift
import KeychainAccess

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -16,14 +18,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//テスト用に毎回削除

let keychain = KeychainManager.sharedManager.keychain
do {
try KeychainManager.sharedManager.keychain.remove("privateKey")
try keychain.remove("privateKey")
try keychain.remove("publicKey")
try keychain.remove("accessPoint")
try keychain.remove("uuid")
} catch let error {
print("error: \(error)")
}

if (KeychainManager.sharedManager.keychain["privateKey"] != nil){
IrohaSwift.setDatas(accessPoint: keychain["accessPoint"]!, publicKey: keychain["publicKey"]!, uuid: keychain["uuid"]!)
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "Tabbar")
Expand Down
5 changes: 1 addition & 4 deletions Example/Example/AssetsListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ class AssetsListViewController : UIViewController, UITableViewDelegate, UITableV

listAlert.view.addSubview(spinnerIndicator)
self.present(listAlert, animated: false, completion: {
let ap = KeychainManager.sharedManager.keychain["accessPoint"]
let uuid = KeychainManager.sharedManager.keychain["uuid"]

let res = IrohaSwift.getAccountInfo(accessPoint: ap!, uuid: uuid!)
let res = IrohaSwift.getAccountInfo()
if res["status"] as! Int == 200 {
self.listAlert.dismiss(animated: false, completion: {() -> Void in
//ここでAssetsDataManager.sharedManager.assetsDataArrayにデータを入れる。
Expand Down
7 changes: 3 additions & 4 deletions Example/Example/CreateAssetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ class CreateAssetViewController : UIViewController, UITextFieldDelegate {
self.present(creatAssetAlert, animated: false, completion: { () -> Void in
var data:Dictionary<String, String>
let keychain = KeychainManager.sharedManager.keychain
let ap = keychain["accessPoint"]
let keypair = (publicKey: keychain["publicKey"]!, privateKey:keychain["privateKey"]!)
let res = IrohaSwift.domainRegister(accessPoint: ap!,domain: self.domainNameField.text!,keyPair: keypair )
let key = keychain["privateKey"]!
let res = IrohaSwift.domainRegister(domain: self.domainNameField.text!,privateKey: key )
if (res["status"] as! Int) == 200 {
let res = IrohaSwift.createAsset(accessPoint: ap!,domain: self.domainNameField.text!,keyPair: keypair , name: self.assetNameField.text!)
let res = IrohaSwift.createAsset(domain: self.domainNameField.text!,privateKey: key , name: self.assetNameField.text!)
if (res["status"] as! Int) == 200{
data = ["domain":self.domainNameField.text!, "name":self.assetNameField.text!, "asset-uuid":res["asset-uuid"] as! String]
AssetsDataManager.sharedManager.assetsDataArray.append(data)
Expand Down
11 changes: 9 additions & 2 deletions Example/Example/RegisterViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,27 @@ class RegisterViewController: UIViewController ,UITextFieldDelegate{
}catch{
print("error")
}
let res = IrohaSwift.register(keyPair:keypair,accessPoint: self.accessField.text!, name: self.userNameField.text!)
IrohaSwift.setDatas(accessPoint: self.accessField.text!, publicKey: keypair.publicKey)
let res = IrohaSwift.register(name: self.userNameField.text!)
if res["status"] as! Int == 200 {
do{
try KeychainManager.sharedManager.keychain.set(res["uuid"] as! String, key: "uuid")
}catch{
print("error")
}
IrohaSwift.setDatas(uuid: res["uuid"] as! String)
self.alertController.dismiss(animated: false, completion: {() -> Void in
let nextvc = self.storyboard?.instantiateViewController(withIdentifier: "Tabbar")
self.present(nextvc!, animated: true, completion: nil)
})
} else {
self.alertController.dismiss(animated: false, completion: {() -> Void in

do {
try KeychainManager.sharedManager.keychain.remove("privateKey")
try KeychainManager.sharedManager.keychain.remove("publicKey")
} catch let error {
print("error: \(error)")
}
self.alertController = UIAlertController(title: String(describing: res["status"]!) , message: res["message"] as! String?, preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
self.alertController.addAction(defaultAction)
Expand Down
8 changes: 2 additions & 6 deletions Example/Example/TransactionHistoryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class TransactionHistoryViewController: UIViewController, UITableViewDelegate, U
historyAlert.view.addSubview(spinnerIndicator)
self.present(historyAlert, animated: false, completion: {
let keychain = KeychainManager.sharedManager.keychain
let ap = keychain["accessPoint"]
let uuid = keychain["uuid"]
let res = IrohaSwift.getTransaction(accessPoint: ap!, uuid: uuid!)
let res = IrohaSwift.getTransaction()
if res["status"] as! Int == 200 {
self.historyAlert.dismiss(animated: false, completion: {() -> Void in
TransactionHistoryDataManager.sharedManager.transactionHistoryDataArray.removeAll()
Expand Down Expand Up @@ -98,9 +96,7 @@ class TransactionHistoryViewController: UIViewController, UITableViewDelegate, U
func refreshHistory() {

let keychain = KeychainManager.sharedManager.keychain
let ap = keychain["accessPoint"]
let uuid = keychain["uuid"]
let res = IrohaSwift.getTransaction(accessPoint: ap!, uuid: uuid!)
let res = IrohaSwift.getTransaction()
if (res["status"] as! Int) == 200{
transactionHistories = res["history"] as! [NSDictionary]
TransactionHistoryDataManager.sharedManager.transactionHistoryDataArray.removeAll()
Expand Down
5 changes: 2 additions & 3 deletions Example/Example/TransferViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ class TransferViewController : UIViewController, UICollectionViewDelegate, UICol
case 11:
if(valueField.text != "" && toAccountField.text != ""){
let keychain = KeychainManager.sharedManager.keychain
let keypair = (publicKey: keychain["publicKey"]!, privateKey:keychain["privateKey"]!)
let ap = keychain["accessPoint"]
IrohaSwift.assetOperation(accessPoint: ap!, command: "Transfer", assetUuid: assetUuid, amount: valueField.text!, keyPair: keypair , reciever: toAccountField.text!)
let key = keychain["privateKey"]!
IrohaSwift.assetOperation( command: "Transfer", assetUuid: assetUuid, amount: valueField.text!, privateKey: key , reciever: toAccountField.text!)
}
break
default:
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ target 'Example' do
# Pods for Example
pod 'KeychainAccess', '3.0.0'
pod 'SwiftyJSON', '3.0.0'
pod 'IrohaSwift', :git => 'https://github.com/soramitsu/iroha-ios.git', :submodules => true
# pod 'IrohaSwift', :git => 'https://github.com/soramitsu/iroha-ios.git', :submodules => true, :branch => 'feature/singleton'
target 'ExampleTests' do
inherit! :search_paths
# Pods for testing
Expand Down
2 changes: 1 addition & 1 deletion IrohaSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "IrohaSwift"
s.version = "1.0.0a3"
s.version = "1.0.0a4"
s.summary = "Easy create signature of Iroha Blockchain"
s.homepage = "http://www.soramitsu.co.jp/"
s.license = "Apache License Version 2.0"
Expand Down
4 changes: 4 additions & 0 deletions IrohaSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
7471C8741D8D942300C151E8 /* IrohaSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7471C8731D8D942300C151E8 /* IrohaSwiftTests.swift */; };
7471C8A71D8D9AC200C151E8 /* IrohaSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7471C8A61D8D9AC200C151E8 /* IrohaSwift.swift */; };
747237A01D8ECB5600D22133 /* HttpRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7472379F1D8ECB5600D22133 /* HttpRequest.swift */; };
747816E51D9FA5AD00394583 /* IrohaDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 747816E41D9FA5AD00394583 /* IrohaDataManager.swift */; };
7494E09D1D8F961300F311DA /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7494E09C1D8F961300F311DA /* Security.framework */; };
74A8F08E1D9819DF008CCF51 /* add_scalar.c in Sources */ = {isa = PBXBuildFile; fileRef = 74A8F07A1D9819DF008CCF51 /* add_scalar.c */; };
74A8F08F1D9819DF008CCF51 /* base64.c in Sources */ = {isa = PBXBuildFile; fileRef = 74A8F07B1D9819DF008CCF51 /* base64.c */; };
Expand Down Expand Up @@ -58,6 +59,7 @@
7471C8751D8D942300C151E8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7471C8A61D8D9AC200C151E8 /* IrohaSwift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IrohaSwift.swift; sourceTree = "<group>"; };
7472379F1D8ECB5600D22133 /* HttpRequest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HttpRequest.swift; sourceTree = "<group>"; };
747816E41D9FA5AD00394583 /* IrohaDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = IrohaDataManager.swift; path = IrohaSwift/IrohaDataManager.swift; sourceTree = SOURCE_ROOT; };
7494E09C1D8F961300F311DA /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
74A8F07A1D9819DF008CCF51 /* add_scalar.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = add_scalar.c; sourceTree = "<group>"; };
74A8F07B1D9819DF008CCF51 /* base64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = base64.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -129,6 +131,7 @@
7471C8A61D8D9AC200C151E8 /* IrohaSwift.swift */,
7472379F1D8ECB5600D22133 /* HttpRequest.swift */,
7413F4211D8FD6D500F4929A /* Ed25519.swift */,
747816E41D9FA5AD00394583 /* IrohaDataManager.swift */,
7458D11D1D903E89003C3D1D /* ColorExtension.swift */,
742989FF1D9AC5330074F91D /* Sha3.swift */,
);
Expand Down Expand Up @@ -309,6 +312,7 @@
74A8F08E1D9819DF008CCF51 /* add_scalar.c in Sources */,
74A8F0A01D9819DF008CCF51 /* verify.c in Sources */,
74A8F08F1D9819DF008CCF51 /* base64.c in Sources */,
747816E51D9FA5AD00394583 /* IrohaDataManager.swift in Sources */,
74A8F09A1D9819DF008CCF51 /* sc.c in Sources */,
7413F4221D8FD6D500F4929A /* Ed25519.swift in Sources */,
74A8F0971D9819DF008CCF51 /* key_exchange.c in Sources */,
Expand Down
18 changes: 18 additions & 0 deletions IrohaSwift/IrohaDataManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// IrohaDataManager.swift
// IrohaSwift
//
// Created by Kaji Satoshi on 2016/09/30.
// Copyright © 2016年 Kaji Satoshi. All rights reserved.
//

import Foundation

class IrohaDataManager {
static let sharedManager = IrohaDataManager()
var accessPoint = ""
var uuid = ""
var publicKey = ""
private init() {
}
}
Loading

0 comments on commit 8eefc84

Please sign in to comment.