Merge pull request #1566 from AlphaWallet/change-redeem-to-token-ids
Change redeem to token idspull/1567/head
commit
2aaee3f2db
@ -0,0 +1,7 @@ |
||||
// Copyright © 2019 Stormbird PTE. LTD. |
||||
import Foundation |
||||
|
||||
struct GetERC721ForTicketsBalance { |
||||
let abi = "[{\"constant\":true,\"inputs\":[{\"name\":\"_owner\",\"type\":\"address\"}],\"name\":\"getBalances\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256[]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]" |
||||
let name = "getBalances" |
||||
} |
@ -0,0 +1,31 @@ |
||||
// Copyright © 2019 Stormbird PTE. LTD. |
||||
|
||||
import Foundation |
||||
import Result |
||||
import BigInt |
||||
|
||||
class GetERC721ForTicketsBalanceCoordinator { |
||||
private let server: RPCServer |
||||
|
||||
init(forServer server: RPCServer) { |
||||
self.server = server |
||||
} |
||||
|
||||
func getERC721ForTicketsTokenBalance(for address: AlphaWallet.Address, contract: AlphaWallet.Address, completion: @escaping (Result<[String], AnyError>) -> Void) { |
||||
let function = GetERC721ForTicketsBalance() |
||||
callSmartContract(withServer: server, contract: contract, functionName: function.name, abiString: function.abi, parameters: [address.eip55String] as [AnyObject]).done { balanceResult in |
||||
let balances = self.adapt(balanceResult["0"]) |
||||
completion(.success(balances)) |
||||
}.catch { |
||||
completion(.failure(AnyError($0))) |
||||
} |
||||
} |
||||
|
||||
private func adapt(_ values: Any?) -> [String] { |
||||
guard let array = values as? [BigUInt] else { return [] } |
||||
return array.map { each in |
||||
let value = each.serialize().hex() |
||||
return "0x\(value)" |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,23 @@ |
||||
// Copyright © 2019 Stormbird PTE. LTD. |
||||
|
||||
import Foundation |
||||
import Result |
||||
|
||||
class GetIsERC721ForTicketsContractCoordinator { |
||||
private let server: RPCServer |
||||
|
||||
init(forServer server: RPCServer) { |
||||
self.server = server |
||||
} |
||||
|
||||
func getIsERC721ForTicketContract(for contract: AlphaWallet.Address, completion: @escaping (Result<Bool, AnyError>) -> Void) { |
||||
//TODO check ERC165 interface hash |
||||
//TODO update with production ready contract |
||||
let defaultTicketContract = Constants.uefaRopsten |
||||
if contract.sameContract(as: defaultTicketContract) { |
||||
completion(.success(true)) |
||||
} else { |
||||
completion(.success(false)) |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue