@locuschain/lib 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/web3/index.amd.js
CHANGED
|
@@ -89,8 +89,22 @@ define(['exports', '../index-BzbudoD7', '../tx-type-BeeK7Ci3', '../rpc-error-CIW
|
|
|
89
89
|
setAccountProvider(accountProvider) {
|
|
90
90
|
this.accountProvider = accountProvider;
|
|
91
91
|
}
|
|
92
|
+
abort() {
|
|
93
|
+
var _a;
|
|
94
|
+
if (!((_a = this.rpcOptions) === null || _a === void 0 ? void 0 : _a.abortController))
|
|
95
|
+
return false;
|
|
96
|
+
this.rpcOptions.abortController.abort();
|
|
97
|
+
this.rpcOptions = Object.assign(Object.assign({}, this.rpcOptions), { abortController: new AbortController() });
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
92
100
|
request(cmd, params, rpcOption) {
|
|
93
101
|
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
var _a;
|
|
103
|
+
const callRpcOptions = Object.assign(Object.assign({}, this.rpcOptions), rpcOption);
|
|
104
|
+
const signal = AbortSignal.any(((_a = callRpcOptions === null || callRpcOptions === void 0 ? void 0 : callRpcOptions.abortController) === null || _a === void 0 ? void 0 : _a.signal) ? [callRpcOptions.abortController.signal, AbortSignal.timeout(30000)] : [AbortSignal.timeout(30000)]);
|
|
105
|
+
if (signal.aborted) {
|
|
106
|
+
throw new rpcError.RpcError(rpcError.RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
107
|
+
}
|
|
94
108
|
const id = ++this.id;
|
|
95
109
|
const data = {
|
|
96
110
|
id,
|
|
@@ -99,8 +113,7 @@ define(['exports', '../index-BzbudoD7', '../tx-type-BeeK7Ci3', '../rpc-error-CIW
|
|
|
99
113
|
params
|
|
100
114
|
};
|
|
101
115
|
try {
|
|
102
|
-
const
|
|
103
|
-
const rpc1Result = yield this.callRpc(data, callRpcOptions);
|
|
116
|
+
const rpc1Result = yield this.callRpc(data, { signal, headersInit: callRpcOptions.headersInit });
|
|
104
117
|
if (!utils.TX_CREATION_RPC_LIST.includes(cmd))
|
|
105
118
|
return rpc1Result;
|
|
106
119
|
if (!this.accountProvider)
|
|
@@ -120,7 +133,7 @@ define(['exports', '../index-BzbudoD7', '../tx-type-BeeK7Ci3', '../rpc-error-CIW
|
|
|
120
133
|
}
|
|
121
134
|
catch (err) {
|
|
122
135
|
// console.trace(err)
|
|
123
|
-
console.log(err.stack);
|
|
136
|
+
// console.log(err.stack);
|
|
124
137
|
throw new rpcError.RpcError(rpcError.RpcErrorCode.RUNTIME_ERROR, err.message);
|
|
125
138
|
}
|
|
126
139
|
});
|
|
@@ -138,16 +151,17 @@ define(['exports', '../index-BzbudoD7', '../tx-type-BeeK7Ci3', '../rpc-error-CIW
|
|
|
138
151
|
callRpc(data, options) {
|
|
139
152
|
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
140
153
|
// console.debug('params', data)
|
|
141
|
-
|
|
154
|
+
var _a;
|
|
155
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
156
|
+
throw new rpcError.RpcError(rpcError.RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
157
|
+
}
|
|
142
158
|
try {
|
|
143
159
|
const res = yield fetch(this.rpcUrl, {
|
|
144
160
|
method: 'POST',
|
|
145
161
|
headers: Object.assign({ Accept: 'application/json, text/plain', 'Content-Type': 'application/json;charset=UTF-8' }, options === null || options === void 0 ? void 0 : options.headersInit),
|
|
146
162
|
body: JSON.stringify(data),
|
|
147
|
-
signal
|
|
163
|
+
signal: options === null || options === void 0 ? void 0 : options.signal
|
|
148
164
|
});
|
|
149
|
-
if (signal.aborted)
|
|
150
|
-
throw new rpcError.RpcError(rpcError.RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
151
165
|
if (!res.ok)
|
|
152
166
|
throw new rpcError.RpcError(rpcError.RpcErrorCode.NET_ERROR, `node response http status : ${res.status}`);
|
|
153
167
|
const response = yield res.json();
|
|
@@ -180,6 +194,8 @@ define(['exports', '../index-BzbudoD7', '../tx-type-BeeK7Ci3', '../rpc-error-CIW
|
|
|
180
194
|
}
|
|
181
195
|
setRpcOptions(rpcOptions) {
|
|
182
196
|
this.rpcOptions = rpcOptions;
|
|
197
|
+
if (this.rpcProvider)
|
|
198
|
+
this.rpcProvider.rpcOptions = Object.assign(Object.assign({}, this.rpcOptions), rpcOptions);
|
|
183
199
|
}
|
|
184
200
|
set provider(param) {
|
|
185
201
|
this.setProvider(param);
|
package/dist/web3/index.cjs.js
CHANGED
|
@@ -95,8 +95,22 @@ class RpcProvider extends utils.Rpc {
|
|
|
95
95
|
setAccountProvider(accountProvider) {
|
|
96
96
|
this.accountProvider = accountProvider;
|
|
97
97
|
}
|
|
98
|
+
abort() {
|
|
99
|
+
var _a;
|
|
100
|
+
if (!((_a = this.rpcOptions) === null || _a === void 0 ? void 0 : _a.abortController))
|
|
101
|
+
return false;
|
|
102
|
+
this.rpcOptions.abortController.abort();
|
|
103
|
+
this.rpcOptions = Object.assign(Object.assign({}, this.rpcOptions), { abortController: new AbortController() });
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
98
106
|
request(cmd, params, rpcOption) {
|
|
99
107
|
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
var _a;
|
|
109
|
+
const callRpcOptions = Object.assign(Object.assign({}, this.rpcOptions), rpcOption);
|
|
110
|
+
const signal = AbortSignal.any(((_a = callRpcOptions === null || callRpcOptions === void 0 ? void 0 : callRpcOptions.abortController) === null || _a === void 0 ? void 0 : _a.signal) ? [callRpcOptions.abortController.signal, AbortSignal.timeout(30000)] : [AbortSignal.timeout(30000)]);
|
|
111
|
+
if (signal.aborted) {
|
|
112
|
+
throw new rpcError.RpcError(rpcError.RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
113
|
+
}
|
|
100
114
|
const id = ++this.id;
|
|
101
115
|
const data = {
|
|
102
116
|
id,
|
|
@@ -105,8 +119,7 @@ class RpcProvider extends utils.Rpc {
|
|
|
105
119
|
params
|
|
106
120
|
};
|
|
107
121
|
try {
|
|
108
|
-
const
|
|
109
|
-
const rpc1Result = yield this.callRpc(data, callRpcOptions);
|
|
122
|
+
const rpc1Result = yield this.callRpc(data, { signal, headersInit: callRpcOptions.headersInit });
|
|
110
123
|
if (!utils.TX_CREATION_RPC_LIST.includes(cmd))
|
|
111
124
|
return rpc1Result;
|
|
112
125
|
if (!this.accountProvider)
|
|
@@ -126,7 +139,7 @@ class RpcProvider extends utils.Rpc {
|
|
|
126
139
|
}
|
|
127
140
|
catch (err) {
|
|
128
141
|
// console.trace(err)
|
|
129
|
-
console.log(err.stack);
|
|
142
|
+
// console.log(err.stack);
|
|
130
143
|
throw new rpcError.RpcError(rpcError.RpcErrorCode.RUNTIME_ERROR, err.message);
|
|
131
144
|
}
|
|
132
145
|
});
|
|
@@ -144,16 +157,17 @@ class HttpRpcProvider extends RpcProvider {
|
|
|
144
157
|
callRpc(data, options) {
|
|
145
158
|
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
146
159
|
// console.debug('params', data)
|
|
147
|
-
|
|
160
|
+
var _a;
|
|
161
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
162
|
+
throw new rpcError.RpcError(rpcError.RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
163
|
+
}
|
|
148
164
|
try {
|
|
149
165
|
const res = yield fetch(this.rpcUrl, {
|
|
150
166
|
method: 'POST',
|
|
151
167
|
headers: Object.assign({ Accept: 'application/json, text/plain', 'Content-Type': 'application/json;charset=UTF-8' }, options === null || options === void 0 ? void 0 : options.headersInit),
|
|
152
168
|
body: JSON.stringify(data),
|
|
153
|
-
signal
|
|
169
|
+
signal: options === null || options === void 0 ? void 0 : options.signal
|
|
154
170
|
});
|
|
155
|
-
if (signal.aborted)
|
|
156
|
-
throw new rpcError.RpcError(rpcError.RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
157
171
|
if (!res.ok)
|
|
158
172
|
throw new rpcError.RpcError(rpcError.RpcErrorCode.NET_ERROR, `node response http status : ${res.status}`);
|
|
159
173
|
const response = yield res.json();
|
|
@@ -186,6 +200,8 @@ class Web3 {
|
|
|
186
200
|
}
|
|
187
201
|
setRpcOptions(rpcOptions) {
|
|
188
202
|
this.rpcOptions = rpcOptions;
|
|
203
|
+
if (this.rpcProvider)
|
|
204
|
+
this.rpcProvider.rpcOptions = Object.assign(Object.assign({}, this.rpcOptions), rpcOptions);
|
|
189
205
|
}
|
|
190
206
|
set provider(param) {
|
|
191
207
|
this.setProvider(param);
|
package/dist/web3/index.esm.js
CHANGED
|
@@ -93,8 +93,22 @@ class RpcProvider extends Rpc {
|
|
|
93
93
|
setAccountProvider(accountProvider) {
|
|
94
94
|
this.accountProvider = accountProvider;
|
|
95
95
|
}
|
|
96
|
+
abort() {
|
|
97
|
+
var _a;
|
|
98
|
+
if (!((_a = this.rpcOptions) === null || _a === void 0 ? void 0 : _a.abortController))
|
|
99
|
+
return false;
|
|
100
|
+
this.rpcOptions.abortController.abort();
|
|
101
|
+
this.rpcOptions = Object.assign(Object.assign({}, this.rpcOptions), { abortController: new AbortController() });
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
96
104
|
request(cmd, params, rpcOption) {
|
|
97
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
var _a;
|
|
107
|
+
const callRpcOptions = Object.assign(Object.assign({}, this.rpcOptions), rpcOption);
|
|
108
|
+
const signal = AbortSignal.any(((_a = callRpcOptions === null || callRpcOptions === void 0 ? void 0 : callRpcOptions.abortController) === null || _a === void 0 ? void 0 : _a.signal) ? [callRpcOptions.abortController.signal, AbortSignal.timeout(30000)] : [AbortSignal.timeout(30000)]);
|
|
109
|
+
if (signal.aborted) {
|
|
110
|
+
throw new RpcError(RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
111
|
+
}
|
|
98
112
|
const id = ++this.id;
|
|
99
113
|
const data = {
|
|
100
114
|
id,
|
|
@@ -103,8 +117,7 @@ class RpcProvider extends Rpc {
|
|
|
103
117
|
params
|
|
104
118
|
};
|
|
105
119
|
try {
|
|
106
|
-
const
|
|
107
|
-
const rpc1Result = yield this.callRpc(data, callRpcOptions);
|
|
120
|
+
const rpc1Result = yield this.callRpc(data, { signal, headersInit: callRpcOptions.headersInit });
|
|
108
121
|
if (!TX_CREATION_RPC_LIST.includes(cmd))
|
|
109
122
|
return rpc1Result;
|
|
110
123
|
if (!this.accountProvider)
|
|
@@ -124,7 +137,7 @@ class RpcProvider extends Rpc {
|
|
|
124
137
|
}
|
|
125
138
|
catch (err) {
|
|
126
139
|
// console.trace(err)
|
|
127
|
-
console.log(err.stack);
|
|
140
|
+
// console.log(err.stack);
|
|
128
141
|
throw new RpcError(RpcErrorCode.RUNTIME_ERROR, err.message);
|
|
129
142
|
}
|
|
130
143
|
});
|
|
@@ -142,16 +155,17 @@ class HttpRpcProvider extends RpcProvider {
|
|
|
142
155
|
callRpc(data, options) {
|
|
143
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
157
|
// console.debug('params', data)
|
|
145
|
-
|
|
158
|
+
var _a;
|
|
159
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
160
|
+
throw new RpcError(RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
161
|
+
}
|
|
146
162
|
try {
|
|
147
163
|
const res = yield fetch(this.rpcUrl, {
|
|
148
164
|
method: 'POST',
|
|
149
165
|
headers: Object.assign({ Accept: 'application/json, text/plain', 'Content-Type': 'application/json;charset=UTF-8' }, options === null || options === void 0 ? void 0 : options.headersInit),
|
|
150
166
|
body: JSON.stringify(data),
|
|
151
|
-
signal
|
|
167
|
+
signal: options === null || options === void 0 ? void 0 : options.signal
|
|
152
168
|
});
|
|
153
|
-
if (signal.aborted)
|
|
154
|
-
throw new RpcError(RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
155
169
|
if (!res.ok)
|
|
156
170
|
throw new RpcError(RpcErrorCode.NET_ERROR, `node response http status : ${res.status}`);
|
|
157
171
|
const response = yield res.json();
|
|
@@ -184,6 +198,8 @@ class Web3 {
|
|
|
184
198
|
}
|
|
185
199
|
setRpcOptions(rpcOptions) {
|
|
186
200
|
this.rpcOptions = rpcOptions;
|
|
201
|
+
if (this.rpcProvider)
|
|
202
|
+
this.rpcProvider.rpcOptions = Object.assign(Object.assign({}, this.rpcOptions), rpcOptions);
|
|
187
203
|
}
|
|
188
204
|
set provider(param) {
|
|
189
205
|
this.setProvider(param);
|
|
@@ -10,5 +10,6 @@ export declare abstract class RpcProvider extends Rpc {
|
|
|
10
10
|
abstract callRpc<T>(data: any, options?: CallRpcOptions): Promise<T>;
|
|
11
11
|
abstract get rpcUrl(): string;
|
|
12
12
|
setAccountProvider(accountProvider: AccountProvider): void;
|
|
13
|
+
abort(): boolean;
|
|
13
14
|
request<T, M extends Web3APIMethod<RpcApiSpec> = any>(cmd: M, params: Web3APIParams<RpcApiSpec, M>, rpcOption?: RpcOptions): Promise<T>;
|
|
14
15
|
}
|
|
@@ -2,11 +2,11 @@ import { RpcApiSpec } from "../../autogen/rpc-api-spec.mts";
|
|
|
2
2
|
export type RpcOptions = {
|
|
3
3
|
address?: string;
|
|
4
4
|
headersInit?: HeadersInit;
|
|
5
|
-
|
|
5
|
+
abortController?: AbortController;
|
|
6
6
|
};
|
|
7
7
|
export type CallRpcOptions = {
|
|
8
8
|
headersInit?: HeadersInit;
|
|
9
|
-
|
|
9
|
+
signal?: AbortSignal;
|
|
10
10
|
};
|
|
11
11
|
export type Web3APIMethod<T extends RpcApiSpec> = (keyof T & string);
|
|
12
12
|
export type Web3APIParams<API extends RpcApiSpec, Method extends Web3APIMethod<API>> = API[Method] extends (...args: any) => any ? Parameters<API[Method]> : any[];
|