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