polkadot-api 2.1.6-canary.b804e21 → 2.1.6
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 +1 -1
- package/package.json +20 -20
package/bin/cli.js
CHANGED
package/dist/umd/ws.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
(function(it,_t){typeof exports=="object"&&typeof module<"u"?_t(exports):typeof define=="function"&&define.amd?define(["exports"],_t):(it=typeof globalThis<"u"?globalThis:it||self,_t(it.papiWs={}))})(this,(function(it){"use strict";var _t=function(e,t){return _t=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])},_t(e,t)};function Qe(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");_t(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}function pc(e,t,n,r){function s(o){return o instanceof n?o:new n(function(i){i(o)})}return new(n||(n=Promise))(function(o,i){function a(u){try{c(r.next(u))}catch(h){i(h)}}function l(u){try{c(r.throw(u))}catch(h){i(h)}}function c(u){u.done?o(u.value):s(u.value).then(a,l)}c((r=r.apply(e,t||[])).next())})}function ms(e,t){var n={label:0,sent:function(){if(o[0]&1)throw o[1];return o[1]},trys:[],ops:[]},r,s,o,i=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),typeof Symbol=="function"&&(i[Symbol.iterator]=function(){return this}),i;function a(c){return function(u){return l([c,u])}}function l(c){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=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 Ft(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=[],i;try{for(;(t===void 0||t-- >0)&&!(s=r.next()).done;)o.push(s.value)}catch(a){i={error:a}}finally{try{s&&!s.done&&(n=r.return)&&n.call(r)}finally{if(i)throw i.error}}return o}function Me(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 Wt(e){return this instanceof Wt?(this.v=e,this):new Wt(e)}function fc(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),a("next"),a("throw"),a("return",i),s[Symbol.asyncIterator]=function(){return this},s;function i(f){return function(d){return Promise.resolve(d).then(f,h)}}function a(f,d){r[f]&&(s[f]=function(v){return new Promise(function(b,y){o.push([f,v,b,y])>1||l(f,v)})},d&&(s[f]=d(s[f])))}function l(f,d){try{c(r[f](d))}catch(v){p(o[0][3],v)}}function c(f){f.value instanceof Wt?Promise.resolve(f.value.v).then(u,h):p(o[0][2],f)}function u(f){l("next",f)}function h(f){l("throw",f)}function p(f,d){f(d),o.shift(),o.length&&l(o[0][0],o[0][1])}}function vc(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 Ft=="function"?Ft(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(i){return new Promise(function(a,l){i=e[o](i),s(a,l,i.done,i.value)})}}function s(o,i,a,l){Promise.resolve(l).then(function(c){o({value:c,done:a})},i)}}typeof SuppressedError=="function"&&SuppressedError;function Q(e){return typeof e=="function"}function or(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 ir=or(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
3
|
`):"",this.name="UnsubscriptionError",this.errors=n}});function gn(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var Rt=(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 i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var a=Ft(i),l=a.next();!l.done;l=a.next()){var c=l.value;c.remove(this)}}catch(v){t={error:v}}finally{try{l&&!l.done&&(n=a.return)&&n.call(a)}finally{if(t)throw t.error}}else i.remove(this);var u=this.initialTeardown;if(Q(u))try{u()}catch(v){o=v instanceof ir?v.errors:[v]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var p=Ft(h),f=p.next();!f.done;f=p.next()){var d=f.value;try{ws(d)}catch(v){o=o??[],v instanceof ir?o=Me(Me([],He(o)),He(v.errors)):o.push(v)}}}catch(v){r={error:v}}finally{try{f&&!f.done&&(s=p.return)&&s.call(p)}finally{if(r)throw r.error}}}if(o)throw new ir(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)ws(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)&&gn(n,t)},e.prototype.remove=function(t){var n=this._finalizers;n&&gn(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=(function(){var t=new e;return t.closed=!0,t})(),e})(),ys=Rt.EMPTY;function gs(e){return e instanceof Rt||e&&"closed"in e&&Q(e.remove)&&Q(e.add)&&Q(e.unsubscribe)}function ws(e){Q(e)?e():e.unsubscribe()}var bc={Promise:void 0},mc={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,Me([e,t],He(n)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function $s(e){mc.setTimeout(function(){throw e})}function ke(){}function wn(e){e()}var tn=(function(e){Qe(t,e);function t(n){var r=e.call(this)||this;return r.isStopped=!1,n?(r.destination=n,gs(n)&&n.add(r)):r.destination=wc,r}return t.create=function(n,r,s){return new qt(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})(Rt),yc=(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){$n(r)}},e.prototype.error=function(t){var n=this.partialObserver;if(n.error)try{n.error(t)}catch(r){$n(r)}else $n(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(n){$n(n)}},e})(),qt=(function(e){Qe(t,e);function t(n,r,s){var o=e.call(this)||this,i;return Q(n)||!n?i={next:n??void 0,error:r??void 0,complete:s??void 0}:i=n,o.destination=new yc(i),o}return t})(tn);function $n(e){$s(e)}function gc(e){throw e}var wc={closed:!0,next:ke,error:gc,complete:ke},ar=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function je(e){return e}function Es(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return ks(e)}function ks(e){return e.length===0?je: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=Ec(t)?t:new qt(t,n,r);return wn(function(){var i=s,a=i.operator,l=i.source;o.add(a?a.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=xs(n),new n(function(s,o){var i=new qt({next:function(a){try{t(a)}catch(l){o(l),i.unsubscribe()}},error:o,complete:s});r.subscribe(i)})},e.prototype._subscribe=function(t){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(t)},e.prototype[ar]=function(){return this},e.prototype.pipe=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return ks(t)(this)},e.prototype.toPromise=function(t){var n=this;return t=xs(t),new t(function(r,s){var o;n.subscribe(function(i){return o=i},function(i){return s(i)},function(){return r(o)})})},e.create=function(t){return new e(t)},e})();function xs(e){var t;return(t=e??bc.Promise)!==null&&t!==void 0?t:Promise}function $c(e){return e&&Q(e.next)&&Q(e.error)&&Q(e.complete)}function Ec(e){return e&&e instanceof tn||$c(e)&&gs(e)}function kc(e){return Q(e?.lift)}function J(e){return function(t){if(kc(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 G(e,t,n,r,s){return new xc(e,t,n,r,s)}var xc=(function(e){Qe(t,e);function t(n,r,s,o,i,a){var l=e.call(this,n)||this;return l.onFinalize=i,l.shouldUnsubscribe=a,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})(tn),Sc=or(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),ve=(function(e){Qe(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 Ss(this,this);return r.operator=n,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new Sc},t.prototype.next=function(n){var r=this;wn(function(){var s,o;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var i=Ft(r.currentObservers),a=i.next();!a.done;a=i.next()){var l=a.value;l.next(n)}}catch(c){s={error:c}}finally{try{a&&!a.done&&(o=i.return)&&o.call(i)}finally{if(s)throw s.error}}}})},t.prototype.error=function(n){var r=this;wn(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;wn(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,i=s.isStopped,a=s.observers;return o||i?ys:(this.currentObservers=null,a.push(n),new Rt(function(){r.currentObservers=null,gn(a,n)}))},t.prototype._checkFinalizedStatuses=function(n){var r=this,s=r.hasError,o=r.thrownError,i=r.isStopped;s?n.error(o):i&&n.complete()},t.prototype.asObservable=function(){var n=new D;return n.source=this,n},t.create=function(n,r){return new Ss(n,r)},t})(D),Ss=(function(e){Qe(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:ys},t})(ve),Bc=(function(e){Qe(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})(ve),cr={now:function(){return(cr.delegate||Date).now()},delegate:void 0},nn=(function(e){Qe(t,e);function t(n,r,s){n===void 0&&(n=1/0),r===void 0&&(r=1/0),s===void 0&&(s=cr);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,i=r._infiniteTimeWindow,a=r._timestampProvider,l=r._windowTime;s||(o.push(n),!i&&o.push(a.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,i=s._buffer,a=i.slice(),l=0;l<a.length&&!n.closed;l+=o?1:2)n.next(a[l]);return this._checkFinalizedStatuses(n),r},t.prototype._trimBuffer=function(){var n=this,r=n._bufferSize,s=n._timestampProvider,o=n._buffer,i=n._infiniteTimeWindow,a=(i?1:2)*r;if(r<1/0&&a<o.length&&o.splice(0,o.length-a),!i){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})(ve),Ic=(function(e){Qe(t,e);function t(n,r){return e.call(this)||this}return t.prototype.schedule=function(n,r){return this},t})(Rt),Bs={setInterval:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setInterval.apply(void 0,Me([e,t],He(n)))},clearInterval:function(e){return clearInterval(e)},delegate:void 0},Ac=(function(e){Qe(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,i=this.scheduler;return o!=null&&(this.id=this.recycleAsyncId(i,o,r)),this.pending=!0,this.delay=r,this.id=(s=this.id)!==null&&s!==void 0?s:this.requestAsyncId(i,this.id,r),this},t.prototype.requestAsyncId=function(n,r,s){return s===void 0&&(s=0),Bs.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&&Bs.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(i){s=!0,o=i||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,gn(o,this),r!=null&&(this.id=this.recycleAsyncId(s,r,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},t})(Ic),Is=(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=cr.now,e})(),Oc=(function(e){Qe(t,e);function t(n,r){r===void 0&&(r=Is.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})(Is),As=new Oc(Ac),Cc=As,Ne=new D(function(e){return e.complete()});function _c(e){return e&&Q(e.schedule)}function lr(e){return e[e.length-1]}function ur(e){return Q(lr(e))?e.pop():void 0}function rn(e){return _c(lr(e))?e.pop():void 0}function Rc(e,t){return typeof lr(e)=="number"?e.pop():t}var Os=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function Cs(e){return Q(e?.then)}function _s(e){return Q(e[ar])}function Rs(e){return Symbol.asyncIterator&&Q(e?.[Symbol.asyncIterator])}function Ts(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 Tc(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Hs=Tc();function Ms(e){return Q(e?.[Hs])}function Us(e){return fc(this,arguments,function(){var n,r,s,o;return ms(this,function(i){switch(i.label){case 0:n=e.getReader(),i.label=1;case 1:i.trys.push([1,,9,10]),i.label=2;case 2:return[4,Wt(n.read())];case 3:return r=i.sent(),s=r.value,o=r.done,o?[4,Wt(void 0)]:[3,5];case 4:return[2,i.sent()];case 5:return[4,Wt(s)];case 6:return[4,i.sent()];case 7:return i.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}})})}function zs(e){return Q(e?.getReader)}function de(e){if(e instanceof D)return e;if(e!=null){if(_s(e))return Hc(e);if(Os(e))return Mc(e);if(Cs(e))return Uc(e);if(Rs(e))return Ds(e);if(Ms(e))return zc(e);if(zs(e))return Dc(e)}throw Ts(e)}function Hc(e){return new D(function(t){var n=e[ar]();if(Q(n.subscribe))return n.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Mc(e){return new D(function(t){for(var n=0;n<e.length&&!t.closed;n++)t.next(e[n]);t.complete()})}function Uc(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,$s)})}function zc(e){return new D(function(t){var n,r;try{for(var s=Ft(e),o=s.next();!o.done;o=s.next()){var i=o.value;if(t.next(i),t.closed)return}}catch(a){n={error:a}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}t.complete()})}function Ds(e){return new D(function(t){Lc(e,t).catch(function(n){return t.error(n)})})}function Dc(e){return Ds(Us(e))}function Lc(e,t){var n,r,s,o;return pc(this,void 0,void 0,function(){var i,a;return ms(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),n=vc(e),l.label=1;case 1:return[4,n.next()];case 2:if(r=l.sent(),!!r.done)return[3,4];if(i=r.value,t.next(i),t.closed)return[2];l.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=l.sent(),s={error:a},[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 Ls(e,t){return t===void 0&&(t=0),J(function(n,r){n.subscribe(G(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 js(e,t){return t===void 0&&(t=0),J(function(n,r){r.add(e.schedule(function(){return n.subscribe(r)},t))})}function jc(e,t){return de(e).pipe(js(t),Ls(t))}function Nc(e,t){return de(e).pipe(js(t),Ls(t))}function Vc(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 Pc(e,t){return new D(function(n){var r;return ft(n,t,function(){r=e[Hs](),ft(n,t,function(){var s,o,i;try{s=r.next(),o=s.value,i=s.done}catch(a){n.error(a);return}i?n.complete():n.next(o)},0,!0)}),function(){return Q(r?.return)&&r.return()}})}function Ns(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 Fc(e,t){return Ns(Us(e),t)}function Wc(e,t){if(e!=null){if(_s(e))return jc(e,t);if(Os(e))return Vc(e,t);if(Cs(e))return Nc(e,t);if(Rs(e))return Ns(e,t);if(Ms(e))return Pc(e,t);if(zs(e))return Fc(e,t)}throw Ts(e)}function vt(e,t){return t?Wc(e,t):de(e)}function W(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=rn(e);return vt(e,n)}function Tt(e,t){var n=Q(e)?e:function(){return e},r=function(s){return s.error(n())};return new D(r)}var Vs=or(function(e){return function(){e(this),this.name="EmptyError",this.message="no elements in sequence"}});function qc(e,t){return new Promise(function(n,r){var s=!1,o;e.subscribe({next:function(i){o=i,s=!0},error:r,complete:function(){s?n(o):r(new Vs)}})})}function at(e,t){return new Promise(function(n,r){var s=new qt({next:function(o){n(o),s.unsubscribe()},error:r,complete:function(){r(new Vs)}});e.subscribe(s)})}function Kc(e){return e instanceof Date&&!isNaN(e)}function x(e,t){return J(function(n,r){var s=0;n.subscribe(G(r,function(o){r.next(e.call(t,o,s++))}))})}var Xc=Array.isArray;function Gc(e,t){return Xc(t)?e.apply(void 0,Me([],He(t))):e(t)}function Ps(e){return x(function(t){return Gc(e,t)})}var Yc=Array.isArray,Qc=Object.getPrototypeOf,Jc=Object.prototype,Zc=Object.keys;function el(e){if(e.length===1){var t=e[0];if(Yc(t))return{args:t,keys:null};if(tl(t)){var n=Zc(t);return{args:n.map(function(r){return t[r]}),keys:n}}}return{args:e,keys:null}}function tl(e){return e&&typeof e=="object"&&Qc(e)===Jc}function nl(e,t){return e.reduce(function(n,r,s){return n[r]=t[s],n},{})}function oe(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=rn(e),r=ur(e),s=el(e),o=s.args,i=s.keys;if(o.length===0)return vt([],n);var a=new D(Fs(o,n,i?function(l){return nl(i,l)}:je));return r?a.pipe(Ps(r)):a}function Fs(e,t,n){return n===void 0&&(n=je),function(r){Ws(t,function(){for(var s=e.length,o=new Array(s),i=s,a=s,l=function(u){Ws(t,function(){var h=vt(e[u],t),p=!1;h.subscribe(G(r,function(f){o[u]=f,p||(p=!0,a--),a||r.next(n(o.slice()))},function(){--i||r.complete()}))},r)},c=0;c<s;c++)l(c)},r)}}function Ws(e,t,n){e?ft(n,e,t):t()}function rl(e,t,n,r,s,o,i,a){var l=[],c=0,u=0,h=!1,p=function(){h&&!l.length&&!c&&t.complete()},f=function(v){return c<r?d(v):l.push(v)},d=function(v){c++;var b=!1;de(n(v,u++)).subscribe(G(t,function(y){t.next(y)},function(){b=!0},void 0,function(){if(b)try{c--;for(var y=function(){var m=l.shift();i||d(m)};l.length&&c<r;)y();p()}catch(m){t.error(m)}}))};return e.subscribe(G(t,f,function(){h=!0,p()})),function(){}}function U(e,t,n){return n===void 0&&(n=1/0),Q(t)?U(function(r,s){return x(function(o,i){return t(r,o,s,i)})(de(e(r,s)))},n):(typeof t=="number"&&(n=t),J(function(r,s){return rl(r,s,e,n)}))}function En(e){return e===void 0&&(e=1/0),U(je,e)}function sl(){return En(1)}function ct(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return sl()(vt(e,rn(e)))}function Kt(e){return new D(function(t){de(e()).subscribe(t)})}function kn(e,t,n){return e===void 0&&(e=0),n===void 0&&(n=Cc),new D(function(r){var s=Kc(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 Ve(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=rn(e),r=Rc(e,1/0),s=e;return s.length?s.length===1?de(s[0]):En(r)(vt(s,n)):Ne}var ol=new D(ke),il=Array.isArray;function qs(e){return e.length===1&&il(e[0])?e[0]:e}function ge(e,t){return J(function(n,r){var s=0;n.subscribe(G(r,function(o){return e.call(t,o,s++)&&r.next(o)}))})}function al(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e=qs(e),e.length===1?de(e[0]):new D(cl(e))}function cl(e){return function(t){for(var n=[],r=function(o){n.push(de(e[o]).subscribe(G(t,function(i){if(n){for(var a=0;a<n.length;a++)a!==o&&n[a].unsubscribe();n=null}t.next(i)})))},s=0;n&&!t.closed&&s<e.length;s++)r(s)}}function ie(e){return J(function(t,n){var r=null,s=!1,o;r=t.subscribe(G(n,void 0,void 0,function(i){o=de(e(i,ie(e)(t))),r?(r.unsubscribe(),r=null,o.subscribe(n)):s=!0})),s&&(r.unsubscribe(),r=null,o.subscribe(n))})}function ll(e,t,n,r,s){return function(o,i){var a=n,l=t,c=0;o.subscribe(G(i,function(u){var h=c++;l=a?e(l,u,h):(a=!0,u),i.next(l)},s))}}function Ks(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=ur(e);return n?Es(Ks.apply(void 0,Me([],He(e))),Ps(n)):J(function(r,s){Fs(Me([r],He(qs(e))))(s)})}function ul(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Ks.apply(void 0,Me([],He(e)))}function Xs(e,t){return Q(t)?U(e,t,1):U(e,1)}function Gs(e,t){return t===void 0&&(t=As),J(function(n,r){var s=null,o=null,i=null,a=function(){if(s){s.unsubscribe(),s=null;var c=o;o=null,r.next(c)}};function l(){var c=i+e,u=t.now();if(u<c){s=this.schedule(void 0,c-u),r.add(s);return}a()}n.subscribe(G(r,function(c){o=c,i=t.now(),s||(s=t.schedule(l,e),r.add(s))},function(){a(),r.complete()},void 0,function(){o=s=null}))})}function Z(e){return e<=0?function(){return Ne}:J(function(t,n){var r=0;t.subscribe(G(n,function(s){++r<=e&&(n.next(s),e<=r&&n.complete())}))})}function xn(){return J(function(e,t){e.subscribe(G(t,ke))})}function dl(e,t){return J(function(n,r){var s=new Set;n.subscribe(G(r,function(o){var i=e?e(o):o;s.has(i)||(s.add(i),r.next(o))})),t&&de(t).subscribe(G(r,function(){return s.clear()},ke))})}function he(e,t){return t===void 0&&(t=je),e=e??hl,J(function(n,r){var s,o=!0;n.subscribe(G(r,function(i){var a=t(i);(o||!e(s,a))&&(o=!1,s=a,r.next(i))}))})}function hl(e,t){return e===t}function Ys(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(n){return ct(n,W.apply(void 0,Me([],He(e))))}}function pl(e,t){return J(function(n,r){var s=0,o=null,i=!1;n.subscribe(G(r,function(a){o||(o=G(r,void 0,function(){o=null,i&&r.complete()}),de(e(a,s++)).subscribe(o))},function(){i=!0,!o&&r.complete()}))})}function dr(e){return J(function(t,n){try{t.subscribe(n)}finally{n.add(e)}})}function Qs(){return J(function(e,t){var n,r=!1;e.subscribe(G(t,function(s){var o=n;n=s,r&&t.next([o,s]),r=!0}))})}function sn(e,t){return J(ll(e,t,arguments.length>=2,!0))}function bt(e){e===void 0&&(e={});var t=e.connector,n=t===void 0?function(){return new ve}:t,r=e.resetOnError,s=r===void 0?!0:r,o=e.resetOnComplete,i=o===void 0?!0:o,a=e.resetOnRefCountZero,l=a===void 0?!0:a;return function(c){var u,h,p,f=0,d=!1,v=!1,b=function(){h?.unsubscribe(),h=void 0},y=function(){b(),u=p=void 0,d=v=!1},m=function(){var g=u;y(),g?.unsubscribe()};return J(function(g,w){f++,!v&&!d&&b();var E=p=p??n();w.add(function(){f--,f===0&&!v&&!d&&(h=hr(m,l))}),E.subscribe(w),!u&&f>0&&(u=new qt({next:function($){return E.next($)},error:function($){v=!0,b(),h=hr(y,s,$),E.error($)},complete:function(){d=!0,b(),h=hr(y,i),E.complete()}}),de(g).subscribe(u))})(c)}}function hr(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 qt({next:function(){s.unsubscribe(),e()}});return de(t.apply(void 0,Me([],He(n)))).subscribe(s)}}function on(e,t,n){var r,s,o,i,a=!1;return e&&typeof e=="object"?(r=e.bufferSize,i=r===void 0?1/0:r,s=e.windowTime,t=s===void 0?1/0:s,o=e.refCount,a=o===void 0?!1:o,n=e.scheduler):i=e??1/0,bt({connector:function(){return new nn(i,t,n)},resetOnError:!0,resetOnComplete:!1,resetOnRefCountZero:a})}function Sn(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=rn(e);return J(function(r,s){(n?ct(e,r,n):ct(e,r)).subscribe(s)})}function mt(e,t){return J(function(n,r){var s=null,o=0,i=!1,a=function(){return i&&!s&&r.complete()};n.subscribe(G(r,function(l){s?.unsubscribe();var c=0,u=o++;de(e(l,u)).subscribe(s=G(r,function(h){return r.next(t?t(l,h,u,c++):h)},function(){s=null,a()}))},function(){i=!0,a()}))})}function fl(){return mt(je)}function Bn(e){return J(function(t,n){de(e).subscribe(G(n,function(){return n.complete()},ke)),!n.closed&&t.subscribe(n)})}function Ht(e,t){return t===void 0&&(t=!1),J(function(n,r){var s=0;n.subscribe(G(r,function(o){var i=e(o,s++);(i||t)&&r.next(o),!i&&r.complete()}))})}function Xt(e,t,n){var r=Q(e)||t||n?{next:e,error:t,complete:n}:e;return r?J(function(s,o){var i;(i=r.subscribe)===null||i===void 0||i.call(r);var a=!0;s.subscribe(G(o,function(l){var c;(c=r.next)===null||c===void 0||c.call(r,l),o.next(l)},function(){var l;a=!1,(l=r.complete)===null||l===void 0||l.call(r),o.complete()},function(l){var c;a=!1,(c=r.error)===null||c===void 0||c.call(r,l),o.error(l)},function(){var l,c;a&&((l=r.unsubscribe)===null||l===void 0||l.call(r)),(c=r.finalize)===null||c===void 0||c.call(r)}))}):je}function pr(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=ur(e);return J(function(r,s){for(var o=e.length,i=new Array(o),a=e.map(function(){return!1}),l=!1,c=function(h){de(e[h]).subscribe(G(s,function(p){i[h]=p,!l&&!a[h]&&(a[h]=!0,(l=a.every(je))&&(a=null))},ke))},u=0;u<o;u++)c(u);r.subscribe(G(s,function(h){if(l){var p=Me([h],He(i));s.next(n?n.apply(void 0,Me([],He(p))):p)}}))})}const Js="0123456789abcdef";function Y(e){const t=new Array(e.length+1);t[0]="0x";for(let n=0;n<e.length;){const r=e[n++];t[n]=Js[r>>4]+Js[r&15]}return t.join("")}const fr={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 te(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|fr[e[2]]);for(let o=0;o<r;){const i=n+o*2,a=fr[e[i]],l=fr[e[i+1]];s[t+o++]=a<<4|l}return s}function yt(e,t){return Object.fromEntries(Object.entries(e).map(([n,r])=>[n,t(r,n)]))}const ae=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},V=Function.prototype;let Zs=class extends Error{constructor(){super("Abort Error"),this.name="AbortError"}};var vl=Object.defineProperty,bl=(e,t,n)=>t in e?vl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,eo=(e,t,n)=>bl(e,typeof t!="symbol"?t+"":t,n);let to=class extends Error{constructor(t){super(t.message),eo(this,"code"),eo(this,"data"),this.code=t.code,this.data=t.data,this.name="RpcError"}};const no=e=>!("method"in e),ro=()=>{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 vr=class extends Error{constructor(){super("Client destroyed"),this.name="DestroyedError"}},ml=1;const br=(e,t)=>{let n=ml++;const r=new Map,s=ro();let o=null;const i=(u,h,p)=>{o.send({jsonrpc:"2.0",id:u,method:h,params:p})};function a(u){if(no(u)){const{id:h}=u,p=r.get(h);return p?(r.delete(h),"error"in u?p.onError(new to(u.error)):p.onSuccess(u.result,(f,d)=>{const v=f;return s.subscribe(v,d),()=>{s.unsubscribe(v)}})):void 0}if(u.id===void 0){const{params:h}=u,{subscription:p,result:f,error:d}=h;p&&s.has(p)&&("result"in h||d)?d?s.error(p,new to(d)):s.next(p,f):t?.(u)}else console.warn("Error parsing incomming message: "+JSON.stringify(u))}o=e(a);const l=()=>{o?.disconnect(),o=null,s.errorAll(new vr),r.forEach(u=>u.onError(new vr)),r.clear()};let c=1;return{request:(u,h,p)=>{if(!o)throw new Error("Not connected");const f=`${n}-${c++}`;return p&&r.set(f,p),i(f,u,h),()=>{r.delete(f)}},disconnect:l}};var yl=Object.defineProperty,gl=(e,t,n)=>t in e?yl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,an=(e,t,n)=>gl(e,t+"",n);const so=class oc extends Error{constructor(){super("ChainHead stopped"),this.name=oc.errorName}};an(so,"errorName","StopError");let oo=so;const io=class ic extends Error{constructor(){super("ChainHead disjointed"),this.name=ic.errorName}};an(io,"errorName","DisjointError");let In=io;const ao=class ac extends Error{constructor(){super("ChainHead operations limit reached"),this.name=ac.errorName}};an(ao,"errorName","OperationLimitError");let An=ao;const co=class cc extends Error{constructor(t){super(t),this.name=cc.errorName}};an(co,"errorName","OperationError");let lo=co;const uo=class lc extends Error{constructor(){super("ChainHead operation inaccessible"),this.name=lc.errorName}};an(uo,"errorName","OperationInaccessibleError");let On=uo;const Ue={body:"",call:"",continue:"",follow:"",header:"",stopOperation:"",storage:"",unfollow:"",unpin:"",followEvent:""},Cn={chainName:"",genesisHash:"",properties:""},mr={broadcast:"",stop:""};Object.entries({chainHead:Ue,chainSpec:Cn,transaction:mr}).forEach(([e,t])=>{Object.keys(t).forEach(n=>{t[n]=`${e}_v1_${n}`})});var wl=Object.defineProperty,$l=(e,t,n)=>t in e?wl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yr=(e,t,n)=>$l(e,t+"",n);const ho=class uc extends Error{constructor(t){super(`Invalid BlockHash: ${t}`),this.name=uc.errorName}};yr(ho,"errorName","BlockHashNotFoundError");let po=ho;const fo=class dc extends Error{constructor(t){super(`Storage Error: ${t}`),this.name=dc.errorName}};yr(fo,"errorName","StorageError");let El=fo;const vo=class hc extends Error{constructor(t){super(`Call Error: ${t}`),this.name=hc.errorName}};yr(vo,"errorName","CallError");let kl=vo;const Gt=()=>{},xl=e=>(t,n)=>{let r=!1,s=()=>{r=!0};return e(mr.broadcast,[t],{onSuccess:o=>{o!==null?(s=()=>{e(mr.stop,[o]),s=Gt},r&&s()):r||n(new Error("Max # of broadcasted transactions has been reached"))},onError:n}),()=>{s()}};function Sl(){let e=()=>{},t=()=>{};return{promise:new Promise((n,r)=>{e=n,t=r}),res:e,rej:t}}const Yt=e=>(...t)=>new Promise((n,r)=>{let s=V;const[o,i]=t[t.length-1]instanceof AbortSignal?[t.slice(0,t.length-1),t[t.length-1]]:[t],a=()=>{s(),r(new Zs)};i?.addEventListener("abort",a,{once:!0});const l=c=>u=>{s=V,i?.removeEventListener("abort",a),c(u)};s=e(l(n),l(r),...o)}),bo=(e,t)=>n=>Yt((r,s,...o)=>{let i=!0,a=()=>{i=!1};const[l,c]=t(...o);return n(e,l,{onSuccess:(u,h)=>{if(u.result==="limitReached")return s(new An);const{operationId:p}=u,f=()=>{n(Ue.stopOperation,[p])};if(!i)return f();let d=Gt;const v=y=>{i=!1,d(),r(y)},b=y=>{i=!1,d(),s(y)};d=h(p,{next:y=>{const m=y;m.event==="operationError"?s(new lo(m.error)):m.event==="operationInaccessible"?s(new On):c(y,v,b)},error:b}),a=()=>{i&&(d(),f())}},onError:s}),()=>{a()}}),Bl=bo(Ue.body,e=>[[e],(t,n)=>{n(t.value)}]),Il=bo(Ue.call,(e,t,n)=>[[e,t,n],(r,s)=>{s(r.output)}]),Al=e=>t=>new Promise((n,r)=>{e(Ue.header,[t],{onSuccess:n,onError:r})}),mo=e=>(t,n,r,s,o,i,a)=>{if(n.length===0)return i(),V;let l=!0,c=()=>{l=!1};return e(Ue.storage,[t,n,r],{onSuccess:(u,h)=>{if(u.result==="limitReached"||u.discardedItems===n.length)return o(new An);const{operationId:p}=u,f=()=>{e(Ue.stopOperation,[p])};if(!l)return f();const d=h(u.operationId,{next:y=>{switch(y.event){case"operationStorageItems":{s(y.items);break}case"operationStorageDone":{b();break}case"operationError":{v(new lo(y.error));break}case"operationInaccessible":{v(new On);break}default:e(Ue.continue,[y.operationId])}},error:o});c=()=>{d(),e(Ue.stopOperation,[u.operationId])};const v=y=>{c=V,d(),o(y)},b=()=>{c=V,d(),i()};a(u.discardedItems)},onError:o}),()=>{c()}},Ol=e=>{const t=mo(e);return Yt((n,r,s,o,i,a)=>{const l=o.startsWith("descendants");let c=l?[]:null;const u=t(s,[{key:i,type:o}],a??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 An))});return u})},Cl=e=>t=>t.length>0?new Promise((n,r)=>{e(Ue.unpin,[t],{onSuccess(){n()},onError:r})}):Promise.resolve();function _l(e){return e.operationId!==void 0}function Rl(e){return(t,n,r)=>{const s=ro(),o=new Set,i=Sl();let a=i.promise,l=Gt;const c=d=>{e(Ue.unfollow,[d])},u=d=>{l(),a!==null&&(d&&(a instanceof Promise?a.then(v=>{typeof v=="string"&&c(v)}):c(a)),a=null,o.forEach(v=>{v()}),o.clear(),s.errorAll(new In))},h=d=>{if(_l(d))return s.next(d.operationId,d);switch(d.event){case"stop":return r(new oo),u(!1);case"initialized":case"newBlock":case"bestBlockChanged":case"finalized":const{event:v,...b}=d;return n({type:v,...b})}},p=d=>{r(d),u(!(d instanceof vr))};e(Ue.follow,[t],{onSuccess:(d,v)=>{a instanceof Promise&&(a=d,l=v(d,{next:h,error:p})),i.res(d)},onError:d=>{a=null,i.res(d),r(d)}});const f=(d,v,b)=>{const y=()=>{b?.onError(new In)};if(a===null)return y(),Gt;const m=w=>{if(!b)return e(d,[w,...v]);o.add(y);const E=(k,S)=>a===null?(S.error(new In),Gt):(s.subscribe(k,S),()=>{s.unsubscribe(k)}),$=e(d,[w,...v],{onSuccess:k=>{o.delete(y),b.onSuccess(k,E)},onError:k=>{o.delete(y),b.onError(k)}});return()=>{o.delete(y),$()}};if(typeof a=="string")return m(a);let g=Gt;return a.then(w=>{if(w instanceof Error)return y();a&&(g=m(w))}),()=>{g()}};return{unfollow(){u(!0)},body:Bl(f),call:Il(f),header:Al(f),storage:Ol(f),storageSubscription:mo(f),unpin:Cl(f),_request:f}}}const Tl=e=>{const t=Yt((r,s,o,i)=>e(o,i,{onSuccess:r,onError:s}));let n=null;return async()=>n||(n=Promise.all([t(Cn.chainName,[]),t(Cn.genesisHash,[]),t(Cn.properties,[])]).then(([r,s,o])=>({name:r,genesisHash:s,properties:o})))},Hl=e=>(t,n,r,s,o,i)=>{if(n.length===0)return i(),V;let a=!0,l=()=>{a=!1};return e("storage",[t,n,r],{onSuccess:(c,u)=>{const h=()=>{e("stopStorage",[c])};if(!a)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"?v():d(new El(b.error))},error:o}),f=()=>{l=V,p()};l=()=>{f(),h()};const d=b=>{f(),o(b)},v=()=>{f(),i()}},onError:o}),()=>{l()}},Ml=e=>Yt((t,n,r,s,o,i)=>{const a=s.startsWith("descendants");let l=a?[]:null;const c=a?l.push.bind(l):({[s]:u})=>{l=u};return e(r,[{key:o,type:s}],i,c,u=>{n(u),l=null},()=>{t(l),l=null})}),yo=()=>e=>e,go=()=>(e,t)=>{if(e===null)throw new po(t);return e},Ul=e=>{const t=(u,...h)=>e(`archive_v1_${u}`,...h),n=u=>h=>Yt((p,f,...d)=>t(u,d,{onSuccess:v=>{try{p(h(v,...d))}catch(b){f(b)}},onError:f})),r=n("header")(go()),s=n("body")(go()),o=Hl(t),i=Ml(o),a=n("call")((u,h)=>{if(!u)throw new po(h);if(!u.success)throw new kl(u.error);return u.value}),l=n("finalizedHeight")(yo()),c=n("hashByHeight")(yo());return{header:r,body:s,storageSubscription:o,storage:i,call:a,finalizedHeight:l,hashByHeight:c}},zl=e=>{const{request:t,disconnect:n}=br(e);return{archive:Ul(t),chainHead:Rl(t),transaction:xl(t),getChainSpecData:Tl(t),destroy:n,request:Yt((r,s,o,i)=>t(o,i,{onSuccess:r,onError:s})),_request:t}};var Dl=Object.defineProperty,Ll=(e,t,n)=>t in e?Dl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wo=(e,t,n)=>Ll(e,typeof t!="symbol"?t+"":t,n);let jl=class{constructor(){wo(this,"first"),wo(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 Nl=()=>{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),i=(h,p)=>{const f=p?s:o;t(h.source$,f(h))},a=()=>{const h=r.pop();h&&(e.delete(h.source$),l(h))},l=h=>{const{source$:p,observer:f}=h;let d=!1;const v=p.subscribe({next(b){f.next(b)},error(b){(d=b instanceof Error&&b.name===An.errorName)?i(h,!0):f.error(b)},complete(){f.complete()}});v.closed?d||a():t(p,()=>{v.unsubscribe(),a()})},c=(h=!1)=>p=>new D(f=>{const d={observer:f,source$:p};return r.isEmpty()?l(d):i(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 gr=e=>{const t=e.pipe(ie(n=>n instanceof Error&&n.name===On.errorName?kn(750).pipe(Xs(()=>t)):Tt(()=>n)));return t},Vl=new Set(["best","finalized",null]),Pl=(e,t,n)=>r=>(s,...o)=>{if(!Vl.has(s))return gr(r(s,...o)).pipe(n(s));const i=(s==="best"?t:e).pipe(Z(1),U(a=>r(a,...o).pipe(n(a))),ie(a=>a instanceof Je?i:Tt(()=>a)));return gr(i)},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}}),Fl=e=>t=>(...n)=>e()[t](...n);var be=(e=>(e[e.Initializing=0]="Initializing",e[e.Ready=1]="Ready",e[e.RecoveringInit=2]="RecoveringInit",e[e.RecoveringFin=3]="RecoveringFin",e))(be||{});function _n(e,t,n){return(r,...s)=>{let o;const i=()=>new Je(r,n),a=t(r,...s).pipe(x(c=>({type:"val",value:c})),Ys({type:"end"})),l=e.pipe(Ht(c=>!c.blocks.has(r)),x(c=>{if(c.blocks.get(c.finalized).number>=o.number)throw i()}),xn());return e.pipe(x(c=>c.state.type===be.Ready),he(),mt(c=>c?(o||(o=e.state.blocks.get(r)),o?ct(l,a):Tt(i)):ol),Ht(c=>c.type==="val"),x(c=>c.value))}}const Wl=(e,t)=>{const n=(r,s,o,i)=>new D(a=>e().storageSubscription(r,s,o??null,l=>{a.next(l)},l=>{a.error(l)},()=>{a.complete()},l=>{l>0&&a.next(n(r,s.slice(-l),o,!0))})).pipe(En(),t(i));return n};var ql=Object.defineProperty,Kl=(e,t,n)=>t in e?ql(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,$o=(e,t,n)=>(Kl(e,typeof t!="symbol"?t+"":t,n),n),wr={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 Xl(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|wr[e[2]]);for(let o=0;o<r;){const i=n+o*2,a=wr[e[i]],l=wr[e[i+1]];s[t+o++]=a<<4|l}return s}var Eo=class extends Uint8Array{constructor(e){super(e),$o(this,"i",0),$o(this,"v"),this.v=new DataView(e)}},ze=e=>t=>e(t instanceof Eo?t:new Eo(t instanceof Uint8Array?t.buffer:typeof t=="string"?Xl(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 i=e[s];r.set(i,o),o+=i.byteLength}return r};function Rn(e,t){const n=Object.keys(e),r=n.length,s={};for(let o=0;o<r;o++){const i=n[o];s[i]=t(e[i],i)}return s}var lt=ze,X=(e,t)=>{const n=[e,t];return n.enc=e,n.dec=t,n},Tn=(e,t)=>n=>e(t(n)),Hn=(e,t)=>n=>t(e(n)),Pe=([e,t],n,r)=>X(Tn(e,n),Hn(t,r));function Gl(e,t){return ze(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 gt(e,t,n){return X(Yl(e,n),Gl(e,t))}var P=gt(1,"getUint8","setUint8"),et=gt(2,"getUint16","setUint16"),Fe=gt(4,"getUint32","setUint32"),cn=gt(8,"getBigUint64","setBigUint64"),Ql=gt(1,"getInt8","setInt8"),Jl=gt(2,"getInt16","setInt16"),Zl=gt(4,"getInt32","setInt32"),eu=gt(8,"getBigInt64","setBigInt64"),ko=e=>{const t=new Uint8Array(16),n=new DataView(t.buffer);return n.setBigInt64(0,e,!0),n.setBigInt64(8,e>>64n,!0),t},xo=e=>ze(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}),So=X(ko,xo("getBigUint64")),tu=X(ko,xo("getBigInt64")),Bo=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},Io=e=>ze(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}),nu=X(Bo,Io("getBigUint64")),ru=X(Bo,Io("getBigInt64")),su=Pe(P,e=>e?1:0,Boolean),ou=[P[1],et[1],Fe[1]],iu=ze(e=>{const t=e[e.i],n=t&3;if(n<3)return ou[n](e)>>>2;const r=(t>>>2)+4;e.i++;let s=0n;const o=r/8|0;let i=0n;for(let l=0;l<o;l++)s=cn[1](e)<<i|s,i+=64n;let a=r%8;return a>3&&(s=BigInt(Fe[1](e))<<i|s,i+=32n,a-=4),a>1&&(s=BigInt(et[1](e))<<i|s,i+=16n,a-=2),a&&(s=BigInt(P[1](e))<<i|s),s}),au=1n<<56n,cu=1<<24,lu=256,uu=4294967295n,du=64,hu=16384,pu=1<<30,fu=e=>{if(e<0)throw new Error(`Wrong compact input (${e})`);const t=Number(e)<<2;if(e<du)return P[0](t);if(e<hu)return et[0](t|1);if(e<pu)return Fe[0](t|2);let n=[new Uint8Array(1)],r=BigInt(e);for(;r>=au;)n.push(cn[0](r)),r>>=64n;r>=cu&&(n.push(Fe[0](Number(r&uu))),r>>=32n);let s=Number(r);s>=lu&&(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=X(fu,iu),vu=new TextEncoder,bu=e=>{const t=vu.encode(e);return Ze([pe.enc(t.length),t])},mu=new TextDecoder,yu=ze(e=>{let t=pe.dec(e);const n=new DataView(e.buffer,e.i,t);return e.i+=t,mu.decode(n)}),q=X(bu,yu),gu=()=>{},wu=new Uint8Array(0),M=X(()=>wu,gu),Ao=e=>e===void 0?t=>Ze([pe.enc(t.length),t]):t=>t.length===e?t:t.slice(0,e),Oo=e=>ze(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=>X(Ao(e),Oo(e));ne.enc=Ao,ne.dec=Oo;var Co=(e,t)=>{const n=Object.keys(e),r=new Map(t?.map((o,i)=>[n[i],o])??n.map((o,i)=>[o,i])),s=o=>r.get(o);return({tag:o,value:i})=>Ze([P.enc(s(o)),e[o](i)])},_o=(e,t)=>{const n=Object.keys(e),r=new Map(t?.map((s,o)=>[s,n[o]])??n.map((s,o)=>[o,s]));return ze(s=>{const o=P.dec(s),i=r.get(o),a=e[i];return{tag:i,value:a(s)}})},xe=(e,...t)=>X(Co(Rn(e,([n])=>n),...t),_o(Rn(e,([,n])=>n),...t));xe.enc=Co,xe.dec=_o;var Ro=e=>ze(t=>P[1](t)>0?e(t):void 0),To=e=>t=>{const n=new Uint8Array(1);return t===void 0?n:(n[0]=1,Ze([n,e(t)]))},Se=e=>X(To(e[0]),Ro(e[1]));Se.enc=To,Se.dec=Ro;var Ho=(e,t)=>ze(n=>{const r=P[1](n)===0,o=(r?e:t)(n);return{success:r,value:o}}),Mo=(e,t)=>({success:n,value:r})=>Ze([P[0](n?0:1),(n?e:t)(r)]),ln=(e,t)=>X(Mo(e[0],t[0]),Ho(e[1],t[1]));ln.dec=Ho,ln.enc=Mo;var Uo=(...e)=>ze(t=>e.map(n=>n(t))),zo=(...e)=>t=>Ze(e.map((n,r)=>n(t[r]))),De=(...e)=>X(zo(...e.map(([t])=>t)),Uo(...e.map(([,t])=>t)));De.enc=zo,De.dec=Uo;var Do=e=>{const t=Object.keys(e);return Tn(De.enc(...Object.values(e)),n=>t.map(r=>n[r]))},Lo=e=>{const t=Object.keys(e);return Hn(De.dec(...Object.values(e)),n=>Object.fromEntries(n.map((r,s)=>[t[s],r])))},z=e=>X(Do(Rn(e,t=>t[0])),Lo(Rn(e,t=>t[1])));z.enc=Do,z.dec=Lo;var jo=(e,t)=>t>=0?n=>Ze(n.map(e)):n=>Ze([pe.enc(n.length),Ze(n.map(e))]),No=(e,t)=>ze(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}),L=(e,t)=>X(jo(e[0],t),No(e[1],t));L.enc=jo,L.dec=No;/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function $u(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function Vo(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 $r(e,t){if(typeof t!="string")throw new TypeError(`${e}: string expected`);return!0}function Po(e){if(typeof e!="number")throw new TypeError(`number expected, got ${typeof e}`);if(!Number.isSafeInteger(e))throw new RangeError(`invalid integer: ${e}`)}function Er(e){if(!Array.isArray(e))throw new TypeError("array expected")}function Fo(e,t){if(!Vo(!0,t))throw new TypeError(`${e}: array of strings expected`)}function Eu(e,t){if(!Vo(!1,t))throw new TypeError(`${e}: array of numbers expected`)}function ku(...e){const t=o=>o,n=(o,i)=>a=>o(i(a)),r=e.map(o=>o.encode).reduceRight(n,t),s=e.map(o=>o.decode).reduce(n,t);return{encode:r,decode:s}}function xu(e){const t=typeof e=="string"?e.split(""):e,n=t.length;Fo("alphabet",t);const r=new Map(t.map((s,o)=>[s,o]));return{encode:s=>(Er(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=>(Er(s),s.map(o=>{$r("alphabet.decode",o);const i=r.get(o);if(i===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${e}`);return i}))}}function Su(e=""){return $r("join",e),{encode:t=>(Fo("join.decode",t),t.join(e)),decode:t=>($r("join.decode",t),t.split(e))}}function Wo(e,t,n){if(t<2)throw new RangeError(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw new RangeError(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(Er(e),!e.length)return[];let r=0;const s=[],o=Array.from(e,a=>{if(Po(a),a<0||a>=t)throw new Error(`invalid integer: ${a}`);return a}),i=o.length;for(;;){let a=0,l=!0;for(let c=r;c<i;c++){const u=o[c],h=t*a,p=h+u;if(!Number.isSafeInteger(p)||h/t!==a||p-u!==h)throw new Error("convertRadix: carry overflow");const f=p/n;a=p%n;const d=Math.floor(f);if(o[c]=d,!Number.isSafeInteger(d)||d*n+a!==p)throw new Error("convertRadix: carry overflow");if(l)d?l=!1:r=c;else continue}if(s.push(a),l)break}for(let a=0;a<e.length-1&&e[a]===0;a++)s.push(0);return s.reverse()}function Bu(e){Po(e);const t=2**8;return{encode:n=>{if(!$u(n))throw new TypeError("radix.encode input should be Uint8Array");return Wo(Array.from(n),t,e)},decode:n=>(Eu("radix.decode",n),Uint8Array.from(Wo(n,e,t)))}}const qo=Object.freeze((e=>ku(Bu(58),xu(e),Su("")))("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"));function Iu(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function Ut(e,t=""){if(typeof e!="number"){const n=t&&`"${t}" `;throw new TypeError(`${n}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){const n=t&&`"${t}" `;throw new RangeError(`${n}expected integer >= 0, got ${e}`)}}function Ae(e,t,n=""){const r=Iu(e),s=e?.length,o=t!==void 0;if(!r||o&&s!==t){const i=n&&`"${n}" `,a=o?` of length ${t}`:"",l=r?`length=${s}`:`type=${typeof e}`,c=i+"expected Uint8Array"+a+", got "+l;throw r?new RangeError(c):new TypeError(c)}return e}function Au(e){return Uint8Array.from(Ae(e))}function un(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 kr(e,t){Ae(e,void 0,"digestInto() output");const n=t.outputLen;if(e.length<n)throw new RangeError('"digestInto() output" expected to be of length >='+n)}function Ou(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function zt(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function wt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Mn(e,t){return e<<32-t|e>>>t}const Ko=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Xo(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const ut=Ko?e=>e:e=>Xo(e)>>>0;function Cu(e){for(let t=0;t<e.length;t++)e[t]=Xo(e[t]);return e}const we=Ko?e=>e:Cu;function xr(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.canXOF=r.canXOF,n.create=s=>e(s),Object.assign(n,t),Object.freeze(n)}const _u=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 $t(e,t,n,r,s){return e=e+t+s|0,r=Mn(r^e,16),n=n+r|0,t=Mn(t^n,12),{a:e,b:t,c:n,d:r}}function Et(e,t,n,r,s){return e=e+t+s|0,r=Mn(r^e,8),n=n+r|0,t=Mn(t^n,7),{a:e,b:t,c:n,d:r}}const Ru=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Un=BigInt(2**32-1),Go=BigInt(32);function zn(e,t=!1){return t?{h:Number(e&Un),l:Number(e>>Go&Un)}:{h:Number(e>>Go&Un)|0,l:Number(e&Un)|0}}function Tu(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:i,l:a}=zn(e[o],t);[r[o],s[o]]=[i,a]}return[r,s]}const Yo=(e,t,n)=>e>>>n|t<<32-n,Qo=(e,t,n)=>e<<32-n|t>>>n,Hu=(e,t,n)=>e<<64-n|t>>>n-32,Mu=(e,t,n)=>e>>>n-32|t<<64-n,Uu=(e,t)=>t,zu=(e,t)=>e,Du=(e,t,n)=>e<<n|t>>>32-n,Lu=(e,t,n)=>t<<n|e>>>32-n,ju=(e,t,n)=>t<<n-32|e>>>64-n,Nu=(e,t,n)=>e<<n-32|t>>>64-n;function Jo(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const Zo=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),ei=(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 kt(e,t,n,r,s,o){const i=s[o],a=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],f=O[2*n+1],d=O[2*r],v=O[2*r+1],b=Zo(l,u,i);c=ei(b,c,h,a),l=b|0,{Dh:v,Dl:d}={Dh:v^c,Dl:d^l},{Dh:v,Dl:d}={Dh:Uu(v,d),Dl:zu(v)},{h:f,l:p}=Jo(f,p,v,d),{Bh:h,Bl:u}={Bh:h^f,Bl:u^p},{Bh:h,Bl:u}={Bh:Yo(h,u,24),Bl:Qo(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]=f,O[2*r]=d,O[2*r+1]=v}function xt(e,t,n,r,s,o){const i=s[o],a=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],f=O[2*n+1],d=O[2*r],v=O[2*r+1],b=Zo(l,u,i);c=ei(b,c,h,a),l=b|0,{Dh:v,Dl:d}={Dh:v^c,Dl:d^l},{Dh:v,Dl:d}={Dh:Yo(v,d,16),Dl:Qo(v,d,16)},{h:f,l:p}=Jo(f,p,v,d),{Bh:h,Bl:u}={Bh:h^f,Bl:u^p},{Bh:h,Bl:u}={Bh:Hu(h,u,63),Bl:Mu(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]=f,O[2*r]=d,O[2*r+1]=v}function Vu(e,t={},n,r,s){if(Ut(n),e<=0||e>n)throw new Error("outputLen bigger than keyLen");const{key:o,salt:i,personalization:a}=t;if(o!==void 0&&(o.length<1||o.length>n))throw new Error('"key" expected to be undefined or of length=1..'+n);i!==void 0&&Ae(i,r,"salt"),a!==void 0&&Ae(a,s,"personalization")}class ti{buffer;buffer32;finished=!1;destroyed=!1;length=0;pos=0;blockLen;outputLen;canXOF=!1;constructor(t,n){Ut(t),Ut(n),this.blockLen=t,this.outputLen=n,this.buffer=new Uint8Array(t),this.buffer32=zt(this.buffer)}update(t){un(this),Ae(t);const{blockLen:n,buffer:r,buffer32:s}=this,o=t.length,i=t.byteOffset,a=t.buffer;for(let l=0;l<o;){this.pos===n&&(we(s),this.compress(s,0,!1),we(s),this.pos=0);const c=Math.min(n-this.pos,o-l),u=i+l;if(c===n&&!(u%4)&&l+c<o){const h=new Uint32Array(a,u,Math.floor((o-l)/4));we(h);for(let p=0;l+n<o;p+=s.length,l+=n)this.length+=n,this.compress(h,p,!1);we(h);continue}r.set(t.subarray(l,l+c),this.pos),this.pos+=c,this.length+=c,l+=c}return this}digestInto(t){un(this),kr(t,this);const{pos:n,buffer32:r}=this;if(this.finished=!0,wt(this.buffer.subarray(n)),we(r),this.compress(r,0,!0),we(r),t.byteOffset&3)throw new RangeError('"digestInto() output" expected 4-byte aligned byteOffset, got '+t.byteOffset);const s=this.get(),o=zt(t),i=Math.floor(this.outputLen/4);for(let u=0;u<i;u++)o[u]=ut(s[u]);const a=this.outputLen%4;if(!a)return;const l=i*4,c=s[i];for(let u=0;u<a;u++)t[l+u]=c>>>8*u}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:i,pos:a}=this;return t||=new this.constructor({dkLen:i}),t.set(...this.get()),t.buffer.set(n),t.destroyed=o,t.finished=s,t.length=r,t.pos=a,t.outputLen=i,t}clone(){return this._cloneInto()}}class Pu extends ti{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),Vu(n,t,64,16,16);let{key:r,personalization:s,salt:o}=t,i=0;if(r!==void 0&&(Ae(r,void 0,"key"),i=r.length),this.v0l^=this.outputLen|i<<8|65536|1<<24,o!==void 0){Ae(o,void 0,"salt");const a=zt(o);this.v4l^=ut(a[0]),this.v4h^=ut(a[1]),this.v5l^=ut(a[2]),this.v5h^=ut(a[3])}if(s!==void 0){Ae(s,void 0,"personalization");const a=zt(s);this.v6l^=ut(a[0]),this.v6h^=ut(a[1]),this.v7l^=ut(a[2]),this.v7h^=ut(a[3])}if(r!==void 0){const a=new Uint8Array(this.blockLen);a.set(r),this.update(a)}}get(){let{v0l:t,v0h:n,v1l:r,v1h:s,v2l:o,v2h:i,v3l:a,v3h:l,v4l:c,v4h:u,v5l:h,v5h:p,v6l:f,v6h:d,v7l:v,v7h:b}=this;return[t,n,r,s,o,i,a,l,c,u,h,p,f,d,v,b]}set(t,n,r,s,o,i,a,l,c,u,h,p,f,d,v,b){this.v0l=t|0,this.v0h=n|0,this.v1l=r|0,this.v1h=s|0,this.v2l=o|0,this.v2h=i|0,this.v3l=a|0,this.v3h=l|0,this.v4l=c|0,this.v4h=u|0,this.v5l=h|0,this.v5h=p|0,this.v6l=f|0,this.v6h=d|0,this.v7l=v|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}=zn(BigInt(this.length));O[24]=se[8]^o,O[25]=se[9]^s,r&&(O[28]=~O[28],O[29]=~O[29]);let i=0;const a=_u;for(let l=0;l<12;l++)kt(0,4,8,12,t,n+2*a[i++]),xt(0,4,8,12,t,n+2*a[i++]),kt(1,5,9,13,t,n+2*a[i++]),xt(1,5,9,13,t,n+2*a[i++]),kt(2,6,10,14,t,n+2*a[i++]),xt(2,6,10,14,t,n+2*a[i++]),kt(3,7,11,15,t,n+2*a[i++]),xt(3,7,11,15,t,n+2*a[i++]),kt(0,5,10,15,t,n+2*a[i++]),xt(0,5,10,15,t,n+2*a[i++]),kt(1,6,11,12,t,n+2*a[i++]),xt(1,6,11,12,t,n+2*a[i++]),kt(2,7,8,13,t,n+2*a[i++]),xt(2,7,8,13,t,n+2*a[i++]),kt(3,4,9,14,t,n+2*a[i++]),xt(3,4,9,14,t,n+2*a[i++]);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],wt(O)}destroy(){this.destroyed=!0,wt(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const Dn=xr(e=>new Pu(e));function ni(e,t,n,r,s,o,i,a,l,c,u,h,p,f,d,v,b,y,m,g){let w=0;for(let E=0;E<r;E++)({a:s,b:l,c:p,d:b}=$t(s,l,p,b,n[t+e[w++]])),{a:s,b:l,c:p,d:b}=Et(s,l,p,b,n[t+e[w++]]),{a:o,b:c,c:f,d:y}=$t(o,c,f,y,n[t+e[w++]]),{a:o,b:c,c:f,d:y}=Et(o,c,f,y,n[t+e[w++]]),{a:i,b:u,c:d,d:m}=$t(i,u,d,m,n[t+e[w++]]),{a:i,b:u,c:d,d:m}=Et(i,u,d,m,n[t+e[w++]]),{a,b:h,c:v,d:g}=$t(a,h,v,g,n[t+e[w++]]),{a,b:h,c:v,d:g}=Et(a,h,v,g,n[t+e[w++]]),{a:s,b:c,c:d,d:g}=$t(s,c,d,g,n[t+e[w++]]),{a:s,b:c,c:d,d:g}=Et(s,c,d,g,n[t+e[w++]]),{a:o,b:u,c:v,d:b}=$t(o,u,v,b,n[t+e[w++]]),{a:o,b:u,c:v,d:b}=Et(o,u,v,b,n[t+e[w++]]),{a:i,b:h,c:p,d:y}=$t(i,h,p,y,n[t+e[w++]]),{a:i,b:h,c:p,d:y}=Et(i,h,p,y,n[t+e[w++]]),{a,b:l,c:f,d:m}=$t(a,l,f,m,n[t+e[w++]]),{a,b:l,c:f,d:m}=Et(a,l,f,m,n[t+e[w++]]);return{v0:s,v1:o,v2:i,v3:a,v4:l,v5:c,v6:u,v7:h,v8:p,v9:f,v10:d,v11:v,v12:b,v13:y,v14:m,v15:g}}const ri=new TextEncoder().encode("SS58PRE"),Sr=2,si=e=>{try{const t=qo.decode(e),n=t.subarray(0,t[0]&64?2:1),r=t.subarray(n.length,t.length-Sr),s=t.subarray(n.length+r.length),o=Dn(Uint8Array.of(...ri,...n,...r),{dkLen:64}).subarray(0,Sr);return s[0]===o[0]&&s[1]===o[1]?{isValid:!0,ss58Format:Fu(n),publicKey:r.slice()}:{isValid:!1}}catch{return{isValid:!1}}},Fu=e=>{const t=new DataView(e.buffer,e.byteOffset,e.byteLength);return t.byteLength===1?t.getUint8(0):t.getUint16(0)},Wu=e=>{let t=0n;const n=new DataView(e.buffer),r=Math.floor(e.length/8);for(let s=0;s<r;s++)t=t<<64n|n.getBigUint64(s*8);for(let s=r*8;s<e.length;s++)t=t<<8n|BigInt(n.getUint8(s));return t},qu=e=>{let t=new Map,n=0,r=0;const s=()=>{n===r?(t.clear(),n=r=0):(r=n,setTimeout(s,0))};return o=>{++n===1&&s();const i=Wu(o);return t.has(i)||t.set(i,e(o)),t.get(i)}},oi=e=>{const t=e<64?Uint8Array.of(e):Uint8Array.of((e&252)>>2|64,e>>8|(e&3)<<6);return qu(n=>{const r=Dn(Uint8Array.of(...ri,...t,...n),{dkLen:64}).subarray(0,Sr);return qo.encode(Uint8Array.of(...t,...n,...r))})};function Ku(e,t){return n=>{const r=si(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 dn=(e=42,t=32)=>Pe(ne(t),Ku(t),oi(e)),R=Pe(pe,e=>e,Number),Ln=Pe(pe,e=>e,BigInt),Xu=new TextEncoder,Gu=new TextDecoder,Yu=De(R,ne(1/0))[1],Qt={toText:e=>Gu.decode(e),toHex:e=>Y(e),toOpaque:e=>ae([pe[0](e.length),e]),fromText:e=>Xu.encode(e),fromHex:e=>te(e),fromOpaque:e=>{const t=typeof e=="string"?te(e):e;try{const[n,r]=Yu(t);if(n===r.length)return r}catch{}throw new Error("Invalid opaque bytes")}},ii=e=>Pe(ne(e),te,Y),Qu=lt(e=>{const t=R.dec(e),n=Math.ceil(t/8);return{bytes:ne(n).dec(e),bitsLen:t}}),Ju=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},Zu=X(Ju,Qu),ed=Pe(P,e=>e.charCodeAt(0),String.fromCharCode),ai=e=>{const t=ne.enc(e);return n=>t(te(n))},ci=e=>{const t=ne.dec(e);return n=>Y(t(n))},$e=e=>X(ai(e),ci(e));$e.enc=ai,$e.dec=ci;const li=new TextEncoder,td=new TextDecoder,nd=e=>Pe(ne(e),t=>li.encode(t),t=>td.decode(t)),ui=e=>{let t=n=>{const r=e();return t=r,r(n)};return n=>t(n)},di=e=>{let t=n=>{const r=e(),s=r;return t=r,s(n)};return n=>t(n)},Br=e=>X(ui(()=>e().enc),di(()=>e().dec)),rd={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}},jn=Object.assign((e,t)=>({type:e,value:t}),rd),sd=new Proxy({},{get(e,t){return n=>jn(t,n)}}),re=(e,t)=>{const n=e;return n.inner=t,n},hi=(...e)=>{const t=xe.enc(...e);return re(n=>t({tag:n.type,value:n.value}),e[0])},pi=(...e)=>{const t=xe.dec(...e);return re(n=>{const{tag:r,value:s}=t(n);return jn(r,s)},e[0])},Be=(e,...t)=>re(X(hi(yt(e,([n])=>n),...t),pi(yt(e,([,n])=>n),...t)),e);Be.enc=hi,Be.dec=pi;const Ir=(e,...t)=>re(xe(e,...t),e);Ir.enc=(e,...t)=>re(xe.enc(e,...t),e),Ir.dec=(e,...t)=>re(xe.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=Ru.slice(),fi=(()=>{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 Ar extends ti{canXOF=!0;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');Ae(r,32,"key");const i=Au(r);this.IV=zt(i),we(this.IV),this.flags=n|tt.KEYED_HASH}else if(o){Ae(s,void 0,"context");const i=s,a=new Ar({dkLen:32},tt.DERIVE_KEY_CONTEXT).update(i).digest();this.IV=zt(a),we(this.IV),this.flags=n|tt.DERIVE_KEY_MATERIAL}else this.IV=dt.slice(),this.flags=n;this.state=this.IV.slice(),this.bufferOut=Ou(this.bufferOut32)}get(){return[]}set(){}b2Compress(t,n,r,s=0){const{state:o,pos:i}=this,{h:a,l}=zn(BigInt(t),!0),{v0:c,v1:u,v2:h,v3:p,v4:f,v5:d,v6:v,v7:b,v8:y,v9:m,v10:g,v11:w,v12:E,v13:$,v14:k,v15:S}=ni(fi,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],a,l,i,n);o[0]=c^y,o[1]=u^m,o[2]=h^g,o[3]=p^w,o[4]=f^E,o[5]=d^$,o[6]=v^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 i,a=this.chunksDone+1;(r||!(a&1))&&(i=this.stack.pop());a>>=1)this.buffer32.set(i,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:i,chunkOut:a,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=i,t.chunkOut=a,t.enableXOF=this.enableXOF,t.bufferOut32.set(this.bufferOut32),t}destroy(){this.destroyed=!0,wt(this.state,this.buffer32,this.IV,this.bufferOut32),wt(...this.stack)}b2CompressOut(){const{state:t,pos:n,flags:r,buffer32:s,bufferOut32:o}=this,{h:i,l:a}=zn(BigInt(this.chunkOut++));we(s);const{v0:l,v1:c,v2:u,v3:h,v4:p,v5:f,v6:d,v7:v,v8:b,v9:y,v10:m,v11:g,v12:w,v13:E,v14:$,v15:k}=ni(fi,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],a,i,n,r);o[0]=l^b,o[1]=c^y,o[2]=u^m,o[3]=h^g,o[4]=p^w,o[5]=f^E,o[6]=d^$,o[7]=v^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,we(s),we(o),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,wt(this.buffer.subarray(this.pos));let t=this.flags|tt.ROOT;this.stack.length?(t|=tt.PARENT,we(this.buffer32),this.compress(this.buffer32,0,!0),we(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){un(this,!1),Ae(t),this.finish();const{blockLen:n,bufferOut:r}=this;for(let s=0,o=t.length;s<o;){this.posOut>=n&&this.b2CompressOut();const i=Math.min(n-this.posOut,o-s);t.set(r.subarray(this.posOut,this.posOut+i),s),this.posOut+=i,s+=i}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible after digest call");return this.writeInto(t)}xof(t){return Ut(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(kr(t,this),this.finished)throw new Error("digest() was already called");this.enableXOF=!1,this.writeInto(t.subarray(0,this.outputLen)),this.destroy()}digest(){const t=new Uint8Array(this.outputLen);return this.digestInto(t),t}}const od=xr((e={})=>new Ar(e)),id=BigInt(0),hn=BigInt(1),ad=BigInt(2),cd=BigInt(7),ld=BigInt(256),ud=BigInt(113),vi=[],bi=[],mi=[];for(let e=0,t=hn,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],vi.push(2*(5*r+n)),bi.push((e+1)*(e+2)/2%64);let s=id;for(let o=0;o<7;o++)t=(t<<hn^(t>>cd)*ud)%ld,t&ad&&(s^=hn<<(hn<<BigInt(o))-hn);mi.push(s)}const yi=Tu(mi,!0),dd=yi[0],hd=yi[1],gi=(e,t,n)=>n>32?ju(e,t,n):Du(e,t,n),wi=(e,t,n)=>n>32?Nu(e,t,n):Lu(e,t,n);function pd(e,t=24){if(Ut(t,"rounds"),t<1||t>24)throw new Error('"rounds" expected integer 1..24');const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let i=0;i<10;i++)n[i]=e[i]^e[i+10]^e[i+20]^e[i+30]^e[i+40];for(let i=0;i<10;i+=2){const a=(i+8)%10,l=(i+2)%10,c=n[l],u=n[l+1],h=gi(c,u,1)^n[a],p=wi(c,u,1)^n[a+1];for(let f=0;f<50;f+=10)e[i+f]^=h,e[i+f+1]^=p}let s=e[2],o=e[3];for(let i=0;i<24;i++){const a=bi[i],l=gi(s,o,a),c=wi(s,o,a),u=vi[i];s=e[u],o=e[u+1],e[u]=l,e[u+1]=c}for(let i=0;i<50;i+=10){const a=e[i],l=e[i+1],c=e[i+2],u=e[i+3];e[i]^=~e[i+2]&e[i+4],e[i+1]^=~e[i+3]&e[i+5],e[i+2]^=~e[i+4]&e[i+6],e[i+3]^=~e[i+5]&e[i+7],e[i+4]^=~e[i+6]&e[i+8],e[i+5]^=~e[i+7]&e[i+9],e[i+6]^=~e[i+8]&a,e[i+7]^=~e[i+9]&l,e[i+8]^=~a&c,e[i+9]^=~l&u}e[0]^=dd[r],e[1]^=hd[r]}wt(n)}class Or{state;pos=0;posOut=0;finished=!1;state32;destroyed=!1;blockLen;suffix;outputLen;canXOF;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.canXOF=s,this.rounds=o,Ut(r,"outputLen"),!(0<t&&t<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=zt(this.state)}clone(){return this._cloneInto()}keccak(){we(this.state32),pd(this.state32,this.rounds),we(this.state32),this.posOut=0,this.pos=0}update(t){un(this),Ae(t);const{blockLen:n,state:r}=this,s=t.length;for(let o=0;o<s;){const i=Math.min(n-this.pos,s-o);for(let a=0;a<i;a++)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){un(this,!1),Ae(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 i=Math.min(r-this.posOut,o-s);t.set(n.subarray(this.posOut,this.posOut+i),s),this.posOut+=i,s+=i}return t}xofInto(t){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(t)}xof(t){return Ut(t),this.xofInto(new Uint8Array(t))}digestInto(t){if(kr(t,this),this.finished)throw new Error("digest() was already called");this.writeInto(t.subarray(0,this.outputLen)),this.destroy()}digest(){const t=new Uint8Array(this.outputLen);return this.digestInto(t),t}destroy(){this.destroyed=!0,wt(this.state)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:s,rounds:o,enableXOF:i}=this;return t||=new Or(n,r,s,i,o),t.blockLen=n,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=i,t.canXOF=this.canXOF,t.destroyed=this.destroyed,t}}const Nn=((e,t,n,r={})=>xr(()=>new Or(t,e,n),r))(1,136,32),$i=e=>{const t=e.slice(2),n=Y(Nn(li.encode(t))).slice(2),r=new Array(40);for(let s=0;s<40;s++){const o=parseInt(n[s],16),i=t[s];r[s]=o>7?i.toUpperCase():i}return`0x${r.join("")}`},fd=ne(20)[1],Ei=X(e=>{const t=te(e);if(t.length!==20)throw new Error(`Invalid length found on EthAddress(${e})`);const n=Y(t);if(e===n||e===n.toUpperCase())return t;if($i(n)!==e)throw new Error(`Invalid checksum found on EthAddress(${e})`);return t},lt(e=>$i(Y(fd(e))))),me=e=>re(z(e),e);me.enc=e=>re(z.enc(e),e),me.dec=e=>re(z.dec(e),e);const We=(...e)=>re(De(...e),e);We.enc=(...e)=>re(De.enc(...e),e),We.dec=(...e)=>re(De.dec(...e),e);const Oe=(e,...t)=>re(L(e,...t),e);Oe.enc=(e,...t)=>re(L.enc(e,...t),e),Oe.dec=(e,...t)=>re(L.dec(e,...t),e);const Vn=(e,t)=>re(ln(e,t),{ok:e,ko:t});Vn.enc=(e,t)=>re(ln.enc(e,t),{ok:e,ko:t}),Vn.dec=(e,t)=>re(ln.dec(e,t),{ok:e,ko:t});const St=e=>re(Se(e),e);St.enc=e=>re(Se.enc(e),e),St.dec=e=>re(Se.dec(e),e);const ki=(e=!0)=>lt(t=>{const n=R.dec(t),r=Math.ceil(n/8),s=ne(r).dec(t),o=new Array(n);let i=0;return s.forEach(a=>{for(let l=0;l<8&&i<n;l++){const c=e?l:7-l;o[i++]=a>>c&1}}),o}),xi=(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 i=o*8,a=0;for(let l=0;l<8&&i<t.length;l++,i++)a|=t[i]<<(e?l:7-l);s[o]=a}return ae([n,s])},Pn=e=>X(xi(e),ki(e));Pn.enc=xi,Pn.dec=ki;const Si=new TextEncoder,Bi=new TextDecoder,vd=Pe(ne(4),Si.encode.bind(Si),Bi.decode.bind(Bi)),Cr=me({engine:vd,payload:$e()}),bd=Be({other:ne(),consensus:Cr,seal:Cr,preRuntime:Cr,runtimeUpdated:M},[0,4,5,6,8]),_r=$e(32),Fn=me({parentHash:_r,number:R,stateRoot:_r,extrinsicRoot:_r,digests:Oe(bd)}),Ce=L(q),Ii=Se(q),md=xe({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}),Ai=L(z({name:Ii,type:R,typeName:Ii,docs:Ce})),yd=z({len:Fe,type:R}),gd=z({bitStoreType:R,bitOrderType:R}),wd=L(z({name:q,fields:Ai,index:P,docs:Ce})),$d=xe({composite:Ai,variant:wd,sequence:R,array:yd,tuple:L(R),primitive:md,compact:R,bitSequence:gd}),Ed=z({name:q,type:Se(R)}),kd=L(Ed),xd=z({id:R,path:Ce,params:kd,def:$d,docs:Ce}),Wn=L(xd),Jt=xe({NotDeprecated:M,DeprecatedWithoutNote:M,Deprecated:z({note:q,since:Se(q)})}),Sd=L(z({index:P,deprecation:xe({DeprecatedWithoutNote:M,Deprecated:z({note:q,since:Se(q)})},[1,2])})),Rr={name:q,inputs:L(z({name:q,type:R})),output:R,docs:Ce},Bd=z({name:q,methods:L(z(Rr)),docs:Ce}),Id=z({name:q,methods:L(z({...Rr,deprecationInfo:Jt})),docs:Ce,version:R,deprecationInfo:Jt}),Ad=z({id:$e(32),...Rr,deprecationInfo:Jt}),Od=xe({Blake2128:M,Blake2256:M,Blake2128Concat:M,Twox128:M,Twox256:M,Twox64Concat:M,Identity:M}),Cd=L(Od),_d=z({hashers:Cd,key:R,value:R}),Oi={name:q,modifier:P,type:xe({plain:R,map:_d}),fallback:$e(),docs:Ce},Tr=Se(R),Ci={name:q,storage:Se(z({prefix:q,items:L(z(Oi))})),calls:Tr,events:Tr,constants:L(z({name:q,type:R,value:$e(),docs:Ce})),errors:Tr,index:P},Rd={...Ci,docs:Ce},Hr=Se(z({type:R,deprecationInfo:Sd})),Td={name:q,storage:Se(z({prefix:q,items:L(z({...Oi,deprecationInfo:Jt}))})),calls:Hr,events:Hr,constants:L(z({name:q,type:R,value:$e(),docs:Ce,deprecationInfo:Jt})),errors:Hr,associatedTypes:L(z({name:q,type:R,docs:Ce})),viewFns:L(Ad),index:P,docs:Ce,deprecationInfo:Jt},Hd=new Uint8Array,_i=e=>X(()=>Hd,()=>e),Md=z({type:R,version:P,signedExtensions:L(z({identifier:q,type:R,additionalSigned:R}))}),Ri=z({lookup:Wn,pallets:L(z({...Ci,docs:_i([])})),extrinsic:Md,type:R,apis:_i([])}),Ud=z({version:P,address:R,call:R,signature:R,extra:R,signedExtensions:L(z({identifier:q,type:R,additionalSigned:R}))}),Ti=z({lookup:Wn,pallets:L(z(Rd)),extrinsic:Ud,type:R,apis:L(Bd),outerEnums:z({call:R,event:R,error:R}),custom:L(De(q,z({type:R,value:$e()})))}),zd=z({version:L(P),address:R,call:R,signature:R,signedExtensionsByVersion:L(De(P,L(R))),signedExtensions:L(z({identifier:q,type:R,additionalSigned:R}))}),Hi=z({lookup:Wn,pallets:L(z(Td)),extrinsic:zd,apis:L(Id),outerEnums:z({call:R,event:R,error:R}),custom:L(De(q,z({type:R,value:$e()})))}),Mi=()=>{throw new Error("Unsupported metadata version!")},Ie=X(Mi,Mi),Dt=z({magicNumber:Fe,metadata:xe({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:Ri,v15:Ti,v16:Hi})}),Mr=ne(),Dd=Se(Mr),Ld=De(pe,Mr),Ui=e=>{try{return Dt.dec(e)}catch{}try{return Dt.dec(Dd.dec(e))}catch{}try{return Dt.dec(Mr.dec(e))}catch{}try{return Dt.dec(Ld.dec(e)[1])}catch{}throw null},qn=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,...i},...a}=e;if(!o.some(([l])=>l===0))throw new Error("Extension version 0 not found");return{version:16,extrinsic:{...i,signedExtensions:Object.fromEntries(o.map(([l,c])=>[l,c.map(u=>s[u])]))},...a}}if("custom"in e){const{lookup:s,extrinsic:o,custom:i,apis:a,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:a,outerEnums:c,custom:i}}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:[]}},Lt={bare:0,0:"bare",general:1,1:"general",signed:2,2:"signed"},Ur=Pe(P,({version:e,type:t})=>e+(Lt[t]<<6),e=>{const t=e&63,n=e>>6;if(t===4&&(n===Lt.bare||n===Lt.signed))return{version:t,type:Lt[n]};if(t===5&&(n===Lt.bare||n===Lt.general))return{version:t,type:Lt[n]};throw new Error(`ExtrinsicFormat ${e} not valid`)}),jd={dkLen:32},jt=e=>Dn(e,jd),Nd={dkLen:16},zr=e=>Dn(e,Nd),zi=e=>ae([zr(e),e]),Vd={dkLen:32},Di=e=>od(e,Vd),Pd=e=>ae([Di(e),e]),Li=e=>e,Nt=(e,t,n,r)=>new DataView(new Uint16Array([e,t,n,r]).buffer).getBigUint64(0,!0),Dr=2n**64n-1n,ye=(e,t)=>e<<t&Dr|e>>64n-t,F=(e,t)=>e*t&Dr,ce=(e,t)=>e+t&Dr,le=11400714785074694791n,_e=14029467366897019727n,ji=1609587929392839161n,pn=9650029242287828579n,Ni=2870177450012600261n;function Bt(e,t=0n){let n=ce(ce(t,le),_e),r=ce(t,_e),s=t,o=t-le,i=e.length,a=0,l=null;(function(){let p=0,f=p+i;if(i){if(l=new Uint8Array(32),i<32){l.set(e.subarray(0,i),a),a+=i;return}if(p<=f-32){const d=f-32;do{let v;v=Nt(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(ye(ce(n,F(v,_e)),31n),le),p+=8,v=Nt(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(ye(ce(r,F(v,_e)),31n),le),p+=8,v=Nt(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(ye(ce(s,F(v,_e)),31n),le),p+=8,v=Nt(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(ye(ce(o,F(v,_e)),31n),le),p+=8}while(p<=d)}p<f&&(l.set(e.subarray(p,f),a),a=f-p)}})(),e=l||e;let c,u=0;for(i>=32?(c=ye(n,1n),c=ce(c,ye(r,7n)),c=ce(c,ye(s,12n)),c=ce(c,ye(o,18n)),n=F(ye(F(n,_e),31n),le),c=c^n,c=ce(F(c,le),pn),r=F(ye(F(r,_e),31n),le),c=c^r,c=ce(F(c,le),pn),s=F(ye(F(s,_e),31n),le),c=c^s,c=ce(F(c,le),pn),o=F(ye(F(o,_e),31n),le),c=c^o,c=ce(F(c,le),pn)):c=ce(t,Ni),c=ce(c,BigInt(i));u<=a-8;){let p=Nt(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(ye(F(p,_e),31n),le),c=ce(F(ye(c^p,27n),le),pn),u+=8}if(u+4<=a){let p=F(Nt(e[u+1]<<8|e[u],e[u+3]<<8|e[u+2],0,0),le);c=ce(F(ye(c^p,23n),_e),ji),u+=4}for(;u<a;){const p=F(Nt(e[u++],0,0,0),Ni);c=F(ye(c^p,11n),le)}let h=c>>33n;return c=F(c^h,_e),h=c>>29n,c=F(c^h,ji),h=c>>32n,c^=h,c}const Kn=e=>{const t=new Uint8Array(16),n=new DataView(t.buffer);return n.setBigUint64(0,Bt(e),!0),n.setBigUint64(8,Bt(e,1n),!0),t},Vi=e=>{const t=new Uint8Array(32),n=new DataView(t.buffer);return n.setBigUint64(0,Bt(e),!0),n.setBigUint64(8,Bt(e,1n),!0),n.setBigUint64(16,Bt(e,2n),!0),n.setBigUint64(24,Bt(e,3n),!0),t},Pi=e=>ae([cn.enc(Bt(e)),e]),Fi=new TextEncoder,Fd=new Map([[Li,0],[Pi,8],[zi,16],[zr,-16],[jt,-32],[Kn,-16],[Vi,-32]]),Wi=e=>{const t=Kn(Fi.encode(e));return(n,...r)=>{const s=ae([t,Kn(Fi.encode(n))]),o=Y(s),i=l=>{if(!l.startsWith(o))throw new Error(`key does not match this storage (${e}.${n})`);if(r.length===0)return[];const c=te(l.slice(o.length)),u=new Array(r.length);for(let h=0,p=0;h<r.length;h++){const[f,d]=r[h],v=Fd.get(d);if(v==null)throw new Error("Unknown hasher");if(v<0){const b=v*-1;u[h]=Y(c.slice(p,p+b)),p+=b}else p+=v,u[h]=f.dec(c.slice(p)),p+=f.enc(u[h]).length}return u},a=r.map(([{enc:l},c])=>u=>c(l(u)));return{enc:(...l)=>Y(ae([s,...l.map((c,u)=>a[u](c))])),dec:i}}},Wd=Qt.fromText("modlpy/utilisuba"),qd=({threshold:e,signatories:t})=>{const n=qi(t),r=ae([Wd,pe.enc(n.length),...n,et.enc(e)]);return jt(r)},qi=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"},Ki=$e().dec,Kd=$e(1/0).dec,Xd=$e(32).dec,Xi=P.dec,Gd=e=>{const t=Xi(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 i;do o+=i=Xi(e);while(i===255)}return{type:s,partialKey:$e(Math.ceil(o/2)).dec(e).slice(o%2?3:2)}},Gi=lt(e=>{const t=Gd(e),{type:n}=t;if(n==="Empty"||n==="Reserved")return t;if(n==="Leaf"||n==="LeafWithHash")return{...t,value:Kd(e)};const r=et.dec(e),s=[];for(let a=0;a<16;a++)r>>a&1&&s.push(a.toString(16));let o=null;n==="BranchWithVal"&&(o=Ki(e)),n==="BranchWithHash"&&(o=Xd(e));const i={...t,children:Object.fromEntries(s.map(a=>[a,Ki(e)]))};return o!==null&&(i.value=o),i}),Yi=e=>lt(t=>{const n=Y(e(new Uint8Array(t.buffer)));try{return{hash:n,...Gi(t)}}catch{return{type:"Raw",hash:n,value:""}}}),Qi=(e,t=jt)=>{const n=e.map(Yi(t)),r=Object.fromEntries(n.map(a=>[a.hash,a])),s=n.map(a=>a.hash),o=new Set(s),i=a=>{if(a.value)return;const l=e[s.indexOf(a.hash)];a.value=typeof l=="string"?l:Y(l)};return n.forEach(a=>{if("children"in a&&Object.values(a.children).forEach(l=>{const c=r[l];c&&(c.parent=a.hash,o.delete(l))}),a.type==="BranchWithHash"||a.type==="LeafWithHash"){const l=a.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=a.hash,i(c)}a.type==="Raw"&&i(a)}),o.size===1?{rootHash:o.values().next().value,proofs:r}:null};var Ji=Object.freeze({__proto__:null,AccountId:dn,Binary:Qt,BitSeq:Pn,Blake2128:zr,Blake2128Concat:zi,Blake2256:jt,Blake3256:Di,Blake3256Concat:Pd,Bytes:ne,Enum:jn,Hex:$e,Identity:Li,Keccak256:Nn,Option:St,Result:Vn,ScaleEnum:Ir,Self:Br,SizedBytes:ii,Storage:Wi,Struct:me,TrieNodeHeaders:It,TrieNodeWithHash:Yi,Tuple:We,Twox128:Kn,Twox256:Vi,Twox64Concat:Pi,Variant:Be,Vector:Oe,_Enum:sd,_void:M,bitSequence:Zu,blockHeader:Fn,bool:su,char:ed,compact:pe,compactBn:Ln,compactNumber:R,createCodec:X,createDecoder:lt,decAnyMetadata:Ui,enhanceCodec:Pe,enhanceDecoder:Hn,enhanceEncoder:Tn,ethAccount:Ei,extrinsicFormat:Ur,fixedStr:nd,fromBufferToBase58:oi,getMultisigAccountId:qd,getSs58AddressInfo:si,h64:Bt,i128:tu,i16:Jl,i256:ru,i32:Zl,i64:eu,i8:Ql,metadata:Dt,selfDecoder:di,selfEncoder:ui,sortMultisigSignatories:qi,str:q,trieNodeDec:Gi,u128:So,u16:et,u256:nu,u32:Fe,u64:cn,u8:P,unifyMetadata:qn,v14:Ri,v14Lookup:Wn,v15:Ti,v16:Hi,validateProofs:Qi});const Yd=[jt,Nn],Qd=(e,t)=>Yd.find(n=>Y(n(te(e)))===t)||(()=>{throw new Error("Unsupported hasher")}),Jd=e=>{const t=(n,r,s)=>{const o=n[r.idx],i=n[s.idx];if(n.length===2)return W([[o,r.id],[i,s.id]]);const a=r.idx+Math.floor((s.idx-r.idx)/2);return e(n[a]).pipe(U(l=>{const c={id:l,idx:a};return c.id===r.id?t(n,c,s):c.id===s.id?t(n,r,c):oe([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 oe([r,n[s]].map(e)).pipe(U(([o,i])=>o===i?W([[r,o]]):t(n,{idx:0,id:o},{idx:s,id:i})))}},Zd=(e,t,n)=>{const r=Jd(t),s=l=>Kt(()=>e().header(l)),o=new nn(1),i=l=>{if(l.type==="initialized"){const[c]=l.finalizedBlockHashes;return oe([s(c),r(l.finalizedBlockHashes)]).pipe(x(([u,h])=>{o.closed||(o.next(Qd(u,c)),o.complete());const{number:p,parentHash:f,digests:d}=Fn.dec(u);return{type:"initialized",finalizedBlockHashes:l.finalizedBlockHashes,runtimeChanges:new Map(h),number:p,parentHash:f,hasNewRuntime:d.some(v=>v.type==="runtimeUpdated")}}))}if(l.type==="newBlock"&&l.newRuntime)return t(l.blockHash).pipe(x(c=>({...l,codeHash:c})))},a=l=>new D(c=>{let u=null,h;const p=v=>u?.push(v)||f(v),f=v=>{const b=i(v);b?(u=[],h=b.subscribe({next:y=>{const m=[...u];u=null,c.next(y),m.forEach(p)},error:n})):c.next(v)},d=l.subscribe(v=>{v.type==="stop-error"?(h?.unsubscribe(),u=null,c.next(v)):p(v)});return()=>{h?.unsubscribe(),d.unsubscribe()}});return{getHeader:l=>s(l).pipe(x(Fn[1])),hasher$:o.asObservable(),enhancer:a}},eh=(e,t)=>{let n=null,r=!1,s=()=>{r=!0};const o=()=>{if(!n)throw new Error("Missing chainHead subscription");return n},i=t(Mt((f,d)=>o().storage(f,"hash","0x3a636f6465",null,d)));let a=ke,l;const{hasher$:c,enhancer:u,getHeader:h}=Zd(o,i,f=>{console.warn("ChainHead subfollow request failed, retrying\u2026",f),l=setTimeout(()=>a(),250)}),p=new D(f=>{if(r)return f.complete();const d=()=>{let v=[];n=e(!0,b=>{v?v.push(b):f.next(b)},b=>{n=null,!r&&(b instanceof Error&&b.name===oo.errorName?(d(),f.next({type:"stop-error"})):(console.warn("ChainHead follow request failed, retrying\u2026",b),l=setTimeout(d,250)))}),v.forEach(b=>f.next(b)),v=null};a=()=>{f.next({type:"stop-error"}),clearTimeout(l),n?.unfollow(),d()},d(),s=()=>{r=!0,clearTimeout(l),f.complete(),n?.unfollow()}}).pipe(u,bt());return{getHeader:h,hasher$:c,getFollower:o,follow$:p,unfollow:()=>{s()}}},th=e=>Y(Fe.enc(e)),Zi=ne(),nh=St(Zi),rh=Oe(Fe).dec,ea=e=>{const t=e("Metadata_metadata_versions","").pipe(x(rh),ie(()=>W([14]))),n=r=>{const[s]=r.filter(o=>o>13&&o<17).sort((o,i)=>i-o);return s===14?e("Metadata_metadata","").pipe(x(Zi.dec)):e("Metadata_metadata_at_version",th(s)).pipe(x(o=>nh.dec(o)))};return t.pipe(U(n))},ta=(e,t)=>e.type==="array"&&e.len===t&&e.value.type==="primitive"&&e.value.value==="u8",At={type:"void"},sh=(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 f=u(h);return p=n.get(h),p?Object.assign(p,f):(p={id:h,...f},n.set(h,p)),r.delete(h),p};let o=!0,i=!0;const a=s(u=>{const h=t(e[u]);if(h)return h;const{def:p,path:f,params:d}=e[u];if(p.tag==="composite"){if(p.value.length===0)return At;if(p.value.length===1){const v=a(p.value[0].type);return o&&f.at(-1)==="AccountId32"&&ta(v,32)?(o=!1,{type:"AccountId32"}):i&&f.at(-1)==="AccountId20"&&ta(v,20)?(i=!1,{type:"AccountId20"}):v}return l(p.value)}if(p.tag==="variant"){if(f.length===1&&f[0]==="Option"&&d.length===1&&d[0].name==="T"){const y=a(d[0].type);return y.type==="void"?{type:"primitive",value:"bool"}:{type:"option",value:y}}if(f.length===1&&f[0]==="Result"&&d.length===2&&d[0].name==="T"&&d[1].name==="E")return{type:"result",value:{ok:a(d[0].type),ko:a(d[1].type)}};if(p.value.length===0)return At;const v={},b={};return p.value.forEach(y=>{const m=y.name;if(b[m]=y.docs,y.fields.length===0){v[m]={...At,idx:y.index};return}if(y.fields.length===1&&!y.fields[0].name){v[m]={type:"lookupEntry",value:a(y.fields[0].type),idx:y.index};return}v[m]={...l(y.fields),idx:y.index}}),{type:"enum",value:v,innerDocs:b}}if(p.tag==="sequence")return{type:"sequence",value:a(p.value)};if(p.tag==="array"){const{len:v}=p.value,b=a(p.value.type);return!v||b.type==="void"?At:v>1?{type:"array",value:b,len:p.value.len}:b}if(p.tag==="tuple")return p.value.length===0?At:p.value.length>1?c(p.value.map(v=>a(v)),p.value.map(v=>e[v].docs)):a(p.value[0]);if(p.tag==="primitive")return{type:"primitive",value:p.value.tag};if(p.tag==="compact"){const v=a(p.value);return v.type==="void"?At:{type:"compact",isBig:Number(v.value.slice(1))>32,size:v.value}}return{type:p.tag,isLSB:(e[p.value.bitOrderType].path.at(-1)??"LSB").toUpperCase().startsWith("LSB")}}),l=u=>{let h=!0;const p={},f={};return u.forEach((d,v)=>{h=h&&!!d.name;const b=d.name||v,y=a(d.type);y.type!=="void"&&(p[b]=y,f[b]=d.docs)}),h?{type:"struct",value:p,innerDocs:f}:c(Object.values(p),Object.values(f))},c=(u,h)=>{if(u.every(p=>p.id===u[0].id)&&h.every(p=>!p.length)){const[p]=u;return p.type==="void"?At:{type:"array",value:u[0],len:u.length}}return{type:"tuple",value:u,innerDocs:h}};return a},na=e=>{const t=sh(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?{...At,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})},oh=(e,t,n)=>(r,s,o,...i)=>{const{id:a}=r;if(s.has(a))return s.get(a);if(o.has(a)){const c=t(()=>s.get(a),r,...i);return s.set(a,c),c}o.add(a);let l=e(r,s,o,...i);return o.delete(a),s.has(a)&&(l=n(l,s.get(a),r,...i)),s.set(a,l),l},ih=ne(),ah=(e,t,n,r)=>{if(e.type==="primitive")return Ji[e.value];if(e.type==="void")return M;if(e.type==="AccountId32")return r;if(e.type==="AccountId20")return Ei;if(e.type==="compact")return e.isBig?Ln:R;if(e.type==="bitSequence")return Pn(e.isLSB);const s=p=>ra(p,t,n,r),o=(p,f)=>{const d=s(p);return f?Oe(d,f):Oe(d)},i=p=>We(...p.map(s)),a=p=>{const f=Object.fromEntries(Object.entries(p).map(([d,v])=>[d,s(v)]));return me(f)};if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return ih;if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?ii(e.len):o(e.value,e.len);if(e.type==="sequence")return o(e.value);if(e.type==="tuple")return i(e.value);if(e.type==="struct")return a(e.value);if(e.type==="option")return St(s(e.value));if(e.type==="result")return Vn(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 i(p.value);case"struct":return a(p.value);case"array":return o(p.value,p.len)}}),c=Object.fromEntries(Object.keys(e.value).map((p,f)=>[p,l[f]])),u=Object.values(e.value).map(p=>p.idx),h=u.every((p,f)=>p===f)?Be(c):Be(c,u);return e.byteLength?ch(h,e.byteLength):h},ra=oh(ah,Br,e=>e),sa=(e,t=dn())=>{const n=new Map,r=s=>ra(e(s),n,new Set,t);return s=>r(s)},ch=(e,t)=>{const n=ne(t);return X(r=>n.enc(e.enc(r)),r=>e.dec(n.dec(r)))},lh=Pe(M,()=>{},()=>null),uh=e=>{const{metadata:t}=e;let n=sa(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=sa(e,dn(p)))}catch{}const o=new Map,i=(p,f)=>{let d=o.get(p);d||o.set(p,d=Wi(p));const v=t.pallets.find(S=>S.name===p).storage.items.find(S=>S.name===f),b=S=>S===M?lh:S,y=(S,I,...B)=>{const _=d(...B),[,...T]=B;return{args:We(...T.map(([j])=>j)),keys:_,value:I,len:S,fallback:v.modifier===1?I.dec(v.fallback):void 0}};if(v.type.tag==="plain")return y(0,b(n(v.type.value)),f);const{key:m,value:g,hashers:w}=v.type.value,E=b(n(g)),$=w.map(S=>Ji[S.tag]),k=(()=>{if($.length===1)return[[n(m),$[0]]];const S=e(m);switch(S.type){case"array":return $.map(I=>[n(S.value.id),I]);case"tuple":return S.value.map((I,B)=>[n(I.id),$[B]]);default:throw new Error("Invalid key type")}})();return y($.length,E,f,...k)},a=p=>{switch(p.type){case"void":return M;case"lookupEntry":return n(p.value.id);case"tuple":return We(...Object.values(p.value).map(f=>n(f.id)));case"struct":return me(yt(p.value,f=>n(f.id)));case"array":return Oe(n(p.value.id),p.len)}},l=(p,f)=>{const d=t.pallets.find(v=>v.name===p).constants.find(v=>v.name===f);return n(d.type)},c=p=>(f,d)=>{const v=t.pallets.find(m=>m.name===f),b=e(v[p].type);if(b.type!=="enum")throw null;const y=b.value[d];return{location:[v.index,y.idx],codec:a(b.value[d])}},u=(p,f)=>{const d=t.pallets.find(v=>v.name===p)?.viewFns.find(v=>v.name===f);if(!d)throw null;return{args:We(...d.inputs.map(v=>n(v.type))),value:n(d.output)}},h=(p,f)=>{const d=t.apis.find(v=>v.name===p)?.methods.find(v=>v.name===f);if(!d)throw null;return{args:We(...d.inputs.map(v=>n(v.type))),value:n(d.output)}};return{buildDefinition:n,buildStorage:i,buildEvent:c("events"),buildError:c("errors"),buildViewFn:u,buildRuntimeCall:h,buildCall:c("calls"),buildConstant:l,ss58Prefix:s}},dh=(e,t)=>Object.fromEntries(e.pallets.map(n=>{const[r,s,o]=["errors","events","calls"].map(i=>{try{const a=t(n[i].type);if(a.type!=="enum")throw null;return new Map(Object.entries(a.value))}catch{return new Map}});return[n.name,{error:r,event:s,call:o}]})),hh=(e,t)=>{const n=dh(e,t),r=Object.fromEntries(e.pallets.map(a=>{const[l,c]=["constants","viewFns"].map(u=>new Map(a[u].map(h=>[h.name,h])));return[a.name,{const:l,view:c}]})),s=Object.fromEntries(e.pallets.map(a=>[a.name,new Map((a.storage?.items||[]).map(l=>[l.name,l]))])),o=yt(n,({error:a,event:l,call:c},u)=>({error:a,event:l,call:c,storage:s[u],...r[u]})),i=Object.fromEntries(e.apis.map(a=>[a.name,new Map(a.methods.map(l=>[l.name,l]))]));return{pallets:o,api:i,extensions:yt(e.extrinsic.signedExtensions,a=>Object.fromEntries(a.map(({identifier:l,...c})=>[l,c])))}},Lr="CheckMortality",oa=(e,t,n)=>{const r=na(e),s=uh(r),o=s.buildStorage("System","Events"),i=e.extrinsic.signedExtensions[0].find(u=>u.identifier==="ChargeAssetTxPayment");let a=null;if(i){const u=r(i.type);if(u.type==="struct"){const h=u.value.asset_id;h.type==="option"&&(a=h.value.id)}}const l=fh(r.metadata,s),c=u=>{const h=l(u);return"extra"in h&&h.extra[Lr]||{mortal:!1}};return{mappedMeta:hh(e,r),assetId:a,metadataRaw:t,codeHash:n,lookup:r,dynamicBuilder:s,events:{key:o.keys.enc(),dec:o.value.dec},accountId:dn(s.ss58Prefix),getMortalityFromTx:c,extVersions:e.extrinsic.version}},jr=ne(1/0).dec,ph=Hn(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}}),ia=lt(e=>{const t=P.dec(e);if(t===0)return{mortal:!1};const n=P.dec(e);return ph(Uint8Array.from([t,n]))}),fh=(e,t)=>{const n=me.dec(Object.fromEntries(e.extrinsic.signedExtensions[0].map(a=>[a.identifier,a.identifier===Lr?ia:t.buildDefinition(a.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 a=e.lookup[o.type]?.params,l=a?.find(h=>h.name==="Call")?.type,c=a?.find(h=>h.name==="Address")?.type,u=a?.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 i=me.dec({address:r,signature:s,extra:n,callData:jr});return lt(a=>{const l=R.dec(a),{type:c,version:u}=Ur[1](a);if(c==="bare")return{len:l,version:u,type:c,callData:jr(a)};if(c==="signed")return{len:l,version:u,type:c,...i(a)};const h=P.dec(a);let p;if(e.version===16){const d=e.extrinsic.signedExtensions[h];if(!d)throw new Error("Unexpected extension version");p=me.dec(Object.fromEntries(d.map(v=>[v.identifier,v.identifier===Lr?ia:t.buildDefinition(v.type)[1]])))}else p=n;const f=p(a);return{len:l,type:c,version:u,extensionVersion:h,extra:f,callData:jr(a)}})},vh=e=>t=>{const n=(...r)=>{let s;try{s=e()}catch(o){return Tt(o)}return s?t(s,...r).pipe(ie(o=>{if(o instanceof Je)return n(...r);if(o instanceof Error&&o.name===On.errorName)return kn(750).pipe(U(()=>n(...r)));throw o})):Ne};return n},bh=(e,t,n)=>{const r=(s,o)=>t(s).pipe(ie(()=>W(null)),U(i=>i?W(i):o.pipe(Xt(a=>{n(s,a)}))),x(i=>({codeHash:s,metadataRaw:i,metadata:qn(Dt.dec(i))})));return(s,o)=>{const i=new Set([o]),a={},l=vh(()=>{if(!i.size)throw a;return i.has(o)?o:[...i].at(-1)}),c=r(s,ea(l(e)).pipe(ie(h=>h===a?Ne:Tt(()=>h)))).pipe(x(({metadata:h,metadataRaw:p,codeHash:f})=>oa(h,p,f)),on(1)),u={codeHash:s,runtime:c,addBlock:h=>{i.add(h)},deleteBlocks:h=>(h.forEach(p=>{i.delete(p)}),i.size),usages:i};return c.subscribe({error(){}}),u}},fn=bt({connector:()=>new nn(1),resetOnError:!0,resetOnComplete:!0,resetOnRefCountZero:!0}),vn=({hash:e,number:t,parent:n,hasNewRuntime:r})=>({hash:e,number:t,parent:n,hasNewRuntime:r}),mh=(e,t,n,r,s,o,i,a)=>{const l=({blocks:m,runtimes:g},w)=>{w.forEach(E=>{m.get(m.get(E).parent)?.children.delete(E),m.delete(E),a(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(vn(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:be.Ready},g.forEach(c)},h=new ve,p=h.pipe(pl(()=>kn(0)),x(()=>({type:"cleanup"}))),f=aa(),d=()=>(l(f,[...f.blocks.values()].map(m=>m.hash)),Object.assign(f,aa())),v=Ve(s,p,e).pipe(sn((m,g)=>{const w=$=>{l(m,$),i($)},E=(...$)=>{const k=m.blocks.get(m.finalized)?.number??-1,S=$.filter(({refCount:I,recovering:B,number:_,pruned:T})=>!I&&!B&&(T||_<k)).map(({hash:I})=>I);S.length&&w(S)};switch(g.type){case"initialized":if(m.state.type!==be.Initializing&&m.state.type!==be.RecoveringInit)throw new Error("Initialized event out of order");m.state.type===be.RecoveringInit&&!g.finalizedBlockHashes.some(B=>m.blocks.has(B))&&(d(),o.next(null));const $=m.blocks.get(m.finalized)?.number??-1,k=g.finalizedBlockHashes.length-1,S=[];$>g.number+k?m.state={type:be.RecoveringFin,target:$,pendingBlocks:S}:(m.state={type:be.Initializing,pendingBlocks:S},m.finalized=g.finalizedBlockHashes[k]);let I=m.finalizedRuntime.codeHash;return g.finalizedBlockHashes.forEach((B,_)=>{const T=m.blocks.get(B);if(T)T.recovering=!1;else{const j=g.number+_,ee=j>$,ue=g.runtimeChanges.get(B),Ee=ue&&!m.runtimes[ue]&ⅇEe&&(I=ue);const ot=_===0?g.parentHash:g.finalizedBlockHashes[_-1],Ot={hash:B,hasNewRuntime:_?g.runtimeChanges.has(B):g.hasNewRuntime,parent:ot,children:new Set(_===k?[]:[g.finalizedBlockHashes[_+1]]),pruned:!1,runtime:I,refCount:0,number:j,recovering:!1};m.blocks.set(B,Ot),Ee&&(m.finalizedRuntime=m.runtimes[ue]=y(ue,B)),m.runtimes[I].usages.add(B),ee&&S.push(Ot)}}),m;case"stop-error":if(m.state.type===be.Initializing)return d();for(const B of m.blocks.values())B.recovering=!0;return m.state={type:be.RecoveringInit},m;case"newBlock":{const{parentBlockHash:B,blockHash:_}=g;if(m.blocks.has(_))m.blocks.get(_).recovering=!1;else{const T=m.blocks.get(B);T.children.add(_);const j=T.number+1,ee={hash:_,number:j,parent:B,children:new Set,runtime:T.runtime,pruned:!1,refCount:0,recovering:!1,hasNewRuntime:!!g.newRuntime};if(m.blocks.set(_,ee),g.newRuntime){const{codeHash:ue}=g;ee.runtime=ue,m.runtimes[ue]=y(ue,_)}m.runtimes[ee.runtime].addBlock(_),"pendingBlocks"in m.state?m.state.pendingBlocks.push(ee):c(ee)}return m}case"bestBlockChanged":return m.state.type===be.RecoveringFin||(m.best=g.bestBlockHash,m.state.type===be.Initializing&&u(m)),m;case"finalized":{const B=g.finalizedBlockHashes.slice(-1)[0];let _=!1;if(m.state.type===be.RecoveringFin){if(m.blocks.get(B).number<m.state.target)return m;_=!0}m.finalized=B;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(j=>{const ee=m.blocks.get(j);ee&&(ee.pruned=!0)}),_&&u(m),m.state.type===be.Ready&&h.next(),m}case"cleanup":return E(...m.blocks.values()),m;case"blockUsage":{const B=m.blocks.get(g.value.hash);return B&&(B.refCount+=g.value.type==="hold"?1:-1,E(B)),m}}},f),x(m=>({...m})),Xt({error(m){o.error(m)}}),fn),b=Object.assign(v,{state:f}),y=bh(_n(b,t,"pinned-blocks"),n,r);return b},aa=()=>({best:"",finalized:"",runtimes:{},blocks:new Map,finalizedRuntime:{},state:{type:be.Initializing,pendingBlocks:[]}}),ca=(e,t,n,r,s,o)=>{const i=new Map,a=f=>{i.get(f)?.(),i.delete(f)},l=new D(f=>{const d=t.subscribe({next:({hash:v})=>{i.set(v,o(v))},complete(){f.error(new Error("Tracking stopped"))}});return d.add(e.pipe(x(v=>v.finalized),he()).subscribe(()=>{e.state.blocks.forEach(({pruned:v,hash:b})=>{v&&a(b)})})),d.add(()=>[...i.keys()].forEach(a)),d}),c=f=>Bn(e.pipe(ge(({blocks:d})=>d.get(f)?.pruned??!0))),u=(f,d,v)=>{if(v)return W({hash:f,found:{type:!1,validity:null}});const b=c(f);return n(f).pipe(U(y=>{const m=y.findIndex(g=>yh(g,d));return m>-1?b(s(f)).pipe(x(g=>({hash:f,found:{type:!0,index:m,events:g}}))):r(f,d).pipe(x(g=>({hash:f,found:{type:!1,validity:g}})))}),b,dr(()=>a(f)))},h=f=>{[...e.state.blocks.get(f)?.children.keys()??[]].forEach(h),a(f)},p=(f,d,v)=>u(f,d,v.has(f)).pipe(U(b=>{const{found:y}=b,m=y.type||y.validity?.success===!1;return m&&h(f),m?W(b):e.pipe(c(f),U(g=>g.blocks.get(f).children),dl(),U(g=>p(g,d,v)),Sn(b))}));return f=>Ve(l,e.pipe(Z(1),U(d=>p(d.finalized,f,new Set(d.blocks.keys())))))},yh=(e,t)=>e.length===t.length&&e.every((n,r)=>t[r]===n),gh=new Uint8Array([2]),wh=(e,t)=>Y(ae([gh,e,te(t)])),la="TaggedTransactionQueue",ua="validate_transaction",[,$h]=Be({InvalidTransaction:Be({Call:M,Payment:M,Future:M,Stale:M,BadProof:M,AncientBirthBlock:M,ExhaustsResources:M,Custom:P,BadMandatory:M,MandatoryValidation:M,BadSigner:M}),UnknownTransaction:Be({CannotLookup:M,NoUnsignedValidator:M,Custom:P})}),Eh=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=$h(e)}catch{n={type:"UnknownInvalidTx"}}return{success:!1,value:n}}),kh=(e,t)=>(n,r)=>{const s=t(n).pipe(x(o=>{try{return o.dynamicBuilder.buildRuntimeCall(la,ua).value[1]}catch{return Eh}}));return e(n,`${la}_${ua}`,wh(r,n)).pipe(pr(s),x(([o,i])=>i(o)))},xh=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}),Sh=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)}}),Nr=(e,t=1/0)=>n=>new D(r=>{let s;const o=new Map,i=new Map,a=new Map;let l=0,c=0,u=0;const h=()=>{const p=o.get(c);if(!p){i.size===0&&(typeof s>"u"||s.closed)&&r.complete();return}const f=c++;o.delete(f),u!==f&&a.set(f,[]);let d=!1,v=p.subscribe({next(b){u===f?r.next(b):a.get(f).push(b)},complete(){if(d=!0,i.delete(f),f===u)for(u++;a.has(u)&&(a.get(u).forEach(b=>r.next(b)),a.delete(u),!i.has(u));)u++;h()},error(b){r.error(b)}});d||i.set(f,v)};return s=new Rt,s.add(n.subscribe({next(p){const f=l++;o.set(f,Kt(()=>e(p,f))),i.size<t&&h()},error(p){r.error(p)},complete(){i.size===0&&r.complete()}})),()=>{i.forEach(p=>p.unsubscribe()),s.unsubscribe(),o.clear(),a.clear()}}),Bh=(e,t,n)=>{const{withRecovery:r,withRecoveryFn:s}=Nl(),{getFollower:o,unfollow:i,follow$:a,getHeader:l,hasher$:c}=eh(e,s),u=Fl(o),h=new ve,p=A=>C=>new D(H=>{h.next({type:"blockUsage",value:{type:"hold",hash:A}});const N=C.subscribe(H);return N.add(()=>{setTimeout(()=>{h.next({type:"blockUsage",value:{type:"release",hash:A}})},0)}),N}),f=A=>(C,...H)=>A(C,...H).pipe(p(C)),d=(A,C)=>(H,...N)=>new D(fe=>g.state.blocks.has(H)?A(H,...N).subscribe(fe):fe.error(new Je(H,C))),v=A=>o().unpin(A).catch(C=>{if(!(C instanceof Error&&C.name===In.errorName))throw C}),b=(A,C)=>d(f(_n(g,s(Mt(A)),`stop-${C}`)),C),y=new Map,m=new ve,g=mh(a,(...A)=>f(s(Mt(u("call"))))(...A).pipe(x(te)),t,n,h,m,A=>{v(A).catch(C=>{console.error("unpin",C)}),A.forEach(C=>{y.delete(C)})},A=>{y.delete(A)}),w=d(f(A=>g.state.runtimes[g.state.blocks.get(A).runtime].runtime),"getRuntimeCtx"),E=A=>C=>C.pipe(Nr(H=>w(A(H)).pipe(x(N=>[H,N])))),$=(A,C,H)=>{const N=y.get(A)??new Map,fe=N.get(C);if(fe)return fe;y.set(A,N);let Ct;const Ye=H.pipe(bt({connector:()=>Ct=new nn}),Xt({complete(){N.set(C,Ct)}}),Sh());return N.set(C,Ye),Ye},k=Object.assign(g.pipe(ge(A=>A.state.type===be.Ready)),{state:g.state}),S=k.pipe(he((A,C)=>A.finalized===C.finalized),sn((A,C)=>{let H=C.blocks.get(C.finalized);const N=[H],fe=A.at(-1);if(!fe)return N;for(;H.number>fe.number+1&&(H=C.blocks.get(H.parent),!!H);)N.unshift(H);return N},[]),En(),x(vn),fn),I=k.pipe(he((A,C)=>A.best===C.best),x(A=>vn(A.blocks.get(A.best))),fn),B=k.pipe(he((A,C)=>A.finalized===C.finalized&&A.best===C.best),sn((A,C)=>{const H=Te=>A.get(Te)||vn(C.blocks.get(Te)),N=H(C.best),fe=H(C.finalized),Ct=N.number-fe.number+1,Ye=new Array(Ct);for(let Te=0,sr=N.hash;Te<Ct;Te++)Ye[Te]=H(sr),sr=Ye[Te].parent;return new Map(Ye.map(Te=>[Te.hash,Te]))},new Map),x(A=>[...A.values()]),fn),_=k.pipe(he((A,C)=>A.finalizedRuntime===C.finalizedRuntime),mt(({finalizedRuntime:{runtime:A}})=>A.pipe(xh(null))),fn),T=_.pipe(x(A=>A?.lookup.metadata??null)),j=Pl(S.pipe(x(A=>A.hash)),I.pipe(x(A=>A.hash)),p),ee=b(u("body"),"body"),ue=A=>gr($(A,"body",ee(A))).pipe(x(C=>C.map(te))),Ee=b(u("storage"),"storage"),ot=j(d((A,C,H,N=null,fe)=>{const Ct=g.state.blocks.get(A);return g.state.runtimes[Ct.runtime].runtime.pipe(U(Ye=>{const Te=H(Ye);return $(A,`storage-${C}-${Te}-${N??""}`,Ee(A,C,Te,N)).pipe(fe?x(sr=>fe(sr,Ye)):je)}),x(Ye=>({block:vn(Ct),value:Ye})))},"storage")),Ot=Wl(o,r),hv=j(d(_n(g,(A,C,H)=>Ot(A,C,H??null,!1),"storageQueries"),"storageQueries")),pv=d(_n(g,l,"header"),"header"),rc=A=>ot(A,"value",C=>C.events.key,null,(C,H)=>C?H.events.dec(C):[]).pipe(x(C=>C.value)),fv=b(u("call"),"call"),sc=j((A,C,H)=>$(A,`call-${C}-${H}`,fv(A,C,H).pipe(x(te)))),vs=kh(sc,w),vv=_.pipe(ge(Boolean),Z(1),U(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(N=>N.value))}),on(1));Ve(_,B).subscribe({error(){}});const bv=A=>g.state.runtimes[A]?.runtime??W(null),rr=(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 ke}h.next({type:"blockUsage",value:{type:"hold",hash:H}});let N=()=>{h.next({type:"blockUsage",value:{type:"release",hash:H}}),N=ke};return()=>{N()}},mv=A=>C=>new D(H=>{const N=C.subscribe(H);return N.closed||N.add(rr(A)),N}),bs=m.pipe(Ht(Boolean)),yv=ca(k,bs,ue,vs,rc,rr),gv=ca(g,bs,ue,vs,()=>W(),rr);return{follow$:a,unfollow:i,finalized$:S,best$:I,bestBlocks$:B,newBlocks$:ct(k.pipe(Z(1),U(({blocks:A,finalized:C})=>{const H=N=>{const fe=A.get(N);return fe?[fe,...Array.from(fe.children).flatMap(H)]:[]};return H(C)})),bs),runtime$:_,metadata$:T,genesis$:vv,hasher$:c,getRuntime$:bv,header$:pv,body$:ue,call$:sc,storage$:ot,storageQueries$:hv,eventsAt$:rc,withHodl:mv,holdBlock:rr,trackTx$:yv,trackTxWithoutEvents$:gv,validateTx$:vs,pinnedBlocks$:k,withRuntime:E,getRuntimeContext$:j(w)}};var Ih=e=>t=>new D(n=>e(Y(t),r=>{n.error(r)}));const Ah=({storageSubscription:e,...t})=>n=>{const r={},s=Mt(t.storage),o=(f,d,v)=>Mt(t.call)(f,d,v).pipe(x(te)),i=Mt(t.header),a=f=>Mt(t.body)(f).pipe(x(d=>d.map(te))),l=f=>i(f).pipe(x(Fn[1])),c=f=>s(f,"hash","0x3a636f6465",null).pipe(x(d=>d)),u=(f,d)=>n(f).pipe(ie(()=>W(null)),U(v=>v?W(v):ea((...b)=>o(d,...b)).pipe(x(b=>oa(qn(Dt.dec(b)),b,f)))),Xt(v=>{r[f]=v})),h=f=>c(f).pipe(U(d=>{const v=r[d];return v?W(v):u(d,f)})),p=(f,d,v,b=null,y)=>h(f).pipe(U(m=>s(f,d,v(m),b).pipe(x(g=>y?y(g,m):g))));return{body$:a,header$:l,storage$:p,storageQueries$:(f,d,v)=>new D(b=>e(f,d,v||null,y=>b.next(y),y=>b.error(y),()=>{b.complete()})),call$:o,eventsAt$:f=>p(f,"value",d=>d.events.key,null,(d,v)=>v.events.dec(d)),getRuntimeContext$:h}},Oh=()=>W(null),Ch=(e,{getMetadata:t,setMetadata:n}={})=>({chainHead$:()=>Bh(e.chainHead,t||Oh,n||ke),archive:Ah(e.archive),broadcastTx$:Ih(e.transaction),destroy:e.destroy}),da=(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(ie(s=>{if(!(s instanceof Je))throw s;return t(n,...r).pipe(ie(o=>{throw console.warn(o),s}))})),ht=R,_h=Oe(We(q,ht)),K={bool:"boolean",str:"string",num:"number",big:"bigint",bits:"bitseq",void:"void"},Rh=Be(Object.fromEntries(Object.values(K).map(e=>[e,M]))),Th=Oe(We(q,Be({inline:Br(()=>Vr),lookup:ht}))),Hh=Oe(ht),Mh=me({typeRef:ht,length:St(ht)}),Uh=St(ht),zh=ht,Dh=me({ok:ht,ko:ht}),Vr=Be({struct:_h,terminal:Rh,enum:Th,tuple:Hh,array:Mh,binary:Uh,option:zh,result:Dh}),Lh={i256:K.big,i128:K.big,i64:K.big,i32:K.num,i16:K.num,i8:K.num,u256:K.big,u128:K.big,u64:K.big,u32:K.num,u16:K.num,u8:K.num,bool:K.bool,char:K.str,str:K.str},bn=e=>({type:"terminal",value:{type:e}});function Pr(e,t=()=>{}){switch(e.type){case"AccountId20":case"AccountId32":return bn(K.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 bn(K.bits);case"compact":return bn(e.isBig?K.big:K.num);case"enum":return{type:"enum",value:Object.entries(e.value).map(([n,r])=>r.type!=="lookupEntry"?[n,{type:"inline",value:Pr(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 bn(Lh[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 bn(K.void)}}function Fr(e,t,n){if(t.type==="option"&&e==null)return!0;const r=(o,i)=>Fr(o,i,n),s=o=>{switch(o.value.type){case K.str:case K.big:case K.bool:case K.num:return typeof e===o.value.type;case K.bits:return typeof e=="object"&&e!=null&&typeof e.bitsLen=="number"&&e.bytes instanceof Uint8Array;case K.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 i=e,a=Object.fromEntries(t.value);if(!(i.type in a))return!1;const l=a[i.type];return l==null?!0:r(i.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 jh=Object.defineProperty,Nh=(e,t,n)=>t in e?jh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Vh=(e,t,n)=>Nh(e,t+"",n);let ha=class{constructor(t=[]){Vh(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 Wr(e,t,n,r,s,o=!1){if(!n&&!e)return qe(3,[]);if(!n)return qe(2,[]);if(!e)return qe(n.type==="option"?2:0,[]);s.has(n)||s.set(n,new Map);const i=s.get(n);if(i.has(e)){const l=i.get(e);return l==null?{level:3,changes:[],assumptions:new ha([[e,n]])}:qe(l.level,l.changes)}i.set(e,null);const a=Ph(e,n,(l,c)=>Wr(typeof l=="number"?t(l):l,t,typeof c=="number"?r(c):c,r,s),o);return a.assumptions.delete(e,n),a.assumptions.isEmpty()||a.level===0?i.set(e,a):i.delete(e),a}function Ph(e,t,n,r){const s=(o,i,a)=>{const l=n(o,i);return{...l,changes:l.level<3?[{id:[typeof o=="number"?o:null,typeof i=="number"?i:null],level:l.level,path:a}]:[]}};if(e.type!==t.type)return t.type==="option"?Xn(s(e,t.value,"some"),2):e.type==="option"?Xn(s(e.value,t,"some"),1):qe(0,[]);switch(t.type){case"terminal":return qe(t.value.type===e.value.type?3:0,[]);case"binary":return Kr(va(e.value,t.value));case"array":const o=e,i=Kr(va(o.value.length,t.value.length));return qr([i,()=>s(o.value.typeRef,t.value.typeRef,"value")],r);case"enum":{const h=e,p=Object.fromEntries(t.value.map(([v,b])=>[v,b.value]));let f=fa(h.value.map(([v,b])=>()=>v in p?s(b.value,p[v],v):qe(0,[{id:[typeof b.value=="number"?b.value:null,null],level:0,path:v}])));if(h.value.length===t.value.length)return f;f=Xn(f,2);const d=new Set(h.value.map(([v])=>v));return f.changes=[...f.changes,...t.value.filter(([v])=>!d.has(v)).map(([v,b])=>({id:[null,typeof b=="number"?b:null],level:0,path:v}))],f}case"option":return Fh(s(e.value,t.value,"some"),1);case"struct":const a=e,l=Object.fromEntries(a.value),c=a.value.length===t.value.length?3:2;return Xn(qr(t.value.map(([h,p])=>()=>s(l[h],p,h)),r),c);case"tuple":{const h=e,p=Kr(Wh(h.value,t.value));return qr([p,...t.value.map((f,d)=>()=>s(h.value[d],f,String(d)))],r)}case"result":const u=e;return fa([s(u.value.ok,t.value.ok,"ok"),s(u.value.ko,t.value.ko,"ko")])}}const Xn=(e,t)=>({...e,level:Math.min(e.level,t)}),Fh=(e,t)=>({...e,level:Math.max(e.level,t)}),pa=new ha,qe=(e,t)=>({level:e,changes:t,assumptions:pa}),qr=(e,t)=>{let n=qe(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},fa=e=>{if(!e.length)return qe(3,[]);let t=!1,n=qe(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:qe(0,n.changes)},Kr=e=>({assumptions:pa,changes:e===3?[]:[{id:[null,null],level:e,path:"length"}],level:e}),Wh=(e,t)=>t.length===e.length?3:e.length>=t.length?2:0,va=(e,t)=>t===e?3:t==null||e>=t?2:e==null?1:0,ba=Be({lookup:R,typedef:Vr}),Zt=e=>({type:"lookup",value:e}),Xr=e=>({type:"typedef",value:e}),Gn=Xr({type:"terminal",value:{type:K.void}}),qh=me({args:ba,values:ba});function Kh(e){if(e.type.tag==="plain")return{args:Gn,values:Zt(e.type.value)};const{key:t,value:n}=e.type.value;return{args:Zt(t),values:Zt(n)}}function ma(e){return{args:Xr({type:"tuple",value:e.inputs.map(t=>t.type)}),values:Zt(e.output)}}function Xh(e){return e.type==="lookupEntry"?Zt(e.value.id):Xr(Pr(e))}function Gh(e){return{args:Gn,values:Zt(e)}}function Yh(e,t,n,r,s,o){const i=(a,l)=>a.type==="lookup"?l(a.value):a.value;return{args:Wr(i(e.args,t),t,i(n.args,r),r,s,o),values:Wr(i(n.values,r),r,i(e.values,t),t,s,o)}}function ya(e,t,n){const r=e.type==="lookup"?t(e.value):e.value;return Fr(n,r,t)}const Yn=e=>{const t=new WeakMap,n={};return r=>{const s=r??n,o=t.get(s)||e(r);return t.set(s,o),o}},Qh=Oe(qh),Jh=Oe(Vr),[,Zh]=We(Qh,Jh);var Le=(e=>(e.Storage="storage",e.Tx="tx",e.Event="events",e.Const="constants",e.ViewFns="viewFns",e.Api="apis",e))(Le||{});const ep=async({metadataTypes:e,descriptors:t})=>{const[[n,r],s]=await Promise.all([e.then(Zh),t]);return{getTypeDefNode:o=>r[o],getEntryPointNode:(o,i,a)=>{const l=s[o]?.[i]?.[a];return l==null?l:n[l]}}},ga=(e,t)=>{const n=Xh(e),[r,s]=t==="args"?[n,Gn]:[Gn,n];return{args:r,values:s}},wa=Yn(({lookup:e,assetId:t,mappedMeta:{pallets:n,api:r}})=>{const s=new Map,o=i=>{let a=s.get(i);return a||(s.set(i,a=Pr(e(i))),a)};return{getTypeDefNode:o,getEntryPointNode:(i,a,l)=>{switch(i){case"storage":{const c=n[a]?.storage.get(l);return c&&Kh(c)}case"tx":{const c=n[a]?.call.get(l);return c&&ga(c,"args")}case"events":{const c=n[a]?.event.get(l);return c&&ga(c,"values")}case"viewFns":{const c=n[a]?.view.get(l);return c&&ma(c)}case"apis":{const c=r[a]?.get(l);return c&&ma(c)}case"constants":{const c=n[a]?.const.get(l);return c&&Gh(c.type)}}},isAssetCompat:i=>t==null||Fr(i,o(t),o)}}),$a=(e,t,n,r)=>{if(!e)return null;const{getEntryPointNode:s,getTypeDefNode:o}=e;return{entry:s(t,n,r),getter:o}},tp=bt({connector:()=>new nn(1),resetOnError:!0,resetOnComplete:!0,resetOnRefCountZero:!0});function Ke(e,t){return new Promise((n,r)=>{let s=null,o=!1;const i=t?()=>{s?.unsubscribe(),r(new Zs)}:ke;s=e.subscribe({next:a=>{n(a),s?.unsubscribe(),o=!0},error:a=>{t?.removeEventListener("abort",i),r(a),o=!0},complete:()=>{t?.removeEventListener("abort",i),r(new Error("Observable completed without emitting")),o=!0}}),o||t?.addEventListener("abort",i)})}const Gr=Symbol("EMPTY_VALUE"),Yr=e=>t=>new D(n=>{let r=0,s=null,o=Gr,i=!1;const a=()=>{const c=e(o,r++);o=Gr,s=c.subscribe({next(u){n.next(u)},error(u){n.error(u)},complete(){o!==Gr?a():(s=null,i&&n.complete())}})},l=t.subscribe({next(c){o=c,s||a()},error(c){n.error(c)},complete(){s||n.complete(),i=!0}});return()=>{s?.unsubscribe(),l.unsubscribe()}});let Ea={};const np=e=>t=>new D(n=>{let r=Ea,s=t.subscribe({next(o){n.next(r=o)},error(o){n.error(o)},complete(){r===Ea?n.complete():s=e(r).subscribe(n)}});return()=>{s.unsubscribe()}}),Pt=e=>typeof e!="object"||e===null||Object.getPrototypeOf(e)!==Object.prototype?!1:Object.entries(e).every(([t,n])=>t==="at"&&(n===void 0||typeof n=="string")||t==="signal"&&(n===void 0||n instanceof AbortSignal)),rp=()=>{const e=new Bc(new ve);return[e.pipe(fl()),()=>Xt({next:t=>e.value.next(t),error:t=>{e.value.error(t),e.next(new ve)},complete:()=>{e.value.complete(),e.next(new ve)}})]},sp={},ka=e=>new Proxy(sp,{get(t,n){return e(n)}}),nt=e=>{const t={};return ka(n=>(t[n]||(t[n]={}),ka(r=>(t[n][r]||(t[n][r]=e(n,r)),t[n][r]))))},Qn={level:pt.Incompatible,isCompatible:()=>!1,isValueCompatible:()=>!1},op={args:Qn,value:Qn,isCompatible:()=>!1},ip={level:pt.Identical,isCompatible:()=>!0,isValueCompatible:()=>!0},Jn=e=>(t=pt.BackwardsCompatible)=>e>=t,ap=(e,t,n,r)=>{let s;if(!r.entry)s=op;else{const{args:o}=r.entry,i=l=>ya(o,r.getter,l),a=e===Le.Storage?l=>i(l.length===1?l[0]:l):i;if(n?.entry){const{values:l}=n.entry,{args:c,values:u}=Yh(n.entry,n.getter,r.entry,r.getter,t);s={args:{level:c.level,isValueCompatible:a,isCompatible:Jn(c.level)},value:u.level===pt.Incompatible?Qn:{level:u.level,isValueCompatible:u.level>pt.Partial?()=>!0:h=>ya(l,n.getter,h),isCompatible:Jn(u.level)}}}else{const l=pt.Partial;s={args:{level:l,isValueCompatible:a,isCompatible:Jn(l)},value:n?Qn:ip}}}return e===Le.Storage||e===Le.Api||e===Le.ViewFns?Object.assign(s,{isCompatible:Jn(Math.min(s.args.level,s.value.level))}):e===Le.Tx?s.args:s.value},cp=Yn(e=>{let t=null;const n=(e?ep(e):Promise.resolve(null)).then(s=>t=s),r=Yn(s=>{const o=new Map,i=wa(s),a=l=>nt((c,u)=>ap(l,o,$a(t,l,c,u),$a(i,l,c,u)));return{tx:a(Le.Tx),constants:a(Le.Const),apis:a(Le.Api),view:a(Le.ViewFns),query:a(Le.Storage),event:a(Le.Event)}});return{getSyncHelpers:async s=>(await n,r(s)),getClientCompat:async(s,o,i)=>(await n,a=>r(a)[s][o][i]),getIsAsssetCompat:s=>wa(s).isAssetCompat}}),xa=({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)},lp=(e,t,n,r)=>({at:s,signal:o}={})=>Ke(oe([n.getRuntimeContext$(s||null),r]).pipe(x(([i,a])=>{const l=xa(i,e,t);if(a(i).isValueCompatible(l))return l;throw new Error(`Incompatible entry Const(${e}.${t})`)})),o),up=(e,t,n,r)=>{const s=()=>new Error(`Incompatible runtime entry Event(${e}.${t})`),o=(l,c)=>n.eventsAt$(l).pipe(x(u=>u.filter(h=>h.event.type===e&&h.event.value.type===t).map(h=>{if(!c(h.event.value.value))throw s();return{original:h,payload:h.event.value.value}}))),i=oe([n.finalized$,r]).pipe(n.withRuntime(([l])=>l.hash),Nr(([[l,c],u])=>{if(!u.mappedMeta.pallets[e]?.event.has(t))throw new Error(`Runtime entry Event(${e}.${t}) not found`);const{isValueCompatible:h}=c(u);return o(l.hash,h).pipe(x(p=>({block:l,events:p})))}),tp),a=Kt(()=>{const l=f=>{const d=da(n.pinnedBlocks$,f).pipe(ge(v=>v===null),Z(1));return oe([r,n.getRuntimeContext$(f)]).pipe(Z(1),mt(([v,b])=>{if(!b.mappedMeta.pallets[e]?.event.has(t))throw new Error(`Runtime entry Event(${e}.${t}) not found`);return o(f,v(b).isValueCompatible)}),Bn(d))};let c=[];const u=new Set,h=new ve,p=h.pipe(Nr(f=>l(f.hash).pipe(x(d=>({events:d,block:f})))),ge(f=>u.has(f.block.hash)),pr(n.finalized$),U(([{events:f,block:d},v])=>(u.delete(d.hash),v.number<d.number?(c.push({block:d,events:f}),W({type:"new",block:d,events:f})):[{type:"new",block:d,events:f},{type:"finalized",block:d,events:f}])));return Ve(p,n.bestBlocks$.pipe(x(f=>f.slice(0).reverse()),Sn([]),Qs(),U(([f,d])=>{if(f.length===0)return d.map(m=>({type:"new",block:m}));if(f[0].hash!==d[0].hash){const m=c[0];if(!m)return[];const g=d[0].number-m.block.number+1,w=c.slice(0,g);return c=c.slice(g),w.map(E=>({type:"finalized",block:E.block,events:E.events}))}let v=[];for(let m=0;m<c.length;m++)if(c[m].block.hash!==d[m+1]?.hash){v=c.slice(m).reverse(),c=c.slice(0,m);break}let b=f.length;for(let m=0;m<f.length;m++)if(f[m].hash!==d[m].hash){b=m;break}const y=d.slice(b);return[...v.map(m=>({type:"drop",block:m.block,events:m.events})),...y.map(m=>({type:"new",block:m}))]}),U(f=>f.type==="new"?(u.add(f.block.hash),h.next(f.block),Ne):(f.type==="drop"&&u.delete(f.block.hash),W(f)))))});return{watch:()=>i,watchBest:()=>a,get:l=>at(oe([r,n.getRuntimeContext$(l)]).pipe(Z(1),mt(([c,u])=>o(l,c(u).isValueCompatible)))),filter:l=>l.filter(({event:c})=>c.type===e&&c.value.type===t).map(c=>({original:c,payload:c.event.value.value}))}},dp=(e,t,n,r)=>{const s=`${e}_${t}`,o=()=>new Error(`Incompatible runtime entry RuntimeCall(${s})`);return(...i)=>{const a=i[i.length-1],l=Pt(a),{signal:c,at:u}=l?a:{},h=u??null,p=oe([n.getRuntimeContext$(h),r]).pipe(U(([f,d])=>{let v;try{v=f.dynamicBuilder.buildRuntimeCall(e,t)}catch{throw new Error(`Runtime entry RuntimeCall(${s}) not found`)}const b=d(f);if(!b.args.isValueCompatible(i))throw o();return n.call$(h,s,Y(v.args.enc(i))).pipe(x(v.value.dec),x(y=>{if(!b.value.isValueCompatible(y))throw o();return y}))}),n.withHodl(h));return Ke(p,c)}},Sa=(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:i,codec:[a]}=o;return ae([new Uint8Array(i),a(s)])},Ba=(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(...i)=>{if(i.length===o.len&&!r(i))throw s();return o.keys.enc(...i)}},Qr=()=>new Error("Unkown signer"),hp=e=>{const{extrinsic:t}=e,n=na(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(i=>i.type!=null).map(i=>[i.name,n(i.type)]));if(r=o.Address,s=o.Signature,!r||!s)throw Qr()}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 Qr();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 Qr()},pp={Ed25519:0,Sr25519:1,Ecdsa:2},fp=(e,t,n,r,s,o)=>{const[i,a]=hp(e),l=ae([Ur.enc({version:4,type:"signed"}),i===1?t:new Uint8Array([...a,...t]),i===1||!o?n:new Uint8Array([pp[o],...n]),...r,s]);return ae([pe.enc(l.length),l])},[Zn,mn]=["<Bytes>","</Bytes>"].map(e=>Qt.fromText(e)),vp=e=>async t=>{let n=!0,r;for(r=0;n&&r<Zn.length;r++)n=Zn[r]===t[r];n=n&&r===Zn.length;const s=t.length-mn.length;for(r=0;n&&r<mn.length;r++)n=mn[r]===t[s+r];return n=n&&r===mn.length,e(n?t:ae([Zn,t,mn]))};function bp(e,t,n){return{publicKey:e,signTx:async(r,s,o,i,a=jt)=>{const l=qn(Ui(o)),c=[],u=[];l.extrinsic.signedExtensions[0].map(({identifier:f})=>{const d=s[f];if(!d)throw new Error(`Missing ${f} signed extension`);c.push(d.value),u.push(d.additionalSigned)});const h=ae([r,...c,...u]),p=await n(h.length>256?a(h):h);return fp(l,e,p,c,r,t)},signBytes:vp(n)}}Uint8Array.from([1]);const mp=(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 yp(e){let t=0;for(;!(e&1);)t++,e>>=1;return t}const gp=e=>1<<Math.ceil(Math.log2(e)),wp=Tn(ne(2)[0],e=>{const t=Math.min(Math.max(gp(e.period),4),65536),n=e.startAtBlock%t,r=Math.max(t>>12,1),s=Math.min(Math.max(yp(t)-1,1),15),o=n/r<<4;return et[0](s|o)}),[$p]=me({tip:pe,asset:St(ne(1/0))}),Ia=new Uint8Array,Jr=Uint8Array.from([0]),Zr=e=>({value:e,additionalSigned:Ia}),es=e=>({value:Ia,additionalSigned:e}),ts=(e,t)=>({value:e,additionalSigned:t}),Ep=(e,t,n)=>{const r={};return t.metadata.extrinsic.signedExtensions[0].forEach(({identifier:s,type:o,additionalSigned:i})=>{r[s]=[o,i].map(a=>n.buildDefinition(a)[0])}),({mortality:s,tip:o=0n,nonce:i,customSignedExtensions:a={},...l})=>{const c=[],u=mp(t,n),h=f=>{const[d,v]=r[f],b=a[f];try{return yt({value:d,additionalSigned:v},(y,m)=>{const g=b?.[m];return g instanceof Uint8Array?g:y(g)})}catch{if(b)throw new Error(`Wrong input received for ${f}`);return c.push(f),null}},p=yt(r,([f,d],v)=>{if(a[v])return h(v);switch(v){case"CheckNonce":return Zr(f(i));case"CheckMortality":return s.mortal?ts(wp({period:s.period,startAtBlock:s.startAtBlock.height}),te(s.startAtBlock.hash)):ts(Jr,e);case"ChargeTransactionPayment":return Zr(f(o));case"ChargeAssetTxPayment":return Zr($p({tip:o,asset:l.asset}));case"CheckGenesis":return es(e);case"CheckMetadataHash":return ts(Jr,Jr);case"CheckSpecVersion":return es(d(u.spec_version));case"CheckTxVersion":return es(d(u.transaction_version));default:return h(v)}});return c.forEach(f=>{delete p[f]}),yt(p,(f,d)=>({...f,identifier:d}))}},Aa="AccountNonceApi_account_nonce",kp={1:P.dec,2:et.dec,4:Fe.dec,8:cn.dec},xp=(e,t,n)=>e(n,Aa,t).pipe(x(r=>{const s=kp[r.length];if(!s)throw new Error(`${Aa} retrieved wrong data`);return s(r)})),Sp=(e,t)=>e.pinnedBlocks$.pipe(Gs(0),x(n=>{const r=s=>{const o=n.blocks.get(s);if(!o)return null;if(o.hasNewRuntime)return o;for(const i of o.children){const a=r(i);if(a)return a}return null};return r(t)?.hash??t}),he()),Bp=(e,t,n,r,s,o={})=>oe([o.nonce!=null?W(o.nonce):Ip(e,Y(t.publicKey)),Sp(e,r.hash).pipe(mt(e.getRuntimeContext$)),e.genesis$]).pipe(Z(1),U(([i,a,l])=>{const c=Ep(te(l),a.lookup,a.dynamicBuilder),u=o.mortality??{period:64,mortal:!0},h=c({nonce:i,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,a.metadataRaw,r.number)})),Ip=(e,t)=>{const n=o=>e.newBlocks$.pipe(sn((i,a)=>a.parent===i?a.hash:i,o),Sn(o),he()),r=o=>n(o).pipe(Z(2),mt(i=>xp(e.call$,t,i))),s=o=>oe(o.map(i=>r(i).pipe(x(a=>({success:!0,value:a})),ie(a=>W({success:!1,value:a}))))).pipe(Z(1));return e.pinnedBlocks$.pipe(Z(1),x(({blocks:o,best:i})=>{const a=o.get(i);return[...o.values()].filter(l=>!l.pruned&&l.children.size===0&&l.number>=a.number).map(l=>l.hash)}),mt(s),x(o=>{const i=o.reduce((a,l)=>l.success&&l.value>=(a??0)?l.value:a,null);if(i==null)throw o[0].value;return i}))};var Ap=Object.defineProperty,Op=(e,t,n)=>t in e?Ap(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Cp=(e,t,n)=>Op(e,t+"",n);const _p=(e,t)=>new D(n=>{const r=new Map;let s,o;const i=()=>{let l=s.best,c=r.get(l),u=s.blocks.get(l).number;for(;!c;){const f=s.blocks.get(l);if(!f)break;c=r.get(l=f.parent),u--}if(!c)return;const h=u<=s.blocks.get(s.finalized).number,p=c.found.type;c!==o&&(p?n.next({found:!0,hash:c.hash,number:u,index:c.found.index,events:c.found.events}):o?.found.type&&n.next({found:!1,validity:c.found.validity}),o=c),h&&(p?n.complete():c.found.validity?.success===!1&&n.error(new Oa(c.found.validity.value)))},a=t.pipe(he((l,c)=>l.finalized===c.finalized&&l.best===c.best)).subscribe({next:l=>{s=l,i()},error(l){n.error(l)}});return a.add(e.subscribe({next:l=>{r.set(l.hash,l),i()},error(l){n.error(l)}})),a}).pipe(he((n,r)=>n===r)),Rp=(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 Oa extends Error{constructor(t){super(JSON.stringify(t,(n,r)=>typeof r=="bigint"?r.toString():r instanceof Uint8Array?Y(r):r,2)),Cp(this,"error"),this.name="InvalidTxError",this.error=t}}const ns=(e,t,n,r=!1)=>e.hasher$.pipe(U(s=>{const o=Y(s(n)),i=(d,v)=>({type:d,txHash:o,...v}),a=e.pinnedBlocks$.state,l=d=>{if(!d.mortal)return 0;const{phase:v,period:b}=d,y=a.blocks.get(a.best).number;return Math.floor((Math.max(y,v)-v)/b)*b+v},c=d=>{let v=[...a.blocks.values()].filter(m=>!m.pruned&&!m.children.size);const b=Math.max(...v.map(({number:m})=>m));v=v.filter(({number:m})=>m>=b-1);const y=a.blocks.get(a.finalized);return v=y.children?[y,...v]:v,v.filter(m=>m.number>=d)},u=({hash:d})=>e.validateTx$(d,n),h=Kt(()=>a.finalizedRuntime.runtime.pipe(x(d=>d.getMortalityFromTx(n)),x(l),x(c),U(d=>{let v;return Ve(...d.map(b=>al(u(b),e.finalized$.pipe(Ht(y=>{if(y.number<b.number)return!0;let m=y;for(;m.number>b.number;){const g=a.blocks.get(m.parent);if(!g)return!1;m=g}return m.hash===y.hash}),xn(),Ys({success:null}))))).pipe(ge((b,y)=>{if(b.success===!1&&(v??(v=new Oa(b.value))),b.success)return!0;if(y===d.length-1&&v)throw v;return!1}),Z(1))}),xn())),p=new D(d=>{const v=e.trackTx$(n).subscribe(d);return v.add(t(n).subscribe({error(b){d.error(b)}})),v}),f=_p(p,e.pinnedBlocks$).pipe(x(d=>d.found?i("txBestBlocksState",{found:!0,block:{index:d.index,number:d.number,hash:d.hash},...Rp(d.events,d.index)}):i("txBestBlocksState",{found:!1,isValid:d.validity?.success!==!1})));return ct(r?W(i("signed",{})):Ne,h,W(i("broadcasted",{})),f.pipe(np(({found:d,type:v,...b})=>d?W(i("finalized",b)):Ne)))})),Ca=async(e,t,n,r)=>qc(ns(e,t,n)).then(s=>{if(s.type!=="finalized")throw null;const o={...s};return delete o.type,o}),Tp=dn().enc,Hp=new Uint8Array(64),Mp=new Uint8Array(65),Up=e=>()=>e?Mp:Hp,[,zp]=me({weight:me({ref_time:Ln,proof_size:Ln}),class:Be({Normal:M,Operational:M,Mandatory:M}),partial_fee:So}),rs=(e,t,n,r,s,o)=>{const i=c=>oe([n.getRuntimeContext$(c),s]).pipe(x(([u,h])=>({ctx:u,isAssetCompat:o(u),...h(u)}))),a=(c,u)=>i(u).pipe(x(({ctx:{dynamicBuilder:h,extVersions:p},isValueCompatible:f})=>{const d=Sa(h,f,e,t,c);return{callData:d,bare:ae([pe.enc(d.length+1),new Uint8Array(p.slice(-1)),d])}})),l=(c,u)=>c===void 0?W(void 0):i(u).pipe(x(({ctx:h,isAssetCompat:p})=>{if(!p(c))throw new Error("Incompatible runtime asset");const{dynamicBuilder:f,assetId:d}=h;if(d)return f.buildDefinition(d).enc(c)}));return c=>{const u=(y,{...m},g)=>oe([a(c,g.hash),l(m.asset,g.hash)]).pipe(U(([w,E])=>Bp(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?Tt(()=>new Error(`Uknown block ${m}`)):(w?W(w):n.finalized$).pipe(Z(1),U(E=>u(y,g,E).pipe(x($=>({tx:$,block:E})))))},p=(y,m)=>at(h(y,m)).then(g=>g.tx),f=(y,m)=>at(h(y,m)).then(({tx:g,block:w})=>Ca(n,r,g,w.hash)),d=(y,m)=>h(y,m).pipe(U(({tx:g})=>ns(n,r,g,!0))),v=async(y,m)=>{typeof y=="string"&&(y=y.startsWith("0x")?te(y):Tp(y));const g=y.length===20,w=bp(y,g?"Ecdsa":"Sr25519",Up(g)),E=await p(w,m),$=Y(ae([E,Fe.enc(E.length)])),k=n.getRuntimeContext$(null).pipe(x(I=>{try{return I.dynamicBuilder.buildRuntimeCall("TransactionPaymentApi","query_info").value[1]}catch{return zp}})),S=n.call$(null,"TransactionPaymentApi_query_info",$);return at(oe([S,k]).pipe(x(([I,B])=>B(I))))},b=()=>at(a(c,null).pipe(x(({callData:y})=>y)));return{getPaymentInfo:v,getEstimatedFees:async(y,m)=>(await v(y,m)).partial_fee,decodedCall:{type:e,value:jn(t,c)},getEncodedData:b,getBareTx:()=>at(a(c,null).pipe(x(({bare:y})=>y))),sign:p,signSubmitAndWatch:d,signAndSubmit:f}}},Dp=(e,t,{getClientCompat:n,getSyncHelpers:r,getIsAsssetCompat:s})=>{const o=({dynamicBuilder:i,lookup:a})=>l=>{try{const{type:c,value:{type:u,value:h}}=i.buildDefinition(a.call).dec(l);return rs(c,u,e,t,n("tx",c,u),s)(h)}catch{throw new Error("Invalid call data")}};return({at:i,signal:a}={})=>Ke(e.getRuntimeContext$(i??null).pipe(U(Yn(async l=>{const c=await r(l);return{id:l.codeHash,txFromCallData:o(l),constants:nt((u,h)=>xa(l,u,h)),query:nt((u,h)=>({getKey:Ba(l,u,h,c.query[u][h].args.isValueCompatible)})),tx:nt((u,h)=>({getEncodedData:p=>Sa(l.dynamicBuilder,c.tx[u][h].isValueCompatible,u,h,p)})),compat:c}}))),a)},Lp=(e,t,n,r,s)=>{const o=e==="System"&&t==="Number",i=e==="System"&&t==="BlockHash",a=n.runtime$.pipe(ge(Boolean),Z(1),x(({dynamicBuilder:d})=>typeof d.buildStorage("System","Number").value.dec(new Uint8Array(32))=="bigint"?BigInt:je),on()),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 v=d.at(-1),b=Pt(v),[y,m]=b?[d.slice(0,-1),d.at(-1).at==="best"]:[d,!1];return n[m?"best$":"finalized$"].pipe(Yr(()=>p(...y,m?{at:"best"}:{})),sn((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 v=d[d.length-1],b=Pt(v),{at:y}=b?v:{},m=y??null,g=vt(s).pipe(U(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($),I=E===null?k.fallback:k.value.dec(E);if(!S(I))throw l();return{raw:E,mapped:I}})),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),ul(a),x(([w,E])=>({block:w,value:{raw:w.number.toString(),mapped:E(w.number)}})),ie(w=>{if(w instanceof Je)return g;throw w})):i&&Number(d[0])===0?oe([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 $}),Z(1))]).pipe(x(([w,E])=>({block:E,value:{raw:w,mapped:w}}))):g},f=async(...d)=>{const v=d[d.length-1],b=Pt(v),{signal:y}=b?v:{};return Ke(p(...d).pipe(x(m=>m.value.mapped)),y)};return{getKey:(...d)=>at(oe([n.getRuntimeContext$(null),s]).pipe(x(([v,b])=>Ba(v,e,t,b(v).args.isValueCompatible)(...d)))),getValue:f,getValues:(d,v)=>Promise.all(d.map(b=>f(...v?[...b,v]:b))),getEntries:async(...d)=>{const v=d[d.length-1],b=Pt(v),{signal:y,at:m}=b?v:{},g=m??null,w=vt(s).pipe(U(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 I=d.length>0&&b?d.slice(0,-1):d;if(d.length===S.len&&I===d)throw c(d);return S.keys.enc(...I)},null,($,k)=>{const S=u(k),I=E(k),B=$.map(({key:_,value:T})=>({keyArgs:S.keys.dec(_),value:S.value.dec(T)}));if(I.value.level===pt.Partial&&B.some(({value:_})=>!I.value.isValueCompatible(_)))throw l();return B})),x(E=>E.value),n.withHodl(g));return Ke(w,y)},watchValue:h,watchEntries:(...d)=>{const v=d.at(-1),b=Pt(v);return r(e,t,b?d.slice(0,-1):d,b&&v.at==="best")}}},_a="RuntimeViewFunction",Ra="execute_view_function",ss=_a+"_"+Ra,jp=(e,t,n,r)=>{const s=()=>new Error(`Incompatible runtime entry ViewFn(${e}.${t})`);return(...o)=>{const i=o[o.length-1],a=Pt(i),{signal:l,at:c}=a?i:{},u=c??null,h=oe([n.getRuntimeContext$(u),r]).pipe(U(([p,f])=>{let d;try{d=p.dynamicBuilder.buildRuntimeCall(_a,Ra)}catch{throw new Error(`Runtime entry RuntimeCall(${ss}) not found`)}let v;try{v=p.dynamicBuilder.buildViewFn(e,t)}catch{throw new Error(`Runtime entry ViewFn(${e}.${t}) not found`)}const b=f(p);if(!b.args.isValueCompatible(o))throw s();const y=v.args.enc(o),m=ae([te(p.mappedMeta.pallets[e].view.get(t).id),R.enc(y.length),y]);return n.call$(u,ss,Y(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(${ss}) type`)}}),x(({success:g,value:w})=>{if(!g)throw new Error(`ViewFn API Error: ${w.type}`);const E=v.value.dec(w);if(!b.value.isValueCompatible(E))throw s();return E}))}),n.withHodl(u));return Ke(h,l)}};var Np=Object.defineProperty,Vp=(e,t,n)=>t in e?Np(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,rt=(e,t,n)=>(Vp(e,typeof t!="symbol"?t+"":t,n),n),os=Symbol("SUSPENSE"),Pp=class extends Promise{constructor(e){super(e)}},Ta=class extends Error{constructor(){super(),this.name="NoSubscribersError"}},Ha=class extends Error{constructor(){super(),this.name="EmptyObservableError"}},Re={},er=class extends D{constructor(e,t,n=ke){super(r=>{const s=new tn({next:r.next.bind(r),error:r.error.bind(r),complete:ke});this.refCount++;let o;r.add(()=>{var i;this.refCount--,o.unsubscribe(),this.refCount===0&&(this.currentValue=Re,this.subscription&&this.subscription.unsubscribe(),n(),(i=this.subject)==null||i.complete(),this.subject=null,this.subscription=null,this.promise&&(this.promise.rej(new Ta),this.promise=null))}),this.subject?(o=this.subject.subscribe(s),this.currentValue!==Re&&r.next(this.currentValue)):(this.subject=new ve,o=this.subject.subscribe(s),this.subscription=null,this.subscription=new tn({next:i=>{this.promise&&i!==os&&(this.promise.res(i),this.promise=null),this.subject.next(this.currentValue=i)},error:i=>{var a;this.subscription=null;const l=this.subject;this.subject=null,this.currentValue=Re;const c=(a=this.promise)==null?void 0:a.rej;c&&i===os&&(this.promise.rej=()=>{c(i)}),l.error(i),c&&this.promise&&(this.promise.rej=c)},complete:()=>{if(this.subscription=null,this.promise&&(this.promise.rej(new Ha),this.promise=null),this.currentValue!==Re)return this.subject.complete();if(t===Re){const i=this.subject;return this.subject=null,i.error(new Ha)}this.subject.next(this.currentValue=t),this.subject.complete()}}),e.subscribe(this.subscription),t!==Re&&this.currentValue===Re&&this.subject.next(this.currentValue=t))}),this.defaultValue=t,rt(this,"subject",null),rt(this,"subscription",null),rt(this,"refCount",0),rt(this,"currentValue",Re),rt(this,"promise",null),rt(this,"pipeState",(...r)=>{const s=super.pipe(...r);return s instanceof er?s:new er(s,Re)}),rt(this,"getRefCount",()=>this.refCount),rt(this,"getValue",()=>{if(this.promise)return this.promise.p;if(this.currentValue!==Re&&this.currentValue!==os)return this.currentValue;if(this.defaultValue!==Re)return this.defaultValue;if(this.refCount===0)throw new Ta;const r=new Pp((s,o)=>{this.promise={res:s,rej:o,p:null}});return this.promise.p=r,r}),rt(this,"getDefaultValue",()=>this.defaultValue),t===Re&&delete this.getDefaultValue}};function Ma(e,t){t.getValue=e.getValue,t.getRefCount=e.getRefCount,t.pipeState=e.pipeState,e.getDefaultValue&&(t.getDefaultValue=e.getDefaultValue)}function Fp(e,t){const n=new Wp,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 i=[o.length,...o],a=n.get(i);if(a!==void 0)return a;const l=new er(e(...o),r(...o),()=>{n.delete(i)}),c=new D(h=>{const p=n.get(i);let f=l;return p?p!==c&&(f=p,Ma(f,c)):n.set(i,u),f.subscribe(h)});Ma(l,c);const u=c;return n.set(i,u),u};return(...o)=>s(o)}var Wp=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 qp(e,t){return new er(e,t)}var is=(...e)=>(typeof e[0]=="function"?Fp:qp)(e[0],e.length>1?e[1]:Re);const Ua=(e,t,n)=>{const r=new Map(t.map(a=>[a.key,a])),s=new Map(e.map(a=>[a.key,a])),o=new Map,i=[];return t.forEach(a=>{const{key:l}=a,c=s.get(l);(!c||c.value!==a.value)&&o.set(l,n(a))}),e.forEach(a=>{r.has(a.key)||i.push(a)}),{deltas:{deleted:i,upserted:[...o.values()]},entries:t.map(({key:a})=>o.get(a)??s.get(a))}},za=(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}},Kp=(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)},Xp=(e,t,n)=>{const r=is((a,l,c)=>{const u=Kp(a,l),h=(b,y)=>{const m=da(e,y.hash).pipe(ge(g=>!g),Z(1));return t(y.hash,"closestDescendantMerkleValue",()=>c).pipe(U(g=>{const w=g.value;return w===b?.rootHash?W({...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:$,...Ua(b?.entries??[],E,$)})))}),Bn(m),ie(g=>g instanceof Je?Ne:Tt(()=>g)))},p=e.pipe(he((b,y)=>b.finalized===y.finalized),Yr(({blocks:b,finalized:y})=>h(null,b.get(y))),Z(1),x(b=>({blocks:{[b.block.hash]:b},finalized:b.block.hash}))),[f,d]=rp(),v=e.pipe(he((b,y)=>b.best===y.best),pr(f),Yr(([b,y])=>{const{best:m}=b,{blocks:g}=y;let w=g[m]?null:m;if(!w)return Ne;const E=za(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 Ve(p,v).pipe(d())}),s=a=>(l,c,u)=>{const h=r(l,c,u),p=a?"finalized":"best";return oe([h,e.pipe(he((f,d)=>f[p]===d[p]))]).pipe(x(([f,d])=>{const v=za(d[p],f.blocks,d,!0);return v&&{update:v,state:f}}),ge(Boolean),he((f,d)=>f.update===d.update),Sn(null),Qs(),U(([f,d])=>{if(!f)return[d.update];const{update:v}=f,{state:b,update:y}=d;let m=y;const g=[];for(;m&&m.block.number>v.block.number;)g.unshift(m),m=m.prev?b.blocks[m.prev]:null;if(a&&(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 v===m?g:[{...y,...v.rootHash===y.rootHash?{entries:v.entries,deltas:null}:Ua(v.entries,y.entries,y.patcher)}]}))},o=is(s(!0)),i=is(s(!1));return(a,l,c,u)=>{const h=u?i:o;return e.pipe(Z(1),U(p=>p.runtimes[p.blocks.get(p[u?"best":"finalized"]).runtime].runtime),x(p=>p.dynamicBuilder.buildStorage(a,l).keys.enc(...c))).pipe(Z(1),U(p=>h(a,l,p)),x(({block:{hash:p,number:f,parent:d},deltas:v,entries:b},y)=>{const m=y>0?v:{deleted:[],upserted:b};return{block:{hash:p,number:f,parent:d},entries:b.map(as),deltas:m&&{deleted:m.deleted.map(as),upserted:m.upserted.map(as)}}}))}},as=e=>e.dec,Gp=/^(?:0x)?((?:[0-9a-fA-F][0-9a-fA-F])+)$/,Da=(e,t,n)=>{const r=cp(n),{getClientCompat:s,getIsAsssetCompat:o}=r,i=Dp(e,t,r),a=Xp(e.pinnedBlocks$,e.storage$,e.withRuntime),l=nt((d,v)=>Lp(d,v,e,a,s("query",d,v))),c=nt((d,v)=>rs(d,v,e,t,s("tx",d,v),o)),u=nt((d,v)=>up(d,v,e,s("event",d,v))),h=nt((d,v)=>lp(d,v,e,s("constants",d,v))),p=nt((d,v)=>dp(d,v,e,s("apis",d,v))),f=nt((d,v)=>jp(d,v,e,s("view",d,v)));return{tx:c,constants:h,apis:p,view:f,query:l,event:u,txFromCallData:(d,{at:v,signal:b}={})=>Ke(e.getRuntimeContext$(v??null).pipe(x(({dynamicBuilder:y,lookup:m})=>{try{const{type:g,value:{type:w,value:E}}=y.buildDefinition(m.call).dec(d);return rs(g,w,e,t,s("tx",g,w),o)(E)}catch{throw new Error("createTx: invalid call data")}})),b),getStaticApis:i}};function Yp(e,{getMetadata:t,setMetadata:n}={}){const r=zl(e),s=Ch(r,{getMetadata:t?I=>vt(t(I)):void 0,setMetadata:n}),{getChainSpecData:o}=r,i=I=>(B,..._)=>oe([I(B,..._),c.header$(B).pipe(x(({number:T,parentHash:j})=>({hash:B,number:T,parent:j,hasNewRuntime:!1})))]).pipe(x(([T,j])=>({value:T,block:j}))),{genesis$:a,...l}=s.chainHead$(),c=s.archive(l.getRuntime$),u={...l,genesis$:Kt(o).pipe(x(({genesisHash:I})=>I),ie(()=>a),on(1)),storage$:Vt(l.storage$,i(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=(I,B,_)=>new D(T=>{let j=null,ee=null;const ue=()=>{ee!=null&&r.request(B,[ee])};return r._request(I,_,{onSuccess:(Ee,ot)=>{if(ee=Ee,T.closed){ue();return}j=ot(ee,{next:Ot=>T.next(Ot),error:Ot=>T.error(Ot)})},onError(Ee){T.error(Ee)}}),()=>{ue(),j?.()}});let f;const d=new WeakMap,{broadcastTx$:v}=s,b=I=>u.getRuntimeContext$(I).pipe(x(B=>B.metadataRaw)),{holdBlock:y,finalized$:m,bestBlocks$:g,body$:w,header$:E,storage$:$,unfollow:k}=u,S={getChainSpecData:o,getMetadata$:b,getMetadata:(I,B)=>Ke(b(I),B),blocks$:u.newBlocks$,hodlBlock:I=>y(I,!0),finalizedBlock$:m,getFinalizedBlock:()=>at(m),bestBlocks$:u.bestBlocks$,getBestBlocks:()=>at(g),getBlockBody$:w,getBlockBody:(I,B)=>Ke(w(I),B),getBlockHeader$:E,getBlockHeader:(I,B)=>Ke(E(I),B),submit:(...I)=>Ca(u,v,...I),submitAndWatch:I=>ns(u,v,I),getTypedApi:I=>{if(d.has(I))return d.get(I);const B=Da(u,v,I);return d.set(I,B),B},getUnsafeApi:()=>(f??(f=Da(u,v)),f),rawQuery:(I,{at:B,signal:_}={})=>Ke($(B??null,"value",()=>{const T=I.match(Gp)?.[1];return T?`0x${T}`:Y(Qt.fromText(I))}).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:""},cs={body:"",call:"",finalizedHeight:"",genesisHash:"",hashByHeight:"",header:"",stopStorage:"",storage:""},ls={broadcast:"",stop:""},La={chainName:"",genesisHash:"",properties:""};Object.entries({chainHead:st,chainSpec:La,transaction:ls,archive:cs}).forEach(([e,t])=>{Object.keys(t).forEach(n=>{t[n]=`${e}_v1_${n}`})});const us=e=>t=>new D(n=>{let r,s=[],o=!1;const i=new Rt;return i.add(t.subscribe({next(a){s?s.push(a):n.next([r,a])},error(a){n.error(a)},complete(){s?o=!0:n.complete()}})),i.add(e.subscribe({next(a){if(r=a,s){const l=[...s];s=null,l.forEach(c=>n.next([r,c]))}o&&n.complete()},error(a){n.error(a)},complete(){s&&n.error(new Error("Empty complete"))}})),i}),tr=on({refCount:!0,bufferSize:1}),Qp=({allHeads$:e,finalized$:t,getHeader$:n,hasher$:r,getRecursiveHeader:s})=>{const o={blocks:new Map,prevFin:"",finalized:"",best:""},i=($,k=[])=>(k.push($),o.blocks.get($).children.forEach(S=>{i(S,k)}),k),a=$=>{const{blocks:k}=o,{hash:S,parent:I}=$,B={...$,children:new Set,usages:new Set};return k.set(S,B),k.get(I)?.children.add(S),B},l=()=>{o.best=o.finalized;let $=0;const{finalized:k,blocks:S}=o;i(k).map(I=>S.get(I)).forEach(I=>{I.number>$&&($=I.number,o.best=I.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(I=>{h(I,k)})),k},p=new ve,f=$=>p.error($),d=t.pipe(Xs(($,k)=>{const{hash:S}=$;return k||(a($),o.finalized=o.best=$.hash),o.blocks.has(S)?W(S):p.pipe(ge(I=>I===S),Gs(0),Z(1))}),bt());e.subscribe($=>{const{parent:k,hash:S,number:I}=$;o.blocks.has(S)||!I||(o.blocks.has(k)?(a($),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(B=>{let _=c.get(B.hash);if(!_)return!1;_.header=B;const T=o.blocks.get(o.finalized);if(T&&B.number<=T.number){for(;c.has(_.header?.parent??"");)_=c.get(_.header.parent);return u(_.hash),!1}if(o.blocks.has(B.parent)){let ee=o.blocks.get(B.parent);const ue=ee.number-T.number;for(let Ee=0;Ee<ue;Ee++){const ot=o.blocks.get(ee.parent);if(!ot)break;ee=ot}return ee===T?h(B.hash).forEach(Ee=>{c.delete(Ee.hash),a(Ee),p.next(Ee.hash)}):u(B.hash),!1}const j=c.get(B.parent);return j?(j.children.add(B.hash),!1):(c.set(B.parent,{hash:B.parent,header:null,children:new Set([B.hash])}),!0)})).subscribe({error:f})),c.get(k).children.add(S)))},f);const v=()=>{const $=[],k=[],{blocks:S,finalized:I,prevFin:B}=o;let _=S.get(I),T=S.get(_.parent);for(;T&&(k.push(_.hash),T.children.forEach(j=>{j!==_.hash&&i(j,$)}),_=T,_.hash!==B);)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,I=S.get($);if(!I||I.usages.size>0)return;const{parent:B,children:_}=I;k!==!0&&_.forEach(T=>m(T,!1)),k!==!1&&m(B,!0),(!S.has(B)||!I.children.size)&&(S.get(B)?.children.delete($),S.delete($))},g=Ve(p.pipe(x($=>({type:"new",value:o.blocks.get($)}))),d.pipe(x($=>({type:"fin",value:$})))).pipe(U($=>{if($.type==="new"){const I=$.value,{hash:B}=I;a(I);const _=[y(B)];return I.number>o.blocks.get(o.best).number&&(o.best=B,_.push({event:"bestBlockChanged",bestBlockHash:B})),_}o.prevFin=o.finalized,o.finalized=$.value;let k=o.best;l();const S=[v()];return k!==o.best&&S.unshift({event:"bestBlockChanged",bestBlockHash:o.best}),S}),bt()),w=Kt(()=>o.blocks.size?[null]:d.pipe(Z(1),x(()=>null))).pipe(tr),E=d.pipe(x($=>o.blocks.get($)),tr);return Ve(g,E).subscribe({error:f}),{clean:()=>{c.clear(),o.blocks.clear()},upstream:$=>{const k=()=>{const{blocks:B,finalized:_}=o,T=[];let j=B.get(_);for(;j&&T.length<10;)T.push(j.hash),j.usages.add($),j=B.get(j.parent);return T.reverse(),{event:"initialized",finalizedBlockHashes:T}},S=B=>{const _=o.blocks.get(B);_&&(_.usages.delete($),m(B))},I=w.pipe(U(()=>{const{best:B,finalized:_}=o,T=i(_).slice(1).map(y);return T.push({event:"bestBlockChanged",bestBlockHash:B}),[k(),...T]}));return{blocks$:ct(I,g).pipe(Xt({subscribe:()=>{b.add($)},finalize:()=>{b.delete($)}}),bt()),getHeader:B=>o.blocks.get(B)?.header??null,isPinned:B=>!!o.blocks.get(B)?.usages.has($),unpin:S}},finalized$:E,getHeader$:$=>{const k=o.blocks.get($);return k?W(k):n($)},hasher$:r}},ja=e=>({parentHash:t,number:n,stateRoot:r,extrinsicsRoot:s,digest:o})=>{const i=Number(n),a=o.logs.map(te),l=ae([te(t),pe.enc(i),te(r),te(s),pe.enc(o.logs.length),...a]);return{parent:t,hash:Y(e(l)),number:i,hasUpgrade:a.some(([c])=>c===8),header:Y(l)}},Na=[jt,Nn],Jp=Na.map(ja),Zp=e=>{throw new Error("Hasher not supported")},ef=e=>t=>Na[Jp.findIndex(n=>n(e).hash===t)]||Zp,tf={},nf=(e,t)=>{const n=new ve,r=n.pipe(U(h=>t("chain_getBlockHash",[h.number]).pipe(x(ef(h)))),tr),s=r.pipe(x(ja),tr),o=Es(us(s),x(([h,p])=>h(p))),i=(h,p,f=!1)=>new D(d=>{const v=m=>{d.error(m)};let b=null,y=f;return e(h,[],{onSuccess:(m,g)=>{const w=g(m,{next:$=>{y&&(y=!1,n.next($),n.complete()),d.next($)},error:v}),E=()=>{w();try{e(p,[m],{onError:V,onSuccess:V})}catch{}};b!==null?E():b=E},onError(){v(tf)}}),()=>{b?.(),b=V}}).pipe(o),a=i("chain_subscribeAllHeads","chain_unsubscribeAllHeads"),l=i("chain_subscribeFinalizedHeads","chain_unsubscribeFinalizedHeads",!0),c=h=>t("chain_getHeader",[h]).pipe(o),u=h=>c(h).pipe(U(p=>ct(W(p),u(p.parent))));return{allHeads$:a,finalized$:l,hasher$:r,getRecursiveHeader:u,getHeader$:c}},rf=(e,t)=>Qp(nf(e,t)),sf=e=>(t,n)=>e("state_getReadProof",[[n],t]).pipe(U(r=>{const s=Qi(r.proof);if(!s)throw new Error("Invalid Proof");const{rootHash:o,proofs:i}=s;let a=o,l=i[a],c=2;do{const u=i[a];if(!u||u.type==="Raw")break;if(l=u,a=void 0,!l.partialKey.startsWith(n.slice(c,c+l.partialKey.length)))return[];if(c+=l.partialKey.length,(l.type==="LeafWithHash"||l.type==="BranchWithHash")&&i[l.value]){a=l.value;continue}if("children"in l){const h=Object.entries(l.children).find(([,p])=>i[p]);if(h){if(h[0]!==n[c++])return[];a=h[1]}}}while(a);return[l.hash]})),of=e=>{const t=(g,w,E,$)=>e(g,w,{onSuccess:E,onError:$}),n=(g,w)=>new D(E=>t(g,w,$=>{E.next($),E.complete()},$=>{E.error($)}));let r=null;const s=()=>(r??(r=rf(e,n)),{...r,getBlocks:r.upstream}),o=()=>r?.clean(),i=(g,w,E)=>n("state_call",[w,E,g]),a=(g,w)=>{const E=k=>n("state_getKeysPaged",[w,1e3,k||void 0,g]).pipe(U(S=>{const I=S[0]===k?S.slice(1):S,B=S.length<1e3?Ne:E(S.at(-1));return Ve(W(I),B)})),$=(k,S=0)=>k.length?n("state_queryStorageAt",[k,g]).pipe(x(([{changes:I}])=>I),ie(I=>{if(S>3)throw I;const B=Math.floor(k.length/2);return Ve($(k.slice(0,B),++S),$(k.slice(B),S))})):Ne;return E().pipe(U(k=>$(k)))},l=(g,w)=>a(g,w).pipe(us(s().hasher$),x(([E,$])=>$.map(([k,S])=>[k,Y(E(te(S)))]))),c=sf(n),[u,h]=["state_getStorage","state_getStorageHash"].map(g=>(w,E)=>n(g,[E,w])),p=(g,w)=>h(g,w).pipe(ie(E=>{if(E instanceof Error&&E.message==="Method not found")return u(g,w).pipe(us(s().hasher$),x(([$,k])=>k==null?null:Qt.toHex($(Qt.fromHex(k)))));throw E})),f=n("rpc_methods",[]),d=n("system_name",[]),v=n("system_properties",[]),b=g=>n("chain_getBlock",[g]),y=g=>n("chain_getBlockHash",[g]),m=y(0);return{subscribeBlocks:s,getBlockHash$:y,stgValue:u,stgHash:p,stgDescendantValues:a,stgDescendantHashes:l,stgClosestDescendant:c,runtimeCall:i,getBody:b,chainName:d,properties:v,genesisHash:m,methods:f,request:t,obsRequest:n,clean:o}};let af=1;const en=()=>`${af++}${Date.now()}`,cf=new Set(["value","hash","closestDescendantMerkleValue","descendantsValues","descendantsHashes"]),Va=e=>Array.isArray(e)&&e.every(t=>typeof t=="object"&&typeof t.key=="string"&&cf.has(t.type)),Pa=(e,t,n)=>Ve(...n.map(({key:r,type:s})=>{switch(s){case"value":return e.stgValue(t,r).pipe(ge(Boolean),x(o=>[{key:r,value:o}]));case"hash":return e.stgHash(t,r).pipe(ge(Boolean),x(o=>[{key:r,hash:o}]));case"descendantsValues":return e.stgDescendantValues(t,r).pipe(x(o=>o.map(([i,a])=>({key:i,value:a}))));case"descendantsHashes":return e.stgDescendantHashes(t,r).pipe(x(o=>o.map(([i,a])=>({key:i,hash:a}))));case"closestDescendantMerkleValue":return e.stgClosestDescendant(t,r).pipe(ge(Boolean),x(o=>[{key:r,closestDescendantMerkleValue:o}]))}})),yn=e=>e instanceof Error?e.message:typeof e=="string"?e:"Unhandled exception",{body:lf,call:uf,finalizedHeight:df,genesisHash:hf,hashByHeight:pf,header:ff,stopStorage:vf,storage:bf}=cs,mf=(e,t,n,r)=>{const s=new Map,o=(a,l,c)=>{const u=en();a(u);const h=f=>{r("archive_v1_storageEvent",u,f)},p=Pa(e,l,c).pipe(dr(()=>{s.delete(u)})).subscribe(f=>{f.forEach(d=>h({event:"storage",...d}))},f=>{h({event:"storageError",error:yn(f)})},()=>{h({event:"storageDone"})});p.closed||s.set(u,p)},i=(a,l,c)=>{const u=v=>{t(a,v)},h=v=>{v.subscribe({next:u,error:b=>{n(a,b.code??-1,yn(b))}})},[p,f,d]=c;switch(l){case lf:return h(e.getBody(p).pipe(x(({block:v})=>v.extrinsics)));case uf:return h(e.runtimeCall(p,f,d).pipe(x(v=>({success:!0,value:v}))));case df:return h(e.subscribeBlocks().finalized$.pipe(x(v=>v.number),Z(1)));case hf:return h(e.genesisHash);case pf:return h(e.getBlockHash$(p).pipe(x(v=>[v])));case ff:return h(e.subscribeBlocks().getHeader$(p).pipe(x(v=>v.header)));case vf:{const v=s.get(p);return v?v.unsubscribe():n(a,-32602,"Invalid args")}case bf:return Va(f)?o(u,p,f):n(a,-32602,"Invalid args")}throw null};return i.stop=()=>{[...s].forEach(([,a])=>a.unsubscribe()),s.clear()},i},yf=(e,t,n)=>(r,s)=>{const[,,o]=s.split("_"),i=e[o];if(!i)throw null;i.subscribe(a=>{t(r,a)},()=>{n(r,-32602,"Invalid")})},{stop:gf,broadcast:wf}=ls,$f=(e,t)=>{const n=new Map,r=(s,o,i)=>{if(o===gf){const[a]=i;n.get(a)?.unsubscribe(),n.delete(a),t(s,null)}else if(o===wf){const a=en();n.set(a,e.obsRequest("author_submitExtrinsic",i).pipe(ie((l,c)=>ct(kn(5e3),c)),Bn(e.subscribeBlocks().finalized$.pipe(xn(),ie(()=>(n.delete(a),[null]))))).subscribe()),t(s,a)}else throw null};return r.stop=()=>{n.forEach(s=>s.unsubscribe()),n.clear()},r},{follow:Ef,header:kf,storage:Fa,body:ds,call:Wa,unfollow:xf,stopOperation:Sf,unpin:Bf}=st,If=(e,t,n,r)=>{const s=new Map,o=d=>{if(s.size===2)return n(d,-32800,"Limit reached");const v=en(),b=E=>r("chainHead_v1_followEvent",v,E),y=e.subscribeBlocks().getBlocks(v),m=new Map;s.set(v,{id:v,up:y,operations:m,cleanUp:()=>{w()}}),t(d,v);let g=null,w=()=>{w=V,g?.unsubscribe(),g=null,m.forEach(E=>{E()}),m.clear(),s.delete(v)};g=y.blocks$.subscribe({next(E){b(E)},error(){w(),b({event:"stop"})}}),g.closed&&(g=null)},i=(d,v)=>{s.get(v)?.cleanUp(),t(d,"null")},a=(d,v,b)=>{const y=s.get(v)?.operations.get(b);y&&y(),t(d,"null")},l=({up:{getHeader:d}},v,b)=>v(d(b)),c=({up:{unpin:d}},v,b)=>{(typeof b=="string"?[b]:b).forEach(d),v(null)},u=({operations:d,id:v},b,y,m,g)=>{const w=en();b({result:"started",operationId:w});const E=(k,S=!1)=>r(Wa,v,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(yn(k),!0)});$.closed||d.set(w,()=>{$.unsubscribe(),d.delete(w)})},h=({operations:d,id:v},b,y)=>{const m=en();b({result:"started",operationId:m});const g=e.getBody(y).subscribe(({block:{extrinsics:w}})=>{d.delete(m),r(ds,v,{event:"operationBodyDone",operationId:m,value:w})},w=>{d.delete(m),r(ds,v,{event:"operationError",operationId:m,error:yn(w)})});g.closed||d.set(m,()=>{g.unsubscribe(),d.delete(m)})},p=({operations:d,id:v},b,y,m)=>{const g=en();b({result:"started",operationId:g});const w=$=>{r(Fa,v,$)},E=Pa(e,y,m).pipe(dr(()=>{d.delete(g)})).subscribe($=>{w({event:"operationStorageItems",operationId:g,items:$})},$=>{w({event:"operationError",operationId:g,error:yn($)})},()=>{w({event:"operationStorageDone",operationId:g})});E.closed||d.set(g,()=>{E.unsubscribe()})},f=(d,v,b)=>{if(v===Ef)return o(d);const[y,...m]=b,g=s.get(y);if(!g)return console.log("Invalid followSubscription",d,v,b),n(d,-32602,"Ivalid followSubscription");const w=E=>{t(d,E)};switch(v){case xf:return i(d,y);case Sf:return a(d,y,m[0]);case Bf:{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(v){case kf:return l(g,w,E);case ds:return h(g,w,E);case Wa:{const[k,S]=$;return typeof k!="string"||typeof S!="string"?n(d,-32602,"Invalid args"):u(g,w,E,k,S)}case Fa:{const[k]=$;return Va(k)?p(g,w,E,k):n(d,-32602,"Invalid args")}}}}throw null};return f.stop=()=>{s.forEach(d=>{d.cleanUp()})},f},qa=new Set([st,La,cs,ls].map(e=>Object.values(e)).flat()),Af=e=>(t,n)=>{let r=V,s=V;const o=e(b=>{s(b)},b=>{r(),n(b)}),{disconnect:i,request:a}=br(b=>(s=b,o),t),l=of(a),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}})},f={chainSpec:()=>yf(l,u,h),chainHead:()=>If(l,u,h,p),archive:()=>mf(l,u,h,p),transaction:()=>$f(l,u)},d={},v=b=>b in d?d[b]:b in f?d[b]=f[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:[...qa,...$.filter(k=>!qa.has(k))]})},$=>{console.error($),h(y,-32602,"Invalid")});const[w]=m.split("_"),E=v(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(),i()}}},{follow:Of,unfollow:Cf}=st,Ka=()=>({latest:Date.now(),count:0}),_f=e=>(t,n)=>{const r=new Map,s=new Map,o=new Set;let i=Ka();const a=()=>{[r,s,o].forEach(h=>{h.clear()})},l=()=>{u(),a(),n()},{send:c,disconnect:u}=e(h=>{if("id"in h){const{id:p,result:f}=h;if(s.get(p)){s.delete(p);const d=r.get(f);if(d){r.delete(f),t(h),t(d);return}o.add(f);const v=o.size+s.size;if(v>2)console.warn(`Too many chainHead follow subscriptions (${v})`);else if(h.error){console.warn(`chainHead follow failed on the ${v} sub`),l();return}}}else{const{subscription:p,result:f}=h.params;if(f?.event==="stop"){const d=Date.now()-i.latest;i.latest+=d,i.count=d<1e3?i.count+1:1,o.has(p)?o.delete(p):r.set(p,h)}}t(h),i.count>2&&(i=Ka(),l())},h=>{a(),n(h)});return{send(h){const{method:p}=h;p===Of?s.set(h.id,h):p===Cf&&o.delete(h.params[0]),c(h)},disconnect:u}},{follow:Rf,unpin:Tf,unfollow:Hf}=st,Mf=e=>(t,n)=>{const r=new Set,s=new Map,o=new Map,i=c=>(...u)=>{[r,s,o].forEach(h=>{h.clear()}),c(...u)},{send:a,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 f=c.params.result,{event:d}=f;if(d==="initialized"&&f.finalizedBlockHashes.forEach(v=>{h.add(v)}),d==="newBlock"){const{parentBlockHash:v}=f;if(!h.has(v)){const m=p.get(v)??[];m.push(c),p.set(v,m);return}const b=f.blockHash;h.add(f.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)}},i(n));return{send:c=>{const u=c.params[0];switch(c.method){case Rf:r.add(c.id);break;case Tf:const[h,p]=c.params;p.forEach(f=>{s.get(h)?.delete(f),o.get(h)?.delete(f)});break;case Hf:s.delete(u),o.delete(u);break}a(c)},disconnect:i(l)}},{follow:Uf,unpin:zf,unfollow:Df}=st,Lf=e=>(t,n)=>{const r=new Set,s=new Map,o=new Map,i=c=>(...u)=>{[r,s,o].forEach(h=>{h.clear()}),c(...u)},{send:a,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 f=c.params.result,{event:d}=f;if(d==="initialized"&&f.finalizedBlockHashes.forEach(v=>{h.add(v)}),d==="finalized"&&(f.prunedBlockHashes=f.prunedBlockHashes.filter(v=>h.has(v))),d==="newBlock"){h.add(f.blockHash);const v=f.blockHash,b=p.get(v);if(b){p.delete(v),t(c),Promise.resolve().then(()=>{t(b)});return}}if(d==="bestBlockChanged"){const v=f.bestBlockHash;if(!h.has(v)){o.get(u).set(v,c);return}}d==="stop"&&(h.delete(u),o.delete(u))}t(c)}},i(n));return{send:c=>{const u=c.params[0];switch(c.method){case Uf:r.add(c.id);break;case zf:const[h,p]=c.params;p.forEach(f=>{s.get(h)?.delete(f),o.get(h)?.delete(f)});break;case Df:s.delete(u),o.delete(u);break}a(c)},disconnect:i(l)}},{follow:jf,body:Nf,call:Vf,storage:Pf,unfollow:Ff,stopOperation:Wf}=st,qf=new Set(["BodyDone","CallDone","StorageDone","Inaccessible","Error"].map(e=>"operation"+e)),Xa=e=>qf.has(e.params?.result?.event),Kf=e=>(t,n)=>{const r=new Set,s=new Map,o=new Map,i=new Map,a=u=>(...h)=>{[r,s,o,i].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),i.set(p,new Map);return}const f=s.get(h);if(f!==void 0){s.delete(h);const d=u.result?.operationId;if(d!==void 0&&o.has(f)){const v=o.get(f);v.add(d);const b=i.get(f)?.get(d);b&&(b.forEach(t),i.get(f).delete(d),Xa(b.at(-1))&&v.delete(d))}}}else{const{subscription:h,result:p}=u.params,f=o.get(h);if(f){const{operationId:d}=u.params.result;if(d!==void 0)if(f.has(d))Xa(u)&&f.delete(d);else{const v=i.get(h),b=v.get(d)??[];b.push(u),v.set(d,b);return}else p?.event==="stop"&&(o.delete(h),i.delete(h))}t(u)}},a(n));return{send:u=>{const h=u.params[0];switch(u.method){case jf:r.add(u.id);break;case Nf:case Vf:case Pf:s.set(u.id,h);break;case Ff:o.delete(h),i.delete(h);break;case Wf:o.get(h)?.delete(u.params[1])}l(u)},disconnect:a(c)}},Xf=e=>(t,n)=>e(r=>{const s=r.params?.result;if(!("id"in r)&&s){const{prunedBlockHashes:o,finalizedBlockHash:i,event:a}=s;a==="finalized"&&Array.isArray(o)?s.prunedBlockHashes=[...new Set(s.prunedBlockHashes)]:a==="initialized"&&i&&(s.finalizedBlockHashes=[s.finalizedBlockHash],delete s.finalizedBlockHash)}t(r)},n),Gf=e=>(...t)=>{const{send:n,disconnect:r}=e(...t);return{send:s=>{const{method:o,params:i,id:a,...l}=s;o==st.unpin&&i&&Array.isArray(i[1])?i[1].forEach((c,u)=>{n({...l,id:u===0?a:`${a}-patched-${u}`,method:o,params:[i[0],c]})}):n(s)},disconnect:r}},hs=(...e)=>t=>e.reduce((n,r)=>r(n),t),Ga=e=>({jsonrpc:"2.0",...e}),Yf=(e,t,n,r={})=>Ga({method:"chainHead_v1_followEvent",params:{subscription:e,result:{event:t,operationId:n,...r}}}),Qf=new Set(["newBlock","bestBlockChanged","stop"]),Jf=hs(Kf,Gf,Xf,Mf,Lf,e=>(t,n)=>{const r=new Set,s=new Map,o=l=>(...c)=>{[r,s].forEach(u=>{u.clear()}),l(...c)},{send:i,disconnect:a}=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 f=setTimeout(()=>{s.delete(c),t(Yf(c,"bestBlockChanged",void 0,{bestBlockHash:h.finalizedBlockHashes.at(-1)}))},500);s.set(c,()=>{s.delete(c),clearTimeout(f)})}else Qf.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])?.()}i(l)},disconnect:o(a)}},_f),Ya=["chainHead","transaction","chainSpec","archive"].map(e=>`${e}_v1`),Zf=e=>{const t=Object.fromEntries(Ya.map(n=>[n,!!e.find(r=>r.startsWith(n))]));return n=>{const r=ev(n),s=Jf(r()),o=Af(r(i=>["chainHead_v1","archive_v1"].every(a=>!i.method.startsWith(a))));return(i,a)=>{const l=s(u=>{"error"in u&&u.error.code===-32800&&(console.warn("Max follow connections received: chainHead_v1 disabled"),t.chainHead_v1=!1),i(u)},a),c=o(i,a);return{send(u){for(const h of Ya)if(u.method.startsWith(h)){t[h]?l.send(u):c.send(u);return}l.send(u)},disconnect(){l.disconnect(),c.disconnect()}}}}},ev=e=>{const t=new ve,n=new ve;let r=0,s=null;return(o=()=>!0)=>(i,a)=>{r++,s??(s=e(h=>n.next(h),h=>t.next(h)));const l=n.pipe(ge(h=>h.id==null&&"method"in h&&o(h))).subscribe(i),c=t.subscribe(a),u=new Set;return{send(h){if(h.id==null)return s?.send(h);const p=h.id,f=n.pipe(ge(d=>d.id===p),Z(1)).subscribe(d=>{if(i(d),!f)throw new Error("unreachable");u.delete(f)});u.add(f),s?.send(h)},disconnect(){l.unsubscribe(),c.unsubscribe(),u.forEach(h=>h.unsubscribe()),r--,r===0&&(s?.disconnect(),s=null)}}}},tv=e=>t=>(n,r)=>{let s=V,o=[],i=d=>{o.push(d)},a=V,l=!0,c=()=>{l=!1,o=[],a(),c=s=u=a=V},u=d=>{c(),r(d)};const h=t(d=>s(d),d=>u(d));let{disconnect:p}=h;const{request:f}=br(d=>(s=d,{...h,disconnect:V}));return l&&(a=e(d=>{a=V,d?({send:i,disconnect:p}=d((v,b)=>(u=y=>{c(),b(y)},s=v,h))(n,r),o.forEach(i),o=[]):u()},f)),{send:d=>{i(d)},disconnect:()=>{c(),p()}}},Qa="rpc_methods",nv=e=>t=>(n,r)=>{const s={methods:e},{send:o,disconnect:i}=t(n,r);return{disconnect:i,send(a){a.id&&a.method===Qa?n(Ga({id:a.id,result:s})):o(a)}}},rv=hs(e=>(t,n)=>{let r=0;const s=new Map,o=()=>{s.clear()},{send:i,disconnect:a}=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++),i(l)},disconnect(){o(),a()}}},(e=>tv((t,n)=>{let r=0,s=V;const o=()=>{r++,s=n(Qa,[],{onSuccess:({methods:i})=>{t(hs(nv(i),e(i)))},onError:()=>{if(r>3)t(null);else{const i=setTimeout(o,500);s=()=>clearTimeout(i)}}})};return o(),()=>s()}))(Zf));var Xe=(e=>(e.CONNECTING="CONNECTING",e.CONNECTED="CONNECTED",e.ERROR="ERROR",e.CLOSE="CLOSE",e))(Xe||{}),Ge=(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))(Ge||{});let sv=0;const Ja=()=>`proxyOpaque${sv++}`,nr=e=>({jsonrpc:"2.0",...e}),ps=e=>({jsonrpc:"2.0",...e}),Za=()=>`___proxyInternalId__${Ja()}`,ov=e=>{let t={type:1,activeBroadcasts:new Map,pending:[]};const n=s=>{let o=!0;if(t.type===0){if(no(s)){const{id:i}=s,a=t.pendingBroadcasts.get(i);if(a){if(t.pendingBroadcasts.delete(i),!("result"in s))return;const l=s.result,c=t.activeBroadcasts.get(a);c?c.upToken=l:t.connection.send(nr({id:Za(),method:"transaction_v1_stop",params:[l]}));return}o=t.onGoingRequests.has(i),"result"in s&&t.onGoingRequests.get(i)?.type===0&&t.activeChainHeads.add(s.result),t.onGoingRequests.delete(s.id)}else if("params"in s){const{subscription:i,result:a}=s.params;a?.event==="stop"&&t.activeChainHeads.delete(i)}}o&&t.type!==2&&e(s)},r=s=>{if(t.type!==2){if("id"in s){const{method:o,id:i,params:a}=s,[l,,c]=o.split("_");if(l==="transaction"){if(c==="stop"){const[u]=a,h=t.activeBroadcasts.get(u);t.activeBroadcasts.delete(u),e(ps({id:i,result:null})),t.type===0&&h&&h.upToken&&t.connection.send(nr({id:i,method:o,params:[h.upToken]}));return}if(c==="broadcast"){const u=Ja();t.activeBroadcasts.set(u,{tx:a[0],synToken:u}),t.type===0&&(t.pendingBroadcasts.set(i,u),t.connection.send(s)),e(ps({id:i,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:i}=s,[a,,l]=o.split("_"),c=a==="chainHead"?l==="follow"?{type:0,msg:s}:{type:1,id:i}:{type:2,msg:s};t.onGoingRequests.set(i,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:i}=t,a=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(nr({method:"chainHead_v1_follow",params:{subscription:h,result:{event:"stop",internal:!0}}}))}),l.clear();for(const h of a.values())h.type===1?n(ps({id:h.id,error:{code:-32603,message:"Internal error"}})):r(h.msg);a.clear()};t={type:0,connection:null,activeBroadcasts:i,pendingBroadcasts:new Map,onGoingRequests:a,activeChainHeads:l},t.connection=s(n,c),i.forEach(u=>{if(t.type===0){const h=Za();t.pendingBroadcasts.set(h,u.synToken),t.connection.send(nr({id:h,method:"transaction_v1_broadcast",params:[u.tx]}))}}),o.forEach(r)}}},fs=()=>{},ec=250,iv=e=>t=>{let n=ov(t),r=Date.now(),s=0,o;const i=()=>s&&2**Math.min(5,s)*ec;let a=fs,l=()=>{const u=setTimeout(()=>{let h=!0;const p=e(f=>{h=!1,a=fs,f?n&&n.connect((d,v)=>{let b=!0;return f(d,y=>{if(b){b=!1;const m=Date.now()-r;s+=m>ec+i()?-s:1,r+=m,v(y),c()}})}):c()});h&&(a=p)},0);a=()=>clearTimeout(u)};const c=()=>{o=setTimeout(l,i())};return l(),{send(u){n?.send(u)},disconnect(){clearTimeout(o),a(),a=fs,n?.disconnect(),n=null}}},av=e=>(t,n)=>{let r=null,s=[];const o=()=>{a(),i=a=V,r=void 0,s=[]};let i=l=>{o(),n(l)},a=e(l=>{a=V,l?(r=l(t,i),s.forEach(c=>r?.send(c)),s=[]):i()});return{send:l=>{r?r.send(l):r===null&&s.push(l)},disconnect:()=>{const l=r;o(),l?.disconnect()}}},cv=(e,t,n,r)=>{const s=r?i=>r({type:i}):V,o=r?(i,a)=>r({type:i,msg:a}):V;return av(i=>{const[a,l]=e();r?.({type:Ge.CONNECTING,url:a.url});let c=()=>{c=V,d(),i(null)},u=!0,h;const p=()=>{clearTimeout(h);const[g,w]=u?[n,Ge.TIMEOUT]:[t,Ge.STALE];u=!1,h=setTimeout(()=>{s(w),c({type:Xe.ERROR,event:{type:"timeout"}})},g)},f=()=>{clearTimeout(h)};p();let d=()=>{f()};const v=g=>{r?.({type:Ge.ERROR,error:g}),c({type:Xe.ERROR,event:g})},b=g=>{s(Ge.CLOSE),c({type:Xe.CLOSE,event:g})},y=()=>{s(Ge.DISCONNECT),d();try{a.addEventListener("error",V,{once:!0}),a.close()}catch{}},m=()=>{s(Ge.CONNECTED),l(),p(),a.removeEventListener("open",m),i((g,w)=>{d=()=>{d=V,f(),a.removeEventListener("error",v),a.removeEventListener("ping",p),a.removeEventListener("message",E),a.removeEventListener("close",b)},c=$=>{c=V,d(),w($)};const E=$=>{p(),typeof $.data=="string"&&(o(Ge.IN,$.data),g(JSON.parse($.data)))};return a.addEventListener("ping",p),a.addEventListener("message",E),a.addEventListener("error",v),a.addEventListener("close",b),{send($){const k=JSON.stringify($);o(Ge.OUT,k),a.send(k)},disconnect:y}})};return d=()=>{d=V,f(),a.removeEventListener("error",v),a.removeEventListener("close",b),a.removeEventListener("open",m)},a.addEventListener("open",m),a.addEventListener("error",v),y})},lv={onStatusChanged:V,timeout:5e3,heartbeatTimeout:4e4,middleware:je},tc=(e,t)=>{const{onStatusChanged:n,timeout:r,heartbeatTimeout:s,middleware:o,logger:i}={...lv,...t},a=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:Xe.CLOSE,event:null},f;const d=m=>n(p=m),v=o(cv(()=>{f=h?.url;const m=u??a[c++%a.length];return u=void 0,d({type:Xe.CONNECTING,uri:m}),[h=new l(m),()=>{d({type:Xe.CONNECTED,uri:m})}]},s,r,i)),b=(m,g)=>v(m,w=>{d({type:Xe.ERROR,event:w}),g(w)}),y=iv(m=>{if(!f||h.url!==f)return m(b),V;const g=setTimeout(m,250,b);return()=>{clearTimeout(g)}});return Object.assign(y,{switch:m=>{p.type!==Xe.CLOSE&&(u=m,p.type!==Xe.ERROR&&h&&h.close())},getStatus:()=>p})},uv=(e,t={})=>tc(e,t),nc=(e,t={})=>tc(e,{...t,middleware:rv}),dv=(e,t={})=>{const n=nc(e,t),r=Yp(n,t);return Object.assign(r,{switch:n.switch,getStatus:n.getStatus})};it.SocketEvents=Ge,it.WsEvent=Xe,it.createWsClient=dv,it.getWsProvider=nc,it.getWsRawProvider=uv}));
|
|
4
|
+
${JSON.stringify(b)}`);return}if(m==="rpc_methods")return l.methods.subscribe(({methods:$})=>{u(y,{methods:[...qa,...$.filter(k=>!qa.has(k))]})},$=>{console.error($),h(y,-32602,"Invalid")});const[w]=m.split("_"),E=v(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(),i()}}},{follow:Of,unfollow:Cf}=st,Ka=()=>({latest:Date.now(),count:0}),_f=e=>(t,n)=>{const r=new Map,s=new Map,o=new Set;let i=Ka();const a=()=>{[r,s,o].forEach(h=>{h.clear()})},l=()=>{u(),a(),n()},{send:c,disconnect:u}=e(h=>{if("id"in h){const{id:p,result:f}=h;if(s.get(p)){s.delete(p);const d=r.get(f);if(d){r.delete(f),t(h),t(d);return}o.add(f);const v=o.size+s.size;if(v>2)console.warn(`Too many chainHead follow subscriptions (${v})`);else if(h.error){console.warn(`chainHead follow failed on the ${v} sub`),l();return}}}else{const{subscription:p,result:f}=h.params;if(f?.event==="stop"){const d=Date.now()-i.latest;i.latest+=d,i.count=d<1e3?i.count+1:1,o.has(p)?o.delete(p):r.set(p,h)}}t(h),i.count>2&&(i=Ka(),l())},h=>{a(),n(h)});return{send(h){const{method:p}=h;p===Of?s.set(h.id,h):p===Cf&&o.delete(h.params[0]),c(h)},disconnect:u}},{follow:Rf,unpin:Tf,unfollow:Hf}=st,Mf=e=>(t,n)=>{const r=new Set,s=new Map,o=new Map,i=c=>(...u)=>{[r,s,o].forEach(h=>{h.clear()}),c(...u)},{send:a,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 f=c.params.result,{event:d}=f;if(d==="initialized"&&f.finalizedBlockHashes.forEach(v=>{h.add(v)}),d==="newBlock"){const{parentBlockHash:v}=f;if(!h.has(v)){const m=p.get(v)??[];m.push(c),p.set(v,m);return}const b=f.blockHash;h.add(f.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)}},i(n));return{send:c=>{const u=c.params[0];switch(c.method){case Rf:r.add(c.id);break;case Tf:const[h,p]=c.params;p.forEach(f=>{s.get(h)?.delete(f),o.get(h)?.delete(f)});break;case Hf:s.delete(u),o.delete(u);break}a(c)},disconnect:i(l)}},{follow:Uf,unpin:zf,unfollow:Df}=st,Lf=e=>(t,n)=>{const r=new Set,s=new Map,o=new Map,i=c=>(...u)=>{[r,s,o].forEach(h=>{h.clear()}),c(...u)},{send:a,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 f=c.params.result,{event:d}=f;if(d==="initialized"&&f.finalizedBlockHashes.forEach(v=>{h.add(v)}),d==="finalized"&&(f.prunedBlockHashes=f.prunedBlockHashes.filter(v=>h.has(v))),d==="newBlock"){h.add(f.blockHash);const v=f.blockHash,b=p.get(v);if(b){p.delete(v),t(c),Promise.resolve().then(()=>{t(b)});return}}if(d==="bestBlockChanged"){const v=f.bestBlockHash;if(!h.has(v)){o.get(u).set(v,c);return}}d==="stop"&&(h.delete(u),o.delete(u))}t(c)}},i(n));return{send:c=>{const u=c.params[0];switch(c.method){case Uf:r.add(c.id);break;case zf:const[h,p]=c.params;p.forEach(f=>{s.get(h)?.delete(f),o.get(h)?.delete(f)});break;case Df:s.delete(u),o.delete(u);break}a(c)},disconnect:i(l)}},{follow:jf,body:Nf,call:Vf,storage:Pf,unfollow:Ff,stopOperation:Wf}=st,qf=new Set(["BodyDone","CallDone","StorageDone","Inaccessible","Error"].map(e=>"operation"+e)),Xa=e=>qf.has(e.params?.result?.event),Kf=e=>(t,n)=>{const r=new Set,s=new Map,o=new Map,i=new Map,a=u=>(...h)=>{[r,s,o,i].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),i.set(p,new Map);return}const f=s.get(h);if(f!==void 0){s.delete(h);const d=u.result?.operationId;if(d!==void 0&&o.has(f)){const v=o.get(f);v.add(d);const b=i.get(f)?.get(d);b&&(b.forEach(t),i.get(f).delete(d),Xa(b.at(-1))&&v.delete(d))}}}else{const{subscription:h,result:p}=u.params,f=o.get(h);if(f){const{operationId:d}=u.params.result;if(d!==void 0)if(f.has(d))Xa(u)&&f.delete(d);else{const v=i.get(h),b=v.get(d)??[];b.push(u),v.set(d,b);return}else p?.event==="stop"&&(o.delete(h),i.delete(h))}t(u)}},a(n));return{send:u=>{const h=u.params[0];switch(u.method){case jf:r.add(u.id);break;case Nf:case Vf:case Pf:s.set(u.id,h);break;case Ff:o.delete(h),i.delete(h);break;case Wf:o.get(h)?.delete(u.params[1])}l(u)},disconnect:a(c)}},Xf=e=>(t,n)=>e(r=>{const s=r.params?.result;if(!("id"in r)&&s){const{prunedBlockHashes:o,finalizedBlockHash:i,event:a}=s;a==="finalized"&&Array.isArray(o)?s.prunedBlockHashes=[...new Set(s.prunedBlockHashes)]:a==="initialized"&&i&&(s.finalizedBlockHashes=[s.finalizedBlockHash],delete s.finalizedBlockHash)}t(r)},n),Gf=e=>(...t)=>{const{send:n,disconnect:r}=e(...t);return{send:s=>{const{method:o,params:i,id:a,...l}=s;o==st.unpin&&i&&Array.isArray(i[1])?i[1].forEach((c,u)=>{n({...l,id:u===0?a:`${a}-patched-${u}`,method:o,params:[i[0],c]})}):n(s)},disconnect:r}},hs=(...e)=>t=>e.reduce((n,r)=>r(n),t),Ga=e=>({jsonrpc:"2.0",...e}),Yf=(e,t,n,r={})=>Ga({method:"chainHead_v1_followEvent",params:{subscription:e,result:{event:t,operationId:n,...r}}}),Qf=new Set(["newBlock","bestBlockChanged","stop"]),Jf=hs(Kf,Gf,Xf,Mf,Lf,e=>(t,n)=>{const r=new Set,s=new Map,o=l=>(...c)=>{[r,s].forEach(u=>{u.clear()}),l(...c)},{send:i,disconnect:a}=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 f=setTimeout(()=>{s.delete(c),t(Yf(c,"bestBlockChanged",void 0,{bestBlockHash:h.finalizedBlockHashes.at(-1)}))},500);s.set(c,()=>{s.delete(c),clearTimeout(f)})}else Qf.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])?.()}i(l)},disconnect:o(a)}},_f),Ya=["chainHead","transaction","chainSpec","archive"].map(e=>`${e}_v1`),Zf=e=>{const t=Object.fromEntries(Ya.map(n=>[n,!!e.find(r=>r.startsWith(n))]));return n=>{const r=ev(n),s=a=>["chainHead_v1","archive_v1"].some(l=>a.method.startsWith(l)),o=Jf(r(s)),i=Af(r(a=>!s(a)));return(a,l)=>{const c=o(h=>{"error"in h&&h.error.code===-32800&&(console.warn("Max follow connections received: chainHead_v1 disabled"),t.chainHead_v1=!1),a(h)},l),u=i(a,l);return{send(h){for(const p of Ya)if(h.method.startsWith(p)){t[p]?c.send(h):u.send(h);return}c.send(h)},disconnect(){c.disconnect(),u.disconnect()}}}}},ev=e=>{const t=new ve,n=new ve;let r=0,s=null;return(o=()=>!0)=>(i,a)=>{r++,s??(s=e(h=>n.next(h),h=>t.next(h)));const l=n.pipe(ge(h=>h.id==null&&"method"in h&&o(h))).subscribe(i),c=t.subscribe(a),u=new Set;return{send(h){if(h.id==null)return s?.send(h);const p=h.id,f=n.pipe(ge(d=>d.id===p),Z(1)).subscribe(d=>{if(i(d),!f)throw new Error("unreachable");u.delete(f)});u.add(f),s?.send(h)},disconnect(){l.unsubscribe(),c.unsubscribe(),u.forEach(h=>h.unsubscribe()),r--,r===0&&(s?.disconnect(),s=null)}}}},tv=e=>t=>(n,r)=>{let s=V,o=[],i=d=>{o.push(d)},a=V,l=!0,c=()=>{l=!1,o=[],a(),c=s=u=a=V},u=d=>{c(),r(d)};const h=t(d=>s(d),d=>u(d));let{disconnect:p}=h;const{request:f}=br(d=>(s=d,{...h,disconnect:V}));return l&&(a=e(d=>{a=V,d?({send:i,disconnect:p}=d((v,b)=>(u=y=>{c(),b(y)},s=v,h))(n,r),o.forEach(i),o=[]):u()},f)),{send:d=>{i(d)},disconnect:()=>{c(),p()}}},Qa="rpc_methods",nv=e=>t=>(n,r)=>{const s={methods:e},{send:o,disconnect:i}=t(n,r);return{disconnect:i,send(a){a.id&&a.method===Qa?n(Ga({id:a.id,result:s})):o(a)}}},rv=hs(e=>(t,n)=>{let r=0;const s=new Map,o=()=>{s.clear()},{send:i,disconnect:a}=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++),i(l)},disconnect(){o(),a()}}},(e=>tv((t,n)=>{let r=0,s=V;const o=()=>{r++,s=n(Qa,[],{onSuccess:({methods:i})=>{t(hs(nv(i),e(i)))},onError:()=>{if(r>3)t(null);else{const i=setTimeout(o,500);s=()=>clearTimeout(i)}}})};return o(),()=>s()}))(Zf));var Xe=(e=>(e.CONNECTING="CONNECTING",e.CONNECTED="CONNECTED",e.ERROR="ERROR",e.CLOSE="CLOSE",e))(Xe||{}),Ge=(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))(Ge||{});let sv=0;const Ja=()=>`proxyOpaque${sv++}`,nr=e=>({jsonrpc:"2.0",...e}),ps=e=>({jsonrpc:"2.0",...e}),Za=()=>`___proxyInternalId__${Ja()}`,ov=e=>{let t={type:1,activeBroadcasts:new Map,pending:[]};const n=s=>{let o=!0;if(t.type===0){if(no(s)){const{id:i}=s,a=t.pendingBroadcasts.get(i);if(a){if(t.pendingBroadcasts.delete(i),!("result"in s))return;const l=s.result,c=t.activeBroadcasts.get(a);c?c.upToken=l:t.connection.send(nr({id:Za(),method:"transaction_v1_stop",params:[l]}));return}o=t.onGoingRequests.has(i),"result"in s&&t.onGoingRequests.get(i)?.type===0&&t.activeChainHeads.add(s.result),t.onGoingRequests.delete(s.id)}else if("params"in s){const{subscription:i,result:a}=s.params;a?.event==="stop"&&t.activeChainHeads.delete(i)}}o&&t.type!==2&&e(s)},r=s=>{if(t.type!==2){if("id"in s){const{method:o,id:i,params:a}=s,[l,,c]=o.split("_");if(l==="transaction"){if(c==="stop"){const[u]=a,h=t.activeBroadcasts.get(u);t.activeBroadcasts.delete(u),e(ps({id:i,result:null})),t.type===0&&h&&h.upToken&&t.connection.send(nr({id:i,method:o,params:[h.upToken]}));return}if(c==="broadcast"){const u=Ja();t.activeBroadcasts.set(u,{tx:a[0],synToken:u}),t.type===0&&(t.pendingBroadcasts.set(i,u),t.connection.send(s)),e(ps({id:i,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:i}=s,[a,,l]=o.split("_"),c=a==="chainHead"?l==="follow"?{type:0,msg:s}:{type:1,id:i}:{type:2,msg:s};t.onGoingRequests.set(i,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:i}=t,a=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(nr({method:"chainHead_v1_follow",params:{subscription:h,result:{event:"stop",internal:!0}}}))}),l.clear();for(const h of a.values())h.type===1?n(ps({id:h.id,error:{code:-32603,message:"Internal error"}})):r(h.msg);a.clear()};t={type:0,connection:null,activeBroadcasts:i,pendingBroadcasts:new Map,onGoingRequests:a,activeChainHeads:l},t.connection=s(n,c),i.forEach(u=>{if(t.type===0){const h=Za();t.pendingBroadcasts.set(h,u.synToken),t.connection.send(nr({id:h,method:"transaction_v1_broadcast",params:[u.tx]}))}}),o.forEach(r)}}},fs=()=>{},ec=250,iv=e=>t=>{let n=ov(t),r=Date.now(),s=0,o;const i=()=>s&&2**Math.min(5,s)*ec;let a=fs,l=()=>{const u=setTimeout(()=>{let h=!0;const p=e(f=>{h=!1,a=fs,f?n&&n.connect((d,v)=>{let b=!0;return f(d,y=>{if(b){b=!1;const m=Date.now()-r;s+=m>ec+i()?-s:1,r+=m,v(y),c()}})}):c()});h&&(a=p)},0);a=()=>clearTimeout(u)};const c=()=>{o=setTimeout(l,i())};return l(),{send(u){n?.send(u)},disconnect(){clearTimeout(o),a(),a=fs,n?.disconnect(),n=null}}},av=e=>(t,n)=>{let r=null,s=[];const o=()=>{a(),i=a=V,r=void 0,s=[]};let i=l=>{o(),n(l)},a=e(l=>{a=V,l?(r=l(t,i),s.forEach(c=>r?.send(c)),s=[]):i()});return{send:l=>{r?r.send(l):r===null&&s.push(l)},disconnect:()=>{const l=r;o(),l?.disconnect()}}},cv=(e,t,n,r)=>{const s=r?i=>r({type:i}):V,o=r?(i,a)=>r({type:i,msg:a}):V;return av(i=>{const[a,l]=e();r?.({type:Ge.CONNECTING,url:a.url});let c=()=>{c=V,d(),i(null)},u=!0,h;const p=()=>{clearTimeout(h);const[g,w]=u?[n,Ge.TIMEOUT]:[t,Ge.STALE];u=!1,h=setTimeout(()=>{s(w),c({type:Xe.ERROR,event:{type:"timeout"}})},g)},f=()=>{clearTimeout(h)};p();let d=()=>{f()};const v=g=>{r?.({type:Ge.ERROR,error:g}),c({type:Xe.ERROR,event:g})},b=g=>{s(Ge.CLOSE),c({type:Xe.CLOSE,event:g})},y=()=>{s(Ge.DISCONNECT),d();try{a.addEventListener("error",V,{once:!0}),a.close()}catch{}},m=()=>{s(Ge.CONNECTED),l(),p(),a.removeEventListener("open",m),i((g,w)=>{d=()=>{d=V,f(),a.removeEventListener("error",v),a.removeEventListener("ping",p),a.removeEventListener("message",E),a.removeEventListener("close",b)},c=$=>{c=V,d(),w($)};const E=$=>{p(),typeof $.data=="string"&&(o(Ge.IN,$.data),g(JSON.parse($.data)))};return a.addEventListener("ping",p),a.addEventListener("message",E),a.addEventListener("error",v),a.addEventListener("close",b),{send($){const k=JSON.stringify($);o(Ge.OUT,k),a.send(k)},disconnect:y}})};return d=()=>{d=V,f(),a.removeEventListener("error",v),a.removeEventListener("close",b),a.removeEventListener("open",m)},a.addEventListener("open",m),a.addEventListener("error",v),y})},lv={onStatusChanged:V,timeout:5e3,heartbeatTimeout:4e4,middleware:je},tc=(e,t)=>{const{onStatusChanged:n,timeout:r,heartbeatTimeout:s,middleware:o,logger:i}={...lv,...t},a=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:Xe.CLOSE,event:null},f;const d=m=>n(p=m),v=o(cv(()=>{f=h?.url;const m=u??a[c++%a.length];return u=void 0,d({type:Xe.CONNECTING,uri:m}),[h=new l(m),()=>{d({type:Xe.CONNECTED,uri:m})}]},s,r,i)),b=(m,g)=>v(m,w=>{d({type:Xe.ERROR,event:w}),g(w)}),y=iv(m=>{if(!f||h.url!==f)return m(b),V;const g=setTimeout(m,250,b);return()=>{clearTimeout(g)}});return Object.assign(y,{switch:m=>{p.type!==Xe.CLOSE&&(u=m,p.type!==Xe.ERROR&&h&&h.close())},getStatus:()=>p})},uv=(e,t={})=>tc(e,t),nc=(e,t={})=>tc(e,{...t,middleware:rv}),dv=(e,t={})=>{const n=nc(e,t),r=Yp(n,t);return Object.assign(r,{switch:n.switch,getStatus:n.getStatus})};it.SocketEvents=Ge,it.WsEvent=Xe,it.createWsClient=dv,it.getWsProvider=nc,it.getWsRawProvider=uv}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polkadot-api",
|
|
3
|
-
"version": "2.1.6
|
|
3
|
+
"version": "2.1.6",
|
|
4
4
|
"author": "Josep M Sobrepere (https://github.com/josepot)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -113,28 +113,28 @@
|
|
|
113
113
|
},
|
|
114
114
|
"dependencies": {
|
|
115
115
|
"@rx-state/core": "^0.1.4",
|
|
116
|
-
"@polkadot-api/cli": "0.21.5
|
|
117
|
-
"@polkadot-api/ink-contracts": "0.6.
|
|
118
|
-
"@polkadot-api/
|
|
119
|
-
"@polkadot-api/
|
|
120
|
-
"@polkadot-api/logs-provider": "0.2.
|
|
121
|
-
"@polkadot-api/metadata-compatibility": "0.6.
|
|
122
|
-
"@polkadot-api/metadata-builders": "0.14.
|
|
123
|
-
"@polkadot-api/
|
|
124
|
-
"@polkadot-api/
|
|
125
|
-
"@polkadot-api/signer": "0.3
|
|
126
|
-
"@polkadot-api/
|
|
127
|
-
"@polkadot-api/
|
|
128
|
-
"@polkadot-api/
|
|
129
|
-
"@polkadot-api/
|
|
130
|
-
"@polkadot-api/substrate-client": "0.7.
|
|
131
|
-
"@polkadot-api/ws-middleware": "0.3.5
|
|
132
|
-
"@polkadot-api/
|
|
133
|
-
"@polkadot-api/
|
|
116
|
+
"@polkadot-api/cli": "0.21.5",
|
|
117
|
+
"@polkadot-api/ink-contracts": "0.6.3",
|
|
118
|
+
"@polkadot-api/json-rpc-provider": "0.2.0",
|
|
119
|
+
"@polkadot-api/known-chains": "0.11.5",
|
|
120
|
+
"@polkadot-api/logs-provider": "0.2.0",
|
|
121
|
+
"@polkadot-api/metadata-compatibility": "0.6.3",
|
|
122
|
+
"@polkadot-api/metadata-builders": "0.14.3",
|
|
123
|
+
"@polkadot-api/observable-client": "0.18.7",
|
|
124
|
+
"@polkadot-api/signer": "0.3.3",
|
|
125
|
+
"@polkadot-api/pjs-signer": "0.7.3",
|
|
126
|
+
"@polkadot-api/polkadot-signer": "0.1.6",
|
|
127
|
+
"@polkadot-api/smoldot": "0.4.5",
|
|
128
|
+
"@polkadot-api/sm-provider": "0.3.6",
|
|
129
|
+
"@polkadot-api/substrate-bindings": "0.20.3",
|
|
130
|
+
"@polkadot-api/substrate-client": "0.7.0",
|
|
131
|
+
"@polkadot-api/ws-middleware": "0.3.5",
|
|
132
|
+
"@polkadot-api/utils": "0.4.0",
|
|
133
|
+
"@polkadot-api/ws-provider": "0.9.0"
|
|
134
134
|
},
|
|
135
135
|
"devDependencies": {
|
|
136
136
|
"rxjs": "^7.8.2",
|
|
137
|
-
"@polkadot-api/codegen": "0.22.
|
|
137
|
+
"@polkadot-api/codegen": "0.22.5"
|
|
138
138
|
},
|
|
139
139
|
"scripts": {
|
|
140
140
|
"build-core": "tsc --noEmit && rollup -c",
|