@@ -42,33 +42,36 @@ export class RpcChannel {
42
42
43
43
public headers : object ;
44
44
45
- readonly retries : number ;
46
-
47
45
public requestId : number ;
48
46
49
47
readonly blockIdentifier : BlockIdentifier ;
50
48
49
+ readonly retries : number ;
50
+
51
+ readonly waitMode : boolean ; // behave like web2 rpc and return when tx is processed
52
+
51
53
private chainId ?: StarknetChainId ;
52
54
53
55
private specVersion ?: string ;
54
56
55
57
private transactionRetryIntervalFallback ?: number ;
56
58
57
- readonly waitMode : Boolean ; // behave like web2 rpc and return when tx is processed
58
-
59
59
private batchClient ?: BatchClient ;
60
60
61
+ private baseFetch : NonNullable < RpcProviderOptions [ 'baseFetch' ] > ;
62
+
61
63
constructor ( optionsOrProvider ?: RpcProviderOptions ) {
62
64
const {
63
- nodeUrl,
64
- retries,
65
- headers,
65
+ baseFetch,
66
+ batch,
66
67
blockIdentifier,
67
68
chainId,
69
+ headers,
70
+ nodeUrl,
71
+ retries,
68
72
specVersion,
69
- waitMode,
70
73
transactionRetryIntervalFallback,
71
- batch ,
74
+ waitMode ,
72
75
} = optionsOrProvider || { } ;
73
76
if ( Object . values ( NetworkName ) . includes ( nodeUrl as NetworkName ) ) {
74
77
this . nodeUrl = getDefaultNodeUrl ( nodeUrl as NetworkName , optionsOrProvider ?. default ) ;
@@ -77,20 +80,23 @@ export class RpcChannel {
77
80
} else {
78
81
this . nodeUrl = getDefaultNodeUrl ( undefined , optionsOrProvider ?. default ) ;
79
82
}
80
- this . retries = retries || defaultOptions . retries ;
81
- this . headers = { ...defaultOptions . headers , ...headers } ;
82
- this . blockIdentifier = blockIdentifier || defaultOptions . blockIdentifier ;
83
+ this . baseFetch = baseFetch ?? fetch ;
84
+ this . blockIdentifier = blockIdentifier ?? defaultOptions . blockIdentifier ;
83
85
this . chainId = chainId ;
86
+ this . headers = { ...defaultOptions . headers , ...headers } ;
87
+ this . retries = retries ?? defaultOptions . retries ;
84
88
this . specVersion = specVersion ;
85
- this . waitMode = waitMode || false ;
86
- this . requestId = 0 ;
87
89
this . transactionRetryIntervalFallback = transactionRetryIntervalFallback ;
90
+ this . waitMode = waitMode ?? false ;
91
+
92
+ this . requestId = 0 ;
88
93
89
94
if ( typeof batch === 'number' ) {
90
95
this . batchClient = new BatchClient ( {
91
96
nodeUrl : this . nodeUrl ,
92
97
headers : this . headers ,
93
98
interval : batch ,
99
+ baseFetch : this . baseFetch ,
94
100
} ) ;
95
101
}
96
102
}
@@ -110,7 +116,7 @@ export class RpcChannel {
110
116
method,
111
117
...( params && { params } ) ,
112
118
} ;
113
- return fetch ( this . nodeUrl , {
119
+ return this . baseFetch ( this . nodeUrl , {
114
120
method : 'POST' ,
115
121
body : stringify ( rpcRequestBody ) ,
116
122
headers : this . headers as Record < string , string > ,
0 commit comments