@@ -67,9 +67,7 @@ public class ERC1155: IERC1155 {
6767 if self . _hasReadProperties {
6868 return
6969 }
70- let contract = self . contract
7170 guard contract. contract. address != nil else { return }
72- self . transaction. callOnBlock = . latest
7371
7472 guard let tokenIdPromise = try await contract. createReadOperation ( " id " , parameters: [ ] as [ AnyObject ] , extraData: Data ( ) ) ? . callContractMethod ( ) else { return }
7573
@@ -80,34 +78,25 @@ public class ERC1155: IERC1155 {
8078 }
8179
8280 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-
87- let tx = contract. createWriteOperation ( " safeTransferFrom " , parameters: [ originalOwner, to, id, value, data] as [ AnyObject ] ) !
81+ updateTransactionAndContract ( from: from)
82+ let tx = contract. createWriteOperation ( " safeTransferFrom " , parameters: [ originalOwner, to, id, value, data] as [ AnyObject ] ) !
8883 return tx
8984 }
9085
9186 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)
9688 let tx = contract
97- . createWriteOperation ( " safeBatchTransferFrom " , parameters: [ originalOwner, to, ids, values, data] as [ AnyObject ] ) !
89+ . createWriteOperation ( " safeBatchTransferFrom " , parameters: [ originalOwner, to, ids, values, data] as [ AnyObject ] ) !
9890 return tx
9991 }
10092
10193 public func balanceOf( account: EthereumAddress , id: BigUInt ) async throws -> BigUInt {
102- let contract = self . contract
103- self . transaction. callOnBlock = . latest
10494 let result = try await contract
105- . createReadOperation ( " balanceOf " , parameters: [ account, id] as [ AnyObject ] , extraData: Data ( ) ) !
95+ . createReadOperation ( " balanceOf " , parameters: [ account, id] as [ AnyObject ] , extraData: Data ( ) ) !
10696 . callContractMethod ( )
107-
10897 /*
10998 let result = try await contract
110- .prepareToRead("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data() )!
99+ .prepareToRead("balanceOf", parameters: [account, id] as [AnyObject], extraData: Data())!
111100 .execute()
112101 .decodeData()
113102
@@ -117,27 +106,32 @@ public class ERC1155: IERC1155 {
117106 }
118107
119108 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-
124- let tx = contract. createWriteOperation ( " setApprovalForAll " , parameters: [ user, approved, scope] as [ AnyObject ] ) !
109+ updateTransactionAndContract ( from: from)
110+ let tx = contract. createWriteOperation ( " setApprovalForAll " , parameters: [ user, approved, scope] as [ AnyObject ] ) !
125111 return tx
126112 }
127113
128114 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] as [ AnyObject ] , extraData: Data ( ) ) !. callContractMethod ( )
115+ let result = try await contract. createReadOperation ( " isApprovedForAll " , parameters: [ owner, user, scope] as [ AnyObject ] , extraData: Data ( ) ) !. callContractMethod ( )
132116 guard let res = result [ " 0 " ] as? Bool else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
133117 return res
134118 }
135119
136120 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] as [ AnyObject ] , extraData: Data ( ) ) !. callContractMethod ( )
121+ let result = try await contract. createReadOperation ( " supportsInterface " , parameters: [ interfaceID] as [ AnyObject ] , extraData: Data ( ) ) !. callContractMethod ( )
140122 guard let res = result [ " 0 " ] as? Bool else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
141123 return res
142124 }
143125}
126+
127+ // MARK: - Private
128+
129+ extension ERC1155 {
130+
131+ private func updateTransactionAndContract( from: EthereumAddress ) {
132+ transaction. from = from
133+ transaction. to = address
134+ contract. transaction = transaction
135+ }
136+
137+ }
0 commit comments