@@ -43,28 +43,22 @@ public class ERC1644: IERC1644, ERC20BaseProperties {
43
43
}
44
44
45
45
public func getBalance( account: EthereumAddress ) async throws -> BigUInt {
46
- let contract = self . contract
47
- self . transaction. callOnBlock = . latest
46
+ transaction. callOnBlock = . latest
48
47
let result = try await contract. createReadOperation ( " balanceOf " , parameters: [ account] as [ AnyObject ] , extraData: Data ( ) ) !. callContractMethod ( )
49
48
guard let res = result [ " 0 " ] as? BigUInt else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
50
49
return res
51
50
}
52
51
53
52
public func getAllowance( originalOwner: EthereumAddress , delegate: EthereumAddress ) async throws -> BigUInt {
54
- let contract = self . contract
55
- self . transaction. callOnBlock = . latest
53
+ transaction. callOnBlock = . latest
56
54
let result = try await contract. createReadOperation ( " allowance " , parameters: [ originalOwner, delegate] as [ AnyObject ] , extraData: Data ( ) ) !. callContractMethod ( )
57
55
guard let res = result [ " 0 " ] as? BigUInt else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
58
56
return res
59
57
}
60
58
61
59
public func transfer( from: EthereumAddress , to: EthereumAddress , amount: String ) async throws -> WriteOperation {
62
- let contract = self . contract
63
-
64
- self . transaction. from = from
65
- self . transaction. to = self . address
66
- self . transaction. callOnBlock = . latest
67
-
60
+ transaction. callOnBlock = . latest
61
+ updateTransactionAndContract ( from: from)
68
62
// get the decimals manually
69
63
let callResult = try await contract. createReadOperation ( " decimals " ) !. callContractMethod ( )
70
64
var decimals = BigUInt ( 0 )
@@ -81,12 +75,8 @@ public class ERC1644: IERC1644, ERC20BaseProperties {
81
75
}
82
76
83
77
public func transferFrom( from: EthereumAddress , to: EthereumAddress , originalOwner: EthereumAddress , amount: String ) async throws -> WriteOperation {
84
- let contract = self . contract
85
-
86
- self . transaction. from = from
87
- self . transaction. to = self . address
88
- self . transaction. callOnBlock = . latest
89
-
78
+ transaction. callOnBlock = . latest
79
+ updateTransactionAndContract ( from: from)
90
80
// get the decimals manually
91
81
let callResult = try await contract. createReadOperation ( " decimals " ) !. callContractMethod ( )
92
82
var decimals = BigUInt ( 0 )
@@ -104,12 +94,8 @@ public class ERC1644: IERC1644, ERC20BaseProperties {
104
94
}
105
95
106
96
public func setAllowance( from: EthereumAddress , to: EthereumAddress , newAmount: String ) async throws -> WriteOperation {
107
- let contract = self . contract
108
-
109
- self . transaction. from = from
110
- self . transaction. to = self . address
111
- self . transaction. callOnBlock = . latest
112
-
97
+ transaction. callOnBlock = . latest
98
+ updateTransactionAndContract ( from: from)
113
99
// get the decimals manually
114
100
let callResult = try await contract. createReadOperation ( " decimals " ) !. callContractMethod ( )
115
101
var decimals = BigUInt ( 0 )
@@ -127,20 +113,15 @@ public class ERC1644: IERC1644, ERC20BaseProperties {
127
113
}
128
114
129
115
public func totalSupply( ) async throws -> BigUInt {
130
- let contract = self . contract
131
- self . transaction. callOnBlock = . latest
116
+ transaction. callOnBlock = . latest
132
117
let result = try await contract. createReadOperation ( " totalSupply " , parameters: [ AnyObject] ( ) , extraData: Data ( ) ) !. callContractMethod ( )
133
118
guard let res = result [ " 0 " ] as? BigUInt else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
134
119
return res
135
120
}
136
121
137
122
public func approve( from: EthereumAddress , spender: EthereumAddress , amount: String ) async throws -> WriteOperation {
138
- let contract = self . contract
139
-
140
- self . transaction. from = from
141
- self . transaction. to = self . address
142
- self . transaction. callOnBlock = . latest
143
-
123
+ transaction. callOnBlock = . latest
124
+ updateTransactionAndContract ( from: from)
144
125
// get the decimals manually
145
126
let callResult = try await contract. createReadOperation ( " decimals " ) !. callContractMethod ( )
146
127
var decimals = BigUInt ( 0 )
@@ -159,20 +140,15 @@ public class ERC1644: IERC1644, ERC20BaseProperties {
159
140
160
141
// ERC1644
161
142
public func isControllable( ) async throws -> Bool {
162
- let contract = self . contract
163
- self . transaction. callOnBlock = . latest
143
+ transaction. callOnBlock = . latest
164
144
let result = try await contract. createReadOperation ( " isControllable " , parameters: [ AnyObject] ( ) , extraData: Data ( ) ) !. callContractMethod ( )
165
145
guard let res = result [ " 0 " ] as? Bool else { throw Web3Error . processingError ( desc: " Failed to get result of expected type from the Ethereum node " ) }
166
146
return res
167
147
}
168
148
169
149
public func controllerTransfer( from: EthereumAddress , to: EthereumAddress , originalOwner: EthereumAddress , amount: String , data: [ UInt8 ] , operatorData: [ UInt8 ] ) async throws -> WriteOperation {
170
- let contract = self . contract
171
-
172
- self . transaction. from = from
173
- self . transaction. to = self . address
174
- self . transaction. callOnBlock = . latest
175
-
150
+ transaction. callOnBlock = . latest
151
+ updateTransactionAndContract ( from: from)
176
152
// get the decimals manually
177
153
let callResult = try await contract. createReadOperation ( " decimals " ) !. callContractMethod ( )
178
154
var decimals = BigUInt ( 0 )
@@ -190,12 +166,8 @@ public class ERC1644: IERC1644, ERC20BaseProperties {
190
166
}
191
167
192
168
public func controllerRedeem( from: EthereumAddress , tokenHolder: EthereumAddress , amount: String , data: [ UInt8 ] , operatorData: [ UInt8 ] ) async throws -> WriteOperation {
193
- let contract = self . contract
194
-
195
- self . transaction. from = from
196
- self . transaction. to = self . address
197
- self . transaction. callOnBlock = . latest
198
-
169
+ transaction. callOnBlock = . latest
170
+ updateTransactionAndContract ( from: from)
199
171
// get the decimals manually
200
172
let callResult = try await contract. createReadOperation ( " decimals " ) !. callContractMethod ( )
201
173
var decimals = BigUInt ( 0 )
@@ -212,3 +184,15 @@ public class ERC1644: IERC1644, ERC20BaseProperties {
212
184
return tx
213
185
}
214
186
}
187
+
188
+ // MARK: - Private
189
+
190
+ extension ERC1644 {
191
+
192
+ private func updateTransactionAndContract( from: EthereumAddress ) {
193
+ transaction. from = from
194
+ transaction. to = address
195
+ contract. transaction = transaction
196
+ }
197
+
198
+ }
0 commit comments