@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
|
@@ -1,64 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
4
|
-
|
|
5
|
-
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; };
|
|
6
|
-
|
|
7
|
-
var _ecc = require('../../ecc');
|
|
8
|
-
|
|
9
|
-
var _number_utils = require('./number_utils');
|
|
10
|
-
|
|
11
|
-
var _config = require('../../../config.js');
|
|
12
|
-
|
|
13
|
-
var _config2 = _interopRequireDefault(_config);
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
"use strict";
|
|
16
2
|
|
|
17
3
|
// Low-level types that make up operations
|
|
18
4
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
const v = require('./validation');
|
|
6
|
+
const ObjectId = require('./object_id');
|
|
7
|
+
const fp = require('./fast_parser');
|
|
8
|
+
const chain_types = require('./ChainTypes');
|
|
23
9
|
//const BigInt = require('BigInt')
|
|
24
10
|
|
|
25
|
-
|
|
11
|
+
const ecc = require("../../ecc");
|
|
12
|
+
const PublicKey = ecc.PublicKey;
|
|
13
|
+
const Address = ecc.Address;
|
|
14
|
+
const ecc_config = ecc.ecc_config;
|
|
15
|
+
const number_utils = require("./number_utils");
|
|
16
|
+
const fromImpliedDecimal = number_utils.fromImpliedDecimal;
|
|
17
|
+
const Config = require("../../../config.js");
|
|
18
|
+
const Types = {};
|
|
26
19
|
module.exports = Types;
|
|
27
|
-
|
|
28
|
-
var HEX_DUMP = process.env.npm_config__graphene_serializer_hex_dump;
|
|
20
|
+
const HEX_DUMP = process.env.npm_config__graphene_serializer_hex_dump;
|
|
29
21
|
|
|
30
22
|
// Highly optimized implementation of Damm algorithm
|
|
31
23
|
// https://en.wikipedia.org/wiki/Damm_algorithm
|
|
32
24
|
function damm_checksum_8digit(value) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
x = t[x + d1];
|
|
59
|
-
x = t[x + d0];
|
|
60
|
-
|
|
61
|
-
return x / 10;
|
|
25
|
+
if (value >= 100000000) throw new Error("Expected value less than 100000000, instead got " + value);
|
|
26
|
+
const t = [0, 30, 10, 70, 50, 90, 80, 60, 40, 20, 70, 0, 90, 20, 10, 50, 40, 80, 60, 30, 40, 20, 0, 60, 80, 70, 10, 30, 50, 90, 10, 70, 50, 0, 90, 80, 30, 40, 20, 60, 60, 10, 20, 30, 0, 40, 50, 90, 70, 80, 30, 60, 70, 40, 20, 0, 90, 50, 80, 10, 50, 80, 60, 90, 70, 20, 0, 10, 30, 40, 80, 90, 40, 50, 30, 60, 20, 0, 10, 70, 90, 40, 30, 80, 60, 10, 70, 20, 0, 50, 20, 50, 80, 10, 40, 30, 60, 70, 90, 0];
|
|
27
|
+
let q0 = value / 10;
|
|
28
|
+
let d0 = value % 10;
|
|
29
|
+
let q1 = q0 / 10;
|
|
30
|
+
let d1 = q0 % 10;
|
|
31
|
+
let q2 = q1 / 10;
|
|
32
|
+
let d2 = q1 % 10;
|
|
33
|
+
let q3 = q2 / 10;
|
|
34
|
+
let d3 = q2 % 10;
|
|
35
|
+
let q4 = q3 / 10;
|
|
36
|
+
let d4 = q3 % 10;
|
|
37
|
+
let q5 = q4 / 10;
|
|
38
|
+
let d5 = q4 % 10;
|
|
39
|
+
let d6 = q5 % 10;
|
|
40
|
+
let d7 = q5 / 10;
|
|
41
|
+
let x = t[d7];
|
|
42
|
+
x = t[x + d6];
|
|
43
|
+
x = t[x + d5];
|
|
44
|
+
x = t[x + d4];
|
|
45
|
+
x = t[x + d3];
|
|
46
|
+
x = t[x + d2];
|
|
47
|
+
x = t[x + d1];
|
|
48
|
+
x = t[x + d0];
|
|
49
|
+
return x / 10;
|
|
62
50
|
}
|
|
63
51
|
|
|
64
52
|
/**
|
|
@@ -83,1156 +71,1015 @@ function damm_checksum_8digit(value) {
|
|
|
83
71
|
* NAI internal storage of legacy assets
|
|
84
72
|
*/
|
|
85
73
|
Types.asset = {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (symbol.startsWith("@@")) {
|
|
164
|
-
nai = (nai << 5) + 16 + precision;
|
|
165
|
-
b.writeUint32(nai);
|
|
166
|
-
} else {
|
|
167
|
-
b.writeUint8(precision);
|
|
168
|
-
b.append(symbol.toUpperCase(), 'binary');
|
|
169
|
-
for (var i = 0; i < 7 - symbol.length; i++) {
|
|
170
|
-
b.writeUint8(0);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return;
|
|
175
|
-
},
|
|
176
|
-
fromObject: function fromObject(object) {
|
|
177
|
-
return object;
|
|
178
|
-
},
|
|
179
|
-
toObject: function toObject(object) {
|
|
180
|
-
var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
181
|
-
|
|
182
|
-
if (debug.use_default && object === undefined) {
|
|
183
|
-
return "0.000 STEEM";
|
|
184
|
-
}
|
|
185
|
-
return object;
|
|
74
|
+
fromByteBuffer(b) {
|
|
75
|
+
let amount = b.readInt64();
|
|
76
|
+
let precision = b.readUint8();
|
|
77
|
+
let amount_string = "";
|
|
78
|
+
let symbol = "";
|
|
79
|
+
if (precision >= 16) {
|
|
80
|
+
// NAI Case
|
|
81
|
+
let b_copy = b.copy(b.offset - 1, b.offset + 3);
|
|
82
|
+
let nai = new Buffer.from(b_copy.toBinary(), "binary").readInt32();
|
|
83
|
+
nai = nai / 32;
|
|
84
|
+
symbol = "@@" + nai.toString().padStart(8, '0') + damm_checksum_8digit(nai).to_String();
|
|
85
|
+
precision = precision % 16;
|
|
86
|
+
b.skip(3);
|
|
87
|
+
amount_string = fromImpliedDecimal(amount, precision);
|
|
88
|
+
} else {
|
|
89
|
+
// Legacy Case
|
|
90
|
+
let b_copy = b.copy(b.offset, b.offset + 7);
|
|
91
|
+
symbol = new Buffer.from(b_copy.toBinary(), "binary").toString().replace(/\x00/g, "");
|
|
92
|
+
b.skip(7);
|
|
93
|
+
// "1.000 STEEM" always written with full precision
|
|
94
|
+
amount_string = fromImpliedDecimal(amount, precision);
|
|
95
|
+
}
|
|
96
|
+
return amount_string + " " + symbol;
|
|
97
|
+
},
|
|
98
|
+
appendByteBuffer(b, object) {
|
|
99
|
+
let amount = "";
|
|
100
|
+
let symbol = "";
|
|
101
|
+
let nai = 0;
|
|
102
|
+
let precision = 0;
|
|
103
|
+
if (object["nai"]) {
|
|
104
|
+
symbol = object["nai"];
|
|
105
|
+
nai = parseInt(symbol.slice(2));
|
|
106
|
+
let checksum = nai % 10;
|
|
107
|
+
nai = Math.floor(nai / 10);
|
|
108
|
+
let expected_checksum = damm_checksum_8digit(nai);
|
|
109
|
+
switch (object["nai"]) {
|
|
110
|
+
case "@@000000021":
|
|
111
|
+
precision = 3;
|
|
112
|
+
symbol = Config.get("address_prefix") == "STM" ? "STEEM" : "TESTS";
|
|
113
|
+
break;
|
|
114
|
+
case "@@000000013":
|
|
115
|
+
precision = 3;
|
|
116
|
+
symbol = Config.get("address_prefix") == "STM" ? "SBD" : "TBD";
|
|
117
|
+
break;
|
|
118
|
+
case "@@000000037":
|
|
119
|
+
precision = 6;
|
|
120
|
+
symbol = "VESTS";
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
precision = parseInt(object["precision"]);
|
|
124
|
+
b.writeInt64(v.to_long(parseInt(object["amount"])));
|
|
125
|
+
} else {
|
|
126
|
+
object = object.trim();
|
|
127
|
+
if (!/^[0-9]+\.?[0-9]* [A-Za-z0-9@]+$/.test(object)) throw new Error("Expecting amount like '99.000 SYMBOL', instead got '" + object + "'");
|
|
128
|
+
let res = object.split(" ");
|
|
129
|
+
amount = res[0];
|
|
130
|
+
symbol = res[1];
|
|
131
|
+
if (symbol.startsWith("@@")) {
|
|
132
|
+
// NAI Case
|
|
133
|
+
nai = parseInt(symbol.slice(2));
|
|
134
|
+
let checksum = nai % 10;
|
|
135
|
+
nai = Math.floor(nai / 10);
|
|
136
|
+
let expected_checksum = damm_checksum_8digit(nai);
|
|
137
|
+
} else if (symbol.length > 6) throw new Error("Symbols are not longer than 6 characters " + symbol + "-" + symbol.length);
|
|
138
|
+
b.writeInt64(v.to_long(amount.replace(".", "")));
|
|
139
|
+
let dot = amount.indexOf("."); // 0.000
|
|
140
|
+
precision = dot === -1 ? 0 : amount.length - dot - 1;
|
|
141
|
+
}
|
|
142
|
+
if (symbol.startsWith("@@")) {
|
|
143
|
+
nai = (nai << 5) + 16 + precision;
|
|
144
|
+
b.writeUint32(nai);
|
|
145
|
+
} else {
|
|
146
|
+
b.writeUint8(precision);
|
|
147
|
+
b.append(symbol.toUpperCase(), 'binary');
|
|
148
|
+
for (let i = 0; i < 7 - symbol.length; i++) b.writeUint8(0);
|
|
186
149
|
}
|
|
150
|
+
return;
|
|
151
|
+
},
|
|
152
|
+
fromObject(object) {
|
|
153
|
+
return object;
|
|
154
|
+
},
|
|
155
|
+
toObject(object, debug = {}) {
|
|
156
|
+
if (debug.use_default && object === undefined) {
|
|
157
|
+
return "0.000 STEEM";
|
|
158
|
+
}
|
|
159
|
+
return object;
|
|
160
|
+
}
|
|
187
161
|
};
|
|
188
|
-
|
|
189
162
|
Types.asset_symbol = {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
symbol = "VESTS";
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (precision > 0) {
|
|
241
|
-
//Core Symbol Case
|
|
242
|
-
b.writeUint8(precision);
|
|
243
|
-
b.append(symbol, 'binary');
|
|
244
|
-
for (var i = 0; i < 7 - symbol.length; i++) {
|
|
245
|
-
b.writeUint8(0);
|
|
246
|
-
}
|
|
247
|
-
} else {
|
|
248
|
-
nai = (nai << 5) + 16 + object["precision"];
|
|
249
|
-
b.writeUint32(nai);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return;
|
|
253
|
-
},
|
|
254
|
-
fromObject: function fromObject(object) {
|
|
255
|
-
return object;
|
|
256
|
-
},
|
|
257
|
-
toObject: function toObject(object) {
|
|
258
|
-
var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
259
|
-
|
|
260
|
-
if (debug.use_default && object === undefined) {
|
|
261
|
-
return "STEEM";
|
|
262
|
-
}
|
|
263
|
-
return object;
|
|
163
|
+
fromByteBuffer(b) {
|
|
164
|
+
let precision = b.readUint8();
|
|
165
|
+
let amount_string = "";
|
|
166
|
+
let nai_string = "";
|
|
167
|
+
if (precision >= 16) {
|
|
168
|
+
// NAI Case
|
|
169
|
+
let b_copy = b.copy(b.offset - 1, b.offset + 3);
|
|
170
|
+
let nai = new Buffer.from(b_copy.toBinary(), "binary").readInt32();
|
|
171
|
+
nai = nai / 32;
|
|
172
|
+
nai_string = "@@" + nai.toString().padStart(8, '0') + damm_checksum_8digit(nai).to_String();
|
|
173
|
+
precision = precision % 16;
|
|
174
|
+
b.skip(3);
|
|
175
|
+
} else {
|
|
176
|
+
// Legacy Case
|
|
177
|
+
let b_copy = b.copy(b.offset, b.offset + 7);
|
|
178
|
+
let symbol = new Buffer.from(b_copy.toBinary(), "binary").toString().replace(/\x00/g, "");
|
|
179
|
+
if (symbol == "STEEM" || symbol == "TESTS") nai_string = "@@000000021";else if (symbol == "SBD" || symbol == "TBD") nai_string = "@@000000013";else if (symbol == "VESTS") nai_string = "@@000000037";else throw new Error("Expecting non-smt core asset symbol, instead got '" + symbol + "'");
|
|
180
|
+
b.skip(7);
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
"nai": nai_string,
|
|
184
|
+
"precision": precision
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
appendByteBuffer(b, object) {
|
|
188
|
+
let nai = 0;
|
|
189
|
+
if (!object["nai"].startsWith("@@")) throw new Error("Asset Symbols NAIs must be prefixed with '@@'. Was " + object["nai"]);
|
|
190
|
+
nai = parseInt(object["nai"].slice(2));
|
|
191
|
+
let checksum = nai % 10;
|
|
192
|
+
nai = Math.floor(nai / 10);
|
|
193
|
+
let expected_checksum = damm_checksum_8digit(nai);
|
|
194
|
+
let precision = 0;
|
|
195
|
+
let symbol = "";
|
|
196
|
+
switch (object["nai"]) {
|
|
197
|
+
case "@@000000021":
|
|
198
|
+
precision = 3;
|
|
199
|
+
symbol = Config.get("address_prefix") == "STM" ? "STEEM" : "TESTS";
|
|
200
|
+
break;
|
|
201
|
+
case "@@000000013":
|
|
202
|
+
precision = 3;
|
|
203
|
+
symbol = Config.get("address_prefix") == "STM" ? "SBD" : "TBD";
|
|
204
|
+
break;
|
|
205
|
+
case "@@000000037":
|
|
206
|
+
precision = 6;
|
|
207
|
+
symbol = "VESTS";
|
|
208
|
+
break;
|
|
264
209
|
}
|
|
210
|
+
if (precision > 0) {
|
|
211
|
+
//Core Symbol Case
|
|
212
|
+
b.writeUint8(precision);
|
|
213
|
+
b.append(symbol, 'binary');
|
|
214
|
+
for (let i = 0; i < 7 - symbol.length; i++) b.writeUint8(0);
|
|
215
|
+
} else {
|
|
216
|
+
nai = (nai << 5) + 16 + object["precision"];
|
|
217
|
+
b.writeUint32(nai);
|
|
218
|
+
}
|
|
219
|
+
return;
|
|
220
|
+
},
|
|
221
|
+
fromObject(object) {
|
|
222
|
+
return object;
|
|
223
|
+
},
|
|
224
|
+
toObject(object, debug = {}) {
|
|
225
|
+
if (debug.use_default && object === undefined) {
|
|
226
|
+
return "STEEM";
|
|
227
|
+
}
|
|
228
|
+
return object;
|
|
229
|
+
}
|
|
265
230
|
};
|
|
266
|
-
|
|
267
231
|
Types.uint8 = {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (debug.use_default && object === undefined) {
|
|
284
|
-
return 0;
|
|
285
|
-
}
|
|
286
|
-
v.require_range(0, 0xFF, object, 'uint8 ' + object);
|
|
287
|
-
return parseInt(object);
|
|
232
|
+
fromByteBuffer(b) {
|
|
233
|
+
return b.readUint8();
|
|
234
|
+
},
|
|
235
|
+
appendByteBuffer(b, object) {
|
|
236
|
+
v.require_range(0, 0xFF, object, `uint8 ${object}`);
|
|
237
|
+
b.writeUint8(object);
|
|
238
|
+
return;
|
|
239
|
+
},
|
|
240
|
+
fromObject(object) {
|
|
241
|
+
v.require_range(0, 0xFF, object, `uint8 ${object}`);
|
|
242
|
+
return object;
|
|
243
|
+
},
|
|
244
|
+
toObject(object, debug = {}) {
|
|
245
|
+
if (debug.use_default && object === undefined) {
|
|
246
|
+
return 0;
|
|
288
247
|
}
|
|
248
|
+
v.require_range(0, 0xFF, object, `uint8 ${object}`);
|
|
249
|
+
return parseInt(object);
|
|
250
|
+
}
|
|
289
251
|
};
|
|
290
|
-
|
|
291
252
|
Types.uint16 = {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if (debug.use_default && object === undefined) {
|
|
308
|
-
return 0;
|
|
309
|
-
}
|
|
310
|
-
v.require_range(0, 0xFFFF, object, 'uint16 ' + object);
|
|
311
|
-
return parseInt(object);
|
|
253
|
+
fromByteBuffer(b) {
|
|
254
|
+
return b.readUint16();
|
|
255
|
+
},
|
|
256
|
+
appendByteBuffer(b, object) {
|
|
257
|
+
v.require_range(0, 0xFFFF, object, `uint16 ${object}`);
|
|
258
|
+
b.writeUint16(object);
|
|
259
|
+
return;
|
|
260
|
+
},
|
|
261
|
+
fromObject(object) {
|
|
262
|
+
v.require_range(0, 0xFFFF, object, `uint16 ${object}`);
|
|
263
|
+
return object;
|
|
264
|
+
},
|
|
265
|
+
toObject(object, debug = {}) {
|
|
266
|
+
if (debug.use_default && object === undefined) {
|
|
267
|
+
return 0;
|
|
312
268
|
}
|
|
269
|
+
v.require_range(0, 0xFFFF, object, `uint16 ${object}`);
|
|
270
|
+
return parseInt(object);
|
|
271
|
+
}
|
|
313
272
|
};
|
|
314
|
-
|
|
315
273
|
Types.uint32 = {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (debug.use_default && object === undefined) {
|
|
332
|
-
return 0;
|
|
333
|
-
}
|
|
334
|
-
v.require_range(0, 0xFFFFFFFF, object, 'uint32 ' + object);
|
|
335
|
-
return parseInt(object);
|
|
274
|
+
fromByteBuffer(b) {
|
|
275
|
+
return b.readUint32();
|
|
276
|
+
},
|
|
277
|
+
appendByteBuffer(b, object) {
|
|
278
|
+
v.require_range(0, 0xFFFFFFFF, object, `uint32 ${object}`);
|
|
279
|
+
b.writeUint32(object);
|
|
280
|
+
return;
|
|
281
|
+
},
|
|
282
|
+
fromObject(object) {
|
|
283
|
+
v.require_range(0, 0xFFFFFFFF, object, `uint32 ${object}`);
|
|
284
|
+
return object;
|
|
285
|
+
},
|
|
286
|
+
toObject(object, debug = {}) {
|
|
287
|
+
if (debug.use_default && object === undefined) {
|
|
288
|
+
return 0;
|
|
336
289
|
}
|
|
290
|
+
v.require_range(0, 0xFFFFFFFF, object, `uint32 ${object}`);
|
|
291
|
+
return parseInt(object);
|
|
292
|
+
}
|
|
337
293
|
};
|
|
338
|
-
|
|
339
294
|
var MIN_SIGNED_32 = -1 * Math.pow(2, 31);
|
|
340
295
|
var MAX_SIGNED_32 = Math.pow(2, 31) - 1;
|
|
341
|
-
|
|
342
296
|
Types.varint32 = {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (debug.use_default && object === undefined) {
|
|
359
|
-
return 0;
|
|
360
|
-
}
|
|
361
|
-
v.require_range(MIN_SIGNED_32, MAX_SIGNED_32, object, 'uint32 ' + object);
|
|
362
|
-
return parseInt(object);
|
|
297
|
+
fromByteBuffer(b) {
|
|
298
|
+
return b.readVarint32();
|
|
299
|
+
},
|
|
300
|
+
appendByteBuffer(b, object) {
|
|
301
|
+
v.require_range(MIN_SIGNED_32, MAX_SIGNED_32, object, `uint32 ${object}`);
|
|
302
|
+
b.writeVarint32(object);
|
|
303
|
+
return;
|
|
304
|
+
},
|
|
305
|
+
fromObject(object) {
|
|
306
|
+
v.require_range(MIN_SIGNED_32, MAX_SIGNED_32, object, `uint32 ${object}`);
|
|
307
|
+
return object;
|
|
308
|
+
},
|
|
309
|
+
toObject(object, debug = {}) {
|
|
310
|
+
if (debug.use_default && object === undefined) {
|
|
311
|
+
return 0;
|
|
363
312
|
}
|
|
313
|
+
v.require_range(MIN_SIGNED_32, MAX_SIGNED_32, object, `uint32 ${object}`);
|
|
314
|
+
return parseInt(object);
|
|
315
|
+
}
|
|
364
316
|
};
|
|
365
|
-
|
|
366
317
|
Types.int16 = {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
if (debug.use_default && object === undefined) {
|
|
381
|
-
return 0;
|
|
382
|
-
}
|
|
383
|
-
return parseInt(object);
|
|
318
|
+
fromByteBuffer(b) {
|
|
319
|
+
return b.readInt16();
|
|
320
|
+
},
|
|
321
|
+
appendByteBuffer(b, object) {
|
|
322
|
+
b.writeInt16(object);
|
|
323
|
+
return;
|
|
324
|
+
},
|
|
325
|
+
fromObject(object) {
|
|
326
|
+
return object;
|
|
327
|
+
},
|
|
328
|
+
toObject(object, debug = {}) {
|
|
329
|
+
if (debug.use_default && object === undefined) {
|
|
330
|
+
return 0;
|
|
384
331
|
}
|
|
332
|
+
return parseInt(object);
|
|
333
|
+
}
|
|
385
334
|
};
|
|
386
|
-
|
|
387
335
|
Types.int64 = {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
if (debug.use_default && object === undefined) {
|
|
404
|
-
return "0";
|
|
405
|
-
}
|
|
406
|
-
v.required(object);
|
|
407
|
-
return v.to_long(object).toString();
|
|
336
|
+
fromByteBuffer(b) {
|
|
337
|
+
return b.readInt64();
|
|
338
|
+
},
|
|
339
|
+
appendByteBuffer(b, object) {
|
|
340
|
+
v.required(object);
|
|
341
|
+
b.writeInt64(v.to_long(object));
|
|
342
|
+
return;
|
|
343
|
+
},
|
|
344
|
+
fromObject(object) {
|
|
345
|
+
v.required(object);
|
|
346
|
+
return v.to_long(object);
|
|
347
|
+
},
|
|
348
|
+
toObject(object, debug = {}) {
|
|
349
|
+
if (debug.use_default && object === undefined) {
|
|
350
|
+
return "0";
|
|
408
351
|
}
|
|
352
|
+
v.required(object);
|
|
353
|
+
return v.to_long(object).toString();
|
|
354
|
+
}
|
|
409
355
|
};
|
|
410
|
-
|
|
411
356
|
Types.uint64 = {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
if (debug.use_default && object === undefined) {
|
|
426
|
-
return "0";
|
|
427
|
-
}
|
|
428
|
-
return v.to_long(object).toString();
|
|
357
|
+
fromByteBuffer(b) {
|
|
358
|
+
return b.readUint64();
|
|
359
|
+
},
|
|
360
|
+
appendByteBuffer(b, object) {
|
|
361
|
+
b.writeUint64(v.to_long(v.unsigned(object)));
|
|
362
|
+
return;
|
|
363
|
+
},
|
|
364
|
+
fromObject(object) {
|
|
365
|
+
return v.to_long(v.unsigned(object));
|
|
366
|
+
},
|
|
367
|
+
toObject(object, debug = {}) {
|
|
368
|
+
if (debug.use_default && object === undefined) {
|
|
369
|
+
return "0";
|
|
429
370
|
}
|
|
371
|
+
return v.to_long(object).toString();
|
|
372
|
+
}
|
|
430
373
|
};
|
|
431
|
-
|
|
432
374
|
Types.uint128 = {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
if (debug.use_default && object === undefined) {
|
|
449
|
-
return "0";
|
|
450
|
-
}
|
|
451
|
-
return v.to_long(object).toString();
|
|
375
|
+
fromByteBuffer(b) {
|
|
376
|
+
b.readBigInt64();
|
|
377
|
+
return b.readBigInt64();
|
|
378
|
+
},
|
|
379
|
+
appendByteBuffer(b, object) {
|
|
380
|
+
b.writeUint64(v.to_long(v.unsigned(0)));
|
|
381
|
+
b.writeUint64(v.to_long(v.unsigned(object)));
|
|
382
|
+
return;
|
|
383
|
+
},
|
|
384
|
+
fromObject(object) {
|
|
385
|
+
return v.to_long(v.unsigned(object));
|
|
386
|
+
},
|
|
387
|
+
toObject(object, debug = {}) {
|
|
388
|
+
if (debug.use_default && object === undefined) {
|
|
389
|
+
return "0";
|
|
452
390
|
}
|
|
391
|
+
return v.to_long(object).toString();
|
|
392
|
+
}
|
|
453
393
|
};
|
|
454
|
-
|
|
455
394
|
Types.string = {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
if (debug.use_default && object === undefined) {
|
|
472
|
-
return "";
|
|
473
|
-
}
|
|
474
|
-
return object.toString('utf8');
|
|
395
|
+
fromByteBuffer(b) {
|
|
396
|
+
return new Buffer.from(b.readVString(), 'utf8');
|
|
397
|
+
},
|
|
398
|
+
appendByteBuffer(b, object) {
|
|
399
|
+
v.required(object);
|
|
400
|
+
b.writeVString(object.toString());
|
|
401
|
+
return;
|
|
402
|
+
},
|
|
403
|
+
fromObject(object) {
|
|
404
|
+
v.required(object);
|
|
405
|
+
return new Buffer.from(object, 'utf8');
|
|
406
|
+
},
|
|
407
|
+
toObject(object, debug = {}) {
|
|
408
|
+
if (debug.use_default && object === undefined) {
|
|
409
|
+
return "";
|
|
475
410
|
}
|
|
411
|
+
return object.toString('utf8');
|
|
412
|
+
}
|
|
476
413
|
};
|
|
477
|
-
|
|
478
414
|
Types.string_binary = {
|
|
479
|
-
|
|
415
|
+
fromByteBuffer(b) {
|
|
416
|
+
var b_copy;
|
|
417
|
+
var len = b.readVarint32();
|
|
418
|
+
b_copy = b.copy(b.offset, b.offset + len), b.skip(len);
|
|
419
|
+
return new Buffer.from(b_copy.toBinary(), 'binary');
|
|
420
|
+
},
|
|
421
|
+
appendByteBuffer(b, object) {
|
|
422
|
+
b.writeVarint32(object.length);
|
|
423
|
+
b.append(object.toString('binary'), 'binary');
|
|
424
|
+
return;
|
|
425
|
+
},
|
|
426
|
+
fromObject(object) {
|
|
427
|
+
v.required(object);
|
|
428
|
+
return new Buffer.from(object);
|
|
429
|
+
},
|
|
430
|
+
toObject(object, debug = {}) {
|
|
431
|
+
if (debug.use_default && object === undefined) {
|
|
432
|
+
return "";
|
|
433
|
+
}
|
|
434
|
+
return object.toString();
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
Types.bytes = function (size) {
|
|
438
|
+
return {
|
|
439
|
+
fromByteBuffer(b) {
|
|
440
|
+
if (size === undefined) {
|
|
480
441
|
var b_copy;
|
|
481
442
|
var len = b.readVarint32();
|
|
482
443
|
b_copy = b.copy(b.offset, b.offset + len), b.skip(len);
|
|
483
|
-
return new Buffer(b_copy.toBinary(), 'binary');
|
|
444
|
+
return new Buffer.from(b_copy.toBinary(), 'binary');
|
|
445
|
+
} else {
|
|
446
|
+
b_copy = b.copy(b.offset, b.offset + size), b.skip(size);
|
|
447
|
+
return new Buffer.from(b_copy.toBinary(), 'binary');
|
|
448
|
+
}
|
|
484
449
|
},
|
|
485
|
-
appendByteBuffer
|
|
450
|
+
appendByteBuffer(b, object) {
|
|
451
|
+
v.required(object);
|
|
452
|
+
if (typeof object === "string") object = new Buffer.from(object, "hex");
|
|
453
|
+
if (size === undefined) {
|
|
486
454
|
b.writeVarint32(object.length);
|
|
487
|
-
|
|
488
|
-
|
|
455
|
+
}
|
|
456
|
+
b.append(object.toString('binary'), 'binary');
|
|
457
|
+
return;
|
|
489
458
|
},
|
|
490
|
-
fromObject
|
|
491
|
-
|
|
492
|
-
|
|
459
|
+
fromObject(object) {
|
|
460
|
+
v.required(object);
|
|
461
|
+
if (Buffer.isBuffer(object)) return object;
|
|
462
|
+
return new Buffer.from(object, 'hex');
|
|
493
463
|
},
|
|
494
|
-
toObject
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
464
|
+
toObject(object, debug = {}) {
|
|
465
|
+
if (debug.use_default && object === undefined) {
|
|
466
|
+
var zeros = function (num) {
|
|
467
|
+
return new Array(num).join("00");
|
|
468
|
+
};
|
|
469
|
+
return zeros(size);
|
|
470
|
+
}
|
|
471
|
+
v.required(object);
|
|
472
|
+
return object.toString('hex');
|
|
501
473
|
}
|
|
474
|
+
};
|
|
502
475
|
};
|
|
503
|
-
|
|
504
|
-
Types.bytes = function (size) {
|
|
505
|
-
return {
|
|
506
|
-
fromByteBuffer: function fromByteBuffer(b) {
|
|
507
|
-
if (size === undefined) {
|
|
508
|
-
var b_copy;
|
|
509
|
-
var len = b.readVarint32();
|
|
510
|
-
b_copy = b.copy(b.offset, b.offset + len), b.skip(len);
|
|
511
|
-
return new Buffer(b_copy.toBinary(), 'binary');
|
|
512
|
-
} else {
|
|
513
|
-
b_copy = b.copy(b.offset, b.offset + size), b.skip(size);
|
|
514
|
-
return new Buffer(b_copy.toBinary(), 'binary');
|
|
515
|
-
}
|
|
516
|
-
},
|
|
517
|
-
appendByteBuffer: function appendByteBuffer(b, object) {
|
|
518
|
-
v.required(object);
|
|
519
|
-
if (typeof object === "string") object = new Buffer(object, "hex");
|
|
520
|
-
|
|
521
|
-
if (size === undefined) {
|
|
522
|
-
b.writeVarint32(object.length);
|
|
523
|
-
}
|
|
524
|
-
b.append(object.toString('binary'), 'binary');
|
|
525
|
-
return;
|
|
526
|
-
},
|
|
527
|
-
fromObject: function fromObject(object) {
|
|
528
|
-
v.required(object);
|
|
529
|
-
if (Buffer.isBuffer(object)) return object;
|
|
530
|
-
|
|
531
|
-
return new Buffer(object, 'hex');
|
|
532
|
-
},
|
|
533
|
-
toObject: function toObject(object) {
|
|
534
|
-
var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
535
|
-
|
|
536
|
-
if (debug.use_default && object === undefined) {
|
|
537
|
-
var zeros = function zeros(num) {
|
|
538
|
-
return new Array(num).join("00");
|
|
539
|
-
};
|
|
540
|
-
return zeros(size);
|
|
541
|
-
}
|
|
542
|
-
v.required(object);
|
|
543
|
-
return object.toString('hex');
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
};
|
|
547
|
-
|
|
548
476
|
Types.bool = {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
if (debug.use_default && object === undefined) {
|
|
564
|
-
return false;
|
|
565
|
-
}
|
|
566
|
-
return JSON.parse(object) ? true : false;
|
|
477
|
+
fromByteBuffer(b) {
|
|
478
|
+
return b.readUint8() === 1;
|
|
479
|
+
},
|
|
480
|
+
appendByteBuffer(b, object) {
|
|
481
|
+
// supports boolean or integer
|
|
482
|
+
b.writeUint8(JSON.parse(object) ? 1 : 0);
|
|
483
|
+
return;
|
|
484
|
+
},
|
|
485
|
+
fromObject(object) {
|
|
486
|
+
return JSON.parse(object) ? true : false;
|
|
487
|
+
},
|
|
488
|
+
toObject(object, debug = {}) {
|
|
489
|
+
if (debug.use_default && object === undefined) {
|
|
490
|
+
return false;
|
|
567
491
|
}
|
|
492
|
+
return JSON.parse(object) ? true : false;
|
|
493
|
+
}
|
|
568
494
|
};
|
|
569
|
-
|
|
570
495
|
Types.void = {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
if (debug.use_default && object === undefined) {
|
|
584
|
-
return undefined;
|
|
585
|
-
}
|
|
586
|
-
throw new Error("(void) undefined type");
|
|
496
|
+
fromByteBuffer(b) {
|
|
497
|
+
throw new Error("(void) undefined type");
|
|
498
|
+
},
|
|
499
|
+
appendByteBuffer(b, object) {
|
|
500
|
+
throw new Error("(void) undefined type");
|
|
501
|
+
},
|
|
502
|
+
fromObject(object) {
|
|
503
|
+
throw new Error("(void) undefined type");
|
|
504
|
+
},
|
|
505
|
+
toObject(object, debug = {}) {
|
|
506
|
+
if (debug.use_default && object === undefined) {
|
|
507
|
+
return undefined;
|
|
587
508
|
}
|
|
509
|
+
throw new Error("(void) undefined type");
|
|
510
|
+
}
|
|
588
511
|
};
|
|
589
|
-
|
|
590
512
|
Types.array = function (st_operation) {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
},
|
|
603
|
-
appendByteBuffer: function appendByteBuffer(b, object) {
|
|
604
|
-
v.required(object);
|
|
605
|
-
object = sortOperation(object, st_operation);
|
|
606
|
-
b.writeVarint32(object.length);
|
|
607
|
-
for (var i = 0, o; i < object.length; i++) {
|
|
608
|
-
o = object[i];
|
|
609
|
-
st_operation.appendByteBuffer(b, o);
|
|
610
|
-
}
|
|
611
|
-
},
|
|
612
|
-
fromObject: function fromObject(object) {
|
|
613
|
-
v.required(object);
|
|
614
|
-
object = sortOperation(object, st_operation);
|
|
615
|
-
var result = [];
|
|
616
|
-
for (var i = 0, o; i < object.length; i++) {
|
|
617
|
-
o = object[i];
|
|
618
|
-
result.push(st_operation.fromObject(o));
|
|
619
|
-
}
|
|
620
|
-
return result;
|
|
621
|
-
},
|
|
622
|
-
toObject: function toObject(object) {
|
|
623
|
-
var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
624
|
-
|
|
625
|
-
if (debug.use_default && object === undefined) {
|
|
626
|
-
return [st_operation.toObject(object, debug)];
|
|
627
|
-
}
|
|
628
|
-
v.required(object);
|
|
629
|
-
object = sortOperation(object, st_operation);
|
|
630
|
-
|
|
631
|
-
var result = [];
|
|
632
|
-
for (var i = 0, o; i < object.length; i++) {
|
|
633
|
-
o = object[i];
|
|
634
|
-
result.push(st_operation.toObject(o, debug));
|
|
635
|
-
}
|
|
636
|
-
return result;
|
|
637
|
-
}
|
|
638
|
-
};
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
Types.time_point_sec = {
|
|
642
|
-
fromByteBuffer: function fromByteBuffer(b) {
|
|
643
|
-
return b.readUint32();
|
|
513
|
+
return {
|
|
514
|
+
fromByteBuffer(b) {
|
|
515
|
+
var size = b.readVarint32();
|
|
516
|
+
if (HEX_DUMP) {
|
|
517
|
+
console.log("varint32 size = " + size.toString(16));
|
|
518
|
+
}
|
|
519
|
+
var result = [];
|
|
520
|
+
for (var i = 0; 0 < size ? i < size : i > size; 0 < size ? i++ : i++) {
|
|
521
|
+
result.push(st_operation.fromByteBuffer(b));
|
|
522
|
+
}
|
|
523
|
+
return sortOperation(result, st_operation);
|
|
644
524
|
},
|
|
645
|
-
appendByteBuffer
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
525
|
+
appendByteBuffer(b, object) {
|
|
526
|
+
v.required(object);
|
|
527
|
+
object = sortOperation(object, st_operation);
|
|
528
|
+
b.writeVarint32(object.length);
|
|
529
|
+
for (var i = 0, o; i < object.length; i++) {
|
|
530
|
+
o = object[i];
|
|
531
|
+
st_operation.appendByteBuffer(b, o);
|
|
532
|
+
}
|
|
650
533
|
},
|
|
651
|
-
fromObject
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
if (typeof object === "string" && !/Z$/.test(object)) object = object + "Z";
|
|
661
|
-
|
|
662
|
-
return Math.floor(new Date(object).getTime() / 1000);
|
|
534
|
+
fromObject(object) {
|
|
535
|
+
v.required(object);
|
|
536
|
+
object = sortOperation(object, st_operation);
|
|
537
|
+
var result = [];
|
|
538
|
+
for (var i = 0, o; i < object.length; i++) {
|
|
539
|
+
o = object[i];
|
|
540
|
+
result.push(st_operation.fromObject(o));
|
|
541
|
+
}
|
|
542
|
+
return result;
|
|
663
543
|
},
|
|
664
|
-
toObject
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
v.require_range(0, 0xFFFFFFFF, int, 'uint32 ' + object);
|
|
677
|
-
return new Date(int * 1000).toISOString().split('.')[0];
|
|
544
|
+
toObject(object, debug = {}) {
|
|
545
|
+
if (debug.use_default && object === undefined) {
|
|
546
|
+
return [st_operation.toObject(object, debug)];
|
|
547
|
+
}
|
|
548
|
+
v.required(object);
|
|
549
|
+
object = sortOperation(object, st_operation);
|
|
550
|
+
var result = [];
|
|
551
|
+
for (var i = 0, o; i < object.length; i++) {
|
|
552
|
+
o = object[i];
|
|
553
|
+
result.push(st_operation.toObject(o, debug));
|
|
554
|
+
}
|
|
555
|
+
return result;
|
|
678
556
|
}
|
|
557
|
+
};
|
|
679
558
|
};
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
return
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
}
|
|
707
|
-
return result;
|
|
708
|
-
}());
|
|
709
|
-
},
|
|
710
|
-
appendByteBuffer: function appendByteBuffer(b, object) {
|
|
711
|
-
if (!object) {
|
|
712
|
-
object = [];
|
|
713
|
-
}
|
|
714
|
-
b.writeVarint32(object.length);
|
|
715
|
-
var iterable = this.validate(object);
|
|
716
|
-
for (var i = 0, o; i < iterable.length; i++) {
|
|
717
|
-
o = iterable[i];
|
|
718
|
-
st_operation.appendByteBuffer(b, o);
|
|
719
|
-
}
|
|
720
|
-
return;
|
|
721
|
-
},
|
|
722
|
-
fromObject: function fromObject(object) {
|
|
723
|
-
if (!object) {
|
|
724
|
-
object = [];
|
|
725
|
-
}
|
|
726
|
-
return this.validate(function () {
|
|
727
|
-
var result = [];
|
|
728
|
-
for (var i = 0, o; i < object.length; i++) {
|
|
729
|
-
o = object[i];
|
|
730
|
-
result.push(st_operation.fromObject(o));
|
|
731
|
-
}
|
|
732
|
-
return result;
|
|
733
|
-
}());
|
|
734
|
-
},
|
|
735
|
-
toObject: function toObject(object) {
|
|
736
|
-
var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
737
|
-
|
|
738
|
-
if (debug.use_default && object === undefined) {
|
|
739
|
-
return [st_operation.toObject(object, debug)];
|
|
740
|
-
}
|
|
741
|
-
if (!object) {
|
|
742
|
-
object = [];
|
|
743
|
-
}
|
|
744
|
-
return this.validate(function () {
|
|
745
|
-
var result = [];
|
|
746
|
-
for (var i = 0, o; i < object.length; i++) {
|
|
747
|
-
o = object[i];
|
|
748
|
-
result.push(st_operation.toObject(o, debug));
|
|
749
|
-
}
|
|
750
|
-
return result;
|
|
751
|
-
}());
|
|
752
|
-
}
|
|
753
|
-
};
|
|
754
|
-
};
|
|
755
|
-
|
|
756
|
-
// global_parameters_update_operation current_fees
|
|
757
|
-
Types.fixed_array = function (count, st_operation) {
|
|
758
|
-
return {
|
|
759
|
-
fromByteBuffer: function fromByteBuffer(b) {
|
|
760
|
-
var i, j, ref, results;
|
|
761
|
-
results = [];
|
|
762
|
-
for (i = j = 0, ref = count; j < ref; i = j += 1) {
|
|
763
|
-
results.push(st_operation.fromByteBuffer(b));
|
|
764
|
-
}
|
|
765
|
-
return sortOperation(results, st_operation);
|
|
766
|
-
},
|
|
767
|
-
appendByteBuffer: function appendByteBuffer(b, object) {
|
|
768
|
-
var i, j, ref;
|
|
769
|
-
if (count !== 0) {
|
|
770
|
-
v.required(object);
|
|
771
|
-
object = sortOperation(object, st_operation);
|
|
772
|
-
}
|
|
773
|
-
for (i = j = 0, ref = count; j < ref; i = j += 1) {
|
|
774
|
-
st_operation.appendByteBuffer(b, object[i]);
|
|
775
|
-
}
|
|
776
|
-
},
|
|
777
|
-
fromObject: function fromObject(object) {
|
|
778
|
-
var i, j, ref, results;
|
|
779
|
-
if (count !== 0) {
|
|
780
|
-
v.required(object);
|
|
781
|
-
}
|
|
782
|
-
results = [];
|
|
783
|
-
for (i = j = 0, ref = count; j < ref; i = j += 1) {
|
|
784
|
-
results.push(st_operation.fromObject(object[i]));
|
|
785
|
-
}
|
|
786
|
-
return results;
|
|
787
|
-
},
|
|
788
|
-
toObject: function toObject(object, debug) {
|
|
789
|
-
var i, j, k, ref, ref1, results, results1;
|
|
790
|
-
if (debug == null) {
|
|
791
|
-
debug = {};
|
|
792
|
-
}
|
|
793
|
-
if (debug.use_default && object === void 0) {
|
|
794
|
-
results = [];
|
|
795
|
-
for (i = j = 0, ref = count; j < ref; i = j += 1) {
|
|
796
|
-
results.push(st_operation.toObject(void 0, debug));
|
|
797
|
-
}
|
|
798
|
-
return results;
|
|
799
|
-
}
|
|
800
|
-
if (count !== 0) {
|
|
801
|
-
v.required(object);
|
|
802
|
-
}
|
|
803
|
-
results1 = [];
|
|
804
|
-
for (i = k = 0, ref1 = count; k < ref1; i = k += 1) {
|
|
805
|
-
results1.push(st_operation.toObject(object[i], debug));
|
|
806
|
-
}
|
|
807
|
-
return results1;
|
|
808
|
-
}
|
|
809
|
-
};
|
|
559
|
+
Types.time_point_sec = {
|
|
560
|
+
fromByteBuffer(b) {
|
|
561
|
+
return b.readUint32();
|
|
562
|
+
},
|
|
563
|
+
appendByteBuffer(b, object) {
|
|
564
|
+
if (typeof object !== "number") object = Types.time_point_sec.fromObject(object);
|
|
565
|
+
b.writeUint32(object);
|
|
566
|
+
return;
|
|
567
|
+
},
|
|
568
|
+
fromObject(object) {
|
|
569
|
+
v.required(object);
|
|
570
|
+
if (typeof object === "number") return object;
|
|
571
|
+
if (object.getTime) return Math.floor(object.getTime() / 1000);
|
|
572
|
+
if (typeof object !== "string") throw new Error("Unknown date type: " + object);
|
|
573
|
+
if (typeof object === "string" && !/Z$/.test(object)) object = object + "Z";
|
|
574
|
+
return Math.floor(new Date(object).getTime() / 1000);
|
|
575
|
+
},
|
|
576
|
+
toObject(object, debug = {}) {
|
|
577
|
+
if (debug.use_default && object === undefined) return new Date(0).toISOString().split('.')[0];
|
|
578
|
+
v.required(object);
|
|
579
|
+
if (typeof object === "string") return object;
|
|
580
|
+
if (object.getTime) return object.toISOString().split('.')[0];
|
|
581
|
+
var int = parseInt(object);
|
|
582
|
+
v.require_range(0, 0xFFFFFFFF, int, `uint32 ${object}`);
|
|
583
|
+
return new Date(int * 1000).toISOString().split('.')[0];
|
|
584
|
+
}
|
|
810
585
|
};
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
var
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
if (object.resolve !== undefined) {
|
|
824
|
-
object = object.resolve;
|
|
825
|
-
}
|
|
826
|
-
// convert 1.2.n into just n
|
|
827
|
-
if (/^[0-9]+\.[0-9]+\.[0-9]+$/.test(object)) {
|
|
828
|
-
object = v.get_instance(reserved_spaces, object_type, object);
|
|
829
|
-
}
|
|
830
|
-
b.writeVarint32(v.to_number(object));
|
|
831
|
-
return;
|
|
832
|
-
},
|
|
833
|
-
fromObject: function fromObject(object) {
|
|
834
|
-
v.required(object);
|
|
835
|
-
if (object.resolve !== undefined) {
|
|
836
|
-
object = object.resolve;
|
|
837
|
-
}
|
|
838
|
-
if (v.is_digits(object)) {
|
|
839
|
-
return v.to_number(object);
|
|
840
|
-
}
|
|
841
|
-
return v.get_instance(reserved_spaces, object_type, object);
|
|
842
|
-
},
|
|
843
|
-
toObject: function toObject(object) {
|
|
844
|
-
var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
845
|
-
|
|
846
|
-
var object_type_id = chain_types.object_type[object_type];
|
|
847
|
-
if (debug.use_default && object === undefined) {
|
|
848
|
-
return reserved_spaces + '.' + object_type_id + '.0';
|
|
849
|
-
}
|
|
850
|
-
v.required(object);
|
|
851
|
-
if (object.resolve !== undefined) {
|
|
852
|
-
object = object.resolve;
|
|
853
|
-
}
|
|
854
|
-
if (/^[0-9]+\.[0-9]+\.[0-9]+$/.test(object)) {
|
|
855
|
-
object = v.get_instance(reserved_spaces, object_type, object);
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
return reserved_spaces + '.' + object_type_id + '.' + object;
|
|
586
|
+
Types.set = function (st_operation) {
|
|
587
|
+
return {
|
|
588
|
+
validate(array) {
|
|
589
|
+
var dup_map = {};
|
|
590
|
+
for (var i = 0, o; i < array.length; i++) {
|
|
591
|
+
o = array[i];
|
|
592
|
+
var ref;
|
|
593
|
+
if (ref = typeof o, ['string', 'number'].indexOf(ref) >= 0) {
|
|
594
|
+
if (dup_map[o] !== undefined) {
|
|
595
|
+
throw new Error("duplicate (set)");
|
|
596
|
+
}
|
|
597
|
+
dup_map[o] = true;
|
|
859
598
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
Types.protocol_id_type = function (name) {
|
|
864
|
-
v.required(name, "name");
|
|
865
|
-
return id_type(chain_types.reserved_spaces.protocol_ids, name);
|
|
866
|
-
};
|
|
867
|
-
|
|
868
|
-
Types.object_id_type = {
|
|
869
|
-
fromByteBuffer: function fromByteBuffer(b) {
|
|
870
|
-
return ObjectId.fromByteBuffer(b);
|
|
599
|
+
}
|
|
600
|
+
return sortOperation(array, st_operation);
|
|
871
601
|
},
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
602
|
+
fromByteBuffer(b) {
|
|
603
|
+
var size = b.readVarint32();
|
|
604
|
+
if (HEX_DUMP) {
|
|
605
|
+
console.log("varint32 size = " + size.toString(16));
|
|
606
|
+
}
|
|
607
|
+
return this.validate((() => {
|
|
608
|
+
var result = [];
|
|
609
|
+
for (var i = 0; 0 < size ? i < size : i > size; 0 < size ? i++ : i++) {
|
|
610
|
+
result.push(st_operation.fromByteBuffer(b));
|
|
876
611
|
}
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
return;
|
|
612
|
+
return result;
|
|
613
|
+
})());
|
|
880
614
|
},
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
615
|
+
appendByteBuffer(b, object) {
|
|
616
|
+
if (!object) {
|
|
617
|
+
object = [];
|
|
618
|
+
}
|
|
619
|
+
b.writeVarint32(object.length);
|
|
620
|
+
var iterable = this.validate(object);
|
|
621
|
+
for (var i = 0, o; i < iterable.length; i++) {
|
|
622
|
+
o = iterable[i];
|
|
623
|
+
st_operation.appendByteBuffer(b, o);
|
|
624
|
+
}
|
|
625
|
+
return;
|
|
887
626
|
},
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
627
|
+
fromObject(object) {
|
|
628
|
+
if (!object) {
|
|
629
|
+
object = [];
|
|
630
|
+
}
|
|
631
|
+
return this.validate((() => {
|
|
632
|
+
var result = [];
|
|
633
|
+
for (var i = 0, o; i < object.length; i++) {
|
|
634
|
+
o = object[i];
|
|
635
|
+
result.push(st_operation.fromObject(o));
|
|
893
636
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
637
|
+
return result;
|
|
638
|
+
})());
|
|
639
|
+
},
|
|
640
|
+
toObject(object, debug = {}) {
|
|
641
|
+
if (debug.use_default && object === undefined) {
|
|
642
|
+
return [st_operation.toObject(object, debug)];
|
|
643
|
+
}
|
|
644
|
+
if (!object) {
|
|
645
|
+
object = [];
|
|
646
|
+
}
|
|
647
|
+
return this.validate((() => {
|
|
648
|
+
var result = [];
|
|
649
|
+
for (var i = 0, o; i < object.length; i++) {
|
|
650
|
+
o = object[i];
|
|
651
|
+
result.push(st_operation.toObject(o, debug));
|
|
897
652
|
}
|
|
898
|
-
|
|
899
|
-
|
|
653
|
+
return result;
|
|
654
|
+
})());
|
|
900
655
|
}
|
|
656
|
+
};
|
|
901
657
|
};
|
|
902
658
|
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
659
|
+
// global_parameters_update_operation current_fees
|
|
660
|
+
Types.fixed_array = function (count, st_operation) {
|
|
661
|
+
return {
|
|
662
|
+
fromByteBuffer: function (b) {
|
|
663
|
+
var i, j, ref, results;
|
|
664
|
+
results = [];
|
|
665
|
+
for (i = j = 0, ref = count; j < ref; i = j += 1) {
|
|
666
|
+
results.push(st_operation.fromByteBuffer(b));
|
|
667
|
+
}
|
|
668
|
+
return sortOperation(results, st_operation);
|
|
911
669
|
},
|
|
912
|
-
appendByteBuffer: function
|
|
670
|
+
appendByteBuffer: function (b, object) {
|
|
671
|
+
var i, j, ref;
|
|
672
|
+
if (count !== 0) {
|
|
913
673
|
v.required(object);
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
674
|
+
object = sortOperation(object, st_operation);
|
|
675
|
+
}
|
|
676
|
+
for (i = j = 0, ref = count; j < ref; i = j += 1) {
|
|
677
|
+
st_operation.appendByteBuffer(b, object[i]);
|
|
678
|
+
}
|
|
919
679
|
},
|
|
920
|
-
fromObject: function
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
_object$split2 = _slicedToArray(_object$split, 2),
|
|
931
|
-
type = _object$split2[0],
|
|
932
|
-
id = _object$split2[1];
|
|
933
|
-
|
|
934
|
-
v.require_range(0, 0xff, type, 'vote type ' + object);
|
|
935
|
-
v.require_range(0, 0xffffff, id, 'vote id ' + object);
|
|
936
|
-
return { type: type, id: id };
|
|
680
|
+
fromObject: function (object) {
|
|
681
|
+
var i, j, ref, results;
|
|
682
|
+
if (count !== 0) {
|
|
683
|
+
v.required(object);
|
|
684
|
+
}
|
|
685
|
+
results = [];
|
|
686
|
+
for (i = j = 0, ref = count; j < ref; i = j += 1) {
|
|
687
|
+
results.push(st_operation.fromObject(object[i]));
|
|
688
|
+
}
|
|
689
|
+
return results;
|
|
937
690
|
},
|
|
938
|
-
toObject: function
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
691
|
+
toObject: function (object, debug) {
|
|
692
|
+
var i, j, k, ref, ref1, results, results1;
|
|
693
|
+
if (debug == null) {
|
|
694
|
+
debug = {};
|
|
695
|
+
}
|
|
696
|
+
if (debug.use_default && object === void 0) {
|
|
697
|
+
results = [];
|
|
698
|
+
for (i = j = 0, ref = count; j < ref; i = j += 1) {
|
|
699
|
+
results.push(st_operation.toObject(void 0, debug));
|
|
943
700
|
}
|
|
701
|
+
return results;
|
|
702
|
+
}
|
|
703
|
+
if (count !== 0) {
|
|
944
704
|
v.required(object);
|
|
945
|
-
|
|
705
|
+
}
|
|
706
|
+
results1 = [];
|
|
707
|
+
for (i = k = 0, ref1 = count; k < ref1; i = k += 1) {
|
|
708
|
+
results1.push(st_operation.toObject(object[i], debug));
|
|
709
|
+
}
|
|
710
|
+
return results1;
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
};
|
|
946
714
|
|
|
947
|
-
|
|
715
|
+
/* Supports instance numbers (11) or object types (1.2.11). Object type
|
|
716
|
+
validation is enforced when an object type is used. */
|
|
717
|
+
var id_type = function (reserved_spaces, object_type) {
|
|
718
|
+
v.required(reserved_spaces, "reserved_spaces");
|
|
719
|
+
v.required(object_type, "object_type");
|
|
720
|
+
return {
|
|
721
|
+
fromByteBuffer(b) {
|
|
722
|
+
return b.readVarint32();
|
|
723
|
+
},
|
|
724
|
+
appendByteBuffer(b, object) {
|
|
725
|
+
v.required(object);
|
|
726
|
+
if (object.resolve !== undefined) {
|
|
727
|
+
object = object.resolve;
|
|
728
|
+
}
|
|
729
|
+
// convert 1.2.n into just n
|
|
730
|
+
if (/^[0-9]+\.[0-9]+\.[0-9]+$/.test(object)) {
|
|
731
|
+
object = v.get_instance(reserved_spaces, object_type, object);
|
|
732
|
+
}
|
|
733
|
+
b.writeVarint32(v.to_number(object));
|
|
734
|
+
return;
|
|
948
735
|
},
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
736
|
+
fromObject(object) {
|
|
737
|
+
v.required(object);
|
|
738
|
+
if (object.resolve !== undefined) {
|
|
739
|
+
object = object.resolve;
|
|
740
|
+
}
|
|
741
|
+
if (v.is_digits(object)) {
|
|
742
|
+
return v.to_number(object);
|
|
743
|
+
}
|
|
744
|
+
return v.get_instance(reserved_spaces, object_type, object);
|
|
745
|
+
},
|
|
746
|
+
toObject(object, debug = {}) {
|
|
747
|
+
var object_type_id = chain_types.object_type[object_type];
|
|
748
|
+
if (debug.use_default && object === undefined) {
|
|
749
|
+
return `${reserved_spaces}.${object_type_id}.0`;
|
|
750
|
+
}
|
|
751
|
+
v.required(object);
|
|
752
|
+
if (object.resolve !== undefined) {
|
|
753
|
+
object = object.resolve;
|
|
754
|
+
}
|
|
755
|
+
if (/^[0-9]+\.[0-9]+\.[0-9]+$/.test(object)) {
|
|
756
|
+
object = v.get_instance(reserved_spaces, object_type, object);
|
|
757
|
+
}
|
|
758
|
+
return `${reserved_spaces}.${object_type_id}.` + object;
|
|
953
759
|
}
|
|
760
|
+
};
|
|
954
761
|
};
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
return {
|
|
959
|
-
fromByteBuffer: function fromByteBuffer(b) {
|
|
960
|
-
if (!(b.readUint8() === 1)) {
|
|
961
|
-
return undefined;
|
|
962
|
-
}
|
|
963
|
-
return st_operation.fromByteBuffer(b);
|
|
964
|
-
},
|
|
965
|
-
appendByteBuffer: function appendByteBuffer(b, object) {
|
|
966
|
-
if (object !== null && object !== undefined) {
|
|
967
|
-
b.writeUint8(1);
|
|
968
|
-
st_operation.appendByteBuffer(b, object);
|
|
969
|
-
} else {
|
|
970
|
-
b.writeUint8(0);
|
|
971
|
-
}
|
|
972
|
-
return;
|
|
973
|
-
},
|
|
974
|
-
fromObject: function fromObject(object) {
|
|
975
|
-
if (object === undefined) {
|
|
976
|
-
return undefined;
|
|
977
|
-
}
|
|
978
|
-
return st_operation.fromObject(object);
|
|
979
|
-
},
|
|
980
|
-
toObject: function toObject(object) {
|
|
981
|
-
var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
982
|
-
|
|
983
|
-
// toObject is only null save if use_default is true
|
|
984
|
-
var result_object = function () {
|
|
985
|
-
if (!debug.use_default && object === undefined) {
|
|
986
|
-
return undefined;
|
|
987
|
-
} else {
|
|
988
|
-
return st_operation.toObject(object, debug);
|
|
989
|
-
}
|
|
990
|
-
}();
|
|
991
|
-
|
|
992
|
-
if (debug.annotate) {
|
|
993
|
-
if ((typeof result_object === 'undefined' ? 'undefined' : _typeof(result_object)) === "object") {
|
|
994
|
-
result_object.__optional = "parent is optional";
|
|
995
|
-
} else {
|
|
996
|
-
result_object = { __optional: result_object };
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
return result_object;
|
|
1000
|
-
}
|
|
1001
|
-
};
|
|
762
|
+
Types.protocol_id_type = function (name) {
|
|
763
|
+
v.required(name, "name");
|
|
764
|
+
return id_type(chain_types.reserved_spaces.protocol_ids, name);
|
|
1002
765
|
};
|
|
1003
|
-
|
|
1004
|
-
|
|
766
|
+
Types.object_id_type = {
|
|
767
|
+
fromByteBuffer(b) {
|
|
768
|
+
return ObjectId.fromByteBuffer(b);
|
|
769
|
+
},
|
|
770
|
+
appendByteBuffer(b, object) {
|
|
771
|
+
v.required(object);
|
|
772
|
+
if (object.resolve !== undefined) {
|
|
773
|
+
object = object.resolve;
|
|
774
|
+
}
|
|
775
|
+
object = ObjectId.fromString(object);
|
|
776
|
+
object.appendByteBuffer(b);
|
|
777
|
+
return;
|
|
778
|
+
},
|
|
779
|
+
fromObject(object) {
|
|
780
|
+
v.required(object);
|
|
781
|
+
if (object.resolve !== undefined) {
|
|
782
|
+
object = object.resolve;
|
|
783
|
+
}
|
|
784
|
+
return ObjectId.fromString(object);
|
|
785
|
+
},
|
|
786
|
+
toObject(object, debug = {}) {
|
|
787
|
+
if (debug.use_default && object === undefined) {
|
|
788
|
+
return "0.0.0";
|
|
789
|
+
}
|
|
790
|
+
v.required(object);
|
|
791
|
+
if (object.resolve !== undefined) {
|
|
792
|
+
object = object.resolve;
|
|
793
|
+
}
|
|
794
|
+
object = ObjectId.fromString(object);
|
|
795
|
+
return object.toString();
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
Types.vote_id = {
|
|
799
|
+
TYPE: 0x000000FF,
|
|
800
|
+
ID: 0xFFFFFF00,
|
|
801
|
+
fromByteBuffer(b) {
|
|
802
|
+
var value = b.readUint32();
|
|
1005
803
|
return {
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
opTypeId: function opTypeId(value) {
|
|
1009
|
-
var pos = 0,
|
|
1010
|
-
type_id = void 0;
|
|
1011
|
-
if (typeof value === "number") type_id = value;else {
|
|
1012
|
-
var _iteratorNormalCompletion = true;
|
|
1013
|
-
var _didIteratorError = false;
|
|
1014
|
-
var _iteratorError = undefined;
|
|
1015
|
-
|
|
1016
|
-
try {
|
|
1017
|
-
for (var _iterator = this.st_operations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
1018
|
-
var op = _step.value;
|
|
1019
|
-
|
|
1020
|
-
if (op.operation_name === value) {
|
|
1021
|
-
type_id = pos;
|
|
1022
|
-
break;
|
|
1023
|
-
}
|
|
1024
|
-
pos++;
|
|
1025
|
-
}
|
|
1026
|
-
} catch (err) {
|
|
1027
|
-
_didIteratorError = true;
|
|
1028
|
-
_iteratorError = err;
|
|
1029
|
-
} finally {
|
|
1030
|
-
try {
|
|
1031
|
-
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
1032
|
-
_iterator.return();
|
|
1033
|
-
}
|
|
1034
|
-
} finally {
|
|
1035
|
-
if (_didIteratorError) {
|
|
1036
|
-
throw _iteratorError;
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
return type_id;
|
|
1042
|
-
},
|
|
1043
|
-
fromByteBuffer: function fromByteBuffer(b) {
|
|
1044
|
-
var type_id = b.readVarint32();
|
|
1045
|
-
var st_operation = this.st_operations[type_id];
|
|
1046
|
-
if (HEX_DUMP) {
|
|
1047
|
-
console.error('static_variant id 0x' + type_id.toString(16) + ' (' + type_id + ')');
|
|
1048
|
-
}
|
|
1049
|
-
v.required(st_operation, 'operation ' + type_id);
|
|
1050
|
-
return [type_id, st_operation.fromByteBuffer(b)];
|
|
1051
|
-
},
|
|
1052
|
-
appendByteBuffer: function appendByteBuffer(b, object) {
|
|
1053
|
-
v.required(object);
|
|
1054
|
-
var type_id = this.opTypeId(object[0]);
|
|
1055
|
-
var st_operation = this.st_operations[type_id];
|
|
1056
|
-
v.required(st_operation, 'operation ' + type_id);
|
|
1057
|
-
b.writeVarint32(type_id);
|
|
1058
|
-
st_operation.appendByteBuffer(b, object[1]);
|
|
1059
|
-
return;
|
|
1060
|
-
},
|
|
1061
|
-
fromObject: function fromObject(object) {
|
|
1062
|
-
v.required(object);
|
|
1063
|
-
var type_id = this.opTypeId(object[0]);
|
|
1064
|
-
var st_operation = this.st_operations[type_id];
|
|
1065
|
-
v.required(st_operation, 'operation ' + type_id);
|
|
1066
|
-
return [type_id, st_operation.fromObject(object[1])];
|
|
1067
|
-
},
|
|
1068
|
-
toObject: function toObject(object) {
|
|
1069
|
-
var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1070
|
-
|
|
1071
|
-
if (debug.use_default && object === undefined) {
|
|
1072
|
-
return [this.st_operations[0].operation_name, this.st_operations[0].toObject(undefined, debug)];
|
|
1073
|
-
}
|
|
1074
|
-
v.required(object);
|
|
1075
|
-
var type_id = this.opTypeId(object[0]);
|
|
1076
|
-
var st_operation = this.st_operations[type_id];
|
|
1077
|
-
v.required(st_operation, 'operation ' + type_id);
|
|
1078
|
-
return [st_operation.operation_name, st_operation.toObject(object[1], debug)];
|
|
1079
|
-
},
|
|
1080
|
-
compare: function compare(a, b) {
|
|
1081
|
-
return strCmp(this.opTypeId(a[0]), this.opTypeId(b[0]));
|
|
1082
|
-
}
|
|
804
|
+
type: value & this.TYPE,
|
|
805
|
+
id: value & this.ID
|
|
1083
806
|
};
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
|
|
807
|
+
},
|
|
808
|
+
appendByteBuffer(b, object) {
|
|
809
|
+
v.required(object);
|
|
810
|
+
if (object === "string") object = Types.vote_id.fromObject(object);
|
|
811
|
+
var value = object.id << 8 | object.type;
|
|
812
|
+
b.writeUint32(value);
|
|
813
|
+
return;
|
|
814
|
+
},
|
|
815
|
+
fromObject(object) {
|
|
816
|
+
v.required(object, "(type vote_id)");
|
|
817
|
+
if (typeof object === "object") {
|
|
818
|
+
v.required(object.type, "type");
|
|
819
|
+
v.required(object.id, "id");
|
|
820
|
+
return object;
|
|
821
|
+
}
|
|
822
|
+
v.require_test(/^[0-9]+:[0-9]+$/, object, `vote_id format ${object}`);
|
|
823
|
+
var [type, id] = object.split(':');
|
|
824
|
+
v.require_range(0, 0xff, type, `vote type ${object}`);
|
|
825
|
+
v.require_range(0, 0xffffff, id, `vote id ${object}`);
|
|
1087
826
|
return {
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
throw new Error("expecting array");
|
|
1091
|
-
}
|
|
1092
|
-
var dup_map = {};
|
|
1093
|
-
for (var i = 0, o; i < array.length; i++) {
|
|
1094
|
-
o = array[i];
|
|
1095
|
-
var ref;
|
|
1096
|
-
if (!(o.length === 2)) {
|
|
1097
|
-
throw new Error("expecting two elements");
|
|
1098
|
-
}
|
|
1099
|
-
if (ref = _typeof(o[0]), ['number', 'string'].indexOf(ref) >= 0) {
|
|
1100
|
-
if (dup_map[o[0]] !== undefined) {
|
|
1101
|
-
throw new Error("duplicate (map)");
|
|
1102
|
-
}
|
|
1103
|
-
dup_map[o[0]] = true;
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
return sortOperation(array, key_st_operation);
|
|
1107
|
-
},
|
|
1108
|
-
fromByteBuffer: function fromByteBuffer(b) {
|
|
1109
|
-
var result = [];
|
|
1110
|
-
var end = b.readVarint32();
|
|
1111
|
-
for (var i = 0; 0 < end ? i < end : i > end; 0 < end ? i++ : i++) {
|
|
1112
|
-
result.push([key_st_operation.fromByteBuffer(b), value_st_operation.fromByteBuffer(b)]);
|
|
1113
|
-
}
|
|
1114
|
-
return this.validate(result);
|
|
1115
|
-
},
|
|
1116
|
-
appendByteBuffer: function appendByteBuffer(b, object) {
|
|
1117
|
-
this.validate(object);
|
|
1118
|
-
b.writeVarint32(object.length);
|
|
1119
|
-
for (var i = 0, o; i < object.length; i++) {
|
|
1120
|
-
o = object[i];
|
|
1121
|
-
key_st_operation.appendByteBuffer(b, o[0]);
|
|
1122
|
-
value_st_operation.appendByteBuffer(b, o[1]);
|
|
1123
|
-
}
|
|
1124
|
-
return;
|
|
1125
|
-
},
|
|
1126
|
-
fromObject: function fromObject(object) {
|
|
1127
|
-
v.required(object);
|
|
1128
|
-
var result = [];
|
|
1129
|
-
for (var i = 0, o; i < object.length; i++) {
|
|
1130
|
-
o = object[i];
|
|
1131
|
-
result.push([key_st_operation.fromObject(o[0]), value_st_operation.fromObject(o[1])]);
|
|
1132
|
-
}
|
|
1133
|
-
return this.validate(result);
|
|
1134
|
-
},
|
|
1135
|
-
toObject: function toObject(object) {
|
|
1136
|
-
var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1137
|
-
|
|
1138
|
-
if (debug.use_default && object === undefined) {
|
|
1139
|
-
return [[key_st_operation.toObject(undefined, debug), value_st_operation.toObject(undefined, debug)]];
|
|
1140
|
-
}
|
|
1141
|
-
v.required(object);
|
|
1142
|
-
object = this.validate(object);
|
|
1143
|
-
var result = [];
|
|
1144
|
-
for (var i = 0, o; i < object.length; i++) {
|
|
1145
|
-
o = object[i];
|
|
1146
|
-
result.push([key_st_operation.toObject(o[0], debug), value_st_operation.toObject(o[1], debug)]);
|
|
1147
|
-
}
|
|
1148
|
-
return result;
|
|
1149
|
-
}
|
|
827
|
+
type,
|
|
828
|
+
id
|
|
1150
829
|
};
|
|
830
|
+
},
|
|
831
|
+
toObject(object, debug = {}) {
|
|
832
|
+
if (debug.use_default && object === undefined) {
|
|
833
|
+
return "0:0";
|
|
834
|
+
}
|
|
835
|
+
v.required(object);
|
|
836
|
+
if (typeof object === "string") object = Types.vote_id.fromObject(object);
|
|
837
|
+
return object.type + ":" + object.id;
|
|
838
|
+
},
|
|
839
|
+
compare(a, b) {
|
|
840
|
+
if (typeof a !== "object") a = Types.vote_id.fromObject(a);
|
|
841
|
+
if (typeof b !== "object") b = Types.vote_id.fromObject(b);
|
|
842
|
+
return parseInt(a.id) - parseInt(b.id);
|
|
843
|
+
}
|
|
1151
844
|
};
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
845
|
+
Types.optional = function (st_operation) {
|
|
846
|
+
v.required(st_operation, "st_operation");
|
|
847
|
+
return {
|
|
848
|
+
fromByteBuffer(b) {
|
|
849
|
+
if (!(b.readUint8() === 1)) {
|
|
850
|
+
return undefined;
|
|
851
|
+
}
|
|
852
|
+
return st_operation.fromByteBuffer(b);
|
|
1159
853
|
},
|
|
1160
|
-
|
|
1161
|
-
|
|
854
|
+
appendByteBuffer(b, object) {
|
|
855
|
+
if (object !== null && object !== undefined) {
|
|
856
|
+
b.writeUint8(1);
|
|
857
|
+
st_operation.appendByteBuffer(b, object);
|
|
858
|
+
} else {
|
|
859
|
+
b.writeUint8(0);
|
|
860
|
+
}
|
|
861
|
+
return;
|
|
1162
862
|
},
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
863
|
+
fromObject(object) {
|
|
864
|
+
if (object === undefined) {
|
|
865
|
+
return undefined;
|
|
866
|
+
}
|
|
867
|
+
return st_operation.fromObject(object);
|
|
1167
868
|
},
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
869
|
+
toObject(object, debug = {}) {
|
|
870
|
+
// toObject is only null save if use_default is true
|
|
871
|
+
var result_object = (() => {
|
|
872
|
+
if (!debug.use_default && object === undefined) {
|
|
873
|
+
return undefined;
|
|
874
|
+
} else {
|
|
875
|
+
return st_operation.toObject(object, debug);
|
|
1172
876
|
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
877
|
+
})();
|
|
878
|
+
if (debug.annotate) {
|
|
879
|
+
if (typeof result_object === "object") {
|
|
880
|
+
result_object.__optional = "parent is optional";
|
|
881
|
+
} else {
|
|
882
|
+
result_object = {
|
|
883
|
+
__optional: result_object
|
|
884
|
+
};
|
|
1180
885
|
}
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
},
|
|
1184
|
-
compare: function compare(a, b) {
|
|
1185
|
-
// sort ascending
|
|
1186
|
-
return 1 * strCmp(a.toString(), b.toString());
|
|
886
|
+
}
|
|
887
|
+
return result_object;
|
|
1187
888
|
}
|
|
889
|
+
};
|
|
1188
890
|
};
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
891
|
+
Types.static_variant = function (_st_operations) {
|
|
892
|
+
return {
|
|
893
|
+
nosort: true,
|
|
894
|
+
st_operations: _st_operations,
|
|
895
|
+
opTypeId(value) {
|
|
896
|
+
let pos = 0,
|
|
897
|
+
type_id;
|
|
898
|
+
if (typeof value === "number") type_id = value;else {
|
|
899
|
+
for (let op of this.st_operations) {
|
|
900
|
+
if (op.operation_name === value) {
|
|
901
|
+
type_id = pos;
|
|
902
|
+
break;
|
|
903
|
+
}
|
|
904
|
+
pos++;
|
|
1195
905
|
}
|
|
1196
|
-
|
|
906
|
+
}
|
|
907
|
+
return type_id;
|
|
1197
908
|
},
|
|
1198
|
-
fromByteBuffer
|
|
1199
|
-
|
|
909
|
+
fromByteBuffer(b) {
|
|
910
|
+
var type_id = b.readVarint32();
|
|
911
|
+
var st_operation = this.st_operations[type_id];
|
|
912
|
+
if (HEX_DUMP) {
|
|
913
|
+
console.error(`static_variant id 0x${type_id.toString(16)} (${type_id})`);
|
|
914
|
+
}
|
|
915
|
+
v.required(st_operation, `operation ${type_id}`);
|
|
916
|
+
return [type_id, st_operation.fromByteBuffer(b)];
|
|
1200
917
|
},
|
|
1201
|
-
appendByteBuffer
|
|
1202
|
-
|
|
1203
|
-
|
|
918
|
+
appendByteBuffer(b, object) {
|
|
919
|
+
v.required(object);
|
|
920
|
+
var type_id = this.opTypeId(object[0]);
|
|
921
|
+
var st_operation = this.st_operations[type_id];
|
|
922
|
+
v.required(st_operation, `operation ${type_id}`);
|
|
923
|
+
b.writeVarint32(type_id);
|
|
924
|
+
st_operation.appendByteBuffer(b, object[1]);
|
|
925
|
+
return;
|
|
1204
926
|
},
|
|
1205
|
-
fromObject
|
|
1206
|
-
|
|
927
|
+
fromObject(object) {
|
|
928
|
+
v.required(object);
|
|
929
|
+
let type_id = this.opTypeId(object[0]);
|
|
930
|
+
var st_operation = this.st_operations[type_id];
|
|
931
|
+
v.required(st_operation, `operation ${type_id}`);
|
|
932
|
+
return [type_id, st_operation.fromObject(object[1])];
|
|
1207
933
|
},
|
|
1208
|
-
toObject
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
934
|
+
toObject(object, debug = {}) {
|
|
935
|
+
if (debug.use_default && object === undefined) {
|
|
936
|
+
return [this.st_operations[0].operation_name, this.st_operations[0].toObject(undefined, debug)];
|
|
937
|
+
}
|
|
938
|
+
v.required(object);
|
|
939
|
+
let type_id = this.opTypeId(object[0]);
|
|
940
|
+
var st_operation = this.st_operations[type_id];
|
|
941
|
+
v.required(st_operation, `operation ${type_id}`);
|
|
942
|
+
return [st_operation.operation_name, st_operation.toObject(object[1], debug)];
|
|
943
|
+
},
|
|
944
|
+
compare(a, b) {
|
|
945
|
+
return strCmp(this.opTypeId(a[0]), this.opTypeId(b[0]));
|
|
946
|
+
}
|
|
947
|
+
};
|
|
948
|
+
};
|
|
949
|
+
Types.map = function (key_st_operation, value_st_operation) {
|
|
950
|
+
return {
|
|
951
|
+
validate(array) {
|
|
952
|
+
if (!Array.isArray(array)) {
|
|
953
|
+
throw new Error("expecting array");
|
|
954
|
+
}
|
|
955
|
+
var dup_map = {};
|
|
956
|
+
for (var i = 0, o; i < array.length; i++) {
|
|
957
|
+
o = array[i];
|
|
958
|
+
var ref;
|
|
959
|
+
if (!(o.length === 2)) {
|
|
960
|
+
throw new Error("expecting two elements");
|
|
1213
961
|
}
|
|
1214
|
-
|
|
962
|
+
if (ref = typeof o[0], ['number', 'string'].indexOf(ref) >= 0) {
|
|
963
|
+
if (dup_map[o[0]] !== undefined) {
|
|
964
|
+
throw new Error("duplicate (map)");
|
|
965
|
+
}
|
|
966
|
+
dup_map[o[0]] = true;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
return sortOperation(array, key_st_operation);
|
|
970
|
+
},
|
|
971
|
+
fromByteBuffer(b) {
|
|
972
|
+
var result = [];
|
|
973
|
+
var end = b.readVarint32();
|
|
974
|
+
for (var i = 0; 0 < end ? i < end : i > end; 0 < end ? i++ : i++) {
|
|
975
|
+
result.push([key_st_operation.fromByteBuffer(b), value_st_operation.fromByteBuffer(b)]);
|
|
976
|
+
}
|
|
977
|
+
return this.validate(result);
|
|
978
|
+
},
|
|
979
|
+
appendByteBuffer(b, object) {
|
|
980
|
+
this.validate(object);
|
|
981
|
+
b.writeVarint32(object.length);
|
|
982
|
+
for (var i = 0, o; i < object.length; i++) {
|
|
983
|
+
o = object[i];
|
|
984
|
+
key_st_operation.appendByteBuffer(b, o[0]);
|
|
985
|
+
value_st_operation.appendByteBuffer(b, o[1]);
|
|
986
|
+
}
|
|
987
|
+
return;
|
|
988
|
+
},
|
|
989
|
+
fromObject(object) {
|
|
990
|
+
v.required(object);
|
|
991
|
+
var result = [];
|
|
992
|
+
for (var i = 0, o; i < object.length; i++) {
|
|
993
|
+
o = object[i];
|
|
994
|
+
result.push([key_st_operation.fromObject(o[0]), value_st_operation.fromObject(o[1])]);
|
|
995
|
+
}
|
|
996
|
+
return this.validate(result);
|
|
1215
997
|
},
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
return
|
|
998
|
+
toObject(object, debug = {}) {
|
|
999
|
+
if (debug.use_default && object === undefined) {
|
|
1000
|
+
return [[key_st_operation.toObject(undefined, debug), value_st_operation.toObject(undefined, debug)]];
|
|
1001
|
+
}
|
|
1002
|
+
v.required(object);
|
|
1003
|
+
object = this.validate(object);
|
|
1004
|
+
var result = [];
|
|
1005
|
+
for (var i = 0, o; i < object.length; i++) {
|
|
1006
|
+
o = object[i];
|
|
1007
|
+
result.push([key_st_operation.toObject(o[0], debug), value_st_operation.toObject(o[1], debug)]);
|
|
1008
|
+
}
|
|
1009
|
+
return result;
|
|
1219
1010
|
}
|
|
1011
|
+
};
|
|
1220
1012
|
};
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1013
|
+
Types.public_key = {
|
|
1014
|
+
toPublic(object) {
|
|
1015
|
+
if (object.resolve !== undefined) {
|
|
1016
|
+
object = object.resolve;
|
|
1017
|
+
}
|
|
1018
|
+
return object == null ? object : object.Q ? object : PublicKey.fromStringOrThrow(object);
|
|
1019
|
+
},
|
|
1020
|
+
fromByteBuffer(b) {
|
|
1021
|
+
return fp.public_key(b);
|
|
1022
|
+
},
|
|
1023
|
+
appendByteBuffer(b, object) {
|
|
1024
|
+
v.required(object);
|
|
1025
|
+
fp.public_key(b, Types.public_key.toPublic(object));
|
|
1026
|
+
return;
|
|
1027
|
+
},
|
|
1028
|
+
fromObject(object) {
|
|
1029
|
+
v.required(object);
|
|
1030
|
+
if (object.Q) {
|
|
1031
|
+
return object;
|
|
1032
|
+
}
|
|
1033
|
+
return Types.public_key.toPublic(object);
|
|
1034
|
+
},
|
|
1035
|
+
toObject(object, debug = {}) {
|
|
1036
|
+
if (debug.use_default && object === undefined) {
|
|
1037
|
+
return ecc_config.get('address_prefix') + "859gxfnXyUriMgUeThh1fWv3oqcpLFyHa3TfFYC4PK2HqhToVM";
|
|
1038
|
+
}
|
|
1039
|
+
v.required(object);
|
|
1040
|
+
return object.toString();
|
|
1041
|
+
},
|
|
1042
|
+
compare(a, b) {
|
|
1043
|
+
// sort ascending
|
|
1044
|
+
return 1 * strCmp(a.toString(), b.toString());
|
|
1045
|
+
}
|
|
1224
1046
|
};
|
|
1225
|
-
|
|
1226
|
-
|
|
1047
|
+
Types.address = {
|
|
1048
|
+
_to_address(object) {
|
|
1049
|
+
v.required(object);
|
|
1050
|
+
if (object.addy) {
|
|
1051
|
+
return object;
|
|
1052
|
+
}
|
|
1053
|
+
return Address.fromString(object);
|
|
1054
|
+
},
|
|
1055
|
+
fromByteBuffer(b) {
|
|
1056
|
+
return new Address(fp.ripemd160(b));
|
|
1057
|
+
},
|
|
1058
|
+
appendByteBuffer(b, object) {
|
|
1059
|
+
fp.ripemd160(b, Types.address._to_address(object).toBuffer());
|
|
1060
|
+
return;
|
|
1061
|
+
},
|
|
1062
|
+
fromObject(object) {
|
|
1063
|
+
return Types.address._to_address(object);
|
|
1064
|
+
},
|
|
1065
|
+
toObject(object, debug = {}) {
|
|
1066
|
+
if (debug.use_default && object === undefined) {
|
|
1067
|
+
return ecc_config.get('address_prefix') + "664KmHxSuQyDsfwo4WEJvWpzg1QKdg67S";
|
|
1068
|
+
}
|
|
1069
|
+
return Types.address._to_address(object).toString();
|
|
1070
|
+
},
|
|
1071
|
+
compare(a, b) {
|
|
1072
|
+
// sort decending
|
|
1073
|
+
return -1 * strCmp(a.toString(), b.toString());
|
|
1074
|
+
}
|
|
1227
1075
|
};
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
});
|
|
1076
|
+
let strCmp = (a, b) => a > b ? 1 : a < b ? -1 : 0;
|
|
1077
|
+
let firstEl = el => Array.isArray(el) ? el[0] : el;
|
|
1078
|
+
let sortOperation = (array, st_operation) => {
|
|
1079
|
+
// console.log('operation.nosort', st_operation.nosort)
|
|
1080
|
+
return st_operation.nosort ? array : st_operation.compare ? array.sort((a, b) => st_operation.compare(firstEl(a), firstEl(b))) :
|
|
1081
|
+
// custom compare operation
|
|
1082
|
+
array.sort((a, b) => typeof firstEl(a) === "number" && typeof firstEl(b) === "number" ? firstEl(a) - firstEl(b) :
|
|
1083
|
+
// A binary string compare does not work. Performanance is very good so HEX is used.. localeCompare is another option.
|
|
1084
|
+
Buffer.isBuffer(firstEl(a)) && Buffer.isBuffer(firstEl(b)) ? strCmp(firstEl(a).toString("hex"), firstEl(b).toString("hex")) : strCmp(firstEl(a).toString(), firstEl(b).toString()));
|
|
1238
1085
|
};
|