@@ -67,11 +67,9 @@ public class ERC1155: IERC1155 {
67
67
if self . _hasReadProperties {
68
68
return
69
69
}
70
- let contract = self . contract
71
70
guard contract. contract. address != nil else { return }
72
- self . transaction. callOnBlock = . latest
73
71
74
- guard let tokenIdPromise = try await contract. createReadOperation ( " id " , parameters: [ ] , extraData : Data ( ) ) ? . callContractMethod ( ) else { return }
72
+ guard let tokenIdPromise = try await contract. createReadOperation ( " id " , parameters: [ ] ) ? . callContractMethod ( ) else { return }
75
73
76
74
guard let tokenId = tokenIdPromise [ " 0 " ] as? BigUInt else { return }
77
75
self . _tokenId = tokenId
@@ -80,64 +78,55 @@ public class ERC1155: IERC1155 {
80
78
}
81
79
82
80
public func safeTransferFrom( from: EthereumAddress , to: EthereumAddress , originalOwner: EthereumAddress , id: BigUInt , value: BigUInt , data: [ UInt8 ] ) throws -> WriteOperation {
83
- let contract = self . contract
84
- self . transaction. from = from
85
- self . transaction. to = self . address
86
-
81
+ updateTransactionAndContract ( from: from)
87
82
let tx = contract. createWriteOperation ( " safeTransferFrom " , parameters: [ originalOwner, to, id, value, data] ) !
88
83
return tx
89
84
}
90
85
91
86
public func safeBatchTransferFrom( from: EthereumAddress , to: EthereumAddress , originalOwner: EthereumAddress , ids: [ BigUInt ] , values: [ BigUInt ] , data: [ UInt8 ] ) throws -> WriteOperation {
92
- let contract = self . contract
93
- self . transaction. from = from
94
- self . transaction. to = self . address
95
-
87
+ updateTransactionAndContract ( from: from)
96
88
let tx = contract
97
89
. createWriteOperation ( " safeBatchTransferFrom " , parameters: [ originalOwner, to, ids, values, data] ) !
98
90
return tx
99
91
}
100
92
101
93
public func balanceOf( account: EthereumAddress , id: BigUInt ) async throws -> BigUInt {
102
- let contract = self . contract
103
- self . transaction. callOnBlock = . latest
104
94
let result = try await contract
105
- . createReadOperation ( " balanceOf " , parameters: [ account, id] , extraData : Data ( ) ) !
95
+ . createReadOperation ( " balanceOf " , parameters: [ account, id] ) !
106
96
. callContractMethod ( )
107
-
108
- /*
109
- let result = try await contract
110
- .prepareToRead("balanceOf", parameters: [account, id], extraData: Data() )!
111
- .execute()
112
- .decodeData()
113
-
114
- */
115
97
guard let res = result [ " 0 " ] as? BigUInt else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
116
98
return res
117
99
}
118
100
119
101
public func setApprovalForAll( from: EthereumAddress , operator user: EthereumAddress , approved: Bool , scope: Data ) throws -> WriteOperation {
120
- let contract = self . contract
121
- self . transaction. from = from
122
- self . transaction. to = self . address
123
-
102
+ updateTransactionAndContract ( from: from)
124
103
let tx = contract. createWriteOperation ( " setApprovalForAll " , parameters: [ user, approved, scope] ) !
125
104
return tx
126
105
}
127
106
128
107
public func isApprovedForAll( owner: EthereumAddress , operator user: EthereumAddress , scope: Data ) async throws -> Bool {
129
- let contract = self . contract
130
- self . transaction. callOnBlock = . latest
131
- let result = try await contract. createReadOperation ( " isApprovedForAll " , parameters: [ owner, user, scope] , extraData: Data ( ) ) !. callContractMethod ( )
108
+ let result = try await contract. createReadOperation ( " isApprovedForAll " , parameters: [ owner, user, scope] ) !. callContractMethod ( )
109
+
132
110
guard let res = result [ " 0 " ] as? Bool else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
133
111
return res
134
112
}
135
113
136
114
public func supportsInterface( interfaceID: String ) async throws -> Bool {
137
- let contract = self . contract
138
- self . transaction. callOnBlock = . latest
139
- let result = try await contract. createReadOperation ( " supportsInterface " , parameters: [ interfaceID] , extraData: Data ( ) ) !. callContractMethod ( )
115
+ let result = try await contract. createReadOperation ( " supportsInterface " , parameters: [ interfaceID] ) !. callContractMethod ( )
116
+
140
117
guard let res = result [ " 0 " ] as? Bool else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
141
118
return res
142
119
}
143
120
}
121
+
122
+ // MARK: - Private
123
+
124
+ extension ERC1155 {
125
+
126
+ private func updateTransactionAndContract( from: EthereumAddress ) {
127
+ transaction. from = from
128
+ transaction. to = address
129
+ contract. transaction = transaction
130
+ }
131
+
132
+ }
0 commit comments