@steemit/steem-js 0.7.11 → 0.8.0
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/README.md +22 -3
- package/circle.yml +1 -1
- package/config.json +1 -1
- package/dist/steem-tests.min.js +4097 -23
- package/dist/steem.min.js +2089 -18
- package/docker-webpack.config.js +44 -0
- package/lib/api/index.js +305 -412
- package/lib/api/methods.js +16 -1
- package/lib/api/rpc-auth.js +135 -0
- package/lib/api/transports/base.js +25 -66
- package/lib/api/transports/http.js +114 -129
- package/lib/api/transports/index.js +8 -15
- package/lib/api/transports/ws.js +107 -207
- package/lib/auth/ecc/index.js +9 -9
- package/lib/auth/ecc/src/address.js +48 -78
- package/lib/auth/ecc/src/aes.js +93 -129
- package/lib/auth/ecc/src/brain_key.js +7 -7
- package/lib/auth/ecc/src/ecdsa.js +7 -33
- package/lib/auth/ecc/src/ecsignature.js +4 -30
- package/lib/auth/ecc/src/enforce_types.js +1 -8
- package/lib/auth/ecc/src/hash.js +16 -25
- package/lib/auth/ecc/src/key_private.js +146 -199
- package/lib/auth/ecc/src/key_public.js +130 -202
- package/lib/auth/ecc/src/key_utils.js +64 -106
- package/lib/auth/ecc/src/signature.js +125 -177
- package/lib/auth/index.js +84 -97
- package/lib/auth/memo.js +90 -118
- package/lib/auth/serializer/index.js +12 -18
- package/lib/auth/serializer/src/ChainTypes.js +0 -3
- package/lib/auth/serializer/src/convert.js +29 -32
- package/lib/auth/serializer/src/error_with_cause.js +22 -37
- package/lib/auth/serializer/src/fast_parser.js +54 -74
- package/lib/auth/serializer/src/number_utils.js +30 -54
- package/lib/auth/serializer/src/object_id.js +37 -62
- package/lib/auth/serializer/src/operations.js +597 -689
- package/lib/auth/serializer/src/precision.js +55 -73
- package/lib/auth/serializer/src/serializer.js +158 -204
- package/lib/auth/serializer/src/template.js +13 -8
- package/lib/auth/serializer/src/types.js +949 -1102
- package/lib/auth/serializer/src/validation.js +268 -328
- package/lib/broadcast/helpers.js +61 -98
- package/lib/broadcast/index.js +61 -82
- package/lib/browser.js +15 -19
- package/lib/config.js +16 -38
- package/lib/formatter.js +89 -115
- package/lib/index.js +19 -17
- package/lib/utils.js +4 -9
- package/node-18.dockerfile +28 -0
- package/package.json +62 -38
- package/test/Crypto.js +16 -16
- package/test/KeyFormats.js +1 -1
- package/test/api.test.js +37 -0
- package/test/broadcast.test.js +14 -8
- package/test/comment.test.js +17 -3
- package/test/operations_test.js +1 -1
- package/test/promise-broadcast.test.js +86 -0
- package/test/reputation.test.js +68 -0
- package/test/smt.test.js +10 -10
- package/test-github-workflow.bat +19 -0
- package/test-github-workflow.sh +15 -0
- package/webpack/makeConfig.js +25 -17
- package/.circleci/config.yml +0 -23
- package/dist/statistics.html +0 -208
- package/dist/steem-tests.min.js.gz +0 -0
- package/dist/steem-tests.min.js.map +0 -1
- package/dist/steem.min.js.gz +0 -0
- package/dist/steem.min.js.map +0 -1
- package/lib/auth/ecc/README.md +0 -20
- package/lib/auth/ecc/package.json +0 -36
- package/lib/auth/serializer/README.md +0 -13
- package/lib/auth/serializer/package.json +0 -32
- package/node-4.dockerfile +0 -6
- package/node-6.dockerfile +0 -6
- package/yarn.lock +0 -3336
package/lib/api/methods.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = [{
|
|
7
8
|
"api": "database_api",
|
|
8
9
|
"method": "set_subscribe_callback",
|
|
9
10
|
"params": ["callback", "clearFilter"]
|
|
@@ -410,4 +411,18 @@ exports.default = [{
|
|
|
410
411
|
"api": "condenser_api",
|
|
411
412
|
"method": "get_nai_pool",
|
|
412
413
|
"params": []
|
|
414
|
+
}, {
|
|
415
|
+
"api": "rc_api",
|
|
416
|
+
"method": "find_rc_accounts",
|
|
417
|
+
"params": ["accounts"],
|
|
418
|
+
"is_object": true
|
|
419
|
+
}, {
|
|
420
|
+
"api": "condenser_api",
|
|
421
|
+
"method": "get_expiring_vesting_delegations",
|
|
422
|
+
"params": ["account", "start", "limit"]
|
|
423
|
+
}, {
|
|
424
|
+
"api": "database_api",
|
|
425
|
+
"method": "find_change_recovery_account_requests",
|
|
426
|
+
"params": ["account"],
|
|
427
|
+
"is_object": true
|
|
413
428
|
}];
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.K = void 0;
|
|
7
|
+
exports.sign = sign;
|
|
8
|
+
exports.validate = validate;
|
|
9
|
+
var _crypto = require("crypto");
|
|
10
|
+
var _ecc = require("../auth/ecc");
|
|
11
|
+
/**
|
|
12
|
+
* @file JSONRPC 2.0 request authentication with steem authorities.
|
|
13
|
+
* Based on the original @steemit/rpc-auth package
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Signing constant used to reserve opcode space and prevent cross-protocol attacks.
|
|
18
|
+
* Output of `sha256('steem_jsonrpc_auth')`.
|
|
19
|
+
*/
|
|
20
|
+
const K = exports.K = Buffer.from('3b3b081e46ea808d5a96b08c4bc5003f5e15767090f344faab531ec57565136b', 'hex');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Create request hash to be signed.
|
|
24
|
+
*
|
|
25
|
+
* @param timestamp ISO8601 formatted date e.g. `2017-11-14T19:40:29.077Z`.
|
|
26
|
+
* @param account Steem account name that is the signer.
|
|
27
|
+
* @param method RPC request method.
|
|
28
|
+
* @param params Base64 encoded JSON string containing request params.
|
|
29
|
+
* @param nonce 8 bytes of random data.
|
|
30
|
+
*
|
|
31
|
+
* @returns bytes to be signed or validated.
|
|
32
|
+
*/
|
|
33
|
+
function hashMessage(timestamp, account, method, params, nonce) {
|
|
34
|
+
const first = (0, _crypto.createHash)('sha256');
|
|
35
|
+
first.update(timestamp);
|
|
36
|
+
first.update(account);
|
|
37
|
+
first.update(method);
|
|
38
|
+
first.update(params);
|
|
39
|
+
const second = (0, _crypto.createHash)('sha256');
|
|
40
|
+
second.update(K);
|
|
41
|
+
second.update(first.digest());
|
|
42
|
+
second.update(nonce);
|
|
43
|
+
return second.digest();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Sign a JSON RPC Request.
|
|
48
|
+
*/
|
|
49
|
+
function sign(request, account, keys) {
|
|
50
|
+
if (!request.params) {
|
|
51
|
+
throw new Error('Unable to sign a request without params');
|
|
52
|
+
}
|
|
53
|
+
const params = Buffer.from(JSON.stringify(request.params), 'utf8').toString('base64');
|
|
54
|
+
const nonceBytes = (0, _crypto.randomBytes)(8);
|
|
55
|
+
const nonce = nonceBytes.toString('hex');
|
|
56
|
+
const timestamp = new Date().toISOString();
|
|
57
|
+
const message = hashMessage(timestamp, account, request.method, params, nonceBytes);
|
|
58
|
+
const signatures = [];
|
|
59
|
+
for (let key of keys) {
|
|
60
|
+
if (typeof key === 'string') {
|
|
61
|
+
key = _ecc.PrivateKey.fromString(key);
|
|
62
|
+
}
|
|
63
|
+
const signature = key.sign(message).toHex();
|
|
64
|
+
signatures.push(signature);
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
jsonrpc: '2.0',
|
|
68
|
+
method: request.method,
|
|
69
|
+
id: request.id,
|
|
70
|
+
params: {
|
|
71
|
+
__signed: {
|
|
72
|
+
account,
|
|
73
|
+
nonce,
|
|
74
|
+
params,
|
|
75
|
+
signatures,
|
|
76
|
+
timestamp
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Validate a signed JSON RPC request.
|
|
84
|
+
* Throws a ValidationError if the request fails validation.
|
|
85
|
+
*
|
|
86
|
+
* @returns Resolved request params.
|
|
87
|
+
*/
|
|
88
|
+
async function validate(request, verify) {
|
|
89
|
+
if (request.jsonrpc !== '2.0' || typeof request.method !== 'string') {
|
|
90
|
+
throw new Error('Invalid JSON RPC Request');
|
|
91
|
+
}
|
|
92
|
+
if (request.params == undefined || request.params.__signed == undefined) {
|
|
93
|
+
throw new Error('Signed payload missing');
|
|
94
|
+
}
|
|
95
|
+
if (Object.keys(request.params).length !== 1) {
|
|
96
|
+
throw new Error('Invalid request params');
|
|
97
|
+
}
|
|
98
|
+
const signed = request.params.__signed;
|
|
99
|
+
if (signed.account == undefined) {
|
|
100
|
+
throw new Error('Missing account');
|
|
101
|
+
}
|
|
102
|
+
let params;
|
|
103
|
+
try {
|
|
104
|
+
const jsonString = Buffer.from(signed.params, 'base64').toString('utf8');
|
|
105
|
+
params = JSON.parse(jsonString);
|
|
106
|
+
} catch (cause) {
|
|
107
|
+
throw new Error(`Invalid encoded params: ${cause.message}`);
|
|
108
|
+
}
|
|
109
|
+
if (signed.nonce == undefined || typeof signed.nonce !== 'string') {
|
|
110
|
+
throw new Error('Invalid nonce');
|
|
111
|
+
}
|
|
112
|
+
const nonce = Buffer.from(signed.nonce, 'hex');
|
|
113
|
+
if (nonce.length !== 8) {
|
|
114
|
+
throw new Error('Invalid nonce');
|
|
115
|
+
}
|
|
116
|
+
const timestamp = Date.parse(signed.timestamp);
|
|
117
|
+
if (Number.isNaN(timestamp)) {
|
|
118
|
+
throw new Error('Invalid timestamp');
|
|
119
|
+
}
|
|
120
|
+
if (Date.now() - timestamp > 60 * 1000) {
|
|
121
|
+
throw new Error('Signature expired');
|
|
122
|
+
}
|
|
123
|
+
const message = hashMessage(signed.timestamp, signed.account, request.method, signed.params, nonce);
|
|
124
|
+
try {
|
|
125
|
+
await verify(message, signed.signatures, signed.account);
|
|
126
|
+
} catch (cause) {
|
|
127
|
+
throw new Error(`Verification failed: ${cause.message}`);
|
|
128
|
+
}
|
|
129
|
+
return params;
|
|
130
|
+
}
|
|
131
|
+
var _default = exports.default = {
|
|
132
|
+
sign,
|
|
133
|
+
validate,
|
|
134
|
+
K
|
|
135
|
+
};
|
|
@@ -1,72 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _events2 = _interopRequireDefault(_events);
|
|
16
|
-
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
|
|
19
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
|
-
|
|
21
|
-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
22
|
-
|
|
23
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
24
|
-
|
|
25
|
-
var Transport = function (_EventEmitter) {
|
|
26
|
-
_inherits(Transport, _EventEmitter);
|
|
27
|
-
|
|
28
|
-
function Transport() {
|
|
29
|
-
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
30
|
-
|
|
31
|
-
_classCallCheck(this, Transport);
|
|
32
|
-
|
|
33
|
-
var _this = _possibleConstructorReturn(this, (Transport.__proto__ || Object.getPrototypeOf(Transport)).call(this, options));
|
|
34
|
-
|
|
35
|
-
_this.options = options;
|
|
36
|
-
_this.id = 0;
|
|
37
|
-
return _this;
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _bluebird = _interopRequireDefault(require("bluebird"));
|
|
8
|
+
var _events = _interopRequireDefault(require("events"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
class Transport extends _events.default {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
super(options);
|
|
13
|
+
this.options = options;
|
|
14
|
+
this.id = 0;
|
|
38
15
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}, {
|
|
56
|
-
key: 'send',
|
|
57
|
-
value: function send() {}
|
|
58
|
-
}, {
|
|
59
|
-
key: 'start',
|
|
60
|
-
value: function start() {}
|
|
61
|
-
}, {
|
|
62
|
-
key: 'stop',
|
|
63
|
-
value: function stop() {}
|
|
64
|
-
}]);
|
|
65
|
-
|
|
66
|
-
return Transport;
|
|
67
|
-
}(_events2.default);
|
|
68
|
-
|
|
16
|
+
setOptions(options) {
|
|
17
|
+
Object.assign(this.options, options);
|
|
18
|
+
this.stop();
|
|
19
|
+
}
|
|
20
|
+
listenTo(target, eventName, callback) {
|
|
21
|
+
if (target.addEventListener) target.addEventListener(eventName, callback);else target.on(eventName, callback);
|
|
22
|
+
return () => {
|
|
23
|
+
if (target.removeEventListener) target.removeEventListener(eventName, callback);else target.removeListener(eventName, callback);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
send() {}
|
|
27
|
+
start() {}
|
|
28
|
+
stop() {}
|
|
29
|
+
}
|
|
69
30
|
exports.default = Transport;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
_bluebird2.default.promisifyAll(Transport.prototype);
|
|
31
|
+
_bluebird.default.promisifyAll(Transport.prototype);
|
|
@@ -1,55 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
8
|
-
|
|
6
|
+
exports.default = void 0;
|
|
9
7
|
exports.jsonRpc = jsonRpc;
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var _base = require('./base');
|
|
24
|
-
|
|
25
|
-
var _base2 = _interopRequireDefault(_base);
|
|
26
|
-
|
|
27
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
28
|
-
|
|
29
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
30
|
-
|
|
31
|
-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
32
|
-
|
|
33
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
34
|
-
|
|
35
|
-
var debug = (0, _debug2.default)('steem:http');
|
|
36
|
-
|
|
37
|
-
var RPCError = function (_Error) {
|
|
38
|
-
_inherits(RPCError, _Error);
|
|
39
|
-
|
|
40
|
-
function RPCError(rpcError) {
|
|
41
|
-
_classCallCheck(this, RPCError);
|
|
42
|
-
|
|
43
|
-
var _this = _possibleConstructorReturn(this, (RPCError.__proto__ || Object.getPrototypeOf(RPCError)).call(this, rpcError.message));
|
|
44
|
-
|
|
45
|
-
_this.name = 'RPCError';
|
|
46
|
-
_this.code = rpcError.code;
|
|
47
|
-
_this.data = rpcError.data;
|
|
48
|
-
return _this;
|
|
8
|
+
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
9
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
10
|
+
var _retry = _interopRequireDefault(require("retry"));
|
|
11
|
+
var _base = _interopRequireDefault(require("./base"));
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
const debug = (0, _debug.default)('steem:http');
|
|
14
|
+
class RPCError extends Error {
|
|
15
|
+
constructor(rpcError) {
|
|
16
|
+
super(rpcError.message);
|
|
17
|
+
this.name = 'RPCError';
|
|
18
|
+
this.code = rpcError.code;
|
|
19
|
+
this.data = rpcError.data;
|
|
49
20
|
}
|
|
50
|
-
|
|
51
|
-
return RPCError;
|
|
52
|
-
}(Error);
|
|
21
|
+
}
|
|
53
22
|
|
|
54
23
|
/**
|
|
55
24
|
* Makes a JSON-RPC request using `fetch` or a user-provided `fetchMethod`.
|
|
@@ -61,18 +30,32 @@ var RPCError = function (_Error) {
|
|
|
61
30
|
* @param {function} [options.fetchMethod=fetch] - A function with the same
|
|
62
31
|
* signature as `fetch`, which can be used to make the network request, or for
|
|
63
32
|
* stubbing in tests.
|
|
33
|
+
* @param {number} [options.timeoutMs=30000] - Request timeout in milliseconds.
|
|
64
34
|
*/
|
|
35
|
+
function jsonRpc(uri, {
|
|
36
|
+
method,
|
|
37
|
+
id,
|
|
38
|
+
params,
|
|
39
|
+
fetchMethod = _crossFetch.default,
|
|
40
|
+
timeoutMs = 30000
|
|
41
|
+
}) {
|
|
42
|
+
const payload = {
|
|
43
|
+
id,
|
|
44
|
+
jsonrpc: '2.0',
|
|
45
|
+
method,
|
|
46
|
+
params
|
|
47
|
+
};
|
|
48
|
+
let timeoutId = null;
|
|
49
|
+
|
|
50
|
+
// Create a promise that will reject after the timeout
|
|
51
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
52
|
+
timeoutId = setTimeout(() => {
|
|
53
|
+
reject(new Error(`Request timeout after ${timeoutMs}ms`));
|
|
54
|
+
}, timeoutMs);
|
|
55
|
+
});
|
|
65
56
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
var method = _ref.method,
|
|
69
|
-
id = _ref.id,
|
|
70
|
-
params = _ref.params,
|
|
71
|
-
_ref$fetchMethod = _ref.fetchMethod,
|
|
72
|
-
fetchMethod = _ref$fetchMethod === undefined ? _crossFetch2.default : _ref$fetchMethod;
|
|
73
|
-
|
|
74
|
-
var payload = { id: id, jsonrpc: '2.0', method: method, params: params };
|
|
75
|
-
return fetchMethod(uri, {
|
|
57
|
+
// Create the fetch promise
|
|
58
|
+
const fetchPromise = fetchMethod(uri, {
|
|
76
59
|
body: JSON.stringify(payload),
|
|
77
60
|
method: 'post',
|
|
78
61
|
mode: 'cors',
|
|
@@ -80,93 +63,95 @@ function jsonRpc(uri, _ref) {
|
|
|
80
63
|
Accept: 'application/json, text/plain, */*',
|
|
81
64
|
'Content-Type': 'application/json'
|
|
82
65
|
}
|
|
83
|
-
}).then(
|
|
66
|
+
}).then(res => {
|
|
84
67
|
if (!res.ok) {
|
|
85
|
-
throw new Error(
|
|
68
|
+
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
|
86
69
|
}
|
|
87
70
|
return res.json();
|
|
88
|
-
}).then(
|
|
71
|
+
}).then(rpcRes => {
|
|
89
72
|
if (rpcRes.id !== id) {
|
|
90
|
-
throw new Error(
|
|
73
|
+
throw new Error(`Invalid response id: ${rpcRes.id}`);
|
|
91
74
|
}
|
|
92
75
|
if (rpcRes.error) {
|
|
93
76
|
throw new RPCError(rpcRes.error);
|
|
94
77
|
}
|
|
95
78
|
return rpcRes.result;
|
|
96
79
|
});
|
|
97
|
-
}
|
|
98
80
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
callback(retriable.mainError());
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
} else {
|
|
133
|
-
jsonRpc(this.options.uri, { method: 'call', id: id, params: params, fetchMethod: fetchMethod }).then(function (res) {
|
|
81
|
+
// Race the fetch against the timeout
|
|
82
|
+
return Promise.race([fetchPromise, timeoutPromise]).finally(() => {
|
|
83
|
+
// Clear the timeout to avoid memory leaks
|
|
84
|
+
if (timeoutId) {
|
|
85
|
+
clearTimeout(timeoutId);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
class HttpTransport extends _base.default {
|
|
90
|
+
send(api, data, callback) {
|
|
91
|
+
if (this.options.useAppbaseApi) {
|
|
92
|
+
api = 'condenser_api';
|
|
93
|
+
}
|
|
94
|
+
debug('Steem::send', api, data);
|
|
95
|
+
const id = data.id || this.id++;
|
|
96
|
+
const params = [api, data.method, data.params];
|
|
97
|
+
const retriable = this.retriable(api, data);
|
|
98
|
+
const fetchMethod = this.options.fetchMethod;
|
|
99
|
+
|
|
100
|
+
// Use a longer timeout for broadcast operations (60s) and standard operations (30s)
|
|
101
|
+
const timeoutMs = this.isBroadcastOperation(data.method) ? 60000 : 30000;
|
|
102
|
+
if (retriable) {
|
|
103
|
+
retriable.attempt(currentAttempt => {
|
|
104
|
+
jsonRpc(this.options.uri, {
|
|
105
|
+
method: 'call',
|
|
106
|
+
id,
|
|
107
|
+
params,
|
|
108
|
+
fetchMethod,
|
|
109
|
+
timeoutMs
|
|
110
|
+
}).then(res => {
|
|
134
111
|
callback(null, res);
|
|
135
|
-
},
|
|
136
|
-
|
|
112
|
+
}, err => {
|
|
113
|
+
if (retriable.retry(err)) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
callback(retriable.mainError());
|
|
137
117
|
});
|
|
138
|
-
}
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
jsonRpc(this.options.uri, {
|
|
121
|
+
method: 'call',
|
|
122
|
+
id,
|
|
123
|
+
params,
|
|
124
|
+
fetchMethod,
|
|
125
|
+
timeoutMs
|
|
126
|
+
}).then(res => {
|
|
127
|
+
callback(null, res);
|
|
128
|
+
}, err => {
|
|
129
|
+
callback(err);
|
|
130
|
+
});
|
|
139
131
|
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
}
|
|
133
|
+
isBroadcastOperation(method) {
|
|
134
|
+
return this.nonRetriableOperations.some(op => op === method);
|
|
135
|
+
}
|
|
136
|
+
get nonRetriableOperations() {
|
|
137
|
+
return this.options.nonRetriableOperations || ['broadcast_transaction', 'broadcast_transaction_with_callback', 'broadcast_transaction_synchronous', 'broadcast_block'];
|
|
138
|
+
}
|
|
143
139
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// Otherwise, don't retry.
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
140
|
+
// An object which can be used to track retries.
|
|
141
|
+
retriable(api, data) {
|
|
142
|
+
if (this.isBroadcastOperation(data.method)) {
|
|
143
|
+
// Do not retry if the operation is non-retriable.
|
|
144
|
+
return null;
|
|
145
|
+
} else if (Object(this.options.retry) === this.options.retry) {
|
|
146
|
+
// If `this.options.retry` is a map of options, pass those to operation.
|
|
147
|
+
return _retry.default.operation(this.options.retry);
|
|
148
|
+
} else if (this.options.retry) {
|
|
149
|
+
// If `this.options.retry` is `true`, use default options.
|
|
150
|
+
return _retry.default.operation();
|
|
151
|
+
} else {
|
|
152
|
+
// Otherwise, don't retry.
|
|
153
|
+
return null;
|
|
161
154
|
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
get: function get() {
|
|
165
|
-
return this.options.nonRetriableOperations || ['broadcast_transaction', 'broadcast_transaction_with_callback', 'broadcast_transaction_synchronous', 'broadcast_block'];
|
|
166
|
-
}
|
|
167
|
-
}]);
|
|
168
|
-
|
|
169
|
-
return HttpTransport;
|
|
170
|
-
}(_base2.default);
|
|
171
|
-
|
|
155
|
+
}
|
|
156
|
+
}
|
|
172
157
|
exports.default = HttpTransport;
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
var _http = require(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var _ws2 = _interopRequireDefault(_ws);
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
|
-
exports.default = {
|
|
18
|
-
http: _http2.default,
|
|
19
|
-
ws: _ws2.default
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _http = _interopRequireDefault(require("./http"));
|
|
8
|
+
var _ws = _interopRequireDefault(require("./ws"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
var _default = exports.default = {
|
|
11
|
+
http: _http.default,
|
|
12
|
+
ws: _ws.default
|
|
20
13
|
};
|