remove redandant market queue class

pull/1641/head
James Sangalli 5 years ago
parent 456305a4a1
commit 37f1b0d78b
  1. 8
      AlphaWallet.xcodeproj/project.pbxproj
  2. 103
      AlphaWallet/Market/MarketQueueHandler.swift
  3. 59
      AlphaWalletTests/Market/MarketQueueHandlerTests.swift

@ -650,8 +650,6 @@
AA893ED5203C3E5400CDCED1 /* TokenBalance.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA893ED4203C3E5400CDCED1 /* TokenBalance.swift */; };
AAEF2CAB2050A68A0038BE0D /* SignatureHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAEF2CAA2050A68A0038BE0D /* SignatureHelper.swift */; };
B138ABD0208C2C93000FC28A /* MonkeyTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B138ABCF208C2C93000FC28A /* MonkeyTest.swift */; };
B1DC375D203AEAE200C9756D /* MarketQueueHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DC375C203AEAE100C9756D /* MarketQueueHandler.swift */; };
B1DC375F203AEB4800C9756D /* MarketQueueHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1DC375E203AEB4800C9756D /* MarketQueueHandlerTests.swift */; };
BB5D6A9E20232EE8000FC5AB /* CurrencyRate+Fee.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB5D6A9D20232EE8000FC5AB /* CurrencyRate+Fee.swift */; };
BBF4F9B72029D0B3009E04C0 /* GasViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBF4F9B62029D0B2009E04C0 /* GasViewModel.swift */; };
C80DC77E22AB7FAD009CFA1C /* XDAI-bridge.tsml in Resources */ = {isa = PBXBuildFile; fileRef = C80DC77D22AB7FAD009CFA1C /* XDAI-bridge.tsml */; };
@ -1350,8 +1348,6 @@
B138ABCF208C2C93000FC28A /* MonkeyTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonkeyTest.swift; sourceTree = "<group>"; };
B1CCA9D1215B615A0000FBF7 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; };
B1CCA9D2215B61620000FBF7 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = "<group>"; };
B1DC375C203AEAE100C9756D /* MarketQueueHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketQueueHandler.swift; sourceTree = "<group>"; };
B1DC375E203AEB4800C9756D /* MarketQueueHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketQueueHandlerTests.swift; sourceTree = "<group>"; };
B9F84D10470B22C957A61EAE /* Pods-AlphaWalletTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AlphaWalletTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AlphaWalletTests/Pods-AlphaWalletTests.debug.xcconfig"; sourceTree = "<group>"; };
BB5D6A9D20232EE8000FC5AB /* CurrencyRate+Fee.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CurrencyRate+Fee.swift"; sourceTree = "<group>"; };
BBF4F9B62029D0B2009E04C0 /* GasViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GasViewModel.swift; sourceTree = "<group>"; };
@ -3171,7 +3167,6 @@
isa = PBXGroup;
children = (
76F1DADFD07E2941897FD2E1 /* OrderHandler.swift */,
B1DC375C203AEAE100C9756D /* MarketQueueHandler.swift */,
76F1DCD54618349AC91C6DF8 /* UniversalLinkHandler.swift */,
5E7C71D254F51DCFBA549722 /* Coordinators */,
5E7C714506B5E3AED3C410FC /* ViewControllers */,
@ -3196,7 +3191,6 @@
isa = PBXGroup;
children = (
76F1DE8ADA3176D0277EDF20 /* OrderSigningTests.swift */,
B1DC375E203AEB4800C9756D /* MarketQueueHandlerTests.swift */,
76F1D96298E216CBFC3DD78B /* UniversalLinkHandlerTests.swift */,
5E7C77C33FD8D5653F051136 /* ViewControllers */,
);
@ -3964,7 +3958,6 @@
29A13E331F6B1B7A00E432A2 /* AppStyle.swift in Sources */,
737EEDDA201BE3A8009D9D5D /* Lock.swift in Sources */,
29FF12F81F747D6C00AFD326 /* Error.swift in Sources */,
B1DC375D203AEAE200C9756D /* MarketQueueHandler.swift in Sources */,
29AD8A061F93DC8C008E10E7 /* PushDevice.swift in Sources */,
294DFBA91FE6EBFB004CEB56 /* NewTokenViewController.swift in Sources */,
29B933F51F860074009FCABB /* SendTransactionCoordinator.swift in Sources */,
@ -4409,7 +4402,6 @@
files = (
29F1C85620036887003780D8 /* AppTrackerTests.swift in Sources */,
290B2B6C1F92C35B0053C83E /* RPCServerTests.swift in Sources */,
B1DC375F203AEB4800C9756D /* MarketQueueHandlerTests.swift in Sources */,
29FF13031F75EB7500AFD326 /* Account.swift in Sources */,
290B2B6A1F92C0440053C83E /* ConfigTests.swift in Sources */,
29BDF1941FEE43AA0023A45F /* TransactionConfiguratorTests.swift in Sources */,

@ -1,103 +0,0 @@
//
// Created by James Sangalli on 15/2/18.
// Copyright © 2018 Stormbird PTE. LTD.
// Sends the sales orders to and from the market queue server
//
import Foundation
import Alamofire
import SwiftyJSON
import BigInt
//"orders": [
// {
// "message": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACOG8m/BAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWojJJwB77oK92ehmsr0RR4CkfyJhxoTjAAIAAwAE)",
// "expiry": "1518913831",
// "start": "32800312",
// "count": "3",
// "price": "10000000000000000",
// "signature": "jrzcgpsnV7IPGE3nZQeHQk5vyZdy5c8rHk0R/iG7wpiK9NT730I//DN5Dg5fHs+s4ZFgOGQnk7cXLQROBs9NvgE="
// }
//]
public class MarketQueueHandler {
private let baseURL = "https://482kdh4npg.execute-api.ap-southeast-1.amazonaws.com/dev/"
private let contractAddress = "bC9a1026A4BC6F0BA8Bbe486d1D09dA5732B39e4".lowercased()
public func getOrders(callback: @escaping (_ result: Any) -> Void) {
Alamofire.request(baseURL + "contract/" + contractAddress, method: .get).responseJSON { [weak self] response in
guard let strongSelf = self else { return }
var orders = [SignedOrder]()
if response.result.value != nil {
let parsedJSON = try! JSON(data: response.data!)
for i in 0...parsedJSON.count - 1 {
let orderObj: JSON = parsedJSON["orders"][i]
if orderObj == .null {
//String not used in UI
callback("no orders")
return
}
guard let order = strongSelf.parseOrder(orderObj) else { continue }
orders.append(order)
}
callback(orders)
}
}
}
func parseOrder(_ orderObj: JSON) -> SignedOrder? {
let orderString = orderObj["message"].string!
let message = Data(base64Encoded: orderString)!.hex()
let price = message.substring(to: 64)
let expiry = message.substring(with: Range(uncheckedBounds: (64, 128)))
let _ = "0x" + message.substring(with: Range(uncheckedBounds: (128, 168)))
guard let contractAddress = AlphaWallet.Address(uncheckedAgainstNullAddress: contractAddress) else { return nil }
let indices = message.substring(from: 168)
let order = Order(
price: BigUInt(price, radix: 16)!,
indices: indices.hexa2Bytes.map({ UInt16($0) }),
expiry: BigUInt(expiry, radix: 16)!,
contractAddress: contractAddress,
count: BigUInt(orderObj["count"].intValue),
nonce: BigUInt(0),
tokenIds: [BigUInt](),
spawnable: false,
nativeCurrencyDrop: false
)
let signedOrder = SignedOrder(
order: order,
message: message.hexa2Bytes,
signature: "0x" + Data(base64Encoded: orderObj["signature"].string!)!.hex()
)
return signedOrder
}
//only have to give first order to server then pad the signatures
public func putOrderToServer(signedOrders: [SignedOrder],
publicKey: String,
callback: @escaping (_ result: Any) -> Void) {
//TODO get encoding for count and start
let query: String = baseURL + "public-key/" + publicKey + "?start=0" +
";count=" + signedOrders.count.description
var messageBytes = signedOrders[0].message
print(signedOrders[0].signature.count)
for i in 0...signedOrders.count - 1 {
for j in 0...64 {
messageBytes.append(signedOrders[i].signature.hexa2Bytes[j])
}
}
let headers: HTTPHeaders = ["Content-Type": "application/vnd.awallet-signed-orders-v0"]
print(query)
Alamofire.upload(Data(bytes: messageBytes), to: query, method: .put, headers: headers).response { response in
if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
print("Data: \(utf8Text)") // original server data as UTF8 string
callback(data)
}
}
}
}

@ -1,59 +0,0 @@
import Foundation
import XCTest
@testable import AlphaWallet
import BigInt
class MarketQueueHandlerTests: XCTestCase {
var expectations = [XCTestExpectation]()
let keyStore = FakeEtherKeystore()
//TODO reuse when market queue is used/working
// func testGetOrders() {
// let expectation = self.expectation(description: "wait til callback")
// expectations.append(expectation)
// let marketQueueHandler = MarketQueueHandler()
// marketQueueHandler.getOrders(callback: { callback in
// print(callback)
// expectation.fulfill()
// })
// wait(for: expectations, timeout: 10)
// }
//TODO reuse when market queue is working
func testPuttingOrderToQueue() {
// let expectation = self.expectation(description: "wait til callback")
// expectations.append(expectation)
// var testOrdersList : Array<Order> = Array<Order>()
// let account = keyStore.createAccount(password: "test")
// //set up test orders
// var indices = [UInt16]()
// indices.append(1)
// indices.append(2)
//
// var timestamp = NSDate().timeIntervalSince1970.description //1521562138
// timestamp = timestamp.substring(to: timestamp.count - 6);
// let ts = Int(timestamp)! + 300;
// let testOrder1 = Order(
// price: BigUInt("100000")!,
// indices: indices,
// expiry: BigUInt(String(ts))!,
// contractAddress: "bC9a1026A4BC6F0BA8Bbe486d1D09dA5732B39e4".lowercased(),
// start: BigUInt("500000210121213")!,
// count: 3
// )
// testOrdersList.append(testOrder1)
// let signedOrders = try! SignOrders().signOrders(orders: testOrdersList, account: account)
// let privateKey = keyStore.exportPrivateKey(account: account)
// let publicKey = try! Secp256k1.shared.pubKeyFromPrivateKey(from: privateKey.dematerialize())
//
// OrdersRequest.init().putOrderToServer(signedOrders: signedOrders, publicKey: publicKey.hexString, callback: {
// callback in
// print(callback)
// expectation.fulfill()
// })
//
// wait(for: expectations, timeout: 10)
}
}
Loading…
Cancel
Save