@@ -13,6 +13,44 @@ import { Address } from '../types'
13
13
14
14
import { Scheme } from '../scheme'
15
15
16
+ // same address for all networks (mainnet,kovan,xdai,rinkeby)
17
+ const CT4RRedeemerAddress = '0x829BDfd41d517f57E5eBf13AD0E181351cb16a96'
18
+
19
+ const CT4RRedeemerABI = [
20
+ {
21
+ constant : false ,
22
+ inputs : [
23
+ {
24
+ internalType : 'contract ContinuousLocking4Reputation' ,
25
+ name : 'clt4Reputation' ,
26
+ type : 'address'
27
+ } ,
28
+ {
29
+ components : [
30
+ {
31
+ internalType : 'address' ,
32
+ name : 'beneficiary' ,
33
+ type : 'address'
34
+ } ,
35
+ {
36
+ internalType : 'uint256' ,
37
+ name : 'id' ,
38
+ type : 'uint256'
39
+ }
40
+ ] ,
41
+ internalType : 'struct NectarReputationRedeemer.Redeem[]' ,
42
+ name : 'clt4rRedeems' ,
43
+ type : 'tuple[]'
44
+ }
45
+ ] ,
46
+ name : 'redeemContinuousLocking4Reputation' ,
47
+ outputs : [ ] ,
48
+ payable : false ,
49
+ stateMutability : 'nonpayable' ,
50
+ type : 'function'
51
+ }
52
+ ]
53
+
16
54
export class CL4RScheme {
17
55
18
56
constructor ( public scheme : Scheme ) {
@@ -148,18 +186,30 @@ export class CL4RScheme {
148
186
return toIOperationObservable ( observable )
149
187
}
150
188
151
- public redeem ( beneficiary : Address , lockingId : number ) : Operation < any > {
189
+ /**
190
+ * redeem redeem reputation for a beneficiary for all is lockingIds
191
+ * @param beneficiary
192
+ * @param lockingIds
193
+ * @param network network is a optional.
194
+ * @return RepuationRewardForBatch
195
+ */
196
+ public redeem ( beneficiary : Address , lockingIds : number [ ] , ct4rRedeemerAddress ?: Address ) : Operation < any > {
152
197
const mapReceipt = ( receipt : any ) => {
153
198
return receipt
154
199
}
155
200
156
- const observable = from ( this . getContract ( ) )
201
+ const ctl4rReedeems : any = [ ]
202
+ for ( const lockingId of lockingIds ) {
203
+ ctl4rReedeems . push ( { beneficiary, id : lockingId . toString ( ) } )
204
+ }
205
+
206
+ const observable = from ( this . getCT4RRedeemer ( ct4rRedeemerAddress ? ct4rRedeemerAddress : CT4RRedeemerAddress ) )
157
207
. pipe (
158
208
concatMap ( ( contract ) => {
159
209
let transaction : any
160
- transaction = contract . methods . redeem (
161
- beneficiary ,
162
- lockingId
210
+ transaction = contract . methods . redeemContinuousLocking4Reputation (
211
+ ( this . scheme . staticState as any ) . address ,
212
+ ctl4rReedeems
163
213
)
164
214
const errorHandler = async ( error : Error ) => {
165
215
try {
@@ -176,12 +226,20 @@ export class CL4RScheme {
176
226
}
177
227
178
228
public async getContract ( ) {
179
- const state = await this . scheme . fetchStaticState ( )
229
+ const address = await this . getContractAddress ( )
180
230
await this . scheme . context . fetchContractInfos ( { fetchPolicy : 'network-only' } )
181
- const contract = this . scheme . context . getContract ( state . address )
231
+ const contract = this . scheme . context . getContract ( address )
182
232
return contract
183
233
}
184
234
235
+ public async getContractAddress ( ) {
236
+ return ( await this . scheme . fetchStaticState ( ) ) . address
237
+ }
238
+
239
+ public async getCT4RRedeemer ( ct4rRedeemerAddress ?: Address ) {
240
+ return await new this . scheme . context . web3 . eth . Contract ( CT4RRedeemerABI , ct4rRedeemerAddress )
241
+ }
242
+
185
243
public getScheme ( ) {
186
244
return this . scheme
187
245
}
0 commit comments