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