Skip to content

Commit 6968d2d

Browse files
correctly fixed and added erc20, 165, 721, 777, 820
1 parent 424c156 commit 6968d2d

File tree

6 files changed

+2222
-4
lines changed

6 files changed

+2222
-4
lines changed

web3swift.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@
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 */; };
213213
E279C9EF21C46A140081695F /* Web3+ERC165.swift in Sources */ = {isa = PBXBuildFile; fileRef = E279C9EE21C46A140081695F /* Web3+ERC165.swift */; };
214+
E279C9F521C47B4A0081695F /* Web3+ERC777.swift in Sources */ = {isa = PBXBuildFile; fileRef = E279C9F421C47B4A0081695F /* Web3+ERC777.swift */; };
215+
E279C9F821C47CD00081695F /* Web3+ERC820.swift in Sources */ = {isa = PBXBuildFile; fileRef = E279C9F721C47CD00081695F /* Web3+ERC820.swift */; };
214216
E2DCA653218C875100F94FBA /* web3swift_ENS_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81A7B2782143C978004CD2C7 /* web3swift_ENS_Tests.swift */; };
215217
E2DCA654218C879900F94FBA /* ENS.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2E668CD214F8A7B00C3CC2D /* ENS.swift */; };
216218
E2DCA655218C879900F94FBA /* ENSResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B219DC162154F3EE0035BF94 /* ENSResolver.swift */; };
@@ -392,6 +394,8 @@
392394
E23B5AE020EA695400DC7F32 /* web3swift_rinkeby_personalSignature_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = web3swift_rinkeby_personalSignature_Tests.swift; sourceTree = "<group>"; };
393395
E23B5AE220EA69B900DC7F32 /* web3swift_numberFormattingUtil_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = web3swift_numberFormattingUtil_Tests.swift; sourceTree = "<group>"; };
394396
E279C9EE21C46A140081695F /* Web3+ERC165.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+ERC165.swift"; sourceTree = "<group>"; };
397+
E279C9F421C47B4A0081695F /* Web3+ERC777.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+ERC777.swift"; sourceTree = "<group>"; };
398+
E279C9F721C47CD00081695F /* Web3+ERC820.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+ERC820.swift"; sourceTree = "<group>"; };
395399
E2C590752152835400FF53D3 /* JSONRPCrequestDispatcher+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "JSONRPCrequestDispatcher+ObjC.swift"; sourceTree = "<group>"; };
396400
E2E94C5F217788E0005F54A0 /* Web3+ERC721.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+ERC721.swift"; sourceTree = "<group>"; };
397401
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>"; };
@@ -612,6 +616,8 @@
612616
8159C50921343EF900197B91 /* PrecompiledContracts */ = {
613617
isa = PBXGroup;
614618
children = (
619+
E279C9F621C47CC10081695F /* ERC820 */,
620+
E279C9F321C47B3B0081695F /* ERC777 */,
615621
E279C9ED21C3F2970081695F /* ERC165 */,
616622
E2E94C5E2177886C005F54A0 /* ERC721 */,
617623
8159C50621343ED300197B91 /* ERC20 */,
@@ -956,6 +962,22 @@
956962
path = ERC165;
957963
sourceTree = "<group>";
958964
};
965+
E279C9F321C47B3B0081695F /* ERC777 */ = {
966+
isa = PBXGroup;
967+
children = (
968+
E279C9F421C47B4A0081695F /* Web3+ERC777.swift */,
969+
);
970+
path = ERC777;
971+
sourceTree = "<group>";
972+
};
973+
E279C9F621C47CC10081695F /* ERC820 */ = {
974+
isa = PBXGroup;
975+
children = (
976+
E279C9F721C47CD00081695F /* Web3+ERC820.swift */,
977+
);
978+
path = ERC820;
979+
sourceTree = "<group>";
980+
};
959981
E2E94C5E2177886C005F54A0 /* ERC721 */ = {
960982
isa = PBXGroup;
961983
children = (
@@ -1259,6 +1281,7 @@
12591281
81FB21FE207BB297007F9A83 /* EIP67Code.swift in Sources */,
12601282
81A1821A20D5A6F70016741F /* Promise+HttpProvider.swift in Sources */,
12611283
E228BECD21A4C89F0085268C /* Web3Legacy+Contract.swift in Sources */,
1284+
E279C9F821C47CD00081695F /* Web3+ERC820.swift in Sources */,
12621285
81A1823720D6E2BB0016741F /* Promise+Web3+Eth+GetBlockByHash.swift in Sources */,
12631286
81909D51218DAEC0007D2AE5 /* Promise+Web3+Personal+CreateAccount.swift in Sources */,
12641287
818D16CF204D42910084D2A4 /* Web3+EventParser.swift in Sources */,
@@ -1307,6 +1330,7 @@
13071330
81C0FCF220440EB500D82FAF /* Web3+Protocols.swift in Sources */,
13081331
81C0FCF420440F0900D82FAF /* Web3+Options.swift in Sources */,
13091332
81A1822E20D67BC30016741F /* Promise+Web3+Eth+GetTransactionReceipt.swift in Sources */,
1333+
E279C9F521C47B4A0081695F /* Web3+ERC777.swift in Sources */,
13101334
81A1824020D79FDB0016741F /* Promise+Web3+Eth+EstimateGas.swift in Sources */,
13111335
81909D1221862D17007D2AE5 /* Web3+ReadingTransaction.swift in Sources */,
13121336
81A1822B20D67A1B0016741F /* Promise+Web3+Eth+GetTransactionDetails.swift in Sources */,

web3swift/PrecompiledContracts/ERC165/Web3+ERC165.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
//
88

99
import Foundation
10-
import BigInt
11-
import PromiseKit
12-
import EthereumAddress
1310

1411
protocol IERC165 {
1512

web3swift/PrecompiledContracts/ERC20/Web3+ERC20.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class ERC20: IERC20 {
2929
private var _name: String? = nil
3030
private var _symbol: String? = nil
3131
private var _decimals: UInt8? = nil
32+
private var _totalSupply: BigUInt? = nil
3233
private var _hasReadProperties: Bool = false
3334

3435
public var transactionOptions: TransactionOptions
@@ -75,6 +76,14 @@ public class ERC20: IERC20 {
7576
return 255
7677
}
7778

79+
public var totalSupply: BigUInt {
80+
self.readProperties()
81+
if self._totalSupply != nil {
82+
return self._totalSupply!
83+
}
84+
return 0
85+
}
86+
7887
public func readProperties() {
7988
if self._hasReadProperties {
8089
return
@@ -88,8 +97,10 @@ public class ERC20: IERC20 {
8897
guard let symbolPromise = contract.read("symbol", parameters: [] as [AnyObject], extraData: Data(), transactionOptions: transactionOptions)?.callPromise() else {return}
8998

9099
guard let decimalPromise = contract.read("decimals", parameters: [] as [AnyObject], extraData: Data(), transactionOptions: transactionOptions)?.callPromise() else {return}
100+
101+
guard let totalSupplyPromise = contract.read("totalSupply", parameters: [] as [AnyObject], extraData: Data(), transactionOptions: transactionOptions)?.callPromise() else {return}
91102

92-
let allPromises = [namePromise, symbolPromise, decimalPromise]
103+
let allPromises = [namePromise, symbolPromise, decimalPromise, totalSupplyPromise]
93104
let queue = self.web3.requestDispatcher.queue
94105
when(resolved: allPromises).map(on: queue) { (resolvedPromises) -> Void in
95106
guard case .fulfilled(let nameResult) = resolvedPromises[0] else {return}
@@ -104,6 +115,10 @@ public class ERC20: IERC20 {
104115
guard let decimals = decimalsResult["0"] as? BigUInt else {return}
105116
self._decimals = UInt8(decimals)
106117

118+
guard case .fulfilled(let totalSupplyResult) = resolvedPromises[3] else {return}
119+
guard let totalSupply = totalSupplyResult["0"] as? BigUInt else {return}
120+
self._totalSupply = totalSupply
121+
107122
self._hasReadProperties = true
108123
}.wait()
109124
}

0 commit comments

Comments
 (0)