@stellar/stellar-sdk 14.4.3 → 14.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +150 -0
- package/bin/stellar-js +4 -0
- package/dist/stellar-sdk-minimal.js +11450 -10315
- package/dist/stellar-sdk-minimal.min.js +1 -1
- package/dist/stellar-sdk-no-axios.js +7459 -6324
- package/dist/stellar-sdk-no-axios.min.js +1 -1
- package/dist/stellar-sdk-no-eventsource.js +11597 -10483
- package/dist/stellar-sdk-no-eventsource.min.js +1 -1
- package/dist/stellar-sdk.js +10647 -9533
- package/dist/stellar-sdk.min.js +1 -1
- package/lib/bindings/client.d.ts +30 -0
- package/lib/bindings/client.js +134 -0
- package/lib/bindings/config.d.ts +34 -0
- package/lib/bindings/config.js +83 -0
- package/lib/bindings/generator.d.ts +176 -0
- package/lib/bindings/generator.js +131 -0
- package/lib/bindings/index.d.ts +6 -0
- package/lib/bindings/index.js +75 -0
- package/lib/bindings/sac-spec.d.ts +1 -0
- package/lib/bindings/sac-spec.js +7 -0
- package/lib/bindings/types.d.ts +66 -0
- package/lib/bindings/types.js +184 -0
- package/lib/bindings/utils.d.ts +49 -0
- package/lib/bindings/utils.js +223 -0
- package/lib/bindings/wasm_fetcher.d.ts +25 -0
- package/lib/bindings/wasm_fetcher.js +225 -0
- package/lib/cli/index.d.ts +2 -0
- package/lib/cli/index.js +171 -0
- package/lib/cli/util.d.ts +55 -0
- package/lib/cli/util.js +254 -0
- package/lib/contract/client.js +2 -1
- package/lib/horizon/call_builder.js +30 -6
- package/lib/horizon/horizon_axios_client.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +9 -1
- package/lib/minimal/bindings/client.d.ts +30 -0
- package/lib/minimal/bindings/client.js +134 -0
- package/lib/minimal/bindings/config.d.ts +34 -0
- package/lib/minimal/bindings/config.js +83 -0
- package/lib/minimal/bindings/generator.d.ts +176 -0
- package/lib/minimal/bindings/generator.js +131 -0
- package/lib/minimal/bindings/index.d.ts +6 -0
- package/lib/minimal/bindings/index.js +75 -0
- package/lib/minimal/bindings/sac-spec.d.ts +1 -0
- package/lib/minimal/bindings/sac-spec.js +7 -0
- package/lib/minimal/bindings/types.d.ts +66 -0
- package/lib/minimal/bindings/types.js +184 -0
- package/lib/minimal/bindings/utils.d.ts +49 -0
- package/lib/minimal/bindings/utils.js +223 -0
- package/lib/minimal/bindings/wasm_fetcher.d.ts +25 -0
- package/lib/minimal/bindings/wasm_fetcher.js +225 -0
- package/lib/minimal/cli/index.d.ts +2 -0
- package/lib/minimal/cli/index.js +171 -0
- package/lib/minimal/cli/util.d.ts +55 -0
- package/lib/minimal/cli/util.js +254 -0
- package/lib/minimal/contract/client.js +2 -1
- package/lib/minimal/horizon/call_builder.js +30 -6
- package/lib/minimal/horizon/horizon_axios_client.js +1 -1
- package/lib/minimal/index.d.ts +1 -0
- package/lib/minimal/index.js +9 -1
- package/lib/minimal/rpc/axios.js +1 -1
- package/lib/minimal/rpc/server.d.ts +35 -1
- package/lib/minimal/rpc/server.js +110 -43
- package/lib/minimal/stellartoml/index.d.ts +3 -0
- package/lib/no-axios/bindings/client.d.ts +30 -0
- package/lib/no-axios/bindings/client.js +134 -0
- package/lib/no-axios/bindings/config.d.ts +34 -0
- package/lib/no-axios/bindings/config.js +83 -0
- package/lib/no-axios/bindings/generator.d.ts +176 -0
- package/lib/no-axios/bindings/generator.js +131 -0
- package/lib/no-axios/bindings/index.d.ts +6 -0
- package/lib/no-axios/bindings/index.js +75 -0
- package/lib/no-axios/bindings/sac-spec.d.ts +1 -0
- package/lib/no-axios/bindings/sac-spec.js +7 -0
- package/lib/no-axios/bindings/types.d.ts +66 -0
- package/lib/no-axios/bindings/types.js +184 -0
- package/lib/no-axios/bindings/utils.d.ts +49 -0
- package/lib/no-axios/bindings/utils.js +223 -0
- package/lib/no-axios/bindings/wasm_fetcher.d.ts +25 -0
- package/lib/no-axios/bindings/wasm_fetcher.js +225 -0
- package/lib/no-axios/cli/index.d.ts +2 -0
- package/lib/no-axios/cli/index.js +171 -0
- package/lib/no-axios/cli/util.d.ts +55 -0
- package/lib/no-axios/cli/util.js +254 -0
- package/lib/no-axios/contract/client.js +2 -1
- package/lib/no-axios/horizon/call_builder.js +30 -6
- package/lib/no-axios/horizon/horizon_axios_client.js +1 -1
- package/lib/no-axios/index.d.ts +1 -0
- package/lib/no-axios/index.js +9 -1
- package/lib/no-axios/rpc/axios.js +1 -1
- package/lib/no-axios/rpc/server.d.ts +35 -1
- package/lib/no-axios/rpc/server.js +110 -43
- package/lib/no-axios/stellartoml/index.d.ts +3 -0
- package/lib/no-eventsource/bindings/client.d.ts +30 -0
- package/lib/no-eventsource/bindings/client.js +134 -0
- package/lib/no-eventsource/bindings/config.d.ts +34 -0
- package/lib/no-eventsource/bindings/config.js +83 -0
- package/lib/no-eventsource/bindings/generator.d.ts +176 -0
- package/lib/no-eventsource/bindings/generator.js +131 -0
- package/lib/no-eventsource/bindings/index.d.ts +6 -0
- package/lib/no-eventsource/bindings/index.js +75 -0
- package/lib/no-eventsource/bindings/sac-spec.d.ts +1 -0
- package/lib/no-eventsource/bindings/sac-spec.js +7 -0
- package/lib/no-eventsource/bindings/types.d.ts +66 -0
- package/lib/no-eventsource/bindings/types.js +184 -0
- package/lib/no-eventsource/bindings/utils.d.ts +49 -0
- package/lib/no-eventsource/bindings/utils.js +223 -0
- package/lib/no-eventsource/bindings/wasm_fetcher.d.ts +25 -0
- package/lib/no-eventsource/bindings/wasm_fetcher.js +225 -0
- package/lib/no-eventsource/cli/index.d.ts +2 -0
- package/lib/no-eventsource/cli/index.js +171 -0
- package/lib/no-eventsource/cli/util.d.ts +55 -0
- package/lib/no-eventsource/cli/util.js +254 -0
- package/lib/no-eventsource/contract/client.js +2 -1
- package/lib/no-eventsource/horizon/call_builder.js +30 -6
- package/lib/no-eventsource/horizon/horizon_axios_client.js +1 -1
- package/lib/no-eventsource/index.d.ts +1 -0
- package/lib/no-eventsource/index.js +9 -1
- package/lib/no-eventsource/rpc/axios.js +1 -1
- package/lib/no-eventsource/rpc/server.d.ts +35 -1
- package/lib/no-eventsource/rpc/server.js +110 -43
- package/lib/no-eventsource/stellartoml/index.d.ts +3 -0
- package/lib/rpc/axios.js +1 -1
- package/lib/rpc/server.d.ts +35 -1
- package/lib/rpc/server.js +110 -43
- package/lib/stellartoml/index.d.ts +3 -0
- package/package.json +10 -4
- package/CHANGELOG.md +0 -2023
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Server } from "../rpc";
|
|
2
|
+
/**
|
|
3
|
+
* Types of contract data that can be fetched
|
|
4
|
+
*/
|
|
5
|
+
export type ContractData = {
|
|
6
|
+
type: "wasm";
|
|
7
|
+
wasmBytes: Buffer;
|
|
8
|
+
} | {
|
|
9
|
+
type: "stellar-asset-contract";
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Errors that can occur during WASM fetching
|
|
13
|
+
*/
|
|
14
|
+
export declare class WasmFetchError extends Error {
|
|
15
|
+
readonly cause?: Error | undefined;
|
|
16
|
+
constructor(message: string, cause?: Error | undefined);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Fetch WASM from network using WASM hash
|
|
20
|
+
*/
|
|
21
|
+
export declare function fetchFromWasmHash(wasmHash: string, rpcServer: Server): Promise<ContractData>;
|
|
22
|
+
/**
|
|
23
|
+
* Fetch WASM from network using contract ID
|
|
24
|
+
*/
|
|
25
|
+
export declare function fetchFromContractId(contractId: string, rpcServer: Server): Promise<ContractData>;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.WasmFetchError = void 0;
|
|
8
|
+
exports.fetchFromContractId = fetchFromContractId;
|
|
9
|
+
exports.fetchFromWasmHash = fetchFromWasmHash;
|
|
10
|
+
var _stellarBase = require("@stellar/stellar-base");
|
|
11
|
+
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 }; })(); }
|
|
12
|
+
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); }
|
|
13
|
+
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); }
|
|
14
|
+
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); }); }; }
|
|
15
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
16
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
17
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
|
+
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); }
|
|
19
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
20
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
21
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
22
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
23
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
24
|
+
function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
|
|
25
|
+
function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
|
|
26
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
27
|
+
function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
|
|
28
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
29
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
30
|
+
var WasmFetchError = exports.WasmFetchError = function (_Error) {
|
|
31
|
+
function WasmFetchError(message, cause) {
|
|
32
|
+
var _this;
|
|
33
|
+
_classCallCheck(this, WasmFetchError);
|
|
34
|
+
_this = _callSuper(this, WasmFetchError, [message]);
|
|
35
|
+
_this.cause = cause;
|
|
36
|
+
_this.name = "WasmFetchError";
|
|
37
|
+
return _this;
|
|
38
|
+
}
|
|
39
|
+
_inherits(WasmFetchError, _Error);
|
|
40
|
+
return _createClass(WasmFetchError);
|
|
41
|
+
}(_wrapNativeSuper(Error));
|
|
42
|
+
function getRemoteWasmFromHash(_x, _x2) {
|
|
43
|
+
return _getRemoteWasmFromHash.apply(this, arguments);
|
|
44
|
+
}
|
|
45
|
+
function _getRemoteWasmFromHash() {
|
|
46
|
+
_getRemoteWasmFromHash = _asyncToGenerator(_regenerator().m(function _callee(server, hashBuffer) {
|
|
47
|
+
var contractCodeKey, response, entry, contractCode, _t;
|
|
48
|
+
return _regenerator().w(function (_context) {
|
|
49
|
+
while (1) switch (_context.p = _context.n) {
|
|
50
|
+
case 0:
|
|
51
|
+
_context.p = 0;
|
|
52
|
+
contractCodeKey = _stellarBase.xdr.LedgerKey.contractCode(new _stellarBase.xdr.LedgerKeyContractCode({
|
|
53
|
+
hash: _stellarBase.xdr.Hash.fromXDR(hashBuffer, "raw")
|
|
54
|
+
}));
|
|
55
|
+
_context.n = 1;
|
|
56
|
+
return server.getLedgerEntries(contractCodeKey);
|
|
57
|
+
case 1:
|
|
58
|
+
response = _context.v;
|
|
59
|
+
if (!(!response.entries || response.entries.length === 0)) {
|
|
60
|
+
_context.n = 2;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
throw new WasmFetchError("WASM not found for the given hash");
|
|
64
|
+
case 2:
|
|
65
|
+
entry = response.entries[0];
|
|
66
|
+
if (!(entry.key.switch() !== _stellarBase.xdr.LedgerEntryType.contractCode())) {
|
|
67
|
+
_context.n = 3;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
throw new WasmFetchError("Invalid ledger entry type returned");
|
|
71
|
+
case 3:
|
|
72
|
+
contractCode = entry.val.contractCode();
|
|
73
|
+
return _context.a(2, Buffer.from(contractCode.code()));
|
|
74
|
+
case 4:
|
|
75
|
+
_context.p = 4;
|
|
76
|
+
_t = _context.v;
|
|
77
|
+
if (!(_t instanceof WasmFetchError)) {
|
|
78
|
+
_context.n = 5;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
throw _t;
|
|
82
|
+
case 5:
|
|
83
|
+
throw new WasmFetchError("Failed to fetch WASM from hash", _t);
|
|
84
|
+
case 6:
|
|
85
|
+
return _context.a(2);
|
|
86
|
+
}
|
|
87
|
+
}, _callee, null, [[0, 4]]);
|
|
88
|
+
}));
|
|
89
|
+
return _getRemoteWasmFromHash.apply(this, arguments);
|
|
90
|
+
}
|
|
91
|
+
function isStellarAssetContract(instance) {
|
|
92
|
+
return instance.executable().switch() === _stellarBase.xdr.ContractExecutableType.contractExecutableStellarAsset();
|
|
93
|
+
}
|
|
94
|
+
function fetchWasmFromContract(_x3, _x4) {
|
|
95
|
+
return _fetchWasmFromContract.apply(this, arguments);
|
|
96
|
+
}
|
|
97
|
+
function _fetchWasmFromContract() {
|
|
98
|
+
_fetchWasmFromContract = _asyncToGenerator(_regenerator().m(function _callee2(server, contractAddress) {
|
|
99
|
+
var contract, response, entry, contractData, instance, wasmHash, wasmBytes, _t2;
|
|
100
|
+
return _regenerator().w(function (_context2) {
|
|
101
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
102
|
+
case 0:
|
|
103
|
+
_context2.p = 0;
|
|
104
|
+
contract = new _stellarBase.Contract(contractAddress.toString());
|
|
105
|
+
_context2.n = 1;
|
|
106
|
+
return server.getLedgerEntries(contract.getFootprint());
|
|
107
|
+
case 1:
|
|
108
|
+
response = _context2.v;
|
|
109
|
+
if (!(!response.entries || response.entries.length === 0)) {
|
|
110
|
+
_context2.n = 2;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
throw new WasmFetchError("Contract instance not found");
|
|
114
|
+
case 2:
|
|
115
|
+
entry = response.entries[0];
|
|
116
|
+
if (!(entry.key.switch() !== _stellarBase.xdr.LedgerEntryType.contractData())) {
|
|
117
|
+
_context2.n = 3;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
throw new WasmFetchError("Invalid ledger entry type returned");
|
|
121
|
+
case 3:
|
|
122
|
+
contractData = entry.val.contractData();
|
|
123
|
+
instance = contractData.val().instance();
|
|
124
|
+
if (!isStellarAssetContract(instance)) {
|
|
125
|
+
_context2.n = 4;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
return _context2.a(2, {
|
|
129
|
+
type: "stellar-asset-contract"
|
|
130
|
+
});
|
|
131
|
+
case 4:
|
|
132
|
+
wasmHash = instance.executable().wasmHash();
|
|
133
|
+
_context2.n = 5;
|
|
134
|
+
return getRemoteWasmFromHash(server, wasmHash);
|
|
135
|
+
case 5:
|
|
136
|
+
wasmBytes = _context2.v;
|
|
137
|
+
return _context2.a(2, {
|
|
138
|
+
type: "wasm",
|
|
139
|
+
wasmBytes: wasmBytes
|
|
140
|
+
});
|
|
141
|
+
case 6:
|
|
142
|
+
_context2.p = 6;
|
|
143
|
+
_t2 = _context2.v;
|
|
144
|
+
if (!(_t2 instanceof WasmFetchError)) {
|
|
145
|
+
_context2.n = 7;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
throw _t2;
|
|
149
|
+
case 7:
|
|
150
|
+
throw new WasmFetchError("Failed to fetch WASM from contract", _t2);
|
|
151
|
+
case 8:
|
|
152
|
+
return _context2.a(2);
|
|
153
|
+
}
|
|
154
|
+
}, _callee2, null, [[0, 6]]);
|
|
155
|
+
}));
|
|
156
|
+
return _fetchWasmFromContract.apply(this, arguments);
|
|
157
|
+
}
|
|
158
|
+
function fetchFromWasmHash(_x5, _x6) {
|
|
159
|
+
return _fetchFromWasmHash.apply(this, arguments);
|
|
160
|
+
}
|
|
161
|
+
function _fetchFromWasmHash() {
|
|
162
|
+
_fetchFromWasmHash = _asyncToGenerator(_regenerator().m(function _callee3(wasmHash, rpcServer) {
|
|
163
|
+
var hashBuffer, wasmBytes, _t3;
|
|
164
|
+
return _regenerator().w(function (_context3) {
|
|
165
|
+
while (1) switch (_context3.p = _context3.n) {
|
|
166
|
+
case 0:
|
|
167
|
+
_context3.p = 0;
|
|
168
|
+
hashBuffer = Buffer.from(wasmHash, "hex");
|
|
169
|
+
if (!(hashBuffer.length !== 32)) {
|
|
170
|
+
_context3.n = 1;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
throw new WasmFetchError("Invalid WASM hash length: expected 32 bytes, got ".concat(hashBuffer.length));
|
|
174
|
+
case 1:
|
|
175
|
+
_context3.n = 2;
|
|
176
|
+
return getRemoteWasmFromHash(rpcServer, hashBuffer);
|
|
177
|
+
case 2:
|
|
178
|
+
wasmBytes = _context3.v;
|
|
179
|
+
return _context3.a(2, {
|
|
180
|
+
type: "wasm",
|
|
181
|
+
wasmBytes: wasmBytes
|
|
182
|
+
});
|
|
183
|
+
case 3:
|
|
184
|
+
_context3.p = 3;
|
|
185
|
+
_t3 = _context3.v;
|
|
186
|
+
throw new WasmFetchError("Failed to fetch WASM from hash ".concat(wasmHash), _t3);
|
|
187
|
+
case 4:
|
|
188
|
+
return _context3.a(2);
|
|
189
|
+
}
|
|
190
|
+
}, _callee3, null, [[0, 3]]);
|
|
191
|
+
}));
|
|
192
|
+
return _fetchFromWasmHash.apply(this, arguments);
|
|
193
|
+
}
|
|
194
|
+
function fetchFromContractId(_x7, _x8) {
|
|
195
|
+
return _fetchFromContractId.apply(this, arguments);
|
|
196
|
+
}
|
|
197
|
+
function _fetchFromContractId() {
|
|
198
|
+
_fetchFromContractId = _asyncToGenerator(_regenerator().m(function _callee4(contractId, rpcServer) {
|
|
199
|
+
var contractAddress, _t4;
|
|
200
|
+
return _regenerator().w(function (_context4) {
|
|
201
|
+
while (1) switch (_context4.p = _context4.n) {
|
|
202
|
+
case 0:
|
|
203
|
+
_context4.p = 0;
|
|
204
|
+
if (_stellarBase.StrKey.isValidContract(contractId)) {
|
|
205
|
+
_context4.n = 1;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
throw new WasmFetchError("Invalid contract ID: ".concat(contractId));
|
|
209
|
+
case 1:
|
|
210
|
+
contractAddress = _stellarBase.Address.fromString(contractId);
|
|
211
|
+
_context4.n = 2;
|
|
212
|
+
return fetchWasmFromContract(rpcServer, contractAddress);
|
|
213
|
+
case 2:
|
|
214
|
+
return _context4.a(2, _context4.v);
|
|
215
|
+
case 3:
|
|
216
|
+
_context4.p = 3;
|
|
217
|
+
_t4 = _context4.v;
|
|
218
|
+
throw new WasmFetchError("Failed to fetch WASM from contract ".concat(contractId), _t4);
|
|
219
|
+
case 4:
|
|
220
|
+
return _context4.a(2);
|
|
221
|
+
}
|
|
222
|
+
}, _callee4, null, [[0, 3]]);
|
|
223
|
+
}));
|
|
224
|
+
return _fetchFromContractId.apply(this, arguments);
|
|
225
|
+
}
|
package/lib/cli/index.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.runCli = runCli;
|
|
8
|
+
var _commander = require("commander");
|
|
9
|
+
var path = _interopRequireWildcard(require("path"));
|
|
10
|
+
var _wasm_fetcher = require("../bindings/wasm_fetcher");
|
|
11
|
+
var _util = require("./util");
|
|
12
|
+
var _stellarBase = require("@stellar/stellar-base");
|
|
13
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t3 in e) "default" !== _t3 && {}.hasOwnProperty.call(e, _t3) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t3)) && (i.get || i.set) ? o(f, _t3, i) : f[_t3] = e[_t3]); return f; })(e, t); }
|
|
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 }; })(); }
|
|
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 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
|
+
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); }); }; }
|
|
18
|
+
var NETWORK_CONFIG = {
|
|
19
|
+
testnet: {
|
|
20
|
+
passphrase: _stellarBase.Networks.TESTNET,
|
|
21
|
+
rpcUrl: "https://soroban-testnet.stellar.org"
|
|
22
|
+
},
|
|
23
|
+
mainnet: {
|
|
24
|
+
passphrase: _stellarBase.Networks.PUBLIC,
|
|
25
|
+
rpcUrl: null
|
|
26
|
+
},
|
|
27
|
+
futurenet: {
|
|
28
|
+
passphrase: _stellarBase.Networks.FUTURENET,
|
|
29
|
+
rpcUrl: "https://rpc-futurenet.stellar.org"
|
|
30
|
+
},
|
|
31
|
+
localnet: {
|
|
32
|
+
passphrase: _stellarBase.Networks.STANDALONE,
|
|
33
|
+
rpcUrl: "http://localhost:8000/rpc"
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
function runCli() {
|
|
37
|
+
var program = new _commander.Command();
|
|
38
|
+
program.name("stellar-cli").description("CLI for generating TypeScript bindings for Stellar contracts").version("1.0.0");
|
|
39
|
+
program.command("generate").description("Generate TypeScript bindings for a Stellar contract").helpOption("-h, --help", "Display help for command").option("--wasm <path>", "Path to local WASM file").option("--wasm-hash <hash>", "Hash of WASM blob on network").option("--contract-id <id>", "Contract ID on network").option("--rpc-url <url>", "RPC server URL").option("--network <network>", "Network options to use: mainnet, testnet, futurenet, or localnet").option("--output-dir <dir>", "Output directory for generated bindings").option("--allow-http", "Allow insecure HTTP connections to RPC server", false).option("--timeout <ms>", "RPC request timeout in milliseconds").option("--headers <json>", 'Custom headers as JSON object (e.g., \'{"Authorization": "Bearer token"}\')').option("--contract-name <name>", "Name for the generated contract client class").option("--overwrite", "Overwrite existing files", false).action(function () {
|
|
40
|
+
var _ref = _asyncToGenerator(_regenerator().m(function _callee(options) {
|
|
41
|
+
var networkPassphrase, rpcUrl, allowHttp, network, config, needsRpcUrl, headers, timeout, _yield$createGenerato, generator, source, contractName, _t, _t2;
|
|
42
|
+
return _regenerator().w(function (_context) {
|
|
43
|
+
while (1) switch (_context.p = _context.n) {
|
|
44
|
+
case 0:
|
|
45
|
+
_context.p = 0;
|
|
46
|
+
rpcUrl = options.rpcUrl;
|
|
47
|
+
allowHttp = options.allowHttp;
|
|
48
|
+
if (!options.network) {
|
|
49
|
+
_context.n = 3;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
network = options.network.toLowerCase();
|
|
53
|
+
config = NETWORK_CONFIG[network];
|
|
54
|
+
if (config) {
|
|
55
|
+
_context.n = 1;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
throw new Error("\n\u2717 Invalid network: ".concat(options.network, ". Must be mainnet, testnet, futurenet, or localnet"));
|
|
59
|
+
case 1:
|
|
60
|
+
networkPassphrase = config.passphrase;
|
|
61
|
+
needsRpcUrl = options.wasmHash || options.contractId;
|
|
62
|
+
if (!(!rpcUrl && needsRpcUrl)) {
|
|
63
|
+
_context.n = 3;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
if (!config.rpcUrl) {
|
|
67
|
+
_context.n = 2;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
rpcUrl = config.rpcUrl;
|
|
71
|
+
console.log("Using default RPC URL for ".concat(network, ": ").concat(rpcUrl));
|
|
72
|
+
if (network === "localnet" && !options.allowHttp) {
|
|
73
|
+
allowHttp = true;
|
|
74
|
+
}
|
|
75
|
+
_context.n = 3;
|
|
76
|
+
break;
|
|
77
|
+
case 2:
|
|
78
|
+
if (!(network === "mainnet")) {
|
|
79
|
+
_context.n = 3;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
throw new Error("\n\u2717 --rpc-url is required for mainnet. Find RPC providers at: https://developers.stellar.org/docs/data/rpc/rpc-providers");
|
|
83
|
+
case 3:
|
|
84
|
+
if (!(options.outputDir === undefined)) {
|
|
85
|
+
_context.n = 4;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
throw new Error("Output directory (--output-dir) is required");
|
|
89
|
+
case 4:
|
|
90
|
+
if (!options.headers) {
|
|
91
|
+
_context.n = 7;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
_context.p = 5;
|
|
95
|
+
headers = JSON.parse(options.headers);
|
|
96
|
+
_context.n = 7;
|
|
97
|
+
break;
|
|
98
|
+
case 6:
|
|
99
|
+
_context.p = 6;
|
|
100
|
+
_t = _context.v;
|
|
101
|
+
throw new Error("Invalid JSON for --headers: ".concat(options.headers));
|
|
102
|
+
case 7:
|
|
103
|
+
if (!options.timeout) {
|
|
104
|
+
_context.n = 8;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
timeout = parseInt(options.timeout, 10);
|
|
108
|
+
if (!(Number.isNaN(timeout) || timeout <= 0)) {
|
|
109
|
+
_context.n = 8;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
throw new Error("Invalid timeout value: ".concat(options.timeout, ". Must be a positive integer."));
|
|
113
|
+
case 8:
|
|
114
|
+
console.log("Fetching contract...");
|
|
115
|
+
_context.n = 9;
|
|
116
|
+
return (0, _util.createGenerator)({
|
|
117
|
+
wasm: options.wasm,
|
|
118
|
+
wasmHash: options.wasmHash,
|
|
119
|
+
contractId: options.contractId,
|
|
120
|
+
rpcUrl: rpcUrl,
|
|
121
|
+
networkPassphrase: networkPassphrase,
|
|
122
|
+
serverOptions: {
|
|
123
|
+
allowHttp: allowHttp,
|
|
124
|
+
timeout: timeout,
|
|
125
|
+
headers: headers
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
case 9:
|
|
129
|
+
_yield$createGenerato = _context.v;
|
|
130
|
+
generator = _yield$createGenerato.generator;
|
|
131
|
+
source = _yield$createGenerato.source;
|
|
132
|
+
(0, _util.logSourceInfo)(source);
|
|
133
|
+
contractName = options.contractName || (0, _util.deriveContractName)(source) || "contract";
|
|
134
|
+
console.log("\n\u2713 Generating TypeScript bindings for \"".concat(contractName, "\"..."));
|
|
135
|
+
_context.n = 10;
|
|
136
|
+
return (0, _util.generateAndWrite)(generator, {
|
|
137
|
+
contractName: contractName,
|
|
138
|
+
outputDir: path.resolve(options.outputDir),
|
|
139
|
+
overwrite: options.overwrite
|
|
140
|
+
});
|
|
141
|
+
case 10:
|
|
142
|
+
console.log("\n\u2713 Successfully generated bindings in ".concat(options.outputDir));
|
|
143
|
+
console.log("\nUsage:");
|
|
144
|
+
console.log(" import { Client } from './".concat(path.basename(options.outputDir), "';"));
|
|
145
|
+
_context.n = 12;
|
|
146
|
+
break;
|
|
147
|
+
case 11:
|
|
148
|
+
_context.p = 11;
|
|
149
|
+
_t2 = _context.v;
|
|
150
|
+
if (_t2 instanceof _wasm_fetcher.WasmFetchError) {
|
|
151
|
+
console.error("\n\u2717 Error: ".concat(_t2.message));
|
|
152
|
+
if (_t2.cause) {
|
|
153
|
+
console.error(" Caused by: ".concat(_t2.cause.message));
|
|
154
|
+
}
|
|
155
|
+
} else if (_t2 instanceof Error) {
|
|
156
|
+
console.error("\n\u2717 Error: ".concat(_t2.message));
|
|
157
|
+
} else {
|
|
158
|
+
console.error("\n\u2717 Unexpected error:", _t2);
|
|
159
|
+
}
|
|
160
|
+
process.exit(1);
|
|
161
|
+
case 12:
|
|
162
|
+
return _context.a(2);
|
|
163
|
+
}
|
|
164
|
+
}, _callee, null, [[5, 6], [0, 11]]);
|
|
165
|
+
}));
|
|
166
|
+
return function (_x) {
|
|
167
|
+
return _ref.apply(this, arguments);
|
|
168
|
+
};
|
|
169
|
+
}());
|
|
170
|
+
program.parse();
|
|
171
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { BindingGenerator, GeneratedBindings, GenerateOptions } from "../bindings/generator";
|
|
2
|
+
import { RpcServer } from "../rpc/server";
|
|
3
|
+
export type GenerateAndWriteOptions = GenerateOptions & {
|
|
4
|
+
outputDir: string;
|
|
5
|
+
overwrite?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Source information about where the contract was fetched from
|
|
9
|
+
*/
|
|
10
|
+
export type ContractSource = {
|
|
11
|
+
type: "file";
|
|
12
|
+
path: string;
|
|
13
|
+
} | {
|
|
14
|
+
type: "wasm-hash";
|
|
15
|
+
hash: string;
|
|
16
|
+
rpcUrl: string;
|
|
17
|
+
network: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: "contract-id";
|
|
20
|
+
contractId: string;
|
|
21
|
+
rpcUrl: string;
|
|
22
|
+
network: string;
|
|
23
|
+
};
|
|
24
|
+
export type CreateGeneratorArgs = {
|
|
25
|
+
wasm?: string;
|
|
26
|
+
wasmHash?: string;
|
|
27
|
+
contractId?: string;
|
|
28
|
+
rpcUrl?: string;
|
|
29
|
+
networkPassphrase?: string;
|
|
30
|
+
serverOptions?: RpcServer.Options;
|
|
31
|
+
};
|
|
32
|
+
export type CreateGeneratorResult = {
|
|
33
|
+
generator: BindingGenerator;
|
|
34
|
+
source: ContractSource;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Create a BindingGenerator from local file, network hash, or contract ID
|
|
38
|
+
*/
|
|
39
|
+
export declare function createGenerator(args: CreateGeneratorArgs): Promise<CreateGeneratorResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Write generated bindings to disk
|
|
42
|
+
*/
|
|
43
|
+
export declare function writeBindings(outputDir: string, bindings: GeneratedBindings, overwrite: boolean): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Generate and write bindings to disk
|
|
46
|
+
*/
|
|
47
|
+
export declare function generateAndWrite(generator: BindingGenerator, options: GenerateAndWriteOptions): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Log source information
|
|
50
|
+
*/
|
|
51
|
+
export declare function logSourceInfo(source: ContractSource): void;
|
|
52
|
+
/**
|
|
53
|
+
* Derive contract name from source path
|
|
54
|
+
*/
|
|
55
|
+
export declare function deriveContractName(source: ContractSource): string | null;
|