Skip to content

Commit d3fe1c4

Browse files
added 165 protocol and support for it in 721
1 parent 8c58d11 commit d3fe1c4

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

web3swift.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210
E228BED021A4C89F0085268C /* Web3Legacy+Eth.swift in Sources */ = {isa = PBXBuildFile; fileRef = E228BEC921A4C89E0085268C /* Web3Legacy+Eth.swift */; };
211211
E228BED121A4C89F0085268C /* Web3Legacy+Instance.swift in Sources */ = {isa = PBXBuildFile; fileRef = E228BECA21A4C89F0085268C /* Web3Legacy+Instance.swift */; };
212212
E228BED221A4C89F0085268C /* Web3Legacy+Instance.swift in Sources */ = {isa = PBXBuildFile; fileRef = E228BECA21A4C89F0085268C /* Web3Legacy+Instance.swift */; };
213+
E279C9EF21C46A140081695F /* Web3+ERC165.swift in Sources */ = {isa = PBXBuildFile; fileRef = E279C9EE21C46A140081695F /* Web3+ERC165.swift */; };
213214
E2DCA653218C875100F94FBA /* web3swift_ENS_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A7B2782143C978004CD2C7 /* web3swift_ENS_Tests.swift */; };
214215
E2DCA654218C879900F94FBA /* ENS.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2E668CD214F8A7B00C3CC2D /* ENS.swift */; };
215216
E2DCA655218C879900F94FBA /* ENSResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B219DC162154F3EE0035BF94 /* ENSResolver.swift */; };
@@ -390,6 +391,7 @@
390391
E23B5ADC20EA685D00DC7F32 /* web3swift_EIP67_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = web3swift_EIP67_Tests.swift; sourceTree = "<group>"; };
391392
E23B5AE020EA695400DC7F32 /* web3swift_rinkeby_personalSignature_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = web3swift_rinkeby_personalSignature_Tests.swift; sourceTree = "<group>"; };
392393
E23B5AE220EA69B900DC7F32 /* web3swift_numberFormattingUtil_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = web3swift_numberFormattingUtil_Tests.swift; sourceTree = "<group>"; };
394+
E279C9EE21C46A140081695F /* Web3+ERC165.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+ERC165.swift"; sourceTree = "<group>"; };
393395
E2C590752152835400FF53D3 /* JSONRPCrequestDispatcher+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "JSONRPCrequestDispatcher+ObjC.swift"; sourceTree = "<group>"; };
394396
E2E94C5F217788E0005F54A0 /* Web3+ERC721.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+ERC721.swift"; sourceTree = "<group>"; };
395397
FB43EC035C593F9E5A3644B6 /* Pods-web3swift-macOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-web3swift-macOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-web3swift-macOS/Pods-web3swift-macOS.debug.xcconfig"; sourceTree = "<group>"; };
@@ -610,6 +612,7 @@
610612
8159C50921343EF900197B91 /* PrecompiledContracts */ = {
611613
isa = PBXGroup;
612614
children = (
615+
E279C9ED21C3F2970081695F /* ERC165 */,
613616
E2E94C5E2177886C005F54A0 /* ERC721 */,
614617
8159C50621343ED300197B91 /* ERC20 */,
615618
);
@@ -945,6 +948,14 @@
945948
path = Classes;
946949
sourceTree = "<group>";
947950
};
951+
E279C9ED21C3F2970081695F /* ERC165 */ = {
952+
isa = PBXGroup;
953+
children = (
954+
E279C9EE21C46A140081695F /* Web3+ERC165.swift */,
955+
);
956+
path = ERC165;
957+
sourceTree = "<group>";
958+
};
948959
E2E94C5E2177886C005F54A0 /* ERC721 */ = {
949960
isa = PBXGroup;
950961
children = (
@@ -1251,6 +1262,7 @@
12511262
81A1823720D6E2BB0016741F /* Promise+Web3+Eth+GetBlockByHash.swift in Sources */,
12521263
81909D51218DAEC0007D2AE5 /* Promise+Web3+Personal+CreateAccount.swift in Sources */,
12531264
818D16CF204D42910084D2A4 /* Web3+EventParser.swift in Sources */,
1265+
E279C9EF21C46A140081695F /* Web3+ERC165.swift in Sources */,
12541266
81C5DA282072E18200424CD6 /* NativeTypesEncoding+Extensions.swift in Sources */,
12551267
8123E1C7200CBAC200B6D3AB /* Dictionary+Extension.swift in Sources */,
12561268
E228BE7421A4492B0085268C /* Promise+Web3Legacy+Eth+Call.swift in Sources */,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Web3+ERC165.swift
3+
// web3swift-iOS
4+
//
5+
// Created by Anton Grigorev on 15/12/2018.
6+
// Copyright © 2018 The Matter Inc. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import BigInt
11+
import PromiseKit
12+
import EthereumAddress
13+
14+
protocol IERC165 {
15+
16+
func supportsInterface(interfaceID: [UInt8]) throws -> Bool
17+
18+
}

web3swift/PrecompiledContracts/ERC721/Web3+ERC721.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import EthereumAddress
1111

1212
// This namespace contains functions to work with ERC721 tokens.
1313
// can be imperatively read and saved
14-
public class ERC721 {
14+
public class ERC721: IERC165 {
1515

1616
@available(*, deprecated, renamed: "transactionOptions")
1717
public var options: Web3Options = .init()
@@ -178,4 +178,14 @@ public class ERC721 {
178178
return tx
179179
}
180180

181+
public func supportsInterface(interfaceID: [UInt8]) throws -> Bool {
182+
let contract = self.contract
183+
var transactionOptions = TransactionOptions()
184+
transactionOptions.callOnBlock = .latest
185+
transactionOptions.gasLimit = .manual(30000)
186+
let result = try contract.read("supportsInterface", parameters: [interfaceID] as [AnyObject], extraData: Data(), transactionOptions: self.transactionOptions)!.call(transactionOptions: transactionOptions)
187+
guard let res = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Failed to get result of expected type from the Ethereum node")}
188+
return res
189+
}
190+
181191
}

0 commit comments

Comments
 (0)