UNPKG

vid-sdk

Version:

This sdk provides access to venom id domains built on top of the venom blockchain

1,519 lines (1,518 loc) 130 kB
var ue = Object.defineProperty, ce = Object.defineProperties; var pe = Object.getOwnPropertyDescriptors; var te = Object.getOwnPropertySymbols; var de = Object.prototype.hasOwnProperty, le = Object.prototype.propertyIsEnumerable; var ne = (n, e, t) => e in n ? ue(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, j = (n, e) => { for (var t in e || (e = {})) de.call(e, t) && ne(n, t, e[t]); if (te) for (var t of te(e)) le.call(e, t) && ne(n, t, e[t]); return n; }, L = (n, e) => ce(n, pe(e)); var u = (n, e, t) => new Promise((i, a) => { var s = (p) => { try { y(t.next(p)); } catch (h) { a(h); } }, o = (p) => { try { y(t.throw(p)); } catch (h) { a(h); } }, y = (p) => p.done ? i(p.value) : Promise.resolve(p.value).then(s, o); y((t = t.apply(n, e)).next()); }); var D = typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : {}, R = {}, T = {}, N = {}; (function(n) { Object.defineProperty(n, "__esModule", { value: !0 }), n.getUniqueId = n.mergeTransactions = n.LT_COLLATOR = n.Semaphore = n.DelayedTransactions = n.MessageExpiredException = n.AddressLiteral = n.isAddressObject = n.Address = void 0; class e { constructor(d) { this.equals = (f) => this._equals(f), this._address = d; } toString() { return this._address; } toJSON() { return this._address; } _equals(d) { return typeof d == "string" ? this._address === d : this._address === (d == null ? void 0 : d._address); } } n.Address = e; function t(l) { return l != null && (l instanceof e || Object.getPrototypeOf(l).constructor.name === e.prototype.constructor.name); } n.isAddressObject = t; class i extends e { constructor(d) { super(d); } } n.AddressLiteral = i; class a extends Error { constructor(d, f) { super("Message expired"), this.address = d, this.hash = f; } } n.MessageExpiredException = a; class s { constructor() { this.transactions = /* @__PURE__ */ new Map(); } waitTransaction(d, f) { return u(this, null, function* () { var _; let k = (_ = this.transactions.get(f)) === null || _ === void 0 ? void 0 : _.promise; if (k == null) { let w, r; k = new Promise((c, m) => { w = (b) => c(b), r = () => m(); }), this.transactions.set(f, { promise: k, resolve: w, reject: r }); } const M = yield k; if (M == null) throw new a(d, f); return M; }); } fillTransaction(d, f) { const _ = this.transactions.get(d); _ != null ? _.resolve(f) : this.transactions.set(d, { promise: Promise.resolve(f), resolve: () => { }, reject: () => { } }); } } n.DelayedTransactions = s; class o { constructor(d) { this.tasks = [], this.sched = () => { var f; this.count > 0 && this.tasks.length > 0 && (this.count--, (f = this.tasks.shift()) === null || f === void 0 || f()); }, this.count = d; } acquire() { return new Promise((d, f) => { this.tasks.push(() => { let _ = !1; d(() => { _ || (_ = !0, this.count++, this.sched()); }); }), p(this.sched); }); } releaseAll() { for (var d; this.tasks.length > 0; ) (d = this.tasks.shift()) === null || d === void 0 || d(); } } n.Semaphore = o; function y(l) { const d = document.createTextNode(""); let f, _, k = 0, M = 0; return new l(function() { let w; if (f) _ && (f = _.slice(M).concat(f)); else { if (!_) return; f = _; } if (_ = f, f = null, M = 0, typeof _ == "function") { w = _, _ = null, w(); return; } for (d.data = k = ++k % 2; M < _.length; ) w = _[M], M++, M === _.length && (_ = null), w(); }).observe(d, { characterData: !0 }), function(w) { if (f) { typeof f == "function" ? f = [f, w] : f.push(w); return; } f = w, d.data = k = ++k % 2; }; } const p = function() { if (typeof queueMicrotask == "function") return queueMicrotask; if (typeof document == "object" && document) { if (typeof MutationObserver == "function") return y(MutationObserver); if (typeof window.WebKitMutationObserver == "function") return y(window.WebKitMutationObserver); } if (typeof setImmediate == "function") return setImmediate; if (typeof setTimeout == "function" || typeof setTimeout == "object") return function(l) { setTimeout(l, 0); }; throw new Error("No `nextTick` implementation found"); }(); n.LT_COLLATOR = new Intl.Collator(void 0, { numeric: !0, sensitivity: "base" }); function h(l, d, f) { if (f.batchType === "old") return l.push(...d), l; if (l.length === 0) return l.push(...d), l; let _ = 0; for (; _ < l.length && n.LT_COLLATOR.compare(l[_].id.lt, f.maxLt) >= 0; ) ++_; return l.splice(_, 0, ...d), l; } n.mergeTransactions = h; const g = 4294967295; let v = Math.floor(Math.random() * g); function A() { return v = (v + 1) % g, v; } n.getUniqueId = A; })(N); Object.defineProperty(T, "__esModule", { value: !0 }); T.parsePartialTokensObject = T.parseTokensObject = T.serializeTokensObject = T.parseAccountInteraction = T.parsePermissions = T.parseMessage = T.serializeMessage = T.parseTransaction = T.serializeTransaction = void 0; const B = N; function me(n) { return { id: { hash: n.id.hash, lt: n.id.lt }, prevTransactionId: n.prevTransactionId != null ? { hash: n.prevTransactionId.hash, lt: n.prevTransactionId.lt } : void 0, createdAt: n.createdAt, aborted: n.aborted, exitCode: n.exitCode, resultCode: n.resultCode, origStatus: n.origStatus, endStatus: n.endStatus, totalFees: n.totalFees, inMessage: W(n.inMessage), outMessages: n.outMessages.map(W) }; } T.serializeTransaction = me; function ye(n) { return L(j({}, n), { inMessage: Q(n.inMessage), outMessages: n.outMessages.map(Q) }); } T.parseTransaction = ye; function W(n) { return { hash: n.hash, src: n.src ? n.src.toString() : void 0, dst: n.dst ? n.dst.toString() : void 0, value: n.value, bounce: n.bounce, bounced: n.bounced, body: n.body, bodyHash: n.bodyHash }; } T.serializeMessage = W; function Q(n) { return L(j({}, n), { src: n.src ? new B.Address(n.src) : void 0, dst: n.dst ? new B.Address(n.dst) : void 0 }); } T.parseMessage = Q; function he(n) { return L(j({}, n), { accountInteraction: n.accountInteraction ? se(n.accountInteraction) : void 0 }); } T.parsePermissions = he; function se(n) { return L(j({}, n), { address: new B.Address(n.address) }); } T.parseAccountInteraction = se; function fe(n) { return X(n); } T.serializeTokensObject = fe; function X(n) { if (typeof n == "object" && (0, B.isAddressObject)(n)) return n.toString(); if (Array.isArray(n)) { const e = []; for (const t of n) e.push(X(t)); return e; } else if (n != null && typeof n == "object") { const e = {}; for (const [t, i] of Object.entries(n)) e[t] = X(i); return e; } else return n; } function we(n, e) { const t = {}; for (const i of n) t[i.name] = F(i, e[i.name]); return t; } T.parseTokensObject = we; function ge(n, e) { const t = {}; for (const i of n) Object.prototype.hasOwnProperty.call(e, i.name) && (t[i.name] = F(i, !e[i.name])); return t; } T.parsePartialTokensObject = ge; function F(n, e) { if (n.type.startsWith("map")) { const t = n.type.indexOf(","), i = n.type.slice(4, t), a = n.type.slice(t + 1, -1), s = []; for (const [o, y] of e) s.push([ F({ name: "", type: i }, o), F({ name: "", type: a, components: n.components }, y) ]); return s; } else { const t = n.type.endsWith("[]"), i = !t && n.type.startsWith("optional"), a = t ? n.type.slice(0, -2) : i ? n.type.slice(9, -1) : n.type; if (t) { const s = { name: n.name, type: a, components: n.components }, o = []; for (const y of e) o.push(F(s, y)); return o; } else if (i) { if (e == null) return null; { const s = { name: n.name, type: a, components: n.components }; return F(s, e); } } else if (a === "tuple") { const s = {}; if (n.components != null) for (const o of n.components) s[o.name] = F(o, e[o.name]); return s; } else return a === "address" ? new B.Address(e) : e; } } var V = {}; Object.defineProperty(V, "__esModule", { value: !0 }); V.Subscriber = void 0; const Z = N, be = T; class _e { constructor(e) { this.provider = e, this.subscriptions = /* @__PURE__ */ new Map(), this.scanners = /* @__PURE__ */ new Map(), this.unsubscribe = () => u(this, null, function* () { return this._unsubscribe(); }); } /** * Returns a stream of new transactions */ transactions(e) { return this._addSubscription("transactionsFound", e, !1); } /** * Returns a finite stream of child transactions * @param transaction - root transaction */ trace(e) { const t = (0, Z.getUniqueId)(); return new O((i, a) => { const s = new Ae(this.provider, { origin: e, onData: i, onEnd: (o) => { this.scanners.delete(t), a(o); } }); return this.scanners.set(t, s), s.start(), Promise.resolve(); }, () => u(this, null, function* () { const i = this.scanners.get(t); i != null && (this.scanners.delete(t), yield i.stop()); }), K, !0); } /** * Returns a stream of old transactions */ oldTransactions(e, t) { const i = (0, Z.getUniqueId)(); return new O((a, s) => { const o = new ve(this.provider, j({ address: e, onData: a, onEnd: (y) => { this.scanners.delete(i), s(y); } }, t)); return this.scanners.set(i, o), o.start(), Promise.resolve(); }, () => u(this, null, function* () { const a = this.scanners.get(i); a != null && (this.scanners.delete(i), yield a.stop()); }), K, !0); } states(e) { return this._addSubscription("contractStateChanged", e, !1); } _unsubscribe() { return u(this, null, function* () { const e = []; for (const t of this.subscriptions.values()) for (const [i, a] of Object.entries(t)) delete t[i], a != null && e.push(a.subscription.then((s) => s.unsubscribe()).catch(() => { })); this.subscriptions.clear(); for (const t of this.scanners.values()) e.push(t.stop()); this.scanners.clear(), yield Promise.all(e); }); } _addSubscription(e, t, i) { const a = t.toString(), s = (y) => { const p = this.subscriptions.get(a); if (p == null) return; const h = p[e]; if (h != null) { const g = h.handlers.get(y); if (g != null) { h.handlers.delete(y); const { queue: v, onEnd: A, state: l } = g; l.finished || (l.finished = !0, v.clear(), v.enqueue(() => u(this, null, function* () { return A(l.eof); }))); } if (h.handlers.size === 0) { const v = h.subscription; delete p[e], v.then((A) => A.unsubscribe()).catch(console.debug); } } p.contractStateChanged == null && p.transactionsFound == null && this.subscriptions.delete(a); }, o = (0, Z.getUniqueId)(); return new O((y, p) => { const h = this.subscriptions.get(a); let g = h == null ? void 0 : h[e]; const v = { eof: !1, finished: !1 }, A = { onData: y, onEnd: p, queue: new Y(), state: v }; if (g != null) return g.handlers.set(o, A), Promise.resolve(); const l = /* @__PURE__ */ new Map(); l.set(o, A); const d = this.provider.subscribe(e, { address: t }).then((f) => (f.on("data", (_) => { for (const { onData: k, queue: M, state: w } of l.values()) w.eof || w.finished || M.enqueue(() => u(this, null, function* () { (yield k(_)) || (w.eof = !0, s(o)); })); }), f.on("unsubscribed", () => { for (const _ of l.keys()) s(_); }), f)).catch((f) => { console.error(f); for (const _ of l.keys()) s(_); throw f; }); return g = { subscription: d, handlers: l }, h == null ? this.subscriptions.set(a, { [e]: g }) : h[e] = g, d.then(() => { }); }, () => s(o), K, i); } } V.Subscriber = _e; function K(n, e) { return u(this, null, function* () { return e(n); }); } class O { constructor(e, t, i, a) { this.makeProducer = e, this.stopProducer = t, this.extractor = i, this.isFinite = a, this.fold = this.onlyFinite((s, o, y) => { let p = s; return new Promise((h, g) => { const v = this.makeProducer( // onData (A) => this.extractor(A, (l) => u(this, null, function* () { return p = yield o(p, l), !0; })), // onEnd (A) => { A ? h(p) : g(new Error("Subscription closed")); } ); y != null && (y.subscribed = v); }); }), this.finished = this.onlyFinite((s) => new Promise((o, y) => { const p = this.makeProducer( // onData (h) => this.extractor(h, (g) => !0), // onEnd (h) => { h ? o(void 0) : y(new Error("Subscription closed")); } ); s != null && (s.subscribed = p); })); } delayed(e) { return u(this, null, function* () { const { subscribed: t, result: i } = e({ first: () => { const a = {}, s = this.first(a); return { subscribed: a.subscribed, result: s }; }, on: (a) => { const s = {}; return this.on(a, s), { subscribed: s.subscribed, result: void 0 }; }, fold: this.fold != null ? (a, s) => { const o = {}, y = this.fold(a, s, o); return { subscribed: o.subscribed, result: y }; } : void 0, finished: this.finished != null ? () => { const a = {}, s = this.finished(a); return { subscribed: a.subscribed, result: s }; } : void 0 }); return yield t, () => i; }); } first(e) { const t = { found: !1 }; return new Promise((i, a) => { const s = this.makeProducer( // onData (o) => this.extractor(o, (y) => (Object.assign(t, { found: !0, result: y }), !1)), // onEnd (o) => { o ? this.isFinite ? i(t.found ? t.result : void 0) : t.found ? i(t.result) : a(new Error("Unexpected end of stream")) : a(new Error("Subscription closed")); } ); e != null && (e.subscribed = s); }); } on(e, t) { const i = this.makeProducer((a) => this.extractor(a, (s) => u(this, null, function* () { return yield e(s), !0; })), (a) => { }); t != null && (t.subscribed = i); } merge(e) { return new O((t, i) => { const a = { stopped: !1, counter: 0 }, s = (o) => { a.stopped || (++a.counter == 2 || !o) && (a.stopped = !0, i(o)); }; return Promise.all([ this.makeProducer(t, s), e.makeProducer(t, s) ]).then(() => { }); }, () => { this.stopProducer(), e.stopProducer(); }, this.extractor, this.isFinite && e.isFinite); } enumerate() { const e = { index: 0 }; return new O(this.makeProducer, this.stopProducer, (t, i) => this.extractor(t, (a) => u(this, null, function* () { return i({ index: e.index++, item: a }); })), this.isFinite); } tap(e) { return new O(this.makeProducer, this.stopProducer, (t, i) => this.extractor(t, (a) => u(this, null, function* () { return yield e(a), i(a); })), this.isFinite); } filter(e) { return new O(this.makeProducer, this.stopProducer, (t, i) => this.extractor(t, (a) => u(this, null, function* () { return (yield e(a)) ? i(a) : !0; })), this.isFinite); } filterMap(e) { return new O(this.makeProducer, this.stopProducer, (t, i) => this.extractor(t, (a) => u(this, null, function* () { const s = yield e(a); return s !== void 0 ? i(s) : !0; })), this.isFinite); } map(e) { return new O(this.makeProducer, this.stopProducer, (t, i) => this.extractor(t, (a) => u(this, null, function* () { const s = yield e(a); return i(s); })), this.isFinite); } flatMap(e) { return new O(this.makeProducer, this.stopProducer, (t, i) => this.extractor(t, (a) => u(this, null, function* () { const s = yield e(a); for (const o of s) if (!(yield i(o))) return !1; return !0; })), this.isFinite); } skip(e) { const t = { index: 0 }; return new O(this.makeProducer, this.stopProducer, (i, a) => this.extractor(i, (s) => t.index >= e ? a(s) : (++t.index, !0)), this.isFinite); } skipWhile(e) { const t = { shouldSkip: !0 }; return new O(this.makeProducer, this.stopProducer, (i, a) => this.extractor(i, (s) => u(this, null, function* () { return !t.shouldSkip || !(yield e(s)) ? (t.shouldSkip = !1, a(s)) : !0; })), this.isFinite); } take(e) { const t = { index: 0 }; return new O(this.makeProducer, this.stopProducer, (i, a) => this.extractor(i, (s) => t.index < e ? (++t.index, a(s)) : !1), !0); } takeWhile(e) { return new O(this.makeProducer, this.stopProducer, (t, i) => this.extractor(t, (a) => u(this, null, function* () { return (yield e(a)) ? i(a) : !1; })), !0); } takeWhileMap(e) { return new O(this.makeProducer, this.stopProducer, (t, i) => this.extractor(t, (a) => u(this, null, function* () { const s = yield e(a); return s !== void 0 ? i(s) : !1; })), !0); } onlyFinite(e) { if (this.isFinite) return e; } } class ve { constructor(e, t) { this.provider = e, this.params = t, this.queue = new Y(), this.isRunning = !1; } start() { this.isRunning || this.promise != null || (this.isRunning = !0, this.promise = (() => u(this, null, function* () { const e = this.params, t = { complete: !1 }; for (; this.isRunning && !t.complete; ) try { const { transactions: i, continuation: a } = yield this.provider.getTransactions({ address: this.params.address, continuation: this.continuation }); if (t.complete = !t.complete && i.length == null, !this.isRunning || t.complete) break; const s = i.filter((y) => (e.fromLt == null || Z.LT_COLLATOR.compare(y.id.lt, e.fromLt) > 0) && (e.fromUtime == null || y.createdAt > e.fromUtime)); if (s.length == 0) { t.complete = !0; break; } const o = { maxLt: s[0].id.lt, minLt: s[s.length - 1].id.lt, batchType: "old" }; if (this.queue.enqueue(() => u(this, null, function* () { (yield this.params.onData({ address: this.params.address, transactions: s, info: o })) || (t.complete = !0, this.isRunning = !1); })), a != null) this.continuation = a; else { t.complete = !0; break; } } catch (i) { console.error(i); } this.queue.enqueue(() => u(this, null, function* () { return this.params.onEnd(t.complete); })), this.isRunning = !1, this.continuation = void 0; }))()); } stop() { return u(this, null, function* () { this.isRunning = !1, this.queue.clear(), this.promise != null ? yield this.promise : this.params.onEnd(!1); }); } } class Ae { constructor(e, t) { this.provider = e, this.params = t, this.queue = new Y(), this.isRunning = !1, this.semaphore = new Z.Semaphore(10); } start() { if (this.isRunning || this.promise != null) return; const e = this.provider; this.isRunning = !0, this.promise = (() => u(this, null, function* () { const t = { complete: !1 }, i = (s) => { const o = { stopped: !1 }; return { promise: (() => u(this, null, function* () { let h = 500; for (; ; ) { const g = yield this.semaphore.acquire(); if (o.stopped) { g(); return; } const v = yield e.rawApi.findTransaction({ inMessageHash: s }).catch(() => ({ transaction: void 0 })).finally(() => g()); if (o.stopped) return; if (v.transaction != null) { const d = (0, be.parseTransaction)(v.transaction); return d.account = d.inMessage.dst, d; } let A; const l = new Promise((d, f) => { A = () => d(), o.reject = () => f(); }); if (o.timeout = setTimeout(A, h), yield l, o.stopped) return; o.reject = void 0, h = Math.min(h * 2, 3e3); } }))(), reject: () => { var h; o.stopped = !0, (h = o.reject) === null || h === void 0 || h.call(o), o.timeout != null && clearTimeout(o.timeout); } }; }, a = [this.params.origin]; try { e: for (; this.isRunning; ) { const s = a.shift(); if (s == null) { t.complete = !0; break; } const o = s.outMessages.filter((y) => y.dst != null).map((y) => { const p = y.hash; return i(p); }); this.pendingTransactions = o; for (const { promise: y } of o) { const p = yield y; if (!this.isRunning || t.complete || p == null) break e; this.queue.enqueue(() => u(this, null, function* () { (yield this.params.onData(p)) || (t.complete = !0, this.isRunning = !1, this.rejectPendingTransactions()); })), a.push(p); } this.pendingTransactions = void 0; } } catch (s) { console.error(s); } finally { this.queue.enqueue(() => u(this, null, function* () { return this.params.onEnd(t.complete); })), this.isRunning = !1, this.rejectPendingTransactions(); } }))(); } stop() { return u(this, null, function* () { this.isRunning = !1, this.queue.clear(), this.rejectPendingTransactions(), this.promise != null ? yield this.promise : this.params.onEnd(!1); }); } rejectPendingTransactions() { if (this.pendingTransactions != null) { for (const e of this.pendingTransactions) e.reject(); this.pendingTransactions = void 0; } this.semaphore.releaseAll(); } } class Y { constructor() { this.queue = [], this.workingOnPromise = !1; } enqueue(e) { this.queue.push(e), this._dequeue().catch(() => { }); } clear() { this.queue.length = 0; } _dequeue() { return u(this, null, function* () { if (this.workingOnPromise) return; const e = this.queue.shift(); e && (this.workingOnPromise = !0, e().then(() => { this.workingOnPromise = !1, this._dequeue(); }).catch(() => { this.workingOnPromise = !1, this._dequeue(); })); }); } } var q = {}; Object.defineProperty(q, "__esModule", { value: !0 }); q.TvmException = q.Contract = void 0; const H = N, C = T; class Ie { constructor(e, t, i) { if (!Array.isArray(t.functions)) throw new Error("Invalid abi. Functions array required"); if (!Array.isArray(t.events)) throw new Error("Invalid abi. Events array required"); this._provider = e, this._abi = JSON.stringify(t), this.methodsAbi = t.functions.reduce((a, s) => (s.inputs == null && (s.inputs = []), s.outputs == null && (s.outputs = []), a[s.name] = s, a), {}), this.eventsAbi = t.events.reduce((a, s) => (s.inputs == null && (s.inputs = []), a[s.name] = s, a), {}), this.fieldsAbi = t.fields, this._address = i, this._methods = new Proxy({}, { get: (a, s) => { const o = this.methodsAbi[s]; return (y = {}) => new Pe(this._provider, o, this._abi, this._address, s, y); } }), this._fields = new Proxy({}, { get: (a, s) => (...y) => u(this, [...y], function* (o = {}) { yield this._provider.ensureInitialized(); const { fields: p, state: h } = yield this._provider.rawApi.getContractFields({ address: this._address.toString(), abi: this._abi, cachedState: o == null ? void 0 : o.cachedState, allowPartial: (o == null ? void 0 : o.allowPartial) == null ? !1 : o.allowPartial }); if (p == null) throw h == null ? new Error("Account does not exist") : h.isDeployed ? new Error("Invalid account data") : new Error("Account is not deployed"); const g = (0, C.parseTokensObject)(this.fieldsAbi, p); if (g == null || !Object.prototype.hasOwnProperty.call(g, s)) throw new Error("Unknown field"); return g[s]; }) }); } get methods() { return this._methods; } get fields() { return this._fields; } get address() { return this._address; } get abi() { return this._abi; } /** * Requests contract data * * --- * Required permissions: `basic` */ getFullState() { return u(this, null, function* () { return yield this._provider.ensureInitialized(), yield this._provider.rawApi.getFullContractState({ address: this.address.toString() }); }); } /** * Unpacks all fields from the contract state using the specified ABI * * --- * Required permissions: `basic` */ getFields() { return u(this, arguments, function* (e = {}) { yield this._provider.ensureInitialized(); const { fields: t, state: i } = yield this._provider.rawApi.getContractFields({ address: this.address.toString(), abi: this._abi, cachedState: e.cachedState, allowPartial: e.allowPartial == null ? !1 : e.allowPartial }); return { fields: t != null ? (0, C.parseTokensObject)(this.fieldsAbi, t) : void 0, state: i }; }); } /** * Creates new contract transactions stream * * @param subscriber */ transactions(e) { return e.transactions(this._address).flatMap(({ transactions: t }) => t); } /** * Creates new contract events stream * * @param subscriber */ events(e) { return e.transactions(this._address).flatMap(({ transactions: t }) => t).flatMap((t) => this.decodeTransactionEvents({ transaction: t }).then((i) => (i.forEach((a) => a.transaction = t), i))); } waitForEvent() { return u(this, arguments, function* (e = {}) { const { range: t, filter: i } = e, a = typeof i == "string" ? ({ event: p }) => p === i : i; let s = e.subscriber; const o = s == null; s == null && (s = new this._provider.Subscriber()); const y = yield ((t == null ? void 0 : t.fromLt) != null || (t == null ? void 0 : t.fromUtime) != null ? s.oldTransactions(this._address, t).merge(s.transactions(this._address)) : s.transactions(this.address)).flatMap((p) => p.transactions).takeWhile((p) => t == null || (t.fromLt == null || H.LT_COLLATOR.compare(p.id.lt, t.fromLt) > 0) && (t.fromUtime == null || p.createdAt > t.fromUtime) && (t.toLt == null || H.LT_COLLATOR.compare(p.id.lt, t.toLt) < 0) && (t.toUtime == null || p.createdAt < t.toUtime)).flatMap((p) => this.decodeTransactionEvents({ transaction: p }).then((h) => (h.forEach((g) => g.transaction = p), h))).filterMap((p) => u(this, null, function* () { if (a == null || (yield a(p))) return p; })).first(); return o && (yield s.unsubscribe()), y; }); } getPastEvents(e) { return u(this, null, function* () { const { range: t, filter: i, limit: a } = e, s = typeof i == "string" ? ({ event: p }) => p === i : i, o = []; let y = e == null ? void 0 : e.continuation; e: for (; ; ) { const { transactions: p, continuation: h } = yield this._provider.getTransactions({ address: this._address, continuation: y }); if (p.length === null) break; const g = p.filter((v) => ((t == null ? void 0 : t.fromLt) == null || H.LT_COLLATOR.compare(v.id.lt, t.fromLt) > 0) && ((t == null ? void 0 : t.fromUtime) == null || v.createdAt > t.fromUtime) && ((t == null ? void 0 : t.toLt) == null || H.LT_COLLATOR.compare(v.id.lt, t.toLt) < 0) && ((t == null ? void 0 : t.toUtime) == null || v.createdAt < t.toUtime)); if (g.length > 0) { const v = yield Promise.all(g.map((A) => u(this, null, function* () { return { tx: A, events: yield this.decodeTransactionEvents({ transaction: A }).then((l) => (l.forEach((d) => d.transaction = A), l)) }; }))); for (let { tx: A, events: l } of v) { s != null && (l = yield Promise.all(l.map((d) => u(this, null, function* () { return (yield s(d)) ? d : void 0; }))).then((d) => d.filter((f) => f != null))), y = A.id; for (const d of l) { if (a != null && o.length >= a) break e; o.push(d); } if (a != null && o.length >= a) break e; } } if (y = h, y == null) break; } return { events: o, continuation: y }; }); } decodeTransaction(e) { return u(this, null, function* () { yield this._provider.ensureInitialized(); try { const t = yield this._provider.rawApi.decodeTransaction({ transaction: (0, C.serializeTransaction)(e.transaction), abi: this._abi, method: e.methods }); if (t == null) return; const { method: i, input: a, output: s } = t, o = this.methodsAbi[i]; return { method: i, input: o.inputs != null ? (0, C.parseTokensObject)(o.inputs, a) : {}, output: o.outputs != null ? (0, C.parseTokensObject)(o.outputs, s) : {} }; } catch (t) { return; } }); } decodeTransactionEvents(e) { return u(this, null, function* () { yield this._provider.ensureInitialized(); try { const { events: t } = yield this._provider.rawApi.decodeTransactionEvents({ transaction: (0, C.serializeTransaction)(e.transaction), abi: this._abi }), i = []; for (const { event: a, data: s } of t) { const o = this.eventsAbi[a]; i.push({ event: a, data: o.inputs != null ? (0, C.parseTokensObject)(o.inputs, s) : {} }); } return i; } catch (t) { return []; } }); } decodeInputMessage(e) { return u(this, null, function* () { yield this._provider.ensureInitialized(); try { const t = yield this._provider.rawApi.decodeInput({ abi: this._abi, body: e.body, internal: e.internal, method: e.methods }); if (t == null) return; const { method: i, input: a } = t, s = this.methodsAbi[i]; return { method: i, input: s.inputs != null ? (0, C.parseTokensObject)(s.inputs, a) : {} }; } catch (t) { return; } }); } decodeOutputMessage(e) { return u(this, null, function* () { yield this._provider.ensureInitialized(); try { const t = yield this._provider.rawApi.decodeOutput({ abi: this._abi, body: e.body, method: e.methods }); if (t == null) return; const { method: i, output: a } = t, s = this.methodsAbi[i]; return { method: i, output: s.outputs != null ? (0, C.parseTokensObject)(s.outputs, a) : {} }; } catch (t) { return; } }); } decodeEvent(e) { return u(this, null, function* () { yield this._provider.ensureInitialized(); try { const t = yield this._provider.rawApi.decodeEvent({ abi: this.abi, body: e.body, event: e.events }); if (t == null) return; const { event: i, data: a } = t, s = this.eventsAbi[i]; return { event: i, data: s.inputs != null ? (0, C.parseTokensObject)(s.inputs, a) : {} }; } catch (t) { return; } }); } } q.Contract = Ie; class ae extends Error { constructor(e) { super(`TvmException: ${e}`), this.code = e; } } q.TvmException = ae; class Pe { constructor(e, t, i, a, s, o) { this.provider = e, this.functionAbi = t, this.abi = i, this.address = a, this.method = s, this.params = (0, C.serializeTokensObject)(o); } send(e) { return u(this, null, function* () { yield this.provider.ensureInitialized(); const { transaction: t } = yield this.provider.rawApi.sendMessage({ sender: e.from.toString(), recipient: this.address.toString(), amount: e.amount, bounce: e.bounce == null ? !0 : e.bounce, payload: { abi: this.abi, method: this.method, params: this.params }, stateInit: e.stateInit }); return (0, C.parseTransaction)(t); }); } sendDelayed(e) { return u(this, null, function* () { yield this.provider.ensureInitialized(); const t = new H.DelayedTransactions(), i = yield this.provider.subscribe("messageStatusUpdated"); i.on("data", (o) => { o.address.equals(e.from) && t.fillTransaction(o.hash, o.transaction); }); const { message: a } = yield this.provider.rawApi.sendMessageDelayed({ sender: e.from.toString(), recipient: this.address.toString(), amount: e.amount, bounce: e.bounce == null ? !0 : e.bounce, payload: { abi: this.abi, method: this.method, params: this.params }, stateInit: e.stateInit }).catch((o) => { throw i.unsubscribe().catch(console.error), o; }), s = t.waitTransaction(this.address, a.hash).finally(() => i.unsubscribe().catch(console.error)); return { messageHash: a.hash, expireAt: a.expireAt, transaction: s }; }); } sendWithResult(e) { return u(this, null, function* () { yield this.provider.ensureInitialized(); let t = e.subscriber; const i = t == null; t == null && (t = new this.provider.Subscriber()); try { let a, s; const o = new Promise((l) => { s = (d) => l(d); }), y = []; t.transactions(this.address).flatMap((l) => l.transactions).filter((l) => { var d; return ((d = l.inMessage.src) === null || d === void 0 ? void 0 : d.equals(e.from)) || !1; }).on((l) => { a == null ? y.push(l) : a.possibleMessages.findIndex((d) => d.hash == l.inMessage.hash) >= 0 && (s == null || s(l)); }); const p = yield this.send(e), h = p.outMessages.filter((l) => { var d; return ((d = l.dst) === null || d === void 0 ? void 0 : d.equals(this.address)) || !1; }); a = { transaction: p, possibleMessages: h }; const g = y.find((l) => h.findIndex((d) => d.hash == l.inMessage.hash) >= 0); g != null && (s == null || s(g)); const v = yield o; let A; try { const l = yield this.provider.rawApi.decodeTransaction({ transaction: (0, C.serializeTransaction)(v), abi: this.abi, method: this.method }); l != null && (A = this.functionAbi.outputs != null ? (0, C.parseTokensObject)(this.functionAbi.outputs, l.output) : {}); } catch (l) { console.error(l); } return { parentTransaction: a.transaction, childTransaction: v, output: A }; } finally { i && (yield t.unsubscribe()); } }); } estimateFees(e) { return u(this, null, function* () { yield this.provider.ensureInitialized(); const { fees: t } = yield this.provider.rawApi.estimateFees({ sender: e.from.toString(), recipient: this.address.toString(), amount: e.amount, payload: { abi: this.abi, method: this.method, params: this.params }, stateInit: e.stateInit }); return t; }); } sendExternal(e) { return u(this, null, function* () { yield this.provider.ensureInitialized(); const t = e.withoutSignature === !0 ? this.provider.rawApi.sendUnsignedExternalMessage : this.provider.rawApi.sendExternalMessage, { transaction: i, output: a } = yield t({ publicKey: e.publicKey, recipient: this.address.toString(), stateInit: e.stateInit, payload: { abi: this.abi, method: this.method, params: this.params }, local: e.local, executorParams: e.executorParams ? { disableSignatureCheck: e.executorParams.disableSignatureCheck, overrideBalance: e.executorParams.overrideBalance } : void 0 }); return { transaction: (0, C.parseTransaction)(i), output: a != null ? (0, C.parseTokensObject)(this.functionAbi.outputs, a) : void 0 }; }); } sendExternalDelayed(e) { return u(this, null, function* () { yield this.provider.ensureInitialized(); const t = new H.DelayedTransactions(), i = yield this.provider.subscribe("messageStatusUpdated"); i.on("data", (o) => { o.address.equals(this.address) && t.fillTransaction(o.hash, o.transaction); }); const { message: a } = yield this.provider.rawApi.sendExternalMessageDelayed({ publicKey: e.publicKey, recipient: this.address.toString(), stateInit: e.stateInit, payload: { abi: this.abi, method: this.method, params: this.params } }).catch((o) => { throw i.unsubscribe().catch(console.error), o; }), s = t.waitTransaction(this.address, a.hash).finally(() => i.unsubscribe().catch(console.error)); return { messageHash: a.hash, expireAt: a.expireAt, transaction: s }; }); } call() { return u(this, arguments, function* (e = {}) { yield this.provider.ensureInitialized(); const { output: t, code: i } = yield this.provider.rawApi.runLocal({ address: this.address.toString(), cachedState: e.cachedState, responsible: e.responsible, functionCall: { abi: this.abi, method: this.method, params: this.params } }); if (t == null || i != 0) throw new ae(i); return (0, C.parseTokensObject)(this.functionAbi.outputs, t); }); } /** * Encodes this method as an external message and * executes all transaction phases locally, producing a new state */ executeExternal(e) { return u(this, null, function* () { yield this.provider.ensureInitialized(); const { transaction: t, newState: i, output: a } = yield this.provider.rawApi.executeLocal({ address: this.address.toString(), cachedState: e.cachedState, stateInit: e.stateInit, payload: { abi: this.abi, method: this.method, params: this.params }, messageHeader: { type: "external", publicKey: e.publicKey, withoutSignature: e.withoutSignature }, executorParams: e.executorParams != null ? { disableSignatureCheck: e.executorParams.disableSignatureCheck, overrideBalance: e.executorParams.overrideBalance } : void 0 }); return { transaction: (0, C.parseTransaction)(t), newState: i, output: a !== void 0 ? (0, C.parseTokensObject)(this.functionAbi.outputs, a) : void 0 }; }); } /** * Encodes this method as an internal message and * executes all transaction phases locally, producing a new state */ executeInternal(e) { return u(this, null, function* () { yield this.provider.ensureInitialized(); const { transaction: t, newState: i, output: a } = yield this.provider.rawApi.executeLocal({ address: this.address.toString(), cachedState: e.cachedState, stateInit: e.stateInit, payload: { abi: this.abi, method: this.method, params: this.params }, messageHeader: { type: "internal", sender: e.sender.toString(), amount: e.amount, bounce: e.bounce != null ? e.bounce : !1, bounced: e.bounced }, executorParams: e.executorParams != null ? { disableSignatureCheck: e.executorParams.disableSignatureCheck, overrideBalance: e.executorParams.overrideBalance } : void 0 }); return { transaction: (0, C.parseTransaction)(t), newState: i, output: a !== void 0 ? (0, C.parseTokensObject)(this.functionAbi.outputs, a) : void 0 }; }); } encodeInternal() { return u(this, null, function* () { yield this.provider.ensureInitialized(); const { boc: e } = yield this.provider.rawApi.encodeInternalInput({ abi: this.abi, method: this.method, params: this.params }); return e; }); } } var ie = {}; Object.defineProperty(ie, "__esModule", { value: !0 }); (function(n) { var e = D && D.__createBinding || (Object.create ? function(w, r, c, m) { m === void 0 && (m = c); var b = Object.getOwnPropertyDescriptor(r, c); (!b || ("get" in b ? !r.__esModule : b.writable || b.configurable)) && (b = { enumerable: !0, get: function() { return r[c]; } }), Object.defineProperty(w, m, b); } : function(w, r, c, m) { m === void 0 && (m = c), w[m] = r[c]; }), t = D && D.__setModuleDefault || (Object.create ? function(w, r) { Object.defineProperty(w, "default", { enumerable: !0, value: r }); } : function(w, r) { w.default = r; }), i = D && D.__importStar || function(w) { if (w && w.__esModule) return w; var r = {}; if (w != null) for (var c in w) c !== "default" && Object.prototype.hasOwnProperty.call(w, c) && e(r, w, c); return t(r, w), r; }, a = D && D.__exportStar || function(w, r) { for (var c in w) c !== "default" && !Object.prototype.hasOwnProperty.call(r, c) && e(r, w, c); }; Object.defineProperty(n, "__esModule", { value: !0 }), n.ProviderNotInitializedException = n.ProviderNotFoundException = n.ProviderRpcClient = n.hasEverscaleProvider = n.LT_COLLATOR = n.isAddressObject = n.mergeTransactions = n.MessageExpiredException = n.AddressLiteral = n.Address = n.Subscriber = void 0; const s = T, o = N, y = i(V), p = i(q); a(ie, n), a(T, n), a(q, n); var h = V; Object.defineProperty(n, "Subscriber", { enumerable: !0, get: function() { return h.Subscriber; } }); var g = N; Object.defineProperty(n, "Address", { enumerable: !0, get: function() { return g.Address; } }), Object.defineProperty(n, "AddressLiteral", { enumerable: !0, get: function() { return g.AddressLiteral; } }), Object.defineProperty(n, "MessageExpiredException", { enumerable: !0, get: function() { return g.MessageExpiredException; } }), Object.defineProperty(n, "mergeTransactions", { enumerable: !0, get: function() { return g.mergeTransactions; } }), Object.defineProperty(n, "isAddressObject", { enumerable: !0, get: function() { return g.isAddressObject; } }), Object.defineProperty(n, "LT_COLLATOR", { enumerable: !0, get: function() { return g.LT_COLLATOR; } }); const v = typeof window != "undefined" && typeof window.document != "undefined"; let A; !v || document.readyState === "complete" ? A = Promise.resolve() : A = new Promise((w) => { window.addEventListener("load", () => { w(); }); }); const l = () => v ? window.__ever || window.ton : void 0; function d() { return u(this, null, function* () { return v ? (yield A, window.__hasEverscaleProvider === !0 || window.hasTonProvider === !0) : !1; }); } n.hasEverscaleProvider = d; class f { constructor(r = {}) { this._subscriptions = { connected: /* @__PURE__ */ new Map(), disconnected: /* @__PURE__ */ new Map(), transactionsFound: /* @__PURE__ */ new Map(), contractStateChanged: /* @__PURE__ */ new Map(), messageStatusUpdated: /* @__PURE__ */ new Map(), networkChanged: /* @__PURE__ */ new Map(), permissionsChanged: /* @__PURE__ */ new Map(), loggedOut: /* @__PURE__ */ new Map() }, this._contractSubscriptions = /* @__PURE__ */ new Map(), this._properties = r; const c = this; class m extends p.Contract { constructor(I, S) { super(c, I, S); } } this.Contract = m; class b extends y.Subscriber { constructor() { super(c); } } this.Subscriber = b, this._api = new Proxy({}, { get: (P, I) => (S) => { if (this._provider != null) return this._provider.request({ method: I, params: S }); throw new k(); } }), r.forceUseFallback === !0 ? this._initializationPromise = r.fallback != null ? r.fallback().then((P) => { this._provider = P; }) : Promise.resolve() : (this._provider = l(), this._provider != null ? this._initializationPromise = Promise.resolve() : this._initializationPromise = d().then((P) => new Promise((I) => { if (!P) return I(); if (this._provider = l(), this._provider != null) I(); else { const S = window.__hasEverscaleProvider === !0 ? "ever#initialized" : "ton#initialized"; window.addEventListener(S, (x) => { this._provider = l(), I(); }); } })).then(() => u(this, null, function* () { this._provider == null && r.fallback != null && (this._provider = yield r.fallback()); }))), this._initializationPromise.then(() => { this._provider != null && this._registerEventHandlers(this._provider); }); } /** * Checks whether this page has injected Everscale provider or * there is a fallback provider. */ hasProvider() { return u(this, null, function* () { return this._properties.fallback != null ? !0 : d(); }); } /** * Waits until provider api will be available. Calls `fallback` if no provider was found * * @throws ProviderNotFoundException when no provider found */ ensureInitialized() { return u(this, null, function* () { if (yield this._initializationPromise, this._provider == null) throw new _(); }); } /** * Whether provider api is ready */ get isInitialized() { return this._provider != null; } /** * Raw provider */ get raw() { if (this._provider != null) return this._provider; throw new k(); } /** * Raw provider api */ get rawApi() { return this._api; } /** * Creates typed contract wrapper. * * @param abi Readonly object (must be declared with `as const`) * @param address Default contract address * * @deprecated `new ever.Contract(abi, address)` should be used instead */ createContract(r, c) { return new this.Contract(r, c); } /** * Creates subscriptions group * * @deprecated `new ever.Subscriber()` should be used instead */ createSubscriber() { return new this.Subscriber(); } /** * Requests new permissions for current origin. * Shows an approval window to the user. * Will overwrite already existing permissions * * --- * Required permissions: none */ requestPermissions(r) { return u(this, null, function* () { yield this.ensureInitialized(); const c = yield this._api.requestPermissions({ permissions: r.permissions }); return (0, s.parsePermissions)(c); }); } /** * Updates `accountInteraction` permission value * * --- * Requires permissions: `accountInteraction` */ changeAccount() { return u(this, null, function* () { yield this.ensureInitialized(), yield this._api.changeAccount(); }); } /** * Removes all permissions for current origin and stops all subscriptions */ disconnect() { return u(this, null, function* () { yield this.ensureInitialized(), yield this._api.disconnect(); }); }