@stellar/stellar-sdk 14.0.0 → 14.1.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/CHANGELOG.md +4 -1
- package/dist/stellar-sdk-minimal.js +166 -137
- package/dist/stellar-sdk-minimal.min.js +1 -1
- package/dist/stellar-sdk-no-axios.js +166 -137
- package/dist/stellar-sdk-no-axios.min.js +1 -1
- package/dist/stellar-sdk-no-eventsource.js +166 -137
- package/dist/stellar-sdk-no-eventsource.min.js +1 -1
- package/dist/stellar-sdk.js +166 -137
- package/dist/stellar-sdk.min.js +1 -1
- package/lib/contract/client.js +16 -107
- package/lib/contract/spec.d.ts +20 -1
- package/lib/contract/spec.js +41 -9
- package/lib/contract/utils.d.ts +1 -0
- package/lib/contract/utils.js +94 -6
- package/lib/horizon/horizon_axios_client.js +1 -1
- package/lib/minimal/contract/client.js +16 -107
- package/lib/minimal/contract/spec.d.ts +20 -1
- package/lib/minimal/contract/spec.js +41 -9
- package/lib/minimal/contract/utils.d.ts +1 -0
- package/lib/minimal/contract/utils.js +94 -6
- package/lib/minimal/horizon/horizon_axios_client.js +1 -1
- package/lib/minimal/rpc/axios.js +1 -1
- package/lib/no-axios/contract/client.js +16 -107
- package/lib/no-axios/contract/spec.d.ts +20 -1
- package/lib/no-axios/contract/spec.js +41 -9
- package/lib/no-axios/contract/utils.d.ts +1 -0
- package/lib/no-axios/contract/utils.js +94 -6
- package/lib/no-axios/horizon/horizon_axios_client.js +1 -1
- package/lib/no-axios/rpc/axios.js +1 -1
- package/lib/no-eventsource/contract/client.js +16 -107
- package/lib/no-eventsource/contract/spec.d.ts +20 -1
- package/lib/no-eventsource/contract/spec.js +41 -9
- package/lib/no-eventsource/contract/utils.d.ts +1 -0
- package/lib/no-eventsource/contract/utils.js +94 -6
- package/lib/no-eventsource/horizon/horizon_axios_client.js +1 -1
- package/lib/no-eventsource/rpc/axios.js +1 -1
- package/lib/rpc/axios.js +1 -1
- package/package.json +1 -1
package/lib/contract/client.js
CHANGED
|
@@ -9,7 +9,6 @@ var _stellarBase = require("@stellar/stellar-base");
|
|
|
9
9
|
var _spec = require("./spec");
|
|
10
10
|
var _rpc = require("../rpc");
|
|
11
11
|
var _assembled_transaction = require("./assembled_transaction");
|
|
12
|
-
var _utils = require("./utils");
|
|
13
12
|
var _excluded = ["method"],
|
|
14
13
|
_excluded2 = ["wasmHash", "salt", "format", "fee", "timeoutInSeconds", "simulate"];
|
|
15
14
|
function _regenerator() { var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
@@ -24,117 +23,27 @@ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r),
|
|
|
24
23
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
25
24
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
26
25
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
27
|
-
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
28
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
29
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
30
|
-
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
31
|
-
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
32
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
33
26
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
34
27
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
35
28
|
var CONSTRUCTOR_FUNC = "__constructor";
|
|
36
|
-
function
|
|
37
|
-
return _specFromWasm.apply(this, arguments);
|
|
38
|
-
}
|
|
39
|
-
function _specFromWasm() {
|
|
40
|
-
_specFromWasm = _asyncToGenerator(_regenerator().m(function _callee5(wasm) {
|
|
41
|
-
var xdrSections, wasmModule, customData, bufferSection, specEntryArray, spec, _t;
|
|
42
|
-
return _regenerator().w(function (_context5) {
|
|
43
|
-
while (1) switch (_context5.p = _context5.n) {
|
|
44
|
-
case 0:
|
|
45
|
-
_context5.p = 0;
|
|
46
|
-
_context5.n = 1;
|
|
47
|
-
return WebAssembly.compile(wasm);
|
|
48
|
-
case 1:
|
|
49
|
-
wasmModule = _context5.v;
|
|
50
|
-
xdrSections = WebAssembly.Module.customSections(wasmModule, "contractspecv0");
|
|
51
|
-
_context5.n = 3;
|
|
52
|
-
break;
|
|
53
|
-
case 2:
|
|
54
|
-
_context5.p = 2;
|
|
55
|
-
_t = _context5.v;
|
|
56
|
-
customData = parseWasmCustomSections(wasm);
|
|
57
|
-
xdrSections = customData.get('contractspecv0');
|
|
58
|
-
case 3:
|
|
59
|
-
if (!(!xdrSections || xdrSections.length === 0)) {
|
|
60
|
-
_context5.n = 4;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
throw new Error("Could not obtain contract spec from wasm");
|
|
64
|
-
case 4:
|
|
65
|
-
bufferSection = Buffer.from(xdrSections[0]);
|
|
66
|
-
specEntryArray = (0, _utils.processSpecEntryStream)(bufferSection);
|
|
67
|
-
spec = new _spec.Spec(specEntryArray);
|
|
68
|
-
return _context5.a(2, spec);
|
|
69
|
-
}
|
|
70
|
-
}, _callee5, null, [[0, 2]]);
|
|
71
|
-
}));
|
|
72
|
-
return _specFromWasm.apply(this, arguments);
|
|
73
|
-
}
|
|
74
|
-
function parseWasmCustomSections(buffer) {
|
|
75
|
-
var sections = new Map();
|
|
76
|
-
var arrayBuffer = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
77
|
-
var offset = 0;
|
|
78
|
-
var read = function read(length) {
|
|
79
|
-
if (offset + length > buffer.byteLength) throw new Error('Buffer overflow');
|
|
80
|
-
var bytes = new Uint8Array(arrayBuffer, offset, length);
|
|
81
|
-
offset += length;
|
|
82
|
-
return bytes;
|
|
83
|
-
};
|
|
84
|
-
if (_toConsumableArray(read(4)).join() !== '0,97,115,109') throw new Error('Invalid WASM magic');
|
|
85
|
-
if (_toConsumableArray(read(4)).join() !== '1,0,0,0') throw new Error('Invalid WASM version');
|
|
86
|
-
while (offset < buffer.byteLength) {
|
|
87
|
-
var sectionId = read(1)[0];
|
|
88
|
-
var sectionLength = readVarUint32();
|
|
89
|
-
var start = offset;
|
|
90
|
-
if (sectionId === 0) {
|
|
91
|
-
var nameLen = readVarUint32();
|
|
92
|
-
if (nameLen === 0 || offset + nameLen > start + sectionLength) continue;
|
|
93
|
-
var nameBytes = read(nameLen);
|
|
94
|
-
var payload = read(sectionLength - (offset - start));
|
|
95
|
-
try {
|
|
96
|
-
var name = new TextDecoder('utf-8', {
|
|
97
|
-
fatal: true
|
|
98
|
-
}).decode(nameBytes);
|
|
99
|
-
if (payload.length > 0) {
|
|
100
|
-
sections.set(name, (sections.get(name) || []).concat(payload));
|
|
101
|
-
}
|
|
102
|
-
} catch (_unused) {}
|
|
103
|
-
} else {
|
|
104
|
-
offset += sectionLength;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
function readVarUint32() {
|
|
108
|
-
var value = 0,
|
|
109
|
-
shift = 0;
|
|
110
|
-
while (true) {
|
|
111
|
-
var byte = read(1)[0];
|
|
112
|
-
value |= (byte & 0x7F) << shift;
|
|
113
|
-
if ((byte & 0x80) === 0) break;
|
|
114
|
-
if ((shift += 7) >= 32) throw new Error('Invalid WASM value');
|
|
115
|
-
}
|
|
116
|
-
return value >>> 0;
|
|
117
|
-
}
|
|
118
|
-
return sections;
|
|
119
|
-
}
|
|
120
|
-
function specFromWasmHash(_x2, _x3) {
|
|
29
|
+
function specFromWasmHash(_x, _x2) {
|
|
121
30
|
return _specFromWasmHash.apply(this, arguments);
|
|
122
31
|
}
|
|
123
32
|
function _specFromWasmHash() {
|
|
124
|
-
_specFromWasmHash = _asyncToGenerator(_regenerator().m(function
|
|
33
|
+
_specFromWasmHash = _asyncToGenerator(_regenerator().m(function _callee5(wasmHash, options) {
|
|
125
34
|
var format,
|
|
126
35
|
rpcUrl,
|
|
127
36
|
allowHttp,
|
|
128
37
|
serverOpts,
|
|
129
38
|
server,
|
|
130
39
|
wasm,
|
|
131
|
-
|
|
132
|
-
return _regenerator().w(function (
|
|
133
|
-
while (1) switch (
|
|
40
|
+
_args5 = arguments;
|
|
41
|
+
return _regenerator().w(function (_context5) {
|
|
42
|
+
while (1) switch (_context5.n) {
|
|
134
43
|
case 0:
|
|
135
|
-
format =
|
|
44
|
+
format = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : "hex";
|
|
136
45
|
if (!(!options || !options.rpcUrl)) {
|
|
137
|
-
|
|
46
|
+
_context5.n = 1;
|
|
138
47
|
break;
|
|
139
48
|
}
|
|
140
49
|
throw new TypeError("options must contain rpcUrl");
|
|
@@ -144,13 +53,13 @@ function _specFromWasmHash() {
|
|
|
144
53
|
allowHttp: allowHttp
|
|
145
54
|
};
|
|
146
55
|
server = new _rpc.Server(rpcUrl, serverOpts);
|
|
147
|
-
|
|
56
|
+
_context5.n = 2;
|
|
148
57
|
return server.getContractWasmByHash(wasmHash, format);
|
|
149
58
|
case 2:
|
|
150
|
-
wasm =
|
|
151
|
-
return
|
|
59
|
+
wasm = _context5.v;
|
|
60
|
+
return _context5.a(2, _spec.Spec.fromWasm(wasm));
|
|
152
61
|
}
|
|
153
|
-
},
|
|
62
|
+
}, _callee5);
|
|
154
63
|
}));
|
|
155
64
|
return _specFromWasmHash.apply(this, arguments);
|
|
156
65
|
}
|
|
@@ -234,7 +143,7 @@ var Client = exports.Client = function () {
|
|
|
234
143
|
}
|
|
235
144
|
}, _callee);
|
|
236
145
|
}));
|
|
237
|
-
function deploy(
|
|
146
|
+
function deploy(_x3, _x4) {
|
|
238
147
|
return _deploy.apply(this, arguments);
|
|
239
148
|
}
|
|
240
149
|
return deploy;
|
|
@@ -273,7 +182,7 @@ var Client = exports.Client = function () {
|
|
|
273
182
|
}
|
|
274
183
|
}, _callee2);
|
|
275
184
|
}));
|
|
276
|
-
function fromWasmHash(
|
|
185
|
+
function fromWasmHash(_x5, _x6) {
|
|
277
186
|
return _fromWasmHash.apply(this, arguments);
|
|
278
187
|
}
|
|
279
188
|
return fromWasmHash;
|
|
@@ -287,14 +196,14 @@ var Client = exports.Client = function () {
|
|
|
287
196
|
while (1) switch (_context3.n) {
|
|
288
197
|
case 0:
|
|
289
198
|
_context3.n = 1;
|
|
290
|
-
return
|
|
199
|
+
return _spec.Spec.fromWasm(wasm);
|
|
291
200
|
case 1:
|
|
292
201
|
spec = _context3.v;
|
|
293
202
|
return _context3.a(2, new Client(spec, options));
|
|
294
203
|
}
|
|
295
204
|
}, _callee3);
|
|
296
205
|
}));
|
|
297
|
-
function fromWasm(
|
|
206
|
+
function fromWasm(_x7, _x8) {
|
|
298
207
|
return _fromWasm.apply(this, arguments);
|
|
299
208
|
}
|
|
300
209
|
return fromWasm;
|
|
@@ -326,7 +235,7 @@ var Client = exports.Client = function () {
|
|
|
326
235
|
}
|
|
327
236
|
}, _callee4);
|
|
328
237
|
}));
|
|
329
|
-
function from(
|
|
238
|
+
function from(_x9) {
|
|
330
239
|
return _from.apply(this, arguments);
|
|
331
240
|
}
|
|
332
241
|
return from;
|
package/lib/contract/spec.d.ts
CHANGED
|
@@ -38,7 +38,26 @@ export declare class Spec {
|
|
|
38
38
|
* The XDR spec entries.
|
|
39
39
|
*/
|
|
40
40
|
entries: xdr.ScSpecEntry[];
|
|
41
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Generates a Spec instance from the contract's wasm binary.
|
|
43
|
+
*
|
|
44
|
+
* @param {Buffer} wasm The contract's wasm binary as a Buffer.
|
|
45
|
+
* @returns {Promise<module:contract.Spec>} A Promise that resolves to a Spec instance.
|
|
46
|
+
* @throws {Error} If the contract spec cannot be obtained from the provided wasm binary.
|
|
47
|
+
*/
|
|
48
|
+
static fromWasm(wasm: Buffer): Promise<Spec>;
|
|
49
|
+
/**
|
|
50
|
+
* Generates a Spec instance from contract specs in any of the following forms:
|
|
51
|
+
* - An XDR encoded stream of xdr.ScSpecEntry entries, the format of the spec
|
|
52
|
+
* stored inside Wasm files.
|
|
53
|
+
* - A base64 XDR encoded stream of xdr.ScSpecEntry entries.
|
|
54
|
+
* - An array of xdr.ScSpecEntry.
|
|
55
|
+
* - An array of base64 XDR encoded xdr.ScSpecEntry.
|
|
56
|
+
*
|
|
57
|
+
* @returns {Promise<module:contract.Client>} A Promise that resolves to a Client instance.
|
|
58
|
+
* @throws {Error} If the contract spec cannot be obtained from the provided wasm binary.
|
|
59
|
+
*/
|
|
60
|
+
constructor(entries: Buffer | string | xdr.ScSpecEntry[] | string[]);
|
|
42
61
|
/**
|
|
43
62
|
* Gets the XDR functions from the spec.
|
|
44
63
|
* @returns {xdr.ScSpecFunctionV0[]} all contract functions
|
package/lib/contract/spec.js
CHANGED
|
@@ -6,6 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.Spec = void 0;
|
|
7
7
|
var _stellarBase = require("@stellar/stellar-base");
|
|
8
8
|
var _rust_result = require("./rust_result");
|
|
9
|
+
var _utils = require("./utils");
|
|
10
|
+
function _regenerator() { var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
11
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
12
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
13
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
9
14
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
15
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
16
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
@@ -464,16 +469,22 @@ var Spec = exports.Spec = function () {
|
|
|
464
469
|
function Spec(entries) {
|
|
465
470
|
_classCallCheck(this, Spec);
|
|
466
471
|
_defineProperty(this, "entries", []);
|
|
467
|
-
if (entries
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
if (typeof entry === "string") {
|
|
472
|
-
this.entries = entries.map(function (s) {
|
|
473
|
-
return _stellarBase.xdr.ScSpecEntry.fromXDR(s, "base64");
|
|
474
|
-
});
|
|
472
|
+
if (Buffer.isBuffer(entries)) {
|
|
473
|
+
this.entries = (0, _utils.processSpecEntryStream)(entries);
|
|
474
|
+
} else if (typeof entries === "string") {
|
|
475
|
+
this.entries = (0, _utils.processSpecEntryStream)(Buffer.from(entries, "base64"));
|
|
475
476
|
} else {
|
|
476
|
-
|
|
477
|
+
if (entries.length === 0) {
|
|
478
|
+
throw new Error("Contract spec must have at least one entry");
|
|
479
|
+
}
|
|
480
|
+
var entry = entries[0];
|
|
481
|
+
if (typeof entry === "string") {
|
|
482
|
+
this.entries = entries.map(function (s) {
|
|
483
|
+
return _stellarBase.xdr.ScSpecEntry.fromXDR(s, "base64");
|
|
484
|
+
});
|
|
485
|
+
} else {
|
|
486
|
+
this.entries = entries;
|
|
487
|
+
}
|
|
477
488
|
}
|
|
478
489
|
}
|
|
479
490
|
return _createClass(Spec, [{
|
|
@@ -1013,5 +1024,26 @@ var Spec = exports.Spec = function () {
|
|
|
1013
1024
|
}
|
|
1014
1025
|
return res;
|
|
1015
1026
|
}
|
|
1027
|
+
}], [{
|
|
1028
|
+
key: "fromWasm",
|
|
1029
|
+
value: (function () {
|
|
1030
|
+
var _fromWasm = _asyncToGenerator(_regenerator().m(function _callee(wasm) {
|
|
1031
|
+
var spec;
|
|
1032
|
+
return _regenerator().w(function (_context) {
|
|
1033
|
+
while (1) switch (_context.n) {
|
|
1034
|
+
case 0:
|
|
1035
|
+
_context.n = 1;
|
|
1036
|
+
return (0, _utils.specFromWasm)(wasm);
|
|
1037
|
+
case 1:
|
|
1038
|
+
spec = _context.v;
|
|
1039
|
+
return _context.a(2, new Spec(spec));
|
|
1040
|
+
}
|
|
1041
|
+
}, _callee);
|
|
1042
|
+
}));
|
|
1043
|
+
function fromWasm(_x) {
|
|
1044
|
+
return _fromWasm.apply(this, arguments);
|
|
1045
|
+
}
|
|
1046
|
+
return fromWasm;
|
|
1047
|
+
}())
|
|
1016
1048
|
}]);
|
|
1017
1049
|
}();
|
package/lib/contract/utils.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export declare function implementsToString(
|
|
|
38
38
|
obj: unknown): obj is {
|
|
39
39
|
toString(): string;
|
|
40
40
|
};
|
|
41
|
+
export declare function specFromWasm(wasm: Buffer): Promise<Buffer>;
|
|
41
42
|
/**
|
|
42
43
|
* Reads a binary stream of ScSpecEntries into an array for processing by ContractSpec
|
|
43
44
|
* @private
|
package/lib/contract/utils.js
CHANGED
|
@@ -7,11 +7,18 @@ exports.contractErrorPattern = void 0;
|
|
|
7
7
|
exports.getAccount = getAccount;
|
|
8
8
|
exports.implementsToString = implementsToString;
|
|
9
9
|
exports.processSpecEntryStream = processSpecEntryStream;
|
|
10
|
+
exports.specFromWasm = specFromWasm;
|
|
10
11
|
exports.withExponentialBackoff = withExponentialBackoff;
|
|
11
12
|
var _stellarBase = require("@stellar/stellar-base");
|
|
12
13
|
var _types = require("./types");
|
|
13
14
|
function _regenerator() { var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
14
15
|
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
16
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
17
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
19
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
20
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
21
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
15
22
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
16
23
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
17
24
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
@@ -94,6 +101,87 @@ var contractErrorPattern = exports.contractErrorPattern = /Error\(Contract, #(\d
|
|
|
94
101
|
function implementsToString(obj) {
|
|
95
102
|
return _typeof(obj) === "object" && obj !== null && "toString" in obj;
|
|
96
103
|
}
|
|
104
|
+
function specFromWasm(_x4) {
|
|
105
|
+
return _specFromWasm.apply(this, arguments);
|
|
106
|
+
}
|
|
107
|
+
function _specFromWasm() {
|
|
108
|
+
_specFromWasm = _asyncToGenerator(_regenerator().m(function _callee2(wasm) {
|
|
109
|
+
var xdrSections, wasmModule, customData, _t3;
|
|
110
|
+
return _regenerator().w(function (_context2) {
|
|
111
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
112
|
+
case 0:
|
|
113
|
+
_context2.p = 0;
|
|
114
|
+
_context2.n = 1;
|
|
115
|
+
return WebAssembly.compile(wasm);
|
|
116
|
+
case 1:
|
|
117
|
+
wasmModule = _context2.v;
|
|
118
|
+
xdrSections = WebAssembly.Module.customSections(wasmModule, "contractspecv0");
|
|
119
|
+
_context2.n = 3;
|
|
120
|
+
break;
|
|
121
|
+
case 2:
|
|
122
|
+
_context2.p = 2;
|
|
123
|
+
_t3 = _context2.v;
|
|
124
|
+
customData = parseWasmCustomSections(wasm);
|
|
125
|
+
xdrSections = customData.get('contractspecv0');
|
|
126
|
+
case 3:
|
|
127
|
+
if (!(!xdrSections || xdrSections.length === 0)) {
|
|
128
|
+
_context2.n = 4;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
throw new Error("Could not obtain contract spec from wasm");
|
|
132
|
+
case 4:
|
|
133
|
+
return _context2.a(2, Buffer.from(xdrSections[0]));
|
|
134
|
+
}
|
|
135
|
+
}, _callee2, null, [[0, 2]]);
|
|
136
|
+
}));
|
|
137
|
+
return _specFromWasm.apply(this, arguments);
|
|
138
|
+
}
|
|
139
|
+
function parseWasmCustomSections(buffer) {
|
|
140
|
+
var sections = new Map();
|
|
141
|
+
var arrayBuffer = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
142
|
+
var offset = 0;
|
|
143
|
+
var read = function read(length) {
|
|
144
|
+
if (offset + length > buffer.byteLength) throw new Error('Buffer overflow');
|
|
145
|
+
var bytes = new Uint8Array(arrayBuffer, offset, length);
|
|
146
|
+
offset += length;
|
|
147
|
+
return bytes;
|
|
148
|
+
};
|
|
149
|
+
if (_toConsumableArray(read(4)).join() !== '0,97,115,109') throw new Error('Invalid WASM magic');
|
|
150
|
+
if (_toConsumableArray(read(4)).join() !== '1,0,0,0') throw new Error('Invalid WASM version');
|
|
151
|
+
while (offset < buffer.byteLength) {
|
|
152
|
+
var sectionId = read(1)[0];
|
|
153
|
+
var sectionLength = readVarUint32();
|
|
154
|
+
var start = offset;
|
|
155
|
+
if (sectionId === 0) {
|
|
156
|
+
var nameLen = readVarUint32();
|
|
157
|
+
if (nameLen === 0 || offset + nameLen > start + sectionLength) continue;
|
|
158
|
+
var nameBytes = read(nameLen);
|
|
159
|
+
var payload = read(sectionLength - (offset - start));
|
|
160
|
+
try {
|
|
161
|
+
var name = new TextDecoder('utf-8', {
|
|
162
|
+
fatal: true
|
|
163
|
+
}).decode(nameBytes);
|
|
164
|
+
if (payload.length > 0) {
|
|
165
|
+
sections.set(name, (sections.get(name) || []).concat(payload));
|
|
166
|
+
}
|
|
167
|
+
} catch (_unused) {}
|
|
168
|
+
} else {
|
|
169
|
+
offset += sectionLength;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function readVarUint32() {
|
|
173
|
+
var value = 0,
|
|
174
|
+
shift = 0;
|
|
175
|
+
while (true) {
|
|
176
|
+
var byte = read(1)[0];
|
|
177
|
+
value |= (byte & 0x7F) << shift;
|
|
178
|
+
if ((byte & 0x80) === 0) break;
|
|
179
|
+
if ((shift += 7) >= 32) throw new Error('Invalid WASM value');
|
|
180
|
+
}
|
|
181
|
+
return value >>> 0;
|
|
182
|
+
}
|
|
183
|
+
return sections;
|
|
184
|
+
}
|
|
97
185
|
function processSpecEntryStream(buffer) {
|
|
98
186
|
var reader = new _stellarBase.cereal.XdrReader(buffer);
|
|
99
187
|
var res = [];
|
|
@@ -102,17 +190,17 @@ function processSpecEntryStream(buffer) {
|
|
|
102
190
|
}
|
|
103
191
|
return res;
|
|
104
192
|
}
|
|
105
|
-
function getAccount(
|
|
193
|
+
function getAccount(_x5, _x6) {
|
|
106
194
|
return _getAccount.apply(this, arguments);
|
|
107
195
|
}
|
|
108
196
|
function _getAccount() {
|
|
109
|
-
_getAccount = _asyncToGenerator(_regenerator().m(function
|
|
110
|
-
return _regenerator().w(function (
|
|
111
|
-
while (1) switch (
|
|
197
|
+
_getAccount = _asyncToGenerator(_regenerator().m(function _callee3(options, server) {
|
|
198
|
+
return _regenerator().w(function (_context3) {
|
|
199
|
+
while (1) switch (_context3.n) {
|
|
112
200
|
case 0:
|
|
113
|
-
return
|
|
201
|
+
return _context3.a(2, options.publicKey ? server.getAccount(options.publicKey) : new _stellarBase.Account(_types.NULL_ACCOUNT, "0"));
|
|
114
202
|
}
|
|
115
|
-
},
|
|
203
|
+
}, _callee3);
|
|
116
204
|
}));
|
|
117
205
|
return _getAccount.apply(this, arguments);
|
|
118
206
|
}
|
|
@@ -10,7 +10,7 @@ var _urijs = _interopRequireDefault(require("urijs"));
|
|
|
10
10
|
var _httpClient = require("../http-client");
|
|
11
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
13
|
-
var version = exports.version = "14.
|
|
13
|
+
var version = exports.version = "14.1.0";
|
|
14
14
|
var SERVER_TIME_MAP = exports.SERVER_TIME_MAP = {};
|
|
15
15
|
var AxiosClient = exports.AxiosClient = (0, _httpClient.create)({
|
|
16
16
|
headers: {
|
|
@@ -9,7 +9,6 @@ var _stellarBase = require("@stellar/stellar-base");
|
|
|
9
9
|
var _spec = require("./spec");
|
|
10
10
|
var _rpc = require("../rpc");
|
|
11
11
|
var _assembled_transaction = require("./assembled_transaction");
|
|
12
|
-
var _utils = require("./utils");
|
|
13
12
|
var _excluded = ["method"],
|
|
14
13
|
_excluded2 = ["wasmHash", "salt", "format", "fee", "timeoutInSeconds", "simulate"];
|
|
15
14
|
function _regenerator() { var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
@@ -24,117 +23,27 @@ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r),
|
|
|
24
23
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
25
24
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
26
25
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
27
|
-
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
28
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
29
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
30
|
-
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
31
|
-
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
32
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
33
26
|
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
34
27
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
35
28
|
var CONSTRUCTOR_FUNC = "__constructor";
|
|
36
|
-
function
|
|
37
|
-
return _specFromWasm.apply(this, arguments);
|
|
38
|
-
}
|
|
39
|
-
function _specFromWasm() {
|
|
40
|
-
_specFromWasm = _asyncToGenerator(_regenerator().m(function _callee5(wasm) {
|
|
41
|
-
var xdrSections, wasmModule, customData, bufferSection, specEntryArray, spec, _t;
|
|
42
|
-
return _regenerator().w(function (_context5) {
|
|
43
|
-
while (1) switch (_context5.p = _context5.n) {
|
|
44
|
-
case 0:
|
|
45
|
-
_context5.p = 0;
|
|
46
|
-
_context5.n = 1;
|
|
47
|
-
return WebAssembly.compile(wasm);
|
|
48
|
-
case 1:
|
|
49
|
-
wasmModule = _context5.v;
|
|
50
|
-
xdrSections = WebAssembly.Module.customSections(wasmModule, "contractspecv0");
|
|
51
|
-
_context5.n = 3;
|
|
52
|
-
break;
|
|
53
|
-
case 2:
|
|
54
|
-
_context5.p = 2;
|
|
55
|
-
_t = _context5.v;
|
|
56
|
-
customData = parseWasmCustomSections(wasm);
|
|
57
|
-
xdrSections = customData.get('contractspecv0');
|
|
58
|
-
case 3:
|
|
59
|
-
if (!(!xdrSections || xdrSections.length === 0)) {
|
|
60
|
-
_context5.n = 4;
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
throw new Error("Could not obtain contract spec from wasm");
|
|
64
|
-
case 4:
|
|
65
|
-
bufferSection = Buffer.from(xdrSections[0]);
|
|
66
|
-
specEntryArray = (0, _utils.processSpecEntryStream)(bufferSection);
|
|
67
|
-
spec = new _spec.Spec(specEntryArray);
|
|
68
|
-
return _context5.a(2, spec);
|
|
69
|
-
}
|
|
70
|
-
}, _callee5, null, [[0, 2]]);
|
|
71
|
-
}));
|
|
72
|
-
return _specFromWasm.apply(this, arguments);
|
|
73
|
-
}
|
|
74
|
-
function parseWasmCustomSections(buffer) {
|
|
75
|
-
var sections = new Map();
|
|
76
|
-
var arrayBuffer = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
77
|
-
var offset = 0;
|
|
78
|
-
var read = function read(length) {
|
|
79
|
-
if (offset + length > buffer.byteLength) throw new Error('Buffer overflow');
|
|
80
|
-
var bytes = new Uint8Array(arrayBuffer, offset, length);
|
|
81
|
-
offset += length;
|
|
82
|
-
return bytes;
|
|
83
|
-
};
|
|
84
|
-
if (_toConsumableArray(read(4)).join() !== '0,97,115,109') throw new Error('Invalid WASM magic');
|
|
85
|
-
if (_toConsumableArray(read(4)).join() !== '1,0,0,0') throw new Error('Invalid WASM version');
|
|
86
|
-
while (offset < buffer.byteLength) {
|
|
87
|
-
var sectionId = read(1)[0];
|
|
88
|
-
var sectionLength = readVarUint32();
|
|
89
|
-
var start = offset;
|
|
90
|
-
if (sectionId === 0) {
|
|
91
|
-
var nameLen = readVarUint32();
|
|
92
|
-
if (nameLen === 0 || offset + nameLen > start + sectionLength) continue;
|
|
93
|
-
var nameBytes = read(nameLen);
|
|
94
|
-
var payload = read(sectionLength - (offset - start));
|
|
95
|
-
try {
|
|
96
|
-
var name = new TextDecoder('utf-8', {
|
|
97
|
-
fatal: true
|
|
98
|
-
}).decode(nameBytes);
|
|
99
|
-
if (payload.length > 0) {
|
|
100
|
-
sections.set(name, (sections.get(name) || []).concat(payload));
|
|
101
|
-
}
|
|
102
|
-
} catch (_unused) {}
|
|
103
|
-
} else {
|
|
104
|
-
offset += sectionLength;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
function readVarUint32() {
|
|
108
|
-
var value = 0,
|
|
109
|
-
shift = 0;
|
|
110
|
-
while (true) {
|
|
111
|
-
var byte = read(1)[0];
|
|
112
|
-
value |= (byte & 0x7F) << shift;
|
|
113
|
-
if ((byte & 0x80) === 0) break;
|
|
114
|
-
if ((shift += 7) >= 32) throw new Error('Invalid WASM value');
|
|
115
|
-
}
|
|
116
|
-
return value >>> 0;
|
|
117
|
-
}
|
|
118
|
-
return sections;
|
|
119
|
-
}
|
|
120
|
-
function specFromWasmHash(_x2, _x3) {
|
|
29
|
+
function specFromWasmHash(_x, _x2) {
|
|
121
30
|
return _specFromWasmHash.apply(this, arguments);
|
|
122
31
|
}
|
|
123
32
|
function _specFromWasmHash() {
|
|
124
|
-
_specFromWasmHash = _asyncToGenerator(_regenerator().m(function
|
|
33
|
+
_specFromWasmHash = _asyncToGenerator(_regenerator().m(function _callee5(wasmHash, options) {
|
|
125
34
|
var format,
|
|
126
35
|
rpcUrl,
|
|
127
36
|
allowHttp,
|
|
128
37
|
serverOpts,
|
|
129
38
|
server,
|
|
130
39
|
wasm,
|
|
131
|
-
|
|
132
|
-
return _regenerator().w(function (
|
|
133
|
-
while (1) switch (
|
|
40
|
+
_args5 = arguments;
|
|
41
|
+
return _regenerator().w(function (_context5) {
|
|
42
|
+
while (1) switch (_context5.n) {
|
|
134
43
|
case 0:
|
|
135
|
-
format =
|
|
44
|
+
format = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : "hex";
|
|
136
45
|
if (!(!options || !options.rpcUrl)) {
|
|
137
|
-
|
|
46
|
+
_context5.n = 1;
|
|
138
47
|
break;
|
|
139
48
|
}
|
|
140
49
|
throw new TypeError("options must contain rpcUrl");
|
|
@@ -144,13 +53,13 @@ function _specFromWasmHash() {
|
|
|
144
53
|
allowHttp: allowHttp
|
|
145
54
|
};
|
|
146
55
|
server = new _rpc.Server(rpcUrl, serverOpts);
|
|
147
|
-
|
|
56
|
+
_context5.n = 2;
|
|
148
57
|
return server.getContractWasmByHash(wasmHash, format);
|
|
149
58
|
case 2:
|
|
150
|
-
wasm =
|
|
151
|
-
return
|
|
59
|
+
wasm = _context5.v;
|
|
60
|
+
return _context5.a(2, _spec.Spec.fromWasm(wasm));
|
|
152
61
|
}
|
|
153
|
-
},
|
|
62
|
+
}, _callee5);
|
|
154
63
|
}));
|
|
155
64
|
return _specFromWasmHash.apply(this, arguments);
|
|
156
65
|
}
|
|
@@ -234,7 +143,7 @@ var Client = exports.Client = function () {
|
|
|
234
143
|
}
|
|
235
144
|
}, _callee);
|
|
236
145
|
}));
|
|
237
|
-
function deploy(
|
|
146
|
+
function deploy(_x3, _x4) {
|
|
238
147
|
return _deploy.apply(this, arguments);
|
|
239
148
|
}
|
|
240
149
|
return deploy;
|
|
@@ -273,7 +182,7 @@ var Client = exports.Client = function () {
|
|
|
273
182
|
}
|
|
274
183
|
}, _callee2);
|
|
275
184
|
}));
|
|
276
|
-
function fromWasmHash(
|
|
185
|
+
function fromWasmHash(_x5, _x6) {
|
|
277
186
|
return _fromWasmHash.apply(this, arguments);
|
|
278
187
|
}
|
|
279
188
|
return fromWasmHash;
|
|
@@ -287,14 +196,14 @@ var Client = exports.Client = function () {
|
|
|
287
196
|
while (1) switch (_context3.n) {
|
|
288
197
|
case 0:
|
|
289
198
|
_context3.n = 1;
|
|
290
|
-
return
|
|
199
|
+
return _spec.Spec.fromWasm(wasm);
|
|
291
200
|
case 1:
|
|
292
201
|
spec = _context3.v;
|
|
293
202
|
return _context3.a(2, new Client(spec, options));
|
|
294
203
|
}
|
|
295
204
|
}, _callee3);
|
|
296
205
|
}));
|
|
297
|
-
function fromWasm(
|
|
206
|
+
function fromWasm(_x7, _x8) {
|
|
298
207
|
return _fromWasm.apply(this, arguments);
|
|
299
208
|
}
|
|
300
209
|
return fromWasm;
|
|
@@ -326,7 +235,7 @@ var Client = exports.Client = function () {
|
|
|
326
235
|
}
|
|
327
236
|
}, _callee4);
|
|
328
237
|
}));
|
|
329
|
-
function from(
|
|
238
|
+
function from(_x9) {
|
|
330
239
|
return _from.apply(this, arguments);
|
|
331
240
|
}
|
|
332
241
|
return from;
|