check isERC721 by checking erc165 ref

pull/540/head
James Sangalli 6 years ago
parent b1c9be0763
commit 485bf72adb
  1. 3
      AlphaWallet/Settings/Types/Constants.swift
  2. 29
      AlphaWallet/Tokens/Coordinators/GetIsERC721ContractCoordinator.swift
  3. 8
      AlphaWallet/Vendors/New Group/Commands/GetIsERC721Encode.swift

@ -48,6 +48,9 @@ public struct Constants {
public static let mainnetEtherscanContractDetailsWebPageURL = "https://etherscan.io/address/"
public static let ropstenEtherscanContractDetailsWebPageURL = "https://ropsten.etherscan.io/address/"
public static let rinkebyEtherscanContractDetailsWebPageURL = "https://rinkeby.etherscan.io/address/"
//ERC specs
public static let erc721InterfaceHash = "0x80ac58cd"
}
public struct UnitConfiguration {

@ -25,8 +25,33 @@ class GetIsERC721ContractCoordinator {
let request = GetIsERC721Encode()
web3.request(request: request) { result in
switch result {
case .success:
completion(.success(true))
case .success(let res):
let request2 = EtherServiceRequest(
batch: BatchFactory().create(CallRequest(to: contract.description, data: res))
)
Session.send(request2) { [weak self] result2 in
switch result2 {
case .success(let is721):
let request = GetIsERC721Decode(data: is721)
self?.web3.request(request: request) { result in
switch result {
case .success(let isERC721):
if isERC721 == "true" {
completion(.success(true))
}
else {
completion(.success(false))
}
case .failure(let error):
NSLog("getIsERC721Contract 3 error \(error)")
completion(.failure(AnyError(error)))
}
}
case .failure(let error):
NSLog("getIsERC721Contract 2 error \(error)")
completion(.failure(AnyError(error)))
}
}
case .failure(let error):
NSLog("getIsERC721 error \(error)")
completion(.failure(AnyError(error)))

@ -9,11 +9,9 @@ struct GetIsERC721Encode: Web3Request {
typealias Response = String
//Note: if this returns without error than it is ERC721 as non ERC721 contracts will not have this function
static let abi = "{ \"constant\": true, \"inputs\": [ { \"name\": \"_tokenId\", \"type\": \"uint256\" } ], \"name\": \"ownerOf\", \"outputs\": [ { \"name\": \"owner\", \"type\": \"address\" } ], \"payable\": false, \"stateMutability\": \"view\", \"type\": \"function\" }"
static let abi = "[ { \"constant\": true, \"inputs\": [ { \"name\": \"interfaceID\", \"type\": \"bytes4\" } ], \"name\": \"supportsInterface\", \"outputs\": [ { \"name\": \"\", \"type\": \"bool\" } ], \"payable\": false, \"stateMutability\": \"view\", \"type\": \"function\" } ]"
var type: Web3RequestType {
let run = "web3.eth.abi.encodeFunctionCall(\(GetIsERC721Encode.abi), [\(Constants.nullTicket)])"
let run = "web3.eth.abi.encodeFunctionCall(\(GetIsERC721Encode.abi), [\(Constants.erc721InterfaceHash)])"
return .script(command: run)
}
}
@ -24,7 +22,7 @@ struct GetIsERC721Decode: Web3Request {
let data: String
var type: Web3RequestType {
let run = "web3.eth.abi.decodeParameter('address', '\(data)')"
let run = "web3.eth.abi.decodeParameter('bool', '\(data)')"
return .script(command: run)
}
}

Loading…
Cancel
Save