@@ -67,9 +67,7 @@ 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
72
guard let tokenIdPromise = try await contract. createReadOperation ( " id " , parameters: [ ] as [ AnyObject ] , extraData: Data ( ) ) ? . callContractMethod ( ) else { return }
75
73
@@ -80,34 +78,25 @@ 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
-
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 ] ) !
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
- . createWriteOperation ( " safeBatchTransferFrom " , parameters: [ originalOwner, to, ids, values, data] as [ AnyObject ] ) !
89
+ . createWriteOperation ( " safeBatchTransferFrom " , parameters: [ originalOwner, to, ids, values, data] as [ AnyObject ] ) !
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] as [ AnyObject ] , extraData: Data ( ) ) !
95
+ . createReadOperation ( " balanceOf " , parameters: [ account, id] as [ AnyObject ] , extraData: Data ( ) ) !
106
96
. callContractMethod ( )
107
-
108
97
/*
109
98
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())!
111
100
.execute()
112
101
.decodeData()
113
102
@@ -117,27 +106,32 @@ public class ERC1155: IERC1155 {
117
106
}
118
107
119
108
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 ] ) !
125
111
return tx
126
112
}
127
113
128
114
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 ( )
132
116
guard let res = result [ " 0 " ] as? Bool else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
133
117
return res
134
118
}
135
119
136
120
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 ( )
140
122
guard let res = result [ " 0 " ] as? Bool else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
141
123
return res
142
124
}
143
125
}
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