Skip to content

Commit ac4ecea

Browse files
authored
1.2.9 : Trading history (#69)
1 parent 2724f47 commit ac4ecea

File tree

17 files changed

+796
-41
lines changed

17 files changed

+796
-41
lines changed

NFTY.xcodeproj/project.pbxproj

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/* Begin PBXBuildFile section */
1010
4F08724B2651E740002DD748 /* PrivateCollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F08724A2651E740002DD748 /* PrivateCollectionView.swift */; };
1111
4F08724D2651EAC0002DD748 /* FriendsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F08724C2651EAC0002DD748 /* FriendsView.swift */; };
12+
4F0FB826269AA26900AD5165 /* UIKitUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F0FB825269AA26900AD5165 /* UIKitUtils.swift */; };
13+
4F0FB828269BECD000AD5165 /* TradeHistorySheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F0FB827269BECD000AD5165 /* TradeHistorySheet.swift */; };
1214
4F27A7C0267F9000008CCB0A /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = 4F27A7BF267F9000008CCB0A /* Kingfisher */; };
1315
4F27A7C3267F9760008CCB0A /* Cache in Frameworks */ = {isa = PBXBuildFile; productRef = 4F27A7C2267F9760008CCB0A /* Cache */; };
1416
4F27A7C5267FB702008CCB0A /* BAYC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F27A7C4267FB702008CCB0A /* BAYC.swift */; };
@@ -35,6 +37,7 @@
3537
4F446F2E263773EE00BE739E /* CryptoPunks_nearestTokens.json in Resources */ = {isa = PBXBuildFile; fileRef = 4F446F2D263773EE00BE739E /* CryptoPunks_nearestTokens.json */; };
3638
4F468F692645FECB00CA6525 /* AddFavSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F468F682645FECB00CA6525 /* AddFavSheet.swift */; };
3739
4F468F6C2646D63E00CA6525 /* Introspect in Frameworks */ = {isa = PBXBuildFile; productRef = 4F468F6B2646D63E00CA6525 /* Introspect */; };
40+
4F4A24852693B275006DBBFA /* OwnerProfileLinkButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F4A24842693B275006DBBFA /* OwnerProfileLinkButton.swift */; };
3841
4F4C6982264F6483005B9A23 /* AutoglyphView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F4C6981264F6483005B9A23 /* AutoglyphView.swift */; };
3942
4F4CA8012635D806001534A6 /* FavButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F4CA8002635D806001534A6 /* FavButton.swift */; };
4043
4F4CA8062635D813001534A6 /* BackButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F4CA8052635D813001534A6 /* BackButton.swift */; };
@@ -54,6 +57,8 @@
5457
4F5F8F60265331AB00FAD814 /* AddressLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F5F8F5F265331AB00FAD814 /* AddressLabel.swift */; };
5558
4F667F6E264B291000E7A214 /* ObservablePromise.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F667F6D264B291000E7A214 /* ObservablePromise.swift */; };
5659
4F667F70264B2C0200E7A214 /* ObservedPromiseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F667F6F264B2C0200E7A214 /* ObservedPromiseView.swift */; };
60+
4F673C9E2696820900CA6918 /* TokenTradeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F673C9D2696820900CA6918 /* TokenTradeView.swift */; };
61+
4F673CA02697E5F400CA6918 /* TradeEventsList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F673C9F2697E5F400CA6918 /* TradeEventsList.swift */; };
5762
4F6D395D262BD76E007E79BB /* CollectionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F6D395C262BD76E007E79BB /* CollectionsView.swift */; };
5863
4F6D3962262BD8A8007E79BB /* CollectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F6D3961262BD8A8007E79BB /* CollectionView.swift */; };
5964
4F6D3975262BE4F3007E79BB /* NftImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F6D3974262BE4F3007E79BB /* NftImage.swift */; };
@@ -66,7 +71,6 @@
6671
4FA02CD0265046D600B0B9C5 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FA02CCF265046D600B0B9C5 /* ContentView.swift */; };
6772
4FA02CD2265046D700B0B9C5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4FA02CD1265046D700B0B9C5 /* Assets.xcassets */; };
6873
4FA02CD5265046D700B0B9C5 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4FA02CD4265046D700B0B9C5 /* Preview Assets.xcassets */; };
69-
4FA20038264DE73700E81BE6 /* OwnerProfileLinkButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FA20037264DE73700E81BE6 /* OwnerProfileLinkButton.swift */; };
7074
4FB9A7B1262B28A300C58AF9 /* NFTYApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FB9A7B0262B28A300C58AF9 /* NFTYApp.swift */; };
7175
4FB9A7B5262B28A400C58AF9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4FB9A7B4262B28A400C58AF9 /* Assets.xcassets */; };
7276
4FB9A7B8262B28A400C58AF9 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4FB9A7B7262B28A400C58AF9 /* Preview Assets.xcassets */; };
@@ -87,6 +91,7 @@
8791
4FC744732630FD7D0060FC6D /* Web3PromiseKit in Frameworks */ = {isa = PBXBuildFile; productRef = 4FC744722630FD7D0060FC6D /* Web3PromiseKit */; };
8892
4FC744752630FD7D0060FC6D /* Web3ContractABI in Frameworks */ = {isa = PBXBuildFile; productRef = 4FC744742630FD7D0060FC6D /* Web3ContractABI */; };
8993
4FC744772630FD7D0060FC6D /* Web3 in Frameworks */ = {isa = PBXBuildFile; productRef = 4FC744762630FD7D0060FC6D /* Web3 */; };
94+
4FF84E53269512CE0079039E /* TradableTokenPrice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF84E52269512CE0079039E /* TradableTokenPrice.swift */; };
9095
/* End PBXBuildFile section */
9196

9297
/* Begin PBXContainerItemProxy section */
@@ -149,6 +154,8 @@
149154
4F0872492650CB85002DD748 /* NFTY.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = NFTY.entitlements; sourceTree = "<group>"; };
150155
4F08724A2651E740002DD748 /* PrivateCollectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivateCollectionView.swift; sourceTree = "<group>"; };
151156
4F08724C2651EAC0002DD748 /* FriendsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsView.swift; sourceTree = "<group>"; };
157+
4F0FB825269AA26900AD5165 /* UIKitUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitUtils.swift; sourceTree = "<group>"; };
158+
4F0FB827269BECD000AD5165 /* TradeHistorySheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TradeHistorySheet.swift; sourceTree = "<group>"; };
152159
4F27A7C4267FB702008CCB0A /* BAYC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BAYC.swift; sourceTree = "<group>"; };
153160
4F27A7D82682D2BE008CCB0A /* CoreCollections.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreCollections.swift; sourceTree = "<group>"; };
154161
4F27A7DD268768FD008CCB0A /* LogsFetcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogsFetcher.swift; sourceTree = "<group>"; };
@@ -161,6 +168,7 @@
161168
4F446F2226376C3600BE739E /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
162169
4F446F2D263773EE00BE739E /* CryptoPunks_nearestTokens.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = CryptoPunks_nearestTokens.json; sourceTree = "<group>"; };
163170
4F468F682645FECB00CA6525 /* AddFavSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFavSheet.swift; sourceTree = "<group>"; };
171+
4F4A24842693B275006DBBFA /* OwnerProfileLinkButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OwnerProfileLinkButton.swift; sourceTree = "<group>"; };
164172
4F4C6981264F6483005B9A23 /* AutoglyphView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoglyphView.swift; sourceTree = "<group>"; };
165173
4F4CA8002635D806001534A6 /* FavButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavButton.swift; sourceTree = "<group>"; };
166174
4F4CA8052635D813001534A6 /* BackButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackButton.swift; sourceTree = "<group>"; };
@@ -182,6 +190,8 @@
182190
4F5F8F5F265331AB00FAD814 /* AddressLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressLabel.swift; sourceTree = "<group>"; };
183191
4F667F6D264B291000E7A214 /* ObservablePromise.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservablePromise.swift; sourceTree = "<group>"; };
184192
4F667F6F264B2C0200E7A214 /* ObservedPromiseView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservedPromiseView.swift; sourceTree = "<group>"; };
193+
4F673C9D2696820900CA6918 /* TokenTradeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenTradeView.swift; sourceTree = "<group>"; };
194+
4F673C9F2697E5F400CA6918 /* TradeEventsList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TradeEventsList.swift; sourceTree = "<group>"; };
185195
4F6D395C262BD76E007E79BB /* CollectionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionsView.swift; sourceTree = "<group>"; };
186196
4F6D3961262BD8A8007E79BB /* CollectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionView.swift; sourceTree = "<group>"; };
187197
4F6D3974262BE4F3007E79BB /* NftImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NftImage.swift; sourceTree = "<group>"; };
@@ -197,7 +207,6 @@
197207
4FA02CD1265046D700B0B9C5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
198208
4FA02CD4265046D700B0B9C5 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
199209
4FA02CD6265046D700B0B9C5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
200-
4FA20037264DE73700E81BE6 /* OwnerProfileLinkButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OwnerProfileLinkButton.swift; sourceTree = SOURCE_ROOT; };
201210
4FB9A7AD262B28A300C58AF9 /* NFTY.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NFTY.app; sourceTree = BUILT_PRODUCTS_DIR; };
202211
4FB9A7B0262B28A300C58AF9 /* NFTYApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFTYApp.swift; sourceTree = "<group>"; };
203212
4FB9A7B4262B28A400C58AF9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -222,6 +231,7 @@
222231
4FBF8AF7264E079D00569DCA /* AsciiPunks_rarityRanks.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = AsciiPunks_rarityRanks.json; sourceTree = "<group>"; };
223232
4FC639DC264F5EC000ECF7CF /* Erc721Contract.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Erc721Contract.swift; sourceTree = "<group>"; };
224233
4FC744692630F9130060FC6D /* TokenProtocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenProtocols.swift; sourceTree = "<group>"; };
234+
4FF84E52269512CE0079039E /* TradableTokenPrice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TradableTokenPrice.swift; sourceTree = "<group>"; };
225235
/* End PBXFileReference section */
226236

227237
/* Begin PBXFrameworksBuildPhase section */
@@ -459,17 +469,22 @@
459469
4F4DD21A265DDE3C00AD320D /* NftUrlView.swift */,
460470
4F667F6F264B2C0200E7A214 /* ObservedPromiseView.swift */,
461471
4F5F8F5B26532BE200FAD814 /* OpenSeaLink.swift */,
462-
4FA20037264DE73700E81BE6 /* OwnerProfileLinkButton.swift */,
472+
4F4A24842693B275006DBBFA /* OwnerProfileLinkButton.swift */,
463473
4F08724A2651E740002DD748 /* PrivateCollectionView.swift */,
464474
4FB9A7E8262B353E00C58AF9 /* RoundedImage.swift */,
465475
4F58A047263688C500E258C1 /* SimilarTokensView.swift */,
466476
4F5F8F5926531D3A00FAD814 /* TextFieldAlertView.swift */,
467477
4F43153C2638EF7400C16872 /* TokenPrice.swift */,
478+
4F673C9D2696820900CA6918 /* TokenTradeView.swift */,
479+
4FF84E52269512CE0079039E /* TradableTokenPrice.swift */,
480+
4F673C9F2697E5F400CA6918 /* TradeEventsList.swift */,
468481
4FB9A810262B508700C58AF9 /* UsdText.swift */,
469482
4F4DD21C265DF1F400AD320D /* UserUrlView.swift */,
470483
4F55A8E72648D1DF007C8002 /* WalletTokensView.swift */,
471484
4F55A8E52648BB17007C8002 /* WalletView.swift */,
472485
4F5F8F5D26532D9C00FAD814 /* WebView.swift */,
486+
4F0FB825269AA26900AD5165 /* UIKitUtils.swift */,
487+
4F0FB827269BECD000AD5165 /* TradeHistorySheet.swift */,
473488
);
474489
path = Views;
475490
sourceTree = "<group>";
@@ -832,9 +847,11 @@
832847
isa = PBXSourcesBuildPhase;
833848
buildActionMask = 2147483647;
834849
files = (
850+
4F0FB826269AA26900AD5165 /* UIKitUtils.swift in Sources */,
851+
4F4A24852693B275006DBBFA /* OwnerProfileLinkButton.swift in Sources */,
835852
4FB9A811262B508700C58AF9 /* UsdText.swift in Sources */,
853+
4FF84E53269512CE0079039E /* TradableTokenPrice.swift in Sources */,
836854
4F4DD21F265F480A00AD320D /* AddressLabelWithShare.swift in Sources */,
837-
4FA20038264DE73700E81BE6 /* OwnerProfileLinkButton.swift in Sources */,
838855
4FC7446A2630F9130060FC6D /* TokenProtocols.swift in Sources */,
839856
4F667F6E264B291000E7A214 /* ObservablePromise.swift in Sources */,
840857
4F58A048263688C500E258C1 /* SimilarTokensView.swift in Sources */,
@@ -858,6 +875,7 @@
858875
4F08724B2651E740002DD748 /* PrivateCollectionView.swift in Sources */,
859876
4FB9A7F3262B3A5700C58AF9 /* NFT.swift in Sources */,
860877
4F08724D2651EAC0002DD748 /* FriendsView.swift in Sources */,
878+
4F673C9E2696820900CA6918 /* TokenTradeView.swift in Sources */,
861879
4F4DD21D265DF1F400AD320D /* UserUrlView.swift in Sources */,
862880
4F468F692645FECB00CA6525 /* AddFavSheet.swift in Sources */,
863881
4F55A8EA2648D343007C8002 /* ConnectWalletSheet.swift in Sources */,
@@ -867,10 +885,12 @@
867885
4FB9A81E262B53DE00C58AF9 /* NftDetail.swift in Sources */,
868886
4F6D3975262BE4F3007E79BB /* NftImage.swift in Sources */,
869887
4FB9A7B1262B28A300C58AF9 /* NFTYApp.swift in Sources */,
888+
4F673CA02697E5F400CA6918 /* TradeEventsList.swift in Sources */,
870889
4FB9A7DF262B307C00C58AF9 /* CircleImage.swift in Sources */,
871890
4F4DD21B265DDE3C00AD320D /* NftUrlView.swift in Sources */,
872891
4F6D3962262BD8A8007E79BB /* CollectionView.swift in Sources */,
873892
4FB9A7FB262B3BBA00C58AF9 /* ModelData.swift in Sources */,
893+
4F0FB828269BECD000AD5165 /* TradeHistorySheet.swift in Sources */,
874894
4F55A8EC264A0642007C8002 /* BlockTimeLabel.swift in Sources */,
875895
4F55A8E62648BB17007C8002 /* WalletView.swift in Sources */,
876896
);
@@ -1172,7 +1192,7 @@
11721192
"$(inherited)",
11731193
"@executable_path/Frameworks",
11741194
);
1175-
MARKETING_VERSION = 1.2.8;
1195+
MARKETING_VERSION = 1.2.9;
11761196
PRODUCT_BUNDLE_IDENTIFIER = com.nftygo.NFTY;
11771197
PRODUCT_NAME = "$(TARGET_NAME)";
11781198
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -1199,7 +1219,7 @@
11991219
"$(inherited)",
12001220
"@executable_path/Frameworks",
12011221
);
1202-
MARKETING_VERSION = 1.2.8;
1222+
MARKETING_VERSION = 1.2.9;
12031223
PRODUCT_BUNDLE_IDENTIFIER = com.nftygo.NFTY;
12041224
PRODUCT_NAME = "$(TARGET_NAME)";
12051225
PROVISIONING_PROFILE_SPECIFIER = "";

NFTY.xcodeproj/xcuserdata/vkohli.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<key>DownloadCryptoPunks.xcscheme_^#shared#^_</key>
2929
<dict>
3030
<key>orderHint</key>
31-
<integer>1</integer>
31+
<integer>3</integer>
3232
</dict>
3333
<key>MyPlayground (Playground) 1.xcscheme</key>
3434
<dict>
@@ -54,12 +54,12 @@
5454
<key>NFTY.xcscheme_^#shared#^_</key>
5555
<dict>
5656
<key>orderHint</key>
57-
<integer>3</integer>
57+
<integer>5</integer>
5858
</dict>
5959
<key>ParseTokenDistances.xcscheme_^#shared#^_</key>
6060
<dict>
6161
<key>orderHint</key>
62-
<integer>4</integer>
62+
<integer>0</integer>
6363
</dict>
6464
<key>PromiseKit (Playground) 1.xcscheme</key>
6565
<dict>
@@ -106,12 +106,12 @@
106106
<key>RankImages.xcscheme_^#shared#^_</key>
107107
<dict>
108108
<key>orderHint</key>
109-
<integer>0</integer>
109+
<integer>4</integer>
110110
</dict>
111111
<key>RarityRanking.xcscheme_^#shared#^_</key>
112112
<dict>
113113
<key>orderHint</key>
114-
<integer>2</integer>
114+
<integer>1</integer>
115115
</dict>
116116
<key>SimpleStorage (Playground) 1.xcscheme</key>
117117
<dict>
@@ -158,7 +158,7 @@
158158
<key>TestUI.xcscheme_^#shared#^_</key>
159159
<dict>
160160
<key>orderHint</key>
161-
<integer>5</integer>
161+
<integer>2</integer>
162162
</dict>
163163
</dict>
164164
</dict>

NFTY/Model/CollectionContracts/BAYC.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ class BAYC_Contract : ContractInterface {
8383

8484
var ethContract = IpfsImageEthContract(address:"0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D")
8585

86+
func getEventsFetcher(_ tokenId: UInt) -> TokenEventsFetcher? {
87+
return ethContract.getEventsFetcher(tokenId)
88+
}
89+
8690
private func download(_ tokenId:BigUInt) -> ObservablePromise<Media.IpfsImage?> {
8791
switch(try? imageCache.object(forKey:tokenId)) {
8892
case .some(let p):

NFTY/Model/Erc721Contract.swift

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Erc721Contract {
7979
return outputs["tokenURI"] as! String
8080
}
8181
}
82-
82+
8383

8484
func ownerOf(_ tokenId:BigUInt) -> Promise<EthereumAddress> {
8585
let inputs = [SolidityFunctionParameter(name: "tokenId", type: .uint256)]
@@ -351,4 +351,58 @@ class Erc721Contract {
351351
return ethContract.ownerOf(BigUInt(tokenId)).map { addressIfNotZero($0) }
352352
}
353353

354+
class EventsFetcher : TokenEventsFetcher {
355+
let Transfer: SolidityEvent = SolidityEvent(name: "Transfer", anonymous: false, inputs: [
356+
SolidityEvent.Parameter(name: "from", type: .address, indexed: true),
357+
SolidityEvent.Parameter(name: "to", type: .address, indexed: true),
358+
SolidityEvent.Parameter(name: "tokenId", type: .uint256, indexed: true),
359+
])
360+
361+
let transferFetcher : LogsFetcher
362+
init(transferFetcher:LogsFetcher) {
363+
self.transferFetcher = transferFetcher
364+
}
365+
366+
func getEvents(onDone: @escaping () -> Void,_ response: @escaping (TradeEvent) -> Void) {
367+
var reachedMint = false
368+
369+
return transferFetcher.fetchAllLogs(onDone: {
370+
if (reachedMint) { onDone() }
371+
}) { log in
372+
let res = try! web3.eth.abi.decodeLog(event:self.Transfer,from:log)
373+
let from = res["from"] as! EthereumAddress
374+
375+
var type : TradeEventType = .bought
376+
377+
if (from == EthereumAddress(hexString: "0x0000000000000000000000000000000000000000")) {
378+
reachedMint = true
379+
type = .minted
380+
}
381+
382+
txFetcher.eventOfTx(transactionHash: log.transactionHash)
383+
.map(on:DispatchQueue.global(qos:.userInteractive)) { (txData:TxFetcher.TxInfo?) in
384+
switch(txData) {
385+
case .none:
386+
return TradeEvent(type:.transfer,value:BigUInt(0),blockNumber:log.blockNumber!)
387+
case .some(let tx):
388+
return TradeEvent(type:type,value:tx.value,blockNumber:tx.blockNumber)
389+
}
390+
}.done { response($0) }
391+
.catch { print($0) }
392+
}
393+
}
394+
}
395+
396+
func getEventsFetcher(_ tokenId: UInt) -> TokenEventsFetcher? {
397+
398+
let tokenIdTopic = try! ABI.encodeParameter(SolidityWrappedValue.uint(BigUInt(tokenId)))
399+
let transerFetcher = LogsFetcher(
400+
event:self.Transfer,
401+
fromBlock:self.initFromBlock,
402+
address:self.contractAddressHex,
403+
indexedTopics: [nil,nil,tokenIdTopic],
404+
blockDecrements: 10000)
405+
406+
return EventsFetcher(transferFetcher:transerFetcher)
407+
}
354408
}

NFTY/Model/LogsFetcher.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,28 @@ class LogsFetcher {
117117
onDone()
118118
}
119119
}
120+
121+
func fetchAllLogs(onDone: @escaping () -> Void,retries:Int = 0,_ response: @escaping (EthereumLogObject) -> Void) {
122+
123+
web3.eth.getLogs(
124+
params:EthereumGetLogParams(
125+
fromBlock:.block(0),
126+
toBlock: .latest,
127+
address:try! EthereumAddress(hex: self.address, eip55: false),
128+
topics: self.topics
129+
)
130+
) { result in
131+
if case let logs? = result.result {
132+
logs.indices.forEach { index in
133+
let log = logs[index];
134+
response(log)
135+
}
136+
} else {
137+
print(result)
138+
}
139+
onDone()
140+
}
141+
}
142+
143+
120144
}

NFTY/Model/NFT.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import Web3
1111

1212
enum TradeEventType {
1313
case offer
14+
case bid
1415
case bought
16+
case minted
17+
case transfer
1518
}
1619

1720
struct TradeEvent {

0 commit comments

Comments
 (0)