with cleanup and review

pull/11/head
James Sangalli 7 years ago
parent 8f39b51894
commit 9bf59ae493
  1. 1
      Podfile
  2. 14
      Podfile.lock
  3. 6
      Trust.xcodeproj/project.pbxproj
  4. 15
      Trust/Market/OrdersRequest.swift
  5. 11
      Trust/Market/SignOrders.swift
  6. 4
      TrustTests/Market/OrderRequestTest.swift

@ -27,6 +27,7 @@ target 'Trust' do
pod 'Kingfisher', '~> 4.0'
pod 'TrustKeystore', :git=>'https://github.com/TrustWallet/trust-keystore', :branch=>'master'
pod 'Branch'
pod 'SwiftyJSON'
# pod 'web3swift', :git=>'https://github.com/BANKEX/web3swift', :branch=>'master'
pod 'SAMKeychain'

@ -17,7 +17,6 @@ PODS:
- Result (~> 3.1)
- JSONRPCKit (2.0.0):
- Result (~> 3.0)
- Just (0.6.0)
- KeychainSwift (10.0.0)
- Kingfisher (4.6.1)
- Lokalise (0.8.1)
@ -43,6 +42,7 @@ PODS:
- SipHash (1.2.0)
- StatefulViewController (3.0)
- SwiftLint (0.24.1)
- SwiftyJSON (4.0.0)
- TrezorCrypto (0.0.4)
- TrustKeystore (0.1.3):
- CryptoSwift
@ -60,7 +60,6 @@ DEPENDENCIES:
- Fabric
- JavaScriptKit
- JSONRPCKit (from `https://github.com/bricklife/JSONRPCKit.git`)
- Just (from `https://github.com/JustHTTP/Just.git`, branch `swift-4`)
- KeychainSwift
- Kingfisher (~> 4.0)
- Lokalise
@ -73,6 +72,7 @@ DEPENDENCIES:
- SeedStackViewController
- StatefulViewController
- SwiftLint
- SwiftyJSON
- TrustKeystore (from `https://github.com/TrustWallet/trust-keystore`, branch `master`)
EXTERNAL SOURCES:
@ -81,9 +81,6 @@ EXTERNAL SOURCES:
:git: https://github.com/krzyzanowskim/CryptoSwift
JSONRPCKit:
:git: https://github.com/bricklife/JSONRPCKit.git
Just:
:branch: swift-4
:git: https://github.com/JustHTTP/Just.git
QRCodeReaderViewController:
:branch: master
:git: https://github.com/yannickl/QRCodeReaderViewController.git
@ -98,9 +95,6 @@ CHECKOUT OPTIONS:
JSONRPCKit:
:commit: 50d19a4f7ec593ac5e07cffa1e11c17f1fbe347d
:git: https://github.com/bricklife/JSONRPCKit.git
Just:
:commit: 93fc04992243fb459af37963797ef5ac5224b242
:git: https://github.com/JustHTTP/Just.git
QRCodeReaderViewController:
:commit: 80bd79cbeede842949b229f81bc6328f53701c5a
:git: https://github.com/yannickl/QRCodeReaderViewController.git
@ -120,7 +114,6 @@ SPEC CHECKSUMS:
Fabric: 9cd6a848efcf1b8b07497e0b6a2e7d336353ba15
JavaScriptKit: 9ff565209e6efe21bcb9c6d6ca3e863a67a8ecf7
JSONRPCKit: 22132c575ba2dc6f2f4ae72fda4943a63efca686
Just: 72e8a6e01ec5adba1aa0f7996ff4459aa6a3d710
KeychainSwift: f9f7910449a0c0fd2cabc889121530dd2c477c33
Kingfisher: 1f9157d9c02b380cbd0b7cc890161195164eb634
Lokalise: d81f4ccce8cd2c1589bf73bb39fab7781d4f7cbc
@ -138,9 +131,10 @@ SPEC CHECKSUMS:
SipHash: c6e9e43e9c531b5bc6602545130c26194a6d31ce
StatefulViewController: 4803bf900d44de26074344998e10e041113b5931
SwiftLint: 2e4b89feed5909c42c3735bbd6745f4345c4b772
SwiftyJSON: 070dabdcb1beb81b247c65ffa3a79dbbfb3b48aa
TrezorCrypto: 7f87a2296cf13872b21565c29fd9f7882dd00803
TrustKeystore: 02614fb6b5c48fc65a0c485df7e22a44aec0c0d5
PODFILE CHECKSUM: 2c518afd93340e5087c64d66d63ee842b6a7a825
PODFILE CHECKSUM: a1da5b47a2b9279042ea399b114394f480c2e69b
COCOAPODS: 1.3.1

@ -2506,7 +2506,6 @@
"${BUILT_PRODUCTS_DIR}/Eureka/Eureka.framework",
"${BUILT_PRODUCTS_DIR}/JSONRPCKit/JSONRPCKit.framework",
"${BUILT_PRODUCTS_DIR}/JavaScriptKit/JavaScriptKit.framework",
"${BUILT_PRODUCTS_DIR}/Just/Just.framework",
"${BUILT_PRODUCTS_DIR}/KeychainSwift/KeychainSwift.framework",
"${BUILT_PRODUCTS_DIR}/Kingfisher/Kingfisher.framework",
"${BUILT_PRODUCTS_DIR}/MBProgressHUD/MBProgressHUD.framework",
@ -2520,6 +2519,7 @@
"${BUILT_PRODUCTS_DIR}/SeedStackViewController/StackViewController.framework",
"${BUILT_PRODUCTS_DIR}/SipHash/SipHash.framework",
"${BUILT_PRODUCTS_DIR}/StatefulViewController/StatefulViewController.framework",
"${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework",
"${BUILT_PRODUCTS_DIR}/TrezorCrypto/TrezorCrypto.framework",
"${BUILT_PRODUCTS_DIR}/TrustKeystore/TrustKeystore.framework",
"${BUILT_PRODUCTS_DIR}/secp256k1_ios/secp256k1_ios.framework",
@ -2535,7 +2535,6 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Eureka.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/JSONRPCKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/JavaScriptKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Just.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/KeychainSwift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Kingfisher.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MBProgressHUD.framework",
@ -2549,6 +2548,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/StackViewController.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SipHash.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/StatefulViewController.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TrezorCrypto.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/TrustKeystore.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/secp256k1_ios.framework",
@ -2850,7 +2850,6 @@
291ED08D1F6F5F0A00E7E93A /* KeyStoreError.swift in Sources */,
29F1C83E1FEB5C91003780D8 /* EditTokensViewController.swift in Sources */,
296AF9A31F733AB30058AF78 /* WalletCoordinator.swift in Sources */,
76F1DA1A819D5543FF698AF1,
442FCBBFCC5926B4D416E6D3 /* GetNameCoordinator.swift in Sources */,
442FCB9850FC6F2D28978199 /* GETERC20Symbol.swift in Sources */,
442FC5F70AF003F331F7C841 /* GetSymbolCoordinator.swift in Sources */,
@ -2889,7 +2888,6 @@
299573A21FA1F369006F17FD /* QRURLParserTests.swift in Sources */,
61FC5ED11FCFBDEB00CCB12A /* EtherNumberFormatterTests.swift in Sources */,
29E14FD91F7F4D4E00185568 /* FakeTransactionsStorage.swift in Sources */,
AA893ED6203C3E5400CDCED1,
29BDF1961FEE43F40023A45F /* UnconfirmedTransaction.swift in Sources */,
29E14FD71F7F490000185568 /* Transaction.swift in Sources */,
296106CC1F776FD00006164B /* WalletCoordinatorTests.swift in Sources */,

@ -1,9 +1,9 @@
//
// Created by James Sangalli on 15/2/18.
//
import Foundation
import Alamofire
import SwiftyJSON
//"orders": [
// {
@ -29,8 +29,8 @@ public class OrdersRequest {
}
//only have to give first order to server then pad the signatures
public func giveOrderToServer(signedOrders : [SignedOrder], publicKey: String,
callback: @escaping (_ result: Any) -> Void)
public func putOrderToServer(signedOrders : [SignedOrder], publicKey: String,
callback: @escaping (_ result: Any) -> Void)
{
let query : String = baseURL + "public-key/" + publicKey + "?start=" +
signedOrders[0].order.start.description + ";count="
@ -39,7 +39,7 @@ public class OrdersRequest {
for i in 0...signedOrders.count - 1 {
for j in 0...64 {
data.append(signedOrders[i].signature.hexa2Bytes[i])
data.append(signedOrders[i].signature.hexa2Bytes[j])
}
}
@ -58,11 +58,12 @@ public class OrdersRequest {
response in
print("Request: \(String(describing: response.request))") // original url request
print("Response: \(String(describing: response.response))") // http url response
print("Result: \(response.result)") // response serialization result
print("Result: \(response.result)") // response serialization result
if let json = response.result.value {
print("JSON: \(json)") // serialized json response
callback(json)
//print("JSON: \(json)") // serialized json response
let parsedJSON = JSON(parseJSON: json as! String)
callback(parsedJSON["orders"]["accepted"])
}
if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {

@ -61,6 +61,8 @@ public class SignOrders {
return signedOrders
}
//Start is the solidity array index here
//but is not in the put request, put request is ticket id and is a BigInt
func encodeMessageForTrade(price: BigInt, expiryBuffer: BigInt, start: UInt16,
count: Int, contractAddress: String) -> [UInt8] {
//ticket count * 2 because it is 16 bits not 8
@ -68,18 +70,19 @@ public class SignOrders {
var buffer = [UInt8]()
buffer.reserveCapacity(arrayLength)
var priceInWei: [UInt8] = toByteArray(price)
var expiry: [UInt8] = toByteArray(expiryBuffer)
var priceInWei: [UInt8] = toByteArray(price.description)
var expiry: [UInt8] = toByteArray(expiryBuffer.description)
for _ in 0...31 - price.bitWidth / 8 {
for _ in 0...31 - priceInWei.count {
//pad with zeros
priceInWei.insert(0, at: 0)
}
for i in 0...31 {
buffer.append(priceInWei[i])
}
for _ in 0...31 - expiryBuffer.bitWidth / 8 {
for _ in 0...31 - expiry.count {
expiry.insert(0, at: 0)
}

@ -20,7 +20,7 @@ class OrderRequestTest : XCTestCase {
wait(for: expectations, timeout: 10)
}
func testPostingOrderToQueue() {
func testPuttingOrderToQueue() {
let expectation = self.expectation(description: "wait til callback")
expectations.append(expectation)
@ -54,7 +54,7 @@ class OrderRequestTest : XCTestCase {
let publicKey = try! Secp256k1.shared.pubKeyFromPrivateKey(from:
privateKey.dematerialize()).hexString
OrdersRequest.init().giveOrderToServer(signedOrders: signedOrders, publicKey: publicKey, callback: {
OrdersRequest.init().putOrderToServer(signedOrders: signedOrders, publicKey: publicKey, callback: {
callback in
print(callback)
expectation.fulfill()

Loading…
Cancel
Save