@atomichub/atomicassets 2.0.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/LICENSE +23 -0
- package/NOTICE +12 -0
- package/README.md +129 -0
- package/build/atomicassets.global.js +2730 -0
- package/build/index.cjs +2768 -0
- package/build/index.cjs.map +1 -0
- package/build/index.d.mts +1149 -0
- package/build/index.d.ts +1149 -0
- package/build/index.mjs +2708 -0
- package/build/index.mjs.map +1 -0
- package/licenses/Apache-2.0.txt +202 -0
- package/package.json +72 -0
|
@@ -0,0 +1,2730 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var atomicassets = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
|
|
24
|
+
// lib/float.js
|
|
25
|
+
var require_float = __commonJS({
|
|
26
|
+
"lib/float.js"(exports, module) {
|
|
27
|
+
"use strict";
|
|
28
|
+
var isBigeCpu = false;
|
|
29
|
+
var readFloat32Array;
|
|
30
|
+
var writeFloat32Array;
|
|
31
|
+
var readFloat32ArrayRev;
|
|
32
|
+
var writeFloat32ArrayRev;
|
|
33
|
+
var readFloat64Array;
|
|
34
|
+
var writeFloat64Array;
|
|
35
|
+
var readFloat64ArrayRev;
|
|
36
|
+
var writeFloat64ArrayRev;
|
|
37
|
+
typeof Float32Array === "function" && (function() {
|
|
38
|
+
var _fp32 = new Float32Array(1);
|
|
39
|
+
var _b32 = new Uint8Array(_fp32.buffer);
|
|
40
|
+
_fp32[0] = -1;
|
|
41
|
+
isBigeCpu = _b32[3] === 0;
|
|
42
|
+
readFloat32Array = function readFloat32Array2(buf, pos) {
|
|
43
|
+
pos = pos || 0;
|
|
44
|
+
if (pos < 0 || pos + 4 > buf.length) return 0;
|
|
45
|
+
_b32[0] = buf[pos++];
|
|
46
|
+
_b32[1] = buf[pos++];
|
|
47
|
+
_b32[2] = buf[pos++];
|
|
48
|
+
_b32[3] = buf[pos];
|
|
49
|
+
return _fp32[0];
|
|
50
|
+
};
|
|
51
|
+
readFloat32ArrayRev = function readFloat32ArrayRev2(buf, pos) {
|
|
52
|
+
pos = pos || 0;
|
|
53
|
+
if (pos < 0 || pos + 4 > buf.length) return 0;
|
|
54
|
+
_b32[3] = buf[pos++];
|
|
55
|
+
_b32[2] = buf[pos++];
|
|
56
|
+
_b32[1] = buf[pos++];
|
|
57
|
+
_b32[0] = buf[pos];
|
|
58
|
+
return _fp32[0];
|
|
59
|
+
};
|
|
60
|
+
writeFloat32Array = function writeFloat32Array2(buf, v, pos) {
|
|
61
|
+
pos = pos || 0;
|
|
62
|
+
_fp32[0] = v;
|
|
63
|
+
buf[pos++] = _b32[0];
|
|
64
|
+
buf[pos++] = _b32[1];
|
|
65
|
+
buf[pos++] = _b32[2];
|
|
66
|
+
buf[pos] = _b32[3];
|
|
67
|
+
};
|
|
68
|
+
writeFloat32ArrayRev = function writeFloat32ArrayRev2(buf, v, pos) {
|
|
69
|
+
pos = pos || 0;
|
|
70
|
+
_fp32[0] = v;
|
|
71
|
+
buf[pos++] = _b32[3];
|
|
72
|
+
buf[pos++] = _b32[2];
|
|
73
|
+
buf[pos++] = _b32[1];
|
|
74
|
+
buf[pos] = _b32[0];
|
|
75
|
+
};
|
|
76
|
+
})();
|
|
77
|
+
typeof Float64Array === "function" && (function() {
|
|
78
|
+
var _fp64 = new Float64Array(1);
|
|
79
|
+
var _b64 = new Uint8Array(_fp64.buffer);
|
|
80
|
+
readFloat64Array = function readFloat64Array2(buf, pos) {
|
|
81
|
+
pos = pos || 0;
|
|
82
|
+
if (pos < 0 || pos + 8 > buf.length) return 0;
|
|
83
|
+
_b64[0] = buf[pos + 0];
|
|
84
|
+
_b64[1] = buf[pos + 1];
|
|
85
|
+
_b64[2] = buf[pos + 2];
|
|
86
|
+
_b64[3] = buf[pos + 3];
|
|
87
|
+
_b64[4] = buf[pos + 4];
|
|
88
|
+
_b64[5] = buf[pos + 5];
|
|
89
|
+
_b64[6] = buf[pos + 6];
|
|
90
|
+
_b64[7] = buf[pos + 7];
|
|
91
|
+
return _fp64[0];
|
|
92
|
+
};
|
|
93
|
+
readFloat64ArrayRev = function readFloat64ArrayRev2(buf, pos) {
|
|
94
|
+
pos = pos || 0;
|
|
95
|
+
if (pos < 0 || pos + 8 > buf.length) return 0;
|
|
96
|
+
_b64[7] = buf[pos + 0];
|
|
97
|
+
_b64[6] = buf[pos + 1];
|
|
98
|
+
_b64[5] = buf[pos + 2];
|
|
99
|
+
_b64[4] = buf[pos + 3];
|
|
100
|
+
_b64[3] = buf[pos + 4];
|
|
101
|
+
_b64[2] = buf[pos + 5];
|
|
102
|
+
_b64[1] = buf[pos + 6];
|
|
103
|
+
_b64[0] = buf[pos + 7];
|
|
104
|
+
return _fp64[0];
|
|
105
|
+
};
|
|
106
|
+
writeFloat64Array = function writeFloat64Array2(buf, v, pos) {
|
|
107
|
+
pos = pos || 0;
|
|
108
|
+
_fp64[0] = v;
|
|
109
|
+
buf[pos + 0] = _b64[0];
|
|
110
|
+
buf[pos + 1] = _b64[1];
|
|
111
|
+
buf[pos + 2] = _b64[2];
|
|
112
|
+
buf[pos + 3] = _b64[3];
|
|
113
|
+
buf[pos + 4] = _b64[4];
|
|
114
|
+
buf[pos + 5] = _b64[5];
|
|
115
|
+
buf[pos + 6] = _b64[6];
|
|
116
|
+
buf[pos + 7] = _b64[7];
|
|
117
|
+
};
|
|
118
|
+
writeFloat64ArrayRev = function writeFloat64ArrayRev2(buf, v, pos) {
|
|
119
|
+
pos = pos || 0;
|
|
120
|
+
_fp64[0] = v;
|
|
121
|
+
buf[pos + 0] = _b64[7];
|
|
122
|
+
buf[pos + 1] = _b64[6];
|
|
123
|
+
buf[pos + 2] = _b64[5];
|
|
124
|
+
buf[pos + 3] = _b64[4];
|
|
125
|
+
buf[pos + 4] = _b64[3];
|
|
126
|
+
buf[pos + 5] = _b64[2];
|
|
127
|
+
buf[pos + 6] = _b64[1];
|
|
128
|
+
buf[pos + 7] = _b64[0];
|
|
129
|
+
};
|
|
130
|
+
})();
|
|
131
|
+
function readWord(buf, offs, dirn) {
|
|
132
|
+
var a = buf[offs++], b = buf[offs++], c = buf[offs++], d = buf[offs];
|
|
133
|
+
return dirn === "bige" ? ((a * 256 + b) * 256 + c) * 256 + d : ((d * 256 + c) * 256 + b) * 256 + a;
|
|
134
|
+
}
|
|
135
|
+
function writeWord(buf, v, offs, dirn) {
|
|
136
|
+
var a = v >>> 24 & 255, b = v >> 16 & 255, c = v >> 8 & 255, d = v & 255;
|
|
137
|
+
dirn === "bige" ? (buf[offs++] = a, buf[offs++] = b, buf[offs++] = c, buf[offs] = d) : (buf[offs++] = d, buf[offs++] = c, buf[offs++] = b, buf[offs] = a);
|
|
138
|
+
}
|
|
139
|
+
function writeDoubleWord(buf, hi, lo, offs, dirn) {
|
|
140
|
+
if (dirn === "bige") {
|
|
141
|
+
writeWord(buf, hi, offs, dirn);
|
|
142
|
+
writeWord(buf, lo, offs + 4, dirn);
|
|
143
|
+
} else {
|
|
144
|
+
writeWord(buf, lo, offs, dirn);
|
|
145
|
+
writeWord(buf, hi, offs + 4, dirn);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
var _2eXp = new Array();
|
|
149
|
+
for (i = 0; i < 1200; i++) _2eXp[i] = Math.pow(2, i);
|
|
150
|
+
var i;
|
|
151
|
+
var _2eXn = new Array();
|
|
152
|
+
for (i = 0; i < 1200; i++) _2eXn[i] = Math.pow(2, -i);
|
|
153
|
+
var i;
|
|
154
|
+
function pow2(exp) {
|
|
155
|
+
return exp >= 0 ? _2eXp[exp] : _2eXn[-exp];
|
|
156
|
+
}
|
|
157
|
+
var _rshift32 = 1 / 4294967296;
|
|
158
|
+
var _rshift20 = 1 / 1048576;
|
|
159
|
+
var _lshift32 = 1 * 4294967296;
|
|
160
|
+
var _rshift52 = 1 * _rshift32 * _rshift20;
|
|
161
|
+
var _rshift1023 = pow2(-1023);
|
|
162
|
+
function readDouble(buf, offset, dirn) {
|
|
163
|
+
var w0 = readWord(buf, offset, dirn);
|
|
164
|
+
var w1 = readWord(buf, offset + 4, dirn);
|
|
165
|
+
var highWord, lowWord;
|
|
166
|
+
dirn === "bige" ? (highWord = w0, lowWord = w1) : (highWord = w1, lowWord = w0);
|
|
167
|
+
var mantissa = (highWord & 1048575) * _lshift32 + lowWord;
|
|
168
|
+
var exponent = (highWord & 2146435072) >>> 20;
|
|
169
|
+
var sign = highWord >> 31 || 1;
|
|
170
|
+
var value;
|
|
171
|
+
if (exponent === 0) {
|
|
172
|
+
value = mantissa ? mantissa * pow2(-52 + 1 - 1023) : 0;
|
|
173
|
+
} else if (exponent < 2047) {
|
|
174
|
+
value = mantissa >= 0 ? (1 + mantissa * _rshift52) * pow2(exponent - 1023) : 0;
|
|
175
|
+
} else {
|
|
176
|
+
value = mantissa ? NaN : Infinity;
|
|
177
|
+
}
|
|
178
|
+
return sign * value;
|
|
179
|
+
}
|
|
180
|
+
var _rshift23 = Math.pow(2, -23);
|
|
181
|
+
var _rshift127 = Math.pow(2, -127);
|
|
182
|
+
function readFloat(buf, offset, dirn) {
|
|
183
|
+
var word = readWord(buf, offset, dirn);
|
|
184
|
+
var mantissa = word & 8388607;
|
|
185
|
+
var exponent = (word & 2139095040) >>> 23;
|
|
186
|
+
var sign = word >> 31 || 1;
|
|
187
|
+
var value;
|
|
188
|
+
if (exponent === 0) {
|
|
189
|
+
value = mantissa ? mantissa * _rshift23 * 2 * _rshift127 : 0;
|
|
190
|
+
} else if (exponent < 255) {
|
|
191
|
+
value = (1 + mantissa * _rshift23) * pow2(exponent - 127);
|
|
192
|
+
} else {
|
|
193
|
+
value = mantissa ? NaN : Infinity;
|
|
194
|
+
}
|
|
195
|
+
return sign * value;
|
|
196
|
+
}
|
|
197
|
+
var _parts = { exp: 0, mant: 0 };
|
|
198
|
+
function normalize(v) {
|
|
199
|
+
var exp = 0;
|
|
200
|
+
if (v >= 2) {
|
|
201
|
+
exp = countDoublings(1, v);
|
|
202
|
+
v *= pow2(-exp);
|
|
203
|
+
if (v >= 2) {
|
|
204
|
+
v /= 2;
|
|
205
|
+
exp += 1;
|
|
206
|
+
}
|
|
207
|
+
} else if (v < 1) {
|
|
208
|
+
exp = countDoublings(v, 2);
|
|
209
|
+
if (exp <= 1023) v *= pow2(exp);
|
|
210
|
+
else {
|
|
211
|
+
v *= pow2(exp - 100);
|
|
212
|
+
v *= pow2(100);
|
|
213
|
+
}
|
|
214
|
+
exp = -exp;
|
|
215
|
+
}
|
|
216
|
+
_parts.exp = exp;
|
|
217
|
+
_parts.mant = v;
|
|
218
|
+
return _parts;
|
|
219
|
+
}
|
|
220
|
+
var _2e192 = Math.pow(2, 192);
|
|
221
|
+
function countDoublings(a, b) {
|
|
222
|
+
var n = 0;
|
|
223
|
+
while (a * _2e192 < b) {
|
|
224
|
+
a *= _2e192;
|
|
225
|
+
n += 192;
|
|
226
|
+
}
|
|
227
|
+
while (a * 18446744073709552e3 < b) {
|
|
228
|
+
a *= 18446744073709552e3;
|
|
229
|
+
n += 64;
|
|
230
|
+
}
|
|
231
|
+
while (a * 65536 < b) {
|
|
232
|
+
a *= 65536;
|
|
233
|
+
n += 16;
|
|
234
|
+
}
|
|
235
|
+
while (a * 64 < b) {
|
|
236
|
+
a *= 64;
|
|
237
|
+
n += 6;
|
|
238
|
+
}
|
|
239
|
+
while (a * 2 < b) {
|
|
240
|
+
a *= 2;
|
|
241
|
+
n += 1;
|
|
242
|
+
}
|
|
243
|
+
return n;
|
|
244
|
+
}
|
|
245
|
+
function roundMantissa(v, scale) {
|
|
246
|
+
v *= scale;
|
|
247
|
+
return v - Math.floor(v) !== 0.5 || v & 1 ? v + 0.5 : v;
|
|
248
|
+
}
|
|
249
|
+
function writeFloat(buf, v, offset, dirn) {
|
|
250
|
+
var norm, word, sign = 0;
|
|
251
|
+
if (v < 0) {
|
|
252
|
+
sign = 2147483648;
|
|
253
|
+
v = -v;
|
|
254
|
+
}
|
|
255
|
+
if (!(v && v < Infinity)) {
|
|
256
|
+
if (v === 0) {
|
|
257
|
+
word = 1 / v < 0 ? 2147483648 : 0;
|
|
258
|
+
} else if (v === Infinity) {
|
|
259
|
+
word = sign | 2139095040;
|
|
260
|
+
} else {
|
|
261
|
+
word = 2143289344;
|
|
262
|
+
}
|
|
263
|
+
writeWord(buf, word, offset, dirn);
|
|
264
|
+
} else {
|
|
265
|
+
norm = normalize(v);
|
|
266
|
+
norm.exp += 127;
|
|
267
|
+
if (norm.exp <= 0) {
|
|
268
|
+
if (norm.exp <= -25) {
|
|
269
|
+
norm.mant = 0;
|
|
270
|
+
norm.exp = 0;
|
|
271
|
+
} else {
|
|
272
|
+
norm.mant = roundMantissa(norm.mant, pow2(22 + norm.exp));
|
|
273
|
+
norm.exp = 0;
|
|
274
|
+
if (norm.mant >= 8388608) {
|
|
275
|
+
norm.mant -= 8388608;
|
|
276
|
+
norm.exp += 1;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
} else {
|
|
280
|
+
norm.mant = roundMantissa(norm.mant - 1, 8388608);
|
|
281
|
+
if (norm.mant >= 8388608) {
|
|
282
|
+
norm.mant -= 8388608;
|
|
283
|
+
norm.exp += 1;
|
|
284
|
+
}
|
|
285
|
+
if (norm.exp > 254) {
|
|
286
|
+
norm.mant = 0;
|
|
287
|
+
norm.exp = 255;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
word = sign | norm.exp << 23 | norm.mant;
|
|
291
|
+
writeWord(buf, word, offset, dirn);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
var doubleBuf = new Uint8Array(8);
|
|
295
|
+
var _2e52 = Math.pow(2, 52);
|
|
296
|
+
function writeDouble(buf, v, offset, dirn) {
|
|
297
|
+
var norm, highWord, lowWord, sign = 0;
|
|
298
|
+
if (v < 0) {
|
|
299
|
+
sign = 2147483648;
|
|
300
|
+
v = -v;
|
|
301
|
+
}
|
|
302
|
+
if (!(v && v < Infinity)) {
|
|
303
|
+
if (v === 0) {
|
|
304
|
+
highWord = 1 / v < 0 ? 2147483648 : 0;
|
|
305
|
+
lowWord = 0;
|
|
306
|
+
} else if (v === Infinity) {
|
|
307
|
+
highWord = sign + 2146435072;
|
|
308
|
+
lowWord = 0;
|
|
309
|
+
} else {
|
|
310
|
+
highWord = 2146959360;
|
|
311
|
+
lowWord = 0;
|
|
312
|
+
}
|
|
313
|
+
writeDoubleWord(buf, highWord, lowWord, offset, dirn);
|
|
314
|
+
} else {
|
|
315
|
+
norm = normalize(v);
|
|
316
|
+
norm.exp += 1023;
|
|
317
|
+
if (norm.exp <= 0) {
|
|
318
|
+
norm.mant *= pow2(51 + norm.exp);
|
|
319
|
+
norm.exp = 0;
|
|
320
|
+
} else {
|
|
321
|
+
norm.mant = (norm.mant - 1) * _2e52;
|
|
322
|
+
}
|
|
323
|
+
highWord = sign | norm.exp << 20 | norm.mant / 4294967296;
|
|
324
|
+
lowWord = norm.mant >>> 0;
|
|
325
|
+
writeDoubleWord(buf, highWord, lowWord, offset, dirn);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
(function install() {
|
|
329
|
+
var exports2 = typeof module === "object" && module.exports || this;
|
|
330
|
+
exports2.readWord = readWord;
|
|
331
|
+
exports2.writeWord = writeWord;
|
|
332
|
+
exports2.writeDoubleWord = writeDoubleWord;
|
|
333
|
+
exports2.readFloat = readFloat;
|
|
334
|
+
exports2.writeFloat = writeFloat;
|
|
335
|
+
exports2.readDouble = readDouble;
|
|
336
|
+
exports2.writeDouble = writeDouble;
|
|
337
|
+
exports2._useFloatArray = function(yesno) {
|
|
338
|
+
exports2._usingFloatArray = yesno;
|
|
339
|
+
if (yesno) {
|
|
340
|
+
if (yesno == "full") exports2.readFloatLE = isBigeCpu ? readFloat32ArrayRev : readFloat32Array;
|
|
341
|
+
exports2.writeFloatLE = isBigeCpu ? writeFloat32ArrayRev : writeFloat32Array;
|
|
342
|
+
if (yesno == "full") exports2.readFloatBE = isBigeCpu ? readFloat32Array : readFloat32ArrayRev;
|
|
343
|
+
exports2.writeFloatBE = isBigeCpu ? writeFloat32Array : writeFloat32ArrayRev;
|
|
344
|
+
exports2.readDoubleLE = isBigeCpu ? readFloat64ArrayRev : readFloat64Array;
|
|
345
|
+
exports2.writeDoubleLE = isBigeCpu ? writeFloat64ArrayRev : writeFloat64Array;
|
|
346
|
+
exports2.readDoubleBE = isBigeCpu ? readFloat64Array : readFloat64ArrayRev;
|
|
347
|
+
exports2.writeDoubleBE = isBigeCpu ? writeFloat64Array : writeFloat64ArrayRev;
|
|
348
|
+
} else {
|
|
349
|
+
exports2._usingFloatArray = "";
|
|
350
|
+
exports2.readFloatLE = function readFloatLE(buf, offset) {
|
|
351
|
+
return exports2.readFloat(buf, offset || 0, "le");
|
|
352
|
+
};
|
|
353
|
+
exports2.writeFloatLE = function writeFloatLE(buf, v, offset) {
|
|
354
|
+
exports2.writeFloat(buf, v, offset || 0, "le");
|
|
355
|
+
};
|
|
356
|
+
exports2.readFloatBE = function readFloatBE(buf, offset) {
|
|
357
|
+
return exports2.readFloat(buf, offset || 0, "bige");
|
|
358
|
+
};
|
|
359
|
+
exports2.writeFloatBE = function writeFloatBE(buf, v, offset) {
|
|
360
|
+
exports2.writeFloat(buf, v, offset || 0, "bige");
|
|
361
|
+
};
|
|
362
|
+
exports2.readDoubleLE = function readDoubleLE(buf, offset) {
|
|
363
|
+
return exports2.readDouble(buf, offset || 0, "le");
|
|
364
|
+
};
|
|
365
|
+
exports2.writeDoubleLE = function writeDoubleLE(buf, v, offset) {
|
|
366
|
+
exports2.writeDouble(buf, v, offset || 0, "le");
|
|
367
|
+
};
|
|
368
|
+
exports2.readDoubleBE = function readDoubleBE(buf, offset) {
|
|
369
|
+
return exports2.readDouble(buf, offset || 0, "bige");
|
|
370
|
+
};
|
|
371
|
+
exports2.writeDoubleBE = function writeDoubleLE(buf, v, offset) {
|
|
372
|
+
exports2.writeDouble(buf, v, offset || 0, "bige");
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
exports2._getBigeCpu = function() {
|
|
377
|
+
return isBigeCpu;
|
|
378
|
+
};
|
|
379
|
+
exports2._setBigeCpu = function(yesno) {
|
|
380
|
+
isBigeCpu = yesno;
|
|
381
|
+
};
|
|
382
|
+
exports2._useFloatArray(false);
|
|
383
|
+
exports2._useFloatArray(readFloat32Array && readFloat64Array && "fastest");
|
|
384
|
+
install.prototype = exports2;
|
|
385
|
+
}).call(exports);
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
// src/index.ts
|
|
390
|
+
var src_exports = {};
|
|
391
|
+
__export(src_exports, {
|
|
392
|
+
ATOMIC_ATTRIBUTE: () => ATOMIC_ATTRIBUTE,
|
|
393
|
+
ActionBuilder: () => ActionBuilder,
|
|
394
|
+
ActionGenerator: () => ActionGenerator,
|
|
395
|
+
ApiError: () => ApiError,
|
|
396
|
+
AssetsSort: () => AssetsSort,
|
|
397
|
+
AtomicAssetsActionNames: () => AtomicAssetsActionNames,
|
|
398
|
+
AtomicAssetsActions: () => AtomicAssetsActions,
|
|
399
|
+
CachedObjectSchema: () => CachedObjectSchema,
|
|
400
|
+
CollectionsSort: () => CollectionsSort,
|
|
401
|
+
DeserializationError: () => DeserializationError,
|
|
402
|
+
ExplorerActionGenerator: () => ExplorerActionGenerator,
|
|
403
|
+
ExplorerApi: () => ExplorerApi,
|
|
404
|
+
ExplorerError: () => RpcError2,
|
|
405
|
+
NETWORK_ENDPOINTS: () => NETWORK_ENDPOINTS,
|
|
406
|
+
ObjectSchema: () => ObjectSchema,
|
|
407
|
+
OfferState: () => OfferState,
|
|
408
|
+
OffersSort: () => OffersSort,
|
|
409
|
+
OrderParam: () => OrderParam,
|
|
410
|
+
ParserTypes: () => ParserTypes,
|
|
411
|
+
RpcActionGenerator: () => RpcActionGenerator,
|
|
412
|
+
RpcApi: () => RpcApi,
|
|
413
|
+
RpcError: () => RpcError,
|
|
414
|
+
SchemaError: () => SchemaError,
|
|
415
|
+
SchemasSort: () => SchemasSort,
|
|
416
|
+
SerializationError: () => SerializationError,
|
|
417
|
+
TemplatesSort: () => TemplatesSort,
|
|
418
|
+
TransfersSort: () => TransfersSort,
|
|
419
|
+
convertAttributeMapToObject: () => convertAttributeMapToObject,
|
|
420
|
+
createAttributeMap: () => createAttributeMap,
|
|
421
|
+
deserialize: () => deserialize,
|
|
422
|
+
explorerApiForNetwork: () => explorerApiForNetwork,
|
|
423
|
+
mergeSchemaFormatTypes: () => mergeSchemaFormatTypes,
|
|
424
|
+
rpcApiForNetwork: () => rpcApiForNetwork,
|
|
425
|
+
serialize: () => serialize,
|
|
426
|
+
toAttributeMap: () => toAttributeMap,
|
|
427
|
+
toByteArray: () => toByteArray
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// src/Errors/SerializationError.ts
|
|
431
|
+
var SerializationError = class extends Error {
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
// src/Actions/Generator.ts
|
|
435
|
+
var ATOMIC_ATTRIBUTE = {
|
|
436
|
+
int8: "int8",
|
|
437
|
+
int16: "int16",
|
|
438
|
+
int32: "int32",
|
|
439
|
+
int64: "int64",
|
|
440
|
+
uint8: "uint8",
|
|
441
|
+
uint16: "uint16",
|
|
442
|
+
uint32: "uint32",
|
|
443
|
+
uint64: "uint64",
|
|
444
|
+
fixed8: "uint8",
|
|
445
|
+
fixed16: "uint16",
|
|
446
|
+
fixed32: "uint32",
|
|
447
|
+
fixed64: "uint64",
|
|
448
|
+
float: "float32",
|
|
449
|
+
double: "float64",
|
|
450
|
+
string: "string",
|
|
451
|
+
ipfs: "string",
|
|
452
|
+
image: "string",
|
|
453
|
+
bool: "uint8",
|
|
454
|
+
"int8[]": "INT8_VEC",
|
|
455
|
+
"int16[]": "INT16_VEC",
|
|
456
|
+
"int32[]": "INT32_VEC",
|
|
457
|
+
"int64[]": "INT64_VEC",
|
|
458
|
+
"uint8[]": "UINT8_VEC",
|
|
459
|
+
"uint16[]": "UINT16_VEC",
|
|
460
|
+
"uint32[]": "UINT32_VEC",
|
|
461
|
+
"uint64[]": "UINT64_VEC",
|
|
462
|
+
"fixed8[]": "UINT8_VEC",
|
|
463
|
+
"fixed16[]": "UINT16_VEC",
|
|
464
|
+
"fixed32[]": "UINT32_VEC",
|
|
465
|
+
"fixed64[]": "UINT64_VEC",
|
|
466
|
+
"float[]": "FLOAT_VEC",
|
|
467
|
+
"double[]": "DOUBLE_VEC",
|
|
468
|
+
"string[]": "STRING_VEC",
|
|
469
|
+
"image[]": "STRING_VEC",
|
|
470
|
+
"bool[]": "INT8_VEC"
|
|
471
|
+
};
|
|
472
|
+
function createAttributeMap(obj, types) {
|
|
473
|
+
const result = [];
|
|
474
|
+
for (const key of Object.keys(obj)) {
|
|
475
|
+
const type = types[key];
|
|
476
|
+
if (typeof type === "undefined") {
|
|
477
|
+
throw new SerializationError("no type given for field '" + key + "'");
|
|
478
|
+
}
|
|
479
|
+
const variant = ATOMIC_ATTRIBUTE[type];
|
|
480
|
+
if (typeof variant === "undefined") {
|
|
481
|
+
throw new SerializationError("invalid type '" + type + "' for field '" + key + "'");
|
|
482
|
+
}
|
|
483
|
+
result.push({ key, value: [variant, obj[key]] });
|
|
484
|
+
}
|
|
485
|
+
return result;
|
|
486
|
+
}
|
|
487
|
+
var ActionBuilder = class {
|
|
488
|
+
constructor(contract) {
|
|
489
|
+
this.contract = contract;
|
|
490
|
+
}
|
|
491
|
+
acceptauswap(collection_name) {
|
|
492
|
+
return this._action("acceptauswap", { collection_name });
|
|
493
|
+
}
|
|
494
|
+
acceptoffer(offer_id) {
|
|
495
|
+
return this._action("acceptoffer", { offer_id });
|
|
496
|
+
}
|
|
497
|
+
addcolauth(collection_name, account_to_add) {
|
|
498
|
+
return this._action("addcolauth", { collection_name, account_to_add });
|
|
499
|
+
}
|
|
500
|
+
addconftoken(token_contract, token_symbol) {
|
|
501
|
+
return this._action("addconftoken", { token_contract, token_symbol });
|
|
502
|
+
}
|
|
503
|
+
addnotifyacc(collection_name, account_to_add) {
|
|
504
|
+
return this._action("addnotifyacc", { collection_name, account_to_add });
|
|
505
|
+
}
|
|
506
|
+
admincoledit(collection_format_extension) {
|
|
507
|
+
return this._action("admincoledit", { collection_format_extension });
|
|
508
|
+
}
|
|
509
|
+
announcedepo(owner, symbol_to_announce) {
|
|
510
|
+
return this._action("announcedepo", { owner, symbol_to_announce });
|
|
511
|
+
}
|
|
512
|
+
backasset(payer, asset_owner, asset_id, token_to_back) {
|
|
513
|
+
return this._action("backasset", { payer, asset_owner, asset_id, token_to_back });
|
|
514
|
+
}
|
|
515
|
+
burnasset(asset_owner, asset_id) {
|
|
516
|
+
return this._action("burnasset", { asset_owner, asset_id });
|
|
517
|
+
}
|
|
518
|
+
canceloffer(offer_id) {
|
|
519
|
+
return this._action("canceloffer", { offer_id });
|
|
520
|
+
}
|
|
521
|
+
createauswap(collection_name, new_author, owner) {
|
|
522
|
+
return this._action("createauswap", { collection_name, new_author, owner });
|
|
523
|
+
}
|
|
524
|
+
createcol(author, collection_name, allow_notify, authorized_accounts, notify_accounts, market_fee, data) {
|
|
525
|
+
return this._action("createcol", {
|
|
526
|
+
author,
|
|
527
|
+
collection_name,
|
|
528
|
+
allow_notify,
|
|
529
|
+
authorized_accounts,
|
|
530
|
+
notify_accounts,
|
|
531
|
+
market_fee,
|
|
532
|
+
data
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
createoffer(sender, recipient, sender_asset_ids, recipient_asset_ids, memo) {
|
|
536
|
+
return this._action("createoffer", { sender, recipient, sender_asset_ids, recipient_asset_ids, memo });
|
|
537
|
+
}
|
|
538
|
+
createtempl(authorized_creator, collection_name, schema_name, transferable, burnable, max_supply, immutable_data) {
|
|
539
|
+
return this._action("createtempl", {
|
|
540
|
+
authorized_creator,
|
|
541
|
+
collection_name,
|
|
542
|
+
schema_name,
|
|
543
|
+
transferable,
|
|
544
|
+
burnable,
|
|
545
|
+
max_supply,
|
|
546
|
+
immutable_data
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
createtempl2(authorized_creator, collection_name, schema_name, transferable, burnable, max_supply, immutable_data, mutable_data) {
|
|
550
|
+
return this._action("createtempl2", {
|
|
551
|
+
authorized_creator,
|
|
552
|
+
collection_name,
|
|
553
|
+
schema_name,
|
|
554
|
+
transferable,
|
|
555
|
+
burnable,
|
|
556
|
+
max_supply,
|
|
557
|
+
immutable_data,
|
|
558
|
+
mutable_data
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
createschema(authorized_creator, collection_name, schema_name, schema_format) {
|
|
562
|
+
return this._action("createschema", { authorized_creator, collection_name, schema_name, schema_format });
|
|
563
|
+
}
|
|
564
|
+
declineoffer(offer_id) {
|
|
565
|
+
return this._action("declineoffer", { offer_id });
|
|
566
|
+
}
|
|
567
|
+
deltemplate(authorized_editor, collection_name, template_id) {
|
|
568
|
+
return this._action("deltemplate", { authorized_editor, collection_name, template_id });
|
|
569
|
+
}
|
|
570
|
+
extendschema(authorized_editor, collection_name, schema_name, schema_format_extension) {
|
|
571
|
+
return this._action("extendschema", { authorized_editor, collection_name, schema_name, schema_format_extension });
|
|
572
|
+
}
|
|
573
|
+
forbidnotify(collection_name) {
|
|
574
|
+
return this._action("forbidnotify", { collection_name });
|
|
575
|
+
}
|
|
576
|
+
init() {
|
|
577
|
+
return this._action("init", {});
|
|
578
|
+
}
|
|
579
|
+
locktemplate(authorized_editor, collection_name, template_id) {
|
|
580
|
+
return this._action("locktemplate", { authorized_editor, collection_name, template_id });
|
|
581
|
+
}
|
|
582
|
+
mintasset(authorized_minter, collection_name, schema_name, template_id, new_asset_owner, immutable_data, mutable_data, tokens_to_back) {
|
|
583
|
+
return this._action("mintasset", {
|
|
584
|
+
authorized_minter,
|
|
585
|
+
collection_name,
|
|
586
|
+
schema_name,
|
|
587
|
+
template_id,
|
|
588
|
+
new_asset_owner,
|
|
589
|
+
immutable_data,
|
|
590
|
+
mutable_data,
|
|
591
|
+
tokens_to_back
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
payofferram(payer, offer_id) {
|
|
595
|
+
return this._action("payofferram", { payer, offer_id });
|
|
596
|
+
}
|
|
597
|
+
redtemplmax(authorized_editor, collection_name, template_id, new_max_supply) {
|
|
598
|
+
return this._action("redtemplmax", { authorized_editor, collection_name, template_id, new_max_supply });
|
|
599
|
+
}
|
|
600
|
+
rejectauswap(collection_name) {
|
|
601
|
+
return this._action("rejectauswap", { collection_name });
|
|
602
|
+
}
|
|
603
|
+
remcolauth(collection_name, account_to_remove) {
|
|
604
|
+
return this._action("remcolauth", { collection_name, account_to_remove });
|
|
605
|
+
}
|
|
606
|
+
remnotifyacc(collection_name, account_to_remove) {
|
|
607
|
+
return this._action("remnotifyacc", { collection_name, account_to_remove });
|
|
608
|
+
}
|
|
609
|
+
setassetdata(authorized_editor, asset_owner, asset_id, new_mutable_data) {
|
|
610
|
+
return this._action("setassetdata", { authorized_editor, asset_owner, asset_id, new_mutable_data });
|
|
611
|
+
}
|
|
612
|
+
setcoldata(collection_name, data) {
|
|
613
|
+
return this._action("setcoldata", { collection_name, data });
|
|
614
|
+
}
|
|
615
|
+
setlastpayer(owner, collection_name) {
|
|
616
|
+
return this._action("setlastpayer", { owner, collection_name });
|
|
617
|
+
}
|
|
618
|
+
setmarketfee(collection_name, market_fee) {
|
|
619
|
+
return this._action("setmarketfee", { collection_name, market_fee });
|
|
620
|
+
}
|
|
621
|
+
setrampayer(new_payer, asset_id) {
|
|
622
|
+
return this._action("setrampayer", { new_payer, asset_id });
|
|
623
|
+
}
|
|
624
|
+
settempldata(authorized_editor, collection_name, template_id, new_mutable_data) {
|
|
625
|
+
return this._action("settempldata", { authorized_editor, collection_name, template_id, new_mutable_data });
|
|
626
|
+
}
|
|
627
|
+
setschematyp(authorized_editor, collection_name, schema_name, schema_format_type) {
|
|
628
|
+
const normalized = schema_format_type.map(
|
|
629
|
+
({ name, mediatype, info }) => ({ name, mediatype, info: info ?? "" })
|
|
630
|
+
);
|
|
631
|
+
return this._action("setschematyp", {
|
|
632
|
+
authorized_editor,
|
|
633
|
+
collection_name,
|
|
634
|
+
schema_name,
|
|
635
|
+
schema_format_type: normalized
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
setversion(new_version) {
|
|
639
|
+
return this._action("setversion", { new_version });
|
|
640
|
+
}
|
|
641
|
+
transfer(account_from, account_to, asset_ids, memo) {
|
|
642
|
+
return this._action("transfer", { from: account_from, to: account_to, asset_ids, memo });
|
|
643
|
+
}
|
|
644
|
+
withdraw(owner, token_to_withdraw) {
|
|
645
|
+
return this._action("withdraw", { owner, token_to_withdraw });
|
|
646
|
+
}
|
|
647
|
+
_action(name, data) {
|
|
648
|
+
return { account: this.contract, name, data };
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
var ActionGenerator = class {
|
|
652
|
+
constructor(contract) {
|
|
653
|
+
this.contract = contract;
|
|
654
|
+
this.builder = new ActionBuilder(contract);
|
|
655
|
+
}
|
|
656
|
+
async acceptauswap(authorization, collection_name) {
|
|
657
|
+
return this._authorize(authorization, this.builder.acceptauswap(collection_name));
|
|
658
|
+
}
|
|
659
|
+
async acceptoffer(authorization, offer_id) {
|
|
660
|
+
return this._authorize(authorization, this.builder.acceptoffer(offer_id));
|
|
661
|
+
}
|
|
662
|
+
async addcolauth(authorization, collection_name, account_to_add) {
|
|
663
|
+
return this._authorize(authorization, this.builder.addcolauth(collection_name, account_to_add));
|
|
664
|
+
}
|
|
665
|
+
async addconftoken(authorization, token_contract, token_symbol) {
|
|
666
|
+
return this._authorize(authorization, this.builder.addconftoken(token_contract, token_symbol));
|
|
667
|
+
}
|
|
668
|
+
async addnotifyacc(authorization, collection_name, account_to_add) {
|
|
669
|
+
return this._authorize(authorization, this.builder.addnotifyacc(collection_name, account_to_add));
|
|
670
|
+
}
|
|
671
|
+
async admincoledit(authorization, collection_format_extension) {
|
|
672
|
+
return this._authorize(authorization, this.builder.admincoledit(collection_format_extension));
|
|
673
|
+
}
|
|
674
|
+
async announcedepo(authorization, owner, symbol_to_announce) {
|
|
675
|
+
return this._authorize(authorization, this.builder.announcedepo(owner, symbol_to_announce));
|
|
676
|
+
}
|
|
677
|
+
async backasset(authorization, payer, asset_owner, asset_id, token_to_back) {
|
|
678
|
+
return this._authorize(authorization, this.builder.backasset(payer, asset_owner, asset_id, token_to_back));
|
|
679
|
+
}
|
|
680
|
+
async burnasset(authorization, asset_owner, asset_id) {
|
|
681
|
+
return this._authorize(authorization, this.builder.burnasset(asset_owner, asset_id));
|
|
682
|
+
}
|
|
683
|
+
async canceloffer(authorization, offer_id) {
|
|
684
|
+
return this._authorize(authorization, this.builder.canceloffer(offer_id));
|
|
685
|
+
}
|
|
686
|
+
async createauswap(authorization, collection_name, new_author, owner) {
|
|
687
|
+
return this._authorize(authorization, this.builder.createauswap(collection_name, new_author, owner));
|
|
688
|
+
}
|
|
689
|
+
async createcol(authorization, author, collection_name, allow_notify, authorized_accounts, notify_accounts, market_fee, data) {
|
|
690
|
+
return this._authorize(authorization, this.builder.createcol(
|
|
691
|
+
author,
|
|
692
|
+
collection_name,
|
|
693
|
+
allow_notify,
|
|
694
|
+
authorized_accounts,
|
|
695
|
+
notify_accounts,
|
|
696
|
+
market_fee,
|
|
697
|
+
data
|
|
698
|
+
));
|
|
699
|
+
}
|
|
700
|
+
async createoffer(authorization, sender, recipient, sender_asset_ids, recipient_asset_ids, memo) {
|
|
701
|
+
return this._authorize(authorization, this.builder.createoffer(sender, recipient, sender_asset_ids, recipient_asset_ids, memo));
|
|
702
|
+
}
|
|
703
|
+
async createtempl(authorization, authorized_creator, collection_name, schema_name, transferable, burnable, max_supply, immutable_data) {
|
|
704
|
+
return this._authorize(authorization, this.builder.createtempl(
|
|
705
|
+
authorized_creator,
|
|
706
|
+
collection_name,
|
|
707
|
+
schema_name,
|
|
708
|
+
transferable,
|
|
709
|
+
burnable,
|
|
710
|
+
max_supply,
|
|
711
|
+
immutable_data
|
|
712
|
+
));
|
|
713
|
+
}
|
|
714
|
+
async createtempl2(authorization, authorized_creator, collection_name, schema_name, transferable, burnable, max_supply, immutable_data, mutable_data) {
|
|
715
|
+
return this._authorize(authorization, this.builder.createtempl2(
|
|
716
|
+
authorized_creator,
|
|
717
|
+
collection_name,
|
|
718
|
+
schema_name,
|
|
719
|
+
transferable,
|
|
720
|
+
burnable,
|
|
721
|
+
max_supply,
|
|
722
|
+
immutable_data,
|
|
723
|
+
mutable_data
|
|
724
|
+
));
|
|
725
|
+
}
|
|
726
|
+
async createschema(authorization, authorized_creator, collection_name, schema_name, schema_format) {
|
|
727
|
+
return this._authorize(authorization, this.builder.createschema(authorized_creator, collection_name, schema_name, schema_format));
|
|
728
|
+
}
|
|
729
|
+
async declineoffer(authorization, offer_id) {
|
|
730
|
+
return this._authorize(authorization, this.builder.declineoffer(offer_id));
|
|
731
|
+
}
|
|
732
|
+
async deltemplate(authorization, authorized_editor, collection_name, template_id) {
|
|
733
|
+
return this._authorize(authorization, this.builder.deltemplate(authorized_editor, collection_name, template_id));
|
|
734
|
+
}
|
|
735
|
+
async extendschema(authorization, authorized_editor, collection_name, schema_name, schema_format_extension) {
|
|
736
|
+
return this._authorize(authorization, this.builder.extendschema(
|
|
737
|
+
authorized_editor,
|
|
738
|
+
collection_name,
|
|
739
|
+
schema_name,
|
|
740
|
+
schema_format_extension
|
|
741
|
+
));
|
|
742
|
+
}
|
|
743
|
+
async forbidnotify(authorization, collection_name) {
|
|
744
|
+
return this._authorize(authorization, this.builder.forbidnotify(collection_name));
|
|
745
|
+
}
|
|
746
|
+
async init(authorization) {
|
|
747
|
+
return this._authorize(authorization, this.builder.init());
|
|
748
|
+
}
|
|
749
|
+
async locktemplate(authorization, authorized_editor, collection_name, template_id) {
|
|
750
|
+
return this._authorize(authorization, this.builder.locktemplate(authorized_editor, collection_name, template_id));
|
|
751
|
+
}
|
|
752
|
+
async mintasset(authorization, authorized_minter, collection_name, schema_name, template_id, new_asset_owner, immutable_data, mutable_data, tokens_to_back) {
|
|
753
|
+
return this._authorize(authorization, this.builder.mintasset(
|
|
754
|
+
authorized_minter,
|
|
755
|
+
collection_name,
|
|
756
|
+
schema_name,
|
|
757
|
+
template_id,
|
|
758
|
+
new_asset_owner,
|
|
759
|
+
immutable_data,
|
|
760
|
+
mutable_data,
|
|
761
|
+
tokens_to_back
|
|
762
|
+
));
|
|
763
|
+
}
|
|
764
|
+
async payofferram(authorization, payer, offer_id) {
|
|
765
|
+
return this._authorize(authorization, this.builder.payofferram(payer, offer_id));
|
|
766
|
+
}
|
|
767
|
+
async redtemplmax(authorization, authorized_editor, collection_name, template_id, new_max_supply) {
|
|
768
|
+
return this._authorize(authorization, this.builder.redtemplmax(authorized_editor, collection_name, template_id, new_max_supply));
|
|
769
|
+
}
|
|
770
|
+
async rejectauswap(authorization, collection_name) {
|
|
771
|
+
return this._authorize(authorization, this.builder.rejectauswap(collection_name));
|
|
772
|
+
}
|
|
773
|
+
async remcolauth(authorization, collection_name, account_to_remove) {
|
|
774
|
+
return this._authorize(authorization, this.builder.remcolauth(collection_name, account_to_remove));
|
|
775
|
+
}
|
|
776
|
+
async remnotifyacc(authorization, collection_name, account_to_remove) {
|
|
777
|
+
return this._authorize(authorization, this.builder.remnotifyacc(collection_name, account_to_remove));
|
|
778
|
+
}
|
|
779
|
+
async setassetdata(authorization, authorized_editor, asset_owner, asset_id, new_mutable_data) {
|
|
780
|
+
return this._authorize(authorization, this.builder.setassetdata(authorized_editor, asset_owner, asset_id, new_mutable_data));
|
|
781
|
+
}
|
|
782
|
+
async setcoldata(authorization, collection_name, data) {
|
|
783
|
+
return this._authorize(authorization, this.builder.setcoldata(collection_name, data));
|
|
784
|
+
}
|
|
785
|
+
async setlastpayer(authorization, owner, collection_name) {
|
|
786
|
+
return this._authorize(authorization, this.builder.setlastpayer(owner, collection_name));
|
|
787
|
+
}
|
|
788
|
+
async setmarketfee(authorization, collection_name, market_fee) {
|
|
789
|
+
return this._authorize(authorization, this.builder.setmarketfee(collection_name, market_fee));
|
|
790
|
+
}
|
|
791
|
+
async setrampayer(authorization, new_payer, asset_id) {
|
|
792
|
+
return this._authorize(authorization, this.builder.setrampayer(new_payer, asset_id));
|
|
793
|
+
}
|
|
794
|
+
async settempldata(authorization, authorized_editor, collection_name, template_id, new_mutable_data) {
|
|
795
|
+
return this._authorize(authorization, this.builder.settempldata(authorized_editor, collection_name, template_id, new_mutable_data));
|
|
796
|
+
}
|
|
797
|
+
async setschematyp(authorization, authorized_editor, collection_name, schema_name, schema_format_type) {
|
|
798
|
+
return this._authorize(authorization, this.builder.setschematyp(
|
|
799
|
+
authorized_editor,
|
|
800
|
+
collection_name,
|
|
801
|
+
schema_name,
|
|
802
|
+
schema_format_type
|
|
803
|
+
));
|
|
804
|
+
}
|
|
805
|
+
async setversion(authorization, new_version) {
|
|
806
|
+
return this._authorize(authorization, this.builder.setversion(new_version));
|
|
807
|
+
}
|
|
808
|
+
async transfer(authorization, account_from, account_to, asset_ids, memo) {
|
|
809
|
+
return this._authorize(authorization, this.builder.transfer(account_from, account_to, asset_ids, memo));
|
|
810
|
+
}
|
|
811
|
+
async withdraw(authorization, owner, token_to_withdraw) {
|
|
812
|
+
return this._authorize(authorization, this.builder.withdraw(owner, token_to_withdraw));
|
|
813
|
+
}
|
|
814
|
+
_authorize(authorization, action) {
|
|
815
|
+
return [{ account: action.account, name: action.name, authorization, data: action.data }];
|
|
816
|
+
}
|
|
817
|
+
_pack(authorization, name, data) {
|
|
818
|
+
return [{ account: this.contract, name, authorization, data }];
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
function toAttributeMap(obj, schema) {
|
|
822
|
+
const types = {};
|
|
823
|
+
const result = [];
|
|
824
|
+
for (const row of schema) {
|
|
825
|
+
types[row.name] = row.type;
|
|
826
|
+
}
|
|
827
|
+
const keys = Object.keys(obj);
|
|
828
|
+
for (const key of keys) {
|
|
829
|
+
if (typeof types[key] === "undefined") {
|
|
830
|
+
throw new SerializationError("field not defined in schema");
|
|
831
|
+
}
|
|
832
|
+
result.push({ key, value: [types[key], obj[key]] });
|
|
833
|
+
}
|
|
834
|
+
return result;
|
|
835
|
+
}
|
|
836
|
+
function convertAttributeMapToObject(data) {
|
|
837
|
+
const result = {};
|
|
838
|
+
for (const row of data) {
|
|
839
|
+
const key = "key" in row ? row.key : row.first;
|
|
840
|
+
const value = "value" in row ? row.value : row.second;
|
|
841
|
+
if (["uint64", "int64"].indexOf(value[0]) >= 0) {
|
|
842
|
+
Object.defineProperty(result, key, { value: String(value[1]), enumerable: true, writable: true, configurable: true });
|
|
843
|
+
} else if (["INT64_VEC", "UINT64_VEC"].indexOf(value[0]) >= 0) {
|
|
844
|
+
Object.defineProperty(result, key, {
|
|
845
|
+
value: value[1].map((entry) => String(entry)),
|
|
846
|
+
enumerable: true,
|
|
847
|
+
writable: true,
|
|
848
|
+
configurable: true
|
|
849
|
+
});
|
|
850
|
+
} else {
|
|
851
|
+
Object.defineProperty(result, key, { value: value[1], enumerable: true, writable: true, configurable: true });
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return result;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// src/Actions/Explorer.ts
|
|
858
|
+
var ExplorerActionGenerator = class extends ActionGenerator {
|
|
859
|
+
constructor(contract, api) {
|
|
860
|
+
super(contract);
|
|
861
|
+
this.api = api;
|
|
862
|
+
this.config = api.getConfig();
|
|
863
|
+
}
|
|
864
|
+
async createcol(authorization, author, collection_name, allow_notify, authorized_accounts, notify_accounts, market_fee, data) {
|
|
865
|
+
return super.createcol(
|
|
866
|
+
authorization,
|
|
867
|
+
author,
|
|
868
|
+
collection_name,
|
|
869
|
+
allow_notify,
|
|
870
|
+
authorized_accounts,
|
|
871
|
+
notify_accounts,
|
|
872
|
+
market_fee,
|
|
873
|
+
toAttributeMap(data, (await this.config).collection_format)
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
async createtempl(authorization, authorized_creator, collection_name, schema_name, transferable, burnable, max_supply, immutable_data) {
|
|
877
|
+
const schema = await this.api.getSchema(collection_name, schema_name);
|
|
878
|
+
const immutable_attribute_map = toAttributeMap(immutable_data, schema.format);
|
|
879
|
+
return super.createtempl(
|
|
880
|
+
authorization,
|
|
881
|
+
authorized_creator,
|
|
882
|
+
collection_name,
|
|
883
|
+
schema_name,
|
|
884
|
+
transferable,
|
|
885
|
+
burnable,
|
|
886
|
+
max_supply,
|
|
887
|
+
immutable_attribute_map
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
async mintasset(authorization, authorized_minter, collection_name, schema_name, template_id, new_owner, immutable_data, mutable_data, tokens_to_back) {
|
|
891
|
+
const schema = await this.api.getSchema(collection_name, schema_name);
|
|
892
|
+
const immutable_attribute_map = toAttributeMap(immutable_data, schema.format);
|
|
893
|
+
const mutable_attribute_map = toAttributeMap(mutable_data, schema.format);
|
|
894
|
+
return super.mintasset(
|
|
895
|
+
authorization,
|
|
896
|
+
authorized_minter,
|
|
897
|
+
collection_name,
|
|
898
|
+
schema_name,
|
|
899
|
+
template_id,
|
|
900
|
+
new_owner,
|
|
901
|
+
immutable_attribute_map,
|
|
902
|
+
mutable_attribute_map,
|
|
903
|
+
tokens_to_back
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
async setassetdata(authorization, authorized_editor, owner, asset_id, mutable_data) {
|
|
907
|
+
const asset = await this.api.getAsset(asset_id);
|
|
908
|
+
const mutable_attribute_map = toAttributeMap(mutable_data, asset.schema.format);
|
|
909
|
+
return super.setassetdata(authorization, authorized_editor, owner, asset_id, mutable_attribute_map);
|
|
910
|
+
}
|
|
911
|
+
async setcoldata(authorization, collection_name, data) {
|
|
912
|
+
const mdata = toAttributeMap(data, (await this.config).collection_format);
|
|
913
|
+
return super.setcoldata(authorization, collection_name, mdata);
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
// src/Actions/Rpc.ts
|
|
918
|
+
var RpcActionGenerator = class extends ActionGenerator {
|
|
919
|
+
constructor(api) {
|
|
920
|
+
super(api.contract);
|
|
921
|
+
this.api = api;
|
|
922
|
+
}
|
|
923
|
+
async createcol(authorization, author, collection_name, allow_notify, authorized_accounts, notify_accounts, market_fee, data) {
|
|
924
|
+
const config = await this.api.config();
|
|
925
|
+
return super.createcol(
|
|
926
|
+
authorization,
|
|
927
|
+
author,
|
|
928
|
+
collection_name,
|
|
929
|
+
allow_notify,
|
|
930
|
+
authorized_accounts,
|
|
931
|
+
notify_accounts,
|
|
932
|
+
market_fee,
|
|
933
|
+
toAttributeMap(data, config.collection_format)
|
|
934
|
+
);
|
|
935
|
+
}
|
|
936
|
+
async createtempl(authorization, authorized_creator, collection_name, schema_name, transferable, burnable, max_supply, immutable_data) {
|
|
937
|
+
const schema = await this.api.getSchema(collection_name, schema_name);
|
|
938
|
+
const immutable_attribute_map = toAttributeMap(immutable_data, await schema.rawFormat());
|
|
939
|
+
return super.createtempl(
|
|
940
|
+
authorization,
|
|
941
|
+
authorized_creator,
|
|
942
|
+
collection_name,
|
|
943
|
+
schema_name,
|
|
944
|
+
transferable,
|
|
945
|
+
burnable,
|
|
946
|
+
max_supply,
|
|
947
|
+
immutable_attribute_map
|
|
948
|
+
);
|
|
949
|
+
}
|
|
950
|
+
async mintasset(authorization, authorized_minter, collection_name, schema_name, template_id, new_owner, immutable_data, mutable_data, tokens_to_back) {
|
|
951
|
+
const template = await this.api.getTemplate(collection_name, String(template_id));
|
|
952
|
+
const immutable_attribute_map = toAttributeMap(immutable_data, await (await template.schema()).rawFormat());
|
|
953
|
+
const mutable_attribute_map = toAttributeMap(mutable_data, await (await template.schema()).rawFormat());
|
|
954
|
+
return super.mintasset(
|
|
955
|
+
authorization,
|
|
956
|
+
authorized_minter,
|
|
957
|
+
collection_name,
|
|
958
|
+
schema_name,
|
|
959
|
+
template_id,
|
|
960
|
+
new_owner,
|
|
961
|
+
immutable_attribute_map,
|
|
962
|
+
mutable_attribute_map,
|
|
963
|
+
tokens_to_back
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
async setassetdata(authorization, authorized_editor, owner, asset_id, mutable_data) {
|
|
967
|
+
const asset = await this.api.getAsset(owner, asset_id);
|
|
968
|
+
const schema = await asset.schema();
|
|
969
|
+
const mutable_attribute_map = toAttributeMap(mutable_data, await schema.rawFormat());
|
|
970
|
+
return super.setassetdata(authorization, authorized_editor, owner, asset_id, mutable_attribute_map);
|
|
971
|
+
}
|
|
972
|
+
async setcoldata(authorization, collection_name, data) {
|
|
973
|
+
const mdata = toAttributeMap(data, (await this.api.config()).collection_format);
|
|
974
|
+
return super.setcoldata(authorization, collection_name, mdata);
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
|
|
978
|
+
// src/Errors/ApiError.ts
|
|
979
|
+
var ApiError = class extends Error {
|
|
980
|
+
constructor(message, status) {
|
|
981
|
+
super(message);
|
|
982
|
+
this.message = message;
|
|
983
|
+
this.status = status;
|
|
984
|
+
this.isApiError = true;
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
|
|
988
|
+
// src/API/Explorer/index.ts
|
|
989
|
+
function buildDataOptions(options, data) {
|
|
990
|
+
const dataFields = {};
|
|
991
|
+
for (const row of data) {
|
|
992
|
+
const dataType = row.type ?? "data";
|
|
993
|
+
if (typeof row.value === "number") {
|
|
994
|
+
dataFields[dataType + ":number." + row.key] = String(row.value);
|
|
995
|
+
} else if (typeof row.value === "boolean") {
|
|
996
|
+
dataFields[dataType + ":bool." + row.key] = row.value ? "true" : "false";
|
|
997
|
+
} else {
|
|
998
|
+
dataFields[dataType + "." + row.key] = row.value;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
return Object.assign({}, options, dataFields);
|
|
1002
|
+
}
|
|
1003
|
+
var ExplorerApi = class {
|
|
1004
|
+
constructor(endpoint, namespace, args) {
|
|
1005
|
+
this.endpoint = endpoint;
|
|
1006
|
+
this.namespace = namespace;
|
|
1007
|
+
if (args.fetch) {
|
|
1008
|
+
this.fetchBuiltin = args.fetch;
|
|
1009
|
+
} else {
|
|
1010
|
+
this.fetchBuiltin = globalThis.fetch.bind(globalThis);
|
|
1011
|
+
}
|
|
1012
|
+
this.action = (async () => {
|
|
1013
|
+
return new ExplorerActionGenerator((await this.getConfig()).contract, this);
|
|
1014
|
+
})();
|
|
1015
|
+
}
|
|
1016
|
+
async getConfig() {
|
|
1017
|
+
return await this.fetchEndpoint("/v1/config", {});
|
|
1018
|
+
}
|
|
1019
|
+
async getAssets(options = {}, page = 1, limit = 100, data = []) {
|
|
1020
|
+
return await this.fetchEndpoint("/v1/assets", { page, limit, ...buildDataOptions(options, data) });
|
|
1021
|
+
}
|
|
1022
|
+
async countAssets(options, data = []) {
|
|
1023
|
+
return await this.countEndpoint("/v1/assets", buildDataOptions(options, data));
|
|
1024
|
+
}
|
|
1025
|
+
async getAsset(id) {
|
|
1026
|
+
return await this.fetchEndpoint("/v1/assets/" + id, {});
|
|
1027
|
+
}
|
|
1028
|
+
async getAssetStats(id) {
|
|
1029
|
+
return await this.fetchEndpoint("/v1/assets/" + id + "/stats", {});
|
|
1030
|
+
}
|
|
1031
|
+
async getAssetLogs(id, page = 1, limit = 100, order = "desc") {
|
|
1032
|
+
return await this.fetchEndpoint("/v1/assets/" + id + "/logs", { page, limit, order });
|
|
1033
|
+
}
|
|
1034
|
+
async getCollections(options = {}, page = 1, limit = 100) {
|
|
1035
|
+
return await this.fetchEndpoint("/v1/collections", { page, limit, ...options });
|
|
1036
|
+
}
|
|
1037
|
+
async countCollections(options = {}) {
|
|
1038
|
+
return await this.countEndpoint("/v1/collections", options);
|
|
1039
|
+
}
|
|
1040
|
+
async getCollection(name) {
|
|
1041
|
+
return await this.fetchEndpoint("/v1/collections/" + name, {});
|
|
1042
|
+
}
|
|
1043
|
+
async getCollectionStats(name) {
|
|
1044
|
+
return await this.fetchEndpoint("/v1/collections/" + name + "/stats", {});
|
|
1045
|
+
}
|
|
1046
|
+
async getCollectionLogs(name, page = 1, limit = 100, order = "desc") {
|
|
1047
|
+
return await this.fetchEndpoint("/v1/collections/" + name + "/logs", { page, limit, order });
|
|
1048
|
+
}
|
|
1049
|
+
async getSchemas(options = {}, page = 1, limit = 100) {
|
|
1050
|
+
return await this.fetchEndpoint("/v1/schemas", { page, limit, ...options });
|
|
1051
|
+
}
|
|
1052
|
+
async countSchemas(options = {}) {
|
|
1053
|
+
return await this.countEndpoint("/v1/schemas", options);
|
|
1054
|
+
}
|
|
1055
|
+
async getSchema(collection, name) {
|
|
1056
|
+
return await this.fetchEndpoint("/v1/schemas/" + collection + "/" + name, {});
|
|
1057
|
+
}
|
|
1058
|
+
async getSchemaStats(collection, name) {
|
|
1059
|
+
return await this.fetchEndpoint("/v1/schemas/" + collection + "/" + name + "/stats", {});
|
|
1060
|
+
}
|
|
1061
|
+
async getSchemaLogs(collection, name, page = 1, limit = 100, order = "desc") {
|
|
1062
|
+
return await this.fetchEndpoint("/v1/schemas/" + collection + "/" + name + "/logs", { page, limit, order });
|
|
1063
|
+
}
|
|
1064
|
+
async getTemplates(options = {}, page = 1, limit = 100, data = []) {
|
|
1065
|
+
return await this.fetchEndpoint("/v1/templates", { page, limit, ...buildDataOptions(options, data) });
|
|
1066
|
+
}
|
|
1067
|
+
async countTemplates(options = {}, data = []) {
|
|
1068
|
+
return await this.countEndpoint("/v1/templates", buildDataOptions(options, data));
|
|
1069
|
+
}
|
|
1070
|
+
async getTemplate(collection, id) {
|
|
1071
|
+
return await this.fetchEndpoint("/v1/templates/" + collection + "/" + id, {});
|
|
1072
|
+
}
|
|
1073
|
+
async getTemplateStats(collection, name) {
|
|
1074
|
+
return await this.fetchEndpoint("/v1/templates/" + collection + "/" + name + "/stats", {});
|
|
1075
|
+
}
|
|
1076
|
+
async getTemplateLogs(collection, id, page = 1, limit = 100, order = "desc") {
|
|
1077
|
+
return await this.fetchEndpoint("/v1/templates/" + collection + "/" + id + "/logs", { page, limit, order });
|
|
1078
|
+
}
|
|
1079
|
+
async getTransfers(options = {}, page = 1, limit = 100) {
|
|
1080
|
+
return await this.fetchEndpoint("/v1/transfers", { page, limit, ...options });
|
|
1081
|
+
}
|
|
1082
|
+
async countTransfers(options = {}) {
|
|
1083
|
+
return await this.countEndpoint("/v1/transfers", options);
|
|
1084
|
+
}
|
|
1085
|
+
async getOffers(options = {}, page = 1, limit = 100) {
|
|
1086
|
+
return await this.fetchEndpoint("/v1/offers", { page, limit, ...options });
|
|
1087
|
+
}
|
|
1088
|
+
async countOffers(options = {}) {
|
|
1089
|
+
return await this.countEndpoint("/v1/offers", options);
|
|
1090
|
+
}
|
|
1091
|
+
async getOffer(id) {
|
|
1092
|
+
return await this.fetchEndpoint("/v1/offers/" + id, {});
|
|
1093
|
+
}
|
|
1094
|
+
async getAccounts(options = {}, page = 1, limit = 100) {
|
|
1095
|
+
return await this.fetchEndpoint("/v1/accounts", { page, limit, ...options });
|
|
1096
|
+
}
|
|
1097
|
+
async getBurns(options = {}, page = 1, limit = 100) {
|
|
1098
|
+
return await this.fetchEndpoint("/v1/burns", { page, limit, ...options });
|
|
1099
|
+
}
|
|
1100
|
+
async countAccounts(options = {}) {
|
|
1101
|
+
return await this.countEndpoint("/v1/accounts", options);
|
|
1102
|
+
}
|
|
1103
|
+
async getAccount(account, options = {}) {
|
|
1104
|
+
return await this.fetchEndpoint("/v1/accounts/" + account, options);
|
|
1105
|
+
}
|
|
1106
|
+
async getAccountCollection(account, collection) {
|
|
1107
|
+
return await this.fetchEndpoint("/v1/accounts/" + account + "/" + collection, {});
|
|
1108
|
+
}
|
|
1109
|
+
async getAccountBurns(account, options = {}) {
|
|
1110
|
+
return await this.fetchEndpoint("/v1/burns/" + account, options);
|
|
1111
|
+
}
|
|
1112
|
+
async fetchEndpoint(path, args) {
|
|
1113
|
+
let response, json;
|
|
1114
|
+
const f = this.fetchBuiltin;
|
|
1115
|
+
const queryString = Object.keys(args).map((key) => {
|
|
1116
|
+
let value = args[key];
|
|
1117
|
+
if (value === true) {
|
|
1118
|
+
value = "true";
|
|
1119
|
+
}
|
|
1120
|
+
if (value === false) {
|
|
1121
|
+
value = "false";
|
|
1122
|
+
}
|
|
1123
|
+
return key + "=" + encodeURIComponent(value);
|
|
1124
|
+
}).join("&");
|
|
1125
|
+
try {
|
|
1126
|
+
if (queryString.length < 1e3) {
|
|
1127
|
+
response = await f(this.endpoint + "/" + this.namespace + path + (queryString.length > 0 ? "?" + queryString : ""));
|
|
1128
|
+
} else {
|
|
1129
|
+
response = await f(
|
|
1130
|
+
this.endpoint + "/" + this.namespace + path,
|
|
1131
|
+
{
|
|
1132
|
+
headers: {
|
|
1133
|
+
"accept": "*.*",
|
|
1134
|
+
"content-type": "application/json"
|
|
1135
|
+
},
|
|
1136
|
+
method: "POST",
|
|
1137
|
+
body: JSON.stringify(args)
|
|
1138
|
+
}
|
|
1139
|
+
);
|
|
1140
|
+
}
|
|
1141
|
+
json = await response.json();
|
|
1142
|
+
} catch (e) {
|
|
1143
|
+
throw new ApiError(e.message, 500);
|
|
1144
|
+
}
|
|
1145
|
+
if (response.status !== 200) {
|
|
1146
|
+
throw new ApiError(json.message, response.status);
|
|
1147
|
+
}
|
|
1148
|
+
if (!json.success) {
|
|
1149
|
+
throw new ApiError(json.message, response.status);
|
|
1150
|
+
}
|
|
1151
|
+
return json.data;
|
|
1152
|
+
}
|
|
1153
|
+
async countEndpoint(path, args) {
|
|
1154
|
+
const res = await this.fetchEndpoint(path + "/_count", args);
|
|
1155
|
+
return parseInt(res, 10);
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
|
|
1159
|
+
// src/Errors/RpcError.ts
|
|
1160
|
+
var RpcError = class extends Error {
|
|
1161
|
+
constructor(json) {
|
|
1162
|
+
if (json.error && json.error.details && json.error.details.length && json.error.details[0].message) {
|
|
1163
|
+
super(json.error.details[0].message);
|
|
1164
|
+
} else if (json.processed && json.processed.except && json.processed.except.message) {
|
|
1165
|
+
super(json.processed.except.message);
|
|
1166
|
+
} else {
|
|
1167
|
+
super(json.message);
|
|
1168
|
+
}
|
|
1169
|
+
this.json = json;
|
|
1170
|
+
}
|
|
1171
|
+
};
|
|
1172
|
+
|
|
1173
|
+
// src/Errors/SchemaError.ts
|
|
1174
|
+
var SchemaError = class extends Error {
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1177
|
+
// src/Errors/DeserializationError.ts
|
|
1178
|
+
var DeserializationError = class extends Error {
|
|
1179
|
+
};
|
|
1180
|
+
|
|
1181
|
+
// src/Serialization/Coders/Base.ts
|
|
1182
|
+
var BaseCoder = class {
|
|
1183
|
+
constructor(ALPHABET) {
|
|
1184
|
+
this.ALPHABET = ALPHABET;
|
|
1185
|
+
if (ALPHABET.length >= 255) {
|
|
1186
|
+
throw new TypeError("Alphabet too long");
|
|
1187
|
+
}
|
|
1188
|
+
this.BASE_MAP = new Uint8Array(256);
|
|
1189
|
+
for (let j = 0; j < this.BASE_MAP.length; j++) {
|
|
1190
|
+
this.BASE_MAP[j] = 255;
|
|
1191
|
+
}
|
|
1192
|
+
for (let i = 0; i < ALPHABET.length; i++) {
|
|
1193
|
+
const x = ALPHABET.charAt(i);
|
|
1194
|
+
const xc = x.charCodeAt(0);
|
|
1195
|
+
if (this.BASE_MAP[xc] !== 255) {
|
|
1196
|
+
throw new TypeError(x + " is ambiguous");
|
|
1197
|
+
}
|
|
1198
|
+
this.BASE_MAP[xc] = i;
|
|
1199
|
+
}
|
|
1200
|
+
this.BASE = ALPHABET.length;
|
|
1201
|
+
this.LEADER = ALPHABET.charAt(0);
|
|
1202
|
+
this.FACTOR = Math.log(this.BASE) / Math.log(256);
|
|
1203
|
+
this.iFACTOR = Math.log(256) / Math.log(this.BASE);
|
|
1204
|
+
}
|
|
1205
|
+
encode(source) {
|
|
1206
|
+
if (source.length === 0) {
|
|
1207
|
+
return "";
|
|
1208
|
+
}
|
|
1209
|
+
let zeroes = 0;
|
|
1210
|
+
let length = 0;
|
|
1211
|
+
let pbegin = 0;
|
|
1212
|
+
const pend = source.length;
|
|
1213
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
1214
|
+
pbegin++;
|
|
1215
|
+
zeroes++;
|
|
1216
|
+
}
|
|
1217
|
+
const size = (pend - pbegin) * this.iFACTOR + 1 >>> 0;
|
|
1218
|
+
const b58 = new Uint8Array(size);
|
|
1219
|
+
while (pbegin !== pend) {
|
|
1220
|
+
let carry = source[pbegin];
|
|
1221
|
+
let i = 0;
|
|
1222
|
+
for (let it1 = size - 1; (carry !== 0 || i < length) && it1 !== -1; it1--, i++) {
|
|
1223
|
+
carry += 256 * b58[it1] >>> 0;
|
|
1224
|
+
b58[it1] = carry % this.BASE >>> 0;
|
|
1225
|
+
carry = carry / this.BASE >>> 0;
|
|
1226
|
+
}
|
|
1227
|
+
if (carry !== 0) {
|
|
1228
|
+
throw new Error("Non-zero carry");
|
|
1229
|
+
}
|
|
1230
|
+
length = i;
|
|
1231
|
+
pbegin++;
|
|
1232
|
+
}
|
|
1233
|
+
let it2 = size - length;
|
|
1234
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
1235
|
+
it2++;
|
|
1236
|
+
}
|
|
1237
|
+
let str = this.LEADER.repeat(zeroes);
|
|
1238
|
+
for (; it2 < size; ++it2) {
|
|
1239
|
+
str += this.ALPHABET.charAt(b58[it2]);
|
|
1240
|
+
}
|
|
1241
|
+
return str;
|
|
1242
|
+
}
|
|
1243
|
+
decode(source) {
|
|
1244
|
+
const buffer = this.decodeUnsafe(source);
|
|
1245
|
+
if (buffer) {
|
|
1246
|
+
return buffer;
|
|
1247
|
+
}
|
|
1248
|
+
throw new Error("Non-base" + this.BASE + " character");
|
|
1249
|
+
}
|
|
1250
|
+
// Returns null on invalid input (mirroring upstream base-x's undefined) so
|
|
1251
|
+
// decode() can raise; the empty string legitimately decodes to zero bytes.
|
|
1252
|
+
decodeUnsafe(source) {
|
|
1253
|
+
if (source.length === 0) {
|
|
1254
|
+
return new Uint8Array(0);
|
|
1255
|
+
}
|
|
1256
|
+
let psz = 0;
|
|
1257
|
+
if (source[psz] === " ") {
|
|
1258
|
+
return null;
|
|
1259
|
+
}
|
|
1260
|
+
let zeroes = 0;
|
|
1261
|
+
let length = 0;
|
|
1262
|
+
while (source[psz] === this.LEADER) {
|
|
1263
|
+
zeroes++;
|
|
1264
|
+
psz++;
|
|
1265
|
+
}
|
|
1266
|
+
const size = (source.length - psz) * this.FACTOR + 1 >>> 0;
|
|
1267
|
+
const b256 = new Uint8Array(size);
|
|
1268
|
+
while (source[psz]) {
|
|
1269
|
+
let carry = this.BASE_MAP[source.charCodeAt(psz)];
|
|
1270
|
+
if (carry === 255) {
|
|
1271
|
+
return null;
|
|
1272
|
+
}
|
|
1273
|
+
let i = 0;
|
|
1274
|
+
for (let it3 = size - 1; (carry !== 0 || i < length) && it3 !== -1; it3--, i++) {
|
|
1275
|
+
carry += this.BASE * b256[it3] >>> 0;
|
|
1276
|
+
b256[it3] = carry % 256 >>> 0;
|
|
1277
|
+
carry = carry / 256 >>> 0;
|
|
1278
|
+
}
|
|
1279
|
+
if (carry !== 0) {
|
|
1280
|
+
throw new Error("Non-zero carry");
|
|
1281
|
+
}
|
|
1282
|
+
length = i;
|
|
1283
|
+
psz++;
|
|
1284
|
+
}
|
|
1285
|
+
if (source[psz] === " ") {
|
|
1286
|
+
return null;
|
|
1287
|
+
}
|
|
1288
|
+
let it4 = size - length;
|
|
1289
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
1290
|
+
it4++;
|
|
1291
|
+
}
|
|
1292
|
+
const vch = new Uint8Array(zeroes + (size - it4));
|
|
1293
|
+
vch.fill(0, 0, zeroes);
|
|
1294
|
+
let j = zeroes;
|
|
1295
|
+
while (it4 !== size) {
|
|
1296
|
+
vch[j++] = b256[it4++];
|
|
1297
|
+
}
|
|
1298
|
+
return vch;
|
|
1299
|
+
}
|
|
1300
|
+
};
|
|
1301
|
+
|
|
1302
|
+
// src/Serialization/Binary.ts
|
|
1303
|
+
function varint_encode(input) {
|
|
1304
|
+
const bytes = [];
|
|
1305
|
+
let n = BigInt(input);
|
|
1306
|
+
if (n < 0n) {
|
|
1307
|
+
throw new SerializationError("cant pack negative integer");
|
|
1308
|
+
}
|
|
1309
|
+
while (true) {
|
|
1310
|
+
const byte = n & 0x7Fn;
|
|
1311
|
+
n = n >> 7n;
|
|
1312
|
+
if (n === 0n) {
|
|
1313
|
+
bytes.push(Number(byte));
|
|
1314
|
+
break;
|
|
1315
|
+
}
|
|
1316
|
+
bytes.push(Number(byte) + 128);
|
|
1317
|
+
}
|
|
1318
|
+
return new Uint8Array(bytes);
|
|
1319
|
+
}
|
|
1320
|
+
var VARINT_MAX_BYTES = 10;
|
|
1321
|
+
function varint_decode(state) {
|
|
1322
|
+
let result = 0n;
|
|
1323
|
+
for (let i = 0; true; i++) {
|
|
1324
|
+
if (i >= VARINT_MAX_BYTES) {
|
|
1325
|
+
throw new DeserializationError("varint exceeds maximum encoded length");
|
|
1326
|
+
}
|
|
1327
|
+
if (state.position >= state.data.length) {
|
|
1328
|
+
throw new DeserializationError("failed to unpack integer");
|
|
1329
|
+
}
|
|
1330
|
+
const byte = BigInt(state.data[state.position]);
|
|
1331
|
+
state.position += 1;
|
|
1332
|
+
if (byte < 128n) {
|
|
1333
|
+
result = result + (byte << BigInt(7 * i));
|
|
1334
|
+
break;
|
|
1335
|
+
}
|
|
1336
|
+
result = result + ((byte & 0x7Fn) << BigInt(7 * i));
|
|
1337
|
+
}
|
|
1338
|
+
return result;
|
|
1339
|
+
}
|
|
1340
|
+
function zigzag_encode(input) {
|
|
1341
|
+
const n = BigInt(input);
|
|
1342
|
+
if (n < 0n) {
|
|
1343
|
+
return (n + 1n) * -2n + 1n;
|
|
1344
|
+
}
|
|
1345
|
+
return n * 2n;
|
|
1346
|
+
}
|
|
1347
|
+
function zigzag_decode(input) {
|
|
1348
|
+
const n = BigInt(input);
|
|
1349
|
+
if (n % 2n === 0n) {
|
|
1350
|
+
return n / 2n;
|
|
1351
|
+
}
|
|
1352
|
+
return n / 2n * -1n - 1n;
|
|
1353
|
+
}
|
|
1354
|
+
var bs58 = new BaseCoder("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
1355
|
+
function base58_decode(data) {
|
|
1356
|
+
return bs58.decode(data);
|
|
1357
|
+
}
|
|
1358
|
+
function base58_encode(data) {
|
|
1359
|
+
return bs58.encode(data);
|
|
1360
|
+
}
|
|
1361
|
+
function hex_decode(hex) {
|
|
1362
|
+
if (!/^([0-9a-fA-F]{2})*$/.test(hex)) {
|
|
1363
|
+
throw new DeserializationError("invalid hex string");
|
|
1364
|
+
}
|
|
1365
|
+
const bytes = hex.match(/.{2}/g);
|
|
1366
|
+
if (!bytes) {
|
|
1367
|
+
return new Uint8Array(0);
|
|
1368
|
+
}
|
|
1369
|
+
return new Uint8Array(bytes.map((byte) => parseInt(byte, 16)));
|
|
1370
|
+
}
|
|
1371
|
+
function concat_byte_arrays(arr) {
|
|
1372
|
+
const data = new Uint8Array(arr.reduce((acc, val) => acc + val.length, 0));
|
|
1373
|
+
let offset = 0;
|
|
1374
|
+
for (const bytes of arr) {
|
|
1375
|
+
data.set(bytes, offset);
|
|
1376
|
+
offset += bytes.length;
|
|
1377
|
+
}
|
|
1378
|
+
return data;
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// src/Schema/MappingSchema.ts
|
|
1382
|
+
var MappingSchema = class {
|
|
1383
|
+
constructor(attributes) {
|
|
1384
|
+
this.attributes = attributes;
|
|
1385
|
+
this.reserved = 4;
|
|
1386
|
+
}
|
|
1387
|
+
deserialize(state, upwardsCompatible = false) {
|
|
1388
|
+
const object = {};
|
|
1389
|
+
while (state.position < state.data.length) {
|
|
1390
|
+
const identifier = varint_decode(state);
|
|
1391
|
+
if (identifier === 0n) {
|
|
1392
|
+
break;
|
|
1393
|
+
}
|
|
1394
|
+
const attribute = this.getAttribute(Number(identifier), !upwardsCompatible);
|
|
1395
|
+
if (attribute) {
|
|
1396
|
+
Object.defineProperty(object, attribute.name, {
|
|
1397
|
+
value: attribute.value.deserialize(state),
|
|
1398
|
+
enumerable: true,
|
|
1399
|
+
writable: true,
|
|
1400
|
+
configurable: true
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
return object;
|
|
1405
|
+
}
|
|
1406
|
+
serialize(object) {
|
|
1407
|
+
const data = [];
|
|
1408
|
+
for (let i = 0; i < this.attributes.length; i++) {
|
|
1409
|
+
const attribute = this.attributes[i];
|
|
1410
|
+
if (typeof object[attribute.name] === "undefined") {
|
|
1411
|
+
continue;
|
|
1412
|
+
}
|
|
1413
|
+
data.push(varint_encode(i + this.reserved));
|
|
1414
|
+
data.push(attribute.value.serialize(object[attribute.name]));
|
|
1415
|
+
}
|
|
1416
|
+
data.push(varint_encode(0));
|
|
1417
|
+
return concat_byte_arrays(data);
|
|
1418
|
+
}
|
|
1419
|
+
getAttribute(identifier, throwError = true) {
|
|
1420
|
+
const attributeID = identifier - this.reserved;
|
|
1421
|
+
if (attributeID >= this.attributes.length) {
|
|
1422
|
+
if (throwError) {
|
|
1423
|
+
throw new SchemaError("attribute does not exists");
|
|
1424
|
+
}
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
return this.attributes[Number(attributeID)];
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
// src/Serialization/State.ts
|
|
1432
|
+
var SerializationState = class {
|
|
1433
|
+
constructor(data, position = 0) {
|
|
1434
|
+
this.data = data;
|
|
1435
|
+
this.position = position;
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1438
|
+
|
|
1439
|
+
// src/Serialization/index.ts
|
|
1440
|
+
function toByteArray(data) {
|
|
1441
|
+
if (typeof data === "string") {
|
|
1442
|
+
return hex_decode(data.startsWith("\\x") ? data.substring(2) : data);
|
|
1443
|
+
}
|
|
1444
|
+
if (data instanceof Uint8Array) {
|
|
1445
|
+
return data;
|
|
1446
|
+
}
|
|
1447
|
+
return new Uint8Array(data);
|
|
1448
|
+
}
|
|
1449
|
+
function serialize(object, schema) {
|
|
1450
|
+
const data = schema.serialize(object);
|
|
1451
|
+
if (schema instanceof MappingSchema) {
|
|
1452
|
+
return data.slice(0, data.length - 1);
|
|
1453
|
+
}
|
|
1454
|
+
return data;
|
|
1455
|
+
}
|
|
1456
|
+
function deserialize(data, schema) {
|
|
1457
|
+
let bytes = toByteArray(data);
|
|
1458
|
+
if (schema instanceof MappingSchema) {
|
|
1459
|
+
bytes = concat_byte_arrays([bytes, varint_encode(0)]);
|
|
1460
|
+
}
|
|
1461
|
+
const state = new SerializationState(bytes, 0);
|
|
1462
|
+
return schema.deserialize(state);
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
// src/Schema/ValueSchema.ts
|
|
1466
|
+
var ValueSchema = class {
|
|
1467
|
+
constructor(type) {
|
|
1468
|
+
if (typeof ParserTypes[type] === "undefined") {
|
|
1469
|
+
throw new SchemaError(`attribute type '${type}' not defined`);
|
|
1470
|
+
}
|
|
1471
|
+
this.parser = ParserTypes[type];
|
|
1472
|
+
}
|
|
1473
|
+
deserialize(state) {
|
|
1474
|
+
return this.parser.deserialize(state);
|
|
1475
|
+
}
|
|
1476
|
+
serialize(value) {
|
|
1477
|
+
return this.parser.serialize(value);
|
|
1478
|
+
}
|
|
1479
|
+
};
|
|
1480
|
+
|
|
1481
|
+
// src/Schema/VectorSchema.ts
|
|
1482
|
+
var VectorSchema = class {
|
|
1483
|
+
constructor(element) {
|
|
1484
|
+
this.element = element;
|
|
1485
|
+
}
|
|
1486
|
+
deserialize(state) {
|
|
1487
|
+
const rawLength = varint_decode(state);
|
|
1488
|
+
if (rawLength > BigInt(state.data.length - state.position)) {
|
|
1489
|
+
throw new DeserializationError("VectorSchema: length exceeds remaining data");
|
|
1490
|
+
}
|
|
1491
|
+
const length = Number(rawLength);
|
|
1492
|
+
const array = [];
|
|
1493
|
+
for (let i = 0; i < length; i++) {
|
|
1494
|
+
array.push(this.element.deserialize(state));
|
|
1495
|
+
}
|
|
1496
|
+
return array;
|
|
1497
|
+
}
|
|
1498
|
+
serialize(array) {
|
|
1499
|
+
const data = [varint_encode(array.length)];
|
|
1500
|
+
for (const element of array) {
|
|
1501
|
+
data.push(this.element.serialize(element));
|
|
1502
|
+
}
|
|
1503
|
+
return concat_byte_arrays(data);
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
|
|
1507
|
+
// src/Schema/index.ts
|
|
1508
|
+
function buildObjectSchema(objectID, lookup) {
|
|
1509
|
+
const attributes = [];
|
|
1510
|
+
let fields = lookup[objectID];
|
|
1511
|
+
if (typeof fields === "undefined") {
|
|
1512
|
+
fields = [];
|
|
1513
|
+
}
|
|
1514
|
+
delete lookup[objectID];
|
|
1515
|
+
for (const field of fields) {
|
|
1516
|
+
attributes.push({ name: field.name, value: buildValueSchema(field.type, lookup) });
|
|
1517
|
+
}
|
|
1518
|
+
return new MappingSchema(attributes);
|
|
1519
|
+
}
|
|
1520
|
+
function buildValueSchema(type, lookup) {
|
|
1521
|
+
if (type.endsWith("[]")) {
|
|
1522
|
+
return new VectorSchema(buildValueSchema(type.substring(0, type.length - 2), lookup));
|
|
1523
|
+
}
|
|
1524
|
+
if (type.startsWith("object{") && type.endsWith("}")) {
|
|
1525
|
+
const objectID = parseInt(type.substring(7, type.length - 1), 10);
|
|
1526
|
+
if (isNaN(objectID)) {
|
|
1527
|
+
throw new SchemaError(`invalid type '${type}'`);
|
|
1528
|
+
}
|
|
1529
|
+
return buildObjectSchema(objectID, lookup);
|
|
1530
|
+
}
|
|
1531
|
+
return new ValueSchema(type);
|
|
1532
|
+
}
|
|
1533
|
+
function ObjectSchema(schema) {
|
|
1534
|
+
const objectLookup = {};
|
|
1535
|
+
for (const schemaObject of schema) {
|
|
1536
|
+
const objectID = typeof schemaObject.parent === "undefined" ? 0 : schemaObject.parent;
|
|
1537
|
+
if (typeof objectLookup[objectID] === "undefined") {
|
|
1538
|
+
objectLookup[objectID] = [];
|
|
1539
|
+
}
|
|
1540
|
+
objectLookup[objectID].push(schemaObject);
|
|
1541
|
+
}
|
|
1542
|
+
return buildObjectSchema(0, objectLookup);
|
|
1543
|
+
}
|
|
1544
|
+
var objectSchemaCache = /* @__PURE__ */ new Map();
|
|
1545
|
+
var OBJECT_SCHEMA_CACHE_MAX_ENTRIES = 500;
|
|
1546
|
+
function CachedObjectSchema(schema) {
|
|
1547
|
+
const key = JSON.stringify(schema);
|
|
1548
|
+
let cached = objectSchemaCache.get(key);
|
|
1549
|
+
if (!cached) {
|
|
1550
|
+
cached = ObjectSchema(schema);
|
|
1551
|
+
if (objectSchemaCache.size >= OBJECT_SCHEMA_CACHE_MAX_ENTRIES) {
|
|
1552
|
+
const oldestKey = objectSchemaCache.keys().next().value;
|
|
1553
|
+
if (oldestKey !== void 0) {
|
|
1554
|
+
objectSchemaCache.delete(oldestKey);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
objectSchemaCache.set(key, cached);
|
|
1558
|
+
}
|
|
1559
|
+
return cached;
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
// src/API/Rpc/Collection.ts
|
|
1563
|
+
var RpcCollection = class {
|
|
1564
|
+
constructor(api, name, data, cache = true) {
|
|
1565
|
+
this.api = api;
|
|
1566
|
+
this.name = name;
|
|
1567
|
+
this._data = new Promise(async (resolve, reject) => {
|
|
1568
|
+
if (data) {
|
|
1569
|
+
resolve(data);
|
|
1570
|
+
} else {
|
|
1571
|
+
try {
|
|
1572
|
+
resolve(await api.queue.fetchCollection(name, cache));
|
|
1573
|
+
} catch (e) {
|
|
1574
|
+
reject(e);
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
async author() {
|
|
1580
|
+
return (await this._data).author;
|
|
1581
|
+
}
|
|
1582
|
+
async allowNotify() {
|
|
1583
|
+
return (await this._data).allow_notify;
|
|
1584
|
+
}
|
|
1585
|
+
async authorizedAccounts() {
|
|
1586
|
+
return (await this._data).authorized_accounts;
|
|
1587
|
+
}
|
|
1588
|
+
async notifyAccounts() {
|
|
1589
|
+
return (await this._data).notify_accounts;
|
|
1590
|
+
}
|
|
1591
|
+
async marketFee() {
|
|
1592
|
+
return Number((await this._data).market_fee);
|
|
1593
|
+
}
|
|
1594
|
+
async data() {
|
|
1595
|
+
return deserialize((await this._data).serialized_data, ObjectSchema((await this.api.config()).collection_format));
|
|
1596
|
+
}
|
|
1597
|
+
async toObject() {
|
|
1598
|
+
return {
|
|
1599
|
+
collection_name: this.name,
|
|
1600
|
+
author: await this.author(),
|
|
1601
|
+
allowNotify: await this.allowNotify(),
|
|
1602
|
+
authorizedAccounts: await this.authorizedAccounts(),
|
|
1603
|
+
notifyAccounts: await this.notifyAccounts(),
|
|
1604
|
+
marketFee: await this.marketFee(),
|
|
1605
|
+
data: await this.data()
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1609
|
+
|
|
1610
|
+
// src/API/Rpc/Schema.ts
|
|
1611
|
+
var RpcSchema = class {
|
|
1612
|
+
constructor(api, collection, name, data, cache = true) {
|
|
1613
|
+
this.api = api;
|
|
1614
|
+
this._formatTypes = null;
|
|
1615
|
+
this.collection = collection;
|
|
1616
|
+
this.name = name;
|
|
1617
|
+
this._data = new Promise(async (resolve, reject) => {
|
|
1618
|
+
if (data) {
|
|
1619
|
+
resolve(data);
|
|
1620
|
+
} else {
|
|
1621
|
+
try {
|
|
1622
|
+
resolve(await api.queue.fetchSchema(collection, name, cache));
|
|
1623
|
+
} catch (e) {
|
|
1624
|
+
reject(e);
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
});
|
|
1628
|
+
this._collection = new Promise(async (resolve, reject) => {
|
|
1629
|
+
try {
|
|
1630
|
+
resolve(new RpcCollection(api, collection, void 0, cache));
|
|
1631
|
+
} catch (e) {
|
|
1632
|
+
reject(e);
|
|
1633
|
+
}
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
async format() {
|
|
1637
|
+
return ObjectSchema((await this._data).format);
|
|
1638
|
+
}
|
|
1639
|
+
async rawFormat() {
|
|
1640
|
+
return (await this._data).format;
|
|
1641
|
+
}
|
|
1642
|
+
// v2 per-field media-type hints (schematypes table, set via setschematyp);
|
|
1643
|
+
// empty for schemas without a types row.
|
|
1644
|
+
async formatTypes() {
|
|
1645
|
+
if (!this._formatTypes) {
|
|
1646
|
+
this._formatTypes = this.api.queue.fetchSchemaFormatTypes(this.collection, this.name);
|
|
1647
|
+
}
|
|
1648
|
+
return await this._formatTypes;
|
|
1649
|
+
}
|
|
1650
|
+
async toObject() {
|
|
1651
|
+
return {
|
|
1652
|
+
collection_name: this.collection,
|
|
1653
|
+
schema_name: this.name,
|
|
1654
|
+
format: await this.rawFormat()
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
|
|
1659
|
+
// src/API/Rpc/Template.ts
|
|
1660
|
+
var RpcTemplate = class {
|
|
1661
|
+
constructor(api, collection, id, data, schema, cache = true) {
|
|
1662
|
+
this.api = api;
|
|
1663
|
+
this.collection = collection;
|
|
1664
|
+
this.id = id;
|
|
1665
|
+
this._data = new Promise(async (resolve, reject) => {
|
|
1666
|
+
if (data) {
|
|
1667
|
+
resolve(data);
|
|
1668
|
+
} else {
|
|
1669
|
+
try {
|
|
1670
|
+
resolve(await api.queue.fetchTemplate(collection, id, cache));
|
|
1671
|
+
} catch (e) {
|
|
1672
|
+
reject(e);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
});
|
|
1676
|
+
this._schema = new Promise(async (resolve, reject) => {
|
|
1677
|
+
if (schema) {
|
|
1678
|
+
resolve(schema);
|
|
1679
|
+
} else {
|
|
1680
|
+
try {
|
|
1681
|
+
const row = await this._data;
|
|
1682
|
+
resolve(new RpcSchema(this.api, collection, row.schema_name, void 0, cache));
|
|
1683
|
+
} catch (e) {
|
|
1684
|
+
reject(e);
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
});
|
|
1688
|
+
}
|
|
1689
|
+
async schema() {
|
|
1690
|
+
return await this._schema;
|
|
1691
|
+
}
|
|
1692
|
+
async immutableData() {
|
|
1693
|
+
const schema = await this._schema;
|
|
1694
|
+
return deserialize((await this._data).immutable_serialized_data, await schema.format());
|
|
1695
|
+
}
|
|
1696
|
+
// v2 mutable template data (templates2 table, set via
|
|
1697
|
+
// createtempl2/settempldata); empty for templates without a mutable row.
|
|
1698
|
+
async mutableData() {
|
|
1699
|
+
const schema = await this._schema;
|
|
1700
|
+
return deserialize((await this._data).mutable_serialized_data, await schema.format());
|
|
1701
|
+
}
|
|
1702
|
+
// immutable_data wins over mutable_data on key collision: immutable
|
|
1703
|
+
// attributes are set at mint time and mutable data must not be able to
|
|
1704
|
+
// override them, so immutableData is applied last.
|
|
1705
|
+
async data() {
|
|
1706
|
+
return Object.assign({}, await this.mutableData(), await this.immutableData());
|
|
1707
|
+
}
|
|
1708
|
+
async isTransferable() {
|
|
1709
|
+
return (await this._data).transferable;
|
|
1710
|
+
}
|
|
1711
|
+
async isBurnable() {
|
|
1712
|
+
return (await this._data).burnable;
|
|
1713
|
+
}
|
|
1714
|
+
async maxSupply() {
|
|
1715
|
+
return (await this._data).max_supply;
|
|
1716
|
+
}
|
|
1717
|
+
async circulation() {
|
|
1718
|
+
return (await this._data).issued_supply;
|
|
1719
|
+
}
|
|
1720
|
+
async toObject() {
|
|
1721
|
+
return {
|
|
1722
|
+
collection_name: this.collection,
|
|
1723
|
+
template_id: this.id,
|
|
1724
|
+
schema: await (await this.schema()).toObject(),
|
|
1725
|
+
immutableData: await this.immutableData(),
|
|
1726
|
+
mutableData: await this.mutableData(),
|
|
1727
|
+
transferable: await this.isTransferable(),
|
|
1728
|
+
burnable: await this.isBurnable(),
|
|
1729
|
+
maxSupply: await this.maxSupply(),
|
|
1730
|
+
circulation: await this.circulation()
|
|
1731
|
+
};
|
|
1732
|
+
}
|
|
1733
|
+
};
|
|
1734
|
+
|
|
1735
|
+
// src/API/Rpc/Asset.ts
|
|
1736
|
+
var RpcAsset = class {
|
|
1737
|
+
constructor(api, owner, id, data, collection, schema, template, cache = true) {
|
|
1738
|
+
this.api = api;
|
|
1739
|
+
this.owner = owner;
|
|
1740
|
+
this.id = id;
|
|
1741
|
+
this._data = new Promise(async (resolve, reject) => {
|
|
1742
|
+
if (data) {
|
|
1743
|
+
resolve(data);
|
|
1744
|
+
} else {
|
|
1745
|
+
try {
|
|
1746
|
+
resolve(await api.queue.fetchAsset(owner, id, cache));
|
|
1747
|
+
} catch (e) {
|
|
1748
|
+
reject(e);
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
});
|
|
1752
|
+
this._template = new Promise(async (resolve, reject) => {
|
|
1753
|
+
if (template) {
|
|
1754
|
+
resolve(template);
|
|
1755
|
+
} else {
|
|
1756
|
+
try {
|
|
1757
|
+
const row = await this._data;
|
|
1758
|
+
if (Number(row.template_id) < 0) {
|
|
1759
|
+
return resolve(null);
|
|
1760
|
+
}
|
|
1761
|
+
resolve(new RpcTemplate(api, row.collection_name, row.template_id, void 0, void 0, cache));
|
|
1762
|
+
} catch (e) {
|
|
1763
|
+
reject(e);
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
});
|
|
1767
|
+
this._collection = new Promise(async (resolve, reject) => {
|
|
1768
|
+
if (collection) {
|
|
1769
|
+
resolve(collection);
|
|
1770
|
+
} else {
|
|
1771
|
+
try {
|
|
1772
|
+
const row = await this._data;
|
|
1773
|
+
resolve(new RpcCollection(api, row.collection_name, void 0, cache));
|
|
1774
|
+
} catch (e) {
|
|
1775
|
+
reject(e);
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
});
|
|
1779
|
+
this._schema = new Promise(async (resolve, reject) => {
|
|
1780
|
+
if (schema) {
|
|
1781
|
+
resolve(schema);
|
|
1782
|
+
} else {
|
|
1783
|
+
try {
|
|
1784
|
+
const row = await this._data;
|
|
1785
|
+
resolve(new RpcSchema(api, row.collection_name, row.schema_name, void 0, cache));
|
|
1786
|
+
} catch (e) {
|
|
1787
|
+
reject(e);
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
async template() {
|
|
1793
|
+
return await this._template;
|
|
1794
|
+
}
|
|
1795
|
+
async collection() {
|
|
1796
|
+
return await this._collection;
|
|
1797
|
+
}
|
|
1798
|
+
async schema() {
|
|
1799
|
+
return await this._schema;
|
|
1800
|
+
}
|
|
1801
|
+
async backedTokens() {
|
|
1802
|
+
return (await this._data).backed_tokens;
|
|
1803
|
+
}
|
|
1804
|
+
async immutableData() {
|
|
1805
|
+
const schema = await this.schema();
|
|
1806
|
+
const row = await this._data;
|
|
1807
|
+
return deserialize(row.immutable_serialized_data, await schema.format());
|
|
1808
|
+
}
|
|
1809
|
+
async mutableData() {
|
|
1810
|
+
const schema = await this.schema();
|
|
1811
|
+
const row = await this._data;
|
|
1812
|
+
return deserialize(row.mutable_serialized_data, await schema.format());
|
|
1813
|
+
}
|
|
1814
|
+
// template data overrides asset data on key collision: assets inherit
|
|
1815
|
+
// their attributes from the template and cannot override them, so
|
|
1816
|
+
// templateData is applied last (this is canonical AtomicAssets
|
|
1817
|
+
// semantics). Within templateData itself, immutable_data already won
|
|
1818
|
+
// over mutable_data (see Template#data).
|
|
1819
|
+
async data() {
|
|
1820
|
+
const mutableData = await this.mutableData();
|
|
1821
|
+
const immutableData = await this.immutableData();
|
|
1822
|
+
const template = await this.template();
|
|
1823
|
+
const templateData = template ? await template.data() : {};
|
|
1824
|
+
return Object.assign({}, mutableData, immutableData, templateData);
|
|
1825
|
+
}
|
|
1826
|
+
async toObject() {
|
|
1827
|
+
const template = await this.template();
|
|
1828
|
+
const collection = await this.collection();
|
|
1829
|
+
const schema = await this.schema();
|
|
1830
|
+
return {
|
|
1831
|
+
asset_id: this.id,
|
|
1832
|
+
collection: await collection.toObject(),
|
|
1833
|
+
schema: await schema.toObject(),
|
|
1834
|
+
template: template ? await template.toObject() : null,
|
|
1835
|
+
backedTokens: await this.backedTokens(),
|
|
1836
|
+
immutableData: await this.immutableData(),
|
|
1837
|
+
mutableData: await this.mutableData(),
|
|
1838
|
+
data: await this.data()
|
|
1839
|
+
};
|
|
1840
|
+
}
|
|
1841
|
+
};
|
|
1842
|
+
|
|
1843
|
+
// src/API/Rpc/BaseCache.ts
|
|
1844
|
+
var MemoryCache = class {
|
|
1845
|
+
constructor() {
|
|
1846
|
+
this.store = {};
|
|
1847
|
+
}
|
|
1848
|
+
get(key) {
|
|
1849
|
+
const res = this.store[key];
|
|
1850
|
+
if (typeof res === "undefined") {
|
|
1851
|
+
return null;
|
|
1852
|
+
}
|
|
1853
|
+
const [value, expires] = res;
|
|
1854
|
+
if (/* @__PURE__ */ new Date() > expires) {
|
|
1855
|
+
delete this.store[key];
|
|
1856
|
+
return null;
|
|
1857
|
+
}
|
|
1858
|
+
return value;
|
|
1859
|
+
}
|
|
1860
|
+
put(key, value, timeout) {
|
|
1861
|
+
const expires = new Date(Date.now() + timeout);
|
|
1862
|
+
this.store[key] = [value, expires];
|
|
1863
|
+
}
|
|
1864
|
+
remove(key) {
|
|
1865
|
+
delete this.store[key];
|
|
1866
|
+
}
|
|
1867
|
+
};
|
|
1868
|
+
|
|
1869
|
+
// src/API/Rpc/RpcCache.ts
|
|
1870
|
+
var RpcCache = class {
|
|
1871
|
+
constructor() {
|
|
1872
|
+
this.cache = new MemoryCache();
|
|
1873
|
+
}
|
|
1874
|
+
getAsset(assetID, data) {
|
|
1875
|
+
if (data) {
|
|
1876
|
+
data.mutable_serialized_data = new Uint8Array(data.mutable_serialized_data);
|
|
1877
|
+
data.immutable_serialized_data = new Uint8Array(data.immutable_serialized_data);
|
|
1878
|
+
}
|
|
1879
|
+
return this.access("assets", assetID, data);
|
|
1880
|
+
}
|
|
1881
|
+
deleteAsset(assetID) {
|
|
1882
|
+
this.delete("assets", assetID);
|
|
1883
|
+
}
|
|
1884
|
+
getTemplate(collectionName, templateID, data) {
|
|
1885
|
+
if (data) {
|
|
1886
|
+
data.immutable_serialized_data = new Uint8Array(data.immutable_serialized_data);
|
|
1887
|
+
data.mutable_serialized_data = new Uint8Array(data.mutable_serialized_data ?? []);
|
|
1888
|
+
}
|
|
1889
|
+
return this.access("templates", collectionName + ":" + templateID, data);
|
|
1890
|
+
}
|
|
1891
|
+
deleteTemplate(collectionName, templateID) {
|
|
1892
|
+
this.delete("templates", collectionName + ":" + templateID);
|
|
1893
|
+
}
|
|
1894
|
+
getSchema(collectionName, schemaName, data) {
|
|
1895
|
+
return this.access("schemas", collectionName + ":" + schemaName, data);
|
|
1896
|
+
}
|
|
1897
|
+
deleteSchema(collectionName, schemaName) {
|
|
1898
|
+
this.delete("schemas", collectionName + ":" + schemaName);
|
|
1899
|
+
}
|
|
1900
|
+
getCollection(collectionName, data) {
|
|
1901
|
+
return this.access("collections", collectionName, data);
|
|
1902
|
+
}
|
|
1903
|
+
deleteCollection(collectionName) {
|
|
1904
|
+
this.delete("collections", collectionName);
|
|
1905
|
+
}
|
|
1906
|
+
getOffer(offerID, data) {
|
|
1907
|
+
return this.access("offers", offerID, data);
|
|
1908
|
+
}
|
|
1909
|
+
deleteOffer(offerID) {
|
|
1910
|
+
this.delete("offers", offerID);
|
|
1911
|
+
}
|
|
1912
|
+
access(namespace, identifier, data) {
|
|
1913
|
+
if (typeof data === "undefined") {
|
|
1914
|
+
const cache = this.cache.get(namespace + ":" + identifier);
|
|
1915
|
+
return cache === null ? null : cache;
|
|
1916
|
+
}
|
|
1917
|
+
this.cache.put(namespace + ":" + identifier, data, 15 * 60 * 1e3);
|
|
1918
|
+
return data;
|
|
1919
|
+
}
|
|
1920
|
+
delete(namespace, identifier) {
|
|
1921
|
+
this.cache.remove(namespace + ":" + identifier);
|
|
1922
|
+
}
|
|
1923
|
+
};
|
|
1924
|
+
|
|
1925
|
+
// src/API/Rpc/Offer.ts
|
|
1926
|
+
var RpcOffer = class {
|
|
1927
|
+
constructor(api, id, data, senderAssets, receiverAssets, cache = true) {
|
|
1928
|
+
this.api = api;
|
|
1929
|
+
this.id = id;
|
|
1930
|
+
this._data = new Promise(async (resolve, reject) => {
|
|
1931
|
+
if (data) {
|
|
1932
|
+
resolve(data);
|
|
1933
|
+
} else {
|
|
1934
|
+
try {
|
|
1935
|
+
resolve(await this.api.queue.fetchOffer(id, cache));
|
|
1936
|
+
} catch (e) {
|
|
1937
|
+
reject(e);
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
});
|
|
1941
|
+
this._senderAssets = new Promise(async (resolve, reject) => {
|
|
1942
|
+
if (senderAssets) {
|
|
1943
|
+
resolve(senderAssets);
|
|
1944
|
+
} else {
|
|
1945
|
+
try {
|
|
1946
|
+
const row = await this._data;
|
|
1947
|
+
const inventory = await this.api.queue.fetchAccountAssets(row.sender);
|
|
1948
|
+
return resolve(row.sender_asset_ids.map((assetID) => {
|
|
1949
|
+
const asset = inventory.find((assetRow) => assetRow.asset_id === assetID);
|
|
1950
|
+
return asset ? new RpcAsset(this.api, row.sender, assetID, asset, void 0, void 0, void 0, cache) : assetID;
|
|
1951
|
+
}));
|
|
1952
|
+
} catch (e) {
|
|
1953
|
+
return reject(e);
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
});
|
|
1957
|
+
this._recipientAssets = new Promise(async (resolve, reject) => {
|
|
1958
|
+
if (receiverAssets) {
|
|
1959
|
+
resolve(receiverAssets);
|
|
1960
|
+
} else {
|
|
1961
|
+
try {
|
|
1962
|
+
const row = await this._data;
|
|
1963
|
+
const inventory = await this.api.queue.fetchAccountAssets(row.recipient);
|
|
1964
|
+
return resolve(row.recipient_asset_ids.map((assetID) => {
|
|
1965
|
+
const asset = inventory.find((assetRow) => assetRow.asset_id === assetID);
|
|
1966
|
+
return asset ? new RpcAsset(this.api, row.recipient, assetID, asset, void 0, void 0, void 0, cache) : assetID;
|
|
1967
|
+
}));
|
|
1968
|
+
} catch (e) {
|
|
1969
|
+
return reject(e);
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
});
|
|
1973
|
+
}
|
|
1974
|
+
async sender() {
|
|
1975
|
+
return (await this._data).sender;
|
|
1976
|
+
}
|
|
1977
|
+
async recipient() {
|
|
1978
|
+
return (await this._data).recipient;
|
|
1979
|
+
}
|
|
1980
|
+
async senderAssets() {
|
|
1981
|
+
return await this._senderAssets;
|
|
1982
|
+
}
|
|
1983
|
+
async recipientAssets() {
|
|
1984
|
+
return await this._recipientAssets;
|
|
1985
|
+
}
|
|
1986
|
+
async memo() {
|
|
1987
|
+
return (await this._data).memo;
|
|
1988
|
+
}
|
|
1989
|
+
async toObject() {
|
|
1990
|
+
return {
|
|
1991
|
+
offer_id: this.id,
|
|
1992
|
+
sender: {
|
|
1993
|
+
account: await this.sender(),
|
|
1994
|
+
assets: await Promise.all((await this.senderAssets()).map(async (asset) => typeof asset === "string" ? asset : await asset.toObject()))
|
|
1995
|
+
},
|
|
1996
|
+
recipient: {
|
|
1997
|
+
account: await this.recipient(),
|
|
1998
|
+
assets: await Promise.all((await this.recipientAssets()).map(async (asset) => typeof asset === "string" ? asset : await asset.toObject()))
|
|
1999
|
+
},
|
|
2000
|
+
memo: await this.memo()
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
};
|
|
2004
|
+
|
|
2005
|
+
// src/API/Rpc/Queue.ts
|
|
2006
|
+
var RpcQueue = class {
|
|
2007
|
+
constructor(api, requestLimit = 4) {
|
|
2008
|
+
this.api = api;
|
|
2009
|
+
this.requestLimit = requestLimit;
|
|
2010
|
+
this.elements = [];
|
|
2011
|
+
this.interval = null;
|
|
2012
|
+
this.preloadedCollections = {};
|
|
2013
|
+
}
|
|
2014
|
+
async fetchAsset(owner, assetID, useCache = true) {
|
|
2015
|
+
return await this.fetch_single_row("assets", owner, assetID, (data) => {
|
|
2016
|
+
return useCache || typeof data !== "undefined" ? this.api.cache.getAsset(assetID, data) : null;
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
2019
|
+
async fetchAccountAssets(account) {
|
|
2020
|
+
const rows = await this.fetch_all_rows("assets", account, "asset_id");
|
|
2021
|
+
return rows.map((asset) => {
|
|
2022
|
+
return this.api.cache.getAsset(asset.asset_id, asset);
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
async fetchTemplate(collectionName, templateID, useCache = true) {
|
|
2026
|
+
const cached = useCache ? this.api.cache.getTemplate(collectionName, templateID) : null;
|
|
2027
|
+
if (cached) {
|
|
2028
|
+
return cached;
|
|
2029
|
+
}
|
|
2030
|
+
const [row, mutableRow] = await Promise.all([
|
|
2031
|
+
this.fetch_optional_row("templates", collectionName, templateID),
|
|
2032
|
+
this.fetch_optional_row("templates2", collectionName, templateID)
|
|
2033
|
+
]);
|
|
2034
|
+
if (!row) {
|
|
2035
|
+
throw new Error("Row not found for template " + collectionName + ":" + templateID);
|
|
2036
|
+
}
|
|
2037
|
+
row.mutable_serialized_data = mutableRow ? mutableRow.mutable_serialized_data : [];
|
|
2038
|
+
return this.api.cache.getTemplate(collectionName, templateID, row);
|
|
2039
|
+
}
|
|
2040
|
+
async fetchSchemaFormatTypes(collectionName, schemaName) {
|
|
2041
|
+
const row = await this.fetch_optional_row(
|
|
2042
|
+
"schematypes",
|
|
2043
|
+
collectionName,
|
|
2044
|
+
schemaName
|
|
2045
|
+
);
|
|
2046
|
+
return row ? row.format_type : [];
|
|
2047
|
+
}
|
|
2048
|
+
async fetchSchema(collectionName, schemaName, useCache = true) {
|
|
2049
|
+
return await this.fetch_single_row("schemas", collectionName, schemaName, (data) => {
|
|
2050
|
+
return useCache || typeof data !== "undefined" ? this.api.cache.getSchema(collectionName, schemaName, data) : null;
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
async fetchCollection(collectionName, useCache = true) {
|
|
2054
|
+
return await this.fetch_single_row("collections", this.api.contract, collectionName, (data) => {
|
|
2055
|
+
return useCache || typeof data !== "undefined" ? this.api.cache.getCollection(collectionName, data) : null;
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
async fetchCollectionSchemas(collectionName) {
|
|
2059
|
+
const rows = await this.fetch_all_rows("schemas", collectionName, "schema_name");
|
|
2060
|
+
return rows.map((schema) => {
|
|
2061
|
+
return this.api.cache.getSchema(collectionName, schema.schema_name, schema);
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
async fetchCollectionTemplates(collectionName) {
|
|
2065
|
+
const [rows, mutableRows] = await Promise.all([
|
|
2066
|
+
this.fetch_all_rows("templates", collectionName, "template_id"),
|
|
2067
|
+
this.fetch_all_rows("templates2", collectionName, "template_id")
|
|
2068
|
+
]);
|
|
2069
|
+
const mutableData = new Map(mutableRows.map((row) => [String(row.template_id), row.mutable_serialized_data]));
|
|
2070
|
+
return rows.map((template) => {
|
|
2071
|
+
template.mutable_serialized_data = mutableData.get(String(template.template_id)) ?? [];
|
|
2072
|
+
return this.api.cache.getTemplate(collectionName, String(template.template_id), template);
|
|
2073
|
+
});
|
|
2074
|
+
}
|
|
2075
|
+
async preloadCollection(collectionName, useCache = true) {
|
|
2076
|
+
if (!useCache || !this.preloadedCollections[collectionName] || this.preloadedCollections[collectionName] + 15 * 60 * 1e3 < Date.now()) {
|
|
2077
|
+
await this.fetchCollectionSchemas(collectionName);
|
|
2078
|
+
await this.fetchCollectionTemplates(collectionName);
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
async fetchOffer(offerID, useCache = true) {
|
|
2082
|
+
return await this.fetch_single_row("offers", this.api.contract, offerID, (data) => {
|
|
2083
|
+
return useCache || typeof data !== "undefined" ? this.api.cache.getOffer(offerID, data) : null;
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
2086
|
+
async fetchAccountOffers(account) {
|
|
2087
|
+
const rows = await Promise.all([
|
|
2088
|
+
this.fetch_all_rows(
|
|
2089
|
+
"offers",
|
|
2090
|
+
this.api.contract,
|
|
2091
|
+
"offer_sender",
|
|
2092
|
+
account,
|
|
2093
|
+
account,
|
|
2094
|
+
2,
|
|
2095
|
+
"name"
|
|
2096
|
+
),
|
|
2097
|
+
this.fetch_all_rows(
|
|
2098
|
+
"offers",
|
|
2099
|
+
this.api.contract,
|
|
2100
|
+
"offer_recipient",
|
|
2101
|
+
account,
|
|
2102
|
+
account,
|
|
2103
|
+
3,
|
|
2104
|
+
"name"
|
|
2105
|
+
)
|
|
2106
|
+
]);
|
|
2107
|
+
const offers = rows[0].concat(rows[1]);
|
|
2108
|
+
return offers.map((offer) => {
|
|
2109
|
+
return this.api.cache.getOffer(offer.offer_id, offer);
|
|
2110
|
+
});
|
|
2111
|
+
}
|
|
2112
|
+
dequeue() {
|
|
2113
|
+
if (this.interval) {
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
this.interval = setInterval(async () => {
|
|
2117
|
+
if (this.elements.length > 0) {
|
|
2118
|
+
this.elements.shift()();
|
|
2119
|
+
} else {
|
|
2120
|
+
clearInterval(this.interval);
|
|
2121
|
+
this.interval = null;
|
|
2122
|
+
}
|
|
2123
|
+
}, Math.ceil(1e3 / this.requestLimit));
|
|
2124
|
+
}
|
|
2125
|
+
// Like fetch_single_row but resolves null for a missing row instead of
|
|
2126
|
+
// rejecting; used for the v2 side tables (templates2, schematypes) whose
|
|
2127
|
+
// rows only exist once the corresponding v2 action has run.
|
|
2128
|
+
async fetch_optional_row(table, scope, match, indexPosition = 1, keyType = "") {
|
|
2129
|
+
return new Promise((resolve, reject) => {
|
|
2130
|
+
this.elements.push(async () => {
|
|
2131
|
+
try {
|
|
2132
|
+
const resp = await this.api.getTableRows({
|
|
2133
|
+
code: this.api.contract,
|
|
2134
|
+
table,
|
|
2135
|
+
scope,
|
|
2136
|
+
limit: 1,
|
|
2137
|
+
lower_bound: match,
|
|
2138
|
+
upper_bound: match,
|
|
2139
|
+
index_position: indexPosition,
|
|
2140
|
+
key_type: keyType
|
|
2141
|
+
});
|
|
2142
|
+
return resolve(resp.rows.length === 0 ? null : resp.rows[0]);
|
|
2143
|
+
} catch (e) {
|
|
2144
|
+
return reject(e);
|
|
2145
|
+
}
|
|
2146
|
+
});
|
|
2147
|
+
this.dequeue();
|
|
2148
|
+
});
|
|
2149
|
+
}
|
|
2150
|
+
async fetch_single_row(table, scope, match, cacheFn, indexPosition = 1, keyType = "") {
|
|
2151
|
+
return new Promise((resolve, reject) => {
|
|
2152
|
+
let data = cacheFn();
|
|
2153
|
+
if (data !== null) {
|
|
2154
|
+
return resolve(data);
|
|
2155
|
+
}
|
|
2156
|
+
this.elements.push(async () => {
|
|
2157
|
+
data = cacheFn();
|
|
2158
|
+
if (data !== null) {
|
|
2159
|
+
return resolve(data);
|
|
2160
|
+
}
|
|
2161
|
+
try {
|
|
2162
|
+
const options = {
|
|
2163
|
+
code: this.api.contract,
|
|
2164
|
+
table,
|
|
2165
|
+
scope,
|
|
2166
|
+
limit: 1,
|
|
2167
|
+
lower_bound: match,
|
|
2168
|
+
upper_bound: match,
|
|
2169
|
+
index_position: indexPosition,
|
|
2170
|
+
key_type: keyType
|
|
2171
|
+
};
|
|
2172
|
+
const resp = await this.api.getTableRows(options);
|
|
2173
|
+
if (resp.rows.length === 0) {
|
|
2174
|
+
return reject(new Error("Row not found for " + JSON.stringify(options)));
|
|
2175
|
+
}
|
|
2176
|
+
return resolve(cacheFn(resp.rows[0]));
|
|
2177
|
+
} catch (e) {
|
|
2178
|
+
return reject(e);
|
|
2179
|
+
}
|
|
2180
|
+
});
|
|
2181
|
+
this.dequeue();
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2184
|
+
async fetch_all_rows(table, scope, tableKey, lowerBound = "", upperBound = "", indexPosition = 1, keyType = "") {
|
|
2185
|
+
return new Promise(async (resolve, reject) => {
|
|
2186
|
+
this.elements.push(async () => {
|
|
2187
|
+
const resp = await this.api.getTableRows({
|
|
2188
|
+
code: this.api.contract,
|
|
2189
|
+
scope,
|
|
2190
|
+
table,
|
|
2191
|
+
lower_bound: lowerBound,
|
|
2192
|
+
upper_bound: upperBound,
|
|
2193
|
+
limit: 1e3,
|
|
2194
|
+
index_position: indexPosition,
|
|
2195
|
+
key_type: keyType
|
|
2196
|
+
});
|
|
2197
|
+
if (resp.more && indexPosition === 1) {
|
|
2198
|
+
this.elements.unshift(async () => {
|
|
2199
|
+
try {
|
|
2200
|
+
const next = await this.fetch_all_rows(
|
|
2201
|
+
table,
|
|
2202
|
+
scope,
|
|
2203
|
+
tableKey,
|
|
2204
|
+
resp.rows[resp.rows.length - 1][tableKey],
|
|
2205
|
+
upperBound,
|
|
2206
|
+
indexPosition,
|
|
2207
|
+
keyType
|
|
2208
|
+
);
|
|
2209
|
+
if (next.length > 0) {
|
|
2210
|
+
next.shift();
|
|
2211
|
+
}
|
|
2212
|
+
resolve(resp.rows.concat(next));
|
|
2213
|
+
} catch (e) {
|
|
2214
|
+
reject(e);
|
|
2215
|
+
}
|
|
2216
|
+
});
|
|
2217
|
+
this.dequeue();
|
|
2218
|
+
} else {
|
|
2219
|
+
resolve(resp.rows);
|
|
2220
|
+
}
|
|
2221
|
+
});
|
|
2222
|
+
this.dequeue();
|
|
2223
|
+
});
|
|
2224
|
+
}
|
|
2225
|
+
};
|
|
2226
|
+
|
|
2227
|
+
// src/API/Rpc/index.ts
|
|
2228
|
+
var RpcApi = class {
|
|
2229
|
+
constructor(endpoint, contract, args = { rateLimit: 4 }) {
|
|
2230
|
+
this.endpoint = endpoint;
|
|
2231
|
+
this.contract = contract;
|
|
2232
|
+
if (args.fetch) {
|
|
2233
|
+
this.fetchBuiltin = args.fetch;
|
|
2234
|
+
} else {
|
|
2235
|
+
this.fetchBuiltin = globalThis.fetch.bind(globalThis);
|
|
2236
|
+
}
|
|
2237
|
+
this.queue = new RpcQueue(this, args.rateLimit);
|
|
2238
|
+
this.cache = new RpcCache();
|
|
2239
|
+
this.action = new RpcActionGenerator(this);
|
|
2240
|
+
this._config = new Promise((async (resolve, reject) => {
|
|
2241
|
+
try {
|
|
2242
|
+
const resp = await this.getTableRows({
|
|
2243
|
+
code: this.contract,
|
|
2244
|
+
scope: this.contract,
|
|
2245
|
+
table: "config"
|
|
2246
|
+
});
|
|
2247
|
+
if (resp.rows.length !== 1) {
|
|
2248
|
+
return reject("invalid config");
|
|
2249
|
+
}
|
|
2250
|
+
return resolve(resp.rows[0]);
|
|
2251
|
+
} catch (e) {
|
|
2252
|
+
reject(e);
|
|
2253
|
+
}
|
|
2254
|
+
}));
|
|
2255
|
+
}
|
|
2256
|
+
async config() {
|
|
2257
|
+
return await this._config;
|
|
2258
|
+
}
|
|
2259
|
+
async getAsset(owner, id, cache = true) {
|
|
2260
|
+
if (!cache) {
|
|
2261
|
+
this.cache.deleteAsset(id);
|
|
2262
|
+
}
|
|
2263
|
+
const data = await this.queue.fetchAsset(owner, id, cache);
|
|
2264
|
+
return new RpcAsset(this, owner, id, data, void 0, void 0, void 0, cache);
|
|
2265
|
+
}
|
|
2266
|
+
async getTemplate(collectionName, templateID, cache = true) {
|
|
2267
|
+
if (!cache) {
|
|
2268
|
+
this.cache.deleteTemplate(collectionName, templateID);
|
|
2269
|
+
}
|
|
2270
|
+
const data = await this.queue.fetchTemplate(collectionName, templateID, cache);
|
|
2271
|
+
return new RpcTemplate(this, collectionName, templateID, data, void 0, cache);
|
|
2272
|
+
}
|
|
2273
|
+
async getCollection(collectionName, cache = true) {
|
|
2274
|
+
if (!cache) {
|
|
2275
|
+
this.cache.deleteCollection(collectionName);
|
|
2276
|
+
}
|
|
2277
|
+
const data = await this.queue.fetchCollection(collectionName, cache);
|
|
2278
|
+
return new RpcCollection(this, collectionName, data, cache);
|
|
2279
|
+
}
|
|
2280
|
+
async getCollectionTemplates(collectionName) {
|
|
2281
|
+
return (await this.queue.fetchCollectionTemplates(collectionName)).map((templateRow) => {
|
|
2282
|
+
return new RpcTemplate(this, collectionName, String(templateRow.template_id), templateRow, void 0);
|
|
2283
|
+
});
|
|
2284
|
+
}
|
|
2285
|
+
async getCollectionsSchemas(collectionName) {
|
|
2286
|
+
return (await this.queue.fetchCollectionSchemas(collectionName)).map((schemaRow) => {
|
|
2287
|
+
return new RpcSchema(this, collectionName, schemaRow.schema_name, void 0);
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2290
|
+
async getSchema(collectionName, schemaName, cache = true) {
|
|
2291
|
+
if (!cache) {
|
|
2292
|
+
this.cache.deleteSchema(collectionName, schemaName);
|
|
2293
|
+
}
|
|
2294
|
+
const data = await this.queue.fetchSchema(collectionName, schemaName, cache);
|
|
2295
|
+
return new RpcSchema(this, collectionName, schemaName, data, cache);
|
|
2296
|
+
}
|
|
2297
|
+
async getOffer(offerID, cache = true) {
|
|
2298
|
+
if (!cache) {
|
|
2299
|
+
this.cache.deleteOffer(offerID);
|
|
2300
|
+
}
|
|
2301
|
+
const data = await this.queue.fetchOffer(offerID, cache);
|
|
2302
|
+
return new RpcOffer(this, offerID, data, void 0, void 0, cache);
|
|
2303
|
+
}
|
|
2304
|
+
async getAccountOffers(account) {
|
|
2305
|
+
return (await this.queue.fetchAccountOffers(account)).map((offerRow) => {
|
|
2306
|
+
return new RpcOffer(this, offerRow.offer_id, offerRow, void 0, void 0);
|
|
2307
|
+
});
|
|
2308
|
+
}
|
|
2309
|
+
async getAccountAssets(account) {
|
|
2310
|
+
return (await this.queue.fetchAccountAssets(account)).map((assetRow) => {
|
|
2311
|
+
return new RpcAsset(this, account, assetRow.asset_id, assetRow, void 0, void 0, void 0);
|
|
2312
|
+
});
|
|
2313
|
+
}
|
|
2314
|
+
async getCollectionInventory(collectionName, account) {
|
|
2315
|
+
await this.queue.preloadCollection(collectionName, true);
|
|
2316
|
+
return (await this.queue.fetchAccountAssets(account)).filter((assetRow) => assetRow.collection_name === collectionName).map((assetRow) => {
|
|
2317
|
+
return new RpcAsset(this, account, assetRow.asset_id, assetRow, void 0, void 0, void 0);
|
|
2318
|
+
});
|
|
2319
|
+
}
|
|
2320
|
+
async preloadCollection(collectionName, cache = true) {
|
|
2321
|
+
await this.queue.preloadCollection(collectionName, cache);
|
|
2322
|
+
}
|
|
2323
|
+
async getTableRows({
|
|
2324
|
+
code,
|
|
2325
|
+
scope,
|
|
2326
|
+
table,
|
|
2327
|
+
table_key = "",
|
|
2328
|
+
lower_bound = "",
|
|
2329
|
+
upper_bound = "",
|
|
2330
|
+
index_position = 1,
|
|
2331
|
+
key_type = ""
|
|
2332
|
+
}) {
|
|
2333
|
+
return await this.fetchRpc("/v1/chain/get_table_rows", {
|
|
2334
|
+
code,
|
|
2335
|
+
scope,
|
|
2336
|
+
table,
|
|
2337
|
+
table_key,
|
|
2338
|
+
lower_bound,
|
|
2339
|
+
upper_bound,
|
|
2340
|
+
index_position,
|
|
2341
|
+
key_type,
|
|
2342
|
+
limit: 101,
|
|
2343
|
+
reverse: false,
|
|
2344
|
+
show_payer: false,
|
|
2345
|
+
json: true
|
|
2346
|
+
});
|
|
2347
|
+
}
|
|
2348
|
+
async fetchRpc(path, body) {
|
|
2349
|
+
let response;
|
|
2350
|
+
let json;
|
|
2351
|
+
try {
|
|
2352
|
+
const f = this.fetchBuiltin;
|
|
2353
|
+
response = await f(this.endpoint + path, {
|
|
2354
|
+
body: JSON.stringify(body),
|
|
2355
|
+
method: "POST"
|
|
2356
|
+
});
|
|
2357
|
+
json = await response.json();
|
|
2358
|
+
} catch (e) {
|
|
2359
|
+
e.isFetchError = true;
|
|
2360
|
+
throw e;
|
|
2361
|
+
}
|
|
2362
|
+
if (json.processed && json.processed.except || !response.ok) {
|
|
2363
|
+
throw new RpcError(json);
|
|
2364
|
+
}
|
|
2365
|
+
return json;
|
|
2366
|
+
}
|
|
2367
|
+
};
|
|
2368
|
+
|
|
2369
|
+
// src/Serialization/TypeParser/FixedParser.ts
|
|
2370
|
+
var FixedParser = class {
|
|
2371
|
+
constructor(size) {
|
|
2372
|
+
this.size = size;
|
|
2373
|
+
}
|
|
2374
|
+
deserialize(state) {
|
|
2375
|
+
state.position += this.size;
|
|
2376
|
+
const data = state.data.slice(state.position - this.size, state.position);
|
|
2377
|
+
if (data.length !== this.size) {
|
|
2378
|
+
throw new DeserializationError("FixedParser: read past end");
|
|
2379
|
+
}
|
|
2380
|
+
return data;
|
|
2381
|
+
}
|
|
2382
|
+
serialize(data) {
|
|
2383
|
+
if (data.length !== this.size) {
|
|
2384
|
+
throw new SerializationError(`input data does not conform fixed size`);
|
|
2385
|
+
}
|
|
2386
|
+
return data;
|
|
2387
|
+
}
|
|
2388
|
+
};
|
|
2389
|
+
|
|
2390
|
+
// src/Serialization/TypeParser/BooleanParser.ts
|
|
2391
|
+
var BooleanParser = class extends FixedParser {
|
|
2392
|
+
constructor() {
|
|
2393
|
+
super(1);
|
|
2394
|
+
}
|
|
2395
|
+
deserialize(state) {
|
|
2396
|
+
const data = super.deserialize(state);
|
|
2397
|
+
return data[0] === 1 ? 1 : 0;
|
|
2398
|
+
}
|
|
2399
|
+
serialize(data) {
|
|
2400
|
+
return super.serialize(new Uint8Array([data ? 1 : 0]));
|
|
2401
|
+
}
|
|
2402
|
+
};
|
|
2403
|
+
|
|
2404
|
+
// src/Serialization/TypeParser/VariableParser.ts
|
|
2405
|
+
var VariableParser = class {
|
|
2406
|
+
deserialize(state) {
|
|
2407
|
+
const rawLength = varint_decode(state);
|
|
2408
|
+
if (rawLength > BigInt(state.data.length - state.position)) {
|
|
2409
|
+
throw new DeserializationError(`VariableParser: read past end`);
|
|
2410
|
+
}
|
|
2411
|
+
const length = Number(rawLength);
|
|
2412
|
+
state.position += length;
|
|
2413
|
+
const data = state.data.slice(state.position - length, state.position);
|
|
2414
|
+
if (data.length !== length) {
|
|
2415
|
+
throw new DeserializationError(`VariableParser: read past end`);
|
|
2416
|
+
}
|
|
2417
|
+
return data;
|
|
2418
|
+
}
|
|
2419
|
+
serialize(data) {
|
|
2420
|
+
return concat_byte_arrays([varint_encode(data.length), data]);
|
|
2421
|
+
}
|
|
2422
|
+
};
|
|
2423
|
+
|
|
2424
|
+
// src/Serialization/TypeParser/ByteParser.ts
|
|
2425
|
+
var ByteParser = class extends VariableParser {
|
|
2426
|
+
deserialize(state) {
|
|
2427
|
+
return super.deserialize(state);
|
|
2428
|
+
}
|
|
2429
|
+
serialize(data) {
|
|
2430
|
+
return super.serialize(data);
|
|
2431
|
+
}
|
|
2432
|
+
};
|
|
2433
|
+
|
|
2434
|
+
// src/Serialization/TypeParser/FixedIntegerParser.ts
|
|
2435
|
+
var FixedIntegerParser = class extends FixedParser {
|
|
2436
|
+
deserialize(state) {
|
|
2437
|
+
const data = super.deserialize(state).reverse();
|
|
2438
|
+
let n = 0n;
|
|
2439
|
+
for (const byte of data) {
|
|
2440
|
+
n = n << 8n;
|
|
2441
|
+
n = n + BigInt(byte);
|
|
2442
|
+
}
|
|
2443
|
+
if (this.size <= 6) {
|
|
2444
|
+
return Number(n);
|
|
2445
|
+
}
|
|
2446
|
+
return n.toString();
|
|
2447
|
+
}
|
|
2448
|
+
serialize(data) {
|
|
2449
|
+
let n = BigInt(data);
|
|
2450
|
+
const buffer = [];
|
|
2451
|
+
for (let i = 0; i < this.size; i++) {
|
|
2452
|
+
buffer.push(Number(n & 0xFFn));
|
|
2453
|
+
n = n >> 8n;
|
|
2454
|
+
}
|
|
2455
|
+
return super.serialize(new Uint8Array(buffer));
|
|
2456
|
+
}
|
|
2457
|
+
};
|
|
2458
|
+
|
|
2459
|
+
// src/Serialization/TypeParser/FloatingParser.ts
|
|
2460
|
+
var fp = require_float();
|
|
2461
|
+
var FloatingParser = class extends FixedParser {
|
|
2462
|
+
constructor(isDouble) {
|
|
2463
|
+
super(isDouble ? 8 : 4);
|
|
2464
|
+
this.isDouble = isDouble;
|
|
2465
|
+
}
|
|
2466
|
+
deserialize(state) {
|
|
2467
|
+
if (this.isDouble) {
|
|
2468
|
+
return fp.readDoubleLE(super.deserialize(state));
|
|
2469
|
+
}
|
|
2470
|
+
return fp.readFloatLE(super.deserialize(state));
|
|
2471
|
+
}
|
|
2472
|
+
serialize(data) {
|
|
2473
|
+
let bytes = [];
|
|
2474
|
+
if (this.isDouble) {
|
|
2475
|
+
fp.writeDoubleLE(bytes, data);
|
|
2476
|
+
return super.serialize(new Uint8Array(bytes));
|
|
2477
|
+
}
|
|
2478
|
+
fp.writeFloatLE(bytes, data);
|
|
2479
|
+
return super.serialize(new Uint8Array(bytes));
|
|
2480
|
+
}
|
|
2481
|
+
};
|
|
2482
|
+
|
|
2483
|
+
// src/Serialization/TypeParser/IPFSParser.ts
|
|
2484
|
+
var IPFSParser = class extends VariableParser {
|
|
2485
|
+
deserialize(state) {
|
|
2486
|
+
return base58_encode(super.deserialize(state));
|
|
2487
|
+
}
|
|
2488
|
+
serialize(data) {
|
|
2489
|
+
return super.serialize(base58_decode(data));
|
|
2490
|
+
}
|
|
2491
|
+
};
|
|
2492
|
+
|
|
2493
|
+
// src/Serialization/TypeParser/StringParser.ts
|
|
2494
|
+
var StringParser = class extends VariableParser {
|
|
2495
|
+
deserialize(state) {
|
|
2496
|
+
return new TextDecoder().decode(super.deserialize(state));
|
|
2497
|
+
}
|
|
2498
|
+
serialize(data) {
|
|
2499
|
+
return super.serialize(new TextEncoder().encode(data));
|
|
2500
|
+
}
|
|
2501
|
+
};
|
|
2502
|
+
|
|
2503
|
+
// src/Serialization/TypeParser/VariableIntegerParser.ts
|
|
2504
|
+
var VariableIntegerParser = class {
|
|
2505
|
+
constructor(size, unsigned) {
|
|
2506
|
+
this.size = size;
|
|
2507
|
+
this.unsigned = unsigned;
|
|
2508
|
+
}
|
|
2509
|
+
deserialize(state) {
|
|
2510
|
+
let n = varint_decode(state);
|
|
2511
|
+
if (!this.unsigned) {
|
|
2512
|
+
n = zigzag_decode(n);
|
|
2513
|
+
}
|
|
2514
|
+
if (n >= 2n ** BigInt(this.size * 8 - (this.unsigned ? 0 : 1))) {
|
|
2515
|
+
throw new DeserializationError("number '" + n.toString() + "' too large for given type");
|
|
2516
|
+
}
|
|
2517
|
+
if (!this.unsigned && n < -(2n ** BigInt(this.size * 8 - 1))) {
|
|
2518
|
+
throw new DeserializationError("number '" + n.toString() + "' too small for given type");
|
|
2519
|
+
}
|
|
2520
|
+
if (this.size <= 6) {
|
|
2521
|
+
return Number(n);
|
|
2522
|
+
}
|
|
2523
|
+
return n.toString();
|
|
2524
|
+
}
|
|
2525
|
+
serialize(data) {
|
|
2526
|
+
let n = BigInt(data);
|
|
2527
|
+
if (n >= 2n ** BigInt(this.size * 8 - (this.unsigned ? 0 : 1))) {
|
|
2528
|
+
throw new SerializationError("number '" + n.toString() + "' too large for given type");
|
|
2529
|
+
}
|
|
2530
|
+
if (!this.unsigned && n < -(2n ** BigInt(this.size * 8 - 1))) {
|
|
2531
|
+
throw new SerializationError("number '" + n.toString() + "' too small for given type");
|
|
2532
|
+
}
|
|
2533
|
+
if (!this.unsigned) {
|
|
2534
|
+
n = zigzag_encode(n);
|
|
2535
|
+
}
|
|
2536
|
+
return varint_encode(n);
|
|
2537
|
+
}
|
|
2538
|
+
};
|
|
2539
|
+
|
|
2540
|
+
// src/Serialization/Types.ts
|
|
2541
|
+
var ParserTypes = {
|
|
2542
|
+
int8: new VariableIntegerParser(1, false),
|
|
2543
|
+
int16: new VariableIntegerParser(2, false),
|
|
2544
|
+
int32: new VariableIntegerParser(4, false),
|
|
2545
|
+
int64: new VariableIntegerParser(8, false),
|
|
2546
|
+
uint8: new VariableIntegerParser(1, true),
|
|
2547
|
+
uint16: new VariableIntegerParser(2, true),
|
|
2548
|
+
uint32: new VariableIntegerParser(4, true),
|
|
2549
|
+
uint64: new VariableIntegerParser(8, true),
|
|
2550
|
+
fixed8: new FixedIntegerParser(1),
|
|
2551
|
+
fixed16: new FixedIntegerParser(2),
|
|
2552
|
+
fixed32: new FixedIntegerParser(4),
|
|
2553
|
+
fixed64: new FixedIntegerParser(8),
|
|
2554
|
+
bool: new BooleanParser(),
|
|
2555
|
+
bytes: new ByteParser(),
|
|
2556
|
+
string: new StringParser(),
|
|
2557
|
+
image: new StringParser(),
|
|
2558
|
+
ipfs: new IPFSParser(),
|
|
2559
|
+
float: new FloatingParser(false),
|
|
2560
|
+
double: new FloatingParser(true)
|
|
2561
|
+
};
|
|
2562
|
+
|
|
2563
|
+
// src/Networks.ts
|
|
2564
|
+
var NETWORK_ENDPOINTS = {
|
|
2565
|
+
"wax": {
|
|
2566
|
+
api: "https://wax.api.atomicassets.io",
|
|
2567
|
+
rpc: "https://wax.api.atomicassets.io"
|
|
2568
|
+
},
|
|
2569
|
+
"wax-testnet": {
|
|
2570
|
+
api: "https://test.wax.api.atomicassets.io",
|
|
2571
|
+
rpc: "https://test.wax.api.atomicassets.io"
|
|
2572
|
+
},
|
|
2573
|
+
"vaulta": {
|
|
2574
|
+
api: "https://vaulta.api.atomicassets.io",
|
|
2575
|
+
rpc: "https://vaulta.api.atomicassets.io"
|
|
2576
|
+
},
|
|
2577
|
+
"xpr": {
|
|
2578
|
+
api: "https://xpr.api.atomicassets.io",
|
|
2579
|
+
rpc: "https://xpr.api.atomicassets.io"
|
|
2580
|
+
},
|
|
2581
|
+
"xpr-testnet": {
|
|
2582
|
+
api: "https://test.xpr.api.atomicassets.io",
|
|
2583
|
+
rpc: "https://test.xpr.api.atomicassets.io"
|
|
2584
|
+
},
|
|
2585
|
+
"jungle4": {
|
|
2586
|
+
api: "https://jungle4.api.atomicassets.io",
|
|
2587
|
+
rpc: "https://jungle4.api.atomicassets.io"
|
|
2588
|
+
}
|
|
2589
|
+
};
|
|
2590
|
+
function explorerApiForNetwork(network, options) {
|
|
2591
|
+
return new ExplorerApi(NETWORK_ENDPOINTS[network].api, "atomicassets", options ?? {});
|
|
2592
|
+
}
|
|
2593
|
+
function rpcApiForNetwork(network, contract = "atomicassets", options) {
|
|
2594
|
+
return new RpcApi(NETWORK_ENDPOINTS[network].rpc, contract, options);
|
|
2595
|
+
}
|
|
2596
|
+
|
|
2597
|
+
// src/Errors/ExplorerError.ts
|
|
2598
|
+
var RpcError2 = class extends Error {
|
|
2599
|
+
};
|
|
2600
|
+
|
|
2601
|
+
// src/API/Explorer/Enums.ts
|
|
2602
|
+
var OfferState = /* @__PURE__ */ ((OfferState2) => {
|
|
2603
|
+
OfferState2[OfferState2["Pending"] = 0] = "Pending";
|
|
2604
|
+
OfferState2[OfferState2["Invalid"] = 1] = "Invalid";
|
|
2605
|
+
OfferState2[OfferState2["Unknown"] = 2] = "Unknown";
|
|
2606
|
+
OfferState2[OfferState2["Accepted"] = 3] = "Accepted";
|
|
2607
|
+
OfferState2[OfferState2["Declined"] = 4] = "Declined";
|
|
2608
|
+
OfferState2[OfferState2["Canceled"] = 5] = "Canceled";
|
|
2609
|
+
return OfferState2;
|
|
2610
|
+
})(OfferState || {});
|
|
2611
|
+
var OrderParam = /* @__PURE__ */ ((OrderParam2) => {
|
|
2612
|
+
OrderParam2["Asc"] = "asc";
|
|
2613
|
+
OrderParam2["Desc"] = "desc";
|
|
2614
|
+
return OrderParam2;
|
|
2615
|
+
})(OrderParam || {});
|
|
2616
|
+
var AssetsSort = /* @__PURE__ */ ((AssetsSort2) => {
|
|
2617
|
+
AssetsSort2["AssetId"] = "asset_id";
|
|
2618
|
+
AssetsSort2["Updated"] = "updated";
|
|
2619
|
+
AssetsSort2["Transferred"] = "transferred";
|
|
2620
|
+
AssetsSort2["Minted"] = "minted";
|
|
2621
|
+
AssetsSort2["TemplateMint"] = "template_mint";
|
|
2622
|
+
AssetsSort2["Name"] = "name";
|
|
2623
|
+
return AssetsSort2;
|
|
2624
|
+
})(AssetsSort || {});
|
|
2625
|
+
var CollectionsSort = /* @__PURE__ */ ((CollectionsSort2) => {
|
|
2626
|
+
CollectionsSort2["Created"] = "created";
|
|
2627
|
+
CollectionsSort2["CollectionName"] = "collection_name";
|
|
2628
|
+
return CollectionsSort2;
|
|
2629
|
+
})(CollectionsSort || {});
|
|
2630
|
+
var OffersSort = /* @__PURE__ */ ((OffersSort2) => {
|
|
2631
|
+
OffersSort2["Created"] = "created";
|
|
2632
|
+
OffersSort2["Updated"] = "updated";
|
|
2633
|
+
return OffersSort2;
|
|
2634
|
+
})(OffersSort || {});
|
|
2635
|
+
var SchemasSort = /* @__PURE__ */ ((SchemasSort2) => {
|
|
2636
|
+
SchemasSort2["Created"] = "created";
|
|
2637
|
+
SchemasSort2["SchemaName"] = "schema_name";
|
|
2638
|
+
return SchemasSort2;
|
|
2639
|
+
})(SchemasSort || {});
|
|
2640
|
+
var TemplatesSort = /* @__PURE__ */ ((TemplatesSort2) => {
|
|
2641
|
+
TemplatesSort2["Created"] = "created";
|
|
2642
|
+
TemplatesSort2["Name"] = "name";
|
|
2643
|
+
return TemplatesSort2;
|
|
2644
|
+
})(TemplatesSort || {});
|
|
2645
|
+
var TransfersSort = /* @__PURE__ */ ((TransfersSort2) => {
|
|
2646
|
+
TransfersSort2["Created"] = "created";
|
|
2647
|
+
return TransfersSort2;
|
|
2648
|
+
})(TransfersSort || {});
|
|
2649
|
+
|
|
2650
|
+
// src/Contracts/ActionNames.ts
|
|
2651
|
+
var AtomicAssetsActionNames = [
|
|
2652
|
+
"acceptauswap",
|
|
2653
|
+
"acceptoffer",
|
|
2654
|
+
"addcolauth",
|
|
2655
|
+
"addconftoken",
|
|
2656
|
+
"addnotifyacc",
|
|
2657
|
+
"admincoledit",
|
|
2658
|
+
"announcedepo",
|
|
2659
|
+
"backasset",
|
|
2660
|
+
"burnasset",
|
|
2661
|
+
"canceloffer",
|
|
2662
|
+
"createauswap",
|
|
2663
|
+
"createcol",
|
|
2664
|
+
"createoffer",
|
|
2665
|
+
"createschema",
|
|
2666
|
+
"createtempl",
|
|
2667
|
+
"createtempl2",
|
|
2668
|
+
"declineoffer",
|
|
2669
|
+
"deltemplate",
|
|
2670
|
+
"extendschema",
|
|
2671
|
+
"forbidnotify",
|
|
2672
|
+
"init",
|
|
2673
|
+
"locktemplate",
|
|
2674
|
+
"logbackasset",
|
|
2675
|
+
"logburnasset",
|
|
2676
|
+
"logmint",
|
|
2677
|
+
"lognewoffer",
|
|
2678
|
+
"lognewtempl",
|
|
2679
|
+
"logrampayer",
|
|
2680
|
+
"logsetdata",
|
|
2681
|
+
"logsetdatatl",
|
|
2682
|
+
"logtransfer",
|
|
2683
|
+
"mintasset",
|
|
2684
|
+
"payofferram",
|
|
2685
|
+
"redtemplmax",
|
|
2686
|
+
"rejectauswap",
|
|
2687
|
+
"remcolauth",
|
|
2688
|
+
"remnotifyacc",
|
|
2689
|
+
"setassetdata",
|
|
2690
|
+
"setcoldata",
|
|
2691
|
+
"setlastpayer",
|
|
2692
|
+
"setmarketfee",
|
|
2693
|
+
"setrampayer",
|
|
2694
|
+
"setschematyp",
|
|
2695
|
+
"settempldata",
|
|
2696
|
+
"setversion",
|
|
2697
|
+
"transfer",
|
|
2698
|
+
"withdraw"
|
|
2699
|
+
];
|
|
2700
|
+
var AtomicAssetsActions = Object.fromEntries(
|
|
2701
|
+
AtomicAssetsActionNames.map((name) => [name, name])
|
|
2702
|
+
);
|
|
2703
|
+
|
|
2704
|
+
// src/Contracts/SchemaFormat.ts
|
|
2705
|
+
function mergeSchemaFormatTypes(format, types) {
|
|
2706
|
+
return format.map((field) => {
|
|
2707
|
+
const type = types.find((x) => x.name === field.name);
|
|
2708
|
+
const checkName = (match) => field.name.toLowerCase().startsWith(match) || field.name.toLowerCase().endsWith(match);
|
|
2709
|
+
let derivedType = null;
|
|
2710
|
+
if (field.name === "name") {
|
|
2711
|
+
derivedType = "name";
|
|
2712
|
+
}
|
|
2713
|
+
if (checkName("image") || checkName("img") || field.type === "image") {
|
|
2714
|
+
derivedType = "image";
|
|
2715
|
+
}
|
|
2716
|
+
if (checkName("video")) {
|
|
2717
|
+
derivedType = "video";
|
|
2718
|
+
}
|
|
2719
|
+
if (checkName("audio")) {
|
|
2720
|
+
derivedType = "audio";
|
|
2721
|
+
}
|
|
2722
|
+
return {
|
|
2723
|
+
...field,
|
|
2724
|
+
mediatype: type?.mediatype || derivedType,
|
|
2725
|
+
info: type?.info || null
|
|
2726
|
+
};
|
|
2727
|
+
});
|
|
2728
|
+
}
|
|
2729
|
+
return __toCommonJS(src_exports);
|
|
2730
|
+
})();
|