@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.
Files changed (74) hide show
  1. package/README.md +22 -3
  2. package/circle.yml +1 -1
  3. package/config.json +1 -1
  4. package/dist/steem-tests.min.js +4097 -23
  5. package/dist/steem.min.js +2089 -18
  6. package/docker-webpack.config.js +44 -0
  7. package/lib/api/index.js +305 -412
  8. package/lib/api/methods.js +16 -1
  9. package/lib/api/rpc-auth.js +135 -0
  10. package/lib/api/transports/base.js +25 -66
  11. package/lib/api/transports/http.js +114 -129
  12. package/lib/api/transports/index.js +8 -15
  13. package/lib/api/transports/ws.js +107 -207
  14. package/lib/auth/ecc/index.js +9 -9
  15. package/lib/auth/ecc/src/address.js +48 -78
  16. package/lib/auth/ecc/src/aes.js +93 -129
  17. package/lib/auth/ecc/src/brain_key.js +7 -7
  18. package/lib/auth/ecc/src/ecdsa.js +7 -33
  19. package/lib/auth/ecc/src/ecsignature.js +4 -30
  20. package/lib/auth/ecc/src/enforce_types.js +1 -8
  21. package/lib/auth/ecc/src/hash.js +16 -25
  22. package/lib/auth/ecc/src/key_private.js +146 -199
  23. package/lib/auth/ecc/src/key_public.js +130 -202
  24. package/lib/auth/ecc/src/key_utils.js +64 -106
  25. package/lib/auth/ecc/src/signature.js +125 -177
  26. package/lib/auth/index.js +84 -97
  27. package/lib/auth/memo.js +90 -118
  28. package/lib/auth/serializer/index.js +12 -18
  29. package/lib/auth/serializer/src/ChainTypes.js +0 -3
  30. package/lib/auth/serializer/src/convert.js +29 -32
  31. package/lib/auth/serializer/src/error_with_cause.js +22 -37
  32. package/lib/auth/serializer/src/fast_parser.js +54 -74
  33. package/lib/auth/serializer/src/number_utils.js +30 -54
  34. package/lib/auth/serializer/src/object_id.js +37 -62
  35. package/lib/auth/serializer/src/operations.js +597 -689
  36. package/lib/auth/serializer/src/precision.js +55 -73
  37. package/lib/auth/serializer/src/serializer.js +158 -204
  38. package/lib/auth/serializer/src/template.js +13 -8
  39. package/lib/auth/serializer/src/types.js +949 -1102
  40. package/lib/auth/serializer/src/validation.js +268 -328
  41. package/lib/broadcast/helpers.js +61 -98
  42. package/lib/broadcast/index.js +61 -82
  43. package/lib/browser.js +15 -19
  44. package/lib/config.js +16 -38
  45. package/lib/formatter.js +89 -115
  46. package/lib/index.js +19 -17
  47. package/lib/utils.js +4 -9
  48. package/node-18.dockerfile +28 -0
  49. package/package.json +62 -38
  50. package/test/Crypto.js +16 -16
  51. package/test/KeyFormats.js +1 -1
  52. package/test/api.test.js +37 -0
  53. package/test/broadcast.test.js +14 -8
  54. package/test/comment.test.js +17 -3
  55. package/test/operations_test.js +1 -1
  56. package/test/promise-broadcast.test.js +86 -0
  57. package/test/reputation.test.js +68 -0
  58. package/test/smt.test.js +10 -10
  59. package/test-github-workflow.bat +19 -0
  60. package/test-github-workflow.sh +15 -0
  61. package/webpack/makeConfig.js +25 -17
  62. package/.circleci/config.yml +0 -23
  63. package/dist/statistics.html +0 -208
  64. package/dist/steem-tests.min.js.gz +0 -0
  65. package/dist/steem-tests.min.js.map +0 -1
  66. package/dist/steem.min.js.gz +0 -0
  67. package/dist/steem.min.js.map +0 -1
  68. package/lib/auth/ecc/README.md +0 -20
  69. package/lib/auth/ecc/package.json +0 -36
  70. package/lib/auth/serializer/README.md +0 -13
  71. package/lib/auth/serializer/package.json +0 -32
  72. package/node-4.dockerfile +0 -6
  73. package/node-6.dockerfile +0 -6
  74. package/yarn.lock +0 -3336
package/lib/api/index.js CHANGED
@@ -1,422 +1,315 @@
1
- 'use strict';
2
-
3
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4
-
5
- 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; }; }();
6
-
7
- var _events = require('events');
8
-
9
- var _events2 = _interopRequireDefault(_events);
10
-
11
- var _bluebird = require('bluebird');
12
-
13
- var _bluebird2 = _interopRequireDefault(_bluebird);
14
-
15
- var _config = require('../config');
16
-
17
- var _config2 = _interopRequireDefault(_config);
18
-
19
- var _methods = require('./methods');
20
-
21
- var _methods2 = _interopRequireDefault(_methods);
22
-
23
- var _transports = require('./transports');
24
-
25
- var _transports2 = _interopRequireDefault(_transports);
26
-
27
- var _utils = require('../utils');
28
-
29
- var _ecc = require('../auth/ecc');
30
-
31
- var _serializer = require('../auth/serializer');
32
-
33
- var _http = require('./transports/http');
34
-
35
- var _rpcAuth = require('@steemit/rpc-auth');
36
-
37
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
-
39
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
40
-
41
- 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; }
42
-
43
- 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; }
44
-
45
- var Steem = function (_EventEmitter) {
46
- _inherits(Steem, _EventEmitter);
47
-
48
- function Steem() {
49
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
50
-
51
- _classCallCheck(this, Steem);
52
-
53
- var _this = _possibleConstructorReturn(this, (Steem.__proto__ || Object.getPrototypeOf(Steem)).call(this, options));
54
-
55
- _this._setTransport(options);
56
- _this._setLogger(options);
57
- _this.options = options;
58
- _this.seqNo = 0; // used for rpc calls
59
- _methods2.default.forEach(function (method) {
60
- var methodName = method.method_name || (0, _utils.camelCase)(method.method);
61
- var methodParams = method.params || [];
62
-
63
- _this[methodName + 'With'] = function (options, callback) {
64
- return _this.send(method.api, {
65
- method: method.method,
66
- params: methodParams.map(function (param) {
67
- return options[param];
68
- })
69
- }, callback);
70
- };
71
-
72
- _this[methodName] = function () {
73
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
74
- args[_key] = arguments[_key];
75
- }
76
-
77
- var options = methodParams.reduce(function (memo, param, i) {
78
- memo[param] = args[i]; // eslint-disable-line no-param-reassign
79
- return memo;
80
- }, {});
81
- var callback = args[methodParams.length];
82
- return _this[methodName + 'With'](options, callback);
83
- };
84
-
85
- _this[methodName + 'WithAsync'] = _bluebird2.default.promisify(_this[methodName + 'With']);
86
- _this[methodName + 'Async'] = _bluebird2.default.promisify(_this[methodName]);
87
- });
88
- _this.callAsync = _bluebird2.default.promisify(_this.call);
89
- _this.signedCallAsync = _bluebird2.default.promisify(_this.signedCall);
90
- return _this;
91
- }
92
-
93
- _createClass(Steem, [{
94
- key: '_setTransport',
95
- value: function _setTransport(options) {
96
- if (options.url && options.url.match('^((http|https)?:\/\/)')) {
97
- options.uri = options.url;
98
- options.transport = 'http';
99
- this._transportType = options.transport;
100
- this.options = options;
101
- this.transport = new _transports2.default.http(options);
102
- } else if (options.url && options.url.match('^((ws|wss)?:\/\/)')) {
103
- options.websocket = options.url;
104
- options.transport = 'ws';
105
- this._transportType = options.transport;
106
- this.options = options;
107
- this.transport = new _transports2.default.ws(options);
108
- } else if (options.transport) {
109
- if (this.transport && this._transportType !== options.transport) {
110
- this.transport.stop();
111
- }
112
-
113
- this._transportType = options.transport;
114
-
115
- if (typeof options.transport === 'string') {
116
- if (!_transports2.default[options.transport]) {
117
- throw new TypeError('Invalid `transport`, valid values are `http`, `ws` or a class');
118
- }
119
- this.transport = new _transports2.default[options.transport](options);
120
- } else {
121
- this.transport = new options.transport(options);
122
- }
123
- } else {
124
- this.transport = new _transports2.default.ws(options);
125
- }
126
- }
127
- }, {
128
- key: '_setLogger',
129
- value: function _setLogger(options) {
130
- if (options.hasOwnProperty('logger')) {
131
- switch (_typeof(options.logger)) {
132
- case 'function':
133
- this.__logger = {
134
- log: options.logger
135
- };
136
- break;
137
- case 'object':
138
- if (typeof options.logger.log !== 'function') {
139
- throw new Error('setOptions({logger:{}}) must have a property .log of type function');
140
- }
141
- this.__logger = options.logger;
142
- break;
143
- case 'undefined':
144
- if (this.__logger) break;
145
- default:
146
- this.__logger = false;
147
- }
148
- }
149
- }
150
- }, {
151
- key: 'log',
152
- value: function log(logLevel) {
153
- if (this.__logger) {
154
- if (arguments.length > 1 && typeof this.__logger[logLevel] === 'function') {
155
- var args = Array.prototype.slice.call(arguments, 1);
156
- this.__logger[logLevel].apply(this.__logger, args);
157
- } else {
158
- this.__logger.log.apply(this.__logger, arguments);
159
- }
160
- }
161
- }
162
- }, {
163
- key: 'start',
164
- value: function start() {
165
- return this.transport.start();
166
- }
167
- }, {
168
- key: 'stop',
169
- value: function stop() {
170
- return this.transport.stop();
171
- }
172
- }, {
173
- key: 'send',
174
- value: function send(api, data, callback) {
175
- var cb = callback;
176
- if (this.__logger) {
177
- var id = Math.random();
178
- var self = this;
179
- this.log('xmit:' + id + ':', data);
180
- cb = function cb(e, d) {
181
- if (e) {
182
- self.log('error', 'rsp:' + id + ':\n\n', e, d);
183
- } else {
184
- self.log('rsp:' + id + ':', d);
185
- }
186
- if (callback) {
187
- callback.apply(self, arguments);
188
- }
189
- };
190
- }
191
- return this.transport.send(api, data, cb);
192
- }
193
- }, {
194
- key: 'call',
195
- value: function call(method, params, callback) {
196
- if (this._transportType !== 'http') {
197
- callback(new Error('RPC methods can only be called when using http transport'));
198
- return;
199
- }
200
- var id = ++this.seqNo;
201
- (0, _http.jsonRpc)(this.options.uri, { method: method, params: params, id: id }).then(function (res) {
202
- callback(null, res);
203
- }, function (err) {
204
- callback(err);
205
- });
206
- }
207
- }, {
208
- key: 'signedCall',
209
- value: function signedCall(method, params, account, key, callback) {
210
- if (this._transportType !== 'http') {
211
- callback(new Error('RPC methods can only be called when using http transport'));
212
- return;
213
- }
214
- var id = ++this.seqNo;
215
- var request = void 0;
216
- try {
217
- request = (0, _rpcAuth.sign)({ method: method, params: params, id: id }, account, [key]);
218
- } catch (error) {
219
- callback(error);
220
- return;
221
- }
222
- (0, _http.jsonRpc)(this.options.uri, request).then(function (res) {
223
- callback(null, res);
224
- }, function (err) {
225
- callback(err);
226
- });
1
+ "use strict";
2
+
3
+ var _events = _interopRequireDefault(require("events"));
4
+ var _bluebird = _interopRequireDefault(require("bluebird"));
5
+ var _config = _interopRequireDefault(require("../config"));
6
+ var _methods = _interopRequireDefault(require("./methods"));
7
+ var _transports = _interopRequireDefault(require("./transports"));
8
+ var _utils = require("../utils");
9
+ var _ecc = require("../auth/ecc");
10
+ var _serializer = require("../auth/serializer");
11
+ var _http = require("./transports/http");
12
+ var _rpcAuth = require("./rpc-auth");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ class Steem extends _events.default {
15
+ constructor(options = {}) {
16
+ super(options);
17
+ this._setTransport(options);
18
+ this._setLogger(options);
19
+ this.options = options;
20
+ this.seqNo = 0; // used for rpc calls
21
+ _methods.default.forEach(method => {
22
+ const methodName = method.method_name || (0, _utils.camelCase)(method.method);
23
+ const methodParams = method.params || [];
24
+ this[`${methodName}With`] = (options, callback) => {
25
+ let params;
26
+ if (!method.is_object) {
27
+ params = methodParams.map(param => options[param]);
28
+ } else {
29
+ params = options;
227
30
  }
228
- }, {
229
- key: 'setOptions',
230
- value: function setOptions(options) {
231
- Object.assign(this.options, options);
232
- this._setLogger(options);
233
- this._setTransport(options);
234
- this.transport.setOptions(options);
235
- if (options.hasOwnProperty('useTestNet')) {
236
- _config2.default.set('address_prefix', options.useTestNet ? 'TST' : 'STM');
237
- }
238
- }
239
- }, {
240
- key: 'setWebSocket',
241
- value: function setWebSocket(url) {
242
- this.setOptions({
243
- websocket: url
244
- });
31
+ return this.send(method.api, {
32
+ method: method.method,
33
+ params: params
34
+ }, callback);
35
+ };
36
+ this[methodName] = (...args) => {
37
+ const options = methodParams.reduce((memo, param, i) => {
38
+ memo[param] = args[i]; // eslint-disable-line no-param-reassign
39
+ return memo;
40
+ }, {});
41
+ const callback = args[methodParams.length];
42
+ return this[`${methodName}With`](options, callback);
43
+ };
44
+ this[`${methodName}WithAsync`] = _bluebird.default.promisify(this[`${methodName}With`]);
45
+ this[`${methodName}Async`] = _bluebird.default.promisify(this[methodName]);
46
+ });
47
+ this.callAsync = _bluebird.default.promisify(this.call);
48
+ this.signedCallAsync = _bluebird.default.promisify(this.signedCall);
49
+ }
50
+ _setTransport(options) {
51
+ if (options.url && options.url.match('^((http|https)?:\/\/)')) {
52
+ options.uri = options.url;
53
+ options.transport = 'http';
54
+ this._transportType = options.transport;
55
+ this.options = options;
56
+ this.transport = new _transports.default.http(options);
57
+ } else if (options.url && options.url.match('^((ws|wss)?:\/\/)')) {
58
+ options.websocket = options.url;
59
+ options.transport = 'ws';
60
+ this._transportType = options.transport;
61
+ this.options = options;
62
+ this.transport = new _transports.default.ws(options);
63
+ } else if (options.transport) {
64
+ if (this.transport && this._transportType !== options.transport) {
65
+ this.transport.stop();
66
+ }
67
+ this._transportType = options.transport;
68
+ if (typeof options.transport === 'string') {
69
+ if (!_transports.default[options.transport]) {
70
+ throw new TypeError('Invalid `transport`, valid values are `http`, `ws` or a class');
245
71
  }
246
- }, {
247
- key: 'setUri',
248
- value: function setUri(url) {
249
- this.setOptions({
250
- uri: url
251
- });
252
- }
253
- }, {
254
- key: 'streamBlockNumber',
255
- value: function streamBlockNumber() {
256
- var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'head';
257
-
258
- var _this2 = this;
259
-
260
- var callback = arguments[1];
261
- var ts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200;
262
-
263
- if (typeof mode === 'function') {
264
- callback = mode;
265
- mode = 'head';
266
- }
267
- var current = '';
268
- var running = true;
269
-
270
- var update = function update() {
271
- if (!running) return;
272
-
273
- _this2.getDynamicGlobalPropertiesAsync().then(function (result) {
274
- var blockId = mode === 'irreversible' ? result.last_irreversible_block_num : result.head_block_number;
275
-
276
- if (blockId !== current) {
277
- if (current) {
278
- for (var i = current; i < blockId; i++) {
279
- if (i !== current) {
280
- callback(null, i);
281
- }
282
- current = i;
283
- }
284
- } else {
285
- current = blockId;
286
- callback(null, blockId);
287
- }
288
- }
289
-
290
- _bluebird2.default.delay(ts).then(function () {
291
- update();
292
- });
293
- }, function (err) {
294
- callback(err);
295
- });
296
- };
297
-
298
- update();
299
-
300
- return function () {
301
- running = false;
302
- };
72
+ this.transport = new _transports.default[options.transport](options);
73
+ } else {
74
+ this.transport = new options.transport(options);
75
+ }
76
+ } else {
77
+ this.transport = new _transports.default.ws(options);
78
+ }
79
+ }
80
+ _setLogger(options) {
81
+ if (options.hasOwnProperty('logger')) {
82
+ switch (typeof options.logger) {
83
+ case 'function':
84
+ this.__logger = {
85
+ log: options.logger
86
+ };
87
+ break;
88
+ case 'object':
89
+ if (typeof options.logger.log !== 'function') {
90
+ throw new Error('setOptions({logger:{}}) must have a property .log of type function');
91
+ }
92
+ this.__logger = options.logger;
93
+ break;
94
+ case 'undefined':
95
+ if (this.__logger) break;
96
+ default:
97
+ this.__logger = false;
98
+ }
99
+ }
100
+ }
101
+ log(logLevel) {
102
+ if (this.__logger) {
103
+ if (arguments.length > 1 && typeof this.__logger[logLevel] === 'function') {
104
+ let args = Array.prototype.slice.call(arguments, 1);
105
+ this.__logger[logLevel].apply(this.__logger, args);
106
+ } else {
107
+ this.__logger.log.apply(this.__logger, arguments);
108
+ }
109
+ }
110
+ }
111
+ start() {
112
+ return this.transport.start();
113
+ }
114
+ stop() {
115
+ return this.transport.stop();
116
+ }
117
+ send(api, data, callback) {
118
+ var cb = callback;
119
+ if (this.__logger) {
120
+ let id = Math.random();
121
+ let self = this;
122
+ this.log('xmit:' + id + ':', data);
123
+ cb = function (e, d) {
124
+ if (e) {
125
+ self.log('error', 'rsp:' + id + ':\n\n', e, d);
126
+ } else {
127
+ self.log('rsp:' + id + ':', d);
303
128
  }
304
- }, {
305
- key: 'streamBlock',
306
- value: function streamBlock() {
307
- var _this3 = this;
308
-
309
- var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'head';
310
- var callback = arguments[1];
311
-
312
- if (typeof mode === 'function') {
313
- callback = mode;
314
- mode = 'head';
315
- }
316
-
317
- var current = '';
318
- var last = '';
319
-
320
- var release = this.streamBlockNumber(mode, function (err, id) {
321
- if (err) {
322
- release();
323
- callback(err);
324
- return;
325
- }
326
-
327
- current = id;
328
- if (current !== last) {
329
- last = current;
330
- _this3.getBlock(current, callback);
331
- }
332
- });
333
-
334
- return release;
129
+ if (callback) {
130
+ callback.apply(self, arguments);
335
131
  }
336
- }, {
337
- key: 'streamTransactions',
338
- value: function streamTransactions() {
339
- var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'head';
340
- var callback = arguments[1];
341
-
342
- if (typeof mode === 'function') {
343
- callback = mode;
344
- mode = 'head';
345
- }
346
-
347
- var release = this.streamBlock(mode, function (err, result) {
348
- if (err) {
349
- release();
350
- callback(err);
351
- return;
352
- }
353
-
354
- if (result && result.transactions) {
355
- result.transactions.forEach(function (transaction) {
356
- callback(null, transaction);
357
- });
358
- }
359
- });
360
-
361
- return release;
362
- }
363
- }, {
364
- key: 'streamOperations',
365
- value: function streamOperations() {
366
- var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'head';
367
- var callback = arguments[1];
368
-
369
- if (typeof mode === 'function') {
370
- callback = mode;
371
- mode = 'head';
132
+ };
133
+ }
134
+ return this.transport.send(api, data, cb);
135
+ }
136
+ call(method, params, callback) {
137
+ if (this._transportType !== 'http') {
138
+ callback(new Error('RPC methods can only be called when using http transport'));
139
+ return;
140
+ }
141
+ const id = ++this.seqNo;
142
+ (0, _http.jsonRpc)(this.options.uri, {
143
+ method,
144
+ params,
145
+ id
146
+ }).then(res => {
147
+ callback(null, res);
148
+ }, err => {
149
+ callback(err);
150
+ });
151
+ }
152
+ signedCall(method, params, account, key, callback) {
153
+ if (this._transportType !== 'http') {
154
+ callback(new Error('RPC methods can only be called when using http transport'));
155
+ return;
156
+ }
157
+ const id = ++this.seqNo;
158
+ let request;
159
+ try {
160
+ request = (0, _rpcAuth.sign)({
161
+ method,
162
+ params,
163
+ id
164
+ }, account, [key]);
165
+ } catch (error) {
166
+ callback(error);
167
+ return;
168
+ }
169
+ (0, _http.jsonRpc)(this.options.uri, request).then(res => {
170
+ callback(null, res);
171
+ }, err => {
172
+ callback(err);
173
+ });
174
+ }
175
+ setOptions(options) {
176
+ Object.assign(this.options, options);
177
+ this._setLogger(options);
178
+ this._setTransport(options);
179
+ this.transport.setOptions(options);
180
+ if (options.hasOwnProperty('useTestNet')) {
181
+ _config.default.set('address_prefix', options.useTestNet ? 'TST' : 'STM');
182
+ }
183
+ }
184
+ setWebSocket(url) {
185
+ this.setOptions({
186
+ websocket: url
187
+ });
188
+ }
189
+ setUri(url) {
190
+ this.setOptions({
191
+ uri: url
192
+ });
193
+ }
194
+ streamBlockNumber(mode = 'head', callback, ts = 200) {
195
+ if (typeof mode === 'function') {
196
+ callback = mode;
197
+ mode = 'head';
198
+ }
199
+ let current = '';
200
+ let running = true;
201
+ const update = () => {
202
+ if (!running) return;
203
+ this.getDynamicGlobalPropertiesAsync().then(result => {
204
+ const blockId = mode === 'irreversible' ? result.last_irreversible_block_num : result.head_block_number;
205
+ if (blockId !== current) {
206
+ if (current) {
207
+ for (let i = current; i < blockId; i++) {
208
+ if (i !== current) {
209
+ callback(null, i);
210
+ }
211
+ current = i;
372
212
  }
373
-
374
- var release = this.streamTransactions(mode, function (err, transaction) {
375
- if (err) {
376
- release();
377
- callback(err);
378
- return;
379
- }
380
-
381
- transaction.operations.forEach(function (operation) {
382
- callback(null, operation);
383
- });
384
- });
385
-
386
- return release;
387
- }
388
- }, {
389
- key: 'broadcastTransactionSynchronousWith',
390
- value: function broadcastTransactionSynchronousWith(options, callback) {
391
- var trx = options.trx;
392
- return this.send('network_broadcast_api', {
393
- method: 'broadcast_transaction_synchronous',
394
- params: [trx]
395
- }, function (err, result) {
396
- if (err) {
397
- var signed_transaction = _serializer.ops.signed_transaction;
398
- // console.log('-- broadcastTransactionSynchronous -->', JSON.stringify(signed_transaction.toObject(trx), null, 2));
399
- // toObject converts objects into serializable types
400
-
401
- var trObject = signed_transaction.toObject(trx);
402
- var buf = signed_transaction.toBuffer(trx);
403
- err.digest = _ecc.hash.sha256(buf).toString('hex');
404
- err.transaction_id = buf.toString('hex');
405
- err.transaction = JSON.stringify(trObject);
406
- callback(err, '');
407
- } else {
408
- callback('', result);
409
- }
410
- });
213
+ } else {
214
+ current = blockId;
215
+ callback(null, blockId);
216
+ }
411
217
  }
412
- }]);
413
-
414
- return Steem;
415
- }(_events2.default);
218
+ _bluebird.default.delay(ts).then(() => {
219
+ update();
220
+ });
221
+ }, err => {
222
+ callback(err);
223
+ });
224
+ };
225
+ update();
226
+ return () => {
227
+ running = false;
228
+ };
229
+ }
230
+ streamBlock(mode = 'head', callback) {
231
+ if (typeof mode === 'function') {
232
+ callback = mode;
233
+ mode = 'head';
234
+ }
235
+ let current = '';
236
+ let last = '';
237
+ const release = this.streamBlockNumber(mode, (err, id) => {
238
+ if (err) {
239
+ release();
240
+ callback(err);
241
+ return;
242
+ }
243
+ current = id;
244
+ if (current !== last) {
245
+ last = current;
246
+ this.getBlock(current, callback);
247
+ }
248
+ });
249
+ return release;
250
+ }
251
+ streamTransactions(mode = 'head', callback) {
252
+ if (typeof mode === 'function') {
253
+ callback = mode;
254
+ mode = 'head';
255
+ }
256
+ const release = this.streamBlock(mode, (err, result) => {
257
+ if (err) {
258
+ release();
259
+ callback(err);
260
+ return;
261
+ }
262
+ if (result && result.transactions) {
263
+ result.transactions.forEach(transaction => {
264
+ callback(null, transaction);
265
+ });
266
+ }
267
+ });
268
+ return release;
269
+ }
270
+ streamOperations(mode = 'head', callback) {
271
+ if (typeof mode === 'function') {
272
+ callback = mode;
273
+ mode = 'head';
274
+ }
275
+ const release = this.streamTransactions(mode, (err, transaction) => {
276
+ if (err) {
277
+ release();
278
+ callback(err);
279
+ return;
280
+ }
281
+ transaction.operations.forEach(operation => {
282
+ callback(null, operation);
283
+ });
284
+ });
285
+ return release;
286
+ }
287
+ broadcastTransactionSynchronousWith(options, callback) {
288
+ const trx = options.trx;
289
+ return this.send('network_broadcast_api', {
290
+ method: 'broadcast_transaction_synchronous',
291
+ params: [trx]
292
+ }, (err, result) => {
293
+ if (err) {
294
+ const {
295
+ signed_transaction
296
+ } = _serializer.ops;
297
+ // console.log('-- broadcastTransactionSynchronous -->', JSON.stringify(signed_transaction.toObject(trx), null, 2));
298
+ // toObject converts objects into serializable types
299
+ const trObject = signed_transaction.toObject(trx);
300
+ const buf = signed_transaction.toBuffer(trx);
301
+ err.digest = _ecc.hash.sha256(buf).toString('hex');
302
+ err.transaction_id = buf.toString('hex');
303
+ err.transaction = JSON.stringify(trObject);
304
+ callback(err, '');
305
+ } else {
306
+ callback('', result);
307
+ }
308
+ });
309
+ }
310
+ }
416
311
 
417
312
  // Export singleton instance
418
-
419
-
420
- var steem = new Steem(_config2.default);
313
+ const steem = new Steem(_config.default);
421
314
  exports = module.exports = steem;
422
315
  exports.Steem = Steem;