@locuschain/lib 0.0.7 → 0.0.8
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 +33 -12
- package/dist/web3/index.cjs.js +33 -12
- package/dist/web3/index.esm.js +33 -12
- package/dist/web3/providers/rpc-provider.d.mts +5 -4
- package/package.json +1 -1
package/dist/web3/index.amd.js
CHANGED
|
@@ -97,24 +97,39 @@ define(['exports', '../index-BkQ38g4T', '../tx-type-BeeK7Ci3', '../rpc-error-CIW
|
|
|
97
97
|
this.rpcOptions = Object.assign(Object.assign({}, this.rpcOptions), { abortController: new AbortController() });
|
|
98
98
|
return true;
|
|
99
99
|
}
|
|
100
|
+
getSignal(rpcOption) {
|
|
101
|
+
var _a, _b;
|
|
102
|
+
const controller = (_a = rpcOption === null || rpcOption === void 0 ? void 0 : rpcOption.abortController) !== null && _a !== void 0 ? _a : (_b = this.rpcOptions) === null || _b === void 0 ? void 0 : _b.abortController;
|
|
103
|
+
const signals = [AbortSignal.timeout(30000)];
|
|
104
|
+
if (controller) {
|
|
105
|
+
signals.push(controller.signal);
|
|
106
|
+
}
|
|
107
|
+
return AbortSignal.any(signals);
|
|
108
|
+
}
|
|
100
109
|
request(cmd, params, rpcOption) {
|
|
101
110
|
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
|
|
103
|
-
const signal = AbortSignal.any(callRpcOptions.abortController ? [callRpcOptions.abortController.signal, AbortSignal.timeout(30000)] : [AbortSignal.timeout(30000)]);
|
|
104
|
-
if (signal.aborted) {
|
|
111
|
+
if (this.getSignal().aborted) {
|
|
105
112
|
throw new rpcError.RpcError(rpcError.RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
106
113
|
}
|
|
107
|
-
|
|
114
|
+
if (this.id === Number.MAX_SAFE_INTEGER) {
|
|
115
|
+
this.id = 0;
|
|
116
|
+
}
|
|
108
117
|
const data = {
|
|
109
|
-
id,
|
|
118
|
+
id: ++this.id,
|
|
110
119
|
jsonrpc: '2.0',
|
|
111
120
|
method: cmd,
|
|
112
121
|
params
|
|
113
122
|
};
|
|
114
123
|
try {
|
|
115
|
-
const
|
|
116
|
-
|
|
124
|
+
const options = Object.assign(Object.assign({}, this.rpcOptions), rpcOption);
|
|
125
|
+
const callRpc1Signal = this.getSignal();
|
|
126
|
+
const rpc1Result = yield this.callRpc(data, { signal: callRpc1Signal, headersInit: options.headersInit });
|
|
127
|
+
if (callRpc1Signal.aborted) {
|
|
128
|
+
throw new rpcError.RpcError(rpcError.RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
129
|
+
}
|
|
130
|
+
if (!utils.TX_CREATION_RPC_LIST.includes(cmd)) {
|
|
117
131
|
return rpc1Result;
|
|
132
|
+
}
|
|
118
133
|
if (!this.accountProvider)
|
|
119
134
|
throw new rpcError.RpcError(rpcError.RpcErrorCode.REQUIRE_ACCOUNT, 'No accounts found. Please add an account before tx creation.');
|
|
120
135
|
// rpc1Result가 T(제네릭)이므로 'in' 연산자 사용을 위해 any로 캐스팅하여 체크합니다.
|
|
@@ -124,16 +139,22 @@ define(['exports', '../index-BkQ38g4T', '../tx-type-BeeK7Ci3', '../rpc-error-CIW
|
|
|
124
139
|
throw new rpcError.RpcError(rpcError.RpcErrorCode.REQUIRE_ACCOUNT, 'Invalid transaction creation result.');
|
|
125
140
|
}
|
|
126
141
|
// console.debug('rpcResul1>>', txResult)
|
|
127
|
-
const additionalParams = yield this.accountProvider.signTx(txResult, params,
|
|
128
|
-
const newData = Object.assign(Object.assign({}, data), { params: params.map((p, idx) => (idx === 0 ? Object.assign(Object.assign({}, p), additionalParams) : p)) });
|
|
129
|
-
const
|
|
142
|
+
const additionalParams = yield this.accountProvider.signTx(txResult, params, options.address);
|
|
143
|
+
const newData = Object.assign(Object.assign({}, data), { id: ++this.id, params: params.map((p, idx) => (idx === 0 ? Object.assign(Object.assign({}, p), additionalParams) : p)) });
|
|
144
|
+
const callRpc2Signal = this.getSignal();
|
|
145
|
+
const rpcResul2 = yield this.callRpc(newData, { signal: callRpc2Signal, headersInit: options.headersInit });
|
|
146
|
+
if (callRpc2Signal.aborted) {
|
|
147
|
+
throw new rpcError.RpcError(rpcError.RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
148
|
+
}
|
|
149
|
+
return rpcResul2;
|
|
130
150
|
// console.debug('rpcResul2', rpcResult2)
|
|
131
|
-
return rpcResult2;
|
|
132
151
|
}
|
|
133
152
|
catch (err) {
|
|
153
|
+
if (err.code === rpcError.RpcErrorCode.ABORTED)
|
|
154
|
+
throw err;
|
|
155
|
+
throw new rpcError.RpcError(rpcError.RpcErrorCode.RUNTIME_ERROR, err.message);
|
|
134
156
|
// console.trace(err)
|
|
135
157
|
// console.log(err.stack);
|
|
136
|
-
throw new rpcError.RpcError(rpcError.RpcErrorCode.RUNTIME_ERROR, err.message);
|
|
137
158
|
}
|
|
138
159
|
});
|
|
139
160
|
}
|
package/dist/web3/index.cjs.js
CHANGED
|
@@ -103,24 +103,39 @@ class RpcProvider extends utils.Rpc {
|
|
|
103
103
|
this.rpcOptions = Object.assign(Object.assign({}, this.rpcOptions), { abortController: new AbortController() });
|
|
104
104
|
return true;
|
|
105
105
|
}
|
|
106
|
+
getSignal(rpcOption) {
|
|
107
|
+
var _a, _b;
|
|
108
|
+
const controller = (_a = rpcOption === null || rpcOption === void 0 ? void 0 : rpcOption.abortController) !== null && _a !== void 0 ? _a : (_b = this.rpcOptions) === null || _b === void 0 ? void 0 : _b.abortController;
|
|
109
|
+
const signals = [AbortSignal.timeout(30000)];
|
|
110
|
+
if (controller) {
|
|
111
|
+
signals.push(controller.signal);
|
|
112
|
+
}
|
|
113
|
+
return AbortSignal.any(signals);
|
|
114
|
+
}
|
|
106
115
|
request(cmd, params, rpcOption) {
|
|
107
116
|
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
|
|
109
|
-
const signal = AbortSignal.any(callRpcOptions.abortController ? [callRpcOptions.abortController.signal, AbortSignal.timeout(30000)] : [AbortSignal.timeout(30000)]);
|
|
110
|
-
if (signal.aborted) {
|
|
117
|
+
if (this.getSignal().aborted) {
|
|
111
118
|
throw new rpcError.RpcError(rpcError.RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
112
119
|
}
|
|
113
|
-
|
|
120
|
+
if (this.id === Number.MAX_SAFE_INTEGER) {
|
|
121
|
+
this.id = 0;
|
|
122
|
+
}
|
|
114
123
|
const data = {
|
|
115
|
-
id,
|
|
124
|
+
id: ++this.id,
|
|
116
125
|
jsonrpc: '2.0',
|
|
117
126
|
method: cmd,
|
|
118
127
|
params
|
|
119
128
|
};
|
|
120
129
|
try {
|
|
121
|
-
const
|
|
122
|
-
|
|
130
|
+
const options = Object.assign(Object.assign({}, this.rpcOptions), rpcOption);
|
|
131
|
+
const callRpc1Signal = this.getSignal();
|
|
132
|
+
const rpc1Result = yield this.callRpc(data, { signal: callRpc1Signal, headersInit: options.headersInit });
|
|
133
|
+
if (callRpc1Signal.aborted) {
|
|
134
|
+
throw new rpcError.RpcError(rpcError.RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
135
|
+
}
|
|
136
|
+
if (!utils.TX_CREATION_RPC_LIST.includes(cmd)) {
|
|
123
137
|
return rpc1Result;
|
|
138
|
+
}
|
|
124
139
|
if (!this.accountProvider)
|
|
125
140
|
throw new rpcError.RpcError(rpcError.RpcErrorCode.REQUIRE_ACCOUNT, 'No accounts found. Please add an account before tx creation.');
|
|
126
141
|
// rpc1Result가 T(제네릭)이므로 'in' 연산자 사용을 위해 any로 캐스팅하여 체크합니다.
|
|
@@ -130,16 +145,22 @@ class RpcProvider extends utils.Rpc {
|
|
|
130
145
|
throw new rpcError.RpcError(rpcError.RpcErrorCode.REQUIRE_ACCOUNT, 'Invalid transaction creation result.');
|
|
131
146
|
}
|
|
132
147
|
// console.debug('rpcResul1>>', txResult)
|
|
133
|
-
const additionalParams = yield this.accountProvider.signTx(txResult, params,
|
|
134
|
-
const newData = Object.assign(Object.assign({}, data), { params: params.map((p, idx) => (idx === 0 ? Object.assign(Object.assign({}, p), additionalParams) : p)) });
|
|
135
|
-
const
|
|
148
|
+
const additionalParams = yield this.accountProvider.signTx(txResult, params, options.address);
|
|
149
|
+
const newData = Object.assign(Object.assign({}, data), { id: ++this.id, params: params.map((p, idx) => (idx === 0 ? Object.assign(Object.assign({}, p), additionalParams) : p)) });
|
|
150
|
+
const callRpc2Signal = this.getSignal();
|
|
151
|
+
const rpcResul2 = yield this.callRpc(newData, { signal: callRpc2Signal, headersInit: options.headersInit });
|
|
152
|
+
if (callRpc2Signal.aborted) {
|
|
153
|
+
throw new rpcError.RpcError(rpcError.RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
154
|
+
}
|
|
155
|
+
return rpcResul2;
|
|
136
156
|
// console.debug('rpcResul2', rpcResult2)
|
|
137
|
-
return rpcResult2;
|
|
138
157
|
}
|
|
139
158
|
catch (err) {
|
|
159
|
+
if (err.code === rpcError.RpcErrorCode.ABORTED)
|
|
160
|
+
throw err;
|
|
161
|
+
throw new rpcError.RpcError(rpcError.RpcErrorCode.RUNTIME_ERROR, err.message);
|
|
140
162
|
// console.trace(err)
|
|
141
163
|
// console.log(err.stack);
|
|
142
|
-
throw new rpcError.RpcError(rpcError.RpcErrorCode.RUNTIME_ERROR, err.message);
|
|
143
164
|
}
|
|
144
165
|
});
|
|
145
166
|
}
|
package/dist/web3/index.esm.js
CHANGED
|
@@ -101,24 +101,39 @@ class RpcProvider extends Rpc {
|
|
|
101
101
|
this.rpcOptions = Object.assign(Object.assign({}, this.rpcOptions), { abortController: new AbortController() });
|
|
102
102
|
return true;
|
|
103
103
|
}
|
|
104
|
+
getSignal(rpcOption) {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
const controller = (_a = rpcOption === null || rpcOption === void 0 ? void 0 : rpcOption.abortController) !== null && _a !== void 0 ? _a : (_b = this.rpcOptions) === null || _b === void 0 ? void 0 : _b.abortController;
|
|
107
|
+
const signals = [AbortSignal.timeout(30000)];
|
|
108
|
+
if (controller) {
|
|
109
|
+
signals.push(controller.signal);
|
|
110
|
+
}
|
|
111
|
+
return AbortSignal.any(signals);
|
|
112
|
+
}
|
|
104
113
|
request(cmd, params, rpcOption) {
|
|
105
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
|
|
107
|
-
const signal = AbortSignal.any(callRpcOptions.abortController ? [callRpcOptions.abortController.signal, AbortSignal.timeout(30000)] : [AbortSignal.timeout(30000)]);
|
|
108
|
-
if (signal.aborted) {
|
|
115
|
+
if (this.getSignal().aborted) {
|
|
109
116
|
throw new RpcError(RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
110
117
|
}
|
|
111
|
-
|
|
118
|
+
if (this.id === Number.MAX_SAFE_INTEGER) {
|
|
119
|
+
this.id = 0;
|
|
120
|
+
}
|
|
112
121
|
const data = {
|
|
113
|
-
id,
|
|
122
|
+
id: ++this.id,
|
|
114
123
|
jsonrpc: '2.0',
|
|
115
124
|
method: cmd,
|
|
116
125
|
params
|
|
117
126
|
};
|
|
118
127
|
try {
|
|
119
|
-
const
|
|
120
|
-
|
|
128
|
+
const options = Object.assign(Object.assign({}, this.rpcOptions), rpcOption);
|
|
129
|
+
const callRpc1Signal = this.getSignal();
|
|
130
|
+
const rpc1Result = yield this.callRpc(data, { signal: callRpc1Signal, headersInit: options.headersInit });
|
|
131
|
+
if (callRpc1Signal.aborted) {
|
|
132
|
+
throw new RpcError(RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
133
|
+
}
|
|
134
|
+
if (!TX_CREATION_RPC_LIST.includes(cmd)) {
|
|
121
135
|
return rpc1Result;
|
|
136
|
+
}
|
|
122
137
|
if (!this.accountProvider)
|
|
123
138
|
throw new RpcError(RpcErrorCode.REQUIRE_ACCOUNT, 'No accounts found. Please add an account before tx creation.');
|
|
124
139
|
// rpc1Result가 T(제네릭)이므로 'in' 연산자 사용을 위해 any로 캐스팅하여 체크합니다.
|
|
@@ -128,16 +143,22 @@ class RpcProvider extends Rpc {
|
|
|
128
143
|
throw new RpcError(RpcErrorCode.REQUIRE_ACCOUNT, 'Invalid transaction creation result.');
|
|
129
144
|
}
|
|
130
145
|
// console.debug('rpcResul1>>', txResult)
|
|
131
|
-
const additionalParams = yield this.accountProvider.signTx(txResult, params,
|
|
132
|
-
const newData = Object.assign(Object.assign({}, data), { params: params.map((p, idx) => (idx === 0 ? Object.assign(Object.assign({}, p), additionalParams) : p)) });
|
|
133
|
-
const
|
|
146
|
+
const additionalParams = yield this.accountProvider.signTx(txResult, params, options.address);
|
|
147
|
+
const newData = Object.assign(Object.assign({}, data), { id: ++this.id, params: params.map((p, idx) => (idx === 0 ? Object.assign(Object.assign({}, p), additionalParams) : p)) });
|
|
148
|
+
const callRpc2Signal = this.getSignal();
|
|
149
|
+
const rpcResul2 = yield this.callRpc(newData, { signal: callRpc2Signal, headersInit: options.headersInit });
|
|
150
|
+
if (callRpc2Signal.aborted) {
|
|
151
|
+
throw new RpcError(RpcErrorCode.ABORTED, `rpc aborted by user`);
|
|
152
|
+
}
|
|
153
|
+
return rpcResul2;
|
|
134
154
|
// console.debug('rpcResul2', rpcResult2)
|
|
135
|
-
return rpcResult2;
|
|
136
155
|
}
|
|
137
156
|
catch (err) {
|
|
157
|
+
if (err.code === RpcErrorCode.ABORTED)
|
|
158
|
+
throw err;
|
|
159
|
+
throw new RpcError(RpcErrorCode.RUNTIME_ERROR, err.message);
|
|
138
160
|
// console.trace(err)
|
|
139
161
|
// console.log(err.stack);
|
|
140
|
-
throw new RpcError(RpcErrorCode.RUNTIME_ERROR, err.message);
|
|
141
162
|
}
|
|
142
163
|
});
|
|
143
164
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { RpcApiSpec } from
|
|
2
|
-
import { Rpc } from
|
|
3
|
-
import { CallRpcOptions, RpcOptions, Web3APIMethod, Web3APIParams } from
|
|
4
|
-
import { AccountProvider } from
|
|
1
|
+
import { RpcApiSpec } from '../../autogen/rpc-api-spec.mts';
|
|
2
|
+
import { Rpc } from '../../autogen/rpc.mts';
|
|
3
|
+
import { CallRpcOptions, RpcOptions, Web3APIMethod, Web3APIParams } from '../types/index.mts';
|
|
4
|
+
import { AccountProvider } from './account-provider.mts';
|
|
5
5
|
export declare abstract class RpcProvider extends Rpc {
|
|
6
6
|
id: number;
|
|
7
7
|
rpcOptions?: RpcOptions | undefined;
|
|
@@ -11,5 +11,6 @@ export declare abstract class RpcProvider extends Rpc {
|
|
|
11
11
|
abstract get rpcUrl(): string;
|
|
12
12
|
setAccountProvider(accountProvider: AccountProvider): void;
|
|
13
13
|
abort(): boolean;
|
|
14
|
+
private getSignal;
|
|
14
15
|
request<T, M extends Web3APIMethod<RpcApiSpec> = any>(cmd: M, params: Web3APIParams<RpcApiSpec, M>, rpcOption?: RpcOptions): Promise<T>;
|
|
15
16
|
}
|