@@ -13,15 +13,15 @@ import BigInt
13
13
// Multi Token Standard
14
14
protocol IERC1155 : IERC165 {
15
15
16
- func safeTransferFrom( from: EthereumAddress , to: EthereumAddress , originalOwner: EthereumAddress , id: BigUInt , value: BigUInt , data: [ UInt8 ] ) throws -> WriteTransaction
16
+ func safeTransferFrom( from: EthereumAddress , to: EthereumAddress , originalOwner: EthereumAddress , id: BigUInt , value: BigUInt , data: [ UInt8 ] ) async throws -> WriteTransaction
17
17
18
- func safeBatchTransferFrom( from: EthereumAddress , to: EthereumAddress , originalOwner: EthereumAddress , ids: [ BigUInt ] , values: [ BigUInt ] , data: [ UInt8 ] ) throws -> WriteTransaction
18
+ func safeBatchTransferFrom( from: EthereumAddress , to: EthereumAddress , originalOwner: EthereumAddress , ids: [ BigUInt ] , values: [ BigUInt ] , data: [ UInt8 ] ) async throws -> WriteTransaction
19
19
20
- func balanceOf( account: EthereumAddress , id: BigUInt ) throws -> BigUInt
20
+ func balanceOf( account: EthereumAddress , id: BigUInt ) async throws -> BigUInt
21
21
22
- func setApprovalForAll( from: EthereumAddress , operator user: EthereumAddress , approved: Bool , scope: Data ) throws -> WriteTransaction
22
+ func setApprovalForAll( from: EthereumAddress , operator user: EthereumAddress , approved: Bool , scope: Data ) async throws -> WriteTransaction
23
23
24
- func isApprovedForAll( owner: EthereumAddress , operator user: EthereumAddress , scope: Data ) throws -> Bool
24
+ func isApprovedForAll( owner: EthereumAddress , operator user: EthereumAddress , scope: Data ) async throws -> Bool
25
25
}
26
26
27
27
protocol IERC1155Metadata {
@@ -56,15 +56,15 @@ public class ERC1155: IERC1155 {
56
56
self . transactionOptions = mergedOptions
57
57
}
58
58
59
- public var tokenId : BigUInt {
60
- self . readProperties ( )
59
+ public func tokenId( ) async throws -> BigUInt {
60
+ try await self . readProperties ( )
61
61
if self . _tokenId != nil {
62
62
return self . _tokenId!
63
63
}
64
64
return 0
65
65
}
66
66
67
- public func readProperties( ) {
67
+ public func readProperties( ) async throws {
68
68
if self . _hasReadProperties {
69
69
return
70
70
}
@@ -73,19 +73,14 @@ public class ERC1155: IERC1155 {
73
73
var transactionOptions = TransactionOptions . defaultOptions
74
74
transactionOptions. callOnBlock = . latest
75
75
76
- guard let tokenIdPromise = contract. read ( " id " , parameters: [ ] as [ AnyObject ] , extraData: Data ( ) , transactionOptions: transactionOptions) ? . callPromise ( ) else { return }
76
+ guard let tokenIdPromise = try await contract. read ( " id " , parameters: [ ] as [ AnyObject ] , extraData: Data ( ) , transactionOptions: transactionOptions) ? . callPromise ( ) else { return }
77
77
78
- let allPromises = [ tokenIdPromise]
79
- let queue = self . web3. requestDispatcher. queue
80
- when ( resolved: allPromises) . map ( on: queue) { ( resolvedPromises) -> Void in
81
- guard case . fulfilled( let tokenIdResult) = resolvedPromises [ 0 ] else { return }
82
- guard let tokenId = tokenIdResult [ " 0 " ] as? BigUInt else { return }
83
- self . _tokenId = tokenId
78
+ guard let tokenId = tokenIdPromise [ " 0 " ] as? BigUInt else { return }
79
+ self . _tokenId = tokenId
84
80
85
- self . _hasReadProperties = true
86
- } . wait ( )
81
+ self . _hasReadProperties = true
87
82
}
88
-
83
+
89
84
public func safeTransferFrom( from: EthereumAddress , to: EthereumAddress , originalOwner: EthereumAddress , id: BigUInt , value: BigUInt , data: [ UInt8 ] ) throws -> WriteTransaction {
90
85
let contract = self . contract
91
86
var basicOptions = TransactionOptions ( )
@@ -95,7 +90,7 @@ public class ERC1155: IERC1155 {
95
90
let tx = contract. write ( " safeTransferFrom " , parameters: [ originalOwner, to, id, value, data] as [ AnyObject ] , transactionOptions: basicOptions) !
96
91
return tx
97
92
}
98
-
93
+
99
94
public func safeBatchTransferFrom( from: EthereumAddress , to: EthereumAddress , originalOwner: EthereumAddress , ids: [ BigUInt ] , values: [ BigUInt ] , data: [ UInt8 ] ) throws -> WriteTransaction {
100
95
let contract = self . contract
101
96
var basicOptions = TransactionOptions ( )
@@ -105,16 +100,16 @@ public class ERC1155: IERC1155 {
105
100
let tx = contract. write ( " safeBatchTransferFrom " , parameters: [ originalOwner, to, ids, values, data] as [ AnyObject ] , transactionOptions: basicOptions) !
106
101
return tx
107
102
}
108
-
109
- public func balanceOf( account: EthereumAddress , id: BigUInt ) throws -> BigUInt {
103
+
104
+ public func balanceOf( account: EthereumAddress , id: BigUInt ) async throws -> BigUInt {
110
105
let contract = self . contract
111
106
var transactionOptions = TransactionOptions ( )
112
107
transactionOptions. callOnBlock = . latest
113
- let result = try contract. read ( " balanceOf " , parameters: [ account, id] as [ AnyObject ] , extraData: Data ( ) , transactionOptions: self . transactionOptions) !. call ( transactionOptions: transactionOptions)
108
+ let result = try await contract. read ( " balanceOf " , parameters: [ account, id] as [ AnyObject ] , extraData: Data ( ) , transactionOptions: self . transactionOptions) !. call ( transactionOptions: transactionOptions)
114
109
guard let res = result [ " 0 " ] as? BigUInt else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
115
110
return res
116
111
}
117
-
112
+
118
113
public func setApprovalForAll( from: EthereumAddress , operator user: EthereumAddress , approved: Bool , scope: Data ) throws -> WriteTransaction {
119
114
let contract = self . contract
120
115
var basicOptions = TransactionOptions ( )
@@ -124,22 +119,22 @@ public class ERC1155: IERC1155 {
124
119
let tx = contract. write ( " setApprovalForAll " , parameters: [ user, approved, scope] as [ AnyObject ] , transactionOptions: basicOptions) !
125
120
return tx
126
121
}
127
-
128
- public func isApprovedForAll( owner: EthereumAddress , operator user: EthereumAddress , scope: Data ) throws -> Bool {
122
+
123
+ public func isApprovedForAll( owner: EthereumAddress , operator user: EthereumAddress , scope: Data ) async throws -> Bool {
129
124
let contract = self . contract
130
125
var basicOptions = TransactionOptions ( )
131
126
basicOptions. callOnBlock = . latest
132
- let result = try contract. read ( " isApprovedForAll " , parameters: [ owner, user, scope] as [ AnyObject ] , extraData: Data ( ) , transactionOptions: self . transactionOptions) !. call ( transactionOptions: transactionOptions)
127
+ let result = try await contract. read ( " isApprovedForAll " , parameters: [ owner, user, scope] as [ AnyObject ] , extraData: Data ( ) , transactionOptions: self . transactionOptions) !. call ( transactionOptions: transactionOptions)
133
128
guard let res = result [ " 0 " ] as? Bool else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
134
129
return res
135
130
}
136
-
137
- public func supportsInterface( interfaceID: String ) throws -> Bool {
131
+
132
+ public func supportsInterface( interfaceID: String ) async throws -> Bool {
138
133
let contract = self . contract
139
134
var transactionOptions = TransactionOptions ( )
140
135
transactionOptions. callOnBlock = . latest
141
136
transactionOptions. gasLimit = . manual( 30000 )
142
- let result = try contract. read ( " supportsInterface " , parameters: [ interfaceID] as [ AnyObject ] , extraData: Data ( ) , transactionOptions: self . transactionOptions) !. call ( transactionOptions: transactionOptions)
137
+ let result = try await contract. read ( " supportsInterface " , parameters: [ interfaceID] as [ AnyObject ] , extraData: Data ( ) , transactionOptions: self . transactionOptions) !. call ( transactionOptions: transactionOptions)
143
138
guard let res = result [ " 0 " ] as? Bool else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
144
139
return res
145
140
}
0 commit comments