polkadot-api 2.0.0-rc.6 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +1 -1
- package/dist/umd/ws.min.js +3 -3
- package/package.json +9 -9
package/bin/cli.js
CHANGED
package/dist/umd/ws.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(it,Ct){typeof exports=="object"&&typeof module<"u"?Ct(exports):typeof define=="function"&&define.amd?define(["exports"],Ct):(it=typeof globalThis<"u"?globalThis:it||self,Ct(it.papiWs={}))})(this,(function(it){"use strict";var Ct=function(e,t){return Ct=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=r[s])},Ct(e,t)};function Ye(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Ct(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}function dc(e,t,n,r){function s(o){return o instanceof n?o:new n(function(a){a(o)})}return new(n||(n=Promise))(function(o,a){function i(u){try{c(r.next(u))}catch(h){a(h)}}function l(u){try{c(r.throw(u))}catch(h){a(h)}}function c(u){u.done?o(u.value):s(u.value).then(i,l)}c((r=r.apply(e,t||[])).next())})}function ps(e,t){var n={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},r,s,o,a=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return a.next=i(0),a.throw=i(1),a.return=i(2),typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function i(c){return function(u){return l([c,u])}}function l(c){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(n=0)),n;)try{if(r=1,s&&(o=c[0]&2?s.return:c[0]?s.throw||((o=s.return)&&o.call(s),0):s.next)&&!(o=o.call(s,c[1])).done)return o;switch(s=0,o&&(c=[c[0]&2,o.value]),c[0]){case 0:case 1:o=c;break;case 4:return n.label++,{value:c[1],done:!1};case 5:n.label++,s=c[1],c=[0];continue;case 7:c=n.ops.pop(),n.trys.pop();continue;default:if(o=n.trys,!(o=o.length>0&&o[o.length-1])&&(c[0]===6||c[0]===2)){n=0;continue}if(c[0]===3&&(!o||c[1]>o[0]&&c[1]<o[3])){n.label=c[1];break}if(c[0]===6&&n.label<o[1]){n.label=o[1],o=c;break}if(o&&n.label<o[2]){n.label=o[2],n.ops.push(c);break}o[2]&&n.ops.pop(),n.trys.pop();continue}c=t.call(e,n)}catch(u){c=[6,u],s=0}finally{r=o=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function Pt(e){var t=typeof Symbol=="function"&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function
|
|
1
|
+
(function(it,Ct){typeof exports=="object"&&typeof module<"u"?Ct(exports):typeof define=="function"&&define.amd?define(["exports"],Ct):(it=typeof globalThis<"u"?globalThis:it||self,Ct(it.papiWs={}))})(this,(function(it){"use strict";var Ct=function(e,t){return Ct=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=r[s])},Ct(e,t)};function Ye(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Ct(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}function dc(e,t,n,r){function s(o){return o instanceof n?o:new n(function(a){a(o)})}return new(n||(n=Promise))(function(o,a){function i(u){try{c(r.next(u))}catch(h){a(h)}}function l(u){try{c(r.throw(u))}catch(h){a(h)}}function c(u){u.done?o(u.value):s(u.value).then(i,l)}c((r=r.apply(e,t||[])).next())})}function ps(e,t){var n={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},r,s,o,a=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return a.next=i(0),a.throw=i(1),a.return=i(2),typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function i(c){return function(u){return l([c,u])}}function l(c){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(n=0)),n;)try{if(r=1,s&&(o=c[0]&2?s.return:c[0]?s.throw||((o=s.return)&&o.call(s),0):s.next)&&!(o=o.call(s,c[1])).done)return o;switch(s=0,o&&(c=[c[0]&2,o.value]),c[0]){case 0:case 1:o=c;break;case 4:return n.label++,{value:c[1],done:!1};case 5:n.label++,s=c[1],c=[0];continue;case 7:c=n.ops.pop(),n.trys.pop();continue;default:if(o=n.trys,!(o=o.length>0&&o[o.length-1])&&(c[0]===6||c[0]===2)){n=0;continue}if(c[0]===3&&(!o||c[1]>o[0]&&c[1]<o[3])){n.label=c[1];break}if(c[0]===6&&n.label<o[1]){n.label=o[1],o=c;break}if(o&&n.label<o[2]){n.label=o[2],n.ops.push(c);break}o[2]&&n.ops.pop(),n.trys.pop();continue}c=t.call(e,n)}catch(u){c=[6,u],s=0}finally{r=o=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}function Pt(e){var t=typeof Symbol=="function"&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function He(e,t){var n=typeof Symbol=="function"&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),s,o=[],a;try{for(;(t===void 0||t-- >0)&&!(s=r.next()).done;)o.push(s.value)}catch(i){a={error:i}}finally{try{s&&!s.done&&(n=r.return)&&n.call(r)}finally{if(a)throw a.error}}return o}function Te(e,t,n){if(n||arguments.length===2)for(var r=0,s=t.length,o;r<s;r++)(o||!(r in t))&&(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}function Ft(e){return this instanceof Ft?(this.v=e,this):new Ft(e)}function hc(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),s,o=[];return s=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),i("next"),i("throw"),i("return",a),s[Symbol.asyncIterator]=function(){return this},s;function a(v){return function(d){return Promise.resolve(d).then(v,h)}}function i(v,d){r[v]&&(s[v]=function(f){return new Promise(function(b,y){o.push([v,f,b,y])>1||l(v,f)})},d&&(s[v]=d(s[v])))}function l(v,d){try{c(r[v](d))}catch(f){p(o[0][3],f)}}function c(v){v.value instanceof Ft?Promise.resolve(v.value.v).then(u,h):p(o[0][2],v)}function u(v){l("next",v)}function h(v){l("throw",v)}function p(v,d){v(d),o.shift(),o.length&&l(o[0][0],o[0][1])}}function pc(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof Pt=="function"?Pt(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(o){n[o]=e[o]&&function(a){return new Promise(function(i,l){a=e[o](a),s(i,l,a.done,a.value)})}}function s(o,a,i,l){Promise.resolve(l).then(function(c){o({value:c,done:i})},a)}}typeof SuppressedError=="function"&&SuppressedError;function Q(e){return typeof e=="function"}function rr(e){var t=function(r){Error.call(r),r.stack=new Error().stack},n=e(t);return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var sr=rr(function(e){return function(n){e(this),this.message=n?n.length+` errors occurred during unsubscription:
|
|
2
2
|
`+n.map(function(r,s){return s+1+") "+r.toString()}).join(`
|
|
3
|
-
`):"",this.name="UnsubscriptionError",this.errors=n}});function yn(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var _t=(function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,n,r,s,o;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var i=Pt(a),l=i.next();!l.done;l=i.next()){var c=l.value;c.remove(this)}}catch(f){t={error:f}}finally{try{l&&!l.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}else a.remove(this);var u=this.initialTeardown;if(Q(u))try{u()}catch(f){o=f instanceof sr?f.errors:[f]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var p=Pt(h),v=p.next();!v.done;v=p.next()){var d=v.value;try{bs(d)}catch(f){o=o??[],f instanceof sr?o=He(He([],Te(o)),Te(f.errors)):o.push(f)}}}catch(f){r={error:f}}finally{try{v&&!v.done&&(s=p.return)&&s.call(p)}finally{if(r)throw r.error}}}if(o)throw new sr(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)bs(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(t)}},e.prototype._hasParent=function(t){var n=this._parentage;return n===t||Array.isArray(n)&&n.includes(t)},e.prototype._addParent=function(t){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(t),n):n?[n,t]:t},e.prototype._removeParent=function(t){var n=this._parentage;n===t?this._parentage=null:Array.isArray(n)&&yn(n,t)},e.prototype.remove=function(t){var n=this._finalizers;n&&yn(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=(function(){var t=new e;return t.closed=!0,t})(),e})(),fs=_t.EMPTY;function vs(e){return e instanceof _t||e&&"closed"in e&&Q(e.remove)&&Q(e.add)&&Q(e.unsubscribe)}function bs(e){Q(e)?e():e.unsubscribe()}var fc={Promise:void 0},vc={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,He([e,t],Te(n)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function ms(e){vc.setTimeout(function(){throw e})}function Ee(){}function gn(e){e()}var Zt=(function(e){Ye(t,e);function t(n){var r=e.call(this)||this;return r.isStopped=!1,n?(r.destination=n,vs(n)&&n.add(r)):r.destination=yc,r}return t.create=function(n,r,s){return new Wt(n,r,s)},t.prototype.next=function(n){this.isStopped||this._next(n)},t.prototype.error=function(n){this.isStopped||(this.isStopped=!0,this._error(n))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(n){this.destination.next(n)},t.prototype._error=function(n){try{this.destination.error(n)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(_t),bc=(function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var n=this.partialObserver;if(n.next)try{n.next(t)}catch(r){wn(r)}},e.prototype.error=function(t){var n=this.partialObserver;if(n.error)try{n.error(t)}catch(r){wn(r)}else wn(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(n){wn(n)}},e})(),Wt=(function(e){Ye(t,e);function t(n,r,s){var o=e.call(this)||this,a;return Q(n)||!n?a={next:n??void 0,error:r??void 0,complete:s??void 0}:a=n,o.destination=new bc(a),o}return t})(Zt);function wn(e){ms(e)}function mc(e){throw e}var yc={closed:!0,next:Ee,error:mc,complete:Ee},or=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Le(e){return e}function ys(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return gs(e)}function gs(e){return e.length===0?Le:e.length===1?e[0]:function(n){return e.reduce(function(r,s){return s(r)},n)}}var D=(function(){function e(t){t&&(this._subscribe=t)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(t,n,r){var s=this,o=wc(t)?t:new Wt(t,n,r);return gn(function(){var a=s,i=a.operator,l=a.source;o.add(i?i.call(o,l):l?s._subscribe(o):s._trySubscribe(o))}),o},e.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(n){t.error(n)}},e.prototype.forEach=function(t,n){var r=this;return n=ws(n),new n(function(s,o){var a=new Wt({next:function(i){try{t(i)}catch(l){o(l),a.unsubscribe()}},error:o,complete:s});r.subscribe(a)})},e.prototype._subscribe=function(t){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(t)},e.prototype[or]=function(){return this},e.prototype.pipe=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return gs(t)(this)},e.prototype.toPromise=function(t){var n=this;return t=ws(t),new t(function(r,s){var o;n.subscribe(function(a){return o=a},function(a){return s(a)},function(){return r(o)})})},e.create=function(t){return new e(t)},e})();function ws(e){var t;return(t=e??fc.Promise)!==null&&t!==void 0?t:Promise}function gc(e){return e&&Q(e.next)&&Q(e.error)&&Q(e.complete)}function wc(e){return e&&e instanceof Zt||gc(e)&&vs(e)}function $c(e){return Q(e?.lift)}function J(e){return function(t){if($c(t))return t.lift(function(n){try{return e(n,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function Y(e,t,n,r,s){return new Ec(e,t,n,r,s)}var Ec=(function(e){Ye(t,e);function t(n,r,s,o,a,i){var l=e.call(this,n)||this;return l.onFinalize=a,l.shouldUnsubscribe=i,l._next=r?function(c){try{r(c)}catch(u){n.error(u)}}:e.prototype._next,l._error=o?function(c){try{o(c)}catch(u){n.error(u)}finally{this.unsubscribe()}}:e.prototype._error,l._complete=s?function(){try{s()}catch(c){n.error(c)}finally{this.unsubscribe()}}:e.prototype._complete,l}return t.prototype.unsubscribe=function(){var n;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;e.prototype.unsubscribe.call(this),!r&&((n=this.onFinalize)===null||n===void 0||n.call(this))}},t})(Zt),kc=rr(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),ye=(function(e){Ye(t,e);function t(){var n=e.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return t.prototype.lift=function(n){var r=new $s(this,this);return r.operator=n,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new kc},t.prototype.next=function(n){var r=this;gn(function(){var s,o;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var a=Pt(r.currentObservers),i=a.next();!i.done;i=a.next()){var l=i.value;l.next(n)}}catch(c){s={error:c}}finally{try{i&&!i.done&&(o=a.return)&&o.call(a)}finally{if(s)throw s.error}}}})},t.prototype.error=function(n){var r=this;gn(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=n;for(var s=r.observers;s.length;)s.shift().error(n)}})},t.prototype.complete=function(){var n=this;gn(function(){if(n._throwIfClosed(),!n.isStopped){n.isStopped=!0;for(var r=n.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var n;return((n=this.observers)===null||n===void 0?void 0:n.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(n){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,n)},t.prototype._subscribe=function(n){return this._throwIfClosed(),this._checkFinalizedStatuses(n),this._innerSubscribe(n)},t.prototype._innerSubscribe=function(n){var r=this,s=this,o=s.hasError,a=s.isStopped,i=s.observers;return o||a?fs:(this.currentObservers=null,i.push(n),new _t(function(){r.currentObservers=null,yn(i,n)}))},t.prototype._checkFinalizedStatuses=function(n){var r=this,s=r.hasError,o=r.thrownError,a=r.isStopped;s?n.error(o):a&&n.complete()},t.prototype.asObservable=function(){var n=new D;return n.source=this,n},t.create=function(n,r){return new $s(n,r)},t})(D),$s=(function(e){Ye(t,e);function t(n,r){var s=e.call(this)||this;return s.destination=n,s.source=r,s}return t.prototype.next=function(n){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.next)===null||s===void 0||s.call(r,n)},t.prototype.error=function(n){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.error)===null||s===void 0||s.call(r,n)},t.prototype.complete=function(){var n,r;(r=(n=this.destination)===null||n===void 0?void 0:n.complete)===null||r===void 0||r.call(n)},t.prototype._subscribe=function(n){var r,s;return(s=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&s!==void 0?s:fs},t})(ye),xc=(function(e){Ye(t,e);function t(n){var r=e.call(this)||this;return r._value=n,r}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(n){var r=e.prototype._subscribe.call(this,n);return!r.closed&&n.next(this._value),r},t.prototype.getValue=function(){var n=this,r=n.hasError,s=n.thrownError,o=n._value;if(r)throw s;return this._throwIfClosed(),o},t.prototype.next=function(n){e.prototype.next.call(this,this._value=n)},t})(ye),ir={now:function(){return(ir.delegate||Date).now()},delegate:void 0},en=(function(e){Ye(t,e);function t(n,r,s){n===void 0&&(n=1/0),r===void 0&&(r=1/0),s===void 0&&(s=ir);var o=e.call(this)||this;return o._bufferSize=n,o._windowTime=r,o._timestampProvider=s,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=r===1/0,o._bufferSize=Math.max(1,n),o._windowTime=Math.max(1,r),o}return t.prototype.next=function(n){var r=this,s=r.isStopped,o=r._buffer,a=r._infiniteTimeWindow,i=r._timestampProvider,l=r._windowTime;s||(o.push(n),!a&&o.push(i.now()+l)),this._trimBuffer(),e.prototype.next.call(this,n)},t.prototype._subscribe=function(n){this._throwIfClosed(),this._trimBuffer();for(var r=this._innerSubscribe(n),s=this,o=s._infiniteTimeWindow,a=s._buffer,i=a.slice(),l=0;l<i.length&&!n.closed;l+=o?1:2)n.next(i[l]);return this._checkFinalizedStatuses(n),r},t.prototype._trimBuffer=function(){var n=this,r=n._bufferSize,s=n._timestampProvider,o=n._buffer,a=n._infiniteTimeWindow,i=(a?1:2)*r;if(r<1/0&&i<o.length&&o.splice(0,o.length-i),!a){for(var l=s.now(),c=0,u=1;u<o.length&&o[u]<=l;u+=2)c=u;c&&o.splice(0,c+1)}},t})(ye),Sc=(function(e){Ye(t,e);function t(n,r){return e.call(this)||this}return t.prototype.schedule=function(n,r){return this},t})(_t),Es={setInterval:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setInterval.apply(void 0,He([e,t],Te(n)))},clearInterval:function(e){return clearInterval(e)},delegate:void 0},Ic=(function(e){Ye(t,e);function t(n,r){var s=e.call(this,n,r)||this;return s.scheduler=n,s.work=r,s.pending=!1,s}return t.prototype.schedule=function(n,r){var s;if(r===void 0&&(r=0),this.closed)return this;this.state=n;var o=this.id,a=this.scheduler;return o!=null&&(this.id=this.recycleAsyncId(a,o,r)),this.pending=!0,this.delay=r,this.id=(s=this.id)!==null&&s!==void 0?s:this.requestAsyncId(a,this.id,r),this},t.prototype.requestAsyncId=function(n,r,s){return s===void 0&&(s=0),Es.setInterval(n.flush.bind(n,this),s)},t.prototype.recycleAsyncId=function(n,r,s){if(s===void 0&&(s=0),s!=null&&this.delay===s&&this.pending===!1)return r;r!=null&&Es.clearInterval(r)},t.prototype.execute=function(n,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var s=this._execute(n,r);if(s)return s;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(n,r){var s=!1,o;try{this.work(n)}catch(a){s=!0,o=a||new Error("Scheduled action threw falsy error")}if(s)return this.unsubscribe(),o},t.prototype.unsubscribe=function(){if(!this.closed){var n=this,r=n.id,s=n.scheduler,o=s.actions;this.work=this.state=this.scheduler=null,this.pending=!1,yn(o,this),r!=null&&(this.id=this.recycleAsyncId(s,r,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},t})(Sc),ks=(function(){function e(t,n){n===void 0&&(n=e.now),this.schedulerActionCtor=t,this.now=n}return e.prototype.schedule=function(t,n,r){return n===void 0&&(n=0),new this.schedulerActionCtor(this,t).schedule(r,n)},e.now=ir.now,e})(),Bc=(function(e){Ye(t,e);function t(n,r){r===void 0&&(r=ks.now);var s=e.call(this,n,r)||this;return s.actions=[],s._active=!1,s}return t.prototype.flush=function(n){var r=this.actions;if(this._active){r.push(n);return}var s;this._active=!0;do if(s=n.execute(n.state,n.delay))break;while(n=r.shift());if(this._active=!1,s){for(;n=r.shift();)n.unsubscribe();throw s}},t})(ks),xs=new Bc(Ic),Ac=xs,Xe=new D(function(e){return e.complete()});function Oc(e){return e&&Q(e.schedule)}function ar(e){return e[e.length-1]}function cr(e){return Q(ar(e))?e.pop():void 0}function tn(e){return Oc(ar(e))?e.pop():void 0}function Cc(e,t){return typeof ar(e)=="number"?e.pop():t}var Ss=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function Is(e){return Q(e?.then)}function Bs(e){return Q(e[or])}function As(e){return Symbol.asyncIterator&&Q(e?.[Symbol.asyncIterator])}function Os(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function _c(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Cs=_c();function _s(e){return Q(e?.[Cs])}function Rs(e){return hc(this,arguments,function(){var n,r,s,o;return ps(this,function(a){switch(a.label){case 0:n=e.getReader(),a.label=1;case 1:a.trys.push([1,,9,10]),a.label=2;case 2:return[4,Ft(n.read())];case 3:return r=a.sent(),s=r.value,o=r.done,o?[4,Ft(void 0)]:[3,5];case 4:return[2,a.sent()];case 5:return[4,Ft(s)];case 6:return[4,a.sent()];case 7:return a.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}})})}function Ts(e){return Q(e?.getReader)}function le(e){if(e instanceof D)return e;if(e!=null){if(Bs(e))return Rc(e);if(Ss(e))return Tc(e);if(Is(e))return Hc(e);if(As(e))return Hs(e);if(_s(e))return Mc(e);if(Ts(e))return Uc(e)}throw Os(e)}function Rc(e){return new D(function(t){var n=e[or]();if(Q(n.subscribe))return n.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Tc(e){return new D(function(t){for(var n=0;n<e.length&&!t.closed;n++)t.next(e[n]);t.complete()})}function Hc(e){return new D(function(t){e.then(function(n){t.closed||(t.next(n),t.complete())},function(n){return t.error(n)}).then(null,ms)})}function Mc(e){return new D(function(t){var n,r;try{for(var s=Pt(e),o=s.next();!o.done;o=s.next()){var a=o.value;if(t.next(a),t.closed)return}}catch(i){n={error:i}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}t.complete()})}function Hs(e){return new D(function(t){zc(e,t).catch(function(n){return t.error(n)})})}function Uc(e){return Hs(Rs(e))}function zc(e,t){var n,r,s,o;return dc(this,void 0,void 0,function(){var a,i;return ps(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),n=pc(e),l.label=1;case 1:return[4,n.next()];case 2:if(r=l.sent(),!!r.done)return[3,4];if(a=r.value,t.next(a),t.closed)return[2];l.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return i=l.sent(),s={error:i},[3,11];case 6:return l.trys.push([6,,9,10]),r&&!r.done&&(o=n.return)?[4,o.call(n)]:[3,8];case 7:l.sent(),l.label=8;case 8:return[3,10];case 9:if(s)throw s.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function ft(e,t,n,r,s){r===void 0&&(r=0),s===void 0&&(s=!1);var o=t.schedule(function(){n(),s?e.add(this.schedule(null,r)):this.unsubscribe()},r);if(e.add(o),!s)return o}function Ms(e,t){return t===void 0&&(t=0),J(function(n,r){n.subscribe(Y(r,function(s){return ft(r,e,function(){return r.next(s)},t)},function(){return ft(r,e,function(){return r.complete()},t)},function(s){return ft(r,e,function(){return r.error(s)},t)}))})}function Us(e,t){return t===void 0&&(t=0),J(function(n,r){r.add(e.schedule(function(){return n.subscribe(r)},t))})}function Dc(e,t){return le(e).pipe(Us(t),Ms(t))}function jc(e,t){return le(e).pipe(Us(t),Ms(t))}function Lc(e,t){return new D(function(n){var r=0;return t.schedule(function(){r===e.length?n.complete():(n.next(e[r++]),n.closed||this.schedule())})})}function Vc(e,t){return new D(function(n){var r;return ft(n,t,function(){r=e[Cs](),ft(n,t,function(){var s,o,a;try{s=r.next(),o=s.value,a=s.done}catch(i){n.error(i);return}a?n.complete():n.next(o)},0,!0)}),function(){return Q(r?.return)&&r.return()}})}function zs(e,t){if(!e)throw new Error("Iterable cannot be null");return new D(function(n){ft(n,t,function(){var r=e[Symbol.asyncIterator]();ft(n,t,function(){r.next().then(function(s){s.done?n.complete():n.next(s.value)})},0,!0)})})}function Nc(e,t){return zs(Rs(e),t)}function Pc(e,t){if(e!=null){if(Bs(e))return Dc(e,t);if(Ss(e))return Lc(e,t);if(Is(e))return jc(e,t);if(As(e))return zs(e,t);if(_s(e))return Vc(e,t);if(Ts(e))return Nc(e,t)}throw Os(e)}function vt(e,t){return t?Pc(e,t):le(e)}function K(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=tn(e);return vt(e,n)}function Rt(e,t){var n=Q(e)?e:function(){return e},r=function(s){return s.error(n())};return new D(r)}var Ds=rr(function(e){return function(){e(this),this.name="EmptyError",this.message="no elements in sequence"}});function Fc(e,t){return new Promise(function(n,r){var s=!1,o;e.subscribe({next:function(a){o=a,s=!0},error:r,complete:function(){s?n(o):r(new Ds)}})})}function at(e,t){return new Promise(function(n,r){var s=new Wt({next:function(o){n(o),s.unsubscribe()},error:r,complete:function(){r(new Ds)}});e.subscribe(s)})}function Wc(e){return e instanceof Date&&!isNaN(e)}function x(e,t){return J(function(n,r){var s=0;n.subscribe(Y(r,function(o){r.next(e.call(t,o,s++))}))})}var qc=Array.isArray;function Kc(e,t){return qc(t)?e.apply(void 0,He([],Te(t))):e(t)}function js(e){return x(function(t){return Kc(e,t)})}var Gc=Array.isArray,Yc=Object.getPrototypeOf,Xc=Object.prototype,Qc=Object.keys;function Jc(e){if(e.length===1){var t=e[0];if(Gc(t))return{args:t,keys:null};if(Zc(t)){var n=Qc(t);return{args:n.map(function(r){return t[r]}),keys:n}}}return{args:e,keys:null}}function Zc(e){return e&&typeof e=="object"&&Yc(e)===Xc}function el(e,t){return e.reduce(function(n,r,s){return n[r]=t[s],n},{})}function ue(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=tn(e),r=cr(e),s=Jc(e),o=s.args,a=s.keys;if(o.length===0)return vt([],n);var i=new D(Ls(o,n,a?function(l){return el(a,l)}:Le));return r?i.pipe(js(r)):i}function Ls(e,t,n){return n===void 0&&(n=Le),function(r){Vs(t,function(){for(var s=e.length,o=new Array(s),a=s,i=s,l=function(u){Vs(t,function(){var h=vt(e[u],t),p=!1;h.subscribe(Y(r,function(v){o[u]=v,p||(p=!0,i--),i||r.next(n(o.slice()))},function(){--a||r.complete()}))},r)},c=0;c<s;c++)l(c)},r)}}function Vs(e,t,n){e?ft(n,e,t):t()}function tl(e,t,n,r,s,o,a,i){var l=[],c=0,u=0,h=!1,p=function(){h&&!l.length&&!c&&t.complete()},v=function(f){return c<r?d(f):l.push(f)},d=function(f){c++;var b=!1;le(n(f,u++)).subscribe(Y(t,function(y){t.next(y)},function(){b=!0},void 0,function(){if(b)try{c--;for(var y=function(){var m=l.shift();a||d(m)};l.length&&c<r;)y();p()}catch(m){t.error(m)}}))};return e.subscribe(Y(t,v,function(){h=!0,p()})),function(){}}function z(e,t,n){return n===void 0&&(n=1/0),Q(t)?z(function(r,s){return x(function(o,a){return t(r,o,s,a)})(le(e(r,s)))},n):(typeof t=="number"&&(n=t),J(function(r,s){return tl(r,s,e,n)}))}function $n(e){return e===void 0&&(e=1/0),z(Le,e)}function nl(){return $n(1)}function ct(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return nl()(vt(e,tn(e)))}function nn(e){return new D(function(t){le(e()).subscribe(t)})}function En(e,t,n){return e===void 0&&(e=0),n===void 0&&(n=Ac),new D(function(r){var s=Wc(e)?+e-n.now():e;s<0&&(s=0);var o=0;return n.schedule(function(){r.closed||(r.next(o++),r.complete())},s)})}function Qe(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=tn(e),r=Cc(e,1/0),s=e;return s.length?s.length===1?le(s[0]):$n(r)(vt(s,n)):Xe}var rl=new D(Ee),sl=Array.isArray;function Ns(e){return e.length===1&&sl(e[0])?e[0]:e}function Be(e,t){return J(function(n,r){var s=0;n.subscribe(Y(r,function(o){return e.call(t,o,s++)&&r.next(o)}))})}function ol(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e=Ns(e),e.length===1?le(e[0]):new D(il(e))}function il(e){return function(t){for(var n=[],r=function(o){n.push(le(e[o]).subscribe(Y(t,function(a){if(n){for(var i=0;i<n.length;i++)i!==o&&n[i].unsubscribe();n=null}t.next(a)})))},s=0;n&&!t.closed&&s<e.length;s++)r(s)}}function de(e){return J(function(t,n){var r=null,s=!1,o;r=t.subscribe(Y(n,void 0,void 0,function(a){o=le(e(a,de(e)(t))),r?(r.unsubscribe(),r=null,o.subscribe(n)):s=!0})),s&&(r.unsubscribe(),r=null,o.subscribe(n))})}function al(e,t,n,r,s){return function(o,a){var i=n,l=t,c=0;o.subscribe(Y(a,function(u){var h=c++;l=i?e(l,u,h):(i=!0,u),a.next(l)},s))}}function Ps(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=cr(e);return n?ys(Ps.apply(void 0,He([],Te(e))),js(n)):J(function(r,s){Ls(He([r],Te(Ns(e))))(s)})}function cl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Ps.apply(void 0,He([],Te(e)))}function Fs(e,t){return Q(t)?z(e,t,1):z(e,1)}function Ws(e,t){return t===void 0&&(t=xs),J(function(n,r){var s=null,o=null,a=null,i=function(){if(s){s.unsubscribe(),s=null;var c=o;o=null,r.next(c)}};function l(){var c=a+e,u=t.now();if(u<c){s=this.schedule(void 0,c-u),r.add(s);return}i()}n.subscribe(Y(r,function(c){o=c,a=t.now(),s||(s=t.schedule(l,e),r.add(s))},function(){i(),r.complete()},void 0,function(){o=s=null}))})}function te(e){return e<=0?function(){return Xe}:J(function(t,n){var r=0;t.subscribe(Y(n,function(s){++r<=e&&(n.next(s),e<=r&&n.complete())}))})}function kn(){return J(function(e,t){e.subscribe(Y(t,Ee))})}function ll(e,t){return J(function(n,r){var s=new Set;n.subscribe(Y(r,function(o){var a=e?e(o):o;s.has(a)||(s.add(a),r.next(o))})),t&&le(t).subscribe(Y(r,function(){return s.clear()},Ee))})}function he(e,t){return t===void 0&&(t=Le),e=e??ul,J(function(n,r){var s,o=!0;n.subscribe(Y(r,function(a){var i=t(a);(o||!e(s,i))&&(o=!1,s=i,r.next(a))}))})}function ul(e,t){return e===t}function qs(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(n){return ct(n,K.apply(void 0,He([],Te(e))))}}function dl(e,t){return J(function(n,r){var s=0,o=null,a=!1;n.subscribe(Y(r,function(i){o||(o=Y(r,void 0,function(){o=null,a&&r.complete()}),le(e(i,s++)).subscribe(o))},function(){a=!0,!o&&r.complete()}))})}function lr(e){return J(function(t,n){try{t.subscribe(n)}finally{n.add(e)}})}function hl(){return J(function(e,t){var n,r=!1;e.subscribe(Y(t,function(s){var o=n;n=s,r&&t.next([o,s]),r=!0}))})}function rn(e,t){return J(al(e,t,arguments.length>=2,!0))}function bt(e){e===void 0&&(e={});var t=e.connector,n=t===void 0?function(){return new ye}:t,r=e.resetOnError,s=r===void 0?!0:r,o=e.resetOnComplete,a=o===void 0?!0:o,i=e.resetOnRefCountZero,l=i===void 0?!0:i;return function(c){var u,h,p,v=0,d=!1,f=!1,b=function(){h?.unsubscribe(),h=void 0},y=function(){b(),u=p=void 0,d=f=!1},m=function(){var g=u;y(),g?.unsubscribe()};return J(function(g,w){v++,!f&&!d&&b();var E=p=p??n();w.add(function(){v--,v===0&&!f&&!d&&(h=ur(m,l))}),E.subscribe(w),!u&&v>0&&(u=new Wt({next:function($){return E.next($)},error:function($){f=!0,b(),h=ur(y,s,$),E.error($)},complete:function(){d=!0,b(),h=ur(y,a),E.complete()}}),le(g).subscribe(u))})(c)}}function ur(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(t===!0){e();return}if(t!==!1){var s=new Wt({next:function(){s.unsubscribe(),e()}});return le(t.apply(void 0,He([],Te(n)))).subscribe(s)}}function sn(e,t,n){var r,s,o,a,i=!1;return e&&typeof e=="object"?(r=e.bufferSize,a=r===void 0?1/0:r,s=e.windowTime,t=s===void 0?1/0:s,o=e.refCount,i=o===void 0?!1:o,n=e.scheduler):a=e??1/0,bt({connector:function(){return new en(a,t,n)},resetOnError:!0,resetOnComplete:!1,resetOnRefCountZero:i})}function Ks(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=tn(e);return J(function(r,s){(n?ct(e,r,n):ct(e,r)).subscribe(s)})}function Tt(e,t){return J(function(n,r){var s=null,o=0,a=!1,i=function(){return a&&!s&&r.complete()};n.subscribe(Y(r,function(l){s?.unsubscribe();var c=0,u=o++;le(e(l,u)).subscribe(s=Y(r,function(h){return r.next(t?t(l,h,u,c++):h)},function(){s=null,i()}))},function(){a=!0,i()}))})}function pl(){return Tt(Le)}function dr(e){return J(function(t,n){le(e).subscribe(Y(n,function(){return n.complete()},Ee)),!n.closed&&t.subscribe(n)})}function Ht(e,t){return t===void 0&&(t=!1),J(function(n,r){var s=0;n.subscribe(Y(r,function(o){var a=e(o,s++);(a||t)&&r.next(o),!a&&r.complete()}))})}function qt(e,t,n){var r=Q(e)||t||n?{next:e,error:t,complete:n}:e;return r?J(function(s,o){var a;(a=r.subscribe)===null||a===void 0||a.call(r);var i=!0;s.subscribe(Y(o,function(l){var c;(c=r.next)===null||c===void 0||c.call(r,l),o.next(l)},function(){var l;i=!1,(l=r.complete)===null||l===void 0||l.call(r),o.complete()},function(l){var c;i=!1,(c=r.error)===null||c===void 0||c.call(r,l),o.error(l)},function(){var l,c;i&&((l=r.unsubscribe)===null||l===void 0||l.call(r)),(c=r.finalize)===null||c===void 0||c.call(r)}))}):Le}function Gs(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=cr(e);return J(function(r,s){for(var o=e.length,a=new Array(o),i=e.map(function(){return!1}),l=!1,c=function(h){le(e[h]).subscribe(Y(s,function(p){a[h]=p,!l&&!i[h]&&(i[h]=!0,(l=i.every(Le))&&(i=null))},Ee))},u=0;u<o;u++)c(u);r.subscribe(Y(s,function(h){if(l){var p=He([h],Te(a));s.next(n?n.apply(void 0,He([],Te(p))):p)}}))})}const Ys="0123456789abcdef";function X(e){const t=new Array(e.length+1);t[0]="0x";for(let n=0;n<e.length;){const r=e[n++];t[n]=Ys[r>>4]+Ys[r&15]}return t.join("")}const hr={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15};function ee(e){const t=e.length%2,n=(e[1]==="x"?2:0)+t,r=(e.length-n)/2+t,s=new Uint8Array(r);t&&(s[0]=0|hr[e[2]]);for(let o=0;o<r;){const a=n+o*2,i=hr[e[a]],l=hr[e[a+1]];s[t+o++]=i<<4|l}return s}function mt(e,t){return Object.fromEntries(Object.entries(e).map(([n,r])=>[n,t(r,n)]))}const oe=e=>{const t=e.reduce((r,s)=>r+s.byteLength,0),n=new Uint8Array(t);for(let r=0,s=0;r<e.length;r++){const o=e[r];n.set(o,s),s+=o.byteLength}return n},N=Function.prototype;let Xs=class extends Error{constructor(){super("Abort Error"),this.name="AbortError"}};var fl=Object.defineProperty,vl=(e,t,n)=>t in e?fl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qs=(e,t,n)=>vl(e,typeof t!="symbol"?t+"":t,n);let Js=class extends Error{constructor(t){super(t.message),Qs(this,"code"),Qs(this,"data"),this.code=t.code,this.data=t.data,this.name="RpcError"}};const Zs=e=>!("method"in e),eo=()=>{const e=new Map;return{has:e.has.bind(e),subscribe(t,n){e.set(t,n)},unsubscribe(t){e.delete(t)},next(t,n){e.get(t)?.next(n)},error(t,n){const r=e.get(t);r&&(e.delete(t),r.error(n))},errorAll(t){const n=[...e.values()];e.clear(),n.forEach(r=>{r.error(t)})}}};let pr=class extends Error{constructor(){super("Client destroyed"),this.name="DestroyedError"}},bl=1;const fr=(e,t)=>{let n=bl++;const r=new Map,s=eo();let o=null;const a=(u,h,p)=>{o.send({jsonrpc:"2.0",id:u,method:h,params:p})};function i(u){if(Zs(u)){const{id:h}=u,p=r.get(h);return p?(r.delete(h),"error"in u?p.onError(new Js(u.error)):p.onSuccess(u.result,(v,d)=>{const f=v;return s.subscribe(f,d),()=>{s.unsubscribe(f)}})):void 0}if(u.id===void 0){const{params:h}=u,{subscription:p,result:v,error:d}=h;p&&s.has(p)&&("result"in h||d)?d?s.error(p,new Js(d)):s.next(p,v):t?.(u)}else console.warn("Error parsing incomming message: "+JSON.stringify(u))}o=e(i);const l=()=>{o?.disconnect(),o=null,s.errorAll(new pr),r.forEach(u=>u.onError(new pr)),r.clear()};let c=1;return{request:(u,h,p)=>{if(!o)throw new Error("Not connected");const v=`${n}-${c++}`;return p&&r.set(v,p),a(v,u,h),()=>{r.delete(v)}},disconnect:l}};var ml=Object.defineProperty,yl=(e,t,n)=>t in e?ml(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,on=(e,t,n)=>yl(e,t+"",n);const to=class rc extends Error{constructor(){super("ChainHead stopped"),this.name=rc.errorName}};on(to,"errorName","StopError");let no=to;const ro=class sc extends Error{constructor(){super("ChainHead disjointed"),this.name=sc.errorName}};on(ro,"errorName","DisjointError");let xn=ro;const so=class oc extends Error{constructor(){super("ChainHead operations limit reached"),this.name=oc.errorName}};on(so,"errorName","OperationLimitError");let Sn=so;const oo=class ic extends Error{constructor(t){super(t),this.name=ic.errorName}};on(oo,"errorName","OperationError");let io=oo;const ao=class ac extends Error{constructor(){super("ChainHead operation inaccessible"),this.name=ac.errorName}};on(ao,"errorName","OperationInaccessibleError");let In=ao;const Me={body:"",call:"",continue:"",follow:"",header:"",stopOperation:"",storage:"",unfollow:"",unpin:"",followEvent:""},Bn={chainName:"",genesisHash:"",properties:""},vr={broadcast:"",stop:""};Object.entries({chainHead:Me,chainSpec:Bn,transaction:vr}).forEach(([e,t])=>{Object.keys(t).forEach(n=>{t[n]=`${e}_v1_${n}`})});var gl=Object.defineProperty,wl=(e,t,n)=>t in e?gl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,br=(e,t,n)=>wl(e,t+"",n);const co=class cc extends Error{constructor(t){super(`Invalid BlockHash: ${t}`),this.name=cc.errorName}};br(co,"errorName","BlockHashNotFoundError");let lo=co;const uo=class lc extends Error{constructor(t){super(`Storage Error: ${t}`),this.name=lc.errorName}};br(uo,"errorName","StorageError");let $l=uo;const ho=class uc extends Error{constructor(t){super(`Call Error: ${t}`),this.name=uc.errorName}};br(ho,"errorName","CallError");let El=ho;const Kt=()=>{},kl=e=>(t,n)=>{let r=!1,s=()=>{r=!0};return e(vr.broadcast,[t],{onSuccess:o=>{o!==null?(s=()=>{e(vr.stop,[o]),s=Kt},r&&s()):r||n(new Error("Max # of broadcasted transactions has been reached"))},onError:n}),()=>{s()}};function xl(){let e=()=>{},t=()=>{};return{promise:new Promise((n,r)=>{e=n,t=r}),res:e,rej:t}}const Gt=e=>(...t)=>new Promise((n,r)=>{let s=N;const[o,a]=t[t.length-1]instanceof AbortSignal?[t.slice(0,t.length-1),t[t.length-1]]:[t],i=()=>{s(),r(new Xs)};a?.addEventListener("abort",i,{once:!0});const l=c=>u=>{s=N,a?.removeEventListener("abort",i),c(u)};s=e(l(n),l(r),...o)}),po=(e,t)=>n=>Gt((r,s,...o)=>{let a=!0,i=()=>{a=!1};const[l,c]=t(...o);return n(e,l,{onSuccess:(u,h)=>{if(u.result==="limitReached")return s(new Sn);const{operationId:p}=u,v=()=>{n(Me.stopOperation,[p])};if(!a)return v();let d=Kt;const f=y=>{a=!1,d(),r(y)},b=y=>{a=!1,d(),s(y)};d=h(p,{next:y=>{const m=y;m.event==="operationError"?s(new io(m.error)):m.event==="operationInaccessible"?s(new In):c(y,f,b)},error:b}),i=()=>{a&&(d(),v())}},onError:s}),()=>{i()}}),Sl=po(Me.body,e=>[[e],(t,n)=>{n(t.value)}]),Il=po(Me.call,(e,t,n)=>[[e,t,n],(r,s)=>{s(r.output)}]),Bl=e=>t=>new Promise((n,r)=>{e(Me.header,[t],{onSuccess:n,onError:r})}),fo=e=>(t,n,r,s,o,a,i)=>{if(n.length===0)return a(),N;let l=!0,c=()=>{l=!1};return e(Me.storage,[t,n,r],{onSuccess:(u,h)=>{if(u.result==="limitReached"||u.discardedItems===n.length)return o(new Sn);const{operationId:p}=u,v=()=>{e(Me.stopOperation,[p])};if(!l)return v();const d=h(u.operationId,{next:y=>{switch(y.event){case"operationStorageItems":{s(y.items);break}case"operationStorageDone":{b();break}case"operationError":{f(new io(y.error));break}case"operationInaccessible":{f(new In);break}default:e(Me.continue,[y.operationId])}},error:o});c=()=>{d(),e(Me.stopOperation,[u.operationId])};const f=y=>{c=N,d(),o(y)},b=()=>{c=N,d(),a()};i(u.discardedItems)},onError:o}),()=>{c()}},Al=e=>{const t=fo(e);return Gt((n,r,s,o,a,i)=>{const l=o.startsWith("descendants");let c=l?[]:null;const u=t(s,[{key:a,type:o}],i??null,l?h=>{c.push(h)}:h=>{c=h[0]?.[o]},r,()=>{try{n(l?c.flat():c)}catch(h){r(h)}},h=>{h>0&&(u(),r(new Sn))});return u})},Ol=e=>t=>t.length>0?new Promise((n,r)=>{e(Me.unpin,[t],{onSuccess(){n()},onError:r})}):Promise.resolve();function Cl(e){return e.operationId!==void 0}function _l(e){return(t,n,r)=>{const s=eo(),o=new Set,a=xl();let i=a.promise,l=Kt;const c=d=>{e(Me.unfollow,[d])},u=d=>{l(),i!==null&&(d&&(i instanceof Promise?i.then(f=>{typeof f=="string"&&c(f)}):c(i)),i=null,o.forEach(f=>{f()}),o.clear(),s.errorAll(new xn))},h=d=>{if(Cl(d))return s.next(d.operationId,d);switch(d.event){case"stop":return r(new no),u(!1);case"initialized":case"newBlock":case"bestBlockChanged":case"finalized":const{event:f,...b}=d;return n({type:f,...b})}},p=d=>{r(d),u(!(d instanceof pr))};e(Me.follow,[t],{onSuccess:(d,f)=>{i instanceof Promise&&(i=d,l=f(d,{next:h,error:p})),a.res(d)},onError:d=>{i=null,a.res(d),r(d)}});const v=(d,f,b)=>{const y=()=>{b?.onError(new xn)};if(i===null)return y(),Kt;const m=w=>{if(!b)return e(d,[w,...f]);o.add(y);const E=(k,S)=>i===null?(S.error(new xn),Kt):(s.subscribe(k,S),()=>{s.unsubscribe(k)}),$=e(d,[w,...f],{onSuccess:k=>{o.delete(y),b.onSuccess(k,E)},onError:k=>{o.delete(y),b.onError(k)}});return()=>{o.delete(y),$()}};if(typeof i=="string")return m(i);let g=Kt;return i.then(w=>{if(w instanceof Error)return y();i&&(g=m(w))}),()=>{g()}};return{unfollow(){u(!0)},body:Sl(v),call:Il(v),header:Bl(v),storage:Al(v),storageSubscription:fo(v),unpin:Ol(v),_request:v}}}const Rl=e=>{const t=Gt((r,s,o,a)=>e(o,a,{onSuccess:r,onError:s}));let n=null;return async()=>n||(n=Promise.all([t(Bn.chainName,[]),t(Bn.genesisHash,[]),t(Bn.properties,[])]).then(([r,s,o])=>({name:r,genesisHash:s,properties:o})))},Tl=e=>(t,n,r,s,o,a)=>{if(n.length===0)return a(),N;let i=!0,l=()=>{i=!1};return e("storage",[t,n,r],{onSuccess:(c,u)=>{const h=()=>{e("stopStorage",[c])};if(!i)return h();const p=u(c,{next:b=>{const{event:y}=b;if(y==="storage"){const{event:m,...g}=b;s(g)}else y==="storageDone"?f():d(new $l(b.error))},error:o}),v=()=>{l=N,p()};l=()=>{v(),h()};const d=b=>{v(),o(b)},f=()=>{v(),a()}},onError:o}),()=>{l()}},Hl=e=>Gt((t,n,r,s,o,a)=>{const i=s.startsWith("descendants");let l=i?[]:null;const c=i?l.push.bind(l):({[s]:u})=>{l=u};return e(r,[{key:o,type:s}],a,c,u=>{n(u),l=null},()=>{t(l),l=null})}),vo=()=>e=>e,bo=()=>(e,t)=>{if(e===null)throw new lo(t);return e},Ml=e=>{const t=(u,...h)=>e(`archive_v1_${u}`,...h),n=u=>h=>Gt((p,v,...d)=>t(u,d,{onSuccess:f=>{try{p(h(f,...d))}catch(b){v(b)}},onError:v})),r=n("header")(bo()),s=n("body")(bo()),o=Tl(t),a=Hl(o),i=n("call")((u,h)=>{if(!u)throw new lo(h);if(!u.success)throw new El(u.error);return u.value}),l=n("finalizedHeight")(vo()),c=n("hashByHeight")(vo());return{header:r,body:s,storageSubscription:o,storage:a,call:i,finalizedHeight:l,hashByHeight:c}},Ul=e=>{const{request:t,disconnect:n}=fr(e);return{archive:Ml(t),chainHead:_l(t),transaction:kl(t),getChainSpecData:Rl(t),destroy:n,request:Gt((r,s,o,a)=>t(o,a,{onSuccess:r,onError:s})),_request:t}};var zl=Object.defineProperty,Dl=(e,t,n)=>t in e?zl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mo=(e,t,n)=>Dl(e,typeof t!="symbol"?t+"":t,n);let jl=class{constructor(){mo(this,"first"),mo(this,"last")}getRemoveFn(t){return()=>{t.prev?t.prev.next=t.next:this.first=t.next,t.next?t.next.prev=t.prev:this.last=t.prev,delete t.prev,delete t.next}}push(t){const n={value:t};return this.last===void 0?this.last=this.first=n:(this.last.next=n,n.prev=this.last,this.last=n),this.getRemoveFn(n)}unshift(t){return this.first={value:t,next:this.first},this.first.next&&(this.first.next.prev=this.first),this.last||(this.last=this.first),this.getRemoveFn(this.first)}pop(){const t=this.first?.value;return this.first&&(this.first=this.first.next,this.first?(delete this.first.prev?.next,delete this.first.prev):this.last=void 0),t}isEmpty(){return!this.first}};const Ll=()=>{const e=new Map,t=(h,p)=>{e.set(h,()=>{e.delete(h),p()})},n=h=>{e.get(h)?.()},r=new jl,s=r.unshift.bind(r),o=r.push.bind(r),a=(h,p)=>{const v=p?s:o;t(h.source$,v(h))},i=()=>{const h=r.pop();h&&(e.delete(h.source$),l(h))},l=h=>{const{source$:p,observer:v}=h;let d=!1;const f=p.subscribe({next(b){v.next(b)},error(b){(d=b instanceof Error&&b.name===Sn.errorName)?a(h,!0):v.error(b)},complete(){v.complete()}});f.closed?d||i():t(p,()=>{f.unsubscribe(),i()})},c=(h=!1)=>p=>new D(v=>{const d={observer:v,source$:p};return r.isEmpty()?l(d):a(d,h),()=>{n(p)}}),u=c();return{withRecovery:c,withRecoveryFn:h=>(...p)=>u(h(...p))}};let Je=class extends Error{constructor(t,n){super(`Block ${t} is not pinned (${n})`),this.name="BlockNotPinnedError"}};const mr=e=>{const t=e.pipe(de(n=>n instanceof Error&&n.name===In.errorName?En(750).pipe(Fs(()=>t)):Rt(()=>n)));return t},Vl=new Set(["best","finalized",null]),Nl=(e,t,n)=>r=>(s,...o)=>{if(!Vl.has(s))return mr(r(s,...o)).pipe(n(s));const a=(s==="best"?t:e).pipe(te(1),z(i=>r(i,...o).pipe(n(i))),de(i=>i instanceof Je?a:Rt(()=>i)));return mr(a)},Mt=e=>(...t)=>new D(n=>{let r=new AbortController;return e(...t,r.signal).then(s=>{n.next(s),n.complete()},s=>{n.error(s)}),()=>{n.unsubscribe(),r.abort(),r=void 0}}),Pl=e=>t=>(...n)=>e()[t](...n);var ve=(e=>(e[e.Initializing=0]="Initializing",e[e.Ready=1]="Ready",e[e.RecoveringInit=2]="RecoveringInit",e[e.RecoveringFin=3]="RecoveringFin",e))(ve||{});function An(e,t,n){return(r,...s)=>{let o;const a=()=>new Je(r,n),i=t(r,...s).pipe(x(c=>({type:"val",value:c})),qs({type:"end"})),l=e.pipe(Ht(c=>!c.blocks.has(r)),x(c=>{if(c.blocks.get(c.finalized).number>=o.number)throw a()}),kn());return e.pipe(x(c=>c.state.type===ve.Ready),he(),Tt(c=>c?(o||(o=e.state.blocks.get(r)),o?ct(l,i):Rt(a)):rl),Ht(c=>c.type==="val"),x(c=>c.value))}}const Fl=(e,t)=>{const n=(r,s,o,a)=>new D(i=>e().storageSubscription(r,s,o??null,l=>{i.next(l)},l=>{i.error(l)},()=>{i.complete()},l=>{l>0&&i.next(n(r,s.slice(-l),o,!0))})).pipe($n(),t(a));return n};var Wl=Object.defineProperty,ql=(e,t,n)=>t in e?Wl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yo=(e,t,n)=>(ql(e,typeof t!="symbol"?t+"":t,n),n),yr={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15};function Kl(e){const t=e.length%2,n=(e[1]==="x"?2:0)+t,r=(e.length-n)/2+t,s=new Uint8Array(r);t&&(s[0]=0|yr[e[2]]);for(let o=0;o<r;){const a=n+o*2,i=yr[e[a]],l=yr[e[a+1]];s[t+o++]=i<<4|l}return s}var go=class extends Uint8Array{constructor(e){super(e),yo(this,"i",0),yo(this,"v"),this.v=new DataView(e)}},Ue=e=>t=>e(t instanceof go?t:new go(t instanceof Uint8Array?t.buffer:typeof t=="string"?Kl(t).buffer:t)),Ze=e=>{const t=e.length;let n=0;for(let s=0;s<t;s++)n+=e[s].length;const r=new Uint8Array(n);for(let s=0,o=0;s<t;s++){const a=e[s];r.set(a,o),o+=a.byteLength}return r};function On(e,t){const n=Object.keys(e),r=n.length,s={};for(let o=0;o<r;o++){const a=n[o];s[a]=t(e[a],a)}return s}var lt=Ue,G=(e,t)=>{const n=[e,t];return n.enc=e,n.dec=t,n},Cn=(e,t)=>n=>e(t(n)),_n=(e,t)=>n=>t(e(n)),Ve=([e,t],n,r)=>G(Cn(e,n),_n(t,r));function Gl(e,t){return Ue(n=>{const r=n.v[t](n.i,!0);return n.i+=e,r})}function Yl(e,t){return n=>{const r=new Uint8Array(e);return new DataView(r.buffer)[t](0,n,!0),r}}function yt(e,t,n){return G(Yl(e,n),Gl(e,t))}var P=yt(1,"getUint8","setUint8"),et=yt(2,"getUint16","setUint16"),Ne=yt(4,"getUint32","setUint32"),an=yt(8,"getBigUint64","setBigUint64"),Xl=yt(1,"getInt8","setInt8"),Ql=yt(2,"getInt16","setInt16"),Jl=yt(4,"getInt32","setInt32"),Zl=yt(8,"getBigInt64","setBigInt64"),wo=e=>{const t=new Uint8Array(16),n=new DataView(t.buffer);return n.setBigInt64(0,e,!0),n.setBigInt64(8,e>>64n,!0),t},$o=e=>Ue(t=>{const{v:n,i:r}=t,s=n.getBigUint64(r,!0),o=n[e](r+8,!0);return t.i+=16,o<<64n|s}),Eo=G(wo,$o("getBigUint64")),eu=G(wo,$o("getBigInt64")),ko=e=>{const t=new Uint8Array(32),n=new DataView(t.buffer);return n.setBigInt64(0,e,!0),n.setBigInt64(8,e>>64n,!0),n.setBigInt64(16,e>>128n,!0),n.setBigInt64(24,e>>192n,!0),t},xo=e=>Ue(t=>{let n=t.v.getBigUint64(t.i,!0);return t.i+=8,n|=t.v.getBigUint64(t.i,!0)<<64n,t.i+=8,n|=t.v.getBigUint64(t.i,!0)<<128n,t.i+=8,n|=t.v[e](t.i,!0)<<192n,t.i+=8,n}),tu=G(ko,xo("getBigUint64")),nu=G(ko,xo("getBigInt64")),ru=Ve(P,e=>e?1:0,Boolean),su=[P[1],et[1],Ne[1]],ou=Ue(e=>{const t=e[e.i],n=t&3;if(n<3)return su[n](e)>>>2;const r=(t>>>2)+4;e.i++;let s=0n;const o=r/8|0;let a=0n;for(let l=0;l<o;l++)s=an[1](e)<<a|s,a+=64n;let i=r%8;return i>3&&(s=BigInt(Ne[1](e))<<a|s,a+=32n,i-=4),i>1&&(s=BigInt(et[1](e))<<a|s,a+=16n,i-=2),i&&(s=BigInt(P[1](e))<<a|s),s}),iu=1n<<56n,au=1<<24,cu=256,lu=4294967295n,uu=64,du=16384,hu=1<<30,pu=e=>{if(e<0)throw new Error(`Wrong compact input (${e})`);const t=Number(e)<<2;if(e<uu)return P[0](t);if(e<du)return et[0](t|1);if(e<hu)return Ne[0](t|2);let n=[new Uint8Array(1)],r=BigInt(e);for(;r>=iu;)n.push(an[0](r)),r>>=64n;r>=au&&(n.push(Ne[0](Number(r&lu))),r>>=32n);let s=Number(r);s>=cu&&(n.push(et[0](s)),s>>=16),s&&n.push(P[0](s));const o=Ze(n);return o[0]=o.length-5<<2|3,o},pe=G(pu,ou),fu=new TextEncoder,vu=e=>{const t=fu.encode(e);return Ze([pe.enc(t.length),t])},bu=new TextDecoder,mu=Ue(e=>{let t=pe.dec(e);const n=new DataView(e.buffer,e.i,t);return e.i+=t,bu.decode(n)}),W=G(vu,mu),yu=()=>{},gu=new Uint8Array(0),M=G(()=>gu,yu),So=e=>e===void 0?t=>Ze([pe.enc(t.length),t]):t=>t.length===e?t:t.slice(0,e),Io=e=>Ue(t=>{const n=e===void 0?pe.dec(t):e!==1/0?e:t.byteLength-t.i,r=new Uint8Array(t.buffer.slice(t.i,t.i+n));return t.i+=n,r}),ne=e=>G(So(e),Io(e));ne.enc=So,ne.dec=Io;var Bo=(e,t)=>{const n=Object.keys(e),r=new Map(t?.map((o,a)=>[n[a],o])??n.map((o,a)=>[o,a])),s=o=>r.get(o);return({tag:o,value:a})=>Ze([P.enc(s(o)),e[o](a)])},Ao=(e,t)=>{const n=Object.keys(e),r=new Map(t?.map((s,o)=>[s,n[o]])??n.map((s,o)=>[o,s]));return Ue(s=>{const o=P.dec(s),a=r.get(o),i=e[a];return{tag:a,value:i(s)}})},ke=(e,...t)=>G(Bo(On(e,([n])=>n),...t),Ao(On(e,([,n])=>n),...t));ke.enc=Bo,ke.dec=Ao;var Oo=e=>Ue(t=>P[1](t)>0?e(t):void 0),Co=e=>t=>{const n=new Uint8Array(1);return t===void 0?n:(n[0]=1,Ze([n,e(t)]))},xe=e=>G(Co(e[0]),Oo(e[1]));xe.enc=Co,xe.dec=Oo;var _o=(e,t)=>Ue(n=>{const r=P[1](n)===0,o=(r?e:t)(n);return{success:r,value:o}}),Ro=(e,t)=>({success:n,value:r})=>Ze([P[0](n?0:1),(n?e:t)(r)]),cn=(e,t)=>G(Ro(e[0],t[0]),_o(e[1],t[1]));cn.dec=_o,cn.enc=Ro;var To=(...e)=>Ue(t=>e.map(n=>n(t))),Ho=(...e)=>t=>Ze(e.map((n,r)=>n(t[r]))),ze=(...e)=>G(Ho(...e.map(([t])=>t)),To(...e.map(([,t])=>t)));ze.enc=Ho,ze.dec=To;var Mo=e=>{const t=Object.keys(e);return Cn(ze.enc(...Object.values(e)),n=>t.map(r=>n[r]))},Uo=e=>{const t=Object.keys(e);return _n(ze.dec(...Object.values(e)),n=>Object.fromEntries(n.map((r,s)=>[t[s],r])))},U=e=>G(Mo(On(e,t=>t[0])),Uo(On(e,t=>t[1])));U.enc=Mo,U.dec=Uo;var zo=(e,t)=>t>=0?n=>Ze(n.map(e)):n=>Ze([pe.enc(n.length),Ze(n.map(e))]),Do=(e,t)=>Ue(n=>{const r=t>=0?t:pe.dec(n),s=new Array(r);for(let o=0;o<r;o++)s[o]=e(n);return s}),j=(e,t)=>G(zo(e[0],t),Do(e[1],t));j.enc=zo,j.dec=Do;/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function wu(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function jo(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(n=>typeof n=="string"):t.every(n=>Number.isSafeInteger(n)):!1}function gr(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function Lo(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function wr(e){if(!Array.isArray(e))throw new Error("array expected")}function Vo(e,t){if(!jo(!0,t))throw new Error(`${e}: array of strings expected`)}function $u(e,t){if(!jo(!1,t))throw new Error(`${e}: array of numbers expected`)}function Eu(...e){const t=o=>o,n=(o,a)=>i=>o(a(i)),r=e.map(o=>o.encode).reduceRight(n,t),s=e.map(o=>o.decode).reduce(n,t);return{encode:r,decode:s}}function ku(e){const t=typeof e=="string"?e.split(""):e,n=t.length;Vo("alphabet",t);const r=new Map(t.map((s,o)=>[s,o]));return{encode:s=>(wr(s),s.map(o=>{if(!Number.isSafeInteger(o)||o<0||o>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${o}". Allowed: ${e}`);return t[o]})),decode:s=>(wr(s),s.map(o=>{gr("alphabet.decode",o);const a=r.get(o);if(a===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${e}`);return a}))}}function xu(e=""){return gr("join",e),{encode:t=>(Vo("join.decode",t),t.join(e)),decode:t=>(gr("join.decode",t),t.split(e))}}function No(e,t,n){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(wr(e),!e.length)return[];let r=0;const s=[],o=Array.from(e,i=>{if(Lo(i),i<0||i>=t)throw new Error(`invalid integer: ${i}`);return i}),a=o.length;for(;;){let i=0,l=!0;for(let c=r;c<a;c++){const u=o[c],h=t*i,p=h+u;if(!Number.isSafeInteger(p)||h/t!==i||p-u!==h)throw new Error("convertRadix: carry overflow");const v=p/n;i=p%n;const d=Math.floor(v);if(o[c]=d,!Number.isSafeInteger(d)||d*n+i!==p)throw new Error("convertRadix: carry overflow");if(l)d?l=!1:r=c;else continue}if(s.push(i),l)break}for(let i=0;i<e.length-1&&e[i]===0;i++)s.push(0);return s.reverse()}function Su(e){Lo(e);const t=2**8;return{encode:n=>{if(!wu(n))throw new Error("radix.encode input should be Uint8Array");return No(Array.from(n),t,e)},decode:n=>($u("radix.decode",n),Uint8Array.from(No(n,e,t)))}}const Po=(e=>Eu(Su(58),ku(e),xu("")))("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Iu(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Yt(e,t=""){if(!Number.isSafeInteger(e)||e<0){const n=t&&`"${t}" `;throw new Error(`${n}expected integer >= 0, got ${e}`)}}function De(e,t,n=""){const r=Iu(e),s=e?.length,o=t!==void 0;if(!r||o&&s!==t){const a=n&&`"${n}" `,i=o?` of length ${t}`:"",l=r?`length=${s}`:`type=${typeof e}`;throw new Error(a+"expected Uint8Array"+i+", got "+l)}return e}function ln(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function $r(e,t){De(e,void 0,"digestInto() output");const n=t.outputLen;if(e.length<n)throw new Error('"digestInto() output" expected to be of length >='+n)}function Bu(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function Ut(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function gt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Rn(e,t){return e<<32-t|e>>>t}const Fo=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Wo(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const ut=Fo?e=>e:e=>Wo(e);function Au(e){for(let t=0;t<e.length;t++)e[t]=Wo(e[t]);return e}const ge=Fo?e=>e:Au;function Er(e,t={}){const n=(s,o)=>e(o).update(s).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.create=s=>e(s),Object.assign(n,t),Object.freeze(n)}const Ou=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]);function wt(e,t,n,r,s){return e=e+t+s|0,r=Rn(r^e,16),n=n+r|0,t=Rn(t^n,12),{a:e,b:t,c:n,d:r}}function $t(e,t,n,r,s){return e=e+t+s|0,r=Rn(r^e,8),n=n+r|0,t=Rn(t^n,7),{a:e,b:t,c:n,d:r}}const Cu=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Tn=BigInt(2**32-1),qo=BigInt(32);function Hn(e,t=!1){return t?{h:Number(e&Tn),l:Number(e>>qo&Tn)}:{h:Number(e>>qo&Tn)|0,l:Number(e&Tn)|0}}function _u(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let o=0;o<n;o++){const{h:a,l:i}=Hn(e[o],t);[r[o],s[o]]=[a,i]}return[r,s]}const Ko=(e,t,n)=>e>>>n|t<<32-n,Go=(e,t,n)=>e<<32-n|t>>>n,Ru=(e,t,n)=>e<<64-n|t>>>n-32,Tu=(e,t,n)=>e>>>n-32|t<<64-n,Hu=(e,t)=>t,Mu=(e,t)=>e,Uu=(e,t,n)=>e<<n|t>>>32-n,zu=(e,t,n)=>t<<n|e>>>32-n,Du=(e,t,n)=>t<<n-32|e>>>64-n,ju=(e,t,n)=>e<<n-32|t>>>64-n;function Yo(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const Xo=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Qo=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,se=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),O=new Uint32Array(32);function Et(e,t,n,r,s,o){const a=s[o],i=s[o+1];let l=O[2*e],c=O[2*e+1],u=O[2*t],h=O[2*t+1],p=O[2*n],v=O[2*n+1],d=O[2*r],f=O[2*r+1],b=Xo(l,u,a);c=Qo(b,c,h,i),l=b|0,{Dh:f,Dl:d}={Dh:f^c,Dl:d^l},{Dh:f,Dl:d}={Dh:Hu(f,d),Dl:Mu(f)},{h:v,l:p}=Yo(v,p,f,d),{Bh:h,Bl:u}={Bh:h^v,Bl:u^p},{Bh:h,Bl:u}={Bh:Ko(h,u,24),Bl:Go(h,u,24)},O[2*e]=l,O[2*e+1]=c,O[2*t]=u,O[2*t+1]=h,O[2*n]=p,O[2*n+1]=v,O[2*r]=d,O[2*r+1]=f}function kt(e,t,n,r,s,o){const a=s[o],i=s[o+1];let l=O[2*e],c=O[2*e+1],u=O[2*t],h=O[2*t+1],p=O[2*n],v=O[2*n+1],d=O[2*r],f=O[2*r+1],b=Xo(l,u,a);c=Qo(b,c,h,i),l=b|0,{Dh:f,Dl:d}={Dh:f^c,Dl:d^l},{Dh:f,Dl:d}={Dh:Ko(f,d,16),Dl:Go(f,d,16)},{h:v,l:p}=Yo(v,p,f,d),{Bh:h,Bl:u}={Bh:h^v,Bl:u^p},{Bh:h,Bl:u}={Bh:Ru(h,u,63),Bl:Tu(h,u,63)},O[2*e]=l,O[2*e+1]=c,O[2*t]=u,O[2*t+1]=h,O[2*n]=p,O[2*n+1]=v,O[2*r]=d,O[2*r+1]=f}function Lu(e,t={},n,r,s){if(Yt(n),e<0||e>n)throw new Error("outputLen bigger than keyLen");const{key:o,salt:a,personalization:i}=t;if(o!==void 0&&(o.length<1||o.length>n))throw new Error('"key" expected to be undefined or of length=1..'+n);a!==void 0&&De(a,r,"salt"),i!==void 0&&De(i,s,"personalization")}class Jo{buffer;buffer32;finished=!1;destroyed=!1;length=0;pos=0;blockLen;outputLen;constructor(t,n){Yt(t),Yt(n),this.blockLen=t,this.outputLen=n,this.buffer=new Uint8Array(t),this.buffer32=Ut(this.buffer)}update(t){ln(this),De(t);const{blockLen:n,buffer:r,buffer32:s}=this,o=t.length,a=t.byteOffset,i=t.buffer;for(let l=0;l<o;){this.pos===n&&(ge(s),this.compress(s,0,!1),ge(s),this.pos=0);const c=Math.min(n-this.pos,o-l),u=a+l;if(c===n&&!(u%4)&&l+c<o){const h=new Uint32Array(i,u,Math.floor((o-l)/4));ge(h);for(let p=0;l+n<o;p+=s.length,l+=n)this.length+=n,this.compress(h,p,!1);ge(h);continue}r.set(t.subarray(l,l+c),this.pos),this.pos+=c,this.length+=c,l+=c}return this}digestInto(t){ln(this),$r(t,this);const{pos:n,buffer32:r}=this;this.finished=!0,gt(this.buffer.subarray(n)),ge(r),this.compress(r,0,!0),ge(r);const s=Ut(t);this.get().forEach((o,a)=>s[a]=ut(o))}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){const{buffer:n,length:r,finished:s,destroyed:o,outputLen:a,pos:i}=this;return t||=new this.constructor({dkLen:a}),t.set(...this.get()),t.buffer.set(n),t.destroyed=o,t.finished=s,t.length=r,t.pos=i,t.outputLen=a,t}clone(){return this._cloneInto()}}class Vu extends Jo{v0l=se[0]|0;v0h=se[1]|0;v1l=se[2]|0;v1h=se[3]|0;v2l=se[4]|0;v2h=se[5]|0;v3l=se[6]|0;v3h=se[7]|0;v4l=se[8]|0;v4h=se[9]|0;v5l=se[10]|0;v5h=se[11]|0;v6l=se[12]|0;v6h=se[13]|0;v7l=se[14]|0;v7h=se[15]|0;constructor(t={}){const n=t.dkLen===void 0?64:t.dkLen;super(128,n),Lu(n,t,64,16,16);let{key:r,personalization:s,salt:o}=t,a=0;if(r!==void 0&&(De(r,void 0,"key"),a=r.length),this.v0l^=this.outputLen|a<<8|65536|1<<24,o!==void 0){De(o,void 0,"salt");const i=Ut(o);this.v4l^=ut(i[0]),this.v4h^=ut(i[1]),this.v5l^=ut(i[2]),this.v5h^=ut(i[3])}if(s!==void 0){De(s,void 0,"personalization");const i=Ut(s);this.v6l^=ut(i[0]),this.v6h^=ut(i[1]),this.v7l^=ut(i[2]),this.v7h^=ut(i[3])}if(r!==void 0){const i=new Uint8Array(this.blockLen);i.set(r),this.update(i)}}get(){let{v0l:t,v0h:n,v1l:r,v1h:s,v2l:o,v2h:a,v3l:i,v3h:l,v4l:c,v4h:u,v5l:h,v5h:p,v6l:v,v6h:d,v7l:f,v7h:b}=this;return[t,n,r,s,o,a,i,l,c,u,h,p,v,d,f,b]}set(t,n,r,s,o,a,i,l,c,u,h,p,v,d,f,b){this.v0l=t|0,this.v0h=n|0,this.v1l=r|0,this.v1h=s|0,this.v2l=o|0,this.v2h=a|0,this.v3l=i|0,this.v3h=l|0,this.v4l=c|0,this.v4h=u|0,this.v5l=h|0,this.v5h=p|0,this.v6l=v|0,this.v6h=d|0,this.v7l=f|0,this.v7h=b|0}compress(t,n,r){this.get().forEach((l,c)=>O[c]=l),O.set(se,16);let{h:s,l:o}=Hn(BigInt(this.length));O[24]=se[8]^o,O[25]=se[9]^s,r&&(O[28]=~O[28],O[29]=~O[29]);let a=0;const i=Ou;for(let l=0;l<12;l++)Et(0,4,8,12,t,n+2*i[a++]),kt(0,4,8,12,t,n+2*i[a++]),Et(1,5,9,13,t,n+2*i[a++]),kt(1,5,9,13,t,n+2*i[a++]),Et(2,6,10,14,t,n+2*i[a++]),kt(2,6,10,14,t,n+2*i[a++]),Et(3,7,11,15,t,n+2*i[a++]),kt(3,7,11,15,t,n+2*i[a++]),Et(0,5,10,15,t,n+2*i[a++]),kt(0,5,10,15,t,n+2*i[a++]),Et(1,6,11,12,t,n+2*i[a++]),kt(1,6,11,12,t,n+2*i[a++]),Et(2,7,8,13,t,n+2*i[a++]),kt(2,7,8,13,t,n+2*i[a++]),Et(3,4,9,14,t,n+2*i[a++]),kt(3,4,9,14,t,n+2*i[a++]);this.v0l^=O[0]^O[16],this.v0h^=O[1]^O[17],this.v1l^=O[2]^O[18],this.v1h^=O[3]^O[19],this.v2l^=O[4]^O[20],this.v2h^=O[5]^O[21],this.v3l^=O[6]^O[22],this.v3h^=O[7]^O[23],this.v4l^=O[8]^O[24],this.v4h^=O[9]^O[25],this.v5l^=O[10]^O[26],this.v5h^=O[11]^O[27],this.v6l^=O[12]^O[28],this.v6h^=O[13]^O[29],this.v7l^=O[14]^O[30],this.v7h^=O[15]^O[31],gt(O)}destroy(){this.destroyed=!0,gt(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const Mn=Er(e=>new Vu(e));function Zo(e,t,n,r,s,o,a,i,l,c,u,h,p,v,d,f,b,y,m,g){let w=0;for(let E=0;E<r;E++)({a:s,b:l,c:p,d:b}=wt(s,l,p,b,n[t+e[w++]])),{a:s,b:l,c:p,d:b}=$t(s,l,p,b,n[t+e[w++]]),{a:o,b:c,c:v,d:y}=wt(o,c,v,y,n[t+e[w++]]),{a:o,b:c,c:v,d:y}=$t(o,c,v,y,n[t+e[w++]]),{a,b:u,c:d,d:m}=wt(a,u,d,m,n[t+e[w++]]),{a,b:u,c:d,d:m}=$t(a,u,d,m,n[t+e[w++]]),{a:i,b:h,c:f,d:g}=wt(i,h,f,g,n[t+e[w++]]),{a:i,b:h,c:f,d:g}=$t(i,h,f,g,n[t+e[w++]]),{a:s,b:c,c:d,d:g}=wt(s,c,d,g,n[t+e[w++]]),{a:s,b:c,c:d,d:g}=$t(s,c,d,g,n[t+e[w++]]),{a:o,b:u,c:f,d:b}=wt(o,u,f,b,n[t+e[w++]]),{a:o,b:u,c:f,d:b}=$t(o,u,f,b,n[t+e[w++]]),{a,b:h,c:p,d:y}=wt(a,h,p,y,n[t+e[w++]]),{a,b:h,c:p,d:y}=$t(a,h,p,y,n[t+e[w++]]),{a:i,b:l,c:v,d:m}=wt(i,l,v,m,n[t+e[w++]]),{a:i,b:l,c:v,d:m}=$t(i,l,v,m,n[t+e[w++]]);return{v0:s,v1:o,v2:a,v3:i,v4:l,v5:c,v6:u,v7:h,v8:p,v9:v,v10:d,v11:f,v12:b,v13:y,v14:m,v15:g}}const ei=new TextEncoder().encode("SS58PRE"),kr=2,ti=e=>{try{const t=Po.decode(e),n=t.subarray(0,t[0]&64?2:1),r=t.subarray(n.length,t.length-kr),s=t.subarray(n.length+r.length),o=Mn(Uint8Array.of(...ei,...n,...r),{dkLen:64}).subarray(0,kr);return s[0]===o[0]&&s[1]===o[1]?{isValid:!0,ss58Format:Nu(n),publicKey:r.slice()}:{isValid:!1}}catch{return{isValid:!1}}},Nu=e=>{const t=new DataView(e.buffer,e.byteOffset,e.byteLength);return t.byteLength===1?t.getUint8(0):t.getUint16(0)},Pu=e=>{let t={},n=0,r=0;const s=()=>{n===r?(t={},n=r=0):(r=n,setTimeout(s,0))};return o=>{var a,i;++n===1&&s();let l=t;const c=o.length-1;for(let u=0;u<=c;u++)l=l[a=o[u]]||(l[a]={});return l[i=o[c]]||(l[i]=e(o))}},ni=e=>{const t=e<64?Uint8Array.of(e):Uint8Array.of((e&252)>>2|64,e>>8|(e&3)<<6);return Pu(n=>{const r=Mn(Uint8Array.of(...ei,...t,...n),{dkLen:64}).subarray(0,kr);return Po.encode(Uint8Array.of(...t,...n,...r))})};function Fu(e,t){return n=>{const r=ti(n);if(!r.isValid)throw new Error("Invalid checksum");const{publicKey:s}=r;if(s.length!==e)throw new Error("Invalid public key length");return s}}const un=(e=42,t=32)=>Ve(ne(t),Fu(t),ni(e)),R=Ve(pe,e=>e,Number),Un=Ve(pe,e=>e,BigInt),Wu=new TextEncoder,qu=new TextDecoder,Ku=ze(R,ne(1/0))[1],zn={toText:e=>qu.decode(e),toHex:e=>X(e),toOpaque:e=>oe([pe[0](e.length),e]),fromText:e=>Wu.encode(e),fromHex:e=>ee(e),fromOpaque:e=>{const t=typeof e=="string"?ee(e):e;try{const[n,r]=Ku(t);if(n===r.length)return r}catch{}throw new Error("Invalid opaque bytes")}},ri=e=>Ve(ne(e),ee,X),Gu=lt(e=>{const t=R.dec(e),n=Math.ceil(t/8);return{bytes:ne(n).dec(e),bitsLen:t}}),Yu=e=>{if(e.bitsLen>e.bytes.length*8)throw new Error(`Not enough bytes. (bitsLen:${e.bitsLen}, bytesLen:${e.bytes.length})`);const t=R.enc(e.bitsLen),n=new Uint8Array(e.bytes.length+t.length);return n.set(t,0),n.set(e.bytes,t.length),n},Xu=G(Yu,Gu),Qu=Ve(P,e=>e.charCodeAt(0),String.fromCharCode),si=e=>{const t=ne.enc(e);return n=>t(ee(n))},oi=e=>{const t=ne.dec(e);return n=>X(t(n))},we=e=>G(si(e),oi(e));we.enc=si,we.dec=oi;const ii=new TextEncoder,Ju=new TextDecoder,Zu=e=>Ve(ne(e),t=>ii.encode(t),t=>Ju.decode(t)),ai=e=>{let t=n=>{const r=e();return t=r,r(n)};return n=>t(n)},ci=e=>{let t=n=>{const r=e(),s=r;return t=r,s(n)};return n=>t(n)},xr=e=>G(ai(()=>e().enc),ci(()=>e().dec)),ed={is(e,t){return e.type===t},as(e,t){if(t!==e.type)throw new Error(`Enum.as(enum, ${t}) used with actual type ${e.type}`);return e}},Dn=Object.assign((e,t)=>({type:e,value:t}),ed),td=new Proxy({},{get(e,t){return n=>Dn(t,n)}}),re=(e,t)=>{const n=e;return n.inner=t,n},li=(...e)=>{const t=ke.enc(...e);return re(n=>t({tag:n.type,value:n.value}),e[0])},ui=(...e)=>{const t=ke.dec(...e);return re(n=>{const{tag:r,value:s}=t(n);return Dn(r,s)},e[0])},Se=(e,...t)=>re(G(li(mt(e,([n])=>n),...t),ui(mt(e,([,n])=>n),...t)),e);Se.enc=li,Se.dec=ui;const Sr=(e,...t)=>re(ke(e,...t),e);Sr.enc=(e,...t)=>re(ke.enc(e,...t),e),Sr.dec=(e,...t)=>re(ke.dec(e,...t),e);const tt={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},dt=Cu.slice(),di=(()=>{const e=Array.from({length:16},(r,s)=>s),t=r=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map(s=>r[s]),n=[];for(let r=0,s=e;r<7;r++,s=t(s))n.push(...s);return Uint8Array.from(n)})();class Ir extends Jo{chunkPos=0;chunksDone=0;flags=0;IV;state;stack=[];posOut=0;bufferOut32=new Uint32Array(16);bufferOut;chunkOut=0;enableXOF=!0;constructor(t={},n=0){super(64,t.dkLen===void 0?32:t.dkLen);const{key:r,context:s}=t,o=s!==void 0;if(r!==void 0){if(o)throw new Error('Only "key" or "context" can be specified at same time');De(r,32,"key");const a=r.slice();this.IV=Ut(a),ge(this.IV),this.flags=n|tt.KEYED_HASH}else if(o){De(s,void 0,"context");const a=s,i=new Ir({dkLen:32},tt.DERIVE_KEY_CONTEXT).update(a).digest();this.IV=Ut(i),ge(this.IV),this.flags=n|tt.DERIVE_KEY_MATERIAL}else this.IV=dt.slice(),this.flags=n;this.state=this.IV.slice(),this.bufferOut=Bu(this.bufferOut32)}get(){return[]}set(){}b2Compress(t,n,r,s=0){const{state:o,pos:a}=this,{h:i,l}=Hn(BigInt(t),!0),{v0:c,v1:u,v2:h,v3:p,v4:v,v5:d,v6:f,v7:b,v8:y,v9:m,v10:g,v11:w,v12:E,v13:$,v14:k,v15:S}=Zo(di,s,r,7,o[0],o[1],o[2],o[3],o[4],o[5],o[6],o[7],dt[0],dt[1],dt[2],dt[3],i,l,a,n);o[0]=c^y,o[1]=u^m,o[2]=h^g,o[3]=p^w,o[4]=v^E,o[5]=d^$,o[6]=f^k,o[7]=b^S}compress(t,n=0,r=!1){let s=this.flags;if(this.chunkPos||(s|=tt.CHUNK_START),(this.chunkPos===15||r)&&(s|=tt.CHUNK_END),r||(this.pos=this.blockLen),this.b2Compress(this.chunksDone,s,t,n),this.chunkPos+=1,this.chunkPos===16||r){let o=this.state;this.state=this.IV.slice();for(let a,i=this.chunksDone+1;(r||!(i&1))&&(a=this.stack.pop());i>>=1)this.buffer32.set(a,0),this.buffer32.set(o,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|tt.PARENT,this.buffer32,0),o=this.state,this.state=this.IV.slice();this.chunksDone++,this.chunkPos=0,this.stack.push(o)}this.pos=0}_cloneInto(t){t=super._cloneInto(t);const{IV:n,flags:r,state:s,chunkPos:o,posOut:a,chunkOut:i,stack:l,chunksDone:c}=this;return t.state.set(s.slice()),t.stack=l.map(u=>Uint32Array.from(u)),t.IV.set(n),t.flags=r,t.chunkPos=o,t.chunksDone=c,t.posOut=a,t.chunkOut=i,t.enableXOF=this.enableXOF,t.bufferOut32.set(this.bufferOut32),t}destroy(){this.destroyed=!0,gt(this.state,this.buffer32,this.IV,this.bufferOut32),gt(...this.stack)}b2CompressOut(){const{state:t,pos:n,flags:r,buffer32:s,bufferOut32:o}=this,{h:a,l:i}=Hn(BigInt(this.chunkOut++));ge(s);const{v0:l,v1:c,v2:u,v3:h,v4:p,v5:v,v6:d,v7:f,v8:b,v9:y,v10:m,v11:g,v12:w,v13:E,v14:$,v15:k}=Zo(di,0,s,7,t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],dt[0],dt[1],dt[2],dt[3],i,a,n,r);o[0]=l^b,o[1]=c^y,o[2]=u^m,o[3]=h^g,o[4]=p^w,o[5]=v^E,o[6]=d^$,o[7]=f^k,o[8]=t[0]^b,o[9]=t[1]^y,o[10]=t[2]^m,o[11]=t[3]^g,o[12]=t[4]^w,o[13]=t[5]^E,o[14]=t[6]^$,o[15]=t[7]^k,ge(s),ge(o),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,gt(this.buffer.subarray(this.pos));let t=this.flags|tt.ROOT;this.stack.length?(t|=tt.PARENT,ge(this.buffer32),this.compress(this.buffer32,0,!0),ge(this.buffer32),this.chunksDone=0,this.pos=this.blockLen):t|=(this.chunkPos?0:tt.CHUNK_START)|tt.CHUNK_END,this.flags=t,this.b2CompressOut()}writeInto(t){ln(this,!1),De(t),this.finish();const{blockLen:n,bufferOut:r}=this;for(let s=0,o=t.length;s<o;){this.posOut>=n&&this.b2CompressOut();const a=Math.min(n-this.posOut,o-s);t.set(r.subarray(this.posOut,this.posOut+a),s),this.posOut+=a,s+=a}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible after digest call");return this.writeInto(t)}xof(t){return Yt(t),this.xofInto(new Uint8Array(t))}digestInto(t){if($r(t,this),this.finished)throw new Error("digest() was already called");return this.enableXOF=!1,this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}}const nd=Er((e={})=>new Ir(e)),rd=BigInt(0),dn=BigInt(1),sd=BigInt(2),od=BigInt(7),id=BigInt(256),ad=BigInt(113),hi=[],pi=[],fi=[];for(let e=0,t=dn,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],hi.push(2*(5*r+n)),pi.push((e+1)*(e+2)/2%64);let s=rd;for(let o=0;o<7;o++)t=(t<<dn^(t>>od)*ad)%id,t&sd&&(s^=dn<<(dn<<BigInt(o))-dn);fi.push(s)}const vi=_u(fi,!0),cd=vi[0],ld=vi[1],bi=(e,t,n)=>n>32?Du(e,t,n):Uu(e,t,n),mi=(e,t,n)=>n>32?ju(e,t,n):zu(e,t,n);function ud(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let a=0;a<10;a++)n[a]=e[a]^e[a+10]^e[a+20]^e[a+30]^e[a+40];for(let a=0;a<10;a+=2){const i=(a+8)%10,l=(a+2)%10,c=n[l],u=n[l+1],h=bi(c,u,1)^n[i],p=mi(c,u,1)^n[i+1];for(let v=0;v<50;v+=10)e[a+v]^=h,e[a+v+1]^=p}let s=e[2],o=e[3];for(let a=0;a<24;a++){const i=pi[a],l=bi(s,o,i),c=mi(s,o,i),u=hi[a];s=e[u],o=e[u+1],e[u]=l,e[u+1]=c}for(let a=0;a<50;a+=10){for(let i=0;i<10;i++)n[i]=e[a+i];for(let i=0;i<10;i++)e[a+i]^=~n[(i+2)%10]&n[(i+4)%10]}e[0]^=cd[r],e[1]^=ld[r]}gt(n)}class Br{state;pos=0;posOut=0;finished=!1;state32;destroyed=!1;blockLen;suffix;outputLen;enableXOF=!1;rounds;constructor(t,n,r,s=!1,o=24){if(this.blockLen=t,this.suffix=n,this.outputLen=r,this.enableXOF=s,this.rounds=o,Yt(r,"outputLen"),!(0<t&&t<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=Ut(this.state)}clone(){return this._cloneInto()}keccak(){ge(this.state32),ud(this.state32,this.rounds),ge(this.state32),this.posOut=0,this.pos=0}update(t){ln(this),De(t);const{blockLen:n,state:r}=this,s=t.length;for(let o=0;o<s;){const a=Math.min(n-this.pos,s-o);for(let i=0;i<a;i++)r[this.pos++]^=t[o++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:n,pos:r,blockLen:s}=this;t[r]^=n,(n&128)!==0&&r===s-1&&this.keccak(),t[s-1]^=128,this.keccak()}writeInto(t){ln(this,!1),De(t),this.finish();const n=this.state,{blockLen:r}=this;for(let s=0,o=t.length;s<o;){this.posOut>=r&&this.keccak();const a=Math.min(r-this.posOut,o-s);t.set(n.subarray(this.posOut,this.posOut+a),s),this.posOut+=a,s+=a}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return Yt(t),this.xofInto(new Uint8Array(t))}digestInto(t){if($r(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,gt(this.state)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:s,rounds:o,enableXOF:a}=this;return t||=new Br(n,r,s,a,o),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=o,t.suffix=r,t.outputLen=s,t.enableXOF=a,t.destroyed=this.destroyed,t}}const jn=((e,t,n,r={})=>Er(()=>new Br(t,e,n),r))(1,136,32),yi=e=>{const t=e.slice(2),n=X(jn(ii.encode(t))).slice(2),r=new Array(40);for(let s=0;s<40;s++){const o=parseInt(n[s],16),a=t[s];r[s]=o>7?a.toUpperCase():a}return`0x${r.join("")}`},dd=ne(20)[1],gi=G(e=>{const t=ee(e);if(t.length!==20)throw new Error(`Invalid length found on EthAddress(${e})`);const n=X(t);if(e===n||e===n.toUpperCase())return t;if(yi(n)!==e)throw new Error(`Invalid checksum found on EthAddress(${e})`);return t},lt(e=>yi(X(dd(e))))),be=e=>re(U(e),e);be.enc=e=>re(U.enc(e),e),be.dec=e=>re(U.dec(e),e);const Pe=(...e)=>re(ze(...e),e);Pe.enc=(...e)=>re(ze.enc(...e),e),Pe.dec=(...e)=>re(ze.dec(...e),e);const Ae=(e,...t)=>re(j(e,...t),e);Ae.enc=(e,...t)=>re(j.enc(e,...t),e),Ae.dec=(e,...t)=>re(j.dec(e,...t),e);const Ln=(e,t)=>re(cn(e,t),{ok:e,ko:t});Ln.enc=(e,t)=>re(cn.enc(e,t),{ok:e,ko:t}),Ln.dec=(e,t)=>re(cn.dec(e,t),{ok:e,ko:t});const xt=e=>re(xe(e),e);xt.enc=e=>re(xe.enc(e),e),xt.dec=e=>re(xe.dec(e),e);const wi=(e=!0)=>lt(t=>{const n=R.dec(t),r=Math.ceil(n/8),s=ne(r).dec(t),o=new Array(n);let a=0;return s.forEach(i=>{for(let l=0;l<8&&a<n;l++){const c=e?l:7-l;o[a++]=i>>c&1}}),o}),$i=(e=!0)=>t=>{const n=R.enc(t.length),r=Math.ceil(t.length/8),s=new Uint8Array(r);for(let o=0;o<r;o++){let a=o*8,i=0;for(let l=0;l<8&&a<t.length;l++,a++)i|=t[a]<<(e?l:7-l);s[o]=i}return oe([n,s])},Vn=e=>G($i(e),wi(e));Vn.enc=$i,Vn.dec=wi;const Ei=new TextEncoder,ki=new TextDecoder,hd=Ve(ne(4),Ei.encode.bind(Ei),ki.decode.bind(ki)),Ar=be({engine:hd,payload:we()}),pd=Se({other:ne(),consensus:Ar,seal:Ar,preRuntime:Ar,runtimeUpdated:M},[0,4,5,6,8]),Or=we(32),Nn=be({parentHash:Or,number:R,stateRoot:Or,extrinsicRoot:Or,digests:Ae(pd)}),Oe=j(W),xi=xe(W),fd=ke({bool:M,char:M,str:M,u8:M,u16:M,u32:M,u64:M,u128:M,u256:M,i8:M,i16:M,i32:M,i64:M,i128:M,i256:M}),Si=j(U({name:xi,type:R,typeName:xi,docs:Oe})),vd=U({len:Ne,type:R}),bd=U({bitStoreType:R,bitOrderType:R}),md=j(U({name:W,fields:Si,index:P,docs:Oe})),yd=ke({composite:Si,variant:md,sequence:R,array:vd,tuple:j(R),primitive:fd,compact:R,bitSequence:bd}),gd=U({name:W,type:xe(R)}),wd=j(gd),$d=U({id:R,path:Oe,params:wd,def:yd,docs:Oe}),Pn=j($d),Xt=ke({NotDeprecated:M,DeprecatedWithoutNote:M,Deprecated:U({note:W,since:xe(W)})}),Ed=j(U({index:P,deprecation:ke({DeprecatedWithoutNote:M,Deprecated:U({note:W,since:xe(W)})},[1,2])})),Cr={name:W,inputs:j(U({name:W,type:R})),output:R,docs:Oe},kd=U({name:W,methods:j(U(Cr)),docs:Oe}),xd=U({name:W,methods:j(U({...Cr,deprecationInfo:Xt})),docs:Oe,version:R,deprecationInfo:Xt}),Sd=U({id:we(32),...Cr,deprecationInfo:Xt}),Id=ke({Blake2128:M,Blake2256:M,Blake2128Concat:M,Twox128:M,Twox256:M,Twox64Concat:M,Identity:M}),Bd=j(Id),Ad=U({hashers:Bd,key:R,value:R}),Ii={name:W,modifier:P,type:ke({plain:R,map:Ad}),fallback:we(),docs:Oe},_r=xe(R),Bi={name:W,storage:xe(U({prefix:W,items:j(U(Ii))})),calls:_r,events:_r,constants:j(U({name:W,type:R,value:we(),docs:Oe})),errors:_r,index:P},Od={...Bi,docs:Oe},Rr=xe(U({type:R,deprecationInfo:Ed})),Cd={name:W,storage:xe(U({prefix:W,items:j(U({...Ii,deprecationInfo:Xt}))})),calls:Rr,events:Rr,constants:j(U({name:W,type:R,value:we(),docs:Oe,deprecationInfo:Xt})),errors:Rr,associatedTypes:j(U({name:W,type:R,docs:Oe})),viewFns:j(Sd),index:P,docs:Oe,deprecationInfo:Xt},_d=new Uint8Array,Ai=e=>G(()=>_d,()=>e),Rd=U({type:R,version:P,signedExtensions:j(U({identifier:W,type:R,additionalSigned:R}))}),Oi=U({lookup:Pn,pallets:j(U({...Bi,docs:Ai([])})),extrinsic:Rd,type:R,apis:Ai([])}),Td=U({version:P,address:R,call:R,signature:R,extra:R,signedExtensions:j(U({identifier:W,type:R,additionalSigned:R}))}),Ci=U({lookup:Pn,pallets:j(U(Od)),extrinsic:Td,type:R,apis:j(kd),outerEnums:U({call:R,event:R,error:R}),custom:j(ze(W,U({type:R,value:we()})))}),Hd=U({version:j(P),address:R,call:R,signature:R,signedExtensionsByVersion:j(ze(P,j(R))),signedExtensions:j(U({identifier:W,type:R,additionalSigned:R}))}),_i=U({lookup:Pn,pallets:j(U(Cd)),extrinsic:Hd,apis:j(xd),outerEnums:U({call:R,event:R,error:R}),custom:j(ze(W,U({type:R,value:we()})))}),Ri=()=>{throw new Error("Unsupported metadata version!")},Ie=G(Ri,Ri),zt=U({magicNumber:Ne,metadata:ke({v0:Ie,v1:Ie,v2:Ie,v3:Ie,v4:Ie,v5:Ie,v6:Ie,v7:Ie,v8:Ie,v9:Ie,v10:Ie,v11:Ie,v12:Ie,v13:Ie,v14:Oi,v15:Ci,v16:_i})}),Tr=ne(),Md=xe(Tr),Ud=ze(pe,Tr),Ti=e=>{try{return zt.dec(e)}catch{}try{return zt.dec(Md.dec(e))}catch{}try{return zt.dec(Tr.dec(e))}catch{}try{return zt.dec(Ud.dec(e)[1])}catch{}throw null},Fn=e=>{if("magicNumber"in e&&(e=e.metadata),"tag"in e){if(e.tag!=="v14"&&e.tag!=="v15"&&e.tag!=="v16")throw new Error("Only metadata 14, 15, and 16 are supported");e=e.value}if("signedExtensionsByVersion"in e.extrinsic){const{extrinsic:{signedExtensions:s,signedExtensionsByVersion:o,...a},...i}=e;if(!o.some(([l])=>l===0))throw new Error("Extension version 0 not found");return{version:16,extrinsic:{...a,signedExtensions:Object.fromEntries(o.map(([l,c])=>[l,c.map(u=>s[u])]))},...i}}if("custom"in e){const{lookup:s,extrinsic:o,custom:a,apis:i,pallets:l,outerEnums:c}=e;return{version:15,lookup:s,pallets:l.map(u=>({...u,calls:u.calls!=null?{type:u.calls}:void 0,events:u.events!=null?{type:u.events}:void 0,errors:u.errors!=null?{type:u.errors}:void 0,viewFns:[],associatedTypes:[]})),extrinsic:{...o,signedExtensions:{0:o.signedExtensions},version:[o.version]},apis:i,outerEnums:c,custom:a}}const{lookup:t,extrinsic:n,pallets:r}=e;return{version:14,lookup:t,pallets:r.map(s=>({...s,calls:s.calls!=null?{type:s.calls}:void 0,events:s.events!=null?{type:s.events}:void 0,errors:s.errors!=null?{type:s.errors}:void 0,viewFns:[],associatedTypes:[]})),extrinsic:{...n,signedExtensions:{0:n.signedExtensions},version:[n.version]},apis:[]}},Dt={bare:0,0:"bare",general:1,1:"general",signed:2,2:"signed"},Hr=Ve(P,({version:e,type:t})=>e+(Dt[t]<<6),e=>{const t=e&63,n=e>>6;if(t===4&&(n===Dt.bare||n===Dt.signed))return{version:t,type:Dt[n]};if(t===5&&(n===Dt.bare||n===Dt.general))return{version:t,type:Dt[n]};throw new Error(`ExtrinsicFormat ${e} not valid`)}),zd={dkLen:32},jt=e=>Mn(e,zd),Dd={dkLen:16},Mr=e=>Mn(e,Dd),Hi=e=>oe([Mr(e),e]),jd={dkLen:32},Mi=e=>nd(e,jd),Ld=e=>oe([Mi(e),e]),Ui=e=>e,Lt=(e,t,n,r)=>new DataView(new Uint16Array([e,t,n,r]).buffer).getBigUint64(0,!0),Ur=2n**64n-1n,me=(e,t)=>e<<t&Ur|e>>64n-t,F=(e,t)=>e*t&Ur,ie=(e,t)=>e+t&Ur,ae=11400714785074694791n,Ce=14029467366897019727n,zi=1609587929392839161n,hn=9650029242287828579n,Di=2870177450012600261n;function St(e,t=0n){let n=ie(ie(t,ae),Ce),r=ie(t,Ce),s=t,o=t-ae,a=e.length,i=0,l=null;(function(){let p=0,v=p+a;if(a){if(l=new Uint8Array(32),a<32){l.set(e.subarray(0,a),i),i+=a;return}if(p<=v-32){const d=v-32;do{let f;f=Lt(e[p+1]<<8|e[p],e[p+3]<<8|e[p+2],e[p+5]<<8|e[p+4],e[p+7]<<8|e[p+6]),n=F(me(ie(n,F(f,Ce)),31n),ae),p+=8,f=Lt(e[p+1]<<8|e[p],e[p+3]<<8|e[p+2],e[p+5]<<8|e[p+4],e[p+7]<<8|e[p+6]),r=F(me(ie(r,F(f,Ce)),31n),ae),p+=8,f=Lt(e[p+1]<<8|e[p],e[p+3]<<8|e[p+2],e[p+5]<<8|e[p+4],e[p+7]<<8|e[p+6]),s=F(me(ie(s,F(f,Ce)),31n),ae),p+=8,f=Lt(e[p+1]<<8|e[p],e[p+3]<<8|e[p+2],e[p+5]<<8|e[p+4],e[p+7]<<8|e[p+6]),o=F(me(ie(o,F(f,Ce)),31n),ae),p+=8}while(p<=d)}p<v&&(l.set(e.subarray(p,v),i),i=v-p)}})(),e=l||e;let c,u=0;for(a>=32?(c=me(n,1n),c=ie(c,me(r,7n)),c=ie(c,me(s,12n)),c=ie(c,me(o,18n)),n=F(me(F(n,Ce),31n),ae),c=c^n,c=ie(F(c,ae),hn),r=F(me(F(r,Ce),31n),ae),c=c^r,c=ie(F(c,ae),hn),s=F(me(F(s,Ce),31n),ae),c=c^s,c=ie(F(c,ae),hn),o=F(me(F(o,Ce),31n),ae),c=c^o,c=ie(F(c,ae),hn)):c=ie(t,Di),c=ie(c,BigInt(a));u<=i-8;){let p=Lt(e[u+1]<<8|e[u],e[u+3]<<8|e[u+2],e[u+5]<<8|e[u+4],e[u+7]<<8|e[u+6]);p=F(me(F(p,Ce),31n),ae),c=ie(F(me(c^p,27n),ae),hn),u+=8}if(u+4<=i){let p=F(Lt(e[u+1]<<8|e[u],e[u+3]<<8|e[u+2],0,0),ae);c=ie(F(me(c^p,23n),Ce),zi),u+=4}for(;u<i;){const p=F(Lt(e[u++],0,0,0),Di);c=F(me(c^p,11n),ae)}let h=c>>33n;return c=F(c^h,Ce),h=c>>29n,c=F(c^h,zi),h=c>>32n,c^=h,c}const Wn=e=>{const t=new Uint8Array(16),n=new DataView(t.buffer);return n.setBigUint64(0,St(e),!0),n.setBigUint64(8,St(e,1n),!0),t},ji=e=>{const t=new Uint8Array(32),n=new DataView(t.buffer);return n.setBigUint64(0,St(e),!0),n.setBigUint64(8,St(e,1n),!0),n.setBigUint64(16,St(e,2n),!0),n.setBigUint64(24,St(e,3n),!0),t},Li=e=>oe([an.enc(St(e)),e]),Vi=new TextEncoder,Vd=new Map([[Ui,0],[Li,8],[Hi,16],[Mr,-16],[jt,-32],[Wn,-16],[ji,-32]]),Ni=e=>{const t=Wn(Vi.encode(e));return(n,...r)=>{const s=oe([t,Wn(Vi.encode(n))]),o=X(s),a=l=>{if(!l.startsWith(o))throw new Error(`key does not match this storage (${e}.${n})`);if(r.length===0)return[];const c=ee(l.slice(o.length)),u=new Array(r.length);for(let h=0,p=0;h<r.length;h++){const[v,d]=r[h],f=Vd.get(d);if(f==null)throw new Error("Unknown hasher");if(f<0){const b=f*-1;u[h]=X(c.slice(p,p+b)),p+=b}else p+=f,u[h]=v.dec(c.slice(p)),p+=v.enc(u[h]).length}return u},i=r.map(([{enc:l},c])=>u=>c(l(u)));return{enc:(...l)=>X(oe([s,...l.map((c,u)=>i[u](c))])),dec:a}}},Nd=zn.fromText("modlpy/utilisuba"),Pd=({threshold:e,signatories:t})=>{const n=Pi(t),r=oe([Nd,pe.enc(n.length),...n,et.enc(e)]);return jt(r)},Pi=e=>e.slice().sort((t,n)=>{for(let r=0;;r++){const s=r>=t.length,o=r>=n.length;if(s&&o)return 0;if(s)return-1;if(o)return 1;if(t[r]!==n[r])return t[r]>n[r]?1:-1}}),It={Leaf:"Leaf",Branch:"Branch",BranchWithVal:"BranchWithVal",LeafWithHash:"LeafWithHash",BranchWithHash:"BranchWithHash",Empty:"Empty",Reserved:"Reserved"},Fi=we().dec,Fd=we(1/0).dec,Wd=we(32).dec,Wi=P.dec,qd=e=>{const t=Wi(e);let n=6;const r=t>>n,s=r?r===1?It.Leaf:r===2?It.Branch:It.BranchWithVal:t>>--n?It.LeafWithHash:t>>--n?It.BranchWithHash:t?It.Reserved:It.Empty;let o=t&255>>8-n;if(o===2**n-1){let a;do o+=a=Wi(e);while(a===255)}return{type:s,partialKey:we(Math.ceil(o/2)).dec(e).slice(o%2?3:2)}},qi=lt(e=>{const t=qd(e),{type:n}=t;if(n==="Empty"||n==="Reserved")return t;if(n==="Leaf"||n==="LeafWithHash")return{...t,value:Fd(e)};const r=et.dec(e),s=[];for(let i=0;i<16;i++)r>>i&1&&s.push(i.toString(16));let o=null;n==="BranchWithVal"&&(o=Fi(e)),n==="BranchWithHash"&&(o=Wd(e));const a={...t,children:Object.fromEntries(s.map(i=>[i,Fi(e)]))};return o!==null&&(a.value=o),a}),Ki=e=>lt(t=>{const n=X(e(new Uint8Array(t.buffer)));try{return{hash:n,...qi(t)}}catch{return{type:"Raw",hash:n,value:""}}}),Gi=(e,t=jt)=>{const n=e.map(Ki(t)),r=Object.fromEntries(n.map(i=>[i.hash,i])),s=n.map(i=>i.hash),o=new Set(s),a=i=>{if(i.value)return;const l=e[s.indexOf(i.hash)];i.value=typeof l=="string"?l:X(l)};return n.forEach(i=>{if("children"in i&&Object.values(i.children).forEach(l=>{const c=r[l];c&&(c.parent=i.hash,o.delete(l))}),i.type==="BranchWithHash"||i.type==="LeafWithHash"){const l=i.value,c=r[l];if(!c)return;o.delete(l),c.type!=="Raw"&&(Object.keys(c).forEach(u=>delete c[u]),c.type="Raw",c.hash=l),c.parent=i.hash,a(c)}i.type==="Raw"&&a(i)}),o.size===1?{rootHash:o.values().next().value,proofs:r}:null};var Yi=Object.freeze({__proto__:null,AccountId:un,Binary:zn,BitSeq:Vn,Blake2128:Mr,Blake2128Concat:Hi,Blake2256:jt,Blake3256:Mi,Blake3256Concat:Ld,Bytes:ne,Enum:Dn,Hex:we,Identity:Ui,Keccak256:jn,Option:xt,Result:Ln,ScaleEnum:Sr,Self:xr,SizedBytes:ri,Storage:Ni,Struct:be,TrieNodeHeaders:It,TrieNodeWithHash:Ki,Tuple:Pe,Twox128:Wn,Twox256:ji,Twox64Concat:Li,Variant:Se,Vector:Ae,_Enum:td,_void:M,bitSequence:Xu,blockHeader:Nn,bool:ru,char:Qu,compact:pe,compactBn:Un,compactNumber:R,createCodec:G,createDecoder:lt,decAnyMetadata:Ti,enhanceCodec:Ve,enhanceDecoder:_n,enhanceEncoder:Cn,ethAccount:gi,extrinsicFormat:Hr,fixedStr:Zu,fromBufferToBase58:ni,getMultisigAccountId:Pd,getSs58AddressInfo:ti,h64:St,i128:eu,i16:Ql,i256:nu,i32:Jl,i64:Zl,i8:Xl,metadata:zt,selfDecoder:ci,selfEncoder:ai,sortMultisigSignatories:Pi,str:W,trieNodeDec:qi,u128:Eo,u16:et,u256:tu,u32:Ne,u64:an,u8:P,unifyMetadata:Fn,v14:Oi,v14Lookup:Pn,v15:Ci,v16:_i,validateProofs:Gi});const Kd=[jt,jn],Gd=(e,t)=>Kd.find(n=>X(n(ee(e)))===t)||(()=>{throw new Error("Unsupported hasher")}),Yd=e=>{const t=(n,r,s)=>{const o=n[r.idx],a=n[s.idx];if(n.length===2)return K([[o,r.id],[a,s.id]]);const i=r.idx+Math.floor((s.idx-r.idx)/2);return e(n[i]).pipe(z(l=>{const c={id:l,idx:i};return c.id===r.id?t(n,c,s):c.id===s.id?t(n,r,c):ue([t(n,r,c),t(n,c,s)]).pipe(x(([u,[h,...p]])=>[...u,...p]))}))};return n=>{const[r]=n;if(n.length===1)return e(r).pipe(x(o=>[[r,o]]));const s=n.length-1;return ue([r,n[s]].map(e)).pipe(z(([o,a])=>o===a?K([[r,o]]):t(n,{idx:0,id:o},{idx:s,id:a})))}},Xd=(e,t,n)=>{const r=Yd(t),s=l=>nn(()=>e().header(l)),o=new en(1),a=l=>{if(l.type==="initialized"){const[c]=l.finalizedBlockHashes;return ue([s(c),r(l.finalizedBlockHashes)]).pipe(x(([u,h])=>{o.closed||(o.next(Gd(u,c)),o.complete());const{number:p,parentHash:v,digests:d}=Nn.dec(u);return{type:"initialized",finalizedBlockHashes:l.finalizedBlockHashes,runtimeChanges:new Map(h),number:p,parentHash:v,hasNewRuntime:d.some(f=>f.type==="runtimeUpdated")}}))}if(l.type==="newBlock"&&l.newRuntime)return t(l.blockHash).pipe(x(c=>({...l,codeHash:c})))},i=l=>new D(c=>{let u=null,h;const p=f=>u?.push(f)||v(f),v=f=>{const b=a(f);b?(u=[],h=b.subscribe({next:y=>{const m=[...u];u=null,c.next(y),m.forEach(p)},error:n})):c.next(f)},d=l.subscribe(f=>{f.type==="stop-error"?(h?.unsubscribe(),u=null,c.next(f)):p(f)});return()=>{h?.unsubscribe(),d.unsubscribe()}});return{getHeader:l=>s(l).pipe(x(Nn[1])),hasher$:o.asObservable(),enhancer:i}},Qd=(e,t)=>{let n=null,r=!1,s=()=>{r=!0};const o=()=>{if(!n)throw new Error("Missing chainHead subscription");return n},a=t(Mt((v,d)=>o().storage(v,"hash","0x3a636f6465",null,d)));let i=Ee,l;const{hasher$:c,enhancer:u,getHeader:h}=Xd(o,a,v=>{console.warn("ChainHead subfollow request failed, retrying\u2026",v),l=setTimeout(()=>i(),250)}),p=new D(v=>{if(r)return v.complete();const d=()=>{let f=[];n=e(!0,b=>{f?f.push(b):v.next(b)},b=>{n=null,!r&&(b instanceof Error&&b.name===no.errorName?(d(),v.next({type:"stop-error"})):(console.warn("ChainHead follow request failed, retrying\u2026",b),l=setTimeout(d,250)))}),f.forEach(b=>v.next(b)),f=null};i=()=>{v.next({type:"stop-error"}),clearTimeout(l),n?.unfollow(),d()},d(),s=()=>{r=!0,clearTimeout(l),v.complete(),n?.unfollow()}}).pipe(u,bt());return{getHeader:h,hasher$:c,getFollower:o,follow$:p,unfollow:()=>{s()}}},Jd=e=>X(Ne.enc(e)),Xi=ne(),Zd=xt(Xi),eh=Ae(Ne).dec,Qi=e=>{const t=e("Metadata_metadata_versions","").pipe(x(eh),de(()=>K([14]))),n=r=>{const[s]=r.filter(o=>o>13&&o<17).sort((o,a)=>a-o);return s===14?e("Metadata_metadata","").pipe(x(Xi.dec)):e("Metadata_metadata_at_version",Jd(s)).pipe(x(o=>Zd.dec(o)))};return t.pipe(z(n))},Ji=(e,t)=>e.type==="array"&&e.len===t&&e.value.type==="primitive"&&e.value.value==="u8",Bt={type:"void"},th=(e,t=()=>null)=>{const n=new Map,r=new Set,s=u=>h=>{let p=n.get(h);if(p)return p;if(r.has(h)){const d={id:h};return n.set(h,d),d}r.add(h);const v=u(h);return p=n.get(h),p?Object.assign(p,v):(p={id:h,...v},n.set(h,p)),r.delete(h),p};let o=!0,a=!0;const i=s(u=>{const h=t(e[u]);if(h)return h;const{def:p,path:v,params:d}=e[u];if(p.tag==="composite"){if(p.value.length===0)return Bt;if(p.value.length===1){const f=i(p.value[0].type);return o&&v.at(-1)==="AccountId32"&&Ji(f,32)?(o=!1,{type:"AccountId32"}):a&&v.at(-1)==="AccountId20"&&Ji(f,20)?(a=!1,{type:"AccountId20"}):f}return l(p.value)}if(p.tag==="variant"){if(v.length===1&&v[0]==="Option"&&d.length===1&&d[0].name==="T"){const y=i(d[0].type);return y.type==="void"?{type:"primitive",value:"bool"}:{type:"option",value:y}}if(v.length===1&&v[0]==="Result"&&d.length===2&&d[0].name==="T"&&d[1].name==="E")return{type:"result",value:{ok:i(d[0].type),ko:i(d[1].type)}};if(p.value.length===0)return Bt;const f={},b={};return p.value.forEach(y=>{const m=y.name;if(b[m]=y.docs,y.fields.length===0){f[m]={...Bt,idx:y.index};return}if(y.fields.length===1&&!y.fields[0].name){f[m]={type:"lookupEntry",value:i(y.fields[0].type),idx:y.index};return}f[m]={...l(y.fields),idx:y.index}}),{type:"enum",value:f,innerDocs:b}}if(p.tag==="sequence")return{type:"sequence",value:i(p.value)};if(p.tag==="array"){const{len:f}=p.value,b=i(p.value.type);return!f||b.type==="void"?Bt:f>1?{type:"array",value:b,len:p.value.len}:b}if(p.tag==="tuple")return p.value.length===0?Bt:p.value.length>1?c(p.value.map(f=>i(f)),p.value.map(f=>e[f].docs)):i(p.value[0]);if(p.tag==="primitive")return{type:"primitive",value:p.value.tag};if(p.tag==="compact"){const f=i(p.value);return f.type==="void"?Bt:{type:"compact",isBig:Number(f.value.slice(1))>32,size:f.value}}return{type:p.tag,isLSB:(e[p.value.bitOrderType].path.at(-1)??"LSB").toUpperCase().startsWith("LSB")}}),l=u=>{let h=!0;const p={},v={};return u.forEach((d,f)=>{h=h&&!!d.name;const b=d.name||f,y=i(d.type);y.type!=="void"&&(p[b]=y,v[b]=d.docs)}),h?{type:"struct",value:p,innerDocs:v}:c(Object.values(p),Object.values(v))},c=(u,h)=>{if(u.every(p=>p.id===u[0].id)&&h.every(p=>!p.length)){const[p]=u;return p.type==="void"?Bt:{type:"array",value:u[0],len:u.length}}return{type:"tuple",value:u,innerDocs:h}};return i},Zi=e=>{const t=th(e.lookup,({def:r})=>{if(r.tag==="composite"){const s=n(r);if(s)return{type:"enum",innerDocs:{},value:Object.fromEntries(e.pallets.map(o=>[o.name,o.errors==null?{...Bt,idx:o.index}:{type:"lookupEntry",value:t(o.errors.type),idx:o.index}])),byteLength:s}}return null});function n(r){if(!(r.value.length===2&&r.value[0].name==="index"&&r.value[1].name==="error"))return null;const s=t(r.value[0].type),o=t(r.value[1].type);return s.type==="primitive"&&s.value==="u8"&&o.type==="array"&&o.value.type==="primitive"&&o.value.value==="u8"?1+o.len:null}return Object.assign(t,{metadata:e,call:"call"in e.extrinsic?e.extrinsic.call:e.lookup[e.extrinsic.type]?.params.find(r=>r.name==="Call")?.type??null})},nh=(e,t,n)=>(r,s,o,...a)=>{const{id:i}=r;if(s.has(i))return s.get(i);if(o.has(i)){const c=t(()=>s.get(i),r,...a);return s.set(i,c),c}o.add(i);let l=e(r,s,o,...a);return o.delete(i),s.has(i)&&(l=n(l,s.get(i),r,...a)),s.set(i,l),l},rh=ne(),sh=(e,t,n,r)=>{if(e.type==="primitive")return Yi[e.value];if(e.type==="void")return M;if(e.type==="AccountId32")return r;if(e.type==="AccountId20")return gi;if(e.type==="compact")return e.isBig?Un:R;if(e.type==="bitSequence")return Vn(e.isLSB);const s=p=>ea(p,t,n,r),o=(p,v)=>{const d=s(p);return v?Ae(d,v):Ae(d)},a=p=>Pe(...p.map(s)),i=p=>{const v=Object.fromEntries(Object.entries(p).map(([d,f])=>[d,s(f)]));return be(v)};if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return rh;if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?ri(e.len):o(e.value,e.len);if(e.type==="sequence")return o(e.value);if(e.type==="tuple")return a(e.value);if(e.type==="struct")return i(e.value);if(e.type==="option")return xt(s(e.value));if(e.type==="result")return Ln(s(e.value.ok),s(e.value.ko));const l=Object.values(e.value).map(p=>{switch(p.type){case"void":return M;case"lookupEntry":return s(p.value);case"tuple":return a(p.value);case"struct":return i(p.value);case"array":return o(p.value,p.len)}}),c=Object.fromEntries(Object.keys(e.value).map((p,v)=>[p,l[v]])),u=Object.values(e.value).map(p=>p.idx),h=u.every((p,v)=>p===v)?Se(c):Se(c,u);return e.byteLength?oh(h,e.byteLength):h},ea=nh(sh,xr,e=>e),ta=(e,t=un())=>{const n=new Map,r=s=>ea(e(s),n,new Set,t);return s=>r(s)},oh=(e,t)=>{const n=ne(t);return G(r=>n.enc(e.enc(r)),r=>e.dec(n.dec(r)))},ih=Ve(M,()=>{},()=>null),ah=e=>{const{metadata:t}=e;let n=ta(e);const r=t.pallets.find(p=>p.name==="System")?.constants.find(p=>p.name==="SS58Prefix");let s;if(r)try{const p=n(r.type).dec(r.value);typeof p=="number"&&(s=p,n=ta(e,un(p)))}catch{}const o=new Map,a=(p,v)=>{let d=o.get(p);d||o.set(p,d=Ni(p));const f=t.pallets.find(S=>S.name===p).storage.items.find(S=>S.name===v),b=S=>S===M?ih:S,y=(S,B,...I)=>{const _=d(...I),[,...T]=I;return{args:Pe(...T.map(([L])=>L)),keys:_,value:B,len:S,fallback:f.modifier===1?B.dec(f.fallback):void 0}};if(f.type.tag==="plain")return y(0,b(n(f.type.value)),v);const{key:m,value:g,hashers:w}=f.type.value,E=b(n(g)),$=w.map(S=>Yi[S.tag]),k=(()=>{if($.length===1)return[[n(m),$[0]]];const S=e(m);switch(S.type){case"array":return $.map(B=>[n(S.value.id),B]);case"tuple":return S.value.map((B,I)=>[n(B.id),$[I]]);default:throw new Error("Invalid key type")}})();return y($.length,E,v,...k)},i=p=>{switch(p.type){case"void":return M;case"lookupEntry":return n(p.value.id);case"tuple":return Pe(...Object.values(p.value).map(v=>n(v.id)));case"struct":return be(mt(p.value,v=>n(v.id)));case"array":return Ae(n(p.value.id),p.len)}},l=(p,v)=>{const d=t.pallets.find(f=>f.name===p).constants.find(f=>f.name===v);return n(d.type)},c=p=>(v,d)=>{const f=t.pallets.find(m=>m.name===v),b=e(f[p].type);if(b.type!=="enum")throw null;const y=b.value[d];return{location:[f.index,y.idx],codec:i(b.value[d])}},u=(p,v)=>{const d=t.pallets.find(f=>f.name===p)?.viewFns.find(f=>f.name===v);if(!d)throw null;return{args:Pe(...d.inputs.map(f=>n(f.type))),value:n(d.output)}},h=(p,v)=>{const d=t.apis.find(f=>f.name===p)?.methods.find(f=>f.name===v);if(!d)throw null;return{args:Pe(...d.inputs.map(f=>n(f.type))),value:n(d.output)}};return{buildDefinition:n,buildStorage:a,buildEvent:c("events"),buildError:c("errors"),buildViewFn:u,buildRuntimeCall:h,buildCall:c("calls"),buildConstant:l,ss58Prefix:s}},ch=(e,t)=>Object.fromEntries(e.pallets.map(n=>{const[r,s,o]=["errors","events","calls"].map(a=>{try{const i=t(n[a].type);if(i.type!=="enum")throw null;return new Map(Object.entries(i.value))}catch{return new Map}});return[n.name,{error:r,event:s,call:o}]})),lh=(e,t)=>{const n=ch(e,t),r=Object.fromEntries(e.pallets.map(i=>{const[l,c]=["constants","viewFns"].map(u=>new Map(i[u].map(h=>[h.name,h])));return[i.name,{const:l,view:c}]})),s=Object.fromEntries(e.pallets.map(i=>[i.name,new Map((i.storage?.items||[]).map(l=>[l.name,l]))])),o=mt(n,({error:i,event:l,call:c},u)=>({error:i,event:l,call:c,storage:s[u],...r[u]})),a=Object.fromEntries(e.apis.map(i=>[i.name,new Map(i.methods.map(l=>[l.name,l]))]));return{pallets:o,api:a,extensions:mt(e.extrinsic.signedExtensions,i=>Object.fromEntries(i.map(({identifier:l,...c})=>[l,c])))}},zr="CheckMortality",na=(e,t,n)=>{const r=Zi(e),s=ah(r),o=s.buildStorage("System","Events"),a=e.extrinsic.signedExtensions[0].find(u=>u.identifier==="ChargeAssetTxPayment");let i=null;if(a){const u=r(a.type);if(u.type==="struct"){const h=u.value.asset_id;h.type==="option"&&(i=h.value.id)}}const l=dh(r.metadata,s),c=u=>{const h=l(u);return"extra"in h&&h.extra[zr]||{mortal:!1}};return{mappedMeta:lh(e,r),assetId:i,metadataRaw:t,codeHash:n,lookup:r,dynamicBuilder:s,events:{key:o.keys.enc(),dec:o.value.dec},accountId:un(s.ss58Prefix),getMortalityFromTx:c,extVersions:e.extrinsic.version}},Dr=ne(1/0).dec,uh=_n(et[1],e=>{const t=2<<e%16,n=Math.max(t>>12,1),r=(e>>4)*n;return{mortal:!0,period:t,phase:r}}),ra=lt(e=>{const t=P.dec(e);if(t===0)return{mortal:!1};const n=P.dec(e);return uh(Uint8Array.from([t,n]))}),dh=(e,t)=>{const n=be.dec(Object.fromEntries(e.extrinsic.signedExtensions[0].map(i=>[i.identifier,i.identifier===zr?ra:t.buildDefinition(i.type)[1]])));let r,s;const{extrinsic:o}=e;if("address"in o)r=t.buildDefinition(o.address)[1],s=t.buildDefinition(o.signature)[1];else{const i=e.lookup[o.type]?.params,l=i?.find(h=>h.name==="Call")?.type,c=i?.find(h=>h.name==="Address")?.type,u=i?.find(h=>h.name==="Signature")?.type;if(l==null||c==null||u==null)throw new Error("Call, Address and/or signature not found");r=t.buildDefinition(c)[1],s=t.buildDefinition(u)[1]}const a=be.dec({address:r,signature:s,extra:n,callData:Dr});return lt(i=>{const l=R.dec(i),{type:c,version:u}=Hr[1](i);if(c==="bare")return{len:l,version:u,type:c,callData:Dr(i)};if(c==="signed")return{len:l,version:u,type:c,...a(i)};const h=P.dec(i);let p;if(e.version===16){const d=e.extrinsic.signedExtensions[h];if(!d)throw new Error("Unexpected extension version");p=be.dec(Object.fromEntries(d.map(f=>[f.identifier,f.identifier===zr?ra:t.buildDefinition(f.type)[1]])))}else p=n;const v=p(i);return{len:l,type:c,version:u,extensionVersion:h,extra:v,callData:Dr(i)}})},hh=e=>t=>{const n=(...r)=>{let s;try{s=e()}catch(o){return Rt(o)}return s?t(s,...r).pipe(de(o=>{if(o instanceof Je)return n(...r);if(o instanceof Error&&o.name===In.errorName)return En(750).pipe(z(()=>n(...r)));throw o})):Xe};return n},ph=(e,t,n)=>{const r=(s,o)=>t(s).pipe(de(()=>K(null)),z(a=>a?K(a):o.pipe(qt(i=>{n(s,i)}))),x(a=>({codeHash:s,metadataRaw:a,metadata:Fn(zt.dec(a))})));return(s,o)=>{const a=new Set([o]),i={},l=hh(()=>{if(!a.size)throw i;return a.has(o)?o:[...a].at(-1)}),c=r(s,Qi(l(e)).pipe(de(h=>h===i?Xe:Rt(()=>h)))).pipe(x(({metadata:h,metadataRaw:p,codeHash:v})=>na(h,p,v)),sn(1)),u={codeHash:s,runtime:c,addBlock:h=>{a.add(h)},deleteBlocks:h=>(h.forEach(p=>{a.delete(p)}),a.size),usages:a};return c.subscribe({error(){}}),u}},pn=bt({connector:()=>new en(1),resetOnError:!0,resetOnComplete:!0,resetOnRefCountZero:!0}),fn=({hash:e,number:t,parent:n,hasNewRuntime:r})=>({hash:e,number:t,parent:n,hasNewRuntime:r}),fh=(e,t,n,r,s,o,a,i)=>{const l=({blocks:m,runtimes:g},w)=>{w.forEach(E=>{m.get(m.get(E).parent)?.children.delete(E),m.delete(E),i(E)}),Object.entries(g).map(([E,$])=>({key:E,usages:$.deleteBlocks(w)})).filter(E=>E.usages===0).map(E=>E.key).forEach(E=>{delete g[E]})},c=m=>{o.next(fn(m))},u=m=>{l(m,[...m.blocks.values()].filter(w=>w.recovering).map(w=>w.hash));const g="pendingBlocks"in m.state?m.state.pendingBlocks:[];m.state={type:ve.Ready},g.forEach(c)},h=new ye,p=h.pipe(dl(()=>En(0)),x(()=>({type:"cleanup"}))),v=sa(),d=()=>(l(v,[...v.blocks.values()].map(m=>m.hash)),Object.assign(v,sa())),f=Qe(s,p,e).pipe(rn((m,g)=>{const w=$=>{l(m,$),a($)},E=(...$)=>{const k=m.blocks.get(m.finalized)?.number??-1,S=$.filter(({refCount:B,recovering:I,number:_,pruned:T})=>!B&&!I&&(T||_<k)).map(({hash:B})=>B);S.length&&w(S)};switch(g.type){case"initialized":if(m.state.type!==ve.Initializing&&m.state.type!==ve.RecoveringInit)throw new Error("Initialized event out of order");m.state.type===ve.RecoveringInit&&!g.finalizedBlockHashes.some(I=>m.blocks.has(I))&&(d(),o.next(null));const $=m.blocks.get(m.finalized)?.number??-1,k=g.finalizedBlockHashes.length-1,S=[];$>g.number+k?m.state={type:ve.RecoveringFin,target:$,pendingBlocks:S}:(m.state={type:ve.Initializing,pendingBlocks:S},m.finalized=g.finalizedBlockHashes[k]);let B=m.finalizedRuntime.codeHash;return g.finalizedBlockHashes.forEach((I,_)=>{const T=m.blocks.get(I);if(T)T.recovering=!1;else{const L=g.number+_,Z=L>$,ce=g.runtimeChanges.get(I),$e=ce&&!m.runtimes[ce]&&Z;$e&&(B=ce);const ot=_===0?g.parentHash:g.finalizedBlockHashes[_-1],At={hash:I,hasNewRuntime:_?g.runtimeChanges.has(I):g.hasNewRuntime,parent:ot,children:new Set(_===k?[]:[g.finalizedBlockHashes[_+1]]),pruned:!1,runtime:B,refCount:0,number:L,recovering:!1};m.blocks.set(I,At),$e&&(m.finalizedRuntime=m.runtimes[ce]=y(ce,I)),m.runtimes[B].usages.add(I),Z&&S.push(At)}}),m;case"stop-error":if(m.state.type===ve.Initializing)return d();for(const I of m.blocks.values())I.recovering=!0;return m.state={type:ve.RecoveringInit},m;case"newBlock":{const{parentBlockHash:I,blockHash:_}=g;if(m.blocks.has(_))m.blocks.get(_).recovering=!1;else{const T=m.blocks.get(I);T.children.add(_);const L=T.number+1,Z={hash:_,number:L,parent:I,children:new Set,runtime:T.runtime,pruned:!1,refCount:0,recovering:!1,hasNewRuntime:!!g.newRuntime};if(m.blocks.set(_,Z),g.newRuntime){const{codeHash:ce}=g;Z.runtime=ce,m.runtimes[ce]=y(ce,_)}m.runtimes[Z.runtime].addBlock(_),"pendingBlocks"in m.state?m.state.pendingBlocks.push(Z):c(Z)}return m}case"bestBlockChanged":return m.state.type===ve.RecoveringFin||(m.best=g.bestBlockHash,m.state.type===ve.Initializing&&u(m)),m;case"finalized":{const I=g.finalizedBlockHashes.slice(-1)[0];let _=!1;if(m.state.type===ve.RecoveringFin){if(m.blocks.get(I).number<m.state.target)return m;_=!0}m.finalized=I;const{blocks:T}=m;return T.get(m.best).number<T.get(m.finalized).number&&(m.best=m.finalized),m.finalizedRuntime=m.runtimes[T.get(m.finalized).runtime],g.prunedBlockHashes.forEach(L=>{const Z=m.blocks.get(L);Z&&(Z.pruned=!0)}),_&&u(m),m.state.type===ve.Ready&&h.next(),m}case"cleanup":return E(...m.blocks.values()),m;case"blockUsage":{const I=m.blocks.get(g.value.hash);return I&&(I.refCount+=g.value.type==="hold"?1:-1,E(I)),m}}},v),x(m=>({...m})),qt({error(m){o.error(m)}}),pn),b=Object.assign(f,{state:v}),y=ph(An(b,t,"pinned-blocks"),n,r);return b},sa=()=>({best:"",finalized:"",runtimes:{},blocks:new Map,finalizedRuntime:{},state:{type:ve.Initializing,pendingBlocks:[]}}),oa=(e,t,n,r,s,o)=>{const a=new Map,i=v=>{a.get(v)?.(),a.delete(v)},l=new D(v=>{const d=t.subscribe({next:({hash:f})=>{a.set(f,o(f))},complete(){v.error(new Error("Tracking stopped"))}});return d.add(e.pipe(x(f=>f.finalized),he()).subscribe(()=>{e.state.blocks.forEach(({pruned:f,hash:b})=>{f&&i(b)})})),d.add(()=>[...a.keys()].forEach(i)),d}),c=v=>dr(e.pipe(Be(({blocks:d})=>d.get(v)?.pruned??!0))),u=(v,d,f)=>{if(f)return K({hash:v,found:{type:!1,validity:null}});const b=c(v);return n(v).pipe(z(y=>{const m=y.findIndex(g=>vh(g,d));return m>-1?b(s(v)).pipe(x(g=>({hash:v,found:{type:!0,index:m,events:g}}))):r(v,d).pipe(x(g=>({hash:v,found:{type:!1,validity:g}})))}),b,lr(()=>i(v)))},h=v=>{[...e.state.blocks.get(v)?.children.keys()??[]].forEach(h),i(v)},p=(v,d,f)=>u(v,d,f.has(v)).pipe(z(b=>{const{found:y}=b,m=y.type||y.validity?.success===!1;return m&&h(v),m?K(b):e.pipe(c(v),z(g=>g.blocks.get(v).children),ll(),z(g=>p(g,d,f)))}));return v=>Qe(l,e.pipe(te(1),z(d=>p(d.finalized,v,new Set(d.blocks.keys())))))},vh=(e,t)=>e.length===t.length&&e.every((n,r)=>t[r]===n),bh=new Uint8Array([2]),mh=(e,t)=>X(oe([bh,e,ee(t)])),ia="TaggedTransactionQueue",aa="validate_transaction",[,yh]=Se({InvalidTransaction:Se({Call:M,Payment:M,Future:M,Stale:M,BadProof:M,AncientBirthBlock:M,ExhaustsResources:M,Custom:P,BadMandatory:M,MandatoryValidation:M,BadSigner:M}),UnknownTransaction:Se({CannotLookup:M,NoUnsignedValidator:M,Custom:P})}),gh=lt(e=>{const t=P.dec(e);if(t>1)throw new Error("Unable to decode validateTransaction result");if(!t)return{success:!0,value:void 0};let n;try{n=yh(e)}catch{n={type:"UnknownInvalidTx"}}return{success:!1,value:n}}),wh=(e,t)=>(n,r)=>{const s=t(n).pipe(x(o=>{try{return o.dynamicBuilder.buildRuntimeCall(ia,aa).value[1]}catch{return gh}}));return e(n,`${ia}_${aa}`,mh(r,n)).pipe(Gs(s),x(([o,a])=>a(o)))},$h=e=>t=>new D(n=>{let r=!1;const s=t.subscribe({next(o){r=!0,n.next(o)},error(o){n.error(o)},complete(){n.complete()}});return r||n.next(e),s}),Eh=e=>t=>new D(n=>{const r=t.subscribe({next(o){n.next(o)},error(o){n.error(o)},complete(){n.complete()}}),s=()=>r.unsubscribe();return()=>{Promise.resolve().then(s)}}),ca=(e,t=1/0)=>n=>new D(r=>{let s;const o=new Map,a=new Map,i=new Map;let l=0,c=0,u=0;const h=()=>{const p=o.get(c);if(!p){a.size===0&&(typeof s>"u"||s.closed)&&r.complete();return}const v=c++;o.delete(v),u!==v&&i.set(v,[]);let d=!1,f=p.subscribe({next(b){u===v?r.next(b):i.get(v).push(b)},complete(){if(d=!0,a.delete(v),v===u)for(u++;i.has(u)&&(i.get(u).forEach(b=>r.next(b)),i.delete(u),!a.has(u));)u++;h()},error(b){r.error(b)}});d||a.set(v,f)};return s=new _t,s.add(n.subscribe({next(p){const v=l++;o.set(v,nn(()=>e(p,v))),a.size<t&&h()},error(p){r.error(p)},complete(){a.size===0&&r.complete()}})),()=>{a.forEach(p=>p.unsubscribe()),s.unsubscribe(),o.clear(),i.clear()}}),kh=(e,t,n)=>{const{withRecovery:r,withRecoveryFn:s}=Ll(),{getFollower:o,unfollow:a,follow$:i,getHeader:l,hasher$:c}=Qd(e,s),u=Pl(o),h=new ye,p=A=>C=>new D(H=>{h.next({type:"blockUsage",value:{type:"hold",hash:A}});const V=C.subscribe(H);return V.add(()=>{setTimeout(()=>{h.next({type:"blockUsage",value:{type:"release",hash:A}})},0)}),V}),v=A=>(C,...H)=>A(C,...H).pipe(p(C)),d=(A,C)=>(H,...V)=>new D(fe=>g.state.blocks.has(H)?A(H,...V).subscribe(fe):fe.error(new Je(H,C))),f=A=>o().unpin(A).catch(C=>{if(!(C instanceof Error&&C.name===xn.errorName))throw C}),b=(A,C)=>d(v(An(g,s(Mt(A)),`stop-${C}`)),C),y=new Map,m=new ye,g=fh(i,(...A)=>v(s(Mt(u("call"))))(...A).pipe(x(ee)),t,n,h,m,A=>{f(A).catch(C=>{console.error("unpin",C)}),A.forEach(C=>{y.delete(C)})},A=>{y.delete(A)}),w=d(v(A=>g.state.runtimes[g.state.blocks.get(A).runtime].runtime),"getRuntimeCtx"),E=A=>C=>C.pipe(ca(H=>w(A(H)).pipe(x(V=>[H,V])))),$=(A,C,H)=>{const V=y.get(A)??new Map,fe=V.get(C);if(fe)return fe;y.set(A,V);let Ot;const Ge=H.pipe(bt({connector:()=>Ot=new en}),qt({complete(){V.set(C,Ot)}}),Eh());return V.set(C,Ge),Ge},k=Object.assign(g.pipe(Be(A=>A.state.type===ve.Ready)),{state:g.state}),S=k.pipe(he((A,C)=>A.finalized===C.finalized),rn((A,C)=>{let H=C.blocks.get(C.finalized);const V=[H],fe=A.at(-1);if(!fe)return V;for(;H.number>fe.number+1&&(H=C.blocks.get(H.parent),!!H);)V.unshift(H);return V},[]),$n(),x(fn),pn),B=k.pipe(he((A,C)=>A.best===C.best),x(A=>fn(A.blocks.get(A.best))),pn),I=k.pipe(he((A,C)=>A.finalized===C.finalized&&A.best===C.best),rn((A,C)=>{const H=Re=>A.get(Re)||fn(C.blocks.get(Re)),V=H(C.best),fe=H(C.finalized),Ot=V.number-fe.number+1,Ge=new Array(Ot);for(let Re=0,nr=V.hash;Re<Ot;Re++)Ge[Re]=H(nr),nr=Ge[Re].parent;return new Map(Ge.map(Re=>[Re.hash,Re]))},new Map),x(A=>[...A.values()]),pn),_=k.pipe(he((A,C)=>A.finalizedRuntime===C.finalizedRuntime),Tt(({finalizedRuntime:{runtime:A}})=>A.pipe($h(null))),pn),T=_.pipe(x(A=>A?.lookup.metadata??null)),L=Nl(S.pipe(x(A=>A.hash)),B.pipe(x(A=>A.hash)),p),Z=b(u("body"),"body"),ce=A=>mr($(A,"body",Z(A))).pipe(x(C=>C.map(ee))),$e=b(u("storage"),"storage"),ot=L(d((A,C,H,V=null,fe)=>{const Ot=g.state.blocks.get(A);return g.state.runtimes[Ot.runtime].runtime.pipe(z(Ge=>{const Re=H(Ge);return $(A,`storage-${C}-${Re}-${V??""}`,$e(A,C,Re,V)).pipe(fe?x(nr=>fe(nr,Ge)):Le)}),x(Ge=>({block:fn(Ot),value:Ge})))},"storage")),At=Fl(o,r),uv=L(d(An(g,(A,C,H)=>At(A,C,H??null,!1),"storageQueries"),"storageQueries")),dv=d(An(g,l,"header"),"header"),tc=A=>ot(A,"value",C=>C.events.key,null,(C,H)=>C?H.events.dec(C):[]).pipe(x(C=>C.value)),hv=b(u("call"),"call"),nc=L((A,C,H)=>$(A,`call-${C}-${H}`,hv(A,C,H).pipe(x(ee)))),ds=wh(nc,w),pv=_.pipe(Be(Boolean),te(1),z(A=>{const{enc:C}=A.dynamicBuilder.buildStorage("System","BlockHash").keys;let H;try{H=C(0)}catch{H=C(0n)}return ot(null,"value",()=>H,null).pipe(x(V=>V.value))}),sn(1));Qe(_,I).subscribe({error(){}});const fv=A=>g.state.runtimes[A]?.runtime??K(null),tr=(A,C=!1)=>{let H=A||"finalized";if(H=g.state[H]||H,!g.state.blocks.has(H)){if(C)throw new Je(H,"holdBlock");return Ee}h.next({type:"blockUsage",value:{type:"hold",hash:H}});let V=()=>{h.next({type:"blockUsage",value:{type:"release",hash:H}}),V=Ee};return()=>{V()}},vv=A=>C=>new D(H=>{const V=C.subscribe(H);return V.closed||V.add(tr(A)),V}),hs=m.pipe(Ht(Boolean)),bv=oa(k,hs,ce,ds,tc,tr),mv=oa(g,hs,ce,ds,()=>K(),tr);return{follow$:i,unfollow:a,finalized$:S,best$:B,bestBlocks$:I,newBlocks$:ct(k.pipe(te(1),z(({blocks:A,finalized:C})=>{const H=V=>{const fe=A.get(V);return fe?[fe,...Array.from(fe.children).flatMap(H)]:[]};return H(C)})),hs),runtime$:_,metadata$:T,genesis$:pv,hasher$:c,getRuntime$:fv,header$:dv,body$:ce,call$:nc,storage$:ot,storageQueries$:uv,eventsAt$:tc,withHodl:vv,holdBlock:tr,trackTx$:bv,trackTxWithoutEvents$:mv,validateTx$:ds,pinnedBlocks$:k,withRuntime:E,getRuntimeContext$:L(w)}};var xh=e=>t=>new D(n=>e(X(t),r=>{n.error(r)}));const Sh=({storageSubscription:e,...t})=>n=>{const r={},s=Mt(t.storage),o=(v,d,f)=>Mt(t.call)(v,d,f).pipe(x(ee)),a=Mt(t.header),i=v=>Mt(t.body)(v).pipe(x(d=>d.map(ee))),l=v=>a(v).pipe(x(Nn[1])),c=v=>s(v,"hash","0x3a636f6465",null).pipe(x(d=>d)),u=(v,d)=>n(v).pipe(de(()=>K(null)),z(f=>f?K(f):Qi((...b)=>o(d,...b)).pipe(x(b=>na(Fn(zt.dec(b)),b,v)))),qt(f=>{r[v]=f})),h=v=>c(v).pipe(z(d=>{const f=r[d];return f?K(f):u(d,v)})),p=(v,d,f,b=null,y)=>h(v).pipe(z(m=>s(v,d,f(m),b).pipe(x(g=>y?y(g,m):g))));return{body$:i,header$:l,storage$:p,storageQueries$:(v,d,f)=>new D(b=>e(v,d,f||null,y=>b.next(y),y=>b.error(y),()=>{b.complete()})),call$:o,eventsAt$:v=>p(v,"value",d=>d.events.key,null,(d,f)=>f.events.dec(d)),getRuntimeContext$:h}},Ih=()=>K(null),Bh=(e,{getMetadata:t,setMetadata:n}={})=>({chainHead$:()=>kh(e.chainHead,t||Ih,n||Ee),archive:Sh(e.archive),broadcastTx$:xh(e.transaction),destroy:e.destroy}),Ah=(e,t)=>e.pipe(Ht(n=>n.blocks.has(t)),he((n,r)=>n.finalized===r.finalized&&n.best===r.best),x(n=>{if(n.blocks.get(t).number>n.blocks.get(n.best).number)return null;const{number:r}=n.blocks.get(t);let s=n.blocks.get(n.best),o=n.finalized===s.hash;for(;s.number>r;)s=n.blocks.get(s.parent),o=o||n.finalized===s.hash;return o?"finalized":s.hash===t?"best":null}),he(),Ht(n=>n!=="finalized",!0)),Vt=(e,t)=>(n,...r)=>e(n,...r).pipe(de(s=>{if(!(s instanceof Je))throw s;return t(n,...r).pipe(de(o=>{throw console.warn(o),s}))})),ht=R,Oh=Ae(Pe(W,ht)),q={bool:"boolean",str:"string",num:"number",big:"bigint",bits:"bitseq",void:"void"},Ch=Se(Object.fromEntries(Object.values(q).map(e=>[e,M]))),_h=Ae(Pe(W,Se({inline:xr(()=>jr),lookup:ht}))),Rh=Ae(ht),Th=be({typeRef:ht,length:xt(ht)}),Hh=xt(ht),Mh=ht,Uh=be({ok:ht,ko:ht}),jr=Se({struct:Oh,terminal:Ch,enum:_h,tuple:Rh,array:Th,binary:Hh,option:Mh,result:Uh}),zh={i256:q.big,i128:q.big,i64:q.big,i32:q.num,i16:q.num,i8:q.num,u256:q.big,u128:q.big,u64:q.big,u32:q.num,u16:q.num,u8:q.num,bool:q.bool,char:q.str,str:q.str},vn=e=>({type:"terminal",value:{type:e}});function Lr(e,t=()=>{}){switch(e.type){case"AccountId20":case"AccountId32":return vn(q.str);case"array":return e.value.type==="primitive"&&e.value.value==="u8"?{type:"binary",value:e.len}:(t(e.value.id),{type:"array",value:{typeRef:e.value.id,length:e.len}});case"bitSequence":return vn(q.bits);case"compact":return vn(e.isBig?q.big:q.num);case"enum":return{type:"enum",value:Object.entries(e.value).map(([n,r])=>r.type!=="lookupEntry"?[n,{type:"inline",value:Lr(r,t)}]:(t(r.value.id),[n,{type:"lookup",value:r.value.id}]))};case"struct":{const n=Object.entries(e.value).map(([r,s])=>[r,s.id]);return n.forEach(([,r])=>t(r)),{type:"struct",value:n}}case"tuple":{const n=e.value.map(r=>r.id);return n.forEach(t),{type:"tuple",value:n}}case"option":return t(e.value.id),{type:"option",value:e.value.id};case"primitive":return vn(zh[e.value]);case"result":return t(e.value.ok.id),t(e.value.ko.id),{type:"result",value:{ok:e.value.ok.id,ko:e.value.ko.id}};case"sequence":return e.value.type==="primitive"&&e.value.value==="u8"?{type:"binary",value:void 0}:(t(e.value.id),{type:"array",value:{typeRef:e.value.id}});case"void":return vn(q.void)}}function Vr(e,t,n){if(t.type==="option"&&e==null)return!0;const r=(o,a)=>Vr(o,a,n),s=o=>{switch(o.value.type){case q.str:case q.big:case q.bool:case q.num:return typeof e===o.value.type;case q.bits:return typeof e=="object"&&e!=null&&typeof e.bitsLen=="number"&&e.bytes instanceof Uint8Array;case q.void:return!0}};switch(t.type){case"terminal":return s(t);case"binary":return t.value==null?e instanceof Uint8Array:typeof e=="string"&&e.startsWith("0x");case"array":if(!Array.isArray(e))return!1;const o=e;return t.value.length!=null&&o.length<t.value.length?!1:o.slice(0,t.value.length).every(c=>r(c,n(t.value.typeRef)));case"enum":if(!e)return!1;const a=e,i=Object.fromEntries(t.value);if(!(a.type in i))return!1;const l=i[a.type];return l==null?!0:r(a.value,l.type==="inline"?l.value:n(l.value));case"option":return e==null?!0:r(e,n(t.value));case"struct":return e?t.value.every(([c,u])=>r(e[c],n(u))):!1;case"tuple":return e?t.value.every((c,u)=>r(e[u],n(c))):!1;case"result":return"success"in e&&"value"in e?r(e.value,n(e.success?t.value.ok:t.value.ko)):!1}}var Dh=Object.defineProperty,jh=(e,t,n)=>t in e?Dh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Lh=(e,t,n)=>jh(e,t+"",n);let la=class{constructor(t=[]){Lh(this,"value",new Map),t.forEach(([n,r])=>this.add(n,r))}has(t,n){return this.value.get(t)?.has(n)??!1}add(t,n){this.value.has(t)||this.value.set(t,new Set),this.value.get(t).add(n)}addAll(t){t.forEach(([n,r])=>this.add(n,r))}delete(t,n){if(!this.value.has(t))return;const r=this.value.get(t);r.delete(n),r.size||this.value.delete(t)}isEmpty(){return!this.value.size}get values(){return Array.from(this.value).flatMap(([t,n])=>Array.from(n).map(r=>[t,r]))}};var pt=(e=>(e[e.Incompatible=0]="Incompatible",e[e.Partial=1]="Partial",e[e.BackwardsCompatible=2]="BackwardsCompatible",e[e.Identical=3]="Identical",e))(pt||{});function Nr(e,t,n,r,s,o=!1){if(!n&&!e)return Fe(3,[]);if(!n)return Fe(2,[]);if(!e)return Fe(n.type==="option"?2:0,[]);s.has(n)||s.set(n,new Map);const a=s.get(n);if(a.has(e)){const l=a.get(e);return l==null?{level:3,changes:[],assumptions:new la([[e,n]])}:Fe(l.level,l.changes)}a.set(e,null);const i=Vh(e,n,(l,c)=>Nr(typeof l=="number"?t(l):l,t,typeof c=="number"?r(c):c,r,s),o);return i.assumptions.delete(e,n),i.assumptions.isEmpty()||i.level===0?a.set(e,i):a.delete(e),i}function Vh(e,t,n,r){const s=(o,a,i)=>{const l=n(o,a);return{...l,changes:l.level<3?[{id:[typeof o=="number"?o:null,typeof a=="number"?a:null],level:l.level,path:i}]:[]}};if(e.type!==t.type)return t.type==="option"?qn(s(e,t.value,"some"),2):e.type==="option"?qn(s(e.value,t,"some"),1):Fe(0,[]);switch(t.type){case"terminal":return Fe(t.value.type===e.value.type?3:0,[]);case"binary":return Fr(ha(e.value,t.value));case"array":const o=e,a=Fr(ha(o.value.length,t.value.length));return Pr([a,()=>s(o.value.typeRef,t.value.typeRef,"value")],r);case"enum":{const h=e,p=Object.fromEntries(t.value.map(([f,b])=>[f,b.value]));let v=da(h.value.map(([f,b])=>()=>f in p?s(b.value,p[f],f):Fe(0,[{id:[typeof b.value=="number"?b.value:null,null],level:0,path:f}])));if(h.value.length===t.value.length)return v;v=qn(v,2);const d=new Set(h.value.map(([f])=>f));return v.changes=[...v.changes,...t.value.filter(([f])=>!d.has(f)).map(([f,b])=>({id:[null,typeof b=="number"?b:null],level:0,path:f}))],v}case"option":return Nh(s(e.value,t.value,"some"),1);case"struct":const i=e,l=Object.fromEntries(i.value),c=i.value.length===t.value.length?3:2;return qn(Pr(t.value.map(([h,p])=>()=>s(l[h],p,h)),r),c);case"tuple":{const h=e,p=Fr(Ph(h.value,t.value));return Pr([p,...t.value.map((v,d)=>()=>s(h.value[d],v,String(d)))],r)}case"result":const u=e;return da([s(u.value.ok,t.value.ok,"ok"),s(u.value.ko,t.value.ko,"ko")])}}const qn=(e,t)=>({...e,level:Math.min(e.level,t)}),Nh=(e,t)=>({...e,level:Math.max(e.level,t)}),ua=new la,Fe=(e,t)=>({level:e,changes:t,assumptions:ua}),Pr=(e,t)=>{let n=Fe(3,[]);for(const r of e){const s=typeof r=="function"?r():r;if(!t&&s.level===0)return s;s.level!==3&&(n.changes=[...n.changes,...s.changes]),n.assumptions.addAll(s.assumptions.values),n.level=Math.min(n.level,s.level)}return n},da=e=>{if(!e.length)return Fe(3,[]);let t=!1,n=Fe(3,[]);for(const r of e){const s=typeof r=="function"?r():r;if(s.level!==3&&(n.changes=[...n.changes,...s.changes]),s.level===0){n.level=Math.min(n.level,1);continue}t=!0,n.assumptions.addAll(s.assumptions.values),n.level=Math.min(n.level,s.level)}return t?n:Fe(0,n.changes)},Fr=e=>({assumptions:ua,changes:e===3?[]:[{id:[null,null],level:e,path:"length"}],level:e}),Ph=(e,t)=>t.length===e.length?3:e.length>=t.length?2:0,ha=(e,t)=>t===e?3:t==null||e>=t?2:e==null?1:0,pa=Se({lookup:R,typedef:jr}),Qt=e=>({type:"lookup",value:e}),Wr=e=>({type:"typedef",value:e}),Kn=Wr({type:"terminal",value:{type:q.void}}),Fh=be({args:pa,values:pa});function Wh(e){if(e.type.tag==="plain")return{args:Kn,values:Qt(e.type.value)};const{key:t,value:n}=e.type.value;return{args:Qt(t),values:Qt(n)}}function fa(e){return{args:Wr({type:"tuple",value:e.inputs.map(t=>t.type)}),values:Qt(e.output)}}function qh(e){return e.type==="lookupEntry"?Qt(e.value.id):Wr(Lr(e))}function Kh(e){return{args:Kn,values:Qt(e)}}function Gh(e,t,n,r,s,o){const a=(i,l)=>i.type==="lookup"?l(i.value):i.value;return{args:Nr(a(e.args,t),t,a(n.args,r),r,s,o),values:Nr(a(n.values,r),r,a(e.values,t),t,s,o)}}function va(e,t,n){const r=e.type==="lookup"?t(e.value):e.value;return Vr(n,r,t)}const Gn=e=>{const t=new WeakMap,n={};return r=>{const s=r??n,o=t.get(s)||e(r);return t.set(s,o),o}},Yh=Ae(Fh),Xh=Ae(jr),[,Qh]=Pe(Yh,Xh);var je=(e=>(e.Storage="storage",e.Tx="tx",e.Event="events",e.Const="constants",e.ViewFns="viewFns",e.Api="apis",e))(je||{});const Jh=async({metadataTypes:e,descriptors:t})=>{const[[n,r],s]=await Promise.all([e.then(Qh),t]);return{getTypeDefNode:o=>r[o],getEntryPointNode:(o,a,i)=>{const l=s[o]?.[a]?.[i];return l==null?l:n[l]}}},ba=(e,t)=>{const n=qh(e),[r,s]=t==="args"?[n,Kn]:[Kn,n];return{args:r,values:s}},ma=Gn(({lookup:e,assetId:t,mappedMeta:{pallets:n,api:r}})=>{const s=new Map,o=a=>{let i=s.get(a);return i||(s.set(a,i=Lr(e(a))),i)};return{getTypeDefNode:o,getEntryPointNode:(a,i,l)=>{switch(a){case"storage":{const c=n[i]?.storage.get(l);return c&&Wh(c)}case"tx":{const c=n[i]?.call.get(l);return c&&ba(c,"args")}case"events":{const c=n[i]?.event.get(l);return c&&ba(c,"values")}case"viewFns":{const c=n[i]?.view.get(l);return c&&fa(c)}case"apis":{const c=r[i]?.get(l);return c&&fa(c)}case"constants":{const c=n[i]?.const.get(l);return c&&Kh(c.type)}}},isAssetCompat:a=>t==null||Vr(a,o(t),o)}}),ya=(e,t,n,r)=>{if(!e)return null;const{getEntryPointNode:s,getTypeDefNode:o}=e;return{entry:s(t,n,r),getter:o}},Zh=bt({connector:()=>new en(1),resetOnError:!0,resetOnComplete:!0,resetOnRefCountZero:!0});function We(e,t){return new Promise((n,r)=>{let s=null,o=!1;const a=t?()=>{s?.unsubscribe(),r(new Xs)}:Ee;s=e.subscribe({next:i=>{n(i),s?.unsubscribe(),o=!0},error:i=>{t?.removeEventListener("abort",a),r(i),o=!0},complete:()=>{t?.removeEventListener("abort",a),r(new Error("Observable completed without emitting")),o=!0}}),o||t?.addEventListener("abort",a)})}const qr=Symbol("EMPTY_VALUE"),Kr=e=>t=>new D(n=>{let r=0,s=null,o=qr,a=!1;const i=()=>{const c=e(o,r++);o=qr,s=c.subscribe({next(u){n.next(u)},error(u){n.error(u)},complete(){o!==qr?i():(s=null,a&&n.complete())}})},l=t.subscribe({next(c){o=c,s||i()},error(c){n.error(c)},complete(){s||n.complete(),a=!0}});return()=>{s?.unsubscribe(),l.unsubscribe()}});let ga={};const ep=e=>t=>new D(n=>{let r=ga,s=t.subscribe({next(o){n.next(r=o)},error(o){n.error(o)},complete(){r===ga?n.complete():s=e(r).subscribe(n)}});return()=>{s.unsubscribe()}}),Nt=e=>typeof e=="object"&&e!==null&&Object.entries(e).every(([t,n])=>t==="at"&&(n===void 0||typeof n=="string")||t==="signal"&&(n===void 0||n instanceof AbortSignal)),tp=()=>{const e=new xc(new ye);return[e.pipe(pl()),()=>qt({next:t=>e.value.next(t),error:t=>{e.value.error(t),e.next(new ye)},complete:()=>{e.value.complete(),e.next(new ye)}})]},np={},wa=e=>new Proxy(np,{get(t,n){return e(n)}}),nt=e=>{const t={};return wa(n=>(t[n]||(t[n]={}),wa(r=>(t[n][r]||(t[n][r]=e(n,r)),t[n][r]))))},Yn={level:pt.Incompatible,isCompatible:()=>!1,isValueCompatible:()=>!1},rp={args:Yn,value:Yn,isCompatible:()=>!1},sp={level:pt.Identical,isCompatible:()=>!0,isValueCompatible:()=>!0},Xn=e=>(t=pt.BackwardsCompatible)=>e>=t,op=(e,t,n,r)=>{let s;if(!r.entry)s=rp;else{const{args:o}=r.entry,a=l=>va(o,r.getter,l),i=e===je.Storage?l=>a(l.length===1?l[0]:l):a;if(n?.entry){const{values:l}=n.entry,{args:c,values:u}=Gh(n.entry,n.getter,r.entry,r.getter,t);s={args:{level:c.level,isValueCompatible:i,isCompatible:Xn(c.level)},value:u.level===pt.Incompatible?Yn:{level:u.level,isValueCompatible:u.level>pt.Partial?()=>!0:h=>va(l,n.getter,h),isCompatible:Xn(u.level)}}}else{const l=pt.Partial;s={args:{level:l,isValueCompatible:i,isCompatible:Xn(l)},value:n?Yn:sp}}}return e===je.Storage||e===je.Api||e===je.ViewFns?Object.assign(s,{isCompatible:Xn(Math.min(s.args.level,s.value.level))}):e===je.Tx?s.args:s.value},ip=Gn(e=>{let t=null;const n=(e?Jh(e):Promise.resolve(null)).then(s=>t=s),r=Gn(s=>{const o=new Map,a=ma(s),i=l=>nt((c,u)=>op(l,o,ya(t,l,c,u),ya(a,l,c,u)));return{tx:i(je.Tx),constants:i(je.Const),apis:i(je.Api),view:i(je.ViewFns),query:i(je.Storage),event:i(je.Event)}});return{getSyncHelpers:async s=>(await n,r(s)),getClientCompat:async(s,o,a)=>(await n,i=>r(i)[s][o][a]),getIsAsssetCompat:s=>ma(s).isAssetCompat}}),$a=({mappedMeta:e,dynamicBuilder:t},n,r)=>{const s=e.pallets[n].const.get(r);if(!s)throw new Error(`Runtime entry Constant(${n}.${r}) not found`);return t.buildConstant(n,r).dec(s.value)},ap=(e,t,n,r)=>({at:s,signal:o}={})=>We(ue([n.getRuntimeContext$(s||null),r]).pipe(x(([a,i])=>{const l=$a(a,e,t);if(i(a).isValueCompatible(l))return l;throw new Error(`Incompatible entry Const(${e}.${t})`)})),o),cp=(e,t,n,r)=>{const s=()=>new Error(`Incompatible runtime entry Event(${e}.${t})`),o=(i,l)=>n.eventsAt$(i).pipe(x(c=>c.filter(u=>u.event.type===e&&u.event.value.type===t).map(u=>{if(!l(u.event.value.value))throw s();return{original:u,payload:u.event.value.value}}))),a=ue([n.finalized$,r]).pipe(n.withRuntime(([i])=>i.hash),ca(([[i,l],c])=>{if(!c.mappedMeta.pallets[e]?.event.has(t))throw new Error(`Runtime entry Event(${e}.${t}) not found`);const{isValueCompatible:u}=l(c);return o(i.hash,u).pipe(x(h=>({block:i,events:h})))}),Zh);return{watch:()=>a,get:i=>at(ue([r,n.getRuntimeContext$(i)]).pipe(te(1),Tt(([l,c])=>o(i,l(c).isValueCompatible)))),filter:i=>i.filter(({event:l})=>l.type===e&&l.value.type===t).map(l=>({original:l,payload:l.event.value.value}))}},lp=(e,t,n,r)=>{const s=`${e}_${t}`,o=()=>new Error(`Incompatible runtime entry RuntimeCall(${s})`);return(...a)=>{const i=a[a.length-1],l=Nt(i),{signal:c,at:u}=l?i:{},h=u??null,p=ue([n.getRuntimeContext$(h),r]).pipe(z(([v,d])=>{let f;try{f=v.dynamicBuilder.buildRuntimeCall(e,t)}catch{throw new Error(`Runtime entry RuntimeCall(${s}) not found`)}const b=d(v);if(!b.args.isValueCompatible(a))throw o();return n.call$(h,s,X(f.args.enc(a))).pipe(x(f.value.dec),x(y=>{if(!b.value.isValueCompatible(y))throw o();return y}))}),n.withHodl(h));return We(p,c)}},Ea=(e,t,n,r,s)=>{let o;try{o=e.buildCall(n,r)}catch{throw new Error(`Runtime entry Tx(${n}.${r}) not found`)}if(!t(s))throw new Error(`Incompatible runtime entry Tx(${n}.${r})`);const{location:a,codec:[i]}=o;return oe([new Uint8Array(a),i(s)])},ka=(e,t,n,r)=>{const s=()=>new Error(`Incompatible runtime entry Storage(${t}.${n})`);let o;try{o=e.dynamicBuilder.buildStorage(t,n)}catch{throw s()}return(...a)=>{if(a.length===o.len&&!r(a))throw s();return o.keys.enc(...a)}},Gr=()=>new Error("Unkown signer"),up=e=>{const{extrinsic:t}=e,n=Zi(e);let r,s;if("address"in t)r=n(t.address),s=n(t.signature);else{const o=Object.fromEntries(e.lookup[t.type].params.filter(a=>a.type!=null).map(a=>[a.name,n(a.type)]));if(r=o.Address,s=o.Signature,!r||!s)throw Gr()}if(r.type==="AccountId20"&&s.type==="array"&&s.len===65&&s.value.type==="primitive"&&s.value.value==="u8")return[1,[]];if(s.type!=="enum"||["Ecdsa","Ed25519","Sr25519"].some(o=>!(o in s.value)))throw Gr();if(r.type==="enum"){const o=r.value.Id;if(o.type==="lookupEntry"&&o.value.type==="AccountId32")return[0,[o.idx]]}else if(r.type==="AccountId32")return[0,[]];throw Gr()},dp={Ed25519:0,Sr25519:1,Ecdsa:2},hp=(e,t,n,r,s,o)=>{const[a,i]=up(e),l=oe([Hr.enc({version:4,type:"signed"}),a===1?t:new Uint8Array([...i,...t]),a===1||!o?n:new Uint8Array([dp[o],...n]),...r,s]);return oe([pe.enc(l.length),l])},[Qn,bn]=["<Bytes>","</Bytes>"].map(e=>zn.fromText(e)),pp=e=>async t=>{let n=!0,r;for(r=0;n&&r<Qn.length;r++)n=Qn[r]===t[r];n=n&&r===Qn.length;const s=t.length-bn.length;for(r=0;n&&r<bn.length;r++)n=bn[r]===t[s+r];return n=n&&r===bn.length,e(n?t:oe([Qn,t,bn]))};function fp(e,t,n){return{publicKey:e,signTx:async(r,s,o,a,i=jt)=>{const l=Fn(Ti(o)),c=[],u=[];l.extrinsic.signedExtensions[0].map(({identifier:v})=>{const d=s[v];if(!d)throw new Error(`Missing ${v} signed extension`);c.push(d.value),u.push(d.additionalSigned)});const h=oe([r,...c,...u]),p=await n(h.length>256?i(h):h);return hp(l,e,p,c,r,t)},signBytes:pp(n)}}Uint8Array.from([1]);const vp=(e,t)=>{const n=e.metadata.pallets.find(o=>o.name==="System").constants.find(o=>o.name==="Version"),r=e(n.type),s=t.buildDefinition(n.type).dec;if(r.type!=="struct")throw new Error("not a struct");return s(n.value)};function bp(e){let t=0;for(;!(e&1);)t++,e>>=1;return t}const mp=e=>1<<Math.ceil(Math.log2(e)),yp=Cn(ne(2)[0],e=>{const t=Math.min(Math.max(mp(e.period),4),65536),n=e.startAtBlock%t,r=Math.max(t>>12,1),s=Math.min(Math.max(bp(t)-1,1),15),o=n/r<<4;return et[0](s|o)}),[gp]=be({tip:pe,asset:xt(ne(1/0))}),xa=new Uint8Array,Yr=Uint8Array.from([0]),Xr=e=>({value:e,additionalSigned:xa}),Qr=e=>({value:xa,additionalSigned:e}),Jr=(e,t)=>({value:e,additionalSigned:t}),wp=(e,t,n)=>{const r={};return t.metadata.extrinsic.signedExtensions[0].forEach(({identifier:s,type:o,additionalSigned:a})=>{r[s]=[o,a].map(i=>n.buildDefinition(i)[0])}),({mortality:s,tip:o=0n,nonce:a,customSignedExtensions:i={},...l})=>{const c=[],u=vp(t,n),h=v=>{const[d,f]=r[v],b=i[v];try{return mt({value:d,additionalSigned:f},(y,m)=>{const g=b?.[m];return g instanceof Uint8Array?g:y(g)})}catch{if(b)throw new Error(`Wrong input received for ${v}`);return c.push(v),null}},p=mt(r,([v,d],f)=>{if(i[f])return h(f);switch(f){case"CheckNonce":return Xr(v(a));case"CheckMortality":return s.mortal?Jr(yp({period:s.period,startAtBlock:s.startAtBlock.height}),ee(s.startAtBlock.hash)):Jr(Yr,e);case"ChargeTransactionPayment":return Xr(v(o));case"ChargeAssetTxPayment":return Xr(gp({tip:o,asset:l.asset}));case"CheckGenesis":return Qr(e);case"CheckMetadataHash":return Jr(Yr,Yr);case"CheckSpecVersion":return Qr(d(u.spec_version));case"CheckTxVersion":return Qr(d(u.transaction_version));default:return h(f)}});return c.forEach(v=>{delete p[v]}),mt(p,(v,d)=>({...v,identifier:d}))}},Sa="AccountNonceApi_account_nonce",$p={1:P.dec,2:et.dec,4:Ne.dec,8:an.dec},Ep=(e,t,n)=>e(n,Sa,t).pipe(x(r=>{const s=$p[r.length];if(!s)throw new Error(`${Sa} retrieved wrong data`);return s(r)})),kp=(e,t)=>e.pinnedBlocks$.pipe(Ws(0),x(n=>{const r=s=>{const o=n.blocks.get(s);if(!o)return null;if(o.hasNewRuntime)return o;for(const a of o.children){const i=r(a);if(i)return i}return null};return r(t)?.hash??t}),he()),xp=(e,t,n,r,s,o={})=>ue([o.nonce!=null?K(o.nonce):Sp(e,X(t.publicKey)),kp(e,r.hash).pipe(Tt(e.getRuntimeContext$)),e.genesis$]).pipe(te(1),z(([a,i,l])=>{const c=wp(ee(l),i.lookup,i.dynamicBuilder),u=o.mortality??{period:64,mortal:!0},h=c({nonce:a,tip:o.tip??0n,mortality:u.mortal?{mortal:!0,period:u.period,startAtBlock:{height:r.number,hash:r.hash}}:{mortal:!1},customSignedExtensions:s,asset:o.asset});return t.signTx(n,h,i.metadataRaw,r.number)})),Sp=(e,t)=>{const n=o=>e.newBlocks$.pipe(rn((a,i)=>i.parent===a?i.hash:a,o),Ks(o),he()),r=o=>n(o).pipe(te(2),Tt(a=>Ep(e.call$,t,a))),s=o=>ue(o.map(a=>r(a).pipe(x(i=>({success:!0,value:i})),de(i=>K({success:!1,value:i}))))).pipe(te(1));return e.pinnedBlocks$.pipe(te(1),x(({blocks:o,best:a})=>{const i=o.get(a);return[...o.values()].filter(l=>!l.pruned&&l.children.size===0&&l.number>=i.number).map(l=>l.hash)}),Tt(s),x(o=>{const a=o.reduce((i,l)=>l.success&&l.value>=(i??0)?l.value:i,null);if(a==null)throw o[0].value;return a}))};var Ip=Object.defineProperty,Bp=(e,t,n)=>t in e?Ip(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ap=(e,t,n)=>Bp(e,t+"",n);const Op=(e,t)=>new D(n=>{const r=new Map;let s,o;const a=()=>{let l=s.best,c=r.get(l),u=s.blocks.get(l).number;for(;!c;){const v=s.blocks.get(l);if(!v)break;c=r.get(l=v.parent),u--}if(!c)return;const h=u<=s.blocks.get(s.finalized).number,p=c.found.type;if(p&&o?.found&&o.hash===c.hash){h&&n.complete();return}n.next(o=c.found.type?{found:p,hash:c.hash,number:u,index:c.found.index,events:c.found.events}:{found:p,validity:c.found.validity}),h&&(p?n.complete():c.found.validity?.success===!1&&n.error(new Ia(c.found.validity.value)))},i=t.pipe(he((l,c)=>l.finalized===c.finalized&&l.best===c.best)).subscribe({next:l=>{s=l,r.size!==0&&a()},error(l){n.error(l)}});return i.add(e.subscribe({next:l=>{r.set(l.hash,l),a()},error(l){n.error(l)}})),i}).pipe(he((n,r)=>n===r)),Cp=(e,t)=>{const n=e.filter(s=>s.phase.type==="ApplyExtrinsic"&&s.phase.value===t).map(s=>({...s,...s.event})),r=n[n.length-1];return r.type==="System"&&r.value.type==="ExtrinsicFailed"?{ok:!1,events:n,dispatchError:r.value.value.dispatch_error}:{ok:!0,events:n}};class Ia extends Error{constructor(t){super(JSON.stringify(t,(n,r)=>typeof r=="bigint"?r.toString():r instanceof Uint8Array?X(r):r,2)),Ap(this,"error"),this.name="InvalidTxError",this.error=t}}const Zr=(e,t,n,r=!1)=>e.hasher$.pipe(z(s=>{const o=X(s(n)),a=(d,f)=>({type:d,txHash:o,...f}),i=e.pinnedBlocks$.state,l=d=>{if(!d.mortal)return 0;const{phase:f,period:b}=d,y=i.blocks.get(i.best).number;return Math.floor((Math.max(y,f)-f)/b)*b+f},c=d=>{let f=[...i.blocks.values()].filter(m=>!m.pruned&&!m.children.size);const b=Math.max(...f.map(({number:m})=>m));f=f.filter(({number:m})=>m>=b-1);const y=i.blocks.get(i.finalized);return f=y.children?[y,...f]:f,f.filter(m=>m.number>=d)},u=({hash:d})=>e.validateTx$(d,n),h=nn(()=>i.finalizedRuntime.runtime.pipe(x(d=>d.getMortalityFromTx(n)),x(l),x(c),z(d=>{let f;return Qe(...d.map(b=>ol(u(b),e.finalized$.pipe(Ht(y=>{if(y.number<b.number)return!0;let m=y;for(;m.number>b.number;){const g=i.blocks.get(m.parent);if(!g)return!1;m=g}return m.hash===y.hash}),kn(),qs({success:null}))))).pipe(Be((b,y)=>{if(b.success===!1&&(f??(f=new Ia(b.value))),b.success)return!0;if(y===d.length-1&&f)throw f;return!1}),te(1))}),kn())),p=new D(d=>{const f=e.trackTx$(n).subscribe(d);return f.add(t(n).subscribe({error(b){d.error(b)}})),f}),v=Op(p,e.pinnedBlocks$).pipe(x(d=>d.found?a("txBestBlocksState",{found:!0,block:{index:d.index,number:d.number,hash:d.hash},...Cp(d.events,d.index)}):a("txBestBlocksState",{found:!1,isValid:d.validity?.success!==!1})));return ct(r?K(a("signed",{})):Xe,h,K(a("broadcasted",{})),v.pipe(ep(({found:d,type:f,...b})=>d?K(a("finalized",b)):Xe)))})),Ba=async(e,t,n,r)=>Fc(Zr(e,t,n)).then(s=>{if(s.type!=="finalized")throw null;const o={...s};return delete o.type,o}),_p=un().enc,Rp=new Uint8Array(64),Tp=new Uint8Array(65),Hp=e=>()=>e?Tp:Rp,[,Mp]=be({weight:be({ref_time:Un,proof_size:Un}),class:Se({Normal:M,Operational:M,Mandatory:M}),partial_fee:Eo}),es=(e,t,n,r,s,o)=>{const a=c=>ue([n.getRuntimeContext$(c),s]).pipe(x(([u,h])=>({ctx:u,isAssetCompat:o(u),...h(u)}))),i=(c,u)=>a(u).pipe(x(({ctx:{dynamicBuilder:h,extVersions:p},isValueCompatible:v})=>{const d=Ea(h,v,e,t,c);return{callData:d,bare:oe([pe.enc(d.length+1),new Uint8Array(p.slice(-1)),d])}})),l=(c,u)=>c===void 0?K(void 0):a(u).pipe(x(({ctx:h,isAssetCompat:p})=>{if(!p(c))throw new Error("Incompatible runtime asset");const{dynamicBuilder:v,assetId:d}=h;if(d)return v.buildDefinition(d).enc(c)}));return c=>{const u=(y,{...m},g)=>ue([i(c,g.hash),l(m.asset,g.hash)]).pipe(z(([w,E])=>xp(n,y,w.callData,g,m.customSignedExtensions||{},{...m,asset:E}))),h=(y,{at:m,...g}={})=>{const w=n.pinnedBlocks$.state.blocks.get(m);return m&&!w?Rt(()=>new Error(`Uknown block ${m}`)):(w?K(w):n.finalized$).pipe(te(1),z(E=>u(y,g,E).pipe(x($=>({tx:$,block:E})))))},p=(y,m)=>at(h(y,m)).then(g=>g.tx),v=(y,m)=>at(h(y,m)).then(({tx:g,block:w})=>Ba(n,r,g,w.hash)),d=(y,m)=>h(y,m).pipe(z(({tx:g})=>Zr(n,r,g,!0))),f=async(y,m)=>{typeof y=="string"&&(y=y.startsWith("0x")?ee(y):_p(y));const g=y.length===20,w=fp(y,g?"Ecdsa":"Sr25519",Hp(g)),E=await p(w,m),$=X(oe([E,Ne.enc(E.length)])),k=n.getRuntimeContext$(null).pipe(x(B=>{try{return B.dynamicBuilder.buildRuntimeCall("TransactionPaymentApi","query_info").value[1]}catch{return Mp}})),S=n.call$(null,"TransactionPaymentApi_query_info",$);return at(ue([S,k]).pipe(x(([B,I])=>I(B))))},b=()=>at(i(c,null).pipe(x(({callData:y})=>y)));return{getPaymentInfo:f,getEstimatedFees:async(y,m)=>(await f(y,m)).partial_fee,decodedCall:{type:e,value:Dn(t,c)},getEncodedData:b,getBareTx:()=>at(i(c,null).pipe(x(({bare:y})=>y))),sign:p,signSubmitAndWatch:d,signAndSubmit:v}}},Up=(e,t,{getClientCompat:n,getSyncHelpers:r,getIsAsssetCompat:s})=>{const o=({dynamicBuilder:a,lookup:i})=>l=>{try{const{type:c,value:{type:u,value:h}}=a.buildDefinition(i.call).dec(l);return es(c,u,e,t,n("tx",c,u),s)(h)}catch{throw new Error("Invalid call data")}};return({at:a,signal:i}={})=>We(e.getRuntimeContext$(a??null).pipe(z(Gn(async l=>{const c=await r(l);return{id:l.codeHash,txFromCallData:o(l),constants:nt((u,h)=>$a(l,u,h)),query:nt((u,h)=>({getKey:ka(l,u,h,c.query[u][h].args.isValueCompatible)})),tx:nt((u,h)=>({getEncodedData:p=>Ea(l.dynamicBuilder,c.tx[u][h].isValueCompatible,u,h,p)})),compat:c}}))),i)},zp=(e,t,n,r,s)=>{const o=e==="System"&&t==="Number",a=e==="System"&&t==="BlockHash",i=n.runtime$.pipe(Be(Boolean),te(1),x(({dynamicBuilder:d})=>typeof d.buildStorage("System","Number").value.dec(new Uint8Array(32))=="bigint"?BigInt:Le),sn()),l=()=>new Error(`Incompatible runtime entry Storage(${e}.${t})`),c=d=>new Error(`Invalid Arguments calling ${e}.${t}(${d})`),u=d=>{try{return d.dynamicBuilder.buildStorage(e,t)}catch{throw new Error(`Runtime entry Storage(${e}.${t}) not found`)}},h=(...d)=>{const f=d.at(-1),b=Nt(f),[y,m]=b?[d.slice(0,-1),d.at(-1).at==="best"]:[d,!1];return n[m?"best$":"finalized$"].pipe(Kr(()=>p(...y,m?{at:"best"}:{})),rn((g,{value:w,block:E})=>g?{block:E,value:g.value.raw===w.raw?g.value:w}:{block:E,value:w},null),x(g=>({block:g.block,value:g.value.mapped})))},p=(...d)=>{const f=d[d.length-1],b=Nt(f),{at:y}=b?f:{},m=y??null,g=vt(s).pipe(z(w=>n.storage$(m,"value",E=>{const $=u(E),k=w(E),S=d.length===$.len?d:d.slice(0,-1);if(d!==S&&!b)throw c(d);if(!k.args.isValueCompatible(S))throw l();return $.keys.enc(...S)},null,(E,$)=>{const k=u($),{value:{isValueCompatible:S}}=w($),B=E===null?k.fallback:k.value.dec(E);if(!S(B))throw l();return{raw:E,mapped:B}})),n.withHodl(m));return o?n.pinnedBlocks$.pipe(x(w=>{const E=m==="finalized"||!m?w.finalized:m==="best"?w.best:m,$=w.blocks.get(E);if(!$)throw new Je(E,"System.Number");return $}),he((w,E)=>w.number===E.number),cl(i),x(([w,E])=>({block:w,value:{raw:w.number.toString(),mapped:E(w.number)}})),de(w=>{if(w instanceof Je)return g;throw w})):a&&Number(d[0])===0?ue([n.genesis$,n.pinnedBlocks$.pipe(x(w=>{const E=m==="finalized"||!m?w.finalized:m==="best"?w.best:m,$=w.blocks.get(E);if(!$)throw new Je(E,"System.BlockHash");return $}),te(1))]).pipe(x(([w,E])=>({block:E,value:{raw:w,mapped:w}}))):g},v=async(...d)=>{const f=d[d.length-1],b=Nt(f),{signal:y}=b?f:{};return We(p(...d).pipe(x(m=>m.value.mapped)),y)};return{getKey:(...d)=>at(ue([n.getRuntimeContext$(null),s]).pipe(x(([f,b])=>ka(f,e,t,b(f).args.isValueCompatible)(...d)))),getValue:v,getValues:(d,f)=>Promise.all(d.map(b=>v(...f?[...b,f]:b))),getEntries:async(...d)=>{const f=d[d.length-1],b=Nt(f),{signal:y,at:m}=b?f:{},g=m??null,w=vt(s).pipe(z(E=>n.storage$(g,"descendantsValues",$=>{const k=E($),S=u($);if(!k.isCompatible(pt.Partial))throw l();if(d.length>S.len)throw c(d);const B=d.length>0&&b?d.slice(0,-1):d;if(d.length===S.len&&B===d)throw c(d);return S.keys.enc(...B)},null,($,k)=>{const S=u(k),B=E(k),I=$.map(({key:_,value:T})=>({keyArgs:S.keys.dec(_),value:S.value.dec(T)}));if(B.value.level===pt.Partial&&I.some(({value:_})=>!B.value.isValueCompatible(_)))throw l();return I})),x(E=>E.value),n.withHodl(g));return We(w,y)},watchValue:h,watchEntries:(...d)=>{const f=d.at(-1),b=Nt(f);return r(e,t,b?d.slice(0,-1):d,b&&f.at==="best")}}},Aa="RuntimeViewFunction",Oa="execute_view_function",ts=Aa+"_"+Oa,Dp=(e,t,n,r)=>{const s=()=>new Error(`Incompatible runtime entry ViewFn(${e}.${t})`);return(...o)=>{const a=o[o.length-1],i=Nt(a),{signal:l,at:c}=i?a:{},u=c??null,h=ue([n.getRuntimeContext$(u),r]).pipe(z(([p,v])=>{let d;try{d=p.dynamicBuilder.buildRuntimeCall(Aa,Oa)}catch{throw new Error(`Runtime entry RuntimeCall(${ts}) not found`)}let f;try{f=p.dynamicBuilder.buildViewFn(e,t)}catch{throw new Error(`Runtime entry ViewFn(${e}.${t}) not found`)}const b=v(p);if(!b.args.isValueCompatible(o))throw s();const y=f.args.enc(o),m=oe([ee(p.mappedMeta.pallets[e].view.get(t).id),R.enc(y.length),y]);return n.call$(u,ts,X(m)).pipe(x(g=>{try{const w=d.value.dec(g);if(!("success"in w&&"value"in w)||!("type"in w.value)&&!(w.value instanceof Uint8Array))throw null;return w}catch{throw new Error(`Unexpected RuntimeCall(${ts}) type`)}}),x(({success:g,value:w})=>{if(!g)throw new Error(`ViewFn API Error: ${w.type}`);const E=f.value.dec(w);if(!b.value.isValueCompatible(E))throw s();return E}))}),n.withHodl(u));return We(h,l)}};var jp=Object.defineProperty,Lp=(e,t,n)=>t in e?jp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,rt=(e,t,n)=>(Lp(e,typeof t!="symbol"?t+"":t,n),n),ns=Symbol("SUSPENSE"),Vp=class extends Promise{constructor(e){super(e)}},Ca=class extends Error{constructor(){super(),this.name="NoSubscribersError"}},_a=class extends Error{constructor(){super(),this.name="EmptyObservableError"}},_e={},Jn=class extends D{constructor(e,t,n=Ee){super(r=>{const s=new Zt({next:r.next.bind(r),error:r.error.bind(r),complete:Ee});this.refCount++;let o;r.add(()=>{var a;this.refCount--,o.unsubscribe(),this.refCount===0&&(this.currentValue=_e,this.subscription&&this.subscription.unsubscribe(),n(),(a=this.subject)==null||a.complete(),this.subject=null,this.subscription=null,this.promise&&(this.promise.rej(new Ca),this.promise=null))}),this.subject?(o=this.subject.subscribe(s),this.currentValue!==_e&&r.next(this.currentValue)):(this.subject=new ye,o=this.subject.subscribe(s),this.subscription=null,this.subscription=new Zt({next:a=>{this.promise&&a!==ns&&(this.promise.res(a),this.promise=null),this.subject.next(this.currentValue=a)},error:a=>{var i;this.subscription=null;const l=this.subject;this.subject=null,this.currentValue=_e;const c=(i=this.promise)==null?void 0:i.rej;c&&a===ns&&(this.promise.rej=()=>{c(a)}),l.error(a),c&&this.promise&&(this.promise.rej=c)},complete:()=>{if(this.subscription=null,this.promise&&(this.promise.rej(new _a),this.promise=null),this.currentValue!==_e)return this.subject.complete();if(t===_e){const a=this.subject;return this.subject=null,a.error(new _a)}this.subject.next(this.currentValue=t),this.subject.complete()}}),e.subscribe(this.subscription),t!==_e&&this.currentValue===_e&&this.subject.next(this.currentValue=t))}),this.defaultValue=t,rt(this,"subject",null),rt(this,"subscription",null),rt(this,"refCount",0),rt(this,"currentValue",_e),rt(this,"promise",null),rt(this,"pipeState",(...r)=>{const s=super.pipe(...r);return s instanceof Jn?s:new Jn(s,_e)}),rt(this,"getRefCount",()=>this.refCount),rt(this,"getValue",()=>{if(this.promise)return this.promise.p;if(this.currentValue!==_e&&this.currentValue!==ns)return this.currentValue;if(this.defaultValue!==_e)return this.defaultValue;if(this.refCount===0)throw new Ca;const r=new Vp((s,o)=>{this.promise={res:s,rej:o,p:null}});return this.promise.p=r,r}),rt(this,"getDefaultValue",()=>this.defaultValue),t===_e&&delete this.getDefaultValue}};function Ra(e,t){t.getValue=e.getValue,t.getRefCount=e.getRefCount,t.pipeState=e.pipeState,e.getDefaultValue&&(t.getDefaultValue=e.getDefaultValue)}function Np(e,t){const n=new Pp,r=typeof t=="function"?t:()=>t,s=o=>{for(let h=o.length-1;o[h]===void 0&&h>-1;h--)o.splice(-1);const a=[o.length,...o],i=n.get(a);if(i!==void 0)return i;const l=new Jn(e(...o),r(...o),()=>{n.delete(a)}),c=new D(h=>{const p=n.get(a);let v=l;return p?p!==c&&(v=p,Ra(v,c)):n.set(a,u),v.subscribe(h)});Ra(l,c);const u=c;return n.set(a,u),u};return(...o)=>s(o)}var Pp=class{constructor(){rt(this,"root"),this.root=new Map}get(e){let t=this.root;for(let n=0;n<e.length;n++)if(t=t.get(e[n]),!t)return;return t}set(e,t){let n=this.root,r;for(r=0;r<e.length-1;r++){let s=n.get(e[r]);s||(s=new Map,n.set(e[r],s)),n=s}n.set(e[r],t)}delete(e){const t=[this.root];let n=this.root;for(let s=0;s<e.length-1;s++)t.push(n=n.get(e[s]));let r=t.length-1;for(t[r].delete(e[r]);--r>-1&&t[r].get(e[r]).size===0;)t[r].delete(e[r])}};function Fp(e,t){return new Jn(e,t)}var rs=(...e)=>(typeof e[0]=="function"?Np:Fp)(e[0],e.length>1?e[1]:_e);const Ta=(e,t,n)=>{const r=new Map(t.map(i=>[i.key,i])),s=new Map(e.map(i=>[i.key,i])),o=new Map,a=[];return t.forEach(i=>{const{key:l}=i,c=s.get(l);(!c||c.value!==i.value)&&o.set(l,n(i))}),e.forEach(i=>{r.has(i.key)||a.push(i)}),{deltas:{deleted:a,upserted:[...o.values()]},entries:t.map(({key:i})=>o.get(i)??s.get(i))}},Ha=(e,t,n,r=!1)=>{try{let s=r?e:n.blocks.get(e).parent;for(;s&&!t[s];)s=n.blocks.get(s).parent;return s?t[s]:null}catch{return null}},Wp=(e,t)=>n=>{const{keys:r,value:s}=n.dynamicBuilder.buildStorage(e,t);return o=>(o.dec={value:s.dec(o.value),args:r.dec(o.key)},o)},qp=(e,t,n)=>{const r=rs((i,l,c)=>{const u=Wp(i,l),h=(b,y)=>{const m=Ah(e,y.hash).pipe(Be(g=>!g),te(1));return t(y.hash,"closestDescendantMerkleValue",()=>c).pipe(z(g=>{const w=g.value;return w===b?.rootHash?K({...b,block:y,deltas:null,prev:b.block.hash}):t(y.hash,"descendantsValues",()=>c).pipe(n(()=>y.hash),x(([E,$])=>[E.value,u($)]),x(([E,$])=>({prev:b&&b.block.hash,rootHash:w,block:y,patcher:$,...Ta(b?.entries??[],E,$)})))}),dr(m),de(g=>g instanceof Je?Xe:Rt(()=>g)))},p=e.pipe(he((b,y)=>b.finalized===y.finalized),Kr(({blocks:b,finalized:y})=>h(null,b.get(y))),te(1),x(b=>({blocks:{[b.block.hash]:b},finalized:b.block.hash}))),[v,d]=tp(),f=e.pipe(he((b,y)=>b.best===y.best),Gs(v),Kr(([b,y])=>{const{best:m}=b,{blocks:g}=y;let w=g[m]?null:m;if(!w)return Xe;const E=Ha(w,g,b);return E?h(E,b.blocks.get(w)).pipe(x($=>(g[w]=$,y))):(w=b.finalized,h(g[y.finalized],b.blocks.get(w)).pipe(x($=>($.prev=null,{blocks:{[w]:$},finalized:w}))))}));return Qe(p,f).pipe(d())}),s=i=>(l,c,u)=>{const h=r(l,c,u),p=i?"finalized":"best";return ue([h,e.pipe(he((v,d)=>v[p]===d[p]))]).pipe(x(([v,d])=>{const f=Ha(d[p],v.blocks,d,!0);return f&&{update:f,state:v}}),Be(Boolean),he((v,d)=>v.update===d.update),Ks(null),hl(),z(([v,d])=>{if(!v)return[d.update];const{update:f}=v,{state:b,update:y}=d;let m=y;const g=[];for(;m&&m.block.number>f.block.number;)g.unshift(m),m=m.prev?b.blocks[m.prev]:null;if(i&&(b.finalized=y.block.hash,g.length)){const{blocks:w}=b;Object.keys(w).forEach(E=>{w[E].block.number<g[0].block.number&&delete w[E]})}return f===m?g:[{...y,...f.rootHash===y.rootHash?{entries:f.entries,deltas:null}:Ta(f.entries,y.entries,y.patcher)}]}))},o=rs(s(!0)),a=rs(s(!1));return(i,l,c,u)=>{const h=u?a:o;return e.pipe(te(1),z(p=>p.runtimes[p.blocks.get(p[u?"best":"finalized"]).runtime].runtime),x(p=>p.dynamicBuilder.buildStorage(i,l).keys.enc(...c))).pipe(te(1),z(p=>h(i,l,p)),x(({block:{hash:p,number:v,parent:d},deltas:f,entries:b},y)=>{const m=y>0?f:{deleted:[],upserted:b};return{block:{hash:p,number:v,parent:d},entries:b.map(ss),deltas:m&&{deleted:m.deleted.map(ss),upserted:m.upserted.map(ss)}}}))}},ss=e=>e.dec,Kp=/^(?:0x)?((?:[0-9a-fA-F][0-9a-fA-F])+)$/,Ma=(e,t,n)=>{const r=ip(n),{getClientCompat:s,getIsAsssetCompat:o}=r,a=Up(e,t,r),i=qp(e.pinnedBlocks$,e.storage$,e.withRuntime),l=nt((d,f)=>zp(d,f,e,i,s("query",d,f))),c=nt((d,f)=>es(d,f,e,t,s("tx",d,f),o)),u=nt((d,f)=>cp(d,f,e,s("event",d,f))),h=nt((d,f)=>ap(d,f,e,s("constants",d,f))),p=nt((d,f)=>lp(d,f,e,s("apis",d,f))),v=nt((d,f)=>Dp(d,f,e,s("view",d,f)));return{tx:c,constants:h,apis:p,view:v,query:l,event:u,txFromCallData:(d,{at:f,signal:b}={})=>We(e.getRuntimeContext$(f??null).pipe(x(({dynamicBuilder:y,lookup:m})=>{try{const{type:g,value:{type:w,value:E}}=y.buildDefinition(m.call).dec(d);return es(g,w,e,t,s("tx",g,w),o)(E)}catch{throw new Error("createTx: invalid call data")}})),b),getStaticApis:a}};function Gp(e,{getMetadata:t,setMetadata:n}={}){const r=Ul(e),s=Bh(r,{getMetadata:t?B=>vt(t(B)):void 0,setMetadata:n}),{getChainSpecData:o}=r,a=B=>(I,..._)=>ue([B(I,..._),c.header$(I).pipe(x(({number:T,parentHash:L})=>({hash:I,number:T,parent:L,hasNewRuntime:!1})))]).pipe(x(([T,L])=>({value:T,block:L}))),{genesis$:i,...l}=s.chainHead$(),c=s.archive(l.getRuntime$),u={...l,genesis$:nn(o).pipe(x(({genesisHash:B})=>B),de(()=>i),sn(1)),storage$:Vt(l.storage$,a(c.storage$)),body$:Vt(l.body$,c.body$),call$:Vt(l.call$,c.call$),header$:Vt(l.header$,c.header$),eventsAt$:Vt(l.eventsAt$,c.eventsAt$),storageQueries$:Vt(l.storageQueries$,c.storageQueries$),getRuntimeContext$:Vt(l.getRuntimeContext$,c.getRuntimeContext$)},h=r.request,p=(B,I,_)=>new D(T=>{let L=null,Z=null;const ce=()=>{Z!=null&&r.request(I,[Z])};return r._request(B,_,{onSuccess:($e,ot)=>{if(Z=$e,T.closed){ce();return}L=ot(Z,{next:At=>T.next(At),error:At=>T.error(At)})},onError($e){T.error($e)}}),()=>{ce(),L?.()}});let v;const d=new WeakMap,{broadcastTx$:f}=s,b=B=>u.getRuntimeContext$(B).pipe(x(I=>I.metadataRaw)),{holdBlock:y,finalized$:m,bestBlocks$:g,body$:w,header$:E,storage$:$,unfollow:k}=u,S={getChainSpecData:o,getMetadata$:b,getMetadata:(B,I)=>We(b(B),I),blocks$:u.newBlocks$,hodlBlock:B=>y(B,!0),finalizedBlock$:m,getFinalizedBlock:()=>at(m),bestBlocks$:u.bestBlocks$,getBestBlocks:()=>at(g),getBlockBody$:w,getBlockBody:(B,I)=>We(w(B),I),getBlockHeader$:E,getBlockHeader:(B,I)=>We(E(B),I),submit:(...B)=>Ba(u,f,...B),submitAndWatch:B=>Zr(u,f,B),getTypedApi:B=>{if(d.has(B))return d.get(B);const I=Ma(u,f);return d.set(B,I),I},getUnsafeApi:()=>(v??(v=Ma(u,f)),v),rawQuery:(B,{at:I,signal:_}={})=>We($(I??null,"value",()=>{const T=B.match(Kp)?.[1];return T?`0x${T}`:X(zn.fromText(B))}).pipe(x(T=>T.value)),_),destroy:()=>{k(),s.destroy()},_request:h,_subscribe:p};return S.___INTERNAL_DO_NOT_USE=u,S}const st={body:"",call:"",continue:"",follow:"",header:"",stopOperation:"",storage:"",unfollow:"",unpin:""},os={body:"",call:"",finalizedHeight:"",genesisHash:"",hashByHeight:"",header:"",stopStorage:"",storage:""},is={broadcast:"",stop:""},Ua={chainName:"",genesisHash:"",properties:""};Object.entries({chainHead:st,chainSpec:Ua,transaction:is,archive:os}).forEach(([e,t])=>{Object.keys(t).forEach(n=>{t[n]=`${e}_v1_${n}`})});const Zn=sn({refCount:!0,bufferSize:1}),Yp=({allHeads$:e,finalized$:t,getHeader$:n,hasher$:r,getRecursiveHeader:s})=>{const o={blocks:new Map,prevFin:"",finalized:"",best:""},a=($,k=[])=>(k.push($),o.blocks.get($).children.forEach(S=>{a(S,k)}),k),i=$=>{const{blocks:k}=o,{hash:S,parent:B}=$,I={...$,children:new Set,usages:new Set};return k.set(S,I),k.get(B)?.children.add(S),I},l=()=>{o.best=o.finalized;let $=0;const{finalized:k,blocks:S}=o;a(k).map(B=>S.get(B)).forEach(B=>{B.number>$&&($=B.number,o.best=B.hash)})},c=new Map,u=$=>{const k=[...c.get($).children];c.delete($),k.forEach(u)},h=($,k=[])=>{const S=c.get($);return S.header&&(k.push(S.header),S.children.forEach(B=>{h(B,k)})),k},p=new ye,v=$=>p.error($),d=t.pipe(Fs(($,k)=>{const{hash:S}=$;return k||(i($),o.finalized=o.best=$.hash),o.blocks.has(S)?K(S):p.pipe(Be(B=>B===S),Ws(0),te(1))}),bt());e.subscribe($=>{const{parent:k,hash:S,number:B}=$;o.blocks.has(S)||!B||(o.blocks.has(k)?(i($),p.next(S)):(c.set(S,{hash:$.hash,header:$,children:new Set}),c.has(k)||(c.set(k,{hash:k,header:null,children:new Set}),s(k).pipe(Ht(I=>{let _=c.get(I.hash);if(!_)return!1;_.header=I;const T=o.blocks.get(o.finalized);if(T&&I.number<=T.number){for(;c.has(_.header?.parent??"");)_=c.get(_.header.parent);return u(_.hash),!1}if(o.blocks.has(I.parent)){let Z=o.blocks.get(I.parent);const ce=Z.number-T.number;for(let $e=0;$e<ce;$e++){const ot=o.blocks.get(Z.parent);if(!ot)break;Z=ot}return Z===T?h(I.hash).forEach($e=>{c.delete($e.hash),i($e),p.next($e.hash)}):u(I.hash),!1}const L=c.get(I.parent);return L?(L.children.add(I.hash),!1):(c.set(I.parent,{hash:I.parent,header:null,children:new Set([I.hash])}),!0)})).subscribe({error:v})),c.get(k).children.add(S)))},v);const f=()=>{const $=[],k=[],{blocks:S,finalized:B,prevFin:I}=o;let _=S.get(B),T=S.get(_.parent);for(;T&&(k.push(_.hash),T.children.forEach(L=>{L!==_.hash&&a(L,$)}),_=T,_.hash!==I);)T=S.get(_.parent);return k.reverse(),{event:"finalized",prunedBlockHashes:$,finalizedBlockHashes:k}};let b=new Set;const y=$=>{const k=o.blocks.get($);return b.forEach(S=>{k.usages.add(S)}),{event:"newBlock",blockHash:$,parentBlockHash:k.parent,newRuntime:k.hasUpgrade?{}:null}},m=($,k)=>{const{blocks:S}=o,B=S.get($);if(!B||B.usages.size>0)return;const{parent:I,children:_}=B;k!==!0&&_.forEach(T=>m(T,!1)),k!==!1&&m(I,!0),(!S.has(I)||!B.children.size)&&(S.get(I)?.children.delete($),S.delete($))},g=Qe(p.pipe(x($=>({type:"new",value:o.blocks.get($)}))),d.pipe(x($=>({type:"fin",value:$})))).pipe(z($=>{if($.type==="new"){const B=$.value,{hash:I}=B;i(B);const _=[y(I)];return B.number>o.blocks.get(o.best).number&&(o.best=I,_.push({event:"bestBlockChanged",bestBlockHash:I})),_}o.prevFin=o.finalized,o.finalized=$.value;let k=o.best;l();const S=[f()];return k!==o.best&&S.unshift({event:"bestBlockChanged",bestBlockHash:o.best}),S}),bt()),w=nn(()=>o.blocks.size?[null]:d.pipe(te(1),x(()=>null))).pipe(Zn),E=d.pipe(x($=>o.blocks.get($)),Zn);return Qe(g,E).subscribe({error:v}),{clean:()=>{c.clear(),o.blocks.clear()},upstream:$=>{const k=()=>{const{blocks:I,finalized:_}=o,T=[];let L=I.get(_);for(;L&&T.length<10;)T.push(L.hash),L.usages.add($),L=I.get(L.parent);return T.reverse(),{event:"initialized",finalizedBlockHashes:T}},S=I=>{const _=o.blocks.get(I);_&&(_.usages.delete($),m(I))},B=w.pipe(z(()=>{const{best:I,finalized:_}=o,T=a(_).slice(1).map(y);return T.push({event:"bestBlockChanged",bestBlockHash:I}),[k(),...T]}));return{blocks$:ct(B,g).pipe(qt({subscribe:()=>{b.add($)},finalize:()=>{b.delete($)}}),bt()),getHeader:I=>o.blocks.get(I)?.header??null,isPinned:I=>!!o.blocks.get(I)?.usages.has($),unpin:S}},finalized$:E,getHeader$:$=>{const k=o.blocks.get($);return k?K(k):n($)},hasher$:r}},za=e=>({parentHash:t,number:n,stateRoot:r,extrinsicsRoot:s,digest:o})=>{const a=Number(n),i=o.logs.map(ee),l=oe([ee(t),pe.enc(a),ee(r),ee(s),pe.enc(o.logs.length),...i]);return{parent:t,hash:X(e(l)),number:a,hasUpgrade:i.some(([c])=>c===8),header:X(l)}},Da=[jt,jn],Xp=Da.map(za),Qp=e=>{throw new Error("Hasher not supported")},Jp=e=>t=>Da[Xp.findIndex(n=>n(e).hash===t)]||Qp,ja=e=>t=>new D(n=>{let r,s=[],o=!1;const a=new _t;return a.add(t.subscribe({next(i){s?s.push(i):n.next([r,i])},error(i){n.error(i)},complete(){s?o=!0:n.complete()}})),a.add(e.subscribe({next(i){if(r=i,s){const l=[...s];s=null,l.forEach(c=>n.next([r,c]))}o&&n.complete()},error(i){n.error(i)},complete(){s&&n.error(new Error("Empty complete"))}})),a}),Zp={},ef=(e,t)=>{const n=new ye,r=n.pipe(z(h=>t("chain_getBlockHash",[h.number]).pipe(x(Jp(h)))),Zn),s=r.pipe(x(za),Zn),o=ys(ja(s),x(([h,p])=>h(p))),a=(h,p,v=!1)=>new D(d=>{const f=m=>{d.error(m)};let b=null,y=v;return e(h,[],{onSuccess:(m,g)=>{const w=g(m,{next:$=>{y&&(y=!1,n.next($),n.complete()),d.next($)},error:f}),E=()=>{w();try{e(p,[m],{onError:N,onSuccess:N})}catch{}};b!==null?E():b=E},onError(){f(Zp)}}),()=>{b?.(),b=N}}).pipe(o),i=a("chain_subscribeAllHeads","chain_unsubscribeAllHeads"),l=a("chain_subscribeFinalizedHeads","chain_unsubscribeFinalizedHeads",!0),c=h=>t("chain_getHeader",[h]).pipe(o),u=h=>c(h).pipe(z(p=>ct(K(p),u(p.parent))));return{allHeads$:i,finalized$:l,hasher$:r,getRecursiveHeader:u,getHeader$:c}},tf=(e,t)=>Yp(ef(e,t)),nf=e=>(t,n)=>e("state_getReadProof",[[n],t]).pipe(z(r=>{const s=Gi(r.proof);if(!s)throw new Error("Invalid Proof");const{rootHash:o,proofs:a}=s;let i=o,l=a[i],c=2;do{const u=a[i];if(!u||u.type==="Raw")break;if(l=u,i=void 0,!l.partialKey.startsWith(n.slice(c,c+l.partialKey.length)))return[];if(c+=l.partialKey.length,(l.type==="LeafWithHash"||l.type==="BranchWithHash")&&a[l.value]){i=l.value;continue}if("children"in l){const h=Object.entries(l.children).find(([,p])=>a[p]);if(h){if(h[0]!==n[c++])return[];i=h[1]}}}while(i);return[l.hash]})),rf=e=>{const t=(m,g,w,E)=>e(m,g,{onSuccess:w,onError:E}),n=(m,g)=>new D(w=>t(m,g,E=>{w.next(E),w.complete()},E=>{w.error(E)}));let r=null;const s=()=>(r??(r=tf(e,n)),{...r,getBlocks:r.upstream}),o=()=>r?.clean(),a=(m,g,w)=>n("state_call",[g,w,m]),i=(m,g)=>{const w=$=>n("state_getKeysPaged",[g,1e3,$||void 0,m]).pipe(z(k=>{const S=k[0]===$?k.slice(1):k,B=k.length<1e3?Xe:w(k.at(-1));return Qe(K(S),B)})),E=($,k=0)=>$.length?n("state_queryStorageAt",[$,m]).pipe(x(([{changes:S}])=>S),de(S=>{if(k>3)throw S;const B=Math.floor($.length/2);return Qe(E($.slice(0,B),++k),E($.slice(B),k))})):Xe;return w().pipe(z($=>E($)))},l=(m,g)=>i(m,g).pipe(ja(s().hasher$),x(([w,E])=>E.map(([$,k])=>[$,X(w(ee(k)))]))),c=nf(n),[u,h]=["state_getStorage","state_getStorageHash"].map(m=>(g,w)=>n(m,[w,g])),p=n("rpc_methods",[]),v=n("system_name",[]),d=n("system_properties",[]),f=m=>n("chain_getBlock",[m]),b=m=>n("chain_getBlockHash",[m]),y=b(0);return{subscribeBlocks:s,getBlockHash$:b,stgValue:u,stgHash:h,stgDescendantValues:i,stgDescendantHashes:l,stgClosestDescendant:c,runtimeCall:a,getBody:f,chainName:v,properties:d,genesisHash:y,methods:p,request:t,obsRequest:n,clean:o}};let sf=1;const Jt=()=>`${sf++}${Date.now()}`,of=new Set(["value","hash","closestDescendantMerkleValue","descendantsValues","descendantsHashes"]),La=e=>Array.isArray(e)&&e.every(t=>typeof t=="object"&&typeof t.key=="string"&&of.has(t.type)),Va=(e,t,n)=>Qe(...n.map(({key:r,type:s})=>{switch(s){case"value":return e.stgValue(t,r).pipe(Be(Boolean),x(o=>[{key:r,value:o}]));case"hash":return e.stgHash(t,r).pipe(Be(Boolean),x(o=>[{key:r,hash:o}]));case"descendantsValues":return e.stgDescendantValues(t,r).pipe(x(o=>o.map(([a,i])=>({key:a,value:i}))));case"descendantsHashes":return e.stgDescendantHashes(t,r).pipe(x(o=>o.map(([a,i])=>({key:a,hash:i}))));case"closestDescendantMerkleValue":return e.stgClosestDescendant(t,r).pipe(Be(Boolean),x(o=>[{key:r,closestDescendantMerkleValue:o}]))}})),mn=e=>e instanceof Error?e.message:typeof e=="string"?e:"Unhandled exception",{body:af,call:cf,finalizedHeight:lf,genesisHash:uf,hashByHeight:df,header:hf,stopStorage:pf,storage:ff}=os,vf=(e,t,n,r)=>{const s=new Map,o=(i,l,c)=>{const u=Jt();i(u);const h=v=>{r("archive_v1_storageEvent",u,v)},p=Va(e,l,c).pipe(lr(()=>{s.delete(u)})).subscribe(v=>{v.forEach(d=>h({event:"storage",...d}))},v=>{h({event:"storageError",error:mn(v)})},()=>{h({event:"storageDone"})});p.closed||s.set(u,p)},a=(i,l,c)=>{const u=f=>{t(i,f)},h=f=>{f.subscribe({next:u,error:b=>{n(i,b.code??-1,mn(b))}})},[p,v,d]=c;switch(l){case af:return h(e.getBody(p).pipe(x(({block:f})=>f.extrinsics)));case cf:return h(e.runtimeCall(p,v,d).pipe(x(f=>({success:!0,value:f}))));case lf:return h(e.subscribeBlocks().finalized$.pipe(x(f=>f.number),te(1)));case uf:return h(e.genesisHash);case df:return h(e.getBlockHash$(p).pipe(x(f=>[f])));case hf:return h(e.subscribeBlocks().getHeader$(p).pipe(x(f=>f.header)));case pf:{const f=s.get(p);return f?f.unsubscribe():n(i,-32602,"Invalid args")}case ff:return La(v)?o(u,p,v):n(i,-32602,"Invalid args")}throw null};return a.stop=()=>{[...s].forEach(([,i])=>i.unsubscribe()),s.clear()},a},bf=(e,t,n)=>(r,s)=>{const[,,o]=s.split("_"),a=e[o];if(!a)throw null;a.subscribe(i=>{t(r,i)},()=>{n(r,-32602,"Invalid")})},{stop:mf,broadcast:yf}=is,gf=(e,t)=>{const n=new Map,r=(s,o,a)=>{if(o===mf){const[i]=a;n.get(i)?.unsubscribe(),n.delete(i),t(s,null)}else if(o===yf){const i=Jt();n.set(i,e.obsRequest("author_submitExtrinsic",a).pipe(de((l,c)=>ct(En(5e3),c)),dr(e.subscribeBlocks().finalized$.pipe(kn(),de(()=>(n.delete(i),[null]))))).subscribe()),t(s,i)}else throw null};return r.stop=()=>{n.forEach(s=>s.unsubscribe()),n.clear()},r},{follow:wf,header:$f,storage:Na,body:as,call:Pa,unfollow:Ef,stopOperation:kf,unpin:xf}=st,Sf=(e,t,n,r)=>{const s=new Map,o=d=>{if(s.size===2)return n(d,-32800,"Limit reached");const f=Jt(),b=E=>r("chainHead_v1_followEvent",f,E),y=e.subscribeBlocks().getBlocks(f),m=new Map;s.set(f,{id:f,up:y,operations:m,cleanUp:()=>{w()}}),t(d,f);let g=null,w=()=>{w=N,g?.unsubscribe(),g=null,m.forEach(E=>{E()}),m.clear(),s.delete(f)};g=y.blocks$.subscribe({next(E){b(E)},error(){w(),b({event:"stop"})}}),g.closed&&(g=null)},a=(d,f)=>{s.get(f)?.cleanUp(),t(d,"null")},i=(d,f,b)=>{const y=s.get(f)?.operations.get(b);y&&y(),t(d,"null")},l=({up:{getHeader:d}},f,b)=>f(d(b)),c=({up:{unpin:d}},f,b)=>{(typeof b=="string"?[b]:b).forEach(d),f(null)},u=({operations:d,id:f},b,y,m,g)=>{const w=Jt();b({result:"started",operationId:w});const E=(k,S=!1)=>r(Pa,f,S?{operationId:w,event:"operationError",error:k}:{operationId:w,event:"operationCallDone",output:k}),$=e.runtimeCall(y,m,g).subscribe(k=>{d.delete(w),E(k)},k=>{d.delete(w),E(mn(k),!0)});$.closed||d.set(w,()=>{$.unsubscribe(),d.delete(w)})},h=({operations:d,id:f},b,y)=>{const m=Jt();b({result:"started",operationId:m});const g=e.getBody(y).subscribe(({block:{extrinsics:w}})=>{d.delete(m),r(as,f,{event:"operationBodyDone",operationId:m,value:w})},w=>{d.delete(m),r(as,f,{event:"operationError",operationId:m,error:mn(w)})});g.closed||d.set(m,()=>{g.unsubscribe(),d.delete(m)})},p=({operations:d,id:f},b,y,m)=>{const g=Jt();b({result:"started",operationId:g});const w=$=>{r(Na,f,$)},E=Va(e,y,m).pipe(lr(()=>{d.delete(g)})).subscribe($=>{w({event:"operationStorageItems",operationId:g,items:$})},$=>{w({event:"operationError",operationId:g,error:mn($)})},()=>{w({event:"operationStorageDone",operationId:g})});E.closed||d.set(g,()=>{E.unsubscribe()})},v=(d,f,b)=>{if(f===wf)return o(d);const[y,...m]=b,g=s.get(y);if(!g)return n(d,-32602,"Ivalid followSubscription");const w=E=>{t(d,E)};switch(f){case Ef:return a(d,y);case kf:return i(d,y,m[0]);case xf:{const[E]=m;return(Array.isArray(E)?E:[E]).some($=>typeof $!="string")?n(d,-32602,"Invalid args"):c(g,w,E)}default:{const[E,...$]=m;if(!g.up.isPinned(E))return n(d,-32801,"Block not pinned");switch(f){case $f:return l(g,w,E);case as:return h(g,w,E);case Pa:{const[k,S]=$;return typeof k!="string"||typeof S!="string"?n(d,-32602,"Invalid args"):u(g,w,E,k,S)}case Na:{const[k]=$;return La(k)?p(g,w,E,k):n(d,-32602,"Invalid args")}}}}throw null};return v.stop=()=>{s.forEach(d=>{d.cleanUp()})},v},Fa=new Set([st,Ua,os,is].map(e=>Object.values(e)).flat()),If=e=>(t,n)=>{let r=N,s=N;const o=e(b=>{s(b)},b=>{r(),n(b)}),{disconnect:a,request:i}=fr(b=>(s=b,o),t),l=rf(i),c=b=>t({jsonrpc:"2.0",...b}),u=(b,y)=>{c({id:b,result:y})},h=(b,y,m)=>{c({id:b,error:{code:y,message:m}})},p=(b,y,m)=>{c({method:b,params:{subscription:y,result:m}})},v={chainSpec:()=>bf(l,u,h),chainHead:()=>Sf(l,u,h,p),archive:()=>vf(l,u,h,p),transaction:()=>gf(l,u)},d={},f=b=>b in d?d[b]:b in v?d[b]=v[b]():null;return r=()=>{d.chainHead?.stop(),d.archive?.stop(),d.transaction?.stop(),l.clean()},{send:b=>{if(!b)return;const{id:y,method:m,params:g}=b;if(y!==null&&typeof y!="string"&&typeof y!="number"||typeof m!="string"){console.warn(`Invalid message:
|
|
4
|
-
${JSON.stringify(b)}`);return}if(m==="rpc_methods")return l.methods.subscribe(({methods:$})=>{u(y,{methods:[...Fa,...$.filter(k=>!Fa.has(k))]})},$=>{console.error($),h(y,-32602,"Invalid")});const[w]=m.split("_"),E=f(w);if(E)try{return E(y,m,g)}catch($){if($!==null)throw $}l.request(m,g,$=>{u(y,$)},$=>{h(y,$?.code||-1,$?.message||"")})},disconnect:()=>{r(),a()}}},{follow:Bf,unfollow:Af}=st,Wa=()=>({latest:Date.now(),count:0}),Of=e=>(t,n)=>{const r=new Map,s=new Map,o=new Set;let a=Wa();const i=()=>{[r,s,o].forEach(h=>{h.clear()})},l=()=>{u(),i(),n()},{send:c,disconnect:u}=e(h=>{if("id"in h){const{id:p,result:v}=h;if(s.get(p)){s.delete(p);const d=r.get(v);if(d){r.delete(v),t(h),t(d);return}o.add(v);const f=o.size+s.size;if(f>2)console.warn(`Too many chainHead follow subscriptions (${f})`);else if(h.error){console.warn(`chainHead follow failed on the ${f} sub`),l();return}}}else{const{subscription:p,result:v}=h.params;if(v?.event==="stop"){const d=Date.now()-a.latest;a.latest+=d,a.count=d<1e3?a.count+1:1,o.has(p)?o.delete(p):r.set(p,h)}}t(h),a.count>2&&(a=Wa(),l())},h=>{i(),n(h)});return{send(h){const{method:p}=h;p===Bf?s.set(h.id,h):p===Af&&o.delete(h.params[0]),c(h)},disconnect:u}},{follow:Cf,unpin:_f,unfollow:Rf}=st,Tf=e=>(t,n)=>{const r=new Set,s=new Map,o=new Map,a=c=>(...u)=>{[r,s,o].forEach(h=>{h.clear()}),c(...u)},{send:i,disconnect:l}=e(c=>{if("id"in c){t(c);const{id:u,result:h}=c;if(r.has(u)){r.delete(u),s.set(h,new Set),o.set(h,new Map);return}}else{const{subscription:u}=c.params,h=s.get(u),p=o.get(u);if(h){const v=c.params.result,{event:d}=v;if(d==="initialized"&&v.finalizedBlockHashes.forEach(f=>{h.add(f)}),d==="newBlock"){const{parentBlockHash:f}=v;if(!h.has(f)){const m=p.get(f)??[];m.push(c),p.set(f,m);return}const b=v.blockHash;h.add(v.blockHash),t(c);const y=p.get(b);y&&(p.delete(b),y.forEach(m=>{h.add(m.params.result.blockHash),t(m)}));return}d==="stop"&&(h.delete(u),o.delete(u))}t(c)}},a(n));return{send:c=>{const u=c.params[0];switch(c.method){case Cf:r.add(c.id);break;case _f:const[h,p]=c.params;p.forEach(v=>{s.get(h)?.delete(v),o.get(h)?.delete(v)});break;case Rf:s.delete(u),o.delete(u);break}i(c)},disconnect:a(l)}},{follow:Hf,unpin:Mf,unfollow:Uf}=st,zf=e=>(t,n)=>{const r=new Set,s=new Map,o=new Map,a=c=>(...u)=>{[r,s,o].forEach(h=>{h.clear()}),c(...u)},{send:i,disconnect:l}=e(c=>{if("id"in c){t(c);const{id:u,result:h}=c;if(r.has(u)){r.delete(u),s.set(h,new Set),o.set(h,new Map);return}}else{const{subscription:u}=c.params,h=s.get(u),p=o.get(u);if(h){const v=c.params.result,{event:d}=v;if(d==="initialized"&&v.finalizedBlockHashes.forEach(f=>{h.add(f)}),d==="finalized"&&(v.prunedBlockHashes=v.prunedBlockHashes.filter(f=>h.has(f))),d==="newBlock"){h.add(v.blockHash);const f=v.blockHash,b=p.get(f);if(b){p.delete(f),t(c),Promise.resolve().then(()=>{t(b)});return}}if(d==="bestBlockChanged"){const f=v.bestBlockHash;if(!h.has(f)){o.get(u).set(f,c);return}}d==="stop"&&(h.delete(u),o.delete(u))}t(c)}},a(n));return{send:c=>{const u=c.params[0];switch(c.method){case Hf:r.add(c.id);break;case Mf:const[h,p]=c.params;p.forEach(v=>{s.get(h)?.delete(v),o.get(h)?.delete(v)});break;case Uf:s.delete(u),o.delete(u);break}i(c)},disconnect:a(l)}},{follow:Df,body:jf,call:Lf,storage:Vf,unfollow:Nf,stopOperation:Pf}=st,Ff=new Set(["BodyDone","CallDone","StorageDone","Inaccessible","Error"].map(e=>"operation"+e)),qa=e=>Ff.has(e.params?.result?.event),Wf=e=>(t,n)=>{const r=new Set,s=new Map,o=new Map,a=new Map,i=u=>(...h)=>{[r,s,o,a].forEach(p=>{p.clear()}),u(...h)},{send:l,disconnect:c}=e(u=>{if("id"in u){t(u);const{id:h,result:p}=u;if(r.has(h)){r.delete(h),o.set(p,new Set),a.set(p,new Map);return}const v=s.get(h);if(v!==void 0){s.delete(h);const d=u.result?.operationId;if(d!==void 0&&o.has(v)){const f=o.get(v);f.add(d);const b=a.get(v)?.get(d);b&&(b.forEach(t),a.get(v).delete(d),qa(b.at(-1))&&f.delete(d))}}}else{const{subscription:h,result:p}=u.params,v=o.get(h);if(v){const{operationId:d}=u.params.result;if(d!==void 0)if(v.has(d))qa(u)&&v.delete(d);else{const f=a.get(h),b=f.get(d)??[];b.push(u),f.set(d,b);return}else p?.event==="stop"&&(o.delete(h),a.delete(h))}t(u)}},i(n));return{send:u=>{const h=u.params[0];switch(u.method){case Df:r.add(u.id);break;case jf:case Lf:case Vf:s.set(u.id,h);break;case Nf:o.delete(h),a.delete(h);break;case Pf:o.get(h)?.delete(u.params[1])}l(u)},disconnect:i(c)}},qf=e=>(t,n)=>e(r=>{const s=r.params?.result;if(!("id"in r)&&s){const{prunedBlockHashes:o,finalizedBlockHash:a,event:i}=s;i==="finalized"&&Array.isArray(o)?s.prunedBlockHashes=[...new Set(s.prunedBlockHashes)]:i==="initialized"&&a&&(s.finalizedBlockHashes=[s.finalizedBlockHash],delete s.finalizedBlockHash)}t(r)},n),Kf=e=>(...t)=>{const{send:n,disconnect:r}=e(...t);return{send:s=>{const{method:o,params:a,id:i,...l}=s;o==st.unpin&&a&&Array.isArray(a[1])?a[1].forEach((c,u)=>{n({...l,id:u===0?i:`${i}-patched-${u}`,method:o,params:[a[0],c]})}):n(s)},disconnect:r}},cs=(...e)=>t=>e.reduce((n,r)=>r(n),t),Ka=e=>({jsonrpc:"2.0",...e}),Gf=(e,t,n,r={})=>Ka({method:"chainHead_v1_followEvent",params:{subscription:e,result:{event:t,operationId:n,...r}}}),Yf=new Set(["newBlock","bestBlockChanged","stop"]),Xf=cs(Wf,Kf,qf,Tf,zf,e=>(t,n)=>{const r=new Set,s=new Map,o=l=>(...c)=>{[r,s].forEach(u=>{u.clear()}),l(...c)},{send:a,disconnect:i}=e(l=>{if("id"in l){const{id:c,result:u}=l;r.has(c)&&(r.delete(c),s.set(u,()=>{s.delete(u)}))}else{const{subscription:c}=l.params,u=s.get(c);if(u){const h=l.params.result,{event:p}=h;if(p==="initialized"){const v=setTimeout(()=>{s.delete(c),t(Gf(c,"bestBlockChanged",void 0,{bestBlockHash:h.finalizedBlockHashes.at(-1)}))},500);s.set(c,()=>{s.delete(c),clearTimeout(v)})}else Yf.has(p)&&u()}}t(l)},o(n));return{send(l){switch(l.method){case st.follow:r.add(l.id);break;case st.unfollow:s.get(l.params[0])?.()}a(l)},disconnect:o(i)}},Of),Ga=["chainHead","transaction","chainSpec","archive"].map(e=>`${e}_v1`),Qf=e=>{const t=Object.fromEntries(Ga.map(n=>[n,!!e.find(r=>r.startsWith(n))]));return n=>{const r=Jf(n),s=Xf(r),o=If(r);return(a,i)=>{const l=s(u=>{"error"in u&&u.error.code===-32800&&(console.warn("Max follow connections received: chainHead_v1 disabled"),t.chainHead_v1=!1),a(u)},i),c=o(a,i);return{send(u){for(const h of Ga)if(u.method.startsWith(h)){t[h]?l.send(u):c.send(u);return}l.send(u)},disconnect(){l.disconnect(),c.disconnect()}}}}},Jf=e=>{const t=new ye,n=new ye;let r=0,s=null;return(o,a)=>{r++,s??(s=e(u=>n.next(u),u=>t.next(u)));const i=n.pipe(Be(u=>u.id==null)).subscribe(o),l=t.subscribe(a),c=new Set;return{send(u){if(u.id==null)return s?.send(u);const h=u.id,p=n.pipe(Be(v=>v.id===h),te(1)).subscribe(v=>{if(o(v),!p)throw new Error("unreachable");c.delete(p)});c.add(p),s?.send(u)},disconnect(){i.unsubscribe(),l.unsubscribe(),c.forEach(u=>u.unsubscribe()),r--,r===0&&s?.disconnect()}}}},Zf=e=>t=>(n,r)=>{let s=N,o=[],a=d=>{o.push(d)},i=N,l=!0,c=()=>{l=!1,o=[],i(),c=s=u=i=N},u=d=>{c(),r(d)};const h=t(d=>s(d),d=>u(d));let{disconnect:p}=h;const{request:v}=fr(d=>(s=d,{...h,disconnect:N}));return l&&(i=e(d=>{i=N,d?({send:a,disconnect:p}=d((f,b)=>(u=y=>{c(),b(y)},s=f,h))(n,r),o.forEach(a),o=[]):u()},v)),{send:d=>{a(d)},disconnect:()=>{c(),p()}}},Ya="rpc_methods",ev=e=>t=>(n,r)=>{const s={methods:e},{send:o,disconnect:a}=t(n,r);return{disconnect:a,send(i){i.id&&i.method===Ya?n(Ka({id:i.id,result:s})):o(i)}}},tv=cs(e=>(t,n)=>{let r=0;const s=new Map,o=()=>{s.clear()},{send:a,disconnect:i}=e(l=>{const{id:c}=l;s.has(c)&&(l.id=s.get(c),s.delete(c)),t(l)},l=>{o(),n(l)});return{send:l=>{l.id!==void 0&&(s.set(r,l.id),l.id=r++),a(l)},disconnect(){o(),i()}}},(e=>Zf((t,n)=>{let r=0,s=N;const o=()=>{r++,s=n(Ya,[],{onSuccess:({methods:a})=>{t(cs(ev(a),e(a)))},onError:()=>{if(r>3)t(null);else{const a=setTimeout(o,500);s=()=>clearTimeout(a)}}})};return o(),()=>s()}))(Qf));var qe=(e=>(e.CONNECTING="CONNECTING",e.CONNECTED="CONNECTED",e.ERROR="ERROR",e.CLOSE="CLOSE",e))(qe||{}),Ke=(e=>(e.CONNECTING="CONNECTING",e.CONNECTED="CONNECTED",e.TIMEOUT="TIMEOUT",e.STALE="STALE",e.ERROR="ERROR",e.CLOSE="CLOSE",e.DISCONNECT="DISCONNECT",e.IN="IN",e.OUT="OUT",e))(Ke||{});let nv=0;const Xa=()=>`proxyOpaque${nv++}`,er=e=>({jsonrpc:"2.0",...e}),ls=e=>({jsonrpc:"2.0",...e}),Qa=()=>`___proxyInternalId__${Xa()}`,rv=e=>{let t={type:1,activeBroadcasts:new Map,pending:[]};const n=s=>{let o=!0;if(t.type===0){if(Zs(s)){const{id:a}=s,i=t.pendingBroadcasts.get(a);if(i){if(t.pendingBroadcasts.delete(a),!("result"in s))return;const l=s.result,c=t.activeBroadcasts.get(i);c?c.upToken=l:t.connection.send(er({id:Qa(),method:"transaction_v1_stop",params:[l]}));return}o=t.onGoingRequests.has(a),"result"in s&&t.onGoingRequests.get(a)?.type===0&&t.activeChainHeads.add(s.result),t.onGoingRequests.delete(s.id)}else if("params"in s){const{subscription:a,result:i}=s.params;i?.event==="stop"&&t.activeChainHeads.delete(a)}}o&&t.type!==2&&e(s)},r=s=>{if(t.type!==2){if("id"in s){const{method:o,id:a,params:i}=s,[l,,c]=o.split("_");if(l==="transaction"){if(c==="stop"){const[u]=i,h=t.activeBroadcasts.get(u);t.activeBroadcasts.delete(u),e(ls({id:a,result:null})),t.type===0&&h&&h.upToken&&t.connection.send(er({id:a,method:o,params:[h.upToken]}));return}if(c==="broadcast"){const u=Xa();t.activeBroadcasts.set(u,{tx:i[0],synToken:u}),t.type===0&&(t.pendingBroadcasts.set(a,u),t.connection.send(s)),e(ls({id:a,result:u}));return}}}if(t.type===1){t.pending.push(s);return}if(s.method==="chainHead_v1_unfollow"&&t.activeChainHeads.delete(s.params[0]),"id"in s){const{method:o,id:a}=s,[i,,l]=o.split("_"),c=i==="chainHead"?l==="follow"?{type:0,msg:s}:{type:1,id:a}:{type:2,msg:s};t.onGoingRequests.set(a,c)}t.connection.send(s)}};return{send:r,disconnect:()=>{t.type!==2&&(t.type===0&&t.connection.disconnect(),t={type:2})},connect:s=>{if(t.type!==1)throw new Error("Nonesense");const{pending:o,activeBroadcasts:a}=t,i=new Map,l=new Set,c=()=>{const u=t.type!==2?t.activeBroadcasts:new Map;u.forEach(h=>h.upToken=void 0),t={type:1,activeBroadcasts:u,pending:[]},l.forEach(h=>{n(er({method:"chainHead_v1_follow",params:{subscription:h,result:{event:"stop",internal:!0}}}))}),l.clear();for(const h of i.values())h.type===1?n(ls({id:h.id,error:{code:-32603,message:"Internal error"}})):r(h.msg);i.clear()};t={type:0,connection:null,activeBroadcasts:a,pendingBroadcasts:new Map,onGoingRequests:i,activeChainHeads:l},t.connection=s(n,c),a.forEach(u=>{if(t.type===0){const h=Qa();t.pendingBroadcasts.set(h,u.synToken),t.connection.send(er({id:h,method:"transaction_v1_broadcast",params:[u.tx]}))}}),o.forEach(r)}}},us=()=>{},Ja=250,sv=e=>t=>{let n=rv(t),r=Date.now(),s=0,o;const a=()=>s&&2**Math.min(5,s)*Ja;let i=us,l=()=>{const u=setTimeout(()=>{let h=!0;const p=e(v=>{h=!1,i=us,v?n&&n.connect((d,f)=>{let b=!0;return v(d,y=>{if(b){b=!1;const m=Date.now()-r;s+=m>Ja+a()?-s:1,r+=m,f(y),c()}})}):c()});h&&(i=p)},0);i=()=>clearTimeout(u)};const c=()=>{o=setTimeout(l,a())};return l(),{send(u){n?.send(u)},disconnect(){clearTimeout(o),i(),i=us,n?.disconnect(),n=null}}},ov=e=>(t,n)=>{let r=null,s=[];const o=()=>{i(),a=i=N,r=void 0,s=[]};let a=l=>{o(),n(l)},i=e(l=>{i=N,l?(r=l(t,a),s.forEach(c=>r?.send(c)),s=[]):a()});return{send:l=>{r?r.send(l):r===null&&s.push(l)},disconnect:()=>{const l=r;o(),l?.disconnect()}}},iv=(e,t,n,r)=>{const s=r?a=>r({type:a}):N,o=r?(a,i)=>r({type:a,msg:i}):N;return ov(a=>{const[i,l]=e();r?.({type:Ke.CONNECTING,url:i.url});let c=()=>{c=N,d(),a(null)},u=!0,h;const p=()=>{clearTimeout(h);const[g,w]=u?[n,Ke.TIMEOUT]:[t,Ke.STALE];u=!1,h=setTimeout(()=>{s(w),c({type:qe.ERROR,event:{type:"timeout"}})},g)},v=()=>{clearTimeout(h)};p();let d=()=>{v()};const f=g=>{r?.({type:Ke.ERROR,error:g}),c({type:qe.ERROR,event:g})},b=g=>{s(Ke.CLOSE),c({type:qe.CLOSE,event:g})},y=()=>{s(Ke.DISCONNECT),d();try{i.addEventListener("error",N,{once:!0}),i.close()}catch{}},m=()=>{s(Ke.CONNECTED),l(),p(),i.removeEventListener("open",m),a((g,w)=>{d=()=>{d=N,v(),i.removeEventListener("error",f),i.removeEventListener("ping",p),i.removeEventListener("message",E),i.removeEventListener("close",b)},c=$=>{c=N,d(),w($)};const E=$=>{p(),typeof $.data=="string"&&(o(Ke.IN,$.data),g(JSON.parse($.data)))};return i.addEventListener("ping",p),i.addEventListener("message",E),i.addEventListener("error",f),i.addEventListener("close",b),{send($){const k=JSON.stringify($);o(Ke.OUT,k),i.send(k)},disconnect:y}})};return d=()=>{d=N,v(),i.removeEventListener("error",f),i.removeEventListener("close",b),i.removeEventListener("open",m)},i.addEventListener("open",m),i.addEventListener("error",f),y})},av={onStatusChanged:N,timeout:5e3,heartbeatTimeout:4e4,middleware:Le},Za=(e,t)=>{const{onStatusChanged:n,timeout:r,heartbeatTimeout:s,middleware:o,logger:a}={...av,...t},i=Array.isArray(e)?e:[e],l=t?.websocketClass??globalThis.WebSocket;if(!l)throw new Error("Missing WebSocket class");let c=0,u,h=null,p={type:qe.CLOSE,event:null},v;const d=m=>n(p=m),f=o(iv(()=>{v=h?.url;const m=u??i[c++%i.length];return u=void 0,d({type:qe.CONNECTING,uri:m}),[h=new l(m),()=>{d({type:qe.CONNECTED,uri:m})}]},s,r,a)),b=(m,g)=>f(m,w=>{d({type:qe.ERROR,event:w}),g(w)}),y=sv(m=>{if(!v||h.url!==v)return m(b),N;const g=setTimeout(m,250,b);return()=>{clearTimeout(g)}});return Object.assign(y,{switch:m=>{p.type!==qe.CLOSE&&(u=m,p.type!==qe.ERROR&&h&&h.close())},getStatus:()=>p})},cv=(e,t={})=>Za(e,t),ec=(e,t={})=>Za(e,{...t,middleware:tv}),lv=(e,t={})=>{const n=ec(e,t),r=Gp(n,t);return Object.assign(r,{switch:n.switch,getStatus:n.getStatus})};it.SocketEvents=Ke,it.WsEvent=qe,it.createWsClient=lv,it.getWsProvider=ec,it.getWsRawProvider=cv}));
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=n}});function yn(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var _t=(function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,n,r,s,o;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var i=Pt(a),l=i.next();!l.done;l=i.next()){var c=l.value;c.remove(this)}}catch(f){t={error:f}}finally{try{l&&!l.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}else a.remove(this);var u=this.initialTeardown;if(Q(u))try{u()}catch(f){o=f instanceof sr?f.errors:[f]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var p=Pt(h),v=p.next();!v.done;v=p.next()){var d=v.value;try{bs(d)}catch(f){o=o??[],f instanceof sr?o=Te(Te([],He(o)),He(f.errors)):o.push(f)}}}catch(f){r={error:f}}finally{try{v&&!v.done&&(s=p.return)&&s.call(p)}finally{if(r)throw r.error}}}if(o)throw new sr(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)bs(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(t)}},e.prototype._hasParent=function(t){var n=this._parentage;return n===t||Array.isArray(n)&&n.includes(t)},e.prototype._addParent=function(t){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(t),n):n?[n,t]:t},e.prototype._removeParent=function(t){var n=this._parentage;n===t?this._parentage=null:Array.isArray(n)&&yn(n,t)},e.prototype.remove=function(t){var n=this._finalizers;n&&yn(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=(function(){var t=new e;return t.closed=!0,t})(),e})(),fs=_t.EMPTY;function vs(e){return e instanceof _t||e&&"closed"in e&&Q(e.remove)&&Q(e.add)&&Q(e.unsubscribe)}function bs(e){Q(e)?e():e.unsubscribe()}var fc={Promise:void 0},vc={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,Te([e,t],He(n)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function ms(e){vc.setTimeout(function(){throw e})}function Ee(){}function gn(e){e()}var Zt=(function(e){Ye(t,e);function t(n){var r=e.call(this)||this;return r.isStopped=!1,n?(r.destination=n,vs(n)&&n.add(r)):r.destination=yc,r}return t.create=function(n,r,s){return new Wt(n,r,s)},t.prototype.next=function(n){this.isStopped||this._next(n)},t.prototype.error=function(n){this.isStopped||(this.isStopped=!0,this._error(n))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(n){this.destination.next(n)},t.prototype._error=function(n){try{this.destination.error(n)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(_t),bc=(function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var n=this.partialObserver;if(n.next)try{n.next(t)}catch(r){wn(r)}},e.prototype.error=function(t){var n=this.partialObserver;if(n.error)try{n.error(t)}catch(r){wn(r)}else wn(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(n){wn(n)}},e})(),Wt=(function(e){Ye(t,e);function t(n,r,s){var o=e.call(this)||this,a;return Q(n)||!n?a={next:n??void 0,error:r??void 0,complete:s??void 0}:a=n,o.destination=new bc(a),o}return t})(Zt);function wn(e){ms(e)}function mc(e){throw e}var yc={closed:!0,next:Ee,error:mc,complete:Ee},or=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Le(e){return e}function ys(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return gs(e)}function gs(e){return e.length===0?Le:e.length===1?e[0]:function(n){return e.reduce(function(r,s){return s(r)},n)}}var D=(function(){function e(t){t&&(this._subscribe=t)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(t,n,r){var s=this,o=wc(t)?t:new Wt(t,n,r);return gn(function(){var a=s,i=a.operator,l=a.source;o.add(i?i.call(o,l):l?s._subscribe(o):s._trySubscribe(o))}),o},e.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(n){t.error(n)}},e.prototype.forEach=function(t,n){var r=this;return n=ws(n),new n(function(s,o){var a=new Wt({next:function(i){try{t(i)}catch(l){o(l),a.unsubscribe()}},error:o,complete:s});r.subscribe(a)})},e.prototype._subscribe=function(t){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(t)},e.prototype[or]=function(){return this},e.prototype.pipe=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return gs(t)(this)},e.prototype.toPromise=function(t){var n=this;return t=ws(t),new t(function(r,s){var o;n.subscribe(function(a){return o=a},function(a){return s(a)},function(){return r(o)})})},e.create=function(t){return new e(t)},e})();function ws(e){var t;return(t=e??fc.Promise)!==null&&t!==void 0?t:Promise}function gc(e){return e&&Q(e.next)&&Q(e.error)&&Q(e.complete)}function wc(e){return e&&e instanceof Zt||gc(e)&&vs(e)}function $c(e){return Q(e?.lift)}function J(e){return function(t){if($c(t))return t.lift(function(n){try{return e(n,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function Y(e,t,n,r,s){return new Ec(e,t,n,r,s)}var Ec=(function(e){Ye(t,e);function t(n,r,s,o,a,i){var l=e.call(this,n)||this;return l.onFinalize=a,l.shouldUnsubscribe=i,l._next=r?function(c){try{r(c)}catch(u){n.error(u)}}:e.prototype._next,l._error=o?function(c){try{o(c)}catch(u){n.error(u)}finally{this.unsubscribe()}}:e.prototype._error,l._complete=s?function(){try{s()}catch(c){n.error(c)}finally{this.unsubscribe()}}:e.prototype._complete,l}return t.prototype.unsubscribe=function(){var n;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;e.prototype.unsubscribe.call(this),!r&&((n=this.onFinalize)===null||n===void 0||n.call(this))}},t})(Zt),kc=rr(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),ye=(function(e){Ye(t,e);function t(){var n=e.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return t.prototype.lift=function(n){var r=new $s(this,this);return r.operator=n,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new kc},t.prototype.next=function(n){var r=this;gn(function(){var s,o;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var a=Pt(r.currentObservers),i=a.next();!i.done;i=a.next()){var l=i.value;l.next(n)}}catch(c){s={error:c}}finally{try{i&&!i.done&&(o=a.return)&&o.call(a)}finally{if(s)throw s.error}}}})},t.prototype.error=function(n){var r=this;gn(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=n;for(var s=r.observers;s.length;)s.shift().error(n)}})},t.prototype.complete=function(){var n=this;gn(function(){if(n._throwIfClosed(),!n.isStopped){n.isStopped=!0;for(var r=n.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var n;return((n=this.observers)===null||n===void 0?void 0:n.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(n){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,n)},t.prototype._subscribe=function(n){return this._throwIfClosed(),this._checkFinalizedStatuses(n),this._innerSubscribe(n)},t.prototype._innerSubscribe=function(n){var r=this,s=this,o=s.hasError,a=s.isStopped,i=s.observers;return o||a?fs:(this.currentObservers=null,i.push(n),new _t(function(){r.currentObservers=null,yn(i,n)}))},t.prototype._checkFinalizedStatuses=function(n){var r=this,s=r.hasError,o=r.thrownError,a=r.isStopped;s?n.error(o):a&&n.complete()},t.prototype.asObservable=function(){var n=new D;return n.source=this,n},t.create=function(n,r){return new $s(n,r)},t})(D),$s=(function(e){Ye(t,e);function t(n,r){var s=e.call(this)||this;return s.destination=n,s.source=r,s}return t.prototype.next=function(n){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.next)===null||s===void 0||s.call(r,n)},t.prototype.error=function(n){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.error)===null||s===void 0||s.call(r,n)},t.prototype.complete=function(){var n,r;(r=(n=this.destination)===null||n===void 0?void 0:n.complete)===null||r===void 0||r.call(n)},t.prototype._subscribe=function(n){var r,s;return(s=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&s!==void 0?s:fs},t})(ye),xc=(function(e){Ye(t,e);function t(n){var r=e.call(this)||this;return r._value=n,r}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(n){var r=e.prototype._subscribe.call(this,n);return!r.closed&&n.next(this._value),r},t.prototype.getValue=function(){var n=this,r=n.hasError,s=n.thrownError,o=n._value;if(r)throw s;return this._throwIfClosed(),o},t.prototype.next=function(n){e.prototype.next.call(this,this._value=n)},t})(ye),ir={now:function(){return(ir.delegate||Date).now()},delegate:void 0},en=(function(e){Ye(t,e);function t(n,r,s){n===void 0&&(n=1/0),r===void 0&&(r=1/0),s===void 0&&(s=ir);var o=e.call(this)||this;return o._bufferSize=n,o._windowTime=r,o._timestampProvider=s,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=r===1/0,o._bufferSize=Math.max(1,n),o._windowTime=Math.max(1,r),o}return t.prototype.next=function(n){var r=this,s=r.isStopped,o=r._buffer,a=r._infiniteTimeWindow,i=r._timestampProvider,l=r._windowTime;s||(o.push(n),!a&&o.push(i.now()+l)),this._trimBuffer(),e.prototype.next.call(this,n)},t.prototype._subscribe=function(n){this._throwIfClosed(),this._trimBuffer();for(var r=this._innerSubscribe(n),s=this,o=s._infiniteTimeWindow,a=s._buffer,i=a.slice(),l=0;l<i.length&&!n.closed;l+=o?1:2)n.next(i[l]);return this._checkFinalizedStatuses(n),r},t.prototype._trimBuffer=function(){var n=this,r=n._bufferSize,s=n._timestampProvider,o=n._buffer,a=n._infiniteTimeWindow,i=(a?1:2)*r;if(r<1/0&&i<o.length&&o.splice(0,o.length-i),!a){for(var l=s.now(),c=0,u=1;u<o.length&&o[u]<=l;u+=2)c=u;c&&o.splice(0,c+1)}},t})(ye),Sc=(function(e){Ye(t,e);function t(n,r){return e.call(this)||this}return t.prototype.schedule=function(n,r){return this},t})(_t),Es={setInterval:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setInterval.apply(void 0,Te([e,t],He(n)))},clearInterval:function(e){return clearInterval(e)},delegate:void 0},Ic=(function(e){Ye(t,e);function t(n,r){var s=e.call(this,n,r)||this;return s.scheduler=n,s.work=r,s.pending=!1,s}return t.prototype.schedule=function(n,r){var s;if(r===void 0&&(r=0),this.closed)return this;this.state=n;var o=this.id,a=this.scheduler;return o!=null&&(this.id=this.recycleAsyncId(a,o,r)),this.pending=!0,this.delay=r,this.id=(s=this.id)!==null&&s!==void 0?s:this.requestAsyncId(a,this.id,r),this},t.prototype.requestAsyncId=function(n,r,s){return s===void 0&&(s=0),Es.setInterval(n.flush.bind(n,this),s)},t.prototype.recycleAsyncId=function(n,r,s){if(s===void 0&&(s=0),s!=null&&this.delay===s&&this.pending===!1)return r;r!=null&&Es.clearInterval(r)},t.prototype.execute=function(n,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var s=this._execute(n,r);if(s)return s;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(n,r){var s=!1,o;try{this.work(n)}catch(a){s=!0,o=a||new Error("Scheduled action threw falsy error")}if(s)return this.unsubscribe(),o},t.prototype.unsubscribe=function(){if(!this.closed){var n=this,r=n.id,s=n.scheduler,o=s.actions;this.work=this.state=this.scheduler=null,this.pending=!1,yn(o,this),r!=null&&(this.id=this.recycleAsyncId(s,r,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},t})(Sc),ks=(function(){function e(t,n){n===void 0&&(n=e.now),this.schedulerActionCtor=t,this.now=n}return e.prototype.schedule=function(t,n,r){return n===void 0&&(n=0),new this.schedulerActionCtor(this,t).schedule(r,n)},e.now=ir.now,e})(),Bc=(function(e){Ye(t,e);function t(n,r){r===void 0&&(r=ks.now);var s=e.call(this,n,r)||this;return s.actions=[],s._active=!1,s}return t.prototype.flush=function(n){var r=this.actions;if(this._active){r.push(n);return}var s;this._active=!0;do if(s=n.execute(n.state,n.delay))break;while(n=r.shift());if(this._active=!1,s){for(;n=r.shift();)n.unsubscribe();throw s}},t})(ks),xs=new Bc(Ic),Ac=xs,Xe=new D(function(e){return e.complete()});function Oc(e){return e&&Q(e.schedule)}function ar(e){return e[e.length-1]}function cr(e){return Q(ar(e))?e.pop():void 0}function tn(e){return Oc(ar(e))?e.pop():void 0}function Cc(e,t){return typeof ar(e)=="number"?e.pop():t}var Ss=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function Is(e){return Q(e?.then)}function Bs(e){return Q(e[or])}function As(e){return Symbol.asyncIterator&&Q(e?.[Symbol.asyncIterator])}function Os(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function _c(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Cs=_c();function _s(e){return Q(e?.[Cs])}function Rs(e){return hc(this,arguments,function(){var n,r,s,o;return ps(this,function(a){switch(a.label){case 0:n=e.getReader(),a.label=1;case 1:a.trys.push([1,,9,10]),a.label=2;case 2:return[4,Ft(n.read())];case 3:return r=a.sent(),s=r.value,o=r.done,o?[4,Ft(void 0)]:[3,5];case 4:return[2,a.sent()];case 5:return[4,Ft(s)];case 6:return[4,a.sent()];case 7:return a.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}})})}function Hs(e){return Q(e?.getReader)}function le(e){if(e instanceof D)return e;if(e!=null){if(Bs(e))return Rc(e);if(Ss(e))return Hc(e);if(Is(e))return Tc(e);if(As(e))return Ts(e);if(_s(e))return Mc(e);if(Hs(e))return Uc(e)}throw Os(e)}function Rc(e){return new D(function(t){var n=e[or]();if(Q(n.subscribe))return n.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Hc(e){return new D(function(t){for(var n=0;n<e.length&&!t.closed;n++)t.next(e[n]);t.complete()})}function Tc(e){return new D(function(t){e.then(function(n){t.closed||(t.next(n),t.complete())},function(n){return t.error(n)}).then(null,ms)})}function Mc(e){return new D(function(t){var n,r;try{for(var s=Pt(e),o=s.next();!o.done;o=s.next()){var a=o.value;if(t.next(a),t.closed)return}}catch(i){n={error:i}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}t.complete()})}function Ts(e){return new D(function(t){zc(e,t).catch(function(n){return t.error(n)})})}function Uc(e){return Ts(Rs(e))}function zc(e,t){var n,r,s,o;return dc(this,void 0,void 0,function(){var a,i;return ps(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),n=pc(e),l.label=1;case 1:return[4,n.next()];case 2:if(r=l.sent(),!!r.done)return[3,4];if(a=r.value,t.next(a),t.closed)return[2];l.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return i=l.sent(),s={error:i},[3,11];case 6:return l.trys.push([6,,9,10]),r&&!r.done&&(o=n.return)?[4,o.call(n)]:[3,8];case 7:l.sent(),l.label=8;case 8:return[3,10];case 9:if(s)throw s.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function ft(e,t,n,r,s){r===void 0&&(r=0),s===void 0&&(s=!1);var o=t.schedule(function(){n(),s?e.add(this.schedule(null,r)):this.unsubscribe()},r);if(e.add(o),!s)return o}function Ms(e,t){return t===void 0&&(t=0),J(function(n,r){n.subscribe(Y(r,function(s){return ft(r,e,function(){return r.next(s)},t)},function(){return ft(r,e,function(){return r.complete()},t)},function(s){return ft(r,e,function(){return r.error(s)},t)}))})}function Us(e,t){return t===void 0&&(t=0),J(function(n,r){r.add(e.schedule(function(){return n.subscribe(r)},t))})}function Dc(e,t){return le(e).pipe(Us(t),Ms(t))}function jc(e,t){return le(e).pipe(Us(t),Ms(t))}function Lc(e,t){return new D(function(n){var r=0;return t.schedule(function(){r===e.length?n.complete():(n.next(e[r++]),n.closed||this.schedule())})})}function Vc(e,t){return new D(function(n){var r;return ft(n,t,function(){r=e[Cs](),ft(n,t,function(){var s,o,a;try{s=r.next(),o=s.value,a=s.done}catch(i){n.error(i);return}a?n.complete():n.next(o)},0,!0)}),function(){return Q(r?.return)&&r.return()}})}function zs(e,t){if(!e)throw new Error("Iterable cannot be null");return new D(function(n){ft(n,t,function(){var r=e[Symbol.asyncIterator]();ft(n,t,function(){r.next().then(function(s){s.done?n.complete():n.next(s.value)})},0,!0)})})}function Nc(e,t){return zs(Rs(e),t)}function Pc(e,t){if(e!=null){if(Bs(e))return Dc(e,t);if(Ss(e))return Lc(e,t);if(Is(e))return jc(e,t);if(As(e))return zs(e,t);if(_s(e))return Vc(e,t);if(Hs(e))return Nc(e,t)}throw Os(e)}function vt(e,t){return t?Pc(e,t):le(e)}function K(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=tn(e);return vt(e,n)}function Rt(e,t){var n=Q(e)?e:function(){return e},r=function(s){return s.error(n())};return new D(r)}var Ds=rr(function(e){return function(){e(this),this.name="EmptyError",this.message="no elements in sequence"}});function Fc(e,t){return new Promise(function(n,r){var s=!1,o;e.subscribe({next:function(a){o=a,s=!0},error:r,complete:function(){s?n(o):r(new Ds)}})})}function at(e,t){return new Promise(function(n,r){var s=new Wt({next:function(o){n(o),s.unsubscribe()},error:r,complete:function(){r(new Ds)}});e.subscribe(s)})}function Wc(e){return e instanceof Date&&!isNaN(e)}function x(e,t){return J(function(n,r){var s=0;n.subscribe(Y(r,function(o){r.next(e.call(t,o,s++))}))})}var qc=Array.isArray;function Kc(e,t){return qc(t)?e.apply(void 0,Te([],He(t))):e(t)}function js(e){return x(function(t){return Kc(e,t)})}var Gc=Array.isArray,Yc=Object.getPrototypeOf,Xc=Object.prototype,Qc=Object.keys;function Jc(e){if(e.length===1){var t=e[0];if(Gc(t))return{args:t,keys:null};if(Zc(t)){var n=Qc(t);return{args:n.map(function(r){return t[r]}),keys:n}}}return{args:e,keys:null}}function Zc(e){return e&&typeof e=="object"&&Yc(e)===Xc}function el(e,t){return e.reduce(function(n,r,s){return n[r]=t[s],n},{})}function ue(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=tn(e),r=cr(e),s=Jc(e),o=s.args,a=s.keys;if(o.length===0)return vt([],n);var i=new D(Ls(o,n,a?function(l){return el(a,l)}:Le));return r?i.pipe(js(r)):i}function Ls(e,t,n){return n===void 0&&(n=Le),function(r){Vs(t,function(){for(var s=e.length,o=new Array(s),a=s,i=s,l=function(u){Vs(t,function(){var h=vt(e[u],t),p=!1;h.subscribe(Y(r,function(v){o[u]=v,p||(p=!0,i--),i||r.next(n(o.slice()))},function(){--a||r.complete()}))},r)},c=0;c<s;c++)l(c)},r)}}function Vs(e,t,n){e?ft(n,e,t):t()}function tl(e,t,n,r,s,o,a,i){var l=[],c=0,u=0,h=!1,p=function(){h&&!l.length&&!c&&t.complete()},v=function(f){return c<r?d(f):l.push(f)},d=function(f){c++;var b=!1;le(n(f,u++)).subscribe(Y(t,function(y){t.next(y)},function(){b=!0},void 0,function(){if(b)try{c--;for(var y=function(){var m=l.shift();a||d(m)};l.length&&c<r;)y();p()}catch(m){t.error(m)}}))};return e.subscribe(Y(t,v,function(){h=!0,p()})),function(){}}function z(e,t,n){return n===void 0&&(n=1/0),Q(t)?z(function(r,s){return x(function(o,a){return t(r,o,s,a)})(le(e(r,s)))},n):(typeof t=="number"&&(n=t),J(function(r,s){return tl(r,s,e,n)}))}function $n(e){return e===void 0&&(e=1/0),z(Le,e)}function nl(){return $n(1)}function ct(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return nl()(vt(e,tn(e)))}function nn(e){return new D(function(t){le(e()).subscribe(t)})}function En(e,t,n){return e===void 0&&(e=0),n===void 0&&(n=Ac),new D(function(r){var s=Wc(e)?+e-n.now():e;s<0&&(s=0);var o=0;return n.schedule(function(){r.closed||(r.next(o++),r.complete())},s)})}function Qe(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=tn(e),r=Cc(e,1/0),s=e;return s.length?s.length===1?le(s[0]):$n(r)(vt(s,n)):Xe}var rl=new D(Ee),sl=Array.isArray;function Ns(e){return e.length===1&&sl(e[0])?e[0]:e}function Be(e,t){return J(function(n,r){var s=0;n.subscribe(Y(r,function(o){return e.call(t,o,s++)&&r.next(o)}))})}function ol(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e=Ns(e),e.length===1?le(e[0]):new D(il(e))}function il(e){return function(t){for(var n=[],r=function(o){n.push(le(e[o]).subscribe(Y(t,function(a){if(n){for(var i=0;i<n.length;i++)i!==o&&n[i].unsubscribe();n=null}t.next(a)})))},s=0;n&&!t.closed&&s<e.length;s++)r(s)}}function de(e){return J(function(t,n){var r=null,s=!1,o;r=t.subscribe(Y(n,void 0,void 0,function(a){o=le(e(a,de(e)(t))),r?(r.unsubscribe(),r=null,o.subscribe(n)):s=!0})),s&&(r.unsubscribe(),r=null,o.subscribe(n))})}function al(e,t,n,r,s){return function(o,a){var i=n,l=t,c=0;o.subscribe(Y(a,function(u){var h=c++;l=i?e(l,u,h):(i=!0,u),a.next(l)},s))}}function Ps(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=cr(e);return n?ys(Ps.apply(void 0,Te([],He(e))),js(n)):J(function(r,s){Ls(Te([r],He(Ns(e))))(s)})}function cl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Ps.apply(void 0,Te([],He(e)))}function Fs(e,t){return Q(t)?z(e,t,1):z(e,1)}function Ws(e,t){return t===void 0&&(t=xs),J(function(n,r){var s=null,o=null,a=null,i=function(){if(s){s.unsubscribe(),s=null;var c=o;o=null,r.next(c)}};function l(){var c=a+e,u=t.now();if(u<c){s=this.schedule(void 0,c-u),r.add(s);return}i()}n.subscribe(Y(r,function(c){o=c,a=t.now(),s||(s=t.schedule(l,e),r.add(s))},function(){i(),r.complete()},void 0,function(){o=s=null}))})}function te(e){return e<=0?function(){return Xe}:J(function(t,n){var r=0;t.subscribe(Y(n,function(s){++r<=e&&(n.next(s),e<=r&&n.complete())}))})}function kn(){return J(function(e,t){e.subscribe(Y(t,Ee))})}function ll(e,t){return J(function(n,r){var s=new Set;n.subscribe(Y(r,function(o){var a=e?e(o):o;s.has(a)||(s.add(a),r.next(o))})),t&&le(t).subscribe(Y(r,function(){return s.clear()},Ee))})}function he(e,t){return t===void 0&&(t=Le),e=e??ul,J(function(n,r){var s,o=!0;n.subscribe(Y(r,function(a){var i=t(a);(o||!e(s,i))&&(o=!1,s=i,r.next(a))}))})}function ul(e,t){return e===t}function qs(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(n){return ct(n,K.apply(void 0,Te([],He(e))))}}function dl(e,t){return J(function(n,r){var s=0,o=null,a=!1;n.subscribe(Y(r,function(i){o||(o=Y(r,void 0,function(){o=null,a&&r.complete()}),le(e(i,s++)).subscribe(o))},function(){a=!0,!o&&r.complete()}))})}function lr(e){return J(function(t,n){try{t.subscribe(n)}finally{n.add(e)}})}function hl(){return J(function(e,t){var n,r=!1;e.subscribe(Y(t,function(s){var o=n;n=s,r&&t.next([o,s]),r=!0}))})}function rn(e,t){return J(al(e,t,arguments.length>=2,!0))}function bt(e){e===void 0&&(e={});var t=e.connector,n=t===void 0?function(){return new ye}:t,r=e.resetOnError,s=r===void 0?!0:r,o=e.resetOnComplete,a=o===void 0?!0:o,i=e.resetOnRefCountZero,l=i===void 0?!0:i;return function(c){var u,h,p,v=0,d=!1,f=!1,b=function(){h?.unsubscribe(),h=void 0},y=function(){b(),u=p=void 0,d=f=!1},m=function(){var g=u;y(),g?.unsubscribe()};return J(function(g,w){v++,!f&&!d&&b();var E=p=p??n();w.add(function(){v--,v===0&&!f&&!d&&(h=ur(m,l))}),E.subscribe(w),!u&&v>0&&(u=new Wt({next:function($){return E.next($)},error:function($){f=!0,b(),h=ur(y,s,$),E.error($)},complete:function(){d=!0,b(),h=ur(y,a),E.complete()}}),le(g).subscribe(u))})(c)}}function ur(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(t===!0){e();return}if(t!==!1){var s=new Wt({next:function(){s.unsubscribe(),e()}});return le(t.apply(void 0,Te([],He(n)))).subscribe(s)}}function sn(e,t,n){var r,s,o,a,i=!1;return e&&typeof e=="object"?(r=e.bufferSize,a=r===void 0?1/0:r,s=e.windowTime,t=s===void 0?1/0:s,o=e.refCount,i=o===void 0?!1:o,n=e.scheduler):a=e??1/0,bt({connector:function(){return new en(a,t,n)},resetOnError:!0,resetOnComplete:!1,resetOnRefCountZero:i})}function Ks(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=tn(e);return J(function(r,s){(n?ct(e,r,n):ct(e,r)).subscribe(s)})}function Ht(e,t){return J(function(n,r){var s=null,o=0,a=!1,i=function(){return a&&!s&&r.complete()};n.subscribe(Y(r,function(l){s?.unsubscribe();var c=0,u=o++;le(e(l,u)).subscribe(s=Y(r,function(h){return r.next(t?t(l,h,u,c++):h)},function(){s=null,i()}))},function(){a=!0,i()}))})}function pl(){return Ht(Le)}function dr(e){return J(function(t,n){le(e).subscribe(Y(n,function(){return n.complete()},Ee)),!n.closed&&t.subscribe(n)})}function Tt(e,t){return t===void 0&&(t=!1),J(function(n,r){var s=0;n.subscribe(Y(r,function(o){var a=e(o,s++);(a||t)&&r.next(o),!a&&r.complete()}))})}function qt(e,t,n){var r=Q(e)||t||n?{next:e,error:t,complete:n}:e;return r?J(function(s,o){var a;(a=r.subscribe)===null||a===void 0||a.call(r);var i=!0;s.subscribe(Y(o,function(l){var c;(c=r.next)===null||c===void 0||c.call(r,l),o.next(l)},function(){var l;i=!1,(l=r.complete)===null||l===void 0||l.call(r),o.complete()},function(l){var c;i=!1,(c=r.error)===null||c===void 0||c.call(r,l),o.error(l)},function(){var l,c;i&&((l=r.unsubscribe)===null||l===void 0||l.call(r)),(c=r.finalize)===null||c===void 0||c.call(r)}))}):Le}function Gs(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=cr(e);return J(function(r,s){for(var o=e.length,a=new Array(o),i=e.map(function(){return!1}),l=!1,c=function(h){le(e[h]).subscribe(Y(s,function(p){a[h]=p,!l&&!i[h]&&(i[h]=!0,(l=i.every(Le))&&(i=null))},Ee))},u=0;u<o;u++)c(u);r.subscribe(Y(s,function(h){if(l){var p=Te([h],He(a));s.next(n?n.apply(void 0,Te([],He(p))):p)}}))})}const Ys="0123456789abcdef";function X(e){const t=new Array(e.length+1);t[0]="0x";for(let n=0;n<e.length;){const r=e[n++];t[n]=Ys[r>>4]+Ys[r&15]}return t.join("")}const hr={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15};function ee(e){const t=e.length%2,n=(e[1]==="x"?2:0)+t,r=(e.length-n)/2+t,s=new Uint8Array(r);t&&(s[0]=0|hr[e[2]]);for(let o=0;o<r;){const a=n+o*2,i=hr[e[a]],l=hr[e[a+1]];s[t+o++]=i<<4|l}return s}function mt(e,t){return Object.fromEntries(Object.entries(e).map(([n,r])=>[n,t(r,n)]))}const oe=e=>{const t=e.reduce((r,s)=>r+s.byteLength,0),n=new Uint8Array(t);for(let r=0,s=0;r<e.length;r++){const o=e[r];n.set(o,s),s+=o.byteLength}return n},N=Function.prototype;let Xs=class extends Error{constructor(){super("Abort Error"),this.name="AbortError"}};var fl=Object.defineProperty,vl=(e,t,n)=>t in e?fl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qs=(e,t,n)=>vl(e,typeof t!="symbol"?t+"":t,n);let Js=class extends Error{constructor(t){super(t.message),Qs(this,"code"),Qs(this,"data"),this.code=t.code,this.data=t.data,this.name="RpcError"}};const Zs=e=>!("method"in e),eo=()=>{const e=new Map;return{has:e.has.bind(e),subscribe(t,n){e.set(t,n)},unsubscribe(t){e.delete(t)},next(t,n){e.get(t)?.next(n)},error(t,n){const r=e.get(t);r&&(e.delete(t),r.error(n))},errorAll(t){const n=[...e.values()];e.clear(),n.forEach(r=>{r.error(t)})}}};let pr=class extends Error{constructor(){super("Client destroyed"),this.name="DestroyedError"}},bl=1;const fr=(e,t)=>{let n=bl++;const r=new Map,s=eo();let o=null;const a=(u,h,p)=>{o.send({jsonrpc:"2.0",id:u,method:h,params:p})};function i(u){if(Zs(u)){const{id:h}=u,p=r.get(h);return p?(r.delete(h),"error"in u?p.onError(new Js(u.error)):p.onSuccess(u.result,(v,d)=>{const f=v;return s.subscribe(f,d),()=>{s.unsubscribe(f)}})):void 0}if(u.id===void 0){const{params:h}=u,{subscription:p,result:v,error:d}=h;p&&s.has(p)&&("result"in h||d)?d?s.error(p,new Js(d)):s.next(p,v):t?.(u)}else console.warn("Error parsing incomming message: "+JSON.stringify(u))}o=e(i);const l=()=>{o?.disconnect(),o=null,s.errorAll(new pr),r.forEach(u=>u.onError(new pr)),r.clear()};let c=1;return{request:(u,h,p)=>{if(!o)throw new Error("Not connected");const v=`${n}-${c++}`;return p&&r.set(v,p),a(v,u,h),()=>{r.delete(v)}},disconnect:l}};var ml=Object.defineProperty,yl=(e,t,n)=>t in e?ml(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,on=(e,t,n)=>yl(e,t+"",n);const to=class rc extends Error{constructor(){super("ChainHead stopped"),this.name=rc.errorName}};on(to,"errorName","StopError");let no=to;const ro=class sc extends Error{constructor(){super("ChainHead disjointed"),this.name=sc.errorName}};on(ro,"errorName","DisjointError");let xn=ro;const so=class oc extends Error{constructor(){super("ChainHead operations limit reached"),this.name=oc.errorName}};on(so,"errorName","OperationLimitError");let Sn=so;const oo=class ic extends Error{constructor(t){super(t),this.name=ic.errorName}};on(oo,"errorName","OperationError");let io=oo;const ao=class ac extends Error{constructor(){super("ChainHead operation inaccessible"),this.name=ac.errorName}};on(ao,"errorName","OperationInaccessibleError");let In=ao;const Me={body:"",call:"",continue:"",follow:"",header:"",stopOperation:"",storage:"",unfollow:"",unpin:"",followEvent:""},Bn={chainName:"",genesisHash:"",properties:""},vr={broadcast:"",stop:""};Object.entries({chainHead:Me,chainSpec:Bn,transaction:vr}).forEach(([e,t])=>{Object.keys(t).forEach(n=>{t[n]=`${e}_v1_${n}`})});var gl=Object.defineProperty,wl=(e,t,n)=>t in e?gl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,br=(e,t,n)=>wl(e,t+"",n);const co=class cc extends Error{constructor(t){super(`Invalid BlockHash: ${t}`),this.name=cc.errorName}};br(co,"errorName","BlockHashNotFoundError");let lo=co;const uo=class lc extends Error{constructor(t){super(`Storage Error: ${t}`),this.name=lc.errorName}};br(uo,"errorName","StorageError");let $l=uo;const ho=class uc extends Error{constructor(t){super(`Call Error: ${t}`),this.name=uc.errorName}};br(ho,"errorName","CallError");let El=ho;const Kt=()=>{},kl=e=>(t,n)=>{let r=!1,s=()=>{r=!0};return e(vr.broadcast,[t],{onSuccess:o=>{o!==null?(s=()=>{e(vr.stop,[o]),s=Kt},r&&s()):r||n(new Error("Max # of broadcasted transactions has been reached"))},onError:n}),()=>{s()}};function xl(){let e=()=>{},t=()=>{};return{promise:new Promise((n,r)=>{e=n,t=r}),res:e,rej:t}}const Gt=e=>(...t)=>new Promise((n,r)=>{let s=N;const[o,a]=t[t.length-1]instanceof AbortSignal?[t.slice(0,t.length-1),t[t.length-1]]:[t],i=()=>{s(),r(new Xs)};a?.addEventListener("abort",i,{once:!0});const l=c=>u=>{s=N,a?.removeEventListener("abort",i),c(u)};s=e(l(n),l(r),...o)}),po=(e,t)=>n=>Gt((r,s,...o)=>{let a=!0,i=()=>{a=!1};const[l,c]=t(...o);return n(e,l,{onSuccess:(u,h)=>{if(u.result==="limitReached")return s(new Sn);const{operationId:p}=u,v=()=>{n(Me.stopOperation,[p])};if(!a)return v();let d=Kt;const f=y=>{a=!1,d(),r(y)},b=y=>{a=!1,d(),s(y)};d=h(p,{next:y=>{const m=y;m.event==="operationError"?s(new io(m.error)):m.event==="operationInaccessible"?s(new In):c(y,f,b)},error:b}),i=()=>{a&&(d(),v())}},onError:s}),()=>{i()}}),Sl=po(Me.body,e=>[[e],(t,n)=>{n(t.value)}]),Il=po(Me.call,(e,t,n)=>[[e,t,n],(r,s)=>{s(r.output)}]),Bl=e=>t=>new Promise((n,r)=>{e(Me.header,[t],{onSuccess:n,onError:r})}),fo=e=>(t,n,r,s,o,a,i)=>{if(n.length===0)return a(),N;let l=!0,c=()=>{l=!1};return e(Me.storage,[t,n,r],{onSuccess:(u,h)=>{if(u.result==="limitReached"||u.discardedItems===n.length)return o(new Sn);const{operationId:p}=u,v=()=>{e(Me.stopOperation,[p])};if(!l)return v();const d=h(u.operationId,{next:y=>{switch(y.event){case"operationStorageItems":{s(y.items);break}case"operationStorageDone":{b();break}case"operationError":{f(new io(y.error));break}case"operationInaccessible":{f(new In);break}default:e(Me.continue,[y.operationId])}},error:o});c=()=>{d(),e(Me.stopOperation,[u.operationId])};const f=y=>{c=N,d(),o(y)},b=()=>{c=N,d(),a()};i(u.discardedItems)},onError:o}),()=>{c()}},Al=e=>{const t=fo(e);return Gt((n,r,s,o,a,i)=>{const l=o.startsWith("descendants");let c=l?[]:null;const u=t(s,[{key:a,type:o}],i??null,l?h=>{c.push(h)}:h=>{c=h[0]?.[o]},r,()=>{try{n(l?c.flat():c)}catch(h){r(h)}},h=>{h>0&&(u(),r(new Sn))});return u})},Ol=e=>t=>t.length>0?new Promise((n,r)=>{e(Me.unpin,[t],{onSuccess(){n()},onError:r})}):Promise.resolve();function Cl(e){return e.operationId!==void 0}function _l(e){return(t,n,r)=>{const s=eo(),o=new Set,a=xl();let i=a.promise,l=Kt;const c=d=>{e(Me.unfollow,[d])},u=d=>{l(),i!==null&&(d&&(i instanceof Promise?i.then(f=>{typeof f=="string"&&c(f)}):c(i)),i=null,o.forEach(f=>{f()}),o.clear(),s.errorAll(new xn))},h=d=>{if(Cl(d))return s.next(d.operationId,d);switch(d.event){case"stop":return r(new no),u(!1);case"initialized":case"newBlock":case"bestBlockChanged":case"finalized":const{event:f,...b}=d;return n({type:f,...b})}},p=d=>{r(d),u(!(d instanceof pr))};e(Me.follow,[t],{onSuccess:(d,f)=>{i instanceof Promise&&(i=d,l=f(d,{next:h,error:p})),a.res(d)},onError:d=>{i=null,a.res(d),r(d)}});const v=(d,f,b)=>{const y=()=>{b?.onError(new xn)};if(i===null)return y(),Kt;const m=w=>{if(!b)return e(d,[w,...f]);o.add(y);const E=(k,S)=>i===null?(S.error(new xn),Kt):(s.subscribe(k,S),()=>{s.unsubscribe(k)}),$=e(d,[w,...f],{onSuccess:k=>{o.delete(y),b.onSuccess(k,E)},onError:k=>{o.delete(y),b.onError(k)}});return()=>{o.delete(y),$()}};if(typeof i=="string")return m(i);let g=Kt;return i.then(w=>{if(w instanceof Error)return y();i&&(g=m(w))}),()=>{g()}};return{unfollow(){u(!0)},body:Sl(v),call:Il(v),header:Bl(v),storage:Al(v),storageSubscription:fo(v),unpin:Ol(v),_request:v}}}const Rl=e=>{const t=Gt((r,s,o,a)=>e(o,a,{onSuccess:r,onError:s}));let n=null;return async()=>n||(n=Promise.all([t(Bn.chainName,[]),t(Bn.genesisHash,[]),t(Bn.properties,[])]).then(([r,s,o])=>({name:r,genesisHash:s,properties:o})))},Hl=e=>(t,n,r,s,o,a)=>{if(n.length===0)return a(),N;let i=!0,l=()=>{i=!1};return e("storage",[t,n,r],{onSuccess:(c,u)=>{const h=()=>{e("stopStorage",[c])};if(!i)return h();const p=u(c,{next:b=>{const{event:y}=b;if(y==="storage"){const{event:m,...g}=b;s(g)}else y==="storageDone"?f():d(new $l(b.error))},error:o}),v=()=>{l=N,p()};l=()=>{v(),h()};const d=b=>{v(),o(b)},f=()=>{v(),a()}},onError:o}),()=>{l()}},Tl=e=>Gt((t,n,r,s,o,a)=>{const i=s.startsWith("descendants");let l=i?[]:null;const c=i?l.push.bind(l):({[s]:u})=>{l=u};return e(r,[{key:o,type:s}],a,c,u=>{n(u),l=null},()=>{t(l),l=null})}),vo=()=>e=>e,bo=()=>(e,t)=>{if(e===null)throw new lo(t);return e},Ml=e=>{const t=(u,...h)=>e(`archive_v1_${u}`,...h),n=u=>h=>Gt((p,v,...d)=>t(u,d,{onSuccess:f=>{try{p(h(f,...d))}catch(b){v(b)}},onError:v})),r=n("header")(bo()),s=n("body")(bo()),o=Hl(t),a=Tl(o),i=n("call")((u,h)=>{if(!u)throw new lo(h);if(!u.success)throw new El(u.error);return u.value}),l=n("finalizedHeight")(vo()),c=n("hashByHeight")(vo());return{header:r,body:s,storageSubscription:o,storage:a,call:i,finalizedHeight:l,hashByHeight:c}},Ul=e=>{const{request:t,disconnect:n}=fr(e);return{archive:Ml(t),chainHead:_l(t),transaction:kl(t),getChainSpecData:Rl(t),destroy:n,request:Gt((r,s,o,a)=>t(o,a,{onSuccess:r,onError:s})),_request:t}};var zl=Object.defineProperty,Dl=(e,t,n)=>t in e?zl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mo=(e,t,n)=>Dl(e,typeof t!="symbol"?t+"":t,n);let jl=class{constructor(){mo(this,"first"),mo(this,"last")}getRemoveFn(t){return()=>{t.prev?t.prev.next=t.next:this.first=t.next,t.next?t.next.prev=t.prev:this.last=t.prev,delete t.prev,delete t.next}}push(t){const n={value:t};return this.last===void 0?this.last=this.first=n:(this.last.next=n,n.prev=this.last,this.last=n),this.getRemoveFn(n)}unshift(t){return this.first={value:t,next:this.first},this.first.next&&(this.first.next.prev=this.first),this.last||(this.last=this.first),this.getRemoveFn(this.first)}pop(){const t=this.first?.value;return this.first&&(this.first=this.first.next,this.first?(delete this.first.prev?.next,delete this.first.prev):this.last=void 0),t}isEmpty(){return!this.first}};const Ll=()=>{const e=new Map,t=(h,p)=>{e.set(h,()=>{e.delete(h),p()})},n=h=>{e.get(h)?.()},r=new jl,s=r.unshift.bind(r),o=r.push.bind(r),a=(h,p)=>{const v=p?s:o;t(h.source$,v(h))},i=()=>{const h=r.pop();h&&(e.delete(h.source$),l(h))},l=h=>{const{source$:p,observer:v}=h;let d=!1;const f=p.subscribe({next(b){v.next(b)},error(b){(d=b instanceof Error&&b.name===Sn.errorName)?a(h,!0):v.error(b)},complete(){v.complete()}});f.closed?d||i():t(p,()=>{f.unsubscribe(),i()})},c=(h=!1)=>p=>new D(v=>{const d={observer:v,source$:p};return r.isEmpty()?l(d):a(d,h),()=>{n(p)}}),u=c();return{withRecovery:c,withRecoveryFn:h=>(...p)=>u(h(...p))}};let Je=class extends Error{constructor(t,n){super(`Block ${t} is not pinned (${n})`),this.name="BlockNotPinnedError"}};const mr=e=>{const t=e.pipe(de(n=>n instanceof Error&&n.name===In.errorName?En(750).pipe(Fs(()=>t)):Rt(()=>n)));return t},Vl=new Set(["best","finalized",null]),Nl=(e,t,n)=>r=>(s,...o)=>{if(!Vl.has(s))return mr(r(s,...o)).pipe(n(s));const a=(s==="best"?t:e).pipe(te(1),z(i=>r(i,...o).pipe(n(i))),de(i=>i instanceof Je?a:Rt(()=>i)));return mr(a)},Mt=e=>(...t)=>new D(n=>{let r=new AbortController;return e(...t,r.signal).then(s=>{n.next(s),n.complete()},s=>{n.error(s)}),()=>{n.unsubscribe(),r.abort(),r=void 0}}),Pl=e=>t=>(...n)=>e()[t](...n);var ve=(e=>(e[e.Initializing=0]="Initializing",e[e.Ready=1]="Ready",e[e.RecoveringInit=2]="RecoveringInit",e[e.RecoveringFin=3]="RecoveringFin",e))(ve||{});function An(e,t,n){return(r,...s)=>{let o;const a=()=>new Je(r,n),i=t(r,...s).pipe(x(c=>({type:"val",value:c})),qs({type:"end"})),l=e.pipe(Tt(c=>!c.blocks.has(r)),x(c=>{if(c.blocks.get(c.finalized).number>=o.number)throw a()}),kn());return e.pipe(x(c=>c.state.type===ve.Ready),he(),Ht(c=>c?(o||(o=e.state.blocks.get(r)),o?ct(l,i):Rt(a)):rl),Tt(c=>c.type==="val"),x(c=>c.value))}}const Fl=(e,t)=>{const n=(r,s,o,a)=>new D(i=>e().storageSubscription(r,s,o??null,l=>{i.next(l)},l=>{i.error(l)},()=>{i.complete()},l=>{l>0&&i.next(n(r,s.slice(-l),o,!0))})).pipe($n(),t(a));return n};var Wl=Object.defineProperty,ql=(e,t,n)=>t in e?Wl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yo=(e,t,n)=>(ql(e,typeof t!="symbol"?t+"":t,n),n),yr={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15};function Kl(e){const t=e.length%2,n=(e[1]==="x"?2:0)+t,r=(e.length-n)/2+t,s=new Uint8Array(r);t&&(s[0]=0|yr[e[2]]);for(let o=0;o<r;){const a=n+o*2,i=yr[e[a]],l=yr[e[a+1]];s[t+o++]=i<<4|l}return s}var go=class extends Uint8Array{constructor(e){super(e),yo(this,"i",0),yo(this,"v"),this.v=new DataView(e)}},Ue=e=>t=>e(t instanceof go?t:new go(t instanceof Uint8Array?t.buffer:typeof t=="string"?Kl(t).buffer:t)),Ze=e=>{const t=e.length;let n=0;for(let s=0;s<t;s++)n+=e[s].length;const r=new Uint8Array(n);for(let s=0,o=0;s<t;s++){const a=e[s];r.set(a,o),o+=a.byteLength}return r};function On(e,t){const n=Object.keys(e),r=n.length,s={};for(let o=0;o<r;o++){const a=n[o];s[a]=t(e[a],a)}return s}var lt=Ue,G=(e,t)=>{const n=[e,t];return n.enc=e,n.dec=t,n},Cn=(e,t)=>n=>e(t(n)),_n=(e,t)=>n=>t(e(n)),Ve=([e,t],n,r)=>G(Cn(e,n),_n(t,r));function Gl(e,t){return Ue(n=>{const r=n.v[t](n.i,!0);return n.i+=e,r})}function Yl(e,t){return n=>{const r=new Uint8Array(e);return new DataView(r.buffer)[t](0,n,!0),r}}function yt(e,t,n){return G(Yl(e,n),Gl(e,t))}var P=yt(1,"getUint8","setUint8"),et=yt(2,"getUint16","setUint16"),Ne=yt(4,"getUint32","setUint32"),an=yt(8,"getBigUint64","setBigUint64"),Xl=yt(1,"getInt8","setInt8"),Ql=yt(2,"getInt16","setInt16"),Jl=yt(4,"getInt32","setInt32"),Zl=yt(8,"getBigInt64","setBigInt64"),wo=e=>{const t=new Uint8Array(16),n=new DataView(t.buffer);return n.setBigInt64(0,e,!0),n.setBigInt64(8,e>>64n,!0),t},$o=e=>Ue(t=>{const{v:n,i:r}=t,s=n.getBigUint64(r,!0),o=n[e](r+8,!0);return t.i+=16,o<<64n|s}),Eo=G(wo,$o("getBigUint64")),eu=G(wo,$o("getBigInt64")),ko=e=>{const t=new Uint8Array(32),n=new DataView(t.buffer);return n.setBigInt64(0,e,!0),n.setBigInt64(8,e>>64n,!0),n.setBigInt64(16,e>>128n,!0),n.setBigInt64(24,e>>192n,!0),t},xo=e=>Ue(t=>{let n=t.v.getBigUint64(t.i,!0);return t.i+=8,n|=t.v.getBigUint64(t.i,!0)<<64n,t.i+=8,n|=t.v.getBigUint64(t.i,!0)<<128n,t.i+=8,n|=t.v[e](t.i,!0)<<192n,t.i+=8,n}),tu=G(ko,xo("getBigUint64")),nu=G(ko,xo("getBigInt64")),ru=Ve(P,e=>e?1:0,Boolean),su=[P[1],et[1],Ne[1]],ou=Ue(e=>{const t=e[e.i],n=t&3;if(n<3)return su[n](e)>>>2;const r=(t>>>2)+4;e.i++;let s=0n;const o=r/8|0;let a=0n;for(let l=0;l<o;l++)s=an[1](e)<<a|s,a+=64n;let i=r%8;return i>3&&(s=BigInt(Ne[1](e))<<a|s,a+=32n,i-=4),i>1&&(s=BigInt(et[1](e))<<a|s,a+=16n,i-=2),i&&(s=BigInt(P[1](e))<<a|s),s}),iu=1n<<56n,au=1<<24,cu=256,lu=4294967295n,uu=64,du=16384,hu=1<<30,pu=e=>{if(e<0)throw new Error(`Wrong compact input (${e})`);const t=Number(e)<<2;if(e<uu)return P[0](t);if(e<du)return et[0](t|1);if(e<hu)return Ne[0](t|2);let n=[new Uint8Array(1)],r=BigInt(e);for(;r>=iu;)n.push(an[0](r)),r>>=64n;r>=au&&(n.push(Ne[0](Number(r&lu))),r>>=32n);let s=Number(r);s>=cu&&(n.push(et[0](s)),s>>=16),s&&n.push(P[0](s));const o=Ze(n);return o[0]=o.length-5<<2|3,o},pe=G(pu,ou),fu=new TextEncoder,vu=e=>{const t=fu.encode(e);return Ze([pe.enc(t.length),t])},bu=new TextDecoder,mu=Ue(e=>{let t=pe.dec(e);const n=new DataView(e.buffer,e.i,t);return e.i+=t,bu.decode(n)}),W=G(vu,mu),yu=()=>{},gu=new Uint8Array(0),M=G(()=>gu,yu),So=e=>e===void 0?t=>Ze([pe.enc(t.length),t]):t=>t.length===e?t:t.slice(0,e),Io=e=>Ue(t=>{const n=e===void 0?pe.dec(t):e!==1/0?e:t.byteLength-t.i,r=new Uint8Array(t.buffer.slice(t.i,t.i+n));return t.i+=n,r}),ne=e=>G(So(e),Io(e));ne.enc=So,ne.dec=Io;var Bo=(e,t)=>{const n=Object.keys(e),r=new Map(t?.map((o,a)=>[n[a],o])??n.map((o,a)=>[o,a])),s=o=>r.get(o);return({tag:o,value:a})=>Ze([P.enc(s(o)),e[o](a)])},Ao=(e,t)=>{const n=Object.keys(e),r=new Map(t?.map((s,o)=>[s,n[o]])??n.map((s,o)=>[o,s]));return Ue(s=>{const o=P.dec(s),a=r.get(o),i=e[a];return{tag:a,value:i(s)}})},ke=(e,...t)=>G(Bo(On(e,([n])=>n),...t),Ao(On(e,([,n])=>n),...t));ke.enc=Bo,ke.dec=Ao;var Oo=e=>Ue(t=>P[1](t)>0?e(t):void 0),Co=e=>t=>{const n=new Uint8Array(1);return t===void 0?n:(n[0]=1,Ze([n,e(t)]))},xe=e=>G(Co(e[0]),Oo(e[1]));xe.enc=Co,xe.dec=Oo;var _o=(e,t)=>Ue(n=>{const r=P[1](n)===0,o=(r?e:t)(n);return{success:r,value:o}}),Ro=(e,t)=>({success:n,value:r})=>Ze([P[0](n?0:1),(n?e:t)(r)]),cn=(e,t)=>G(Ro(e[0],t[0]),_o(e[1],t[1]));cn.dec=_o,cn.enc=Ro;var Ho=(...e)=>Ue(t=>e.map(n=>n(t))),To=(...e)=>t=>Ze(e.map((n,r)=>n(t[r]))),ze=(...e)=>G(To(...e.map(([t])=>t)),Ho(...e.map(([,t])=>t)));ze.enc=To,ze.dec=Ho;var Mo=e=>{const t=Object.keys(e);return Cn(ze.enc(...Object.values(e)),n=>t.map(r=>n[r]))},Uo=e=>{const t=Object.keys(e);return _n(ze.dec(...Object.values(e)),n=>Object.fromEntries(n.map((r,s)=>[t[s],r])))},U=e=>G(Mo(On(e,t=>t[0])),Uo(On(e,t=>t[1])));U.enc=Mo,U.dec=Uo;var zo=(e,t)=>t>=0?n=>Ze(n.map(e)):n=>Ze([pe.enc(n.length),Ze(n.map(e))]),Do=(e,t)=>Ue(n=>{const r=t>=0?t:pe.dec(n),s=new Array(r);for(let o=0;o<r;o++)s[o]=e(n);return s}),j=(e,t)=>G(zo(e[0],t),Do(e[1],t));j.enc=zo,j.dec=Do;/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function wu(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function jo(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(n=>typeof n=="string"):t.every(n=>Number.isSafeInteger(n)):!1}function gr(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function Lo(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function wr(e){if(!Array.isArray(e))throw new Error("array expected")}function Vo(e,t){if(!jo(!0,t))throw new Error(`${e}: array of strings expected`)}function $u(e,t){if(!jo(!1,t))throw new Error(`${e}: array of numbers expected`)}function Eu(...e){const t=o=>o,n=(o,a)=>i=>o(a(i)),r=e.map(o=>o.encode).reduceRight(n,t),s=e.map(o=>o.decode).reduce(n,t);return{encode:r,decode:s}}function ku(e){const t=typeof e=="string"?e.split(""):e,n=t.length;Vo("alphabet",t);const r=new Map(t.map((s,o)=>[s,o]));return{encode:s=>(wr(s),s.map(o=>{if(!Number.isSafeInteger(o)||o<0||o>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${o}". Allowed: ${e}`);return t[o]})),decode:s=>(wr(s),s.map(o=>{gr("alphabet.decode",o);const a=r.get(o);if(a===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${e}`);return a}))}}function xu(e=""){return gr("join",e),{encode:t=>(Vo("join.decode",t),t.join(e)),decode:t=>(gr("join.decode",t),t.split(e))}}function No(e,t,n){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(wr(e),!e.length)return[];let r=0;const s=[],o=Array.from(e,i=>{if(Lo(i),i<0||i>=t)throw new Error(`invalid integer: ${i}`);return i}),a=o.length;for(;;){let i=0,l=!0;for(let c=r;c<a;c++){const u=o[c],h=t*i,p=h+u;if(!Number.isSafeInteger(p)||h/t!==i||p-u!==h)throw new Error("convertRadix: carry overflow");const v=p/n;i=p%n;const d=Math.floor(v);if(o[c]=d,!Number.isSafeInteger(d)||d*n+i!==p)throw new Error("convertRadix: carry overflow");if(l)d?l=!1:r=c;else continue}if(s.push(i),l)break}for(let i=0;i<e.length-1&&e[i]===0;i++)s.push(0);return s.reverse()}function Su(e){Lo(e);const t=2**8;return{encode:n=>{if(!wu(n))throw new Error("radix.encode input should be Uint8Array");return No(Array.from(n),t,e)},decode:n=>($u("radix.decode",n),Uint8Array.from(No(n,e,t)))}}const Po=(e=>Eu(Su(58),ku(e),xu("")))("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Iu(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Yt(e,t=""){if(!Number.isSafeInteger(e)||e<0){const n=t&&`"${t}" `;throw new Error(`${n}expected integer >= 0, got ${e}`)}}function De(e,t,n=""){const r=Iu(e),s=e?.length,o=t!==void 0;if(!r||o&&s!==t){const a=n&&`"${n}" `,i=o?` of length ${t}`:"",l=r?`length=${s}`:`type=${typeof e}`;throw new Error(a+"expected Uint8Array"+i+", got "+l)}return e}function ln(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function $r(e,t){De(e,void 0,"digestInto() output");const n=t.outputLen;if(e.length<n)throw new Error('"digestInto() output" expected to be of length >='+n)}function Bu(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function Ut(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function gt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Rn(e,t){return e<<32-t|e>>>t}const Fo=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Wo(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const ut=Fo?e=>e:e=>Wo(e);function Au(e){for(let t=0;t<e.length;t++)e[t]=Wo(e[t]);return e}const ge=Fo?e=>e:Au;function Er(e,t={}){const n=(s,o)=>e(o).update(s).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.create=s=>e(s),Object.assign(n,t),Object.freeze(n)}const Ou=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]);function wt(e,t,n,r,s){return e=e+t+s|0,r=Rn(r^e,16),n=n+r|0,t=Rn(t^n,12),{a:e,b:t,c:n,d:r}}function $t(e,t,n,r,s){return e=e+t+s|0,r=Rn(r^e,8),n=n+r|0,t=Rn(t^n,7),{a:e,b:t,c:n,d:r}}const Cu=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Hn=BigInt(2**32-1),qo=BigInt(32);function Tn(e,t=!1){return t?{h:Number(e&Hn),l:Number(e>>qo&Hn)}:{h:Number(e>>qo&Hn)|0,l:Number(e&Hn)|0}}function _u(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let o=0;o<n;o++){const{h:a,l:i}=Tn(e[o],t);[r[o],s[o]]=[a,i]}return[r,s]}const Ko=(e,t,n)=>e>>>n|t<<32-n,Go=(e,t,n)=>e<<32-n|t>>>n,Ru=(e,t,n)=>e<<64-n|t>>>n-32,Hu=(e,t,n)=>e>>>n-32|t<<64-n,Tu=(e,t)=>t,Mu=(e,t)=>e,Uu=(e,t,n)=>e<<n|t>>>32-n,zu=(e,t,n)=>t<<n|e>>>32-n,Du=(e,t,n)=>t<<n-32|e>>>64-n,ju=(e,t,n)=>e<<n-32|t>>>64-n;function Yo(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const Xo=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Qo=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,se=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),O=new Uint32Array(32);function Et(e,t,n,r,s,o){const a=s[o],i=s[o+1];let l=O[2*e],c=O[2*e+1],u=O[2*t],h=O[2*t+1],p=O[2*n],v=O[2*n+1],d=O[2*r],f=O[2*r+1],b=Xo(l,u,a);c=Qo(b,c,h,i),l=b|0,{Dh:f,Dl:d}={Dh:f^c,Dl:d^l},{Dh:f,Dl:d}={Dh:Tu(f,d),Dl:Mu(f)},{h:v,l:p}=Yo(v,p,f,d),{Bh:h,Bl:u}={Bh:h^v,Bl:u^p},{Bh:h,Bl:u}={Bh:Ko(h,u,24),Bl:Go(h,u,24)},O[2*e]=l,O[2*e+1]=c,O[2*t]=u,O[2*t+1]=h,O[2*n]=p,O[2*n+1]=v,O[2*r]=d,O[2*r+1]=f}function kt(e,t,n,r,s,o){const a=s[o],i=s[o+1];let l=O[2*e],c=O[2*e+1],u=O[2*t],h=O[2*t+1],p=O[2*n],v=O[2*n+1],d=O[2*r],f=O[2*r+1],b=Xo(l,u,a);c=Qo(b,c,h,i),l=b|0,{Dh:f,Dl:d}={Dh:f^c,Dl:d^l},{Dh:f,Dl:d}={Dh:Ko(f,d,16),Dl:Go(f,d,16)},{h:v,l:p}=Yo(v,p,f,d),{Bh:h,Bl:u}={Bh:h^v,Bl:u^p},{Bh:h,Bl:u}={Bh:Ru(h,u,63),Bl:Hu(h,u,63)},O[2*e]=l,O[2*e+1]=c,O[2*t]=u,O[2*t+1]=h,O[2*n]=p,O[2*n+1]=v,O[2*r]=d,O[2*r+1]=f}function Lu(e,t={},n,r,s){if(Yt(n),e<0||e>n)throw new Error("outputLen bigger than keyLen");const{key:o,salt:a,personalization:i}=t;if(o!==void 0&&(o.length<1||o.length>n))throw new Error('"key" expected to be undefined or of length=1..'+n);a!==void 0&&De(a,r,"salt"),i!==void 0&&De(i,s,"personalization")}class Jo{buffer;buffer32;finished=!1;destroyed=!1;length=0;pos=0;blockLen;outputLen;constructor(t,n){Yt(t),Yt(n),this.blockLen=t,this.outputLen=n,this.buffer=new Uint8Array(t),this.buffer32=Ut(this.buffer)}update(t){ln(this),De(t);const{blockLen:n,buffer:r,buffer32:s}=this,o=t.length,a=t.byteOffset,i=t.buffer;for(let l=0;l<o;){this.pos===n&&(ge(s),this.compress(s,0,!1),ge(s),this.pos=0);const c=Math.min(n-this.pos,o-l),u=a+l;if(c===n&&!(u%4)&&l+c<o){const h=new Uint32Array(i,u,Math.floor((o-l)/4));ge(h);for(let p=0;l+n<o;p+=s.length,l+=n)this.length+=n,this.compress(h,p,!1);ge(h);continue}r.set(t.subarray(l,l+c),this.pos),this.pos+=c,this.length+=c,l+=c}return this}digestInto(t){ln(this),$r(t,this);const{pos:n,buffer32:r}=this;this.finished=!0,gt(this.buffer.subarray(n)),ge(r),this.compress(r,0,!0),ge(r);const s=Ut(t);this.get().forEach((o,a)=>s[a]=ut(o))}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){const{buffer:n,length:r,finished:s,destroyed:o,outputLen:a,pos:i}=this;return t||=new this.constructor({dkLen:a}),t.set(...this.get()),t.buffer.set(n),t.destroyed=o,t.finished=s,t.length=r,t.pos=i,t.outputLen=a,t}clone(){return this._cloneInto()}}class Vu extends Jo{v0l=se[0]|0;v0h=se[1]|0;v1l=se[2]|0;v1h=se[3]|0;v2l=se[4]|0;v2h=se[5]|0;v3l=se[6]|0;v3h=se[7]|0;v4l=se[8]|0;v4h=se[9]|0;v5l=se[10]|0;v5h=se[11]|0;v6l=se[12]|0;v6h=se[13]|0;v7l=se[14]|0;v7h=se[15]|0;constructor(t={}){const n=t.dkLen===void 0?64:t.dkLen;super(128,n),Lu(n,t,64,16,16);let{key:r,personalization:s,salt:o}=t,a=0;if(r!==void 0&&(De(r,void 0,"key"),a=r.length),this.v0l^=this.outputLen|a<<8|65536|1<<24,o!==void 0){De(o,void 0,"salt");const i=Ut(o);this.v4l^=ut(i[0]),this.v4h^=ut(i[1]),this.v5l^=ut(i[2]),this.v5h^=ut(i[3])}if(s!==void 0){De(s,void 0,"personalization");const i=Ut(s);this.v6l^=ut(i[0]),this.v6h^=ut(i[1]),this.v7l^=ut(i[2]),this.v7h^=ut(i[3])}if(r!==void 0){const i=new Uint8Array(this.blockLen);i.set(r),this.update(i)}}get(){let{v0l:t,v0h:n,v1l:r,v1h:s,v2l:o,v2h:a,v3l:i,v3h:l,v4l:c,v4h:u,v5l:h,v5h:p,v6l:v,v6h:d,v7l:f,v7h:b}=this;return[t,n,r,s,o,a,i,l,c,u,h,p,v,d,f,b]}set(t,n,r,s,o,a,i,l,c,u,h,p,v,d,f,b){this.v0l=t|0,this.v0h=n|0,this.v1l=r|0,this.v1h=s|0,this.v2l=o|0,this.v2h=a|0,this.v3l=i|0,this.v3h=l|0,this.v4l=c|0,this.v4h=u|0,this.v5l=h|0,this.v5h=p|0,this.v6l=v|0,this.v6h=d|0,this.v7l=f|0,this.v7h=b|0}compress(t,n,r){this.get().forEach((l,c)=>O[c]=l),O.set(se,16);let{h:s,l:o}=Tn(BigInt(this.length));O[24]=se[8]^o,O[25]=se[9]^s,r&&(O[28]=~O[28],O[29]=~O[29]);let a=0;const i=Ou;for(let l=0;l<12;l++)Et(0,4,8,12,t,n+2*i[a++]),kt(0,4,8,12,t,n+2*i[a++]),Et(1,5,9,13,t,n+2*i[a++]),kt(1,5,9,13,t,n+2*i[a++]),Et(2,6,10,14,t,n+2*i[a++]),kt(2,6,10,14,t,n+2*i[a++]),Et(3,7,11,15,t,n+2*i[a++]),kt(3,7,11,15,t,n+2*i[a++]),Et(0,5,10,15,t,n+2*i[a++]),kt(0,5,10,15,t,n+2*i[a++]),Et(1,6,11,12,t,n+2*i[a++]),kt(1,6,11,12,t,n+2*i[a++]),Et(2,7,8,13,t,n+2*i[a++]),kt(2,7,8,13,t,n+2*i[a++]),Et(3,4,9,14,t,n+2*i[a++]),kt(3,4,9,14,t,n+2*i[a++]);this.v0l^=O[0]^O[16],this.v0h^=O[1]^O[17],this.v1l^=O[2]^O[18],this.v1h^=O[3]^O[19],this.v2l^=O[4]^O[20],this.v2h^=O[5]^O[21],this.v3l^=O[6]^O[22],this.v3h^=O[7]^O[23],this.v4l^=O[8]^O[24],this.v4h^=O[9]^O[25],this.v5l^=O[10]^O[26],this.v5h^=O[11]^O[27],this.v6l^=O[12]^O[28],this.v6h^=O[13]^O[29],this.v7l^=O[14]^O[30],this.v7h^=O[15]^O[31],gt(O)}destroy(){this.destroyed=!0,gt(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const Mn=Er(e=>new Vu(e));function Zo(e,t,n,r,s,o,a,i,l,c,u,h,p,v,d,f,b,y,m,g){let w=0;for(let E=0;E<r;E++)({a:s,b:l,c:p,d:b}=wt(s,l,p,b,n[t+e[w++]])),{a:s,b:l,c:p,d:b}=$t(s,l,p,b,n[t+e[w++]]),{a:o,b:c,c:v,d:y}=wt(o,c,v,y,n[t+e[w++]]),{a:o,b:c,c:v,d:y}=$t(o,c,v,y,n[t+e[w++]]),{a,b:u,c:d,d:m}=wt(a,u,d,m,n[t+e[w++]]),{a,b:u,c:d,d:m}=$t(a,u,d,m,n[t+e[w++]]),{a:i,b:h,c:f,d:g}=wt(i,h,f,g,n[t+e[w++]]),{a:i,b:h,c:f,d:g}=$t(i,h,f,g,n[t+e[w++]]),{a:s,b:c,c:d,d:g}=wt(s,c,d,g,n[t+e[w++]]),{a:s,b:c,c:d,d:g}=$t(s,c,d,g,n[t+e[w++]]),{a:o,b:u,c:f,d:b}=wt(o,u,f,b,n[t+e[w++]]),{a:o,b:u,c:f,d:b}=$t(o,u,f,b,n[t+e[w++]]),{a,b:h,c:p,d:y}=wt(a,h,p,y,n[t+e[w++]]),{a,b:h,c:p,d:y}=$t(a,h,p,y,n[t+e[w++]]),{a:i,b:l,c:v,d:m}=wt(i,l,v,m,n[t+e[w++]]),{a:i,b:l,c:v,d:m}=$t(i,l,v,m,n[t+e[w++]]);return{v0:s,v1:o,v2:a,v3:i,v4:l,v5:c,v6:u,v7:h,v8:p,v9:v,v10:d,v11:f,v12:b,v13:y,v14:m,v15:g}}const ei=new TextEncoder().encode("SS58PRE"),kr=2,ti=e=>{try{const t=Po.decode(e),n=t.subarray(0,t[0]&64?2:1),r=t.subarray(n.length,t.length-kr),s=t.subarray(n.length+r.length),o=Mn(Uint8Array.of(...ei,...n,...r),{dkLen:64}).subarray(0,kr);return s[0]===o[0]&&s[1]===o[1]?{isValid:!0,ss58Format:Nu(n),publicKey:r.slice()}:{isValid:!1}}catch{return{isValid:!1}}},Nu=e=>{const t=new DataView(e.buffer,e.byteOffset,e.byteLength);return t.byteLength===1?t.getUint8(0):t.getUint16(0)},Pu=e=>{let t={},n=0,r=0;const s=()=>{n===r?(t={},n=r=0):(r=n,setTimeout(s,0))};return o=>{var a,i;++n===1&&s();let l=t;const c=o.length-1;for(let u=0;u<=c;u++)l=l[a=o[u]]||(l[a]={});return l[i=o[c]]||(l[i]=e(o))}},ni=e=>{const t=e<64?Uint8Array.of(e):Uint8Array.of((e&252)>>2|64,e>>8|(e&3)<<6);return Pu(n=>{const r=Mn(Uint8Array.of(...ei,...t,...n),{dkLen:64}).subarray(0,kr);return Po.encode(Uint8Array.of(...t,...n,...r))})};function Fu(e,t){return n=>{const r=ti(n);if(!r.isValid)throw new Error("Invalid checksum");const{publicKey:s}=r;if(s.length!==e)throw new Error("Invalid public key length");return s}}const un=(e=42,t=32)=>Ve(ne(t),Fu(t),ni(e)),R=Ve(pe,e=>e,Number),Un=Ve(pe,e=>e,BigInt),Wu=new TextEncoder,qu=new TextDecoder,Ku=ze(R,ne(1/0))[1],zn={toText:e=>qu.decode(e),toHex:e=>X(e),toOpaque:e=>oe([pe[0](e.length),e]),fromText:e=>Wu.encode(e),fromHex:e=>ee(e),fromOpaque:e=>{const t=typeof e=="string"?ee(e):e;try{const[n,r]=Ku(t);if(n===r.length)return r}catch{}throw new Error("Invalid opaque bytes")}},ri=e=>Ve(ne(e),ee,X),Gu=lt(e=>{const t=R.dec(e),n=Math.ceil(t/8);return{bytes:ne(n).dec(e),bitsLen:t}}),Yu=e=>{if(e.bitsLen>e.bytes.length*8)throw new Error(`Not enough bytes. (bitsLen:${e.bitsLen}, bytesLen:${e.bytes.length})`);const t=R.enc(e.bitsLen),n=new Uint8Array(e.bytes.length+t.length);return n.set(t,0),n.set(e.bytes,t.length),n},Xu=G(Yu,Gu),Qu=Ve(P,e=>e.charCodeAt(0),String.fromCharCode),si=e=>{const t=ne.enc(e);return n=>t(ee(n))},oi=e=>{const t=ne.dec(e);return n=>X(t(n))},we=e=>G(si(e),oi(e));we.enc=si,we.dec=oi;const ii=new TextEncoder,Ju=new TextDecoder,Zu=e=>Ve(ne(e),t=>ii.encode(t),t=>Ju.decode(t)),ai=e=>{let t=n=>{const r=e();return t=r,r(n)};return n=>t(n)},ci=e=>{let t=n=>{const r=e(),s=r;return t=r,s(n)};return n=>t(n)},xr=e=>G(ai(()=>e().enc),ci(()=>e().dec)),ed={is(e,t){return e.type===t},as(e,t){if(t!==e.type)throw new Error(`Enum.as(enum, ${t}) used with actual type ${e.type}`);return e}},Dn=Object.assign((e,t)=>({type:e,value:t}),ed),td=new Proxy({},{get(e,t){return n=>Dn(t,n)}}),re=(e,t)=>{const n=e;return n.inner=t,n},li=(...e)=>{const t=ke.enc(...e);return re(n=>t({tag:n.type,value:n.value}),e[0])},ui=(...e)=>{const t=ke.dec(...e);return re(n=>{const{tag:r,value:s}=t(n);return Dn(r,s)},e[0])},Se=(e,...t)=>re(G(li(mt(e,([n])=>n),...t),ui(mt(e,([,n])=>n),...t)),e);Se.enc=li,Se.dec=ui;const Sr=(e,...t)=>re(ke(e,...t),e);Sr.enc=(e,...t)=>re(ke.enc(e,...t),e),Sr.dec=(e,...t)=>re(ke.dec(e,...t),e);const tt={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},dt=Cu.slice(),di=(()=>{const e=Array.from({length:16},(r,s)=>s),t=r=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map(s=>r[s]),n=[];for(let r=0,s=e;r<7;r++,s=t(s))n.push(...s);return Uint8Array.from(n)})();class Ir extends Jo{chunkPos=0;chunksDone=0;flags=0;IV;state;stack=[];posOut=0;bufferOut32=new Uint32Array(16);bufferOut;chunkOut=0;enableXOF=!0;constructor(t={},n=0){super(64,t.dkLen===void 0?32:t.dkLen);const{key:r,context:s}=t,o=s!==void 0;if(r!==void 0){if(o)throw new Error('Only "key" or "context" can be specified at same time');De(r,32,"key");const a=r.slice();this.IV=Ut(a),ge(this.IV),this.flags=n|tt.KEYED_HASH}else if(o){De(s,void 0,"context");const a=s,i=new Ir({dkLen:32},tt.DERIVE_KEY_CONTEXT).update(a).digest();this.IV=Ut(i),ge(this.IV),this.flags=n|tt.DERIVE_KEY_MATERIAL}else this.IV=dt.slice(),this.flags=n;this.state=this.IV.slice(),this.bufferOut=Bu(this.bufferOut32)}get(){return[]}set(){}b2Compress(t,n,r,s=0){const{state:o,pos:a}=this,{h:i,l}=Tn(BigInt(t),!0),{v0:c,v1:u,v2:h,v3:p,v4:v,v5:d,v6:f,v7:b,v8:y,v9:m,v10:g,v11:w,v12:E,v13:$,v14:k,v15:S}=Zo(di,s,r,7,o[0],o[1],o[2],o[3],o[4],o[5],o[6],o[7],dt[0],dt[1],dt[2],dt[3],i,l,a,n);o[0]=c^y,o[1]=u^m,o[2]=h^g,o[3]=p^w,o[4]=v^E,o[5]=d^$,o[6]=f^k,o[7]=b^S}compress(t,n=0,r=!1){let s=this.flags;if(this.chunkPos||(s|=tt.CHUNK_START),(this.chunkPos===15||r)&&(s|=tt.CHUNK_END),r||(this.pos=this.blockLen),this.b2Compress(this.chunksDone,s,t,n),this.chunkPos+=1,this.chunkPos===16||r){let o=this.state;this.state=this.IV.slice();for(let a,i=this.chunksDone+1;(r||!(i&1))&&(a=this.stack.pop());i>>=1)this.buffer32.set(a,0),this.buffer32.set(o,8),this.pos=this.blockLen,this.b2Compress(0,this.flags|tt.PARENT,this.buffer32,0),o=this.state,this.state=this.IV.slice();this.chunksDone++,this.chunkPos=0,this.stack.push(o)}this.pos=0}_cloneInto(t){t=super._cloneInto(t);const{IV:n,flags:r,state:s,chunkPos:o,posOut:a,chunkOut:i,stack:l,chunksDone:c}=this;return t.state.set(s.slice()),t.stack=l.map(u=>Uint32Array.from(u)),t.IV.set(n),t.flags=r,t.chunkPos=o,t.chunksDone=c,t.posOut=a,t.chunkOut=i,t.enableXOF=this.enableXOF,t.bufferOut32.set(this.bufferOut32),t}destroy(){this.destroyed=!0,gt(this.state,this.buffer32,this.IV,this.bufferOut32),gt(...this.stack)}b2CompressOut(){const{state:t,pos:n,flags:r,buffer32:s,bufferOut32:o}=this,{h:a,l:i}=Tn(BigInt(this.chunkOut++));ge(s);const{v0:l,v1:c,v2:u,v3:h,v4:p,v5:v,v6:d,v7:f,v8:b,v9:y,v10:m,v11:g,v12:w,v13:E,v14:$,v15:k}=Zo(di,0,s,7,t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],dt[0],dt[1],dt[2],dt[3],i,a,n,r);o[0]=l^b,o[1]=c^y,o[2]=u^m,o[3]=h^g,o[4]=p^w,o[5]=v^E,o[6]=d^$,o[7]=f^k,o[8]=t[0]^b,o[9]=t[1]^y,o[10]=t[2]^m,o[11]=t[3]^g,o[12]=t[4]^w,o[13]=t[5]^E,o[14]=t[6]^$,o[15]=t[7]^k,ge(s),ge(o),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,gt(this.buffer.subarray(this.pos));let t=this.flags|tt.ROOT;this.stack.length?(t|=tt.PARENT,ge(this.buffer32),this.compress(this.buffer32,0,!0),ge(this.buffer32),this.chunksDone=0,this.pos=this.blockLen):t|=(this.chunkPos?0:tt.CHUNK_START)|tt.CHUNK_END,this.flags=t,this.b2CompressOut()}writeInto(t){ln(this,!1),De(t),this.finish();const{blockLen:n,bufferOut:r}=this;for(let s=0,o=t.length;s<o;){this.posOut>=n&&this.b2CompressOut();const a=Math.min(n-this.posOut,o-s);t.set(r.subarray(this.posOut,this.posOut+a),s),this.posOut+=a,s+=a}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible after digest call");return this.writeInto(t)}xof(t){return Yt(t),this.xofInto(new Uint8Array(t))}digestInto(t){if($r(t,this),this.finished)throw new Error("digest() was already called");return this.enableXOF=!1,this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}}const nd=Er((e={})=>new Ir(e)),rd=BigInt(0),dn=BigInt(1),sd=BigInt(2),od=BigInt(7),id=BigInt(256),ad=BigInt(113),hi=[],pi=[],fi=[];for(let e=0,t=dn,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],hi.push(2*(5*r+n)),pi.push((e+1)*(e+2)/2%64);let s=rd;for(let o=0;o<7;o++)t=(t<<dn^(t>>od)*ad)%id,t&sd&&(s^=dn<<(dn<<BigInt(o))-dn);fi.push(s)}const vi=_u(fi,!0),cd=vi[0],ld=vi[1],bi=(e,t,n)=>n>32?Du(e,t,n):Uu(e,t,n),mi=(e,t,n)=>n>32?ju(e,t,n):zu(e,t,n);function ud(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let a=0;a<10;a++)n[a]=e[a]^e[a+10]^e[a+20]^e[a+30]^e[a+40];for(let a=0;a<10;a+=2){const i=(a+8)%10,l=(a+2)%10,c=n[l],u=n[l+1],h=bi(c,u,1)^n[i],p=mi(c,u,1)^n[i+1];for(let v=0;v<50;v+=10)e[a+v]^=h,e[a+v+1]^=p}let s=e[2],o=e[3];for(let a=0;a<24;a++){const i=pi[a],l=bi(s,o,i),c=mi(s,o,i),u=hi[a];s=e[u],o=e[u+1],e[u]=l,e[u+1]=c}for(let a=0;a<50;a+=10){for(let i=0;i<10;i++)n[i]=e[a+i];for(let i=0;i<10;i++)e[a+i]^=~n[(i+2)%10]&n[(i+4)%10]}e[0]^=cd[r],e[1]^=ld[r]}gt(n)}class Br{state;pos=0;posOut=0;finished=!1;state32;destroyed=!1;blockLen;suffix;outputLen;enableXOF=!1;rounds;constructor(t,n,r,s=!1,o=24){if(this.blockLen=t,this.suffix=n,this.outputLen=r,this.enableXOF=s,this.rounds=o,Yt(r,"outputLen"),!(0<t&&t<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=Ut(this.state)}clone(){return this._cloneInto()}keccak(){ge(this.state32),ud(this.state32,this.rounds),ge(this.state32),this.posOut=0,this.pos=0}update(t){ln(this),De(t);const{blockLen:n,state:r}=this,s=t.length;for(let o=0;o<s;){const a=Math.min(n-this.pos,s-o);for(let i=0;i<a;i++)r[this.pos++]^=t[o++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:n,pos:r,blockLen:s}=this;t[r]^=n,(n&128)!==0&&r===s-1&&this.keccak(),t[s-1]^=128,this.keccak()}writeInto(t){ln(this,!1),De(t),this.finish();const n=this.state,{blockLen:r}=this;for(let s=0,o=t.length;s<o;){this.posOut>=r&&this.keccak();const a=Math.min(r-this.posOut,o-s);t.set(n.subarray(this.posOut,this.posOut+a),s),this.posOut+=a,s+=a}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return Yt(t),this.xofInto(new Uint8Array(t))}digestInto(t){if($r(t,this),this.finished)throw new Error("digest() was already called");return this.writeInto(t),this.destroy(),t}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,gt(this.state)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:s,rounds:o,enableXOF:a}=this;return t||=new Br(n,r,s,a,o),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=o,t.suffix=r,t.outputLen=s,t.enableXOF=a,t.destroyed=this.destroyed,t}}const jn=((e,t,n,r={})=>Er(()=>new Br(t,e,n),r))(1,136,32),yi=e=>{const t=e.slice(2),n=X(jn(ii.encode(t))).slice(2),r=new Array(40);for(let s=0;s<40;s++){const o=parseInt(n[s],16),a=t[s];r[s]=o>7?a.toUpperCase():a}return`0x${r.join("")}`},dd=ne(20)[1],gi=G(e=>{const t=ee(e);if(t.length!==20)throw new Error(`Invalid length found on EthAddress(${e})`);const n=X(t);if(e===n||e===n.toUpperCase())return t;if(yi(n)!==e)throw new Error(`Invalid checksum found on EthAddress(${e})`);return t},lt(e=>yi(X(dd(e))))),be=e=>re(U(e),e);be.enc=e=>re(U.enc(e),e),be.dec=e=>re(U.dec(e),e);const Pe=(...e)=>re(ze(...e),e);Pe.enc=(...e)=>re(ze.enc(...e),e),Pe.dec=(...e)=>re(ze.dec(...e),e);const Ae=(e,...t)=>re(j(e,...t),e);Ae.enc=(e,...t)=>re(j.enc(e,...t),e),Ae.dec=(e,...t)=>re(j.dec(e,...t),e);const Ln=(e,t)=>re(cn(e,t),{ok:e,ko:t});Ln.enc=(e,t)=>re(cn.enc(e,t),{ok:e,ko:t}),Ln.dec=(e,t)=>re(cn.dec(e,t),{ok:e,ko:t});const xt=e=>re(xe(e),e);xt.enc=e=>re(xe.enc(e),e),xt.dec=e=>re(xe.dec(e),e);const wi=(e=!0)=>lt(t=>{const n=R.dec(t),r=Math.ceil(n/8),s=ne(r).dec(t),o=new Array(n);let a=0;return s.forEach(i=>{for(let l=0;l<8&&a<n;l++){const c=e?l:7-l;o[a++]=i>>c&1}}),o}),$i=(e=!0)=>t=>{const n=R.enc(t.length),r=Math.ceil(t.length/8),s=new Uint8Array(r);for(let o=0;o<r;o++){let a=o*8,i=0;for(let l=0;l<8&&a<t.length;l++,a++)i|=t[a]<<(e?l:7-l);s[o]=i}return oe([n,s])},Vn=e=>G($i(e),wi(e));Vn.enc=$i,Vn.dec=wi;const Ei=new TextEncoder,ki=new TextDecoder,hd=Ve(ne(4),Ei.encode.bind(Ei),ki.decode.bind(ki)),Ar=be({engine:hd,payload:we()}),pd=Se({other:ne(),consensus:Ar,seal:Ar,preRuntime:Ar,runtimeUpdated:M},[0,4,5,6,8]),Or=we(32),Nn=be({parentHash:Or,number:R,stateRoot:Or,extrinsicRoot:Or,digests:Ae(pd)}),Oe=j(W),xi=xe(W),fd=ke({bool:M,char:M,str:M,u8:M,u16:M,u32:M,u64:M,u128:M,u256:M,i8:M,i16:M,i32:M,i64:M,i128:M,i256:M}),Si=j(U({name:xi,type:R,typeName:xi,docs:Oe})),vd=U({len:Ne,type:R}),bd=U({bitStoreType:R,bitOrderType:R}),md=j(U({name:W,fields:Si,index:P,docs:Oe})),yd=ke({composite:Si,variant:md,sequence:R,array:vd,tuple:j(R),primitive:fd,compact:R,bitSequence:bd}),gd=U({name:W,type:xe(R)}),wd=j(gd),$d=U({id:R,path:Oe,params:wd,def:yd,docs:Oe}),Pn=j($d),Xt=ke({NotDeprecated:M,DeprecatedWithoutNote:M,Deprecated:U({note:W,since:xe(W)})}),Ed=j(U({index:P,deprecation:ke({DeprecatedWithoutNote:M,Deprecated:U({note:W,since:xe(W)})},[1,2])})),Cr={name:W,inputs:j(U({name:W,type:R})),output:R,docs:Oe},kd=U({name:W,methods:j(U(Cr)),docs:Oe}),xd=U({name:W,methods:j(U({...Cr,deprecationInfo:Xt})),docs:Oe,version:R,deprecationInfo:Xt}),Sd=U({id:we(32),...Cr,deprecationInfo:Xt}),Id=ke({Blake2128:M,Blake2256:M,Blake2128Concat:M,Twox128:M,Twox256:M,Twox64Concat:M,Identity:M}),Bd=j(Id),Ad=U({hashers:Bd,key:R,value:R}),Ii={name:W,modifier:P,type:ke({plain:R,map:Ad}),fallback:we(),docs:Oe},_r=xe(R),Bi={name:W,storage:xe(U({prefix:W,items:j(U(Ii))})),calls:_r,events:_r,constants:j(U({name:W,type:R,value:we(),docs:Oe})),errors:_r,index:P},Od={...Bi,docs:Oe},Rr=xe(U({type:R,deprecationInfo:Ed})),Cd={name:W,storage:xe(U({prefix:W,items:j(U({...Ii,deprecationInfo:Xt}))})),calls:Rr,events:Rr,constants:j(U({name:W,type:R,value:we(),docs:Oe,deprecationInfo:Xt})),errors:Rr,associatedTypes:j(U({name:W,type:R,docs:Oe})),viewFns:j(Sd),index:P,docs:Oe,deprecationInfo:Xt},_d=new Uint8Array,Ai=e=>G(()=>_d,()=>e),Rd=U({type:R,version:P,signedExtensions:j(U({identifier:W,type:R,additionalSigned:R}))}),Oi=U({lookup:Pn,pallets:j(U({...Bi,docs:Ai([])})),extrinsic:Rd,type:R,apis:Ai([])}),Hd=U({version:P,address:R,call:R,signature:R,extra:R,signedExtensions:j(U({identifier:W,type:R,additionalSigned:R}))}),Ci=U({lookup:Pn,pallets:j(U(Od)),extrinsic:Hd,type:R,apis:j(kd),outerEnums:U({call:R,event:R,error:R}),custom:j(ze(W,U({type:R,value:we()})))}),Td=U({version:j(P),address:R,call:R,signature:R,signedExtensionsByVersion:j(ze(P,j(R))),signedExtensions:j(U({identifier:W,type:R,additionalSigned:R}))}),_i=U({lookup:Pn,pallets:j(U(Cd)),extrinsic:Td,apis:j(xd),outerEnums:U({call:R,event:R,error:R}),custom:j(ze(W,U({type:R,value:we()})))}),Ri=()=>{throw new Error("Unsupported metadata version!")},Ie=G(Ri,Ri),zt=U({magicNumber:Ne,metadata:ke({v0:Ie,v1:Ie,v2:Ie,v3:Ie,v4:Ie,v5:Ie,v6:Ie,v7:Ie,v8:Ie,v9:Ie,v10:Ie,v11:Ie,v12:Ie,v13:Ie,v14:Oi,v15:Ci,v16:_i})}),Hr=ne(),Md=xe(Hr),Ud=ze(pe,Hr),Hi=e=>{try{return zt.dec(e)}catch{}try{return zt.dec(Md.dec(e))}catch{}try{return zt.dec(Hr.dec(e))}catch{}try{return zt.dec(Ud.dec(e)[1])}catch{}throw null},Fn=e=>{if("magicNumber"in e&&(e=e.metadata),"tag"in e){if(e.tag!=="v14"&&e.tag!=="v15"&&e.tag!=="v16")throw new Error("Only metadata 14, 15, and 16 are supported");e=e.value}if("signedExtensionsByVersion"in e.extrinsic){const{extrinsic:{signedExtensions:s,signedExtensionsByVersion:o,...a},...i}=e;if(!o.some(([l])=>l===0))throw new Error("Extension version 0 not found");return{version:16,extrinsic:{...a,signedExtensions:Object.fromEntries(o.map(([l,c])=>[l,c.map(u=>s[u])]))},...i}}if("custom"in e){const{lookup:s,extrinsic:o,custom:a,apis:i,pallets:l,outerEnums:c}=e;return{version:15,lookup:s,pallets:l.map(u=>({...u,calls:u.calls!=null?{type:u.calls}:void 0,events:u.events!=null?{type:u.events}:void 0,errors:u.errors!=null?{type:u.errors}:void 0,viewFns:[],associatedTypes:[]})),extrinsic:{...o,signedExtensions:{0:o.signedExtensions},version:[o.version]},apis:i,outerEnums:c,custom:a}}const{lookup:t,extrinsic:n,pallets:r}=e;return{version:14,lookup:t,pallets:r.map(s=>({...s,calls:s.calls!=null?{type:s.calls}:void 0,events:s.events!=null?{type:s.events}:void 0,errors:s.errors!=null?{type:s.errors}:void 0,viewFns:[],associatedTypes:[]})),extrinsic:{...n,signedExtensions:{0:n.signedExtensions},version:[n.version]},apis:[]}},Dt={bare:0,0:"bare",general:1,1:"general",signed:2,2:"signed"},Tr=Ve(P,({version:e,type:t})=>e+(Dt[t]<<6),e=>{const t=e&63,n=e>>6;if(t===4&&(n===Dt.bare||n===Dt.signed))return{version:t,type:Dt[n]};if(t===5&&(n===Dt.bare||n===Dt.general))return{version:t,type:Dt[n]};throw new Error(`ExtrinsicFormat ${e} not valid`)}),zd={dkLen:32},jt=e=>Mn(e,zd),Dd={dkLen:16},Mr=e=>Mn(e,Dd),Ti=e=>oe([Mr(e),e]),jd={dkLen:32},Mi=e=>nd(e,jd),Ld=e=>oe([Mi(e),e]),Ui=e=>e,Lt=(e,t,n,r)=>new DataView(new Uint16Array([e,t,n,r]).buffer).getBigUint64(0,!0),Ur=2n**64n-1n,me=(e,t)=>e<<t&Ur|e>>64n-t,F=(e,t)=>e*t&Ur,ie=(e,t)=>e+t&Ur,ae=11400714785074694791n,Ce=14029467366897019727n,zi=1609587929392839161n,hn=9650029242287828579n,Di=2870177450012600261n;function St(e,t=0n){let n=ie(ie(t,ae),Ce),r=ie(t,Ce),s=t,o=t-ae,a=e.length,i=0,l=null;(function(){let p=0,v=p+a;if(a){if(l=new Uint8Array(32),a<32){l.set(e.subarray(0,a),i),i+=a;return}if(p<=v-32){const d=v-32;do{let f;f=Lt(e[p+1]<<8|e[p],e[p+3]<<8|e[p+2],e[p+5]<<8|e[p+4],e[p+7]<<8|e[p+6]),n=F(me(ie(n,F(f,Ce)),31n),ae),p+=8,f=Lt(e[p+1]<<8|e[p],e[p+3]<<8|e[p+2],e[p+5]<<8|e[p+4],e[p+7]<<8|e[p+6]),r=F(me(ie(r,F(f,Ce)),31n),ae),p+=8,f=Lt(e[p+1]<<8|e[p],e[p+3]<<8|e[p+2],e[p+5]<<8|e[p+4],e[p+7]<<8|e[p+6]),s=F(me(ie(s,F(f,Ce)),31n),ae),p+=8,f=Lt(e[p+1]<<8|e[p],e[p+3]<<8|e[p+2],e[p+5]<<8|e[p+4],e[p+7]<<8|e[p+6]),o=F(me(ie(o,F(f,Ce)),31n),ae),p+=8}while(p<=d)}p<v&&(l.set(e.subarray(p,v),i),i=v-p)}})(),e=l||e;let c,u=0;for(a>=32?(c=me(n,1n),c=ie(c,me(r,7n)),c=ie(c,me(s,12n)),c=ie(c,me(o,18n)),n=F(me(F(n,Ce),31n),ae),c=c^n,c=ie(F(c,ae),hn),r=F(me(F(r,Ce),31n),ae),c=c^r,c=ie(F(c,ae),hn),s=F(me(F(s,Ce),31n),ae),c=c^s,c=ie(F(c,ae),hn),o=F(me(F(o,Ce),31n),ae),c=c^o,c=ie(F(c,ae),hn)):c=ie(t,Di),c=ie(c,BigInt(a));u<=i-8;){let p=Lt(e[u+1]<<8|e[u],e[u+3]<<8|e[u+2],e[u+5]<<8|e[u+4],e[u+7]<<8|e[u+6]);p=F(me(F(p,Ce),31n),ae),c=ie(F(me(c^p,27n),ae),hn),u+=8}if(u+4<=i){let p=F(Lt(e[u+1]<<8|e[u],e[u+3]<<8|e[u+2],0,0),ae);c=ie(F(me(c^p,23n),Ce),zi),u+=4}for(;u<i;){const p=F(Lt(e[u++],0,0,0),Di);c=F(me(c^p,11n),ae)}let h=c>>33n;return c=F(c^h,Ce),h=c>>29n,c=F(c^h,zi),h=c>>32n,c^=h,c}const Wn=e=>{const t=new Uint8Array(16),n=new DataView(t.buffer);return n.setBigUint64(0,St(e),!0),n.setBigUint64(8,St(e,1n),!0),t},ji=e=>{const t=new Uint8Array(32),n=new DataView(t.buffer);return n.setBigUint64(0,St(e),!0),n.setBigUint64(8,St(e,1n),!0),n.setBigUint64(16,St(e,2n),!0),n.setBigUint64(24,St(e,3n),!0),t},Li=e=>oe([an.enc(St(e)),e]),Vi=new TextEncoder,Vd=new Map([[Ui,0],[Li,8],[Ti,16],[Mr,-16],[jt,-32],[Wn,-16],[ji,-32]]),Ni=e=>{const t=Wn(Vi.encode(e));return(n,...r)=>{const s=oe([t,Wn(Vi.encode(n))]),o=X(s),a=l=>{if(!l.startsWith(o))throw new Error(`key does not match this storage (${e}.${n})`);if(r.length===0)return[];const c=ee(l.slice(o.length)),u=new Array(r.length);for(let h=0,p=0;h<r.length;h++){const[v,d]=r[h],f=Vd.get(d);if(f==null)throw new Error("Unknown hasher");if(f<0){const b=f*-1;u[h]=X(c.slice(p,p+b)),p+=b}else p+=f,u[h]=v.dec(c.slice(p)),p+=v.enc(u[h]).length}return u},i=r.map(([{enc:l},c])=>u=>c(l(u)));return{enc:(...l)=>X(oe([s,...l.map((c,u)=>i[u](c))])),dec:a}}},Nd=zn.fromText("modlpy/utilisuba"),Pd=({threshold:e,signatories:t})=>{const n=Pi(t),r=oe([Nd,pe.enc(n.length),...n,et.enc(e)]);return jt(r)},Pi=e=>e.slice().sort((t,n)=>{for(let r=0;;r++){const s=r>=t.length,o=r>=n.length;if(s&&o)return 0;if(s)return-1;if(o)return 1;if(t[r]!==n[r])return t[r]>n[r]?1:-1}}),It={Leaf:"Leaf",Branch:"Branch",BranchWithVal:"BranchWithVal",LeafWithHash:"LeafWithHash",BranchWithHash:"BranchWithHash",Empty:"Empty",Reserved:"Reserved"},Fi=we().dec,Fd=we(1/0).dec,Wd=we(32).dec,Wi=P.dec,qd=e=>{const t=Wi(e);let n=6;const r=t>>n,s=r?r===1?It.Leaf:r===2?It.Branch:It.BranchWithVal:t>>--n?It.LeafWithHash:t>>--n?It.BranchWithHash:t?It.Reserved:It.Empty;let o=t&255>>8-n;if(o===2**n-1){let a;do o+=a=Wi(e);while(a===255)}return{type:s,partialKey:we(Math.ceil(o/2)).dec(e).slice(o%2?3:2)}},qi=lt(e=>{const t=qd(e),{type:n}=t;if(n==="Empty"||n==="Reserved")return t;if(n==="Leaf"||n==="LeafWithHash")return{...t,value:Fd(e)};const r=et.dec(e),s=[];for(let i=0;i<16;i++)r>>i&1&&s.push(i.toString(16));let o=null;n==="BranchWithVal"&&(o=Fi(e)),n==="BranchWithHash"&&(o=Wd(e));const a={...t,children:Object.fromEntries(s.map(i=>[i,Fi(e)]))};return o!==null&&(a.value=o),a}),Ki=e=>lt(t=>{const n=X(e(new Uint8Array(t.buffer)));try{return{hash:n,...qi(t)}}catch{return{type:"Raw",hash:n,value:""}}}),Gi=(e,t=jt)=>{const n=e.map(Ki(t)),r=Object.fromEntries(n.map(i=>[i.hash,i])),s=n.map(i=>i.hash),o=new Set(s),a=i=>{if(i.value)return;const l=e[s.indexOf(i.hash)];i.value=typeof l=="string"?l:X(l)};return n.forEach(i=>{if("children"in i&&Object.values(i.children).forEach(l=>{const c=r[l];c&&(c.parent=i.hash,o.delete(l))}),i.type==="BranchWithHash"||i.type==="LeafWithHash"){const l=i.value,c=r[l];if(!c)return;o.delete(l),c.type!=="Raw"&&(Object.keys(c).forEach(u=>delete c[u]),c.type="Raw",c.hash=l),c.parent=i.hash,a(c)}i.type==="Raw"&&a(i)}),o.size===1?{rootHash:o.values().next().value,proofs:r}:null};var Yi=Object.freeze({__proto__:null,AccountId:un,Binary:zn,BitSeq:Vn,Blake2128:Mr,Blake2128Concat:Ti,Blake2256:jt,Blake3256:Mi,Blake3256Concat:Ld,Bytes:ne,Enum:Dn,Hex:we,Identity:Ui,Keccak256:jn,Option:xt,Result:Ln,ScaleEnum:Sr,Self:xr,SizedBytes:ri,Storage:Ni,Struct:be,TrieNodeHeaders:It,TrieNodeWithHash:Ki,Tuple:Pe,Twox128:Wn,Twox256:ji,Twox64Concat:Li,Variant:Se,Vector:Ae,_Enum:td,_void:M,bitSequence:Xu,blockHeader:Nn,bool:ru,char:Qu,compact:pe,compactBn:Un,compactNumber:R,createCodec:G,createDecoder:lt,decAnyMetadata:Hi,enhanceCodec:Ve,enhanceDecoder:_n,enhanceEncoder:Cn,ethAccount:gi,extrinsicFormat:Tr,fixedStr:Zu,fromBufferToBase58:ni,getMultisigAccountId:Pd,getSs58AddressInfo:ti,h64:St,i128:eu,i16:Ql,i256:nu,i32:Jl,i64:Zl,i8:Xl,metadata:zt,selfDecoder:ci,selfEncoder:ai,sortMultisigSignatories:Pi,str:W,trieNodeDec:qi,u128:Eo,u16:et,u256:tu,u32:Ne,u64:an,u8:P,unifyMetadata:Fn,v14:Oi,v14Lookup:Pn,v15:Ci,v16:_i,validateProofs:Gi});const Kd=[jt,jn],Gd=(e,t)=>Kd.find(n=>X(n(ee(e)))===t)||(()=>{throw new Error("Unsupported hasher")}),Yd=e=>{const t=(n,r,s)=>{const o=n[r.idx],a=n[s.idx];if(n.length===2)return K([[o,r.id],[a,s.id]]);const i=r.idx+Math.floor((s.idx-r.idx)/2);return e(n[i]).pipe(z(l=>{const c={id:l,idx:i};return c.id===r.id?t(n,c,s):c.id===s.id?t(n,r,c):ue([t(n,r,c),t(n,c,s)]).pipe(x(([u,[h,...p]])=>[...u,...p]))}))};return n=>{const[r]=n;if(n.length===1)return e(r).pipe(x(o=>[[r,o]]));const s=n.length-1;return ue([r,n[s]].map(e)).pipe(z(([o,a])=>o===a?K([[r,o]]):t(n,{idx:0,id:o},{idx:s,id:a})))}},Xd=(e,t,n)=>{const r=Yd(t),s=l=>nn(()=>e().header(l)),o=new en(1),a=l=>{if(l.type==="initialized"){const[c]=l.finalizedBlockHashes;return ue([s(c),r(l.finalizedBlockHashes)]).pipe(x(([u,h])=>{o.closed||(o.next(Gd(u,c)),o.complete());const{number:p,parentHash:v,digests:d}=Nn.dec(u);return{type:"initialized",finalizedBlockHashes:l.finalizedBlockHashes,runtimeChanges:new Map(h),number:p,parentHash:v,hasNewRuntime:d.some(f=>f.type==="runtimeUpdated")}}))}if(l.type==="newBlock"&&l.newRuntime)return t(l.blockHash).pipe(x(c=>({...l,codeHash:c})))},i=l=>new D(c=>{let u=null,h;const p=f=>u?.push(f)||v(f),v=f=>{const b=a(f);b?(u=[],h=b.subscribe({next:y=>{const m=[...u];u=null,c.next(y),m.forEach(p)},error:n})):c.next(f)},d=l.subscribe(f=>{f.type==="stop-error"?(h?.unsubscribe(),u=null,c.next(f)):p(f)});return()=>{h?.unsubscribe(),d.unsubscribe()}});return{getHeader:l=>s(l).pipe(x(Nn[1])),hasher$:o.asObservable(),enhancer:i}},Qd=(e,t)=>{let n=null,r=!1,s=()=>{r=!0};const o=()=>{if(!n)throw new Error("Missing chainHead subscription");return n},a=t(Mt((v,d)=>o().storage(v,"hash","0x3a636f6465",null,d)));let i=Ee,l;const{hasher$:c,enhancer:u,getHeader:h}=Xd(o,a,v=>{console.warn("ChainHead subfollow request failed, retrying\u2026",v),l=setTimeout(()=>i(),250)}),p=new D(v=>{if(r)return v.complete();const d=()=>{let f=[];n=e(!0,b=>{f?f.push(b):v.next(b)},b=>{n=null,!r&&(b instanceof Error&&b.name===no.errorName?(d(),v.next({type:"stop-error"})):(console.warn("ChainHead follow request failed, retrying\u2026",b),l=setTimeout(d,250)))}),f.forEach(b=>v.next(b)),f=null};i=()=>{v.next({type:"stop-error"}),clearTimeout(l),n?.unfollow(),d()},d(),s=()=>{r=!0,clearTimeout(l),v.complete(),n?.unfollow()}}).pipe(u,bt());return{getHeader:h,hasher$:c,getFollower:o,follow$:p,unfollow:()=>{s()}}},Jd=e=>X(Ne.enc(e)),Xi=ne(),Zd=xt(Xi),eh=Ae(Ne).dec,Qi=e=>{const t=e("Metadata_metadata_versions","").pipe(x(eh),de(()=>K([14]))),n=r=>{const[s]=r.filter(o=>o>13&&o<17).sort((o,a)=>a-o);return s===14?e("Metadata_metadata","").pipe(x(Xi.dec)):e("Metadata_metadata_at_version",Jd(s)).pipe(x(o=>Zd.dec(o)))};return t.pipe(z(n))},Ji=(e,t)=>e.type==="array"&&e.len===t&&e.value.type==="primitive"&&e.value.value==="u8",Bt={type:"void"},th=(e,t=()=>null)=>{const n=new Map,r=new Set,s=u=>h=>{let p=n.get(h);if(p)return p;if(r.has(h)){const d={id:h};return n.set(h,d),d}r.add(h);const v=u(h);return p=n.get(h),p?Object.assign(p,v):(p={id:h,...v},n.set(h,p)),r.delete(h),p};let o=!0,a=!0;const i=s(u=>{const h=t(e[u]);if(h)return h;const{def:p,path:v,params:d}=e[u];if(p.tag==="composite"){if(p.value.length===0)return Bt;if(p.value.length===1){const f=i(p.value[0].type);return o&&v.at(-1)==="AccountId32"&&Ji(f,32)?(o=!1,{type:"AccountId32"}):a&&v.at(-1)==="AccountId20"&&Ji(f,20)?(a=!1,{type:"AccountId20"}):f}return l(p.value)}if(p.tag==="variant"){if(v.length===1&&v[0]==="Option"&&d.length===1&&d[0].name==="T"){const y=i(d[0].type);return y.type==="void"?{type:"primitive",value:"bool"}:{type:"option",value:y}}if(v.length===1&&v[0]==="Result"&&d.length===2&&d[0].name==="T"&&d[1].name==="E")return{type:"result",value:{ok:i(d[0].type),ko:i(d[1].type)}};if(p.value.length===0)return Bt;const f={},b={};return p.value.forEach(y=>{const m=y.name;if(b[m]=y.docs,y.fields.length===0){f[m]={...Bt,idx:y.index};return}if(y.fields.length===1&&!y.fields[0].name){f[m]={type:"lookupEntry",value:i(y.fields[0].type),idx:y.index};return}f[m]={...l(y.fields),idx:y.index}}),{type:"enum",value:f,innerDocs:b}}if(p.tag==="sequence")return{type:"sequence",value:i(p.value)};if(p.tag==="array"){const{len:f}=p.value,b=i(p.value.type);return!f||b.type==="void"?Bt:f>1?{type:"array",value:b,len:p.value.len}:b}if(p.tag==="tuple")return p.value.length===0?Bt:p.value.length>1?c(p.value.map(f=>i(f)),p.value.map(f=>e[f].docs)):i(p.value[0]);if(p.tag==="primitive")return{type:"primitive",value:p.value.tag};if(p.tag==="compact"){const f=i(p.value);return f.type==="void"?Bt:{type:"compact",isBig:Number(f.value.slice(1))>32,size:f.value}}return{type:p.tag,isLSB:(e[p.value.bitOrderType].path.at(-1)??"LSB").toUpperCase().startsWith("LSB")}}),l=u=>{let h=!0;const p={},v={};return u.forEach((d,f)=>{h=h&&!!d.name;const b=d.name||f,y=i(d.type);y.type!=="void"&&(p[b]=y,v[b]=d.docs)}),h?{type:"struct",value:p,innerDocs:v}:c(Object.values(p),Object.values(v))},c=(u,h)=>{if(u.every(p=>p.id===u[0].id)&&h.every(p=>!p.length)){const[p]=u;return p.type==="void"?Bt:{type:"array",value:u[0],len:u.length}}return{type:"tuple",value:u,innerDocs:h}};return i},Zi=e=>{const t=th(e.lookup,({def:r})=>{if(r.tag==="composite"){const s=n(r);if(s)return{type:"enum",innerDocs:{},value:Object.fromEntries(e.pallets.map(o=>[o.name,o.errors==null?{...Bt,idx:o.index}:{type:"lookupEntry",value:t(o.errors.type),idx:o.index}])),byteLength:s}}return null});function n(r){if(!(r.value.length===2&&r.value[0].name==="index"&&r.value[1].name==="error"))return null;const s=t(r.value[0].type),o=t(r.value[1].type);return s.type==="primitive"&&s.value==="u8"&&o.type==="array"&&o.value.type==="primitive"&&o.value.value==="u8"?1+o.len:null}return Object.assign(t,{metadata:e,call:"call"in e.extrinsic?e.extrinsic.call:e.lookup[e.extrinsic.type]?.params.find(r=>r.name==="Call")?.type??null})},nh=(e,t,n)=>(r,s,o,...a)=>{const{id:i}=r;if(s.has(i))return s.get(i);if(o.has(i)){const c=t(()=>s.get(i),r,...a);return s.set(i,c),c}o.add(i);let l=e(r,s,o,...a);return o.delete(i),s.has(i)&&(l=n(l,s.get(i),r,...a)),s.set(i,l),l},rh=ne(),sh=(e,t,n,r)=>{if(e.type==="primitive")return Yi[e.value];if(e.type==="void")return M;if(e.type==="AccountId32")return r;if(e.type==="AccountId20")return gi;if(e.type==="compact")return e.isBig?Un:R;if(e.type==="bitSequence")return Vn(e.isLSB);const s=p=>ea(p,t,n,r),o=(p,v)=>{const d=s(p);return v?Ae(d,v):Ae(d)},a=p=>Pe(...p.map(s)),i=p=>{const v=Object.fromEntries(Object.entries(p).map(([d,f])=>[d,s(f)]));return be(v)};if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return rh;if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?ri(e.len):o(e.value,e.len);if(e.type==="sequence")return o(e.value);if(e.type==="tuple")return a(e.value);if(e.type==="struct")return i(e.value);if(e.type==="option")return xt(s(e.value));if(e.type==="result")return Ln(s(e.value.ok),s(e.value.ko));const l=Object.values(e.value).map(p=>{switch(p.type){case"void":return M;case"lookupEntry":return s(p.value);case"tuple":return a(p.value);case"struct":return i(p.value);case"array":return o(p.value,p.len)}}),c=Object.fromEntries(Object.keys(e.value).map((p,v)=>[p,l[v]])),u=Object.values(e.value).map(p=>p.idx),h=u.every((p,v)=>p===v)?Se(c):Se(c,u);return e.byteLength?oh(h,e.byteLength):h},ea=nh(sh,xr,e=>e),ta=(e,t=un())=>{const n=new Map,r=s=>ea(e(s),n,new Set,t);return s=>r(s)},oh=(e,t)=>{const n=ne(t);return G(r=>n.enc(e.enc(r)),r=>e.dec(n.dec(r)))},ih=Ve(M,()=>{},()=>null),ah=e=>{const{metadata:t}=e;let n=ta(e);const r=t.pallets.find(p=>p.name==="System")?.constants.find(p=>p.name==="SS58Prefix");let s;if(r)try{const p=n(r.type).dec(r.value);typeof p=="number"&&(s=p,n=ta(e,un(p)))}catch{}const o=new Map,a=(p,v)=>{let d=o.get(p);d||o.set(p,d=Ni(p));const f=t.pallets.find(S=>S.name===p).storage.items.find(S=>S.name===v),b=S=>S===M?ih:S,y=(S,B,...I)=>{const _=d(...I),[,...H]=I;return{args:Pe(...H.map(([L])=>L)),keys:_,value:B,len:S,fallback:f.modifier===1?B.dec(f.fallback):void 0}};if(f.type.tag==="plain")return y(0,b(n(f.type.value)),v);const{key:m,value:g,hashers:w}=f.type.value,E=b(n(g)),$=w.map(S=>Yi[S.tag]),k=(()=>{if($.length===1)return[[n(m),$[0]]];const S=e(m);switch(S.type){case"array":return $.map(B=>[n(S.value.id),B]);case"tuple":return S.value.map((B,I)=>[n(B.id),$[I]]);default:throw new Error("Invalid key type")}})();return y($.length,E,v,...k)},i=p=>{switch(p.type){case"void":return M;case"lookupEntry":return n(p.value.id);case"tuple":return Pe(...Object.values(p.value).map(v=>n(v.id)));case"struct":return be(mt(p.value,v=>n(v.id)));case"array":return Ae(n(p.value.id),p.len)}},l=(p,v)=>{const d=t.pallets.find(f=>f.name===p).constants.find(f=>f.name===v);return n(d.type)},c=p=>(v,d)=>{const f=t.pallets.find(m=>m.name===v),b=e(f[p].type);if(b.type!=="enum")throw null;const y=b.value[d];return{location:[f.index,y.idx],codec:i(b.value[d])}},u=(p,v)=>{const d=t.pallets.find(f=>f.name===p)?.viewFns.find(f=>f.name===v);if(!d)throw null;return{args:Pe(...d.inputs.map(f=>n(f.type))),value:n(d.output)}},h=(p,v)=>{const d=t.apis.find(f=>f.name===p)?.methods.find(f=>f.name===v);if(!d)throw null;return{args:Pe(...d.inputs.map(f=>n(f.type))),value:n(d.output)}};return{buildDefinition:n,buildStorage:a,buildEvent:c("events"),buildError:c("errors"),buildViewFn:u,buildRuntimeCall:h,buildCall:c("calls"),buildConstant:l,ss58Prefix:s}},ch=(e,t)=>Object.fromEntries(e.pallets.map(n=>{const[r,s,o]=["errors","events","calls"].map(a=>{try{const i=t(n[a].type);if(i.type!=="enum")throw null;return new Map(Object.entries(i.value))}catch{return new Map}});return[n.name,{error:r,event:s,call:o}]})),lh=(e,t)=>{const n=ch(e,t),r=Object.fromEntries(e.pallets.map(i=>{const[l,c]=["constants","viewFns"].map(u=>new Map(i[u].map(h=>[h.name,h])));return[i.name,{const:l,view:c}]})),s=Object.fromEntries(e.pallets.map(i=>[i.name,new Map((i.storage?.items||[]).map(l=>[l.name,l]))])),o=mt(n,({error:i,event:l,call:c},u)=>({error:i,event:l,call:c,storage:s[u],...r[u]})),a=Object.fromEntries(e.apis.map(i=>[i.name,new Map(i.methods.map(l=>[l.name,l]))]));return{pallets:o,api:a,extensions:mt(e.extrinsic.signedExtensions,i=>Object.fromEntries(i.map(({identifier:l,...c})=>[l,c])))}},zr="CheckMortality",na=(e,t,n)=>{const r=Zi(e),s=ah(r),o=s.buildStorage("System","Events"),a=e.extrinsic.signedExtensions[0].find(u=>u.identifier==="ChargeAssetTxPayment");let i=null;if(a){const u=r(a.type);if(u.type==="struct"){const h=u.value.asset_id;h.type==="option"&&(i=h.value.id)}}const l=dh(r.metadata,s),c=u=>{const h=l(u);return"extra"in h&&h.extra[zr]||{mortal:!1}};return{mappedMeta:lh(e,r),assetId:i,metadataRaw:t,codeHash:n,lookup:r,dynamicBuilder:s,events:{key:o.keys.enc(),dec:o.value.dec},accountId:un(s.ss58Prefix),getMortalityFromTx:c,extVersions:e.extrinsic.version}},Dr=ne(1/0).dec,uh=_n(et[1],e=>{const t=2<<e%16,n=Math.max(t>>12,1),r=(e>>4)*n;return{mortal:!0,period:t,phase:r}}),ra=lt(e=>{const t=P.dec(e);if(t===0)return{mortal:!1};const n=P.dec(e);return uh(Uint8Array.from([t,n]))}),dh=(e,t)=>{const n=be.dec(Object.fromEntries(e.extrinsic.signedExtensions[0].map(i=>[i.identifier,i.identifier===zr?ra:t.buildDefinition(i.type)[1]])));let r,s;const{extrinsic:o}=e;if("address"in o)r=t.buildDefinition(o.address)[1],s=t.buildDefinition(o.signature)[1];else{const i=e.lookup[o.type]?.params,l=i?.find(h=>h.name==="Call")?.type,c=i?.find(h=>h.name==="Address")?.type,u=i?.find(h=>h.name==="Signature")?.type;if(l==null||c==null||u==null)throw new Error("Call, Address and/or signature not found");r=t.buildDefinition(c)[1],s=t.buildDefinition(u)[1]}const a=be.dec({address:r,signature:s,extra:n,callData:Dr});return lt(i=>{const l=R.dec(i),{type:c,version:u}=Tr[1](i);if(c==="bare")return{len:l,version:u,type:c,callData:Dr(i)};if(c==="signed")return{len:l,version:u,type:c,...a(i)};const h=P.dec(i);let p;if(e.version===16){const d=e.extrinsic.signedExtensions[h];if(!d)throw new Error("Unexpected extension version");p=be.dec(Object.fromEntries(d.map(f=>[f.identifier,f.identifier===zr?ra:t.buildDefinition(f.type)[1]])))}else p=n;const v=p(i);return{len:l,type:c,version:u,extensionVersion:h,extra:v,callData:Dr(i)}})},hh=e=>t=>{const n=(...r)=>{let s;try{s=e()}catch(o){return Rt(o)}return s?t(s,...r).pipe(de(o=>{if(o instanceof Je)return n(...r);if(o instanceof Error&&o.name===In.errorName)return En(750).pipe(z(()=>n(...r)));throw o})):Xe};return n},ph=(e,t,n)=>{const r=(s,o)=>t(s).pipe(de(()=>K(null)),z(a=>a?K(a):o.pipe(qt(i=>{n(s,i)}))),x(a=>({codeHash:s,metadataRaw:a,metadata:Fn(zt.dec(a))})));return(s,o)=>{const a=new Set([o]),i={},l=hh(()=>{if(!a.size)throw i;return a.has(o)?o:[...a].at(-1)}),c=r(s,Qi(l(e)).pipe(de(h=>h===i?Xe:Rt(()=>h)))).pipe(x(({metadata:h,metadataRaw:p,codeHash:v})=>na(h,p,v)),sn(1)),u={codeHash:s,runtime:c,addBlock:h=>{a.add(h)},deleteBlocks:h=>(h.forEach(p=>{a.delete(p)}),a.size),usages:a};return c.subscribe({error(){}}),u}},pn=bt({connector:()=>new en(1),resetOnError:!0,resetOnComplete:!0,resetOnRefCountZero:!0}),fn=({hash:e,number:t,parent:n,hasNewRuntime:r})=>({hash:e,number:t,parent:n,hasNewRuntime:r}),fh=(e,t,n,r,s,o,a,i)=>{const l=({blocks:m,runtimes:g},w)=>{w.forEach(E=>{m.get(m.get(E).parent)?.children.delete(E),m.delete(E),i(E)}),Object.entries(g).map(([E,$])=>({key:E,usages:$.deleteBlocks(w)})).filter(E=>E.usages===0).map(E=>E.key).forEach(E=>{delete g[E]})},c=m=>{o.next(fn(m))},u=m=>{l(m,[...m.blocks.values()].filter(w=>w.recovering).map(w=>w.hash));const g="pendingBlocks"in m.state?m.state.pendingBlocks:[];m.state={type:ve.Ready},g.forEach(c)},h=new ye,p=h.pipe(dl(()=>En(0)),x(()=>({type:"cleanup"}))),v=sa(),d=()=>(l(v,[...v.blocks.values()].map(m=>m.hash)),Object.assign(v,sa())),f=Qe(s,p,e).pipe(rn((m,g)=>{const w=$=>{l(m,$),a($)},E=(...$)=>{const k=m.blocks.get(m.finalized)?.number??-1,S=$.filter(({refCount:B,recovering:I,number:_,pruned:H})=>!B&&!I&&(H||_<k)).map(({hash:B})=>B);S.length&&w(S)};switch(g.type){case"initialized":if(m.state.type!==ve.Initializing&&m.state.type!==ve.RecoveringInit)throw new Error("Initialized event out of order");m.state.type===ve.RecoveringInit&&!g.finalizedBlockHashes.some(I=>m.blocks.has(I))&&(d(),o.next(null));const $=m.blocks.get(m.finalized)?.number??-1,k=g.finalizedBlockHashes.length-1,S=[];$>g.number+k?m.state={type:ve.RecoveringFin,target:$,pendingBlocks:S}:(m.state={type:ve.Initializing,pendingBlocks:S},m.finalized=g.finalizedBlockHashes[k]);let B=m.finalizedRuntime.codeHash;return g.finalizedBlockHashes.forEach((I,_)=>{const H=m.blocks.get(I);if(H)H.recovering=!1;else{const L=g.number+_,Z=L>$,ce=g.runtimeChanges.get(I),$e=ce&&!m.runtimes[ce]&&Z;$e&&(B=ce);const ot=_===0?g.parentHash:g.finalizedBlockHashes[_-1],At={hash:I,hasNewRuntime:_?g.runtimeChanges.has(I):g.hasNewRuntime,parent:ot,children:new Set(_===k?[]:[g.finalizedBlockHashes[_+1]]),pruned:!1,runtime:B,refCount:0,number:L,recovering:!1};m.blocks.set(I,At),$e&&(m.finalizedRuntime=m.runtimes[ce]=y(ce,I)),m.runtimes[B].usages.add(I),Z&&S.push(At)}}),m;case"stop-error":if(m.state.type===ve.Initializing)return d();for(const I of m.blocks.values())I.recovering=!0;return m.state={type:ve.RecoveringInit},m;case"newBlock":{const{parentBlockHash:I,blockHash:_}=g;if(m.blocks.has(_))m.blocks.get(_).recovering=!1;else{const H=m.blocks.get(I);H.children.add(_);const L=H.number+1,Z={hash:_,number:L,parent:I,children:new Set,runtime:H.runtime,pruned:!1,refCount:0,recovering:!1,hasNewRuntime:!!g.newRuntime};if(m.blocks.set(_,Z),g.newRuntime){const{codeHash:ce}=g;Z.runtime=ce,m.runtimes[ce]=y(ce,_)}m.runtimes[Z.runtime].addBlock(_),"pendingBlocks"in m.state?m.state.pendingBlocks.push(Z):c(Z)}return m}case"bestBlockChanged":return m.state.type===ve.RecoveringFin||(m.best=g.bestBlockHash,m.state.type===ve.Initializing&&u(m)),m;case"finalized":{const I=g.finalizedBlockHashes.slice(-1)[0];let _=!1;if(m.state.type===ve.RecoveringFin){if(m.blocks.get(I).number<m.state.target)return m;_=!0}m.finalized=I;const{blocks:H}=m;return H.get(m.best).number<H.get(m.finalized).number&&(m.best=m.finalized),m.finalizedRuntime=m.runtimes[H.get(m.finalized).runtime],g.prunedBlockHashes.forEach(L=>{const Z=m.blocks.get(L);Z&&(Z.pruned=!0)}),_&&u(m),m.state.type===ve.Ready&&h.next(),m}case"cleanup":return E(...m.blocks.values()),m;case"blockUsage":{const I=m.blocks.get(g.value.hash);return I&&(I.refCount+=g.value.type==="hold"?1:-1,E(I)),m}}},v),x(m=>({...m})),qt({error(m){o.error(m)}}),pn),b=Object.assign(f,{state:v}),y=ph(An(b,t,"pinned-blocks"),n,r);return b},sa=()=>({best:"",finalized:"",runtimes:{},blocks:new Map,finalizedRuntime:{},state:{type:ve.Initializing,pendingBlocks:[]}}),oa=(e,t,n,r,s,o)=>{const a=new Map,i=v=>{a.get(v)?.(),a.delete(v)},l=new D(v=>{const d=t.subscribe({next:({hash:f})=>{a.set(f,o(f))},complete(){v.error(new Error("Tracking stopped"))}});return d.add(e.pipe(x(f=>f.finalized),he()).subscribe(()=>{e.state.blocks.forEach(({pruned:f,hash:b})=>{f&&i(b)})})),d.add(()=>[...a.keys()].forEach(i)),d}),c=v=>dr(e.pipe(Be(({blocks:d})=>d.get(v)?.pruned??!0))),u=(v,d,f)=>{if(f)return K({hash:v,found:{type:!1,validity:null}});const b=c(v);return n(v).pipe(z(y=>{const m=y.findIndex(g=>vh(g,d));return m>-1?b(s(v)).pipe(x(g=>({hash:v,found:{type:!0,index:m,events:g}}))):r(v,d).pipe(x(g=>({hash:v,found:{type:!1,validity:g}})))}),b,lr(()=>i(v)))},h=v=>{[...e.state.blocks.get(v)?.children.keys()??[]].forEach(h),i(v)},p=(v,d,f)=>u(v,d,f.has(v)).pipe(z(b=>{const{found:y}=b,m=y.type||y.validity?.success===!1;return m&&h(v),m?K(b):e.pipe(c(v),z(g=>g.blocks.get(v).children),ll(),z(g=>p(g,d,f)))}));return v=>Qe(l,e.pipe(te(1),z(d=>p(d.finalized,v,new Set(d.blocks.keys())))))},vh=(e,t)=>e.length===t.length&&e.every((n,r)=>t[r]===n),bh=new Uint8Array([2]),mh=(e,t)=>X(oe([bh,e,ee(t)])),ia="TaggedTransactionQueue",aa="validate_transaction",[,yh]=Se({InvalidTransaction:Se({Call:M,Payment:M,Future:M,Stale:M,BadProof:M,AncientBirthBlock:M,ExhaustsResources:M,Custom:P,BadMandatory:M,MandatoryValidation:M,BadSigner:M}),UnknownTransaction:Se({CannotLookup:M,NoUnsignedValidator:M,Custom:P})}),gh=lt(e=>{const t=P.dec(e);if(t>1)throw new Error("Unable to decode validateTransaction result");if(!t)return{success:!0,value:void 0};let n;try{n=yh(e)}catch{n={type:"UnknownInvalidTx"}}return{success:!1,value:n}}),wh=(e,t)=>(n,r)=>{const s=t(n).pipe(x(o=>{try{return o.dynamicBuilder.buildRuntimeCall(ia,aa).value[1]}catch{return gh}}));return e(n,`${ia}_${aa}`,mh(r,n)).pipe(Gs(s),x(([o,a])=>a(o)))},$h=e=>t=>new D(n=>{let r=!1;const s=t.subscribe({next(o){r=!0,n.next(o)},error(o){n.error(o)},complete(){n.complete()}});return r||n.next(e),s}),Eh=e=>t=>new D(n=>{const r=t.subscribe({next(o){n.next(o)},error(o){n.error(o)},complete(){n.complete()}}),s=()=>r.unsubscribe();return()=>{Promise.resolve().then(s)}}),ca=(e,t=1/0)=>n=>new D(r=>{let s;const o=new Map,a=new Map,i=new Map;let l=0,c=0,u=0;const h=()=>{const p=o.get(c);if(!p){a.size===0&&(typeof s>"u"||s.closed)&&r.complete();return}const v=c++;o.delete(v),u!==v&&i.set(v,[]);let d=!1,f=p.subscribe({next(b){u===v?r.next(b):i.get(v).push(b)},complete(){if(d=!0,a.delete(v),v===u)for(u++;i.has(u)&&(i.get(u).forEach(b=>r.next(b)),i.delete(u),!a.has(u));)u++;h()},error(b){r.error(b)}});d||a.set(v,f)};return s=new _t,s.add(n.subscribe({next(p){const v=l++;o.set(v,nn(()=>e(p,v))),a.size<t&&h()},error(p){r.error(p)},complete(){a.size===0&&r.complete()}})),()=>{a.forEach(p=>p.unsubscribe()),s.unsubscribe(),o.clear(),i.clear()}}),kh=(e,t,n)=>{const{withRecovery:r,withRecoveryFn:s}=Ll(),{getFollower:o,unfollow:a,follow$:i,getHeader:l,hasher$:c}=Qd(e,s),u=Pl(o),h=new ye,p=A=>C=>new D(T=>{h.next({type:"blockUsage",value:{type:"hold",hash:A}});const V=C.subscribe(T);return V.add(()=>{setTimeout(()=>{h.next({type:"blockUsage",value:{type:"release",hash:A}})},0)}),V}),v=A=>(C,...T)=>A(C,...T).pipe(p(C)),d=(A,C)=>(T,...V)=>new D(fe=>g.state.blocks.has(T)?A(T,...V).subscribe(fe):fe.error(new Je(T,C))),f=A=>o().unpin(A).catch(C=>{if(!(C instanceof Error&&C.name===xn.errorName))throw C}),b=(A,C)=>d(v(An(g,s(Mt(A)),`stop-${C}`)),C),y=new Map,m=new ye,g=fh(i,(...A)=>v(s(Mt(u("call"))))(...A).pipe(x(ee)),t,n,h,m,A=>{f(A).catch(C=>{console.error("unpin",C)}),A.forEach(C=>{y.delete(C)})},A=>{y.delete(A)}),w=d(v(A=>g.state.runtimes[g.state.blocks.get(A).runtime].runtime),"getRuntimeCtx"),E=A=>C=>C.pipe(ca(T=>w(A(T)).pipe(x(V=>[T,V])))),$=(A,C,T)=>{const V=y.get(A)??new Map,fe=V.get(C);if(fe)return fe;y.set(A,V);let Ot;const Ge=T.pipe(bt({connector:()=>Ot=new en}),qt({complete(){V.set(C,Ot)}}),Eh());return V.set(C,Ge),Ge},k=Object.assign(g.pipe(Be(A=>A.state.type===ve.Ready)),{state:g.state}),S=k.pipe(he((A,C)=>A.finalized===C.finalized),rn((A,C)=>{let T=C.blocks.get(C.finalized);const V=[T],fe=A.at(-1);if(!fe)return V;for(;T.number>fe.number+1&&(T=C.blocks.get(T.parent),!!T);)V.unshift(T);return V},[]),$n(),x(fn),pn),B=k.pipe(he((A,C)=>A.best===C.best),x(A=>fn(A.blocks.get(A.best))),pn),I=k.pipe(he((A,C)=>A.finalized===C.finalized&&A.best===C.best),rn((A,C)=>{const T=Re=>A.get(Re)||fn(C.blocks.get(Re)),V=T(C.best),fe=T(C.finalized),Ot=V.number-fe.number+1,Ge=new Array(Ot);for(let Re=0,nr=V.hash;Re<Ot;Re++)Ge[Re]=T(nr),nr=Ge[Re].parent;return new Map(Ge.map(Re=>[Re.hash,Re]))},new Map),x(A=>[...A.values()]),pn),_=k.pipe(he((A,C)=>A.finalizedRuntime===C.finalizedRuntime),Ht(({finalizedRuntime:{runtime:A}})=>A.pipe($h(null))),pn),H=_.pipe(x(A=>A?.lookup.metadata??null)),L=Nl(S.pipe(x(A=>A.hash)),B.pipe(x(A=>A.hash)),p),Z=b(u("body"),"body"),ce=A=>mr($(A,"body",Z(A))).pipe(x(C=>C.map(ee))),$e=b(u("storage"),"storage"),ot=L(d((A,C,T,V=null,fe)=>{const Ot=g.state.blocks.get(A);return g.state.runtimes[Ot.runtime].runtime.pipe(z(Ge=>{const Re=T(Ge);return $(A,`storage-${C}-${Re}-${V??""}`,$e(A,C,Re,V)).pipe(fe?x(nr=>fe(nr,Ge)):Le)}),x(Ge=>({block:fn(Ot),value:Ge})))},"storage")),At=Fl(o,r),uv=L(d(An(g,(A,C,T)=>At(A,C,T??null,!1),"storageQueries"),"storageQueries")),dv=d(An(g,l,"header"),"header"),tc=A=>ot(A,"value",C=>C.events.key,null,(C,T)=>C?T.events.dec(C):[]).pipe(x(C=>C.value)),hv=b(u("call"),"call"),nc=L((A,C,T)=>$(A,`call-${C}-${T}`,hv(A,C,T).pipe(x(ee)))),ds=wh(nc,w),pv=_.pipe(Be(Boolean),te(1),z(A=>{const{enc:C}=A.dynamicBuilder.buildStorage("System","BlockHash").keys;let T;try{T=C(0)}catch{T=C(0n)}return ot(null,"value",()=>T,null).pipe(x(V=>V.value))}),sn(1));Qe(_,I).subscribe({error(){}});const fv=A=>g.state.runtimes[A]?.runtime??K(null),tr=(A,C=!1)=>{let T=A||"finalized";if(T=g.state[T]||T,!g.state.blocks.has(T)){if(C)throw new Je(T,"holdBlock");return Ee}h.next({type:"blockUsage",value:{type:"hold",hash:T}});let V=()=>{h.next({type:"blockUsage",value:{type:"release",hash:T}}),V=Ee};return()=>{V()}},vv=A=>C=>new D(T=>{const V=C.subscribe(T);return V.closed||V.add(tr(A)),V}),hs=m.pipe(Tt(Boolean)),bv=oa(k,hs,ce,ds,tc,tr),mv=oa(g,hs,ce,ds,()=>K(),tr);return{follow$:i,unfollow:a,finalized$:S,best$:B,bestBlocks$:I,newBlocks$:ct(k.pipe(te(1),z(({blocks:A,finalized:C})=>{const T=V=>{const fe=A.get(V);return fe?[fe,...Array.from(fe.children).flatMap(T)]:[]};return T(C)})),hs),runtime$:_,metadata$:H,genesis$:pv,hasher$:c,getRuntime$:fv,header$:dv,body$:ce,call$:nc,storage$:ot,storageQueries$:uv,eventsAt$:tc,withHodl:vv,holdBlock:tr,trackTx$:bv,trackTxWithoutEvents$:mv,validateTx$:ds,pinnedBlocks$:k,withRuntime:E,getRuntimeContext$:L(w)}};var xh=e=>t=>new D(n=>e(X(t),r=>{n.error(r)}));const Sh=({storageSubscription:e,...t})=>n=>{const r={},s=Mt(t.storage),o=(v,d,f)=>Mt(t.call)(v,d,f).pipe(x(ee)),a=Mt(t.header),i=v=>Mt(t.body)(v).pipe(x(d=>d.map(ee))),l=v=>a(v).pipe(x(Nn[1])),c=v=>s(v,"hash","0x3a636f6465",null).pipe(x(d=>d)),u=(v,d)=>n(v).pipe(de(()=>K(null)),z(f=>f?K(f):Qi((...b)=>o(d,...b)).pipe(x(b=>na(Fn(zt.dec(b)),b,v)))),qt(f=>{r[v]=f})),h=v=>c(v).pipe(z(d=>{const f=r[d];return f?K(f):u(d,v)})),p=(v,d,f,b=null,y)=>h(v).pipe(z(m=>s(v,d,f(m),b).pipe(x(g=>y?y(g,m):g))));return{body$:i,header$:l,storage$:p,storageQueries$:(v,d,f)=>new D(b=>e(v,d,f||null,y=>b.next(y),y=>b.error(y),()=>{b.complete()})),call$:o,eventsAt$:v=>p(v,"value",d=>d.events.key,null,(d,f)=>f.events.dec(d)),getRuntimeContext$:h}},Ih=()=>K(null),Bh=(e,{getMetadata:t,setMetadata:n}={})=>({chainHead$:()=>kh(e.chainHead,t||Ih,n||Ee),archive:Sh(e.archive),broadcastTx$:xh(e.transaction),destroy:e.destroy}),Ah=(e,t)=>e.pipe(Tt(n=>n.blocks.has(t)),he((n,r)=>n.finalized===r.finalized&&n.best===r.best),x(n=>{if(n.blocks.get(t).number>n.blocks.get(n.best).number)return null;const{number:r}=n.blocks.get(t);let s=n.blocks.get(n.best),o=n.finalized===s.hash;for(;s.number>r;)s=n.blocks.get(s.parent),o=o||n.finalized===s.hash;return o?"finalized":s.hash===t?"best":null}),he(),Tt(n=>n!=="finalized",!0)),Vt=(e,t)=>(n,...r)=>e(n,...r).pipe(de(s=>{if(!(s instanceof Je))throw s;return t(n,...r).pipe(de(o=>{throw console.warn(o),s}))})),ht=R,Oh=Ae(Pe(W,ht)),q={bool:"boolean",str:"string",num:"number",big:"bigint",bits:"bitseq",void:"void"},Ch=Se(Object.fromEntries(Object.values(q).map(e=>[e,M]))),_h=Ae(Pe(W,Se({inline:xr(()=>jr),lookup:ht}))),Rh=Ae(ht),Hh=be({typeRef:ht,length:xt(ht)}),Th=xt(ht),Mh=ht,Uh=be({ok:ht,ko:ht}),jr=Se({struct:Oh,terminal:Ch,enum:_h,tuple:Rh,array:Hh,binary:Th,option:Mh,result:Uh}),zh={i256:q.big,i128:q.big,i64:q.big,i32:q.num,i16:q.num,i8:q.num,u256:q.big,u128:q.big,u64:q.big,u32:q.num,u16:q.num,u8:q.num,bool:q.bool,char:q.str,str:q.str},vn=e=>({type:"terminal",value:{type:e}});function Lr(e,t=()=>{}){switch(e.type){case"AccountId20":case"AccountId32":return vn(q.str);case"array":return e.value.type==="primitive"&&e.value.value==="u8"?{type:"binary",value:e.len}:(t(e.value.id),{type:"array",value:{typeRef:e.value.id,length:e.len}});case"bitSequence":return vn(q.bits);case"compact":return vn(e.isBig?q.big:q.num);case"enum":return{type:"enum",value:Object.entries(e.value).map(([n,r])=>r.type!=="lookupEntry"?[n,{type:"inline",value:Lr(r,t)}]:(t(r.value.id),[n,{type:"lookup",value:r.value.id}]))};case"struct":{const n=Object.entries(e.value).map(([r,s])=>[r,s.id]);return n.forEach(([,r])=>t(r)),{type:"struct",value:n}}case"tuple":{const n=e.value.map(r=>r.id);return n.forEach(t),{type:"tuple",value:n}}case"option":return t(e.value.id),{type:"option",value:e.value.id};case"primitive":return vn(zh[e.value]);case"result":return t(e.value.ok.id),t(e.value.ko.id),{type:"result",value:{ok:e.value.ok.id,ko:e.value.ko.id}};case"sequence":return e.value.type==="primitive"&&e.value.value==="u8"?{type:"binary",value:void 0}:(t(e.value.id),{type:"array",value:{typeRef:e.value.id}});case"void":return vn(q.void)}}function Vr(e,t,n){if(t.type==="option"&&e==null)return!0;const r=(o,a)=>Vr(o,a,n),s=o=>{switch(o.value.type){case q.str:case q.big:case q.bool:case q.num:return typeof e===o.value.type;case q.bits:return typeof e=="object"&&e!=null&&typeof e.bitsLen=="number"&&e.bytes instanceof Uint8Array;case q.void:return!0}};switch(t.type){case"terminal":return s(t);case"binary":return t.value==null?e instanceof Uint8Array:typeof e=="string"&&e.startsWith("0x");case"array":if(!Array.isArray(e))return!1;const o=e;return t.value.length!=null&&o.length<t.value.length?!1:o.slice(0,t.value.length).every(c=>r(c,n(t.value.typeRef)));case"enum":if(!e)return!1;const a=e,i=Object.fromEntries(t.value);if(!(a.type in i))return!1;const l=i[a.type];return l==null?!0:r(a.value,l.type==="inline"?l.value:n(l.value));case"option":return e==null?!0:r(e,n(t.value));case"struct":return e?t.value.every(([c,u])=>r(e[c],n(u))):!1;case"tuple":return e?t.value.every((c,u)=>r(e[u],n(c))):!1;case"result":return"success"in e&&"value"in e?r(e.value,n(e.success?t.value.ok:t.value.ko)):!1}}var Dh=Object.defineProperty,jh=(e,t,n)=>t in e?Dh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Lh=(e,t,n)=>jh(e,t+"",n);let la=class{constructor(t=[]){Lh(this,"value",new Map),t.forEach(([n,r])=>this.add(n,r))}has(t,n){return this.value.get(t)?.has(n)??!1}add(t,n){this.value.has(t)||this.value.set(t,new Set),this.value.get(t).add(n)}addAll(t){t.forEach(([n,r])=>this.add(n,r))}delete(t,n){if(!this.value.has(t))return;const r=this.value.get(t);r.delete(n),r.size||this.value.delete(t)}isEmpty(){return!this.value.size}get values(){return Array.from(this.value).flatMap(([t,n])=>Array.from(n).map(r=>[t,r]))}};var pt=(e=>(e[e.Incompatible=0]="Incompatible",e[e.Partial=1]="Partial",e[e.BackwardsCompatible=2]="BackwardsCompatible",e[e.Identical=3]="Identical",e))(pt||{});function Nr(e,t,n,r,s,o=!1){if(!n&&!e)return Fe(3,[]);if(!n)return Fe(2,[]);if(!e)return Fe(n.type==="option"?2:0,[]);s.has(n)||s.set(n,new Map);const a=s.get(n);if(a.has(e)){const l=a.get(e);return l==null?{level:3,changes:[],assumptions:new la([[e,n]])}:Fe(l.level,l.changes)}a.set(e,null);const i=Vh(e,n,(l,c)=>Nr(typeof l=="number"?t(l):l,t,typeof c=="number"?r(c):c,r,s),o);return i.assumptions.delete(e,n),i.assumptions.isEmpty()||i.level===0?a.set(e,i):a.delete(e),i}function Vh(e,t,n,r){const s=(o,a,i)=>{const l=n(o,a);return{...l,changes:l.level<3?[{id:[typeof o=="number"?o:null,typeof a=="number"?a:null],level:l.level,path:i}]:[]}};if(e.type!==t.type)return t.type==="option"?qn(s(e,t.value,"some"),2):e.type==="option"?qn(s(e.value,t,"some"),1):Fe(0,[]);switch(t.type){case"terminal":return Fe(t.value.type===e.value.type?3:0,[]);case"binary":return Fr(ha(e.value,t.value));case"array":const o=e,a=Fr(ha(o.value.length,t.value.length));return Pr([a,()=>s(o.value.typeRef,t.value.typeRef,"value")],r);case"enum":{const h=e,p=Object.fromEntries(t.value.map(([f,b])=>[f,b.value]));let v=da(h.value.map(([f,b])=>()=>f in p?s(b.value,p[f],f):Fe(0,[{id:[typeof b.value=="number"?b.value:null,null],level:0,path:f}])));if(h.value.length===t.value.length)return v;v=qn(v,2);const d=new Set(h.value.map(([f])=>f));return v.changes=[...v.changes,...t.value.filter(([f])=>!d.has(f)).map(([f,b])=>({id:[null,typeof b=="number"?b:null],level:0,path:f}))],v}case"option":return Nh(s(e.value,t.value,"some"),1);case"struct":const i=e,l=Object.fromEntries(i.value),c=i.value.length===t.value.length?3:2;return qn(Pr(t.value.map(([h,p])=>()=>s(l[h],p,h)),r),c);case"tuple":{const h=e,p=Fr(Ph(h.value,t.value));return Pr([p,...t.value.map((v,d)=>()=>s(h.value[d],v,String(d)))],r)}case"result":const u=e;return da([s(u.value.ok,t.value.ok,"ok"),s(u.value.ko,t.value.ko,"ko")])}}const qn=(e,t)=>({...e,level:Math.min(e.level,t)}),Nh=(e,t)=>({...e,level:Math.max(e.level,t)}),ua=new la,Fe=(e,t)=>({level:e,changes:t,assumptions:ua}),Pr=(e,t)=>{let n=Fe(3,[]);for(const r of e){const s=typeof r=="function"?r():r;if(!t&&s.level===0)return s;s.level!==3&&(n.changes=[...n.changes,...s.changes]),n.assumptions.addAll(s.assumptions.values),n.level=Math.min(n.level,s.level)}return n},da=e=>{if(!e.length)return Fe(3,[]);let t=!1,n=Fe(3,[]);for(const r of e){const s=typeof r=="function"?r():r;if(s.level!==3&&(n.changes=[...n.changes,...s.changes]),s.level===0){n.level=Math.min(n.level,1);continue}t=!0,n.assumptions.addAll(s.assumptions.values),n.level=Math.min(n.level,s.level)}return t?n:Fe(0,n.changes)},Fr=e=>({assumptions:ua,changes:e===3?[]:[{id:[null,null],level:e,path:"length"}],level:e}),Ph=(e,t)=>t.length===e.length?3:e.length>=t.length?2:0,ha=(e,t)=>t===e?3:t==null||e>=t?2:e==null?1:0,pa=Se({lookup:R,typedef:jr}),Qt=e=>({type:"lookup",value:e}),Wr=e=>({type:"typedef",value:e}),Kn=Wr({type:"terminal",value:{type:q.void}}),Fh=be({args:pa,values:pa});function Wh(e){if(e.type.tag==="plain")return{args:Kn,values:Qt(e.type.value)};const{key:t,value:n}=e.type.value;return{args:Qt(t),values:Qt(n)}}function fa(e){return{args:Wr({type:"tuple",value:e.inputs.map(t=>t.type)}),values:Qt(e.output)}}function qh(e){return e.type==="lookupEntry"?Qt(e.value.id):Wr(Lr(e))}function Kh(e){return{args:Kn,values:Qt(e)}}function Gh(e,t,n,r,s,o){const a=(i,l)=>i.type==="lookup"?l(i.value):i.value;return{args:Nr(a(e.args,t),t,a(n.args,r),r,s,o),values:Nr(a(n.values,r),r,a(e.values,t),t,s,o)}}function va(e,t,n){const r=e.type==="lookup"?t(e.value):e.value;return Vr(n,r,t)}const Gn=e=>{const t=new WeakMap,n={};return r=>{const s=r??n,o=t.get(s)||e(r);return t.set(s,o),o}},Yh=Ae(Fh),Xh=Ae(jr),[,Qh]=Pe(Yh,Xh);var je=(e=>(e.Storage="storage",e.Tx="tx",e.Event="events",e.Const="constants",e.ViewFns="viewFns",e.Api="apis",e))(je||{});const Jh=async({metadataTypes:e,descriptors:t})=>{const[[n,r],s]=await Promise.all([e.then(Qh),t]);return{getTypeDefNode:o=>r[o],getEntryPointNode:(o,a,i)=>{const l=s[o]?.[a]?.[i];return l==null?l:n[l]}}},ba=(e,t)=>{const n=qh(e),[r,s]=t==="args"?[n,Kn]:[Kn,n];return{args:r,values:s}},ma=Gn(({lookup:e,assetId:t,mappedMeta:{pallets:n,api:r}})=>{const s=new Map,o=a=>{let i=s.get(a);return i||(s.set(a,i=Lr(e(a))),i)};return{getTypeDefNode:o,getEntryPointNode:(a,i,l)=>{switch(a){case"storage":{const c=n[i]?.storage.get(l);return c&&Wh(c)}case"tx":{const c=n[i]?.call.get(l);return c&&ba(c,"args")}case"events":{const c=n[i]?.event.get(l);return c&&ba(c,"values")}case"viewFns":{const c=n[i]?.view.get(l);return c&&fa(c)}case"apis":{const c=r[i]?.get(l);return c&&fa(c)}case"constants":{const c=n[i]?.const.get(l);return c&&Kh(c.type)}}},isAssetCompat:a=>t==null||Vr(a,o(t),o)}}),ya=(e,t,n,r)=>{if(!e)return null;const{getEntryPointNode:s,getTypeDefNode:o}=e;return{entry:s(t,n,r),getter:o}},Zh=bt({connector:()=>new en(1),resetOnError:!0,resetOnComplete:!0,resetOnRefCountZero:!0});function We(e,t){return new Promise((n,r)=>{let s=null,o=!1;const a=t?()=>{s?.unsubscribe(),r(new Xs)}:Ee;s=e.subscribe({next:i=>{n(i),s?.unsubscribe(),o=!0},error:i=>{t?.removeEventListener("abort",a),r(i),o=!0},complete:()=>{t?.removeEventListener("abort",a),r(new Error("Observable completed without emitting")),o=!0}}),o||t?.addEventListener("abort",a)})}const qr=Symbol("EMPTY_VALUE"),Kr=e=>t=>new D(n=>{let r=0,s=null,o=qr,a=!1;const i=()=>{const c=e(o,r++);o=qr,s=c.subscribe({next(u){n.next(u)},error(u){n.error(u)},complete(){o!==qr?i():(s=null,a&&n.complete())}})},l=t.subscribe({next(c){o=c,s||i()},error(c){n.error(c)},complete(){s||n.complete(),a=!0}});return()=>{s?.unsubscribe(),l.unsubscribe()}});let ga={};const ep=e=>t=>new D(n=>{let r=ga,s=t.subscribe({next(o){n.next(r=o)},error(o){n.error(o)},complete(){r===ga?n.complete():s=e(r).subscribe(n)}});return()=>{s.unsubscribe()}}),Nt=e=>typeof e=="object"&&e!==null&&Object.entries(e).every(([t,n])=>t==="at"&&(n===void 0||typeof n=="string")||t==="signal"&&(n===void 0||n instanceof AbortSignal)),tp=()=>{const e=new xc(new ye);return[e.pipe(pl()),()=>qt({next:t=>e.value.next(t),error:t=>{e.value.error(t),e.next(new ye)},complete:()=>{e.value.complete(),e.next(new ye)}})]},np={},wa=e=>new Proxy(np,{get(t,n){return e(n)}}),nt=e=>{const t={};return wa(n=>(t[n]||(t[n]={}),wa(r=>(t[n][r]||(t[n][r]=e(n,r)),t[n][r]))))},Yn={level:pt.Incompatible,isCompatible:()=>!1,isValueCompatible:()=>!1},rp={args:Yn,value:Yn,isCompatible:()=>!1},sp={level:pt.Identical,isCompatible:()=>!0,isValueCompatible:()=>!0},Xn=e=>(t=pt.BackwardsCompatible)=>e>=t,op=(e,t,n,r)=>{let s;if(!r.entry)s=rp;else{const{args:o}=r.entry,a=l=>va(o,r.getter,l),i=e===je.Storage?l=>a(l.length===1?l[0]:l):a;if(n?.entry){const{values:l}=n.entry,{args:c,values:u}=Gh(n.entry,n.getter,r.entry,r.getter,t);s={args:{level:c.level,isValueCompatible:i,isCompatible:Xn(c.level)},value:u.level===pt.Incompatible?Yn:{level:u.level,isValueCompatible:u.level>pt.Partial?()=>!0:h=>va(l,n.getter,h),isCompatible:Xn(u.level)}}}else{const l=pt.Partial;s={args:{level:l,isValueCompatible:i,isCompatible:Xn(l)},value:n?Yn:sp}}}return e===je.Storage||e===je.Api||e===je.ViewFns?Object.assign(s,{isCompatible:Xn(Math.min(s.args.level,s.value.level))}):e===je.Tx?s.args:s.value},ip=Gn(e=>{let t=null;const n=(e?Jh(e):Promise.resolve(null)).then(s=>t=s),r=Gn(s=>{const o=new Map,a=ma(s),i=l=>nt((c,u)=>op(l,o,ya(t,l,c,u),ya(a,l,c,u)));return{tx:i(je.Tx),constants:i(je.Const),apis:i(je.Api),view:i(je.ViewFns),query:i(je.Storage),event:i(je.Event)}});return{getSyncHelpers:async s=>(await n,r(s)),getClientCompat:async(s,o,a)=>(await n,i=>r(i)[s][o][a]),getIsAsssetCompat:s=>ma(s).isAssetCompat}}),$a=({mappedMeta:e,dynamicBuilder:t},n,r)=>{const s=e.pallets[n].const.get(r);if(!s)throw new Error(`Runtime entry Constant(${n}.${r}) not found`);return t.buildConstant(n,r).dec(s.value)},ap=(e,t,n,r)=>({at:s,signal:o}={})=>We(ue([n.getRuntimeContext$(s||null),r]).pipe(x(([a,i])=>{const l=$a(a,e,t);if(i(a).isValueCompatible(l))return l;throw new Error(`Incompatible entry Const(${e}.${t})`)})),o),cp=(e,t,n,r)=>{const s=()=>new Error(`Incompatible runtime entry Event(${e}.${t})`),o=(i,l)=>n.eventsAt$(i).pipe(x(c=>c.filter(u=>u.event.type===e&&u.event.value.type===t).map(u=>{if(!l(u.event.value.value))throw s();return{original:u,payload:u.event.value.value}}))),a=ue([n.finalized$,r]).pipe(n.withRuntime(([i])=>i.hash),ca(([[i,l],c])=>{if(!c.mappedMeta.pallets[e]?.event.has(t))throw new Error(`Runtime entry Event(${e}.${t}) not found`);const{isValueCompatible:u}=l(c);return o(i.hash,u).pipe(x(h=>({block:i,events:h})))}),Zh);return{watch:()=>a,get:i=>at(ue([r,n.getRuntimeContext$(i)]).pipe(te(1),Ht(([l,c])=>o(i,l(c).isValueCompatible)))),filter:i=>i.filter(({event:l})=>l.type===e&&l.value.type===t).map(l=>({original:l,payload:l.event.value.value}))}},lp=(e,t,n,r)=>{const s=`${e}_${t}`,o=()=>new Error(`Incompatible runtime entry RuntimeCall(${s})`);return(...a)=>{const i=a[a.length-1],l=Nt(i),{signal:c,at:u}=l?i:{},h=u??null,p=ue([n.getRuntimeContext$(h),r]).pipe(z(([v,d])=>{let f;try{f=v.dynamicBuilder.buildRuntimeCall(e,t)}catch{throw new Error(`Runtime entry RuntimeCall(${s}) not found`)}const b=d(v);if(!b.args.isValueCompatible(a))throw o();return n.call$(h,s,X(f.args.enc(a))).pipe(x(f.value.dec),x(y=>{if(!b.value.isValueCompatible(y))throw o();return y}))}),n.withHodl(h));return We(p,c)}},Ea=(e,t,n,r,s)=>{let o;try{o=e.buildCall(n,r)}catch{throw new Error(`Runtime entry Tx(${n}.${r}) not found`)}if(!t(s))throw new Error(`Incompatible runtime entry Tx(${n}.${r})`);const{location:a,codec:[i]}=o;return oe([new Uint8Array(a),i(s)])},ka=(e,t,n,r)=>{const s=()=>new Error(`Incompatible runtime entry Storage(${t}.${n})`);let o;try{o=e.dynamicBuilder.buildStorage(t,n)}catch{throw s()}return(...a)=>{if(a.length===o.len&&!r(a))throw s();return o.keys.enc(...a)}},Gr=()=>new Error("Unkown signer"),up=e=>{const{extrinsic:t}=e,n=Zi(e);let r,s;if("address"in t)r=n(t.address),s=n(t.signature);else{const o=Object.fromEntries(e.lookup[t.type].params.filter(a=>a.type!=null).map(a=>[a.name,n(a.type)]));if(r=o.Address,s=o.Signature,!r||!s)throw Gr()}if(r.type==="AccountId20"&&s.type==="array"&&s.len===65&&s.value.type==="primitive"&&s.value.value==="u8")return[1,[]];if(s.type!=="enum"||["Ecdsa","Ed25519","Sr25519"].some(o=>!(o in s.value)))throw Gr();if(r.type==="enum"){const o=r.value.Id;if(o.type==="lookupEntry"&&o.value.type==="AccountId32")return[0,[o.idx]]}else if(r.type==="AccountId32")return[0,[]];throw Gr()},dp={Ed25519:0,Sr25519:1,Ecdsa:2},hp=(e,t,n,r,s,o)=>{const[a,i]=up(e),l=oe([Tr.enc({version:4,type:"signed"}),a===1?t:new Uint8Array([...i,...t]),a===1||!o?n:new Uint8Array([dp[o],...n]),...r,s]);return oe([pe.enc(l.length),l])},[Qn,bn]=["<Bytes>","</Bytes>"].map(e=>zn.fromText(e)),pp=e=>async t=>{let n=!0,r;for(r=0;n&&r<Qn.length;r++)n=Qn[r]===t[r];n=n&&r===Qn.length;const s=t.length-bn.length;for(r=0;n&&r<bn.length;r++)n=bn[r]===t[s+r];return n=n&&r===bn.length,e(n?t:oe([Qn,t,bn]))};function fp(e,t,n){return{publicKey:e,signTx:async(r,s,o,a,i=jt)=>{const l=Fn(Hi(o)),c=[],u=[];l.extrinsic.signedExtensions[0].map(({identifier:v})=>{const d=s[v];if(!d)throw new Error(`Missing ${v} signed extension`);c.push(d.value),u.push(d.additionalSigned)});const h=oe([r,...c,...u]),p=await n(h.length>256?i(h):h);return hp(l,e,p,c,r,t)},signBytes:pp(n)}}Uint8Array.from([1]);const vp=(e,t)=>{const n=e.metadata.pallets.find(o=>o.name==="System").constants.find(o=>o.name==="Version"),r=e(n.type),s=t.buildDefinition(n.type).dec;if(r.type!=="struct")throw new Error("not a struct");return s(n.value)};function bp(e){let t=0;for(;!(e&1);)t++,e>>=1;return t}const mp=e=>1<<Math.ceil(Math.log2(e)),yp=Cn(ne(2)[0],e=>{const t=Math.min(Math.max(mp(e.period),4),65536),n=e.startAtBlock%t,r=Math.max(t>>12,1),s=Math.min(Math.max(bp(t)-1,1),15),o=n/r<<4;return et[0](s|o)}),[gp]=be({tip:pe,asset:xt(ne(1/0))}),xa=new Uint8Array,Yr=Uint8Array.from([0]),Xr=e=>({value:e,additionalSigned:xa}),Qr=e=>({value:xa,additionalSigned:e}),Jr=(e,t)=>({value:e,additionalSigned:t}),wp=(e,t,n)=>{const r={};return t.metadata.extrinsic.signedExtensions[0].forEach(({identifier:s,type:o,additionalSigned:a})=>{r[s]=[o,a].map(i=>n.buildDefinition(i)[0])}),({mortality:s,tip:o=0n,nonce:a,customSignedExtensions:i={},...l})=>{const c=[],u=vp(t,n),h=v=>{const[d,f]=r[v],b=i[v];try{return mt({value:d,additionalSigned:f},(y,m)=>{const g=b?.[m];return g instanceof Uint8Array?g:y(g)})}catch{if(b)throw new Error(`Wrong input received for ${v}`);return c.push(v),null}},p=mt(r,([v,d],f)=>{if(i[f])return h(f);switch(f){case"CheckNonce":return Xr(v(a));case"CheckMortality":return s.mortal?Jr(yp({period:s.period,startAtBlock:s.startAtBlock.height}),ee(s.startAtBlock.hash)):Jr(Yr,e);case"ChargeTransactionPayment":return Xr(v(o));case"ChargeAssetTxPayment":return Xr(gp({tip:o,asset:l.asset}));case"CheckGenesis":return Qr(e);case"CheckMetadataHash":return Jr(Yr,Yr);case"CheckSpecVersion":return Qr(d(u.spec_version));case"CheckTxVersion":return Qr(d(u.transaction_version));default:return h(f)}});return c.forEach(v=>{delete p[v]}),mt(p,(v,d)=>({...v,identifier:d}))}},Sa="AccountNonceApi_account_nonce",$p={1:P.dec,2:et.dec,4:Ne.dec,8:an.dec},Ep=(e,t,n)=>e(n,Sa,t).pipe(x(r=>{const s=$p[r.length];if(!s)throw new Error(`${Sa} retrieved wrong data`);return s(r)})),kp=(e,t)=>e.pinnedBlocks$.pipe(Ws(0),x(n=>{const r=s=>{const o=n.blocks.get(s);if(!o)return null;if(o.hasNewRuntime)return o;for(const a of o.children){const i=r(a);if(i)return i}return null};return r(t)?.hash??t}),he()),xp=(e,t,n,r,s,o={})=>ue([o.nonce!=null?K(o.nonce):Sp(e,X(t.publicKey)),kp(e,r.hash).pipe(Ht(e.getRuntimeContext$)),e.genesis$]).pipe(te(1),z(([a,i,l])=>{const c=wp(ee(l),i.lookup,i.dynamicBuilder),u=o.mortality??{period:64,mortal:!0},h=c({nonce:a,tip:o.tip??0n,mortality:u.mortal?{mortal:!0,period:u.period,startAtBlock:{height:r.number,hash:r.hash}}:{mortal:!1},customSignedExtensions:s,asset:o.asset});return t.signTx(n,h,i.metadataRaw,r.number)})),Sp=(e,t)=>{const n=o=>e.newBlocks$.pipe(rn((a,i)=>i.parent===a?i.hash:a,o),Ks(o),he()),r=o=>n(o).pipe(te(2),Ht(a=>Ep(e.call$,t,a))),s=o=>ue(o.map(a=>r(a).pipe(x(i=>({success:!0,value:i})),de(i=>K({success:!1,value:i}))))).pipe(te(1));return e.pinnedBlocks$.pipe(te(1),x(({blocks:o,best:a})=>{const i=o.get(a);return[...o.values()].filter(l=>!l.pruned&&l.children.size===0&&l.number>=i.number).map(l=>l.hash)}),Ht(s),x(o=>{const a=o.reduce((i,l)=>l.success&&l.value>=(i??0)?l.value:i,null);if(a==null)throw o[0].value;return a}))};var Ip=Object.defineProperty,Bp=(e,t,n)=>t in e?Ip(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ap=(e,t,n)=>Bp(e,t+"",n);const Op=(e,t)=>new D(n=>{const r=new Map;let s,o;const a=()=>{let l=s.best,c=r.get(l),u=s.blocks.get(l).number;for(;!c;){const v=s.blocks.get(l);if(!v)break;c=r.get(l=v.parent),u--}if(!c)return;const h=u<=s.blocks.get(s.finalized).number,p=c.found.type;if(p&&o?.found&&o.hash===c.hash){h&&n.complete();return}n.next(o=c.found.type?{found:p,hash:c.hash,number:u,index:c.found.index,events:c.found.events}:{found:p,validity:c.found.validity}),h&&(p?n.complete():c.found.validity?.success===!1&&n.error(new Ia(c.found.validity.value)))},i=t.pipe(he((l,c)=>l.finalized===c.finalized&&l.best===c.best)).subscribe({next:l=>{s=l,r.size!==0&&a()},error(l){n.error(l)}});return i.add(e.subscribe({next:l=>{r.set(l.hash,l),a()},error(l){n.error(l)}})),i}).pipe(he((n,r)=>n===r)),Cp=(e,t)=>{const n=e.filter(s=>s.phase.type==="ApplyExtrinsic"&&s.phase.value===t).map(s=>({...s,...s.event})),r=n[n.length-1];return r.type==="System"&&r.value.type==="ExtrinsicFailed"?{ok:!1,events:n,dispatchError:r.value.value.dispatch_error}:{ok:!0,events:n}};class Ia extends Error{constructor(t){super(JSON.stringify(t,(n,r)=>typeof r=="bigint"?r.toString():r instanceof Uint8Array?X(r):r,2)),Ap(this,"error"),this.name="InvalidTxError",this.error=t}}const Zr=(e,t,n,r=!1)=>e.hasher$.pipe(z(s=>{const o=X(s(n)),a=(d,f)=>({type:d,txHash:o,...f}),i=e.pinnedBlocks$.state,l=d=>{if(!d.mortal)return 0;const{phase:f,period:b}=d,y=i.blocks.get(i.best).number;return Math.floor((Math.max(y,f)-f)/b)*b+f},c=d=>{let f=[...i.blocks.values()].filter(m=>!m.pruned&&!m.children.size);const b=Math.max(...f.map(({number:m})=>m));f=f.filter(({number:m})=>m>=b-1);const y=i.blocks.get(i.finalized);return f=y.children?[y,...f]:f,f.filter(m=>m.number>=d)},u=({hash:d})=>e.validateTx$(d,n),h=nn(()=>i.finalizedRuntime.runtime.pipe(x(d=>d.getMortalityFromTx(n)),x(l),x(c),z(d=>{let f;return Qe(...d.map(b=>ol(u(b),e.finalized$.pipe(Tt(y=>{if(y.number<b.number)return!0;let m=y;for(;m.number>b.number;){const g=i.blocks.get(m.parent);if(!g)return!1;m=g}return m.hash===y.hash}),kn(),qs({success:null}))))).pipe(Be((b,y)=>{if(b.success===!1&&(f??(f=new Ia(b.value))),b.success)return!0;if(y===d.length-1&&f)throw f;return!1}),te(1))}),kn())),p=new D(d=>{const f=e.trackTx$(n).subscribe(d);return f.add(t(n).subscribe({error(b){d.error(b)}})),f}),v=Op(p,e.pinnedBlocks$).pipe(x(d=>d.found?a("txBestBlocksState",{found:!0,block:{index:d.index,number:d.number,hash:d.hash},...Cp(d.events,d.index)}):a("txBestBlocksState",{found:!1,isValid:d.validity?.success!==!1})));return ct(r?K(a("signed",{})):Xe,h,K(a("broadcasted",{})),v.pipe(ep(({found:d,type:f,...b})=>d?K(a("finalized",b)):Xe)))})),Ba=async(e,t,n,r)=>Fc(Zr(e,t,n)).then(s=>{if(s.type!=="finalized")throw null;const o={...s};return delete o.type,o}),_p=un().enc,Rp=new Uint8Array(64),Hp=new Uint8Array(65),Tp=e=>()=>e?Hp:Rp,[,Mp]=be({weight:be({ref_time:Un,proof_size:Un}),class:Se({Normal:M,Operational:M,Mandatory:M}),partial_fee:Eo}),es=(e,t,n,r,s,o)=>{const a=c=>ue([n.getRuntimeContext$(c),s]).pipe(x(([u,h])=>({ctx:u,isAssetCompat:o(u),...h(u)}))),i=(c,u)=>a(u).pipe(x(({ctx:{dynamicBuilder:h,extVersions:p},isValueCompatible:v})=>{const d=Ea(h,v,e,t,c);return{callData:d,bare:oe([pe.enc(d.length+1),new Uint8Array(p.slice(-1)),d])}})),l=(c,u)=>c===void 0?K(void 0):a(u).pipe(x(({ctx:h,isAssetCompat:p})=>{if(!p(c))throw new Error("Incompatible runtime asset");const{dynamicBuilder:v,assetId:d}=h;if(d)return v.buildDefinition(d).enc(c)}));return c=>{const u=(y,{...m},g)=>ue([i(c,g.hash),l(m.asset,g.hash)]).pipe(z(([w,E])=>xp(n,y,w.callData,g,m.customSignedExtensions||{},{...m,asset:E}))),h=(y,{at:m,...g}={})=>{const w=n.pinnedBlocks$.state.blocks.get(m);return m&&!w?Rt(()=>new Error(`Uknown block ${m}`)):(w?K(w):n.finalized$).pipe(te(1),z(E=>u(y,g,E).pipe(x($=>({tx:$,block:E})))))},p=(y,m)=>at(h(y,m)).then(g=>g.tx),v=(y,m)=>at(h(y,m)).then(({tx:g,block:w})=>Ba(n,r,g,w.hash)),d=(y,m)=>h(y,m).pipe(z(({tx:g})=>Zr(n,r,g,!0))),f=async(y,m)=>{typeof y=="string"&&(y=y.startsWith("0x")?ee(y):_p(y));const g=y.length===20,w=fp(y,g?"Ecdsa":"Sr25519",Tp(g)),E=await p(w,m),$=X(oe([E,Ne.enc(E.length)])),k=n.getRuntimeContext$(null).pipe(x(B=>{try{return B.dynamicBuilder.buildRuntimeCall("TransactionPaymentApi","query_info").value[1]}catch{return Mp}})),S=n.call$(null,"TransactionPaymentApi_query_info",$);return at(ue([S,k]).pipe(x(([B,I])=>I(B))))},b=()=>at(i(c,null).pipe(x(({callData:y})=>y)));return{getPaymentInfo:f,getEstimatedFees:async(y,m)=>(await f(y,m)).partial_fee,decodedCall:{type:e,value:Dn(t,c)},getEncodedData:b,getBareTx:()=>at(i(c,null).pipe(x(({bare:y})=>y))),sign:p,signSubmitAndWatch:d,signAndSubmit:v}}},Up=(e,t,{getClientCompat:n,getSyncHelpers:r,getIsAsssetCompat:s})=>{const o=({dynamicBuilder:a,lookup:i})=>l=>{try{const{type:c,value:{type:u,value:h}}=a.buildDefinition(i.call).dec(l);return es(c,u,e,t,n("tx",c,u),s)(h)}catch{throw new Error("Invalid call data")}};return({at:a,signal:i}={})=>We(e.getRuntimeContext$(a??null).pipe(z(Gn(async l=>{const c=await r(l);return{id:l.codeHash,txFromCallData:o(l),constants:nt((u,h)=>$a(l,u,h)),query:nt((u,h)=>({getKey:ka(l,u,h,c.query[u][h].args.isValueCompatible)})),tx:nt((u,h)=>({getEncodedData:p=>Ea(l.dynamicBuilder,c.tx[u][h].isValueCompatible,u,h,p)})),compat:c}}))),i)},zp=(e,t,n,r,s)=>{const o=e==="System"&&t==="Number",a=e==="System"&&t==="BlockHash",i=n.runtime$.pipe(Be(Boolean),te(1),x(({dynamicBuilder:d})=>typeof d.buildStorage("System","Number").value.dec(new Uint8Array(32))=="bigint"?BigInt:Le),sn()),l=()=>new Error(`Incompatible runtime entry Storage(${e}.${t})`),c=d=>new Error(`Invalid Arguments calling ${e}.${t}(${d})`),u=d=>{try{return d.dynamicBuilder.buildStorage(e,t)}catch{throw new Error(`Runtime entry Storage(${e}.${t}) not found`)}},h=(...d)=>{const f=d.at(-1),b=Nt(f),[y,m]=b?[d.slice(0,-1),d.at(-1).at==="best"]:[d,!1];return n[m?"best$":"finalized$"].pipe(Kr(()=>p(...y,m?{at:"best"}:{})),rn((g,{value:w,block:E})=>g?{block:E,value:g.value.raw===w.raw?g.value:w}:{block:E,value:w},null),x(g=>({block:g.block,value:g.value.mapped})))},p=(...d)=>{const f=d[d.length-1],b=Nt(f),{at:y}=b?f:{},m=y??null,g=vt(s).pipe(z(w=>n.storage$(m,"value",E=>{const $=u(E),k=w(E),S=d.length===$.len?d:d.slice(0,-1);if(d!==S&&!b)throw c(d);if(!k.args.isValueCompatible(S))throw l();return $.keys.enc(...S)},null,(E,$)=>{const k=u($),{value:{isValueCompatible:S}}=w($),B=E===null?k.fallback:k.value.dec(E);if(!S(B))throw l();return{raw:E,mapped:B}})),n.withHodl(m));return o?n.pinnedBlocks$.pipe(x(w=>{const E=m==="finalized"||!m?w.finalized:m==="best"?w.best:m,$=w.blocks.get(E);if(!$)throw new Je(E,"System.Number");return $}),he((w,E)=>w.number===E.number),cl(i),x(([w,E])=>({block:w,value:{raw:w.number.toString(),mapped:E(w.number)}})),de(w=>{if(w instanceof Je)return g;throw w})):a&&Number(d[0])===0?ue([n.genesis$,n.pinnedBlocks$.pipe(x(w=>{const E=m==="finalized"||!m?w.finalized:m==="best"?w.best:m,$=w.blocks.get(E);if(!$)throw new Je(E,"System.BlockHash");return $}),te(1))]).pipe(x(([w,E])=>({block:E,value:{raw:w,mapped:w}}))):g},v=async(...d)=>{const f=d[d.length-1],b=Nt(f),{signal:y}=b?f:{};return We(p(...d).pipe(x(m=>m.value.mapped)),y)};return{getKey:(...d)=>at(ue([n.getRuntimeContext$(null),s]).pipe(x(([f,b])=>ka(f,e,t,b(f).args.isValueCompatible)(...d)))),getValue:v,getValues:(d,f)=>Promise.all(d.map(b=>v(...f?[...b,f]:b))),getEntries:async(...d)=>{const f=d[d.length-1],b=Nt(f),{signal:y,at:m}=b?f:{},g=m??null,w=vt(s).pipe(z(E=>n.storage$(g,"descendantsValues",$=>{const k=E($),S=u($);if(!k.isCompatible(pt.Partial))throw l();if(d.length>S.len)throw c(d);const B=d.length>0&&b?d.slice(0,-1):d;if(d.length===S.len&&B===d)throw c(d);return S.keys.enc(...B)},null,($,k)=>{const S=u(k),B=E(k),I=$.map(({key:_,value:H})=>({keyArgs:S.keys.dec(_),value:S.value.dec(H)}));if(B.value.level===pt.Partial&&I.some(({value:_})=>!B.value.isValueCompatible(_)))throw l();return I})),x(E=>E.value),n.withHodl(g));return We(w,y)},watchValue:h,watchEntries:(...d)=>{const f=d.at(-1),b=Nt(f);return r(e,t,b?d.slice(0,-1):d,b&&f.at==="best")}}},Aa="RuntimeViewFunction",Oa="execute_view_function",ts=Aa+"_"+Oa,Dp=(e,t,n,r)=>{const s=()=>new Error(`Incompatible runtime entry ViewFn(${e}.${t})`);return(...o)=>{const a=o[o.length-1],i=Nt(a),{signal:l,at:c}=i?a:{},u=c??null,h=ue([n.getRuntimeContext$(u),r]).pipe(z(([p,v])=>{let d;try{d=p.dynamicBuilder.buildRuntimeCall(Aa,Oa)}catch{throw new Error(`Runtime entry RuntimeCall(${ts}) not found`)}let f;try{f=p.dynamicBuilder.buildViewFn(e,t)}catch{throw new Error(`Runtime entry ViewFn(${e}.${t}) not found`)}const b=v(p);if(!b.args.isValueCompatible(o))throw s();const y=f.args.enc(o),m=oe([ee(p.mappedMeta.pallets[e].view.get(t).id),R.enc(y.length),y]);return n.call$(u,ts,X(m)).pipe(x(g=>{try{const w=d.value.dec(g);if(!("success"in w&&"value"in w)||!("type"in w.value)&&!(w.value instanceof Uint8Array))throw null;return w}catch{throw new Error(`Unexpected RuntimeCall(${ts}) type`)}}),x(({success:g,value:w})=>{if(!g)throw new Error(`ViewFn API Error: ${w.type}`);const E=f.value.dec(w);if(!b.value.isValueCompatible(E))throw s();return E}))}),n.withHodl(u));return We(h,l)}};var jp=Object.defineProperty,Lp=(e,t,n)=>t in e?jp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,rt=(e,t,n)=>(Lp(e,typeof t!="symbol"?t+"":t,n),n),ns=Symbol("SUSPENSE"),Vp=class extends Promise{constructor(e){super(e)}},Ca=class extends Error{constructor(){super(),this.name="NoSubscribersError"}},_a=class extends Error{constructor(){super(),this.name="EmptyObservableError"}},_e={},Jn=class extends D{constructor(e,t,n=Ee){super(r=>{const s=new Zt({next:r.next.bind(r),error:r.error.bind(r),complete:Ee});this.refCount++;let o;r.add(()=>{var a;this.refCount--,o.unsubscribe(),this.refCount===0&&(this.currentValue=_e,this.subscription&&this.subscription.unsubscribe(),n(),(a=this.subject)==null||a.complete(),this.subject=null,this.subscription=null,this.promise&&(this.promise.rej(new Ca),this.promise=null))}),this.subject?(o=this.subject.subscribe(s),this.currentValue!==_e&&r.next(this.currentValue)):(this.subject=new ye,o=this.subject.subscribe(s),this.subscription=null,this.subscription=new Zt({next:a=>{this.promise&&a!==ns&&(this.promise.res(a),this.promise=null),this.subject.next(this.currentValue=a)},error:a=>{var i;this.subscription=null;const l=this.subject;this.subject=null,this.currentValue=_e;const c=(i=this.promise)==null?void 0:i.rej;c&&a===ns&&(this.promise.rej=()=>{c(a)}),l.error(a),c&&this.promise&&(this.promise.rej=c)},complete:()=>{if(this.subscription=null,this.promise&&(this.promise.rej(new _a),this.promise=null),this.currentValue!==_e)return this.subject.complete();if(t===_e){const a=this.subject;return this.subject=null,a.error(new _a)}this.subject.next(this.currentValue=t),this.subject.complete()}}),e.subscribe(this.subscription),t!==_e&&this.currentValue===_e&&this.subject.next(this.currentValue=t))}),this.defaultValue=t,rt(this,"subject",null),rt(this,"subscription",null),rt(this,"refCount",0),rt(this,"currentValue",_e),rt(this,"promise",null),rt(this,"pipeState",(...r)=>{const s=super.pipe(...r);return s instanceof Jn?s:new Jn(s,_e)}),rt(this,"getRefCount",()=>this.refCount),rt(this,"getValue",()=>{if(this.promise)return this.promise.p;if(this.currentValue!==_e&&this.currentValue!==ns)return this.currentValue;if(this.defaultValue!==_e)return this.defaultValue;if(this.refCount===0)throw new Ca;const r=new Vp((s,o)=>{this.promise={res:s,rej:o,p:null}});return this.promise.p=r,r}),rt(this,"getDefaultValue",()=>this.defaultValue),t===_e&&delete this.getDefaultValue}};function Ra(e,t){t.getValue=e.getValue,t.getRefCount=e.getRefCount,t.pipeState=e.pipeState,e.getDefaultValue&&(t.getDefaultValue=e.getDefaultValue)}function Np(e,t){const n=new Pp,r=typeof t=="function"?t:()=>t,s=o=>{for(let h=o.length-1;o[h]===void 0&&h>-1;h--)o.splice(-1);const a=[o.length,...o],i=n.get(a);if(i!==void 0)return i;const l=new Jn(e(...o),r(...o),()=>{n.delete(a)}),c=new D(h=>{const p=n.get(a);let v=l;return p?p!==c&&(v=p,Ra(v,c)):n.set(a,u),v.subscribe(h)});Ra(l,c);const u=c;return n.set(a,u),u};return(...o)=>s(o)}var Pp=class{constructor(){rt(this,"root"),this.root=new Map}get(e){let t=this.root;for(let n=0;n<e.length;n++)if(t=t.get(e[n]),!t)return;return t}set(e,t){let n=this.root,r;for(r=0;r<e.length-1;r++){let s=n.get(e[r]);s||(s=new Map,n.set(e[r],s)),n=s}n.set(e[r],t)}delete(e){const t=[this.root];let n=this.root;for(let s=0;s<e.length-1;s++)t.push(n=n.get(e[s]));let r=t.length-1;for(t[r].delete(e[r]);--r>-1&&t[r].get(e[r]).size===0;)t[r].delete(e[r])}};function Fp(e,t){return new Jn(e,t)}var rs=(...e)=>(typeof e[0]=="function"?Np:Fp)(e[0],e.length>1?e[1]:_e);const Ha=(e,t,n)=>{const r=new Map(t.map(i=>[i.key,i])),s=new Map(e.map(i=>[i.key,i])),o=new Map,a=[];return t.forEach(i=>{const{key:l}=i,c=s.get(l);(!c||c.value!==i.value)&&o.set(l,n(i))}),e.forEach(i=>{r.has(i.key)||a.push(i)}),{deltas:{deleted:a,upserted:[...o.values()]},entries:t.map(({key:i})=>o.get(i)??s.get(i))}},Ta=(e,t,n,r=!1)=>{try{let s=r?e:n.blocks.get(e).parent;for(;s&&!t[s];)s=n.blocks.get(s).parent;return s?t[s]:null}catch{return null}},Wp=(e,t)=>n=>{const{keys:r,value:s}=n.dynamicBuilder.buildStorage(e,t);return o=>(o.dec={value:s.dec(o.value),args:r.dec(o.key)},o)},qp=(e,t,n)=>{const r=rs((i,l,c)=>{const u=Wp(i,l),h=(b,y)=>{const m=Ah(e,y.hash).pipe(Be(g=>!g),te(1));return t(y.hash,"closestDescendantMerkleValue",()=>c).pipe(z(g=>{const w=g.value;return w===b?.rootHash?K({...b,block:y,deltas:null,prev:b.block.hash}):t(y.hash,"descendantsValues",()=>c).pipe(n(()=>y.hash),x(([E,$])=>[E.value,u($)]),x(([E,$])=>({prev:b&&b.block.hash,rootHash:w,block:y,patcher:$,...Ha(b?.entries??[],E,$)})))}),dr(m),de(g=>g instanceof Je?Xe:Rt(()=>g)))},p=e.pipe(he((b,y)=>b.finalized===y.finalized),Kr(({blocks:b,finalized:y})=>h(null,b.get(y))),te(1),x(b=>({blocks:{[b.block.hash]:b},finalized:b.block.hash}))),[v,d]=tp(),f=e.pipe(he((b,y)=>b.best===y.best),Gs(v),Kr(([b,y])=>{const{best:m}=b,{blocks:g}=y;let w=g[m]?null:m;if(!w)return Xe;const E=Ta(w,g,b);return E?h(E,b.blocks.get(w)).pipe(x($=>(g[w]=$,y))):(w=b.finalized,h(g[y.finalized],b.blocks.get(w)).pipe(x($=>($.prev=null,{blocks:{[w]:$},finalized:w}))))}));return Qe(p,f).pipe(d())}),s=i=>(l,c,u)=>{const h=r(l,c,u),p=i?"finalized":"best";return ue([h,e.pipe(he((v,d)=>v[p]===d[p]))]).pipe(x(([v,d])=>{const f=Ta(d[p],v.blocks,d,!0);return f&&{update:f,state:v}}),Be(Boolean),he((v,d)=>v.update===d.update),Ks(null),hl(),z(([v,d])=>{if(!v)return[d.update];const{update:f}=v,{state:b,update:y}=d;let m=y;const g=[];for(;m&&m.block.number>f.block.number;)g.unshift(m),m=m.prev?b.blocks[m.prev]:null;if(i&&(b.finalized=y.block.hash,g.length)){const{blocks:w}=b;Object.keys(w).forEach(E=>{w[E].block.number<g[0].block.number&&delete w[E]})}return f===m?g:[{...y,...f.rootHash===y.rootHash?{entries:f.entries,deltas:null}:Ha(f.entries,y.entries,y.patcher)}]}))},o=rs(s(!0)),a=rs(s(!1));return(i,l,c,u)=>{const h=u?a:o;return e.pipe(te(1),z(p=>p.runtimes[p.blocks.get(p[u?"best":"finalized"]).runtime].runtime),x(p=>p.dynamicBuilder.buildStorage(i,l).keys.enc(...c))).pipe(te(1),z(p=>h(i,l,p)),x(({block:{hash:p,number:v,parent:d},deltas:f,entries:b},y)=>{const m=y>0?f:{deleted:[],upserted:b};return{block:{hash:p,number:v,parent:d},entries:b.map(ss),deltas:m&&{deleted:m.deleted.map(ss),upserted:m.upserted.map(ss)}}}))}},ss=e=>e.dec,Kp=/^(?:0x)?((?:[0-9a-fA-F][0-9a-fA-F])+)$/,Ma=(e,t,n)=>{const r=ip(n),{getClientCompat:s,getIsAsssetCompat:o}=r,a=Up(e,t,r),i=qp(e.pinnedBlocks$,e.storage$,e.withRuntime),l=nt((d,f)=>zp(d,f,e,i,s("query",d,f))),c=nt((d,f)=>es(d,f,e,t,s("tx",d,f),o)),u=nt((d,f)=>cp(d,f,e,s("event",d,f))),h=nt((d,f)=>ap(d,f,e,s("constants",d,f))),p=nt((d,f)=>lp(d,f,e,s("apis",d,f))),v=nt((d,f)=>Dp(d,f,e,s("view",d,f)));return{tx:c,constants:h,apis:p,view:v,query:l,event:u,txFromCallData:(d,{at:f,signal:b}={})=>We(e.getRuntimeContext$(f??null).pipe(x(({dynamicBuilder:y,lookup:m})=>{try{const{type:g,value:{type:w,value:E}}=y.buildDefinition(m.call).dec(d);return es(g,w,e,t,s("tx",g,w),o)(E)}catch{throw new Error("createTx: invalid call data")}})),b),getStaticApis:a}};function Gp(e,{getMetadata:t,setMetadata:n}={}){const r=Ul(e),s=Bh(r,{getMetadata:t?B=>vt(t(B)):void 0,setMetadata:n}),{getChainSpecData:o}=r,a=B=>(I,..._)=>ue([B(I,..._),c.header$(I).pipe(x(({number:H,parentHash:L})=>({hash:I,number:H,parent:L,hasNewRuntime:!1})))]).pipe(x(([H,L])=>({value:H,block:L}))),{genesis$:i,...l}=s.chainHead$(),c=s.archive(l.getRuntime$),u={...l,genesis$:nn(o).pipe(x(({genesisHash:B})=>B),de(()=>i),sn(1)),storage$:Vt(l.storage$,a(c.storage$)),body$:Vt(l.body$,c.body$),call$:Vt(l.call$,c.call$),header$:Vt(l.header$,c.header$),eventsAt$:Vt(l.eventsAt$,c.eventsAt$),storageQueries$:Vt(l.storageQueries$,c.storageQueries$),getRuntimeContext$:Vt(l.getRuntimeContext$,c.getRuntimeContext$)},h=r.request,p=(B,I,_)=>new D(H=>{let L=null,Z=null;const ce=()=>{Z!=null&&r.request(I,[Z])};return r._request(B,_,{onSuccess:($e,ot)=>{if(Z=$e,H.closed){ce();return}L=ot(Z,{next:At=>H.next(At),error:At=>H.error(At)})},onError($e){H.error($e)}}),()=>{ce(),L?.()}});let v;const d=new WeakMap,{broadcastTx$:f}=s,b=B=>u.getRuntimeContext$(B).pipe(x(I=>I.metadataRaw)),{holdBlock:y,finalized$:m,bestBlocks$:g,body$:w,header$:E,storage$:$,unfollow:k}=u,S={getChainSpecData:o,getMetadata$:b,getMetadata:(B,I)=>We(b(B),I),blocks$:u.newBlocks$,hodlBlock:B=>y(B,!0),finalizedBlock$:m,getFinalizedBlock:()=>at(m),bestBlocks$:u.bestBlocks$,getBestBlocks:()=>at(g),getBlockBody$:w,getBlockBody:(B,I)=>We(w(B),I),getBlockHeader$:E,getBlockHeader:(B,I)=>We(E(B),I),submit:(...B)=>Ba(u,f,...B),submitAndWatch:B=>Zr(u,f,B),getTypedApi:B=>{if(d.has(B))return d.get(B);const I=Ma(u,f);return d.set(B,I),I},getUnsafeApi:()=>(v??(v=Ma(u,f)),v),rawQuery:(B,{at:I,signal:_}={})=>We($(I??null,"value",()=>{const H=B.match(Kp)?.[1];return H?`0x${H}`:X(zn.fromText(B))}).pipe(x(H=>H.value)),_),destroy:()=>{k(),s.destroy()},_request:h,_subscribe:p};return S.___INTERNAL_DO_NOT_USE=u,S}const st={body:"",call:"",continue:"",follow:"",header:"",stopOperation:"",storage:"",unfollow:"",unpin:""},os={body:"",call:"",finalizedHeight:"",genesisHash:"",hashByHeight:"",header:"",stopStorage:"",storage:""},is={broadcast:"",stop:""},Ua={chainName:"",genesisHash:"",properties:""};Object.entries({chainHead:st,chainSpec:Ua,transaction:is,archive:os}).forEach(([e,t])=>{Object.keys(t).forEach(n=>{t[n]=`${e}_v1_${n}`})});const Zn=sn({refCount:!0,bufferSize:1}),Yp=({allHeads$:e,finalized$:t,getHeader$:n,hasher$:r,getRecursiveHeader:s})=>{const o={blocks:new Map,prevFin:"",finalized:"",best:""},a=($,k=[])=>(k.push($),o.blocks.get($).children.forEach(S=>{a(S,k)}),k),i=$=>{const{blocks:k}=o,{hash:S,parent:B}=$,I={...$,children:new Set,usages:new Set};return k.set(S,I),k.get(B)?.children.add(S),I},l=()=>{o.best=o.finalized;let $=0;const{finalized:k,blocks:S}=o;a(k).map(B=>S.get(B)).forEach(B=>{B.number>$&&($=B.number,o.best=B.hash)})},c=new Map,u=$=>{const k=[...c.get($).children];c.delete($),k.forEach(u)},h=($,k=[])=>{const S=c.get($);return S.header&&(k.push(S.header),S.children.forEach(B=>{h(B,k)})),k},p=new ye,v=$=>p.error($),d=t.pipe(Fs(($,k)=>{const{hash:S}=$;return k||(i($),o.finalized=o.best=$.hash),o.blocks.has(S)?K(S):p.pipe(Be(B=>B===S),Ws(0),te(1))}),bt());e.subscribe($=>{const{parent:k,hash:S,number:B}=$;o.blocks.has(S)||!B||(o.blocks.has(k)?(i($),p.next(S)):(c.set(S,{hash:$.hash,header:$,children:new Set}),c.has(k)||(c.set(k,{hash:k,header:null,children:new Set}),s(k).pipe(Tt(I=>{let _=c.get(I.hash);if(!_)return!1;_.header=I;const H=o.blocks.get(o.finalized);if(H&&I.number<=H.number){for(;c.has(_.header?.parent??"");)_=c.get(_.header.parent);return u(_.hash),!1}if(o.blocks.has(I.parent)){let Z=o.blocks.get(I.parent);const ce=Z.number-H.number;for(let $e=0;$e<ce;$e++){const ot=o.blocks.get(Z.parent);if(!ot)break;Z=ot}return Z===H?h(I.hash).forEach($e=>{c.delete($e.hash),i($e),p.next($e.hash)}):u(I.hash),!1}const L=c.get(I.parent);return L?(L.children.add(I.hash),!1):(c.set(I.parent,{hash:I.parent,header:null,children:new Set([I.hash])}),!0)})).subscribe({error:v})),c.get(k).children.add(S)))},v);const f=()=>{const $=[],k=[],{blocks:S,finalized:B,prevFin:I}=o;let _=S.get(B),H=S.get(_.parent);for(;H&&(k.push(_.hash),H.children.forEach(L=>{L!==_.hash&&a(L,$)}),_=H,_.hash!==I);)H=S.get(_.parent);return k.reverse(),{event:"finalized",prunedBlockHashes:$,finalizedBlockHashes:k}};let b=new Set;const y=$=>{const k=o.blocks.get($);return b.forEach(S=>{k.usages.add(S)}),{event:"newBlock",blockHash:$,parentBlockHash:k.parent,newRuntime:k.hasUpgrade?{}:null}},m=($,k)=>{const{blocks:S}=o,B=S.get($);if(!B||B.usages.size>0)return;const{parent:I,children:_}=B;k!==!0&&_.forEach(H=>m(H,!1)),k!==!1&&m(I,!0),(!S.has(I)||!B.children.size)&&(S.get(I)?.children.delete($),S.delete($))},g=Qe(p.pipe(x($=>({type:"new",value:o.blocks.get($)}))),d.pipe(x($=>({type:"fin",value:$})))).pipe(z($=>{if($.type==="new"){const B=$.value,{hash:I}=B;i(B);const _=[y(I)];return B.number>o.blocks.get(o.best).number&&(o.best=I,_.push({event:"bestBlockChanged",bestBlockHash:I})),_}o.prevFin=o.finalized,o.finalized=$.value;let k=o.best;l();const S=[f()];return k!==o.best&&S.unshift({event:"bestBlockChanged",bestBlockHash:o.best}),S}),bt()),w=nn(()=>o.blocks.size?[null]:d.pipe(te(1),x(()=>null))).pipe(Zn),E=d.pipe(x($=>o.blocks.get($)),Zn);return Qe(g,E).subscribe({error:v}),{clean:()=>{c.clear(),o.blocks.clear()},upstream:$=>{const k=()=>{const{blocks:I,finalized:_}=o,H=[];let L=I.get(_);for(;L&&H.length<10;)H.push(L.hash),L.usages.add($),L=I.get(L.parent);return H.reverse(),{event:"initialized",finalizedBlockHashes:H}},S=I=>{const _=o.blocks.get(I);_&&(_.usages.delete($),m(I))},B=w.pipe(z(()=>{const{best:I,finalized:_}=o,H=a(_).slice(1).map(y);return H.push({event:"bestBlockChanged",bestBlockHash:I}),[k(),...H]}));return{blocks$:ct(B,g).pipe(qt({subscribe:()=>{b.add($)},finalize:()=>{b.delete($)}}),bt()),getHeader:I=>o.blocks.get(I)?.header??null,isPinned:I=>!!o.blocks.get(I)?.usages.has($),unpin:S}},finalized$:E,getHeader$:$=>{const k=o.blocks.get($);return k?K(k):n($)},hasher$:r}},za=e=>({parentHash:t,number:n,stateRoot:r,extrinsicsRoot:s,digest:o})=>{const a=Number(n),i=o.logs.map(ee),l=oe([ee(t),pe.enc(a),ee(r),ee(s),pe.enc(o.logs.length),...i]);return{parent:t,hash:X(e(l)),number:a,hasUpgrade:i.some(([c])=>c===8),header:X(l)}},Da=[jt,jn],Xp=Da.map(za),Qp=e=>{throw new Error("Hasher not supported")},Jp=e=>t=>Da[Xp.findIndex(n=>n(e).hash===t)]||Qp,ja=e=>t=>new D(n=>{let r,s=[],o=!1;const a=new _t;return a.add(t.subscribe({next(i){s?s.push(i):n.next([r,i])},error(i){n.error(i)},complete(){s?o=!0:n.complete()}})),a.add(e.subscribe({next(i){if(r=i,s){const l=[...s];s=null,l.forEach(c=>n.next([r,c]))}o&&n.complete()},error(i){n.error(i)},complete(){s&&n.error(new Error("Empty complete"))}})),a}),Zp={},ef=(e,t)=>{const n=new ye,r=n.pipe(z(h=>t("chain_getBlockHash",[h.number]).pipe(x(Jp(h)))),Zn),s=r.pipe(x(za),Zn),o=ys(ja(s),x(([h,p])=>h(p))),a=(h,p,v=!1)=>new D(d=>{const f=m=>{d.error(m)};let b=null,y=v;return e(h,[],{onSuccess:(m,g)=>{const w=g(m,{next:$=>{y&&(y=!1,n.next($),n.complete()),d.next($)},error:f}),E=()=>{w();try{e(p,[m],{onError:N,onSuccess:N})}catch{}};b!==null?E():b=E},onError(){f(Zp)}}),()=>{b?.(),b=N}}).pipe(o),i=a("chain_subscribeAllHeads","chain_unsubscribeAllHeads"),l=a("chain_subscribeFinalizedHeads","chain_unsubscribeFinalizedHeads",!0),c=h=>t("chain_getHeader",[h]).pipe(o),u=h=>c(h).pipe(z(p=>ct(K(p),u(p.parent))));return{allHeads$:i,finalized$:l,hasher$:r,getRecursiveHeader:u,getHeader$:c}},tf=(e,t)=>Yp(ef(e,t)),nf=e=>(t,n)=>e("state_getReadProof",[[n],t]).pipe(z(r=>{const s=Gi(r.proof);if(!s)throw new Error("Invalid Proof");const{rootHash:o,proofs:a}=s;let i=o,l=a[i],c=2;do{const u=a[i];if(!u||u.type==="Raw")break;if(l=u,i=void 0,!l.partialKey.startsWith(n.slice(c,c+l.partialKey.length)))return[];if(c+=l.partialKey.length,(l.type==="LeafWithHash"||l.type==="BranchWithHash")&&a[l.value]){i=l.value;continue}if("children"in l){const h=Object.entries(l.children).find(([,p])=>a[p]);if(h){if(h[0]!==n[c++])return[];i=h[1]}}}while(i);return[l.hash]})),rf=e=>{const t=(m,g,w,E)=>e(m,g,{onSuccess:w,onError:E}),n=(m,g)=>new D(w=>t(m,g,E=>{w.next(E),w.complete()},E=>{w.error(E)}));let r=null;const s=()=>(r??(r=tf(e,n)),{...r,getBlocks:r.upstream}),o=()=>r?.clean(),a=(m,g,w)=>n("state_call",[g,w,m]),i=(m,g)=>{const w=$=>n("state_getKeysPaged",[g,1e3,$||void 0,m]).pipe(z(k=>{const S=k[0]===$?k.slice(1):k,B=k.length<1e3?Xe:w(k.at(-1));return Qe(K(S),B)})),E=($,k=0)=>$.length?n("state_queryStorageAt",[$,m]).pipe(x(([{changes:S}])=>S),de(S=>{if(k>3)throw S;const B=Math.floor($.length/2);return Qe(E($.slice(0,B),++k),E($.slice(B),k))})):Xe;return w().pipe(z($=>E($)))},l=(m,g)=>i(m,g).pipe(ja(s().hasher$),x(([w,E])=>E.map(([$,k])=>[$,X(w(ee(k)))]))),c=nf(n),[u,h]=["state_getStorage","state_getStorageHash"].map(m=>(g,w)=>n(m,[w,g])),p=n("rpc_methods",[]),v=n("system_name",[]),d=n("system_properties",[]),f=m=>n("chain_getBlock",[m]),b=m=>n("chain_getBlockHash",[m]),y=b(0);return{subscribeBlocks:s,getBlockHash$:b,stgValue:u,stgHash:h,stgDescendantValues:i,stgDescendantHashes:l,stgClosestDescendant:c,runtimeCall:a,getBody:f,chainName:v,properties:d,genesisHash:y,methods:p,request:t,obsRequest:n,clean:o}};let sf=1;const Jt=()=>`${sf++}${Date.now()}`,of=new Set(["value","hash","closestDescendantMerkleValue","descendantsValues","descendantsHashes"]),La=e=>Array.isArray(e)&&e.every(t=>typeof t=="object"&&typeof t.key=="string"&&of.has(t.type)),Va=(e,t,n)=>Qe(...n.map(({key:r,type:s})=>{switch(s){case"value":return e.stgValue(t,r).pipe(Be(Boolean),x(o=>[{key:r,value:o}]));case"hash":return e.stgHash(t,r).pipe(Be(Boolean),x(o=>[{key:r,hash:o}]));case"descendantsValues":return e.stgDescendantValues(t,r).pipe(x(o=>o.map(([a,i])=>({key:a,value:i}))));case"descendantsHashes":return e.stgDescendantHashes(t,r).pipe(x(o=>o.map(([a,i])=>({key:a,hash:i}))));case"closestDescendantMerkleValue":return e.stgClosestDescendant(t,r).pipe(Be(Boolean),x(o=>[{key:r,closestDescendantMerkleValue:o}]))}})),mn=e=>e instanceof Error?e.message:typeof e=="string"?e:"Unhandled exception",{body:af,call:cf,finalizedHeight:lf,genesisHash:uf,hashByHeight:df,header:hf,stopStorage:pf,storage:ff}=os,vf=(e,t,n,r)=>{const s=new Map,o=(i,l,c)=>{const u=Jt();i(u);const h=v=>{r("archive_v1_storageEvent",u,v)},p=Va(e,l,c).pipe(lr(()=>{s.delete(u)})).subscribe(v=>{v.forEach(d=>h({event:"storage",...d}))},v=>{h({event:"storageError",error:mn(v)})},()=>{h({event:"storageDone"})});p.closed||s.set(u,p)},a=(i,l,c)=>{const u=f=>{t(i,f)},h=f=>{f.subscribe({next:u,error:b=>{n(i,b.code??-1,mn(b))}})},[p,v,d]=c;switch(l){case af:return h(e.getBody(p).pipe(x(({block:f})=>f.extrinsics)));case cf:return h(e.runtimeCall(p,v,d).pipe(x(f=>({success:!0,value:f}))));case lf:return h(e.subscribeBlocks().finalized$.pipe(x(f=>f.number),te(1)));case uf:return h(e.genesisHash);case df:return h(e.getBlockHash$(p).pipe(x(f=>[f])));case hf:return h(e.subscribeBlocks().getHeader$(p).pipe(x(f=>f.header)));case pf:{const f=s.get(p);return f?f.unsubscribe():n(i,-32602,"Invalid args")}case ff:return La(v)?o(u,p,v):n(i,-32602,"Invalid args")}throw null};return a.stop=()=>{[...s].forEach(([,i])=>i.unsubscribe()),s.clear()},a},bf=(e,t,n)=>(r,s)=>{const[,,o]=s.split("_"),a=e[o];if(!a)throw null;a.subscribe(i=>{t(r,i)},()=>{n(r,-32602,"Invalid")})},{stop:mf,broadcast:yf}=is,gf=(e,t)=>{const n=new Map,r=(s,o,a)=>{if(o===mf){const[i]=a;n.get(i)?.unsubscribe(),n.delete(i),t(s,null)}else if(o===yf){const i=Jt();n.set(i,e.obsRequest("author_submitExtrinsic",a).pipe(de((l,c)=>ct(En(5e3),c)),dr(e.subscribeBlocks().finalized$.pipe(kn(),de(()=>(n.delete(i),[null]))))).subscribe()),t(s,i)}else throw null};return r.stop=()=>{n.forEach(s=>s.unsubscribe()),n.clear()},r},{follow:wf,header:$f,storage:Na,body:as,call:Pa,unfollow:Ef,stopOperation:kf,unpin:xf}=st,Sf=(e,t,n,r)=>{const s=new Map,o=d=>{if(s.size===2)return n(d,-32800,"Limit reached");const f=Jt(),b=E=>r("chainHead_v1_followEvent",f,E),y=e.subscribeBlocks().getBlocks(f),m=new Map;s.set(f,{id:f,up:y,operations:m,cleanUp:()=>{w()}}),t(d,f);let g=null,w=()=>{w=N,g?.unsubscribe(),g=null,m.forEach(E=>{E()}),m.clear(),s.delete(f)};g=y.blocks$.subscribe({next(E){b(E)},error(){w(),b({event:"stop"})}}),g.closed&&(g=null)},a=(d,f)=>{s.get(f)?.cleanUp(),t(d,"null")},i=(d,f,b)=>{const y=s.get(f)?.operations.get(b);y&&y(),t(d,"null")},l=({up:{getHeader:d}},f,b)=>f(d(b)),c=({up:{unpin:d}},f,b)=>{(typeof b=="string"?[b]:b).forEach(d),f(null)},u=({operations:d,id:f},b,y,m,g)=>{const w=Jt();b({result:"started",operationId:w});const E=(k,S=!1)=>r(Pa,f,S?{operationId:w,event:"operationError",error:k}:{operationId:w,event:"operationCallDone",output:k}),$=e.runtimeCall(y,m,g).subscribe(k=>{d.delete(w),E(k)},k=>{d.delete(w),E(mn(k),!0)});$.closed||d.set(w,()=>{$.unsubscribe(),d.delete(w)})},h=({operations:d,id:f},b,y)=>{const m=Jt();b({result:"started",operationId:m});const g=e.getBody(y).subscribe(({block:{extrinsics:w}})=>{d.delete(m),r(as,f,{event:"operationBodyDone",operationId:m,value:w})},w=>{d.delete(m),r(as,f,{event:"operationError",operationId:m,error:mn(w)})});g.closed||d.set(m,()=>{g.unsubscribe(),d.delete(m)})},p=({operations:d,id:f},b,y,m)=>{const g=Jt();b({result:"started",operationId:g});const w=$=>{r(Na,f,$)},E=Va(e,y,m).pipe(lr(()=>{d.delete(g)})).subscribe($=>{w({event:"operationStorageItems",operationId:g,items:$})},$=>{w({event:"operationError",operationId:g,error:mn($)})},()=>{w({event:"operationStorageDone",operationId:g})});E.closed||d.set(g,()=>{E.unsubscribe()})},v=(d,f,b)=>{if(f===wf)return o(d);const[y,...m]=b,g=s.get(y);if(!g)return n(d,-32602,"Ivalid followSubscription");const w=E=>{t(d,E)};switch(f){case Ef:return a(d,y);case kf:return i(d,y,m[0]);case xf:{const[E]=m;return(Array.isArray(E)?E:[E]).some($=>typeof $!="string")?n(d,-32602,"Invalid args"):c(g,w,E)}default:{const[E,...$]=m;if(!g.up.isPinned(E))return n(d,-32801,"Block not pinned");switch(f){case $f:return l(g,w,E);case as:return h(g,w,E);case Pa:{const[k,S]=$;return typeof k!="string"||typeof S!="string"?n(d,-32602,"Invalid args"):u(g,w,E,k,S)}case Na:{const[k]=$;return La(k)?p(g,w,E,k):n(d,-32602,"Invalid args")}}}}throw null};return v.stop=()=>{s.forEach(d=>{d.cleanUp()})},v},Fa=new Set([st,Ua,os,is].map(e=>Object.values(e)).flat()),If=e=>(t,n)=>{let r=N,s=N;const o=e(b=>{s(b)},b=>{r(),n(b)}),{disconnect:a,request:i}=fr(b=>(s=b,o),t),l=rf(i),c=b=>t({jsonrpc:"2.0",...b}),u=(b,y)=>{c({id:b,result:y})},h=(b,y,m)=>{c({id:b,error:{code:y,message:m}})},p=(b,y,m)=>{c({method:b,params:{subscription:y,result:m}})},v={chainSpec:()=>bf(l,u,h),chainHead:()=>Sf(l,u,h,p),archive:()=>vf(l,u,h,p),transaction:()=>gf(l,u)},d={},f=b=>b in d?d[b]:b in v?d[b]=v[b]():null;return r=()=>{d.chainHead?.stop(),d.archive?.stop(),d.transaction?.stop(),l.clean()},{send:b=>{if(!b)return;const{id:y,method:m,params:g}=b;if(y!==null&&typeof y!="string"&&typeof y!="number"||typeof m!="string"){console.warn(`Invalid message:
|
|
4
|
+
${JSON.stringify(b)}`);return}if(m==="rpc_methods")return l.methods.subscribe(({methods:$})=>{u(y,{methods:[...Fa,...$.filter(k=>!Fa.has(k))]})},$=>{console.error($),h(y,-32602,"Invalid")});const[w]=m.split("_"),E=f(w);if(E)try{return E(y,m,g)}catch($){if($!==null)throw $}l.request(m,g,$=>{u(y,$)},$=>{h(y,$?.code||-1,$?.message||"")})},disconnect:()=>{r(),a()}}},{follow:Bf,unfollow:Af}=st,Wa=()=>({latest:Date.now(),count:0}),Of=e=>(t,n)=>{const r=new Map,s=new Map,o=new Set;let a=Wa();const i=()=>{[r,s,o].forEach(h=>{h.clear()})},l=()=>{u(),i(),n()},{send:c,disconnect:u}=e(h=>{if("id"in h){const{id:p,result:v}=h;if(s.get(p)){s.delete(p);const d=r.get(v);if(d){r.delete(v),t(h),t(d);return}o.add(v);const f=o.size+s.size;if(f>2)console.warn(`Too many chainHead follow subscriptions (${f})`);else if(h.error){console.warn(`chainHead follow failed on the ${f} sub`),l();return}}}else{const{subscription:p,result:v}=h.params;if(v?.event==="stop"){const d=Date.now()-a.latest;a.latest+=d,a.count=d<1e3?a.count+1:1,o.has(p)?o.delete(p):r.set(p,h)}}t(h),a.count>2&&(a=Wa(),l())},h=>{i(),n(h)});return{send(h){const{method:p}=h;p===Bf?s.set(h.id,h):p===Af&&o.delete(h.params[0]),c(h)},disconnect:u}},{follow:Cf,unpin:_f,unfollow:Rf}=st,Hf=e=>(t,n)=>{const r=new Set,s=new Map,o=new Map,a=c=>(...u)=>{[r,s,o].forEach(h=>{h.clear()}),c(...u)},{send:i,disconnect:l}=e(c=>{if("id"in c){t(c);const{id:u,result:h}=c;if(r.has(u)){r.delete(u),s.set(h,new Set),o.set(h,new Map);return}}else{const{subscription:u}=c.params,h=s.get(u),p=o.get(u);if(h){const v=c.params.result,{event:d}=v;if(d==="initialized"&&v.finalizedBlockHashes.forEach(f=>{h.add(f)}),d==="newBlock"){const{parentBlockHash:f}=v;if(!h.has(f)){const m=p.get(f)??[];m.push(c),p.set(f,m);return}const b=v.blockHash;h.add(v.blockHash),t(c);const y=p.get(b);y&&(p.delete(b),y.forEach(m=>{h.add(m.params.result.blockHash),t(m)}));return}d==="stop"&&(h.delete(u),o.delete(u))}t(c)}},a(n));return{send:c=>{const u=c.params[0];switch(c.method){case Cf:r.add(c.id);break;case _f:const[h,p]=c.params;p.forEach(v=>{s.get(h)?.delete(v),o.get(h)?.delete(v)});break;case Rf:s.delete(u),o.delete(u);break}i(c)},disconnect:a(l)}},{follow:Tf,unpin:Mf,unfollow:Uf}=st,zf=e=>(t,n)=>{const r=new Set,s=new Map,o=new Map,a=c=>(...u)=>{[r,s,o].forEach(h=>{h.clear()}),c(...u)},{send:i,disconnect:l}=e(c=>{if("id"in c){t(c);const{id:u,result:h}=c;if(r.has(u)){r.delete(u),s.set(h,new Set),o.set(h,new Map);return}}else{const{subscription:u}=c.params,h=s.get(u),p=o.get(u);if(h){const v=c.params.result,{event:d}=v;if(d==="initialized"&&v.finalizedBlockHashes.forEach(f=>{h.add(f)}),d==="finalized"&&(v.prunedBlockHashes=v.prunedBlockHashes.filter(f=>h.has(f))),d==="newBlock"){h.add(v.blockHash);const f=v.blockHash,b=p.get(f);if(b){p.delete(f),t(c),Promise.resolve().then(()=>{t(b)});return}}if(d==="bestBlockChanged"){const f=v.bestBlockHash;if(!h.has(f)){o.get(u).set(f,c);return}}d==="stop"&&(h.delete(u),o.delete(u))}t(c)}},a(n));return{send:c=>{const u=c.params[0];switch(c.method){case Tf:r.add(c.id);break;case Mf:const[h,p]=c.params;p.forEach(v=>{s.get(h)?.delete(v),o.get(h)?.delete(v)});break;case Uf:s.delete(u),o.delete(u);break}i(c)},disconnect:a(l)}},{follow:Df,body:jf,call:Lf,storage:Vf,unfollow:Nf,stopOperation:Pf}=st,Ff=new Set(["BodyDone","CallDone","StorageDone","Inaccessible","Error"].map(e=>"operation"+e)),qa=e=>Ff.has(e.params?.result?.event),Wf=e=>(t,n)=>{const r=new Set,s=new Map,o=new Map,a=new Map,i=u=>(...h)=>{[r,s,o,a].forEach(p=>{p.clear()}),u(...h)},{send:l,disconnect:c}=e(u=>{if("id"in u){t(u);const{id:h,result:p}=u;if(r.has(h)){r.delete(h),o.set(p,new Set),a.set(p,new Map);return}const v=s.get(h);if(v!==void 0){s.delete(h);const d=u.result?.operationId;if(d!==void 0&&o.has(v)){const f=o.get(v);f.add(d);const b=a.get(v)?.get(d);b&&(b.forEach(t),a.get(v).delete(d),qa(b.at(-1))&&f.delete(d))}}}else{const{subscription:h,result:p}=u.params,v=o.get(h);if(v){const{operationId:d}=u.params.result;if(d!==void 0)if(v.has(d))qa(u)&&v.delete(d);else{const f=a.get(h),b=f.get(d)??[];b.push(u),f.set(d,b);return}else p?.event==="stop"&&(o.delete(h),a.delete(h))}t(u)}},i(n));return{send:u=>{const h=u.params[0];switch(u.method){case Df:r.add(u.id);break;case jf:case Lf:case Vf:s.set(u.id,h);break;case Nf:o.delete(h),a.delete(h);break;case Pf:o.get(h)?.delete(u.params[1])}l(u)},disconnect:i(c)}},qf=e=>(t,n)=>e(r=>{const s=r.params?.result;if(!("id"in r)&&s){const{prunedBlockHashes:o,finalizedBlockHash:a,event:i}=s;i==="finalized"&&Array.isArray(o)?s.prunedBlockHashes=[...new Set(s.prunedBlockHashes)]:i==="initialized"&&a&&(s.finalizedBlockHashes=[s.finalizedBlockHash],delete s.finalizedBlockHash)}t(r)},n),Kf=e=>(...t)=>{const{send:n,disconnect:r}=e(...t);return{send:s=>{const{method:o,params:a,id:i,...l}=s;o==st.unpin&&a&&Array.isArray(a[1])?a[1].forEach((c,u)=>{n({...l,id:u===0?i:`${i}-patched-${u}`,method:o,params:[a[0],c]})}):n(s)},disconnect:r}},cs=(...e)=>t=>e.reduce((n,r)=>r(n),t),Ka=e=>({jsonrpc:"2.0",...e}),Gf=(e,t,n,r={})=>Ka({method:"chainHead_v1_followEvent",params:{subscription:e,result:{event:t,operationId:n,...r}}}),Yf=new Set(["newBlock","bestBlockChanged","stop"]),Xf=cs(Wf,Kf,qf,Hf,zf,e=>(t,n)=>{const r=new Set,s=new Map,o=l=>(...c)=>{[r,s].forEach(u=>{u.clear()}),l(...c)},{send:a,disconnect:i}=e(l=>{if("id"in l){const{id:c,result:u}=l;r.has(c)&&(r.delete(c),s.set(u,()=>{s.delete(u)}))}else{const{subscription:c}=l.params,u=s.get(c);if(u){const h=l.params.result,{event:p}=h;if(p==="initialized"){const v=setTimeout(()=>{s.delete(c),t(Gf(c,"bestBlockChanged",void 0,{bestBlockHash:h.finalizedBlockHashes.at(-1)}))},500);s.set(c,()=>{s.delete(c),clearTimeout(v)})}else Yf.has(p)&&u()}}t(l)},o(n));return{send(l){switch(l.method){case st.follow:r.add(l.id);break;case st.unfollow:s.get(l.params[0])?.()}a(l)},disconnect:o(i)}},Of),Ga=["chainHead","transaction","chainSpec","archive"].map(e=>`${e}_v1`),Qf=e=>{const t=Object.fromEntries(Ga.map(n=>[n,!!e.find(r=>r.startsWith(n))]));return n=>{const r=Jf(n),s=Xf(r()),o=If(r(a=>["chainHead_v1","archive_v1"].every(i=>!a.method.startsWith(i))));return(a,i)=>{const l=s(u=>{"error"in u&&u.error.code===-32800&&(console.warn("Max follow connections received: chainHead_v1 disabled"),t.chainHead_v1=!1),a(u)},i),c=o(a,i);return{send(u){for(const h of Ga)if(u.method.startsWith(h)){t[h]?l.send(u):c.send(u);return}l.send(u)},disconnect(){l.disconnect(),c.disconnect()}}}}},Jf=e=>{const t=new ye,n=new ye;let r=0,s=null;return(o=()=>!0)=>(a,i)=>{r++,s??(s=e(h=>n.next(h),h=>t.next(h)));const l=n.pipe(Be(h=>h.id==null&&"method"in h&&o(h))).subscribe(a),c=t.subscribe(i),u=new Set;return{send(h){if(h.id==null)return s?.send(h);const p=h.id,v=n.pipe(Be(d=>d.id===p),te(1)).subscribe(d=>{if(a(d),!v)throw new Error("unreachable");u.delete(v)});u.add(v),s?.send(h)},disconnect(){l.unsubscribe(),c.unsubscribe(),u.forEach(h=>h.unsubscribe()),r--,r===0&&(s?.disconnect(),s=null)}}}},Zf=e=>t=>(n,r)=>{let s=N,o=[],a=d=>{o.push(d)},i=N,l=!0,c=()=>{l=!1,o=[],i(),c=s=u=i=N},u=d=>{c(),r(d)};const h=t(d=>s(d),d=>u(d));let{disconnect:p}=h;const{request:v}=fr(d=>(s=d,{...h,disconnect:N}));return l&&(i=e(d=>{i=N,d?({send:a,disconnect:p}=d((f,b)=>(u=y=>{c(),b(y)},s=f,h))(n,r),o.forEach(a),o=[]):u()},v)),{send:d=>{a(d)},disconnect:()=>{c(),p()}}},Ya="rpc_methods",ev=e=>t=>(n,r)=>{const s={methods:e},{send:o,disconnect:a}=t(n,r);return{disconnect:a,send(i){i.id&&i.method===Ya?n(Ka({id:i.id,result:s})):o(i)}}},tv=cs(e=>(t,n)=>{let r=0;const s=new Map,o=()=>{s.clear()},{send:a,disconnect:i}=e(l=>{const{id:c}=l;s.has(c)&&(l.id=s.get(c),s.delete(c)),t(l)},l=>{o(),n(l)});return{send:l=>{l.id!==void 0&&(s.set(r,l.id),l.id=r++),a(l)},disconnect(){o(),i()}}},(e=>Zf((t,n)=>{let r=0,s=N;const o=()=>{r++,s=n(Ya,[],{onSuccess:({methods:a})=>{t(cs(ev(a),e(a)))},onError:()=>{if(r>3)t(null);else{const a=setTimeout(o,500);s=()=>clearTimeout(a)}}})};return o(),()=>s()}))(Qf));var qe=(e=>(e.CONNECTING="CONNECTING",e.CONNECTED="CONNECTED",e.ERROR="ERROR",e.CLOSE="CLOSE",e))(qe||{}),Ke=(e=>(e.CONNECTING="CONNECTING",e.CONNECTED="CONNECTED",e.TIMEOUT="TIMEOUT",e.STALE="STALE",e.ERROR="ERROR",e.CLOSE="CLOSE",e.DISCONNECT="DISCONNECT",e.IN="IN",e.OUT="OUT",e))(Ke||{});let nv=0;const Xa=()=>`proxyOpaque${nv++}`,er=e=>({jsonrpc:"2.0",...e}),ls=e=>({jsonrpc:"2.0",...e}),Qa=()=>`___proxyInternalId__${Xa()}`,rv=e=>{let t={type:1,activeBroadcasts:new Map,pending:[]};const n=s=>{let o=!0;if(t.type===0){if(Zs(s)){const{id:a}=s,i=t.pendingBroadcasts.get(a);if(i){if(t.pendingBroadcasts.delete(a),!("result"in s))return;const l=s.result,c=t.activeBroadcasts.get(i);c?c.upToken=l:t.connection.send(er({id:Qa(),method:"transaction_v1_stop",params:[l]}));return}o=t.onGoingRequests.has(a),"result"in s&&t.onGoingRequests.get(a)?.type===0&&t.activeChainHeads.add(s.result),t.onGoingRequests.delete(s.id)}else if("params"in s){const{subscription:a,result:i}=s.params;i?.event==="stop"&&t.activeChainHeads.delete(a)}}o&&t.type!==2&&e(s)},r=s=>{if(t.type!==2){if("id"in s){const{method:o,id:a,params:i}=s,[l,,c]=o.split("_");if(l==="transaction"){if(c==="stop"){const[u]=i,h=t.activeBroadcasts.get(u);t.activeBroadcasts.delete(u),e(ls({id:a,result:null})),t.type===0&&h&&h.upToken&&t.connection.send(er({id:a,method:o,params:[h.upToken]}));return}if(c==="broadcast"){const u=Xa();t.activeBroadcasts.set(u,{tx:i[0],synToken:u}),t.type===0&&(t.pendingBroadcasts.set(a,u),t.connection.send(s)),e(ls({id:a,result:u}));return}}}if(t.type===1){t.pending.push(s);return}if(s.method==="chainHead_v1_unfollow"&&t.activeChainHeads.delete(s.params[0]),"id"in s){const{method:o,id:a}=s,[i,,l]=o.split("_"),c=i==="chainHead"?l==="follow"?{type:0,msg:s}:{type:1,id:a}:{type:2,msg:s};t.onGoingRequests.set(a,c)}t.connection.send(s)}};return{send:r,disconnect:()=>{t.type!==2&&(t.type===0&&t.connection.disconnect(),t={type:2})},connect:s=>{if(t.type!==1)throw new Error("Nonesense");const{pending:o,activeBroadcasts:a}=t,i=new Map,l=new Set,c=()=>{const u=t.type!==2?t.activeBroadcasts:new Map;u.forEach(h=>h.upToken=void 0),t={type:1,activeBroadcasts:u,pending:[]},l.forEach(h=>{n(er({method:"chainHead_v1_follow",params:{subscription:h,result:{event:"stop",internal:!0}}}))}),l.clear();for(const h of i.values())h.type===1?n(ls({id:h.id,error:{code:-32603,message:"Internal error"}})):r(h.msg);i.clear()};t={type:0,connection:null,activeBroadcasts:a,pendingBroadcasts:new Map,onGoingRequests:i,activeChainHeads:l},t.connection=s(n,c),a.forEach(u=>{if(t.type===0){const h=Qa();t.pendingBroadcasts.set(h,u.synToken),t.connection.send(er({id:h,method:"transaction_v1_broadcast",params:[u.tx]}))}}),o.forEach(r)}}},us=()=>{},Ja=250,sv=e=>t=>{let n=rv(t),r=Date.now(),s=0,o;const a=()=>s&&2**Math.min(5,s)*Ja;let i=us,l=()=>{const u=setTimeout(()=>{let h=!0;const p=e(v=>{h=!1,i=us,v?n&&n.connect((d,f)=>{let b=!0;return v(d,y=>{if(b){b=!1;const m=Date.now()-r;s+=m>Ja+a()?-s:1,r+=m,f(y),c()}})}):c()});h&&(i=p)},0);i=()=>clearTimeout(u)};const c=()=>{o=setTimeout(l,a())};return l(),{send(u){n?.send(u)},disconnect(){clearTimeout(o),i(),i=us,n?.disconnect(),n=null}}},ov=e=>(t,n)=>{let r=null,s=[];const o=()=>{i(),a=i=N,r=void 0,s=[]};let a=l=>{o(),n(l)},i=e(l=>{i=N,l?(r=l(t,a),s.forEach(c=>r?.send(c)),s=[]):a()});return{send:l=>{r?r.send(l):r===null&&s.push(l)},disconnect:()=>{const l=r;o(),l?.disconnect()}}},iv=(e,t,n,r)=>{const s=r?a=>r({type:a}):N,o=r?(a,i)=>r({type:a,msg:i}):N;return ov(a=>{const[i,l]=e();r?.({type:Ke.CONNECTING,url:i.url});let c=()=>{c=N,d(),a(null)},u=!0,h;const p=()=>{clearTimeout(h);const[g,w]=u?[n,Ke.TIMEOUT]:[t,Ke.STALE];u=!1,h=setTimeout(()=>{s(w),c({type:qe.ERROR,event:{type:"timeout"}})},g)},v=()=>{clearTimeout(h)};p();let d=()=>{v()};const f=g=>{r?.({type:Ke.ERROR,error:g}),c({type:qe.ERROR,event:g})},b=g=>{s(Ke.CLOSE),c({type:qe.CLOSE,event:g})},y=()=>{s(Ke.DISCONNECT),d();try{i.addEventListener("error",N,{once:!0}),i.close()}catch{}},m=()=>{s(Ke.CONNECTED),l(),p(),i.removeEventListener("open",m),a((g,w)=>{d=()=>{d=N,v(),i.removeEventListener("error",f),i.removeEventListener("ping",p),i.removeEventListener("message",E),i.removeEventListener("close",b)},c=$=>{c=N,d(),w($)};const E=$=>{p(),typeof $.data=="string"&&(o(Ke.IN,$.data),g(JSON.parse($.data)))};return i.addEventListener("ping",p),i.addEventListener("message",E),i.addEventListener("error",f),i.addEventListener("close",b),{send($){const k=JSON.stringify($);o(Ke.OUT,k),i.send(k)},disconnect:y}})};return d=()=>{d=N,v(),i.removeEventListener("error",f),i.removeEventListener("close",b),i.removeEventListener("open",m)},i.addEventListener("open",m),i.addEventListener("error",f),y})},av={onStatusChanged:N,timeout:5e3,heartbeatTimeout:4e4,middleware:Le},Za=(e,t)=>{const{onStatusChanged:n,timeout:r,heartbeatTimeout:s,middleware:o,logger:a}={...av,...t},i=Array.isArray(e)?e:[e],l=t?.websocketClass??globalThis.WebSocket;if(!l)throw new Error("Missing WebSocket class");let c=0,u,h=null,p={type:qe.CLOSE,event:null},v;const d=m=>n(p=m),f=o(iv(()=>{v=h?.url;const m=u??i[c++%i.length];return u=void 0,d({type:qe.CONNECTING,uri:m}),[h=new l(m),()=>{d({type:qe.CONNECTED,uri:m})}]},s,r,a)),b=(m,g)=>f(m,w=>{d({type:qe.ERROR,event:w}),g(w)}),y=sv(m=>{if(!v||h.url!==v)return m(b),N;const g=setTimeout(m,250,b);return()=>{clearTimeout(g)}});return Object.assign(y,{switch:m=>{p.type!==qe.CLOSE&&(u=m,p.type!==qe.ERROR&&h&&h.close())},getStatus:()=>p})},cv=(e,t={})=>Za(e,t),ec=(e,t={})=>Za(e,{...t,middleware:tv}),lv=(e,t={})=>{const n=ec(e,t),r=Gp(n,t);return Object.assign(r,{switch:n.switch,getStatus:n.getStatus})};it.SocketEvents=Ke,it.WsEvent=qe,it.createWsClient=lv,it.getWsProvider=ec,it.getWsRawProvider=cv}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polkadot-api",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"author": "Josep M Sobrepere (https://github.com/josepot)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -113,23 +113,23 @@
|
|
|
113
113
|
},
|
|
114
114
|
"dependencies": {
|
|
115
115
|
"@rx-state/core": "^0.1.4",
|
|
116
|
-
"@polkadot-api/cli": "0.20.
|
|
116
|
+
"@polkadot-api/cli": "0.20.1",
|
|
117
117
|
"@polkadot-api/ink-contracts": "0.6.0",
|
|
118
118
|
"@polkadot-api/json-rpc-provider": "0.2.0",
|
|
119
|
-
"@polkadot-api/
|
|
120
|
-
"@polkadot-api/known-chains": "0.11.0",
|
|
119
|
+
"@polkadot-api/known-chains": "0.11.1",
|
|
121
120
|
"@polkadot-api/metadata-builders": "0.14.0",
|
|
122
|
-
"@polkadot-api/
|
|
121
|
+
"@polkadot-api/metadata-compatibility": "0.6.0",
|
|
123
122
|
"@polkadot-api/observable-client": "0.18.3",
|
|
124
|
-
"@polkadot-api/polkadot-signer": "0.1.6",
|
|
125
123
|
"@polkadot-api/pjs-signer": "0.7.0",
|
|
124
|
+
"@polkadot-api/logs-provider": "0.2.0",
|
|
125
|
+
"@polkadot-api/polkadot-signer": "0.1.6",
|
|
126
126
|
"@polkadot-api/signer": "0.3.0",
|
|
127
|
+
"@polkadot-api/sm-provider": "0.3.0",
|
|
127
128
|
"@polkadot-api/smoldot": "0.4.0",
|
|
128
129
|
"@polkadot-api/substrate-bindings": "0.20.0",
|
|
129
|
-
"@polkadot-api/substrate-client": "0.7.0",
|
|
130
|
-
"@polkadot-api/sm-provider": "0.3.0",
|
|
131
|
-
"@polkadot-api/utils": "0.4.0",
|
|
132
130
|
"@polkadot-api/ws-middleware": "0.3.0",
|
|
131
|
+
"@polkadot-api/utils": "0.4.0",
|
|
132
|
+
"@polkadot-api/substrate-client": "0.7.0",
|
|
133
133
|
"@polkadot-api/ws-provider": "0.9.0"
|
|
134
134
|
},
|
|
135
135
|
"devDependencies": {
|