Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ios eth #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions ETH/iOS/Pocket-Chat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
3E3AB2212268F611004C4AD8 /* ImportWalletViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E3AB2202268F611004C4AD8 /* ImportWalletViewController.swift */; };
3E3AB2232268F797004C4AD8 /* MessageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E3AB2222268F797004C4AD8 /* MessageViewController.swift */; };
3E3AB2252268F815004C4AD8 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E3AB2242268F815004C4AD8 /* Message.swift */; };
3EDA52772284734A007BF6A0 /* DeveloperConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EDA52762284734A007BF6A0 /* DeveloperConfig.swift */; };
757D9DABA056C8A032718354 /* Pods_Pocket_Chat.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B09F4C1555DEB2E74A6E140 /* Pods_Pocket_Chat.framework */; };
C5508D152270BA690054A966 /* ViewController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5508D142270BA690054A966 /* ViewController+Extension.swift */; };
C5508D182270DCFE0054A966 /* AppConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = C5508D172270DCFE0054A966 /* AppConfig.swift */; };
Expand Down Expand Up @@ -55,6 +56,7 @@
3E3AB2202268F611004C4AD8 /* ImportWalletViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportWalletViewController.swift; sourceTree = "<group>"; };
3E3AB2222268F797004C4AD8 /* MessageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageViewController.swift; sourceTree = "<group>"; };
3E3AB2242268F815004C4AD8 /* Message.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
3EDA52762284734A007BF6A0 /* DeveloperConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperConfig.swift; sourceTree = "<group>"; };
51C232BCA50FEF59F30BFDED /* Pods-Pocket-Chat.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Pocket-Chat.release.xcconfig"; path = "Pods/Target Support Files/Pods-Pocket-Chat/Pods-Pocket-Chat.release.xcconfig"; sourceTree = "<group>"; };
B0A932BB4885EA9201F44529 /* Pods-Pocket-Chat.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Pocket-Chat.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Pocket-Chat/Pods-Pocket-Chat.debug.xcconfig"; sourceTree = "<group>"; };
C5508D142270BA690054A966 /* ViewController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ViewController+Extension.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -150,6 +152,7 @@
isa = PBXGroup;
children = (
C5508D172270DCFE0054A966 /* AppConfig.swift */,
3EDA52762284734A007BF6A0 /* DeveloperConfig.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand All @@ -158,9 +161,9 @@
isa = PBXGroup;
children = (
3E3AB1FD2268EE94004C4AD8 /* WelcomeViewController.swift */,
3E3AB2222268F797004C4AD8 /* MessageViewController.swift */,
3E3AB2202268F611004C4AD8 /* ImportWalletViewController.swift */,
3E3AB21E2268F4A3004C4AD8 /* CreateWalletViewController.swift */,
3E3AB2222268F797004C4AD8 /* MessageViewController.swift */,
);
path = "View Controllers";
sourceTree = "<group>";
Expand Down Expand Up @@ -253,6 +256,7 @@
TargetAttributes = {
3E3AB1F72268EE94004C4AD8 = {
CreatedOnToolsVersion = 10.2;
LastSwiftMigration = 1020;
};
3E3AB20E2268EE96004C4AD8 = {
CreatedOnToolsVersion = 10.2;
Expand Down Expand Up @@ -370,6 +374,7 @@
files = (
3E3AB1FE2268EE94004C4AD8 /* WelcomeViewController.swift in Sources */,
C5508D182270DCFE0054A966 /* AppConfig.swift in Sources */,
3EDA52772284734A007BF6A0 /* DeveloperConfig.swift in Sources */,
3E3AB2212268F611004C4AD8 /* ImportWalletViewController.swift in Sources */,
3E3AB21F2268F4A3004C4AD8 /* CreateWalletViewController.swift in Sources */,
3E3AB1FC2268EE94004C4AD8 /* AppDelegate.swift in Sources */,
Expand Down Expand Up @@ -549,7 +554,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "Pkt-Sample.Pocket-Chat";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -568,7 +573,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "Pkt-Sample.Pocket-Chat";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>Pocket-Chat.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>21</integer>
</dict>
</dict>
</dict>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array/>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Pocket-ChatTests/Pocket_ChatTests.swift"
timestampString = "579734091.420791"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "41"
endingLineNumber = "41"
landmarkName = "testExample()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Pocket-Chat/View Controllers/MessageViewController.swift"
timestampString = "579734091.421284"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "87"
endingLineNumber = "87"
landmarkName = "refreshScreen(_:)"
landmarkType = "7">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Pocket_Chat.MessageViewController.refreshScreen(Swift.Optional&lt;__C.UIButton&gt;) -&gt; ()"
moduleName = "Pocket-Chat"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/jeremybeal/Desktop/iOS-Eth/Pocket-Chat/View%20Controllers/MessageViewController.swift"
timestampString = "579732160.929458"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "87"
endingLineNumber = "87"
offsetFromSymbolStart = "1005">
</Location>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "closure #1 (Swift.Optional&lt;PocketSwift.PocketError&gt;, Swift.Optional&lt;Swift.Array&lt;Any&gt;&gt;) -&gt; () in Pocket_Chat.MessageViewController.refreshScreen(Swift.Optional&lt;__C.UIButton&gt;) -&gt; ()"
moduleName = "Pocket-Chat"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/jeremybeal/Desktop/iOS-Eth/Pocket-Chat/View%20Controllers/MessageViewController.swift"
timestampString = "579732160.933035"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "89"
endingLineNumber = "89"
offsetFromSymbolStart = "324">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Pocket-Chat/View Controllers/MessageViewController.swift"
timestampString = "579734091.421357"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "107"
endingLineNumber = "107"
landmarkName = "refreshScreen(_:)"
landmarkType = "7">
<Locations>
<Location
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "closure #1 (Swift.Optional&lt;PocketSwift.PocketError&gt;, Swift.Optional&lt;Swift.Array&lt;Any&gt;&gt;) -&gt; () in Pocket_Chat.MessageViewController.refreshScreen(Swift.Optional&lt;__C.UIButton&gt;) -&gt; ()"
moduleName = "Pocket-Chat"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/jeremybeal/Desktop/iOS-Eth/Pocket-Chat/View%20Controllers/MessageViewController.swift"
timestampString = "579231006.0993789"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "109"
endingLineNumber = "109"
offsetFromSymbolStart = "2478">
</Location>
<Location
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "closure #1 (Swift.Optional&lt;PocketSwift.PocketError&gt;, Swift.Optional&lt;Swift.Array&lt;Any&gt;&gt;) -&gt; () in closure #1 (Swift.Optional&lt;PocketSwift.PocketError&gt;, Swift.Optional&lt;Swift.Array&lt;Any&gt;&gt;) -&gt; () in Pocket_Chat.MessageViewController.refreshScreen(Swift.Optional&lt;__C.UIButton&gt;) -&gt; ()"
moduleName = "Pocket-Chat"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/jeremybeal/Desktop/iOS-Eth/Pocket-Chat/View%20Controllers/MessageViewController.swift"
timestampString = "579231006.1033241"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "111"
endingLineNumber = "111"
offsetFromSymbolStart = "227">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Pocket-Chat/View Controllers/MessageViewController.swift"
timestampString = "579734091.421423"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "94"
endingLineNumber = "94"
landmarkName = "refreshScreen(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
5 changes: 3 additions & 2 deletions ETH/iOS/Pocket-Chat/Utils/AppConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation

public class AppConfig: NSObject {
public static let smartContractAddress = "0xA0dC0a5E880F2ea7fb74eA9fB5319fe9ee98968F0B06bCAC535e7EF0152e8aC9"
public static let abiDefinition = "[{\"outputs\":[{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"string\"}],\"constant\":true,\"payable\":false,\"inputs\":[{\"name\":\"_index\",\"type\":\"uint128\"}],\"name\":\"getMessageByIndex\",\"type\":\"function\"},{\"outputs\":[{\"name\":\"\",\"type\":\"uint128\"}],\"constant\":true,\"payable\":false,\"inputs\":[],\"name\":\"getTotalMessageCount\",\"type\":\"function\"},{\"outputs\":[],\"constant\":false,\"payable\":false,\"inputs\":[{\"name\":\"_sender\",\"type\":\"address\"},{\"name\":\"_content\",\"type\":\"string\"}],\"name\":\"sendMessage\",\"type\":\"function\"}]"

public static let smartContractAddress = "0x0b4515fa7e8287f2da3e8776a239a5d6a493b878"
public static let abiDefinition = "[{\"constant\":true,\"inputs\":[{\"name\":\"_index\",\"type\":\"uint256\"}],\"name\":\"getMessageByIndex\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getTotalMessageCount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_sender\",\"type\":\"address\"},{\"name\":\"_content\",\"type\":\"string\"}],\"name\":\"sendMessage\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
}
15 changes: 15 additions & 0 deletions ETH/iOS/Pocket-Chat/Utils/DeveloperConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// DeveloperConfig.swift
// Pocket-Chat
//
// Created by jeremy beal on 5/9/19.
// Copyright © 2019 Pocket_Sample. All rights reserved.
//

import Foundation

public class DeveloperConfig:NSObject{

public static let devID = "DEV1"

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,45 @@ import PocketSwift


class CreateWalletViewController: UIViewController {
var pocketAion: PocketAion?
var wallet: Wallet?

// declate wallet and PocketAion
var wallet:Wallet?
var pocketEth:PocketEth?



@IBOutlet weak var publicKeyLabel: UILabel!
@IBOutlet weak var privateKetyTextView: UITextView!

override func viewDidLoad() {
super.viewDidLoad()
do {
// Instantiate PocketAion
pocketAion = try PocketAion.init(devID: "", netIds: ["32","256"], defaultNetID: "32", maxNodes: 5, requestTimeOut: 20000)
} catch {

do{
pocketEth = try PocketEth.init(devID: DeveloperConfig.devID, netIds: [PocketEth.Networks.Rinkeby.netID,PocketEth.Networks.Mainnet.netID])


} catch{
print(error)
}


}

@IBAction func createWallet(_ sender: Any) {

//ensure the labels are empty
if publicKeyLabel.text?.isEmpty ?? true || privateKetyTextView.text?.isEmpty ?? true {

//generate the public and private keys
do {
// Create Wallet
self.wallet = try pocketAion?.mastery?.createWallet()
// TODO: call Create Wallet class
wallet = try pocketEth?.rinkeby?.createWallet()

//TODO: display wallet address and private key
self.publicKeyLabel.text = wallet?.address

self.privateKetyTextView.text = wallet?.privateKey

} catch {
let alertController = UIAlertController(title: "Error", message: "Failed to create a wallet, please try again later.", preferredStyle: .alert)
self.present(alertController, animated: true, completion: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,30 @@ import Foundation
import UIKit
import PocketSwift


class ImportWalletViewController: UIViewController {
var wallet: Wallet?
var pocketAion: PocketAion?

// declare Wallet and PocketEth
var wallet:Wallet?
var pocketEth:PocketEth?

@IBOutlet weak var privateKeyTextView: UITextView!

override func viewDidLoad() {
super.viewDidLoad()
}

// Store the imported wallet and request passphrase
func saveWallet() {
let alertController = self.requestPassphrase { (passphrase, error) in
if passphrase != nil {
do {
// encrypt message
let isSaved = try self.wallet?.save(passphrase: passphrase!)
if isSaved ?? false {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "messageViewControllerID") as? MessageViewController
vc?.pocketAion = self.pocketAion
vc?.pocketEth = self.pocketEth
vc?.wallet = self.wallet
self.present(vc!, animated: true, completion: nil)
}
Expand All @@ -48,9 +53,15 @@ class ImportWalletViewController: UIViewController {
}

@IBAction func importButton(_ sender: Any) {


if !privateKeyTextView.text.isEmpty {
do {
self.wallet = try pocketAion?.mastery?.importWallet(privateKey: privateKeyTextView.text)

// Store the private key text from the VC
self.wallet = try pocketEth?.rinkeby?.importWallet(privateKey: privateKeyTextView.text)


if self.wallet != nil {
let saveAlertController = UIAlertController(title: "Account", message: "Wallet import was a sucess, do you want to SAVE the account?", preferredStyle: .alert)

Expand All @@ -60,14 +71,16 @@ class ImportWalletViewController: UIViewController {
let saveAction2 = UIAlertAction(title: "No", style: .destructive) { (UIAlertAction) in
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "messageViewControllerID") as? MessageViewController
vc?.pocketAion = self.pocketAion
vc?.pocketEth = self.pocketEth
vc?.wallet = self.wallet
self.present(vc!, animated: true, completion: nil)
}
saveAlertController.addAction(saveAction1)
saveAlertController.addAction(saveAction2)

self.present(saveAlertController, animated: false, completion: nil)


}else {
let alertController = UIAlertController(title: "Error", message: "Failed to import wallet, please verify the private key", preferredStyle: .alert)
let action = UIAlertAction(title: "Ok", style: .default, handler: nil)
Expand Down
Loading