add function call to check if erc721

pull/520/head
James Sangalli 6 years ago
parent 0fbe793089
commit 90d9335cdb
  1. 8
      AlphaWallet.xcodeproj/project.pbxproj
  2. 58
      AlphaWallet/Tokens/Coordinators/GetIsERC721Contract.swift
  3. 29
      AlphaWallet/Vendors/New Group/Commands/GetIsERC721.swift
  4. 2
      AlphaWallet/Vendors/New Group/Commands/GetIsStormBird.swift

@ -442,6 +442,7 @@
76F1D5AF727A83205BBCF0EC /* OrderHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1DADFD07E2941897FD2E1 /* OrderHandler.swift */; };
76F1D74912F5D8CDA72363BD /* GetContractInteractions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1DF5CF4A922E6FFCB7B2A /* GetContractInteractions.swift */; };
76F1D76BF700FCC461B11CC0 /* ClaimStormBirdOrder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1D1417613174D447DEE56 /* ClaimStormBirdOrder.swift */; };
76F1D7F08263A663C3A67926 /* GetIsERC721Contract.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1D4F77311FBF3A442E4B5 /* GetIsERC721Contract.swift */; };
76F1D850F4F2E968CF8D9C86 /* MonkeyTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B138ABCF208C2C93000FC28A /* MonkeyTest.swift */; };
76F1D91659771C9EEA7B48DC /* CreateRedeem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1DF80932454E9F58B7830 /* CreateRedeem.swift */; };
76F1DB9E1443DCFC36228B08 /* ClaimOrderCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1D419EE36261E50ABAFAE /* ClaimOrderCoordinator.swift */; };
@ -449,6 +450,7 @@
76F1DC92CDEB695115DBC47C /* UniversalLinkHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1D96298E216CBFC3DD78B /* UniversalLinkHandlerTests.swift */; };
76F1DD10DF9A6C844E5F57D6 /* CreateRedeemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1D8877226D5DD086B135D /* CreateRedeemTests.swift */; };
76F1DEFF94F9A1F67BDF2735 /* UniversalLinkHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1DCD54618349AC91C6DF8 /* UniversalLinkHandler.swift */; };
76F1DF0A4667F618D2BAE78C /* GetIsERC721.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76F1DC1E229431AA75EF94C3 /* GetIsERC721.swift */; };
771A847520322FD700528D28 /* PreferencesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 771A847420322FD700528D28 /* PreferencesViewModel.swift */; };
771A8485203242B400528D28 /* InCoordinatorViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 771A8484203242B400528D28 /* InCoordinatorViewModelTests.swift */; };
771AA94E1FF971CD00D25403 /* DappAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 771AA94D1FF971CD00D25403 /* DappAction.swift */; };
@ -976,10 +978,12 @@
76F1D1417613174D447DEE56 /* ClaimStormBirdOrder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClaimStormBirdOrder.swift; sourceTree = "<group>"; };
76F1D419EE36261E50ABAFAE /* ClaimOrderCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClaimOrderCoordinator.swift; sourceTree = "<group>"; };
76F1D473FF303828D93C95EB /* GetERC721BalanceCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GetERC721BalanceCoordinator.swift; sourceTree = "<group>"; };
76F1D4F77311FBF3A442E4B5 /* GetIsERC721Contract.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GetIsERC721Contract.swift; sourceTree = "<group>"; };
76F1D8877226D5DD086B135D /* CreateRedeemTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CreateRedeemTests.swift; sourceTree = "<group>"; };
76F1D96298E216CBFC3DD78B /* UniversalLinkHandlerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UniversalLinkHandlerTests.swift; sourceTree = "<group>"; };
76F1DACA9404AD6740BEADBB /* ClaimOrderCoordinatorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClaimOrderCoordinatorTests.swift; sourceTree = "<group>"; };
76F1DADFD07E2941897FD2E1 /* OrderHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderHandler.swift; sourceTree = "<group>"; };
76F1DC1E229431AA75EF94C3 /* GetIsERC721.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GetIsERC721.swift; sourceTree = "<group>"; };
76F1DC947821847220DE2B97 /* GetERC721BalanceEncode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GetERC721BalanceEncode.swift; sourceTree = "<group>"; };
76F1DCD54618349AC91C6DF8 /* UniversalLinkHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UniversalLinkHandler.swift; sourceTree = "<group>"; };
76F1DE8ADA3176D0277EDF20 /* OrderSigningTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OrderSigningTests.swift; sourceTree = "<group>"; };
@ -1305,6 +1309,7 @@
442FC72F9D22CC36AC015274 /* GetERC20Decimals.swift */,
76F1D1417613174D447DEE56 /* ClaimStormBirdOrder.swift */,
76F1DC947821847220DE2B97 /* GetERC721BalanceEncode.swift */,
76F1DC1E229431AA75EF94C3 /* GetIsERC721.swift */,
);
path = Commands;
sourceTree = "<group>";
@ -2146,6 +2151,7 @@
5E7C7F932B48011A24C26733 /* TokensCoordinator.swift */,
76F1DF5CF4A922E6FFCB7B2A /* GetContractInteractions.swift */,
76F1D473FF303828D93C95EB /* GetERC721BalanceCoordinator.swift */,
76F1D4F77311FBF3A442E4B5 /* GetIsERC721Contract.swift */,
);
path = Coordinators;
sourceTree = "<group>";
@ -3669,6 +3675,8 @@
5E7C7180F07239D2132F31A4 /* DirectoryContentsWatcher.swift in Sources */,
76F1DBCA8BAAA42BAEB14719 /* GetERC721BalanceCoordinator.swift in Sources */,
76F1D51EFA6255E0D0381E06 /* GetERC721BalanceEncode.swift in Sources */,
76F1D7F08263A663C3A67926 /* GetIsERC721Contract.swift in Sources */,
76F1DF0A4667F618D2BAE78C /* GetIsERC721.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -0,0 +1,58 @@
//
// Created by James Sangalli on 14/7/18.
//
import Foundation
import BigInt
import JSONRPCKit
import APIKit
import Result
import TrustKeystore
class GetIsERC721Contract {
private let web3: Web3Swift
init(
web3: Web3Swift
) {
self.web3 = web3
}
func getIsERC721Contract(
for contract: Address,
completion: @escaping (Result<Bool, AnyError>) -> Void
) {
let request = GetIsERC721()
web3.request(request: request) { result in
switch result {
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 balance):
let request = GetIsStormBirdDecode(data: balance)
self?.web3.request(request: request) { result in
switch result {
//if a successful return then it must be ERC721, else it is not
case .success(let res):
NSLog("getIsERC721 result \(res) ")
completion(.success(true))
case .failure(let error):
NSLog("getIsStormBirdContract 3 error \(error)")
completion(.failure(AnyError(error)))
}
}
case .failure(let error):
NSLog("getIsStormBirdContract 2 error \(error)")
completion(.failure(AnyError(error)))
}
}
case .failure(let error):
NSLog("getIsStormBirdContract error \(error)")
completion(.failure(AnyError(error)))
}
}
}
}

@ -0,0 +1,29 @@
//
// Created by James Sangalli on 14/7/18.
//
import Foundation
import TrustKeystore
struct GetIsERC721: 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\":\"erc721Metadata\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}"
var type: Web3RequestType {
let run = "web3.eth.abi.encodeFunctionCall(\(GetIsERC721.abi), [])"
return .script(command: run)
}
}
struct GetIsERC721Decode: Web3Request {
typealias Response = String
let data: String
var type: Web3RequestType {
let run = "web3.eth.abi.decodeParameter('address', '\(data)')"
return .script(command: run)
}
}

@ -1,5 +1,3 @@
// Copyright SIX DAY LLC. All rights reserved.
import Foundation
import TrustKeystore

Loading…
Cancel
Save