1
1
import env from "@/env" ;
2
- import { instance as xTwitterInstance } from "@/integrations/xtwitter" ;
2
+ import { xTwitterInstance } from "@/integrations/xtwitter" ;
3
3
import { log } from "@/logger" ;
4
4
import type { IEvent , IRequestAdded , JsonRpcResponse , ProcessedRequestAdded , RoochNetwork } from "@/types" ;
5
5
import { decodeNotifyValueFull } from "@/util" ;
6
- import { Args , RoochClient , Secp256k1Keypair , Transaction , getRoochNodeUrl } from "@roochnetwork/rooch-sdk" ;
6
+ import {
7
+ Args ,
8
+ RoochClient ,
9
+ RoochWebSocketTransport ,
10
+ Secp256k1Keypair ,
11
+ Transaction ,
12
+ getRoochNodeUrl ,
13
+ } from "@roochnetwork/rooch-sdk" ;
7
14
import axios from "axios" ;
8
15
import prismaClient from "../../prisma" ;
9
16
import { Indexer } from "./base" ;
10
17
11
18
export default class RoochIndexer extends Indexer {
12
19
private keyPair : Secp256k1Keypair ;
20
+ private client : RoochClient ;
13
21
14
22
constructor (
15
23
private privateKey : string ,
@@ -18,6 +26,18 @@ export default class RoochIndexer extends Indexer {
18
26
) {
19
27
super ( oracleAddress , Secp256k1Keypair . fromSecretKey ( privateKey ) . getRoochAddress ( ) . toHexAddress ( ) ) ;
20
28
this . keyPair = Secp256k1Keypair . fromSecretKey ( this . privateKey ) ;
29
+ const wsTransport = new RoochWebSocketTransport ( {
30
+ url : getRoochNodeUrl ( this . chainId ) ,
31
+ reconnectDelay : 1000 , // Delay between reconnection attempts (default: 1000ms)
32
+ maxReconnectAttempts : 5 , // Maximum number of reconnection attempts (default: 5)
33
+ requestTimeout : 30000 , // Request timeout (default: 30000ms)
34
+ connectionReadyTimeout : 5000 , // Connection ready timeout (default: 5000ms)
35
+ } ) ;
36
+
37
+ // Create client with WebSocket transport
38
+ this . client = new RoochClient ( {
39
+ transport : wsTransport ,
40
+ } ) ;
21
41
log . info ( `Rooch Indexer initialized` ) ;
22
42
log . info ( `Chain ID: ${ this . getChainId ( ) } \n\t\tOrchestrator Oracle Node Address: ${ this . orchestrator } ` ) ;
23
43
}
@@ -35,7 +55,7 @@ export default class RoochIndexer extends Indexer {
35
55
*/
36
56
async sendUnfulfilledRequests ( ) {
37
57
// Initialize the Rooch client with the current node URL
38
- const client = new RoochClient ( { url : this . getRoochNodeUrl ( ) } ) ;
58
+ // const _client = new RoochClient({ url: this.getRoochNodeUrl() });
39
59
40
60
// Initialize cursor object for pagination
41
61
const cursor = {
@@ -53,7 +73,7 @@ export default class RoochIndexer extends Indexer {
53
73
while ( cursor . isNextPage ) {
54
74
try {
55
75
// Query for object states with pagination
56
- const query = await client . queryObjectStates ( {
76
+ const query = await this . client . queryObjectStates ( {
57
77
filter : {
58
78
object_type : `${ this . oracleAddress } ::oracles::Request` ,
59
79
} ,
@@ -135,7 +155,7 @@ export default class RoochIndexer extends Indexer {
135
155
}
136
156
137
157
getRoochNodeUrl ( ) {
138
- return this . chainId === "pre-mainnet" ? "https://main-seed.rooch.network" : getRoochNodeUrl ( this . chainId ) ;
158
+ return getRoochNodeUrl ( this . chainId ) ;
139
159
}
140
160
141
161
/**
@@ -216,11 +236,7 @@ export default class RoochIndexer extends Indexer {
216
236
}
217
237
218
238
async isPreviouslyExecuted ( data : ProcessedRequestAdded < any > ) {
219
- const client = new RoochClient ( {
220
- url : this . getRoochNodeUrl ( ) ,
221
- } ) ;
222
-
223
- const view = await client . executeViewFunction ( {
239
+ const view = await this . client . executeViewFunction ( {
224
240
target : `${ this . oracleAddress } ::oracles::get_response_status` ,
225
241
args : [ Args . objectId ( data . request_id ) ] ,
226
242
} ) ;
@@ -240,11 +256,7 @@ export default class RoochIndexer extends Indexer {
240
256
* @returns {Promise<any> } - The receipt of the transaction.
241
257
*/
242
258
async sendFulfillment ( data : ProcessedRequestAdded < any > , status : number , result : string ) {
243
- const client = new RoochClient ( {
244
- url : this . getRoochNodeUrl ( ) ,
245
- } ) ;
246
-
247
- const view = await client . executeViewFunction ( {
259
+ const view = await this . client . executeViewFunction ( {
248
260
target : `${ this . oracleAddress } ::oracles::get_response_status` ,
249
261
args : [ Args . objectId ( data . request_id ) ] ,
250
262
} ) ;
@@ -282,7 +294,7 @@ export default class RoochIndexer extends Indexer {
282
294
283
295
tx . setMaxGas ( 1000000000 ) ;
284
296
285
- const receipt = await client . signAndExecuteTransaction ( {
297
+ const receipt = await this . client . signAndExecuteTransaction ( {
286
298
transaction : tx ,
287
299
signer : this . keyPair ,
288
300
} ) ;
@@ -298,7 +310,7 @@ export default class RoochIndexer extends Indexer {
298
310
} ) ;
299
311
try {
300
312
if ( ( data . notify ?. length ?? 0 ) > 66 ) {
301
- const module_abi = await client . getModuleAbi ( {
313
+ const module_abi = await this . client . getModuleAbi ( {
302
314
moduleAddr : notify_module [ 0 ] ?? "" ,
303
315
moduleName : notify_module [ 1 ] ?? "" ,
304
316
} ) ;
@@ -312,7 +324,7 @@ export default class RoochIndexer extends Indexer {
312
324
args : function_abi ?. params ?. length === 0 ? [ ] : [ Args . objectId ( data . request_id ) ] ,
313
325
} ) ;
314
326
tx . setMaxGas ( 2_0000_0000 ) ;
315
- const notification_receipt = await client . signAndExecuteTransaction ( {
327
+ const notification_receipt = await this . client . signAndExecuteTransaction ( {
316
328
transaction : tx ,
317
329
signer : Secp256k1Keypair . fromSecretKey ( keeper_key . privateKey ) ,
318
330
} ) ;
0 commit comments