@locuschain/lib 0.0.10 → 0.0.12
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/support/index.amd.js +1 -1
- package/dist/support/index.cjs.js +0 -1
- package/dist/support/index.esm.js +0 -1
- package/dist/web3/index.amd.js +45 -12
- package/dist/web3/index.cjs.js +44 -12
- package/dist/web3/index.esm.js +44 -12
- package/package.json +2 -2
- package/dist/index.esm-BKiWMQOK.js +0 -22
- package/dist/index.esm-BRidcUfn.js +0 -20
- package/dist/index.esm-DDuzXjei.js +0 -18
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
define(['exports', '../index-Byqx0KIO', '
|
|
1
|
+
define(['exports', '../index-Byqx0KIO', 'lodash', '../address-class-Dp7aNQb2'], (function (exports, utils$2, _, addressClass) { 'use strict';
|
|
2
2
|
|
|
3
3
|
function _interopNamespaceDefault(e) {
|
|
4
4
|
var n = Object.create(null);
|
package/dist/web3/index.amd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
define(['exports', '../index-Byqx0KIO', '../tx-type-BeeK7Ci3', '../
|
|
1
|
+
define(['exports', '../index-Byqx0KIO', '../tx-type-BeeK7Ci3', '../address-class-Dp7aNQb2', 'lodash'], (function (exports, utils, txType, addressClass, _) { 'use strict';
|
|
2
2
|
|
|
3
3
|
class Account {
|
|
4
4
|
constructor({ address, nsk }) {
|
|
@@ -80,6 +80,39 @@ define(['exports', '../index-Byqx0KIO', '../tx-type-BeeK7Ci3', '../index.esm-BKi
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
const LocusErrorCode = Object.freeze({
|
|
84
|
+
// RPC
|
|
85
|
+
RPC_ERROR: -32e3,
|
|
86
|
+
// LIB
|
|
87
|
+
NETWORK_ABORTED: 'NETWORK_ABORTED',
|
|
88
|
+
NETWORK_TIMEOUT: 'NETWORK_TIMEOUT',
|
|
89
|
+
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
90
|
+
REQUIRE_ACCOUNT: 'REQUIRE_ACCOUNT',
|
|
91
|
+
RUNTIME_ERROR: 'RUNTIME_ERROR',
|
|
92
|
+
// WALLET
|
|
93
|
+
INTERNAL_ERROR: 1000,
|
|
94
|
+
BY_USER: 1001,
|
|
95
|
+
REQUIRE_OPENACCOUNT: 1002,
|
|
96
|
+
DUPLICATED: 1003,
|
|
97
|
+
NOTFOUND: 1004,
|
|
98
|
+
INVALID_PARAM: 1005,
|
|
99
|
+
REQUIRE_LOGIN: 1006,
|
|
100
|
+
REQUIRE_CONNECT: 1007,
|
|
101
|
+
INVALID_RPC_URL: 1008,
|
|
102
|
+
CALL_RPC_ERROR: 1009,
|
|
103
|
+
NO_SELECTED_NETWORK: 1010,
|
|
104
|
+
KEY_SIGN_FAILED: 1011,
|
|
105
|
+
INVALID_NETWORK: 1012,
|
|
106
|
+
INVALID_ADDRESS: 1013,
|
|
107
|
+
});
|
|
108
|
+
class LocusError extends Error {
|
|
109
|
+
constructor(code, message) {
|
|
110
|
+
super(message);
|
|
111
|
+
this.code = code;
|
|
112
|
+
this.message = message;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
83
116
|
class RpcProvider extends utils.Rpc {
|
|
84
117
|
constructor() {
|
|
85
118
|
super(...arguments);
|
|
@@ -108,7 +141,7 @@ define(['exports', '../index-Byqx0KIO', '../tx-type-BeeK7Ci3', '../index.esm-BKi
|
|
|
108
141
|
request(cmd, params, rpcOption) {
|
|
109
142
|
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
110
143
|
if (this.getSignal().aborted) {
|
|
111
|
-
throw new
|
|
144
|
+
throw new LocusError(LocusErrorCode.ABORTED, `rpc aborted by user`);
|
|
112
145
|
}
|
|
113
146
|
if (this.id === Number.MAX_SAFE_INTEGER) {
|
|
114
147
|
this.id = 0;
|
|
@@ -124,18 +157,18 @@ define(['exports', '../index-Byqx0KIO', '../tx-type-BeeK7Ci3', '../index.esm-BKi
|
|
|
124
157
|
const callRpc1Signal = this.getSignal();
|
|
125
158
|
const rpc1Result = yield this.callRpc(data, { signal: callRpc1Signal, headersInit: options.headersInit });
|
|
126
159
|
if (callRpc1Signal.aborted) {
|
|
127
|
-
throw new
|
|
160
|
+
throw new LocusError(LocusErrorCode.ABORTED, `rpc aborted by user`);
|
|
128
161
|
}
|
|
129
162
|
if (!utils.TX_CREATION_RPC_LIST.some(str => str === cmd)) {
|
|
130
163
|
return rpc1Result;
|
|
131
164
|
}
|
|
132
165
|
if (!this.accountProvider)
|
|
133
|
-
throw new
|
|
166
|
+
throw new LocusError(LocusErrorCode.REQUIRE_ACCOUNT, 'No accounts found. Please add an account before tx creation.');
|
|
134
167
|
// rpc1Result가 T(제네릭)이므로 'in' 연산자 사용을 위해 any로 캐스팅하여 체크합니다.
|
|
135
168
|
const txResult = rpc1Result;
|
|
136
169
|
if (!txResult || typeof txResult !== 'object' || !('hash' in txResult) || !('tx' in txResult)) {
|
|
137
170
|
// console.warn('rpcResul1>>', txResult)
|
|
138
|
-
throw new
|
|
171
|
+
throw new LocusError(LocusErrorCode.REQUIRE_ACCOUNT, 'Invalid transaction creation result.');
|
|
139
172
|
}
|
|
140
173
|
// console.debug('rpcResul1>>', txResult)
|
|
141
174
|
const additionalParams = yield this.accountProvider.signTx(txResult, params, options.address);
|
|
@@ -143,15 +176,15 @@ define(['exports', '../index-Byqx0KIO', '../tx-type-BeeK7Ci3', '../index.esm-BKi
|
|
|
143
176
|
const callRpc2Signal = this.getSignal();
|
|
144
177
|
const rpcResul2 = yield this.callRpc(newData, { signal: callRpc2Signal, headersInit: options.headersInit });
|
|
145
178
|
if (callRpc2Signal.aborted) {
|
|
146
|
-
throw new
|
|
179
|
+
throw new LocusError(LocusErrorCode.ABORTED, `rpc aborted by user`);
|
|
147
180
|
}
|
|
148
181
|
return rpcResul2;
|
|
149
182
|
// console.debug('rpcResul2', rpcResult2)
|
|
150
183
|
}
|
|
151
184
|
catch (err) {
|
|
152
|
-
if (err.code ===
|
|
185
|
+
if (err.code === LocusErrorCode.ABORTED)
|
|
153
186
|
throw err;
|
|
154
|
-
throw new
|
|
187
|
+
throw new LocusError(LocusErrorCode.RUNTIME_ERROR, err.message);
|
|
155
188
|
// console.trace(err)
|
|
156
189
|
// console.log(err.stack);
|
|
157
190
|
}
|
|
@@ -171,7 +204,7 @@ define(['exports', '../index-Byqx0KIO', '../tx-type-BeeK7Ci3', '../index.esm-BKi
|
|
|
171
204
|
// console.debug('params', data)
|
|
172
205
|
var _a;
|
|
173
206
|
if ((_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
174
|
-
throw new
|
|
207
|
+
throw new LocusError(LocusErrorCode.NETWORK_ABORTED, `rpc aborted by user`);
|
|
175
208
|
}
|
|
176
209
|
try {
|
|
177
210
|
const res = yield fetch(this.rpcUrl, {
|
|
@@ -181,16 +214,16 @@ define(['exports', '../index-Byqx0KIO', '../tx-type-BeeK7Ci3', '../index.esm-BKi
|
|
|
181
214
|
signal: options === null || options === void 0 ? void 0 : options.signal
|
|
182
215
|
});
|
|
183
216
|
if (!res.ok)
|
|
184
|
-
throw new
|
|
217
|
+
throw new LocusError(LocusErrorCode.NETWORK_ERROR, `node response http status : ${res.status}`);
|
|
185
218
|
const response = yield res.json();
|
|
186
219
|
if (response.error) {
|
|
187
220
|
const { code, message } = response.error;
|
|
188
|
-
throw new
|
|
221
|
+
throw new LocusError(message === 'timeout error' ? LocusErrorCode.NETWORK_TIMEOUT : code, message);
|
|
189
222
|
}
|
|
190
223
|
return response.result;
|
|
191
224
|
}
|
|
192
225
|
catch (err) {
|
|
193
|
-
throw new
|
|
226
|
+
throw new LocusError(err.name === 'TimeoutError' ? LocusErrorCode.NETWORK_TIMEOUT : LocusErrorCode.RUNTIME_ERROR, err.message);
|
|
194
227
|
}
|
|
195
228
|
});
|
|
196
229
|
}
|
package/dist/web3/index.cjs.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var utils = require('../index-Cg0xnkC2.js');
|
|
4
4
|
var txType = require('../tx-type-jR5Owltc.js');
|
|
5
|
-
var index_esm = require('../index.esm-BRidcUfn.js');
|
|
6
5
|
require('../address-class-Cjy48Uqk.js');
|
|
7
6
|
require('lodash');
|
|
8
7
|
|
|
@@ -86,6 +85,39 @@ class AccountProvider {
|
|
|
86
85
|
}
|
|
87
86
|
}
|
|
88
87
|
|
|
88
|
+
const LocusErrorCode = Object.freeze({
|
|
89
|
+
// RPC
|
|
90
|
+
RPC_ERROR: -32e3,
|
|
91
|
+
// LIB
|
|
92
|
+
NETWORK_ABORTED: 'NETWORK_ABORTED',
|
|
93
|
+
NETWORK_TIMEOUT: 'NETWORK_TIMEOUT',
|
|
94
|
+
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
95
|
+
REQUIRE_ACCOUNT: 'REQUIRE_ACCOUNT',
|
|
96
|
+
RUNTIME_ERROR: 'RUNTIME_ERROR',
|
|
97
|
+
// WALLET
|
|
98
|
+
INTERNAL_ERROR: 1000,
|
|
99
|
+
BY_USER: 1001,
|
|
100
|
+
REQUIRE_OPENACCOUNT: 1002,
|
|
101
|
+
DUPLICATED: 1003,
|
|
102
|
+
NOTFOUND: 1004,
|
|
103
|
+
INVALID_PARAM: 1005,
|
|
104
|
+
REQUIRE_LOGIN: 1006,
|
|
105
|
+
REQUIRE_CONNECT: 1007,
|
|
106
|
+
INVALID_RPC_URL: 1008,
|
|
107
|
+
CALL_RPC_ERROR: 1009,
|
|
108
|
+
NO_SELECTED_NETWORK: 1010,
|
|
109
|
+
KEY_SIGN_FAILED: 1011,
|
|
110
|
+
INVALID_NETWORK: 1012,
|
|
111
|
+
INVALID_ADDRESS: 1013,
|
|
112
|
+
});
|
|
113
|
+
class LocusError extends Error {
|
|
114
|
+
constructor(code, message) {
|
|
115
|
+
super(message);
|
|
116
|
+
this.code = code;
|
|
117
|
+
this.message = message;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
89
121
|
class RpcProvider extends utils.Rpc {
|
|
90
122
|
constructor() {
|
|
91
123
|
super(...arguments);
|
|
@@ -114,7 +146,7 @@ class RpcProvider extends utils.Rpc {
|
|
|
114
146
|
request(cmd, params, rpcOption) {
|
|
115
147
|
return utils.__awaiter(this, void 0, void 0, function* () {
|
|
116
148
|
if (this.getSignal().aborted) {
|
|
117
|
-
throw new
|
|
149
|
+
throw new LocusError(LocusErrorCode.ABORTED, `rpc aborted by user`);
|
|
118
150
|
}
|
|
119
151
|
if (this.id === Number.MAX_SAFE_INTEGER) {
|
|
120
152
|
this.id = 0;
|
|
@@ -130,18 +162,18 @@ class RpcProvider extends utils.Rpc {
|
|
|
130
162
|
const callRpc1Signal = this.getSignal();
|
|
131
163
|
const rpc1Result = yield this.callRpc(data, { signal: callRpc1Signal, headersInit: options.headersInit });
|
|
132
164
|
if (callRpc1Signal.aborted) {
|
|
133
|
-
throw new
|
|
165
|
+
throw new LocusError(LocusErrorCode.ABORTED, `rpc aborted by user`);
|
|
134
166
|
}
|
|
135
167
|
if (!utils.TX_CREATION_RPC_LIST.some(str => str === cmd)) {
|
|
136
168
|
return rpc1Result;
|
|
137
169
|
}
|
|
138
170
|
if (!this.accountProvider)
|
|
139
|
-
throw new
|
|
171
|
+
throw new LocusError(LocusErrorCode.REQUIRE_ACCOUNT, 'No accounts found. Please add an account before tx creation.');
|
|
140
172
|
// rpc1Result가 T(제네릭)이므로 'in' 연산자 사용을 위해 any로 캐스팅하여 체크합니다.
|
|
141
173
|
const txResult = rpc1Result;
|
|
142
174
|
if (!txResult || typeof txResult !== 'object' || !('hash' in txResult) || !('tx' in txResult)) {
|
|
143
175
|
// console.warn('rpcResul1>>', txResult)
|
|
144
|
-
throw new
|
|
176
|
+
throw new LocusError(LocusErrorCode.REQUIRE_ACCOUNT, 'Invalid transaction creation result.');
|
|
145
177
|
}
|
|
146
178
|
// console.debug('rpcResul1>>', txResult)
|
|
147
179
|
const additionalParams = yield this.accountProvider.signTx(txResult, params, options.address);
|
|
@@ -149,15 +181,15 @@ class RpcProvider extends utils.Rpc {
|
|
|
149
181
|
const callRpc2Signal = this.getSignal();
|
|
150
182
|
const rpcResul2 = yield this.callRpc(newData, { signal: callRpc2Signal, headersInit: options.headersInit });
|
|
151
183
|
if (callRpc2Signal.aborted) {
|
|
152
|
-
throw new
|
|
184
|
+
throw new LocusError(LocusErrorCode.ABORTED, `rpc aborted by user`);
|
|
153
185
|
}
|
|
154
186
|
return rpcResul2;
|
|
155
187
|
// console.debug('rpcResul2', rpcResult2)
|
|
156
188
|
}
|
|
157
189
|
catch (err) {
|
|
158
|
-
if (err.code ===
|
|
190
|
+
if (err.code === LocusErrorCode.ABORTED)
|
|
159
191
|
throw err;
|
|
160
|
-
throw new
|
|
192
|
+
throw new LocusError(LocusErrorCode.RUNTIME_ERROR, err.message);
|
|
161
193
|
// console.trace(err)
|
|
162
194
|
// console.log(err.stack);
|
|
163
195
|
}
|
|
@@ -177,7 +209,7 @@ class HttpRpcProvider extends RpcProvider {
|
|
|
177
209
|
// console.debug('params', data)
|
|
178
210
|
var _a;
|
|
179
211
|
if ((_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
180
|
-
throw new
|
|
212
|
+
throw new LocusError(LocusErrorCode.NETWORK_ABORTED, `rpc aborted by user`);
|
|
181
213
|
}
|
|
182
214
|
try {
|
|
183
215
|
const res = yield fetch(this.rpcUrl, {
|
|
@@ -187,16 +219,16 @@ class HttpRpcProvider extends RpcProvider {
|
|
|
187
219
|
signal: options === null || options === void 0 ? void 0 : options.signal
|
|
188
220
|
});
|
|
189
221
|
if (!res.ok)
|
|
190
|
-
throw new
|
|
222
|
+
throw new LocusError(LocusErrorCode.NETWORK_ERROR, `node response http status : ${res.status}`);
|
|
191
223
|
const response = yield res.json();
|
|
192
224
|
if (response.error) {
|
|
193
225
|
const { code, message } = response.error;
|
|
194
|
-
throw new
|
|
226
|
+
throw new LocusError(message === 'timeout error' ? LocusErrorCode.NETWORK_TIMEOUT : code, message);
|
|
195
227
|
}
|
|
196
228
|
return response.result;
|
|
197
229
|
}
|
|
198
230
|
catch (err) {
|
|
199
|
-
throw new
|
|
231
|
+
throw new LocusError(err.name === 'TimeoutError' ? LocusErrorCode.NETWORK_TIMEOUT : LocusErrorCode.RUNTIME_ERROR, err.message);
|
|
200
232
|
}
|
|
201
233
|
});
|
|
202
234
|
}
|
package/dist/web3/index.esm.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { s as sign, _ as __awaiter, v as verifyTxParams, R as Rpc, T as TX_CREATION_RPC_LIST } from '../index-BQ0aTXY5.js';
|
|
2
2
|
import { T as TxType } from '../tx-type-nyLU5xv5.js';
|
|
3
|
-
import { R as RpcError, a as RpcErrorCode } from '../index.esm-DDuzXjei.js';
|
|
4
3
|
import '../address-class-CHAZYhdZ.js';
|
|
5
4
|
import 'lodash';
|
|
6
5
|
|
|
@@ -84,6 +83,39 @@ class AccountProvider {
|
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
|
|
86
|
+
const LocusErrorCode = Object.freeze({
|
|
87
|
+
// RPC
|
|
88
|
+
RPC_ERROR: -32e3,
|
|
89
|
+
// LIB
|
|
90
|
+
NETWORK_ABORTED: 'NETWORK_ABORTED',
|
|
91
|
+
NETWORK_TIMEOUT: 'NETWORK_TIMEOUT',
|
|
92
|
+
NETWORK_ERROR: 'NETWORK_ERROR',
|
|
93
|
+
REQUIRE_ACCOUNT: 'REQUIRE_ACCOUNT',
|
|
94
|
+
RUNTIME_ERROR: 'RUNTIME_ERROR',
|
|
95
|
+
// WALLET
|
|
96
|
+
INTERNAL_ERROR: 1000,
|
|
97
|
+
BY_USER: 1001,
|
|
98
|
+
REQUIRE_OPENACCOUNT: 1002,
|
|
99
|
+
DUPLICATED: 1003,
|
|
100
|
+
NOTFOUND: 1004,
|
|
101
|
+
INVALID_PARAM: 1005,
|
|
102
|
+
REQUIRE_LOGIN: 1006,
|
|
103
|
+
REQUIRE_CONNECT: 1007,
|
|
104
|
+
INVALID_RPC_URL: 1008,
|
|
105
|
+
CALL_RPC_ERROR: 1009,
|
|
106
|
+
NO_SELECTED_NETWORK: 1010,
|
|
107
|
+
KEY_SIGN_FAILED: 1011,
|
|
108
|
+
INVALID_NETWORK: 1012,
|
|
109
|
+
INVALID_ADDRESS: 1013,
|
|
110
|
+
});
|
|
111
|
+
class LocusError extends Error {
|
|
112
|
+
constructor(code, message) {
|
|
113
|
+
super(message);
|
|
114
|
+
this.code = code;
|
|
115
|
+
this.message = message;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
87
119
|
class RpcProvider extends Rpc {
|
|
88
120
|
constructor() {
|
|
89
121
|
super(...arguments);
|
|
@@ -112,7 +144,7 @@ class RpcProvider extends Rpc {
|
|
|
112
144
|
request(cmd, params, rpcOption) {
|
|
113
145
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
146
|
if (this.getSignal().aborted) {
|
|
115
|
-
throw new
|
|
147
|
+
throw new LocusError(LocusErrorCode.ABORTED, `rpc aborted by user`);
|
|
116
148
|
}
|
|
117
149
|
if (this.id === Number.MAX_SAFE_INTEGER) {
|
|
118
150
|
this.id = 0;
|
|
@@ -128,18 +160,18 @@ class RpcProvider extends Rpc {
|
|
|
128
160
|
const callRpc1Signal = this.getSignal();
|
|
129
161
|
const rpc1Result = yield this.callRpc(data, { signal: callRpc1Signal, headersInit: options.headersInit });
|
|
130
162
|
if (callRpc1Signal.aborted) {
|
|
131
|
-
throw new
|
|
163
|
+
throw new LocusError(LocusErrorCode.ABORTED, `rpc aborted by user`);
|
|
132
164
|
}
|
|
133
165
|
if (!TX_CREATION_RPC_LIST.some(str => str === cmd)) {
|
|
134
166
|
return rpc1Result;
|
|
135
167
|
}
|
|
136
168
|
if (!this.accountProvider)
|
|
137
|
-
throw new
|
|
169
|
+
throw new LocusError(LocusErrorCode.REQUIRE_ACCOUNT, 'No accounts found. Please add an account before tx creation.');
|
|
138
170
|
// rpc1Result가 T(제네릭)이므로 'in' 연산자 사용을 위해 any로 캐스팅하여 체크합니다.
|
|
139
171
|
const txResult = rpc1Result;
|
|
140
172
|
if (!txResult || typeof txResult !== 'object' || !('hash' in txResult) || !('tx' in txResult)) {
|
|
141
173
|
// console.warn('rpcResul1>>', txResult)
|
|
142
|
-
throw new
|
|
174
|
+
throw new LocusError(LocusErrorCode.REQUIRE_ACCOUNT, 'Invalid transaction creation result.');
|
|
143
175
|
}
|
|
144
176
|
// console.debug('rpcResul1>>', txResult)
|
|
145
177
|
const additionalParams = yield this.accountProvider.signTx(txResult, params, options.address);
|
|
@@ -147,15 +179,15 @@ class RpcProvider extends Rpc {
|
|
|
147
179
|
const callRpc2Signal = this.getSignal();
|
|
148
180
|
const rpcResul2 = yield this.callRpc(newData, { signal: callRpc2Signal, headersInit: options.headersInit });
|
|
149
181
|
if (callRpc2Signal.aborted) {
|
|
150
|
-
throw new
|
|
182
|
+
throw new LocusError(LocusErrorCode.ABORTED, `rpc aborted by user`);
|
|
151
183
|
}
|
|
152
184
|
return rpcResul2;
|
|
153
185
|
// console.debug('rpcResul2', rpcResult2)
|
|
154
186
|
}
|
|
155
187
|
catch (err) {
|
|
156
|
-
if (err.code ===
|
|
188
|
+
if (err.code === LocusErrorCode.ABORTED)
|
|
157
189
|
throw err;
|
|
158
|
-
throw new
|
|
190
|
+
throw new LocusError(LocusErrorCode.RUNTIME_ERROR, err.message);
|
|
159
191
|
// console.trace(err)
|
|
160
192
|
// console.log(err.stack);
|
|
161
193
|
}
|
|
@@ -175,7 +207,7 @@ class HttpRpcProvider extends RpcProvider {
|
|
|
175
207
|
// console.debug('params', data)
|
|
176
208
|
var _a;
|
|
177
209
|
if ((_a = options === null || options === void 0 ? void 0 : options.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
178
|
-
throw new
|
|
210
|
+
throw new LocusError(LocusErrorCode.NETWORK_ABORTED, `rpc aborted by user`);
|
|
179
211
|
}
|
|
180
212
|
try {
|
|
181
213
|
const res = yield fetch(this.rpcUrl, {
|
|
@@ -185,16 +217,16 @@ class HttpRpcProvider extends RpcProvider {
|
|
|
185
217
|
signal: options === null || options === void 0 ? void 0 : options.signal
|
|
186
218
|
});
|
|
187
219
|
if (!res.ok)
|
|
188
|
-
throw new
|
|
220
|
+
throw new LocusError(LocusErrorCode.NETWORK_ERROR, `node response http status : ${res.status}`);
|
|
189
221
|
const response = yield res.json();
|
|
190
222
|
if (response.error) {
|
|
191
223
|
const { code, message } = response.error;
|
|
192
|
-
throw new
|
|
224
|
+
throw new LocusError(message === 'timeout error' ? LocusErrorCode.NETWORK_TIMEOUT : code, message);
|
|
193
225
|
}
|
|
194
226
|
return response.result;
|
|
195
227
|
}
|
|
196
228
|
catch (err) {
|
|
197
|
-
throw new
|
|
229
|
+
throw new LocusError(err.name === 'TimeoutError' ? LocusErrorCode.NETWORK_TIMEOUT : LocusErrorCode.RUNTIME_ERROR, err.message);
|
|
198
230
|
}
|
|
199
231
|
});
|
|
200
232
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@locuschain/lib",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "bloomtechnology",
|
|
6
6
|
"license": "MIT",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"lodash": "^4.17.21",
|
|
72
72
|
"wasm-opt": "^1.4.0",
|
|
73
|
-
"@locuschain/errors": "1.0.
|
|
73
|
+
"@locuschain/errors": "1.0.7"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
76
|
"generate-code": "generate-code.sh",
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
define(['exports'], (function (exports) { 'use strict';
|
|
2
|
-
|
|
3
|
-
exports.RpcErrorCode = void 0;
|
|
4
|
-
(function (RpcErrorCode) {
|
|
5
|
-
RpcErrorCode["ERROR"] = "LOCUSLIB_ERROR";
|
|
6
|
-
RpcErrorCode["RUNTIME_ERROR"] = "LOCUSLIB_RUNTIME_ERROR";
|
|
7
|
-
RpcErrorCode["NET_ERROR"] = "LOCUSLIB_NET_ERROR";
|
|
8
|
-
RpcErrorCode["TIMEOUT"] = "LOCUSLIB_TIMEOUT";
|
|
9
|
-
RpcErrorCode["ABORTED"] = "LOCUSLIB_ABORTED";
|
|
10
|
-
RpcErrorCode["REQUIRE_ACCOUNT"] = "LOCUSLIB_REQUIRE_ACCOUNT";
|
|
11
|
-
})(exports.RpcErrorCode || (exports.RpcErrorCode = {}));
|
|
12
|
-
class RpcError extends Error {
|
|
13
|
-
constructor(code, message) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.code = code;
|
|
16
|
-
this.message = message;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.RpcError = RpcError;
|
|
21
|
-
|
|
22
|
-
}));
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
exports.RpcErrorCode = void 0;
|
|
4
|
-
(function (RpcErrorCode) {
|
|
5
|
-
RpcErrorCode["ERROR"] = "LOCUSLIB_ERROR";
|
|
6
|
-
RpcErrorCode["RUNTIME_ERROR"] = "LOCUSLIB_RUNTIME_ERROR";
|
|
7
|
-
RpcErrorCode["NET_ERROR"] = "LOCUSLIB_NET_ERROR";
|
|
8
|
-
RpcErrorCode["TIMEOUT"] = "LOCUSLIB_TIMEOUT";
|
|
9
|
-
RpcErrorCode["ABORTED"] = "LOCUSLIB_ABORTED";
|
|
10
|
-
RpcErrorCode["REQUIRE_ACCOUNT"] = "LOCUSLIB_REQUIRE_ACCOUNT";
|
|
11
|
-
})(exports.RpcErrorCode || (exports.RpcErrorCode = {}));
|
|
12
|
-
class RpcError extends Error {
|
|
13
|
-
constructor(code, message) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.code = code;
|
|
16
|
-
this.message = message;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.RpcError = RpcError;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
var RpcErrorCode;
|
|
2
|
-
(function (RpcErrorCode) {
|
|
3
|
-
RpcErrorCode["ERROR"] = "LOCUSLIB_ERROR";
|
|
4
|
-
RpcErrorCode["RUNTIME_ERROR"] = "LOCUSLIB_RUNTIME_ERROR";
|
|
5
|
-
RpcErrorCode["NET_ERROR"] = "LOCUSLIB_NET_ERROR";
|
|
6
|
-
RpcErrorCode["TIMEOUT"] = "LOCUSLIB_TIMEOUT";
|
|
7
|
-
RpcErrorCode["ABORTED"] = "LOCUSLIB_ABORTED";
|
|
8
|
-
RpcErrorCode["REQUIRE_ACCOUNT"] = "LOCUSLIB_REQUIRE_ACCOUNT";
|
|
9
|
-
})(RpcErrorCode || (RpcErrorCode = {}));
|
|
10
|
-
class RpcError extends Error {
|
|
11
|
-
constructor(code, message) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.code = code;
|
|
14
|
-
this.message = message;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { RpcError as R, RpcErrorCode as a };
|