polkadot-api 2.0.2-canary.552fbc3 → 2.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { getCli, ink, update, remove, generate, add } from '@polkadot-api/cli';
3
3
 
4
- var version = "2.0.1";
4
+ var version = "2.0.2";
5
5
 
6
6
  getCli({
7
7
  add,
@@ -1,4 +1,4 @@
1
- (function(it,Ct){typeof exports=="object"&&typeof module<"u"?Ct(exports):typeof define=="function"&&define.amd?define(["exports"],Ct):(it=typeof globalThis<"u"?globalThis:it||self,Ct(it.papiWs={}))})(this,(function(it){"use strict";var Ct=function(e,t){return Ct=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=r[s])},Ct(e,t)};function Ge(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Ct(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}function dc(e,t,n,r){function s(o){return o instanceof n?o:new n(function(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 ps(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 hc(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),s,o=[];return s=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",i),s[Symbol.asyncIterator]=function(){return this},s;function i(v){return function(d){return Promise.resolve(d).then(v,h)}}function a(v,d){r[v]&&(s[v]=function(f){return new Promise(function(b,y){o.push([v,f,b,y])>1||l(v,f)})},d&&(s[v]=d(s[v])))}function l(v,d){try{c(r[v](d))}catch(f){p(o[0][3],f)}}function c(v){v.value instanceof Wt?Promise.resolve(v.value.v).then(u,h):p(o[0][2],v)}function u(v){l("next",v)}function h(v){l("throw",v)}function p(v,d){v(d),o.shift(),o.length&&l(o[0][0],o[0][1])}}function pc(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof 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 rr(e){var t=function(r){Error.call(r),r.stack=new Error().stack},n=e(t);return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var sr=rr(function(e){return function(n){e(this),this.message=n?n.length+` errors occurred during unsubscription:
1
+ (function(it,Ct){typeof exports=="object"&&typeof module<"u"?Ct(exports):typeof define=="function"&&define.amd?define(["exports"],Ct):(it=typeof globalThis<"u"?globalThis:it||self,Ct(it.papiWs={}))})(this,(function(it){"use strict";var Ct=function(e,t){return Ct=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=r[s])},Ct(e,t)};function Ge(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");Ct(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}function dc(e,t,n,r){function s(o){return o instanceof n?o:new n(function(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 fs(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 hc(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),s,o=[];return s=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",i),s[Symbol.asyncIterator]=function(){return this},s;function i(v){return function(d){return Promise.resolve(d).then(v,h)}}function a(v,d){r[v]&&(s[v]=function(f){return new Promise(function(b,y){o.push([v,f,b,y])>1||l(v,f)})},d&&(s[v]=d(s[v])))}function l(v,d){try{c(r[v](d))}catch(f){p(o[0][3],f)}}function c(v){v.value instanceof Wt?Promise.resolve(v.value.v).then(u,h):p(o[0][2],v)}function u(v){l("next",v)}function h(v){l("throw",v)}function p(v,d){v(d),o.shift(),o.length&&l(o[0][0],o[0][1])}}function pc(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof 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 rr(e){var t=function(r){Error.call(r),r.stack=new Error().stack},n=e(t);return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var sr=rr(function(e){return function(n){e(this),this.message=n?n.length+` errors occurred during unsubscription:
2
2
  `+n.map(function(r,s){return s+1+") "+r.toString()}).join(`
3
- `):"",this.name="UnsubscriptionError",this.errors=n}});function yn(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var _t=(function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,n,r,s,o;if(!this.closed){this.closed=!0;var 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(f){t={error:f}}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(f){o=f instanceof sr?f.errors:[f]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var p=Ft(h),v=p.next();!v.done;v=p.next()){var d=v.value;try{bs(d)}catch(f){o=o??[],f instanceof sr?o=Me(Me([],He(o)),He(f.errors)):o.push(f)}}}catch(f){r={error:f}}finally{try{v&&!v.done&&(s=p.return)&&s.call(p)}finally{if(r)throw r.error}}}if(o)throw new sr(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)bs(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(t)}},e.prototype._hasParent=function(t){var n=this._parentage;return n===t||Array.isArray(n)&&n.includes(t)},e.prototype._addParent=function(t){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(t),n):n?[n,t]:t},e.prototype._removeParent=function(t){var n=this._parentage;n===t?this._parentage=null:Array.isArray(n)&&yn(n,t)},e.prototype.remove=function(t){var n=this._finalizers;n&&yn(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=(function(){var t=new e;return t.closed=!0,t})(),e})(),fs=_t.EMPTY;function vs(e){return e instanceof _t||e&&"closed"in e&&Q(e.remove)&&Q(e.add)&&Q(e.unsubscribe)}function bs(e){Q(e)?e():e.unsubscribe()}var fc={Promise:void 0},vc={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,Me([e,t],He(n)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function ms(e){vc.setTimeout(function(){throw e})}function Ee(){}function gn(e){e()}var Zt=(function(e){Ge(t,e);function t(n){var r=e.call(this)||this;return r.isStopped=!1,n?(r.destination=n,vs(n)&&n.add(r)):r.destination=yc,r}return t.create=function(n,r,s){return new 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})(_t),bc=(function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var n=this.partialObserver;if(n.next)try{n.next(t)}catch(r){wn(r)}},e.prototype.error=function(t){var n=this.partialObserver;if(n.error)try{n.error(t)}catch(r){wn(r)}else wn(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(n){wn(n)}},e})(),qt=(function(e){Ge(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 bc(i),o}return t})(Zt);function wn(e){ms(e)}function mc(e){throw e}var yc={closed:!0,next:Ee,error:mc,complete:Ee},or=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function je(e){return e}function ys(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return gs(e)}function gs(e){return e.length===0?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=wc(t)?t:new qt(t,n,r);return gn(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=ws(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[or]=function(){return this},e.prototype.pipe=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return gs(t)(this)},e.prototype.toPromise=function(t){var n=this;return t=ws(t),new t(function(r,s){var o;n.subscribe(function(i){return o=i},function(i){return s(i)},function(){return r(o)})})},e.create=function(t){return new e(t)},e})();function ws(e){var t;return(t=e??fc.Promise)!==null&&t!==void 0?t:Promise}function gc(e){return e&&Q(e.next)&&Q(e.error)&&Q(e.complete)}function wc(e){return e&&e instanceof Zt||gc(e)&&vs(e)}function $c(e){return Q(e?.lift)}function J(e){return function(t){if($c(t))return t.lift(function(n){try{return e(n,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function G(e,t,n,r,s){return new Ec(e,t,n,r,s)}var Ec=(function(e){Ge(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})(Zt),kc=rr(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),ye=(function(e){Ge(t,e);function t(){var n=e.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return t.prototype.lift=function(n){var r=new $s(this,this);return r.operator=n,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new kc},t.prototype.next=function(n){var r=this;gn(function(){var s,o;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var 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;gn(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=n;for(var s=r.observers;s.length;)s.shift().error(n)}})},t.prototype.complete=function(){var n=this;gn(function(){if(n._throwIfClosed(),!n.isStopped){n.isStopped=!0;for(var r=n.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var n;return((n=this.observers)===null||n===void 0?void 0:n.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(n){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,n)},t.prototype._subscribe=function(n){return this._throwIfClosed(),this._checkFinalizedStatuses(n),this._innerSubscribe(n)},t.prototype._innerSubscribe=function(n){var r=this,s=this,o=s.hasError,i=s.isStopped,a=s.observers;return o||i?fs:(this.currentObservers=null,a.push(n),new _t(function(){r.currentObservers=null,yn(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 $s(n,r)},t})(D),$s=(function(e){Ge(t,e);function t(n,r){var s=e.call(this)||this;return s.destination=n,s.source=r,s}return t.prototype.next=function(n){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.next)===null||s===void 0||s.call(r,n)},t.prototype.error=function(n){var r,s;(s=(r=this.destination)===null||r===void 0?void 0:r.error)===null||s===void 0||s.call(r,n)},t.prototype.complete=function(){var n,r;(r=(n=this.destination)===null||n===void 0?void 0:n.complete)===null||r===void 0||r.call(n)},t.prototype._subscribe=function(n){var r,s;return(s=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&s!==void 0?s:fs},t})(ye),xc=(function(e){Ge(t,e);function t(n){var r=e.call(this)||this;return r._value=n,r}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(n){var r=e.prototype._subscribe.call(this,n);return!r.closed&&n.next(this._value),r},t.prototype.getValue=function(){var n=this,r=n.hasError,s=n.thrownError,o=n._value;if(r)throw s;return this._throwIfClosed(),o},t.prototype.next=function(n){e.prototype.next.call(this,this._value=n)},t})(ye),ir={now:function(){return(ir.delegate||Date).now()},delegate:void 0},en=(function(e){Ge(t,e);function t(n,r,s){n===void 0&&(n=1/0),r===void 0&&(r=1/0),s===void 0&&(s=ir);var o=e.call(this)||this;return o._bufferSize=n,o._windowTime=r,o._timestampProvider=s,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=r===1/0,o._bufferSize=Math.max(1,n),o._windowTime=Math.max(1,r),o}return t.prototype.next=function(n){var r=this,s=r.isStopped,o=r._buffer,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})(ye),Sc=(function(e){Ge(t,e);function t(n,r){return e.call(this)||this}return t.prototype.schedule=function(n,r){return this},t})(_t),Es={setInterval:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setInterval.apply(void 0,Me([e,t],He(n)))},clearInterval:function(e){return clearInterval(e)},delegate:void 0},Ic=(function(e){Ge(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),Es.setInterval(n.flush.bind(n,this),s)},t.prototype.recycleAsyncId=function(n,r,s){if(s===void 0&&(s=0),s!=null&&this.delay===s&&this.pending===!1)return r;r!=null&&Es.clearInterval(r)},t.prototype.execute=function(n,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var s=this._execute(n,r);if(s)return s;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(n,r){var s=!1,o;try{this.work(n)}catch(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,yn(o,this),r!=null&&(this.id=this.recycleAsyncId(s,r,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},t})(Sc),ks=(function(){function e(t,n){n===void 0&&(n=e.now),this.schedulerActionCtor=t,this.now=n}return e.prototype.schedule=function(t,n,r){return n===void 0&&(n=0),new this.schedulerActionCtor(this,t).schedule(r,n)},e.now=ir.now,e})(),Bc=(function(e){Ge(t,e);function t(n,r){r===void 0&&(r=ks.now);var s=e.call(this,n,r)||this;return s.actions=[],s._active=!1,s}return t.prototype.flush=function(n){var r=this.actions;if(this._active){r.push(n);return}var s;this._active=!0;do if(s=n.execute(n.state,n.delay))break;while(n=r.shift());if(this._active=!1,s){for(;n=r.shift();)n.unsubscribe();throw s}},t})(ks),xs=new Bc(Ic),Ac=xs,Ye=new D(function(e){return e.complete()});function Oc(e){return e&&Q(e.schedule)}function ar(e){return e[e.length-1]}function cr(e){return Q(ar(e))?e.pop():void 0}function tn(e){return Oc(ar(e))?e.pop():void 0}function Cc(e,t){return typeof ar(e)=="number"?e.pop():t}var Ss=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function Is(e){return Q(e?.then)}function Bs(e){return Q(e[or])}function As(e){return Symbol.asyncIterator&&Q(e?.[Symbol.asyncIterator])}function Os(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function _c(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Cs=_c();function _s(e){return Q(e?.[Cs])}function Rs(e){return hc(this,arguments,function(){var n,r,s,o;return ps(this,function(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 Ts(e){return Q(e?.getReader)}function le(e){if(e instanceof D)return e;if(e!=null){if(Bs(e))return Rc(e);if(Ss(e))return Tc(e);if(Is(e))return Hc(e);if(As(e))return Hs(e);if(_s(e))return Mc(e);if(Ts(e))return Uc(e)}throw Os(e)}function Rc(e){return new D(function(t){var n=e[or]();if(Q(n.subscribe))return n.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Tc(e){return new D(function(t){for(var n=0;n<e.length&&!t.closed;n++)t.next(e[n]);t.complete()})}function Hc(e){return new D(function(t){e.then(function(n){t.closed||(t.next(n),t.complete())},function(n){return t.error(n)}).then(null,ms)})}function Mc(e){return new D(function(t){var n,r;try{for(var s=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 Hs(e){return new D(function(t){zc(e,t).catch(function(n){return t.error(n)})})}function Uc(e){return Hs(Rs(e))}function zc(e,t){var n,r,s,o;return dc(this,void 0,void 0,function(){var i,a;return ps(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),n=pc(e),l.label=1;case 1:return[4,n.next()];case 2:if(r=l.sent(),!!r.done)return[3,4];if(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 Ms(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 Us(e,t){return t===void 0&&(t=0),J(function(n,r){r.add(e.schedule(function(){return n.subscribe(r)},t))})}function Dc(e,t){return le(e).pipe(Us(t),Ms(t))}function Lc(e,t){return le(e).pipe(Us(t),Ms(t))}function jc(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 Nc(e,t){return new D(function(n){var r;return ft(n,t,function(){r=e[Cs](),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 zs(e,t){if(!e)throw new Error("Iterable cannot be null");return new D(function(n){ft(n,t,function(){var r=e[Symbol.asyncIterator]();ft(n,t,function(){r.next().then(function(s){s.done?n.complete():n.next(s.value)})},0,!0)})})}function Vc(e,t){return zs(Rs(e),t)}function Pc(e,t){if(e!=null){if(Bs(e))return Dc(e,t);if(Ss(e))return jc(e,t);if(Is(e))return Lc(e,t);if(As(e))return zs(e,t);if(_s(e))return Nc(e,t);if(Ts(e))return Vc(e,t)}throw Os(e)}function vt(e,t){return t?Pc(e,t):le(e)}function K(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=tn(e);return vt(e,n)}function Rt(e,t){var n=Q(e)?e:function(){return e},r=function(s){return s.error(n())};return new D(r)}var Ds=rr(function(e){return function(){e(this),this.name="EmptyError",this.message="no elements in sequence"}});function Fc(e,t){return new Promise(function(n,r){var s=!1,o;e.subscribe({next:function(i){o=i,s=!0},error:r,complete:function(){s?n(o):r(new Ds)}})})}function at(e,t){return new Promise(function(n,r){var s=new qt({next:function(o){n(o),s.unsubscribe()},error:r,complete:function(){r(new Ds)}});e.subscribe(s)})}function Wc(e){return e instanceof Date&&!isNaN(e)}function x(e,t){return J(function(n,r){var s=0;n.subscribe(G(r,function(o){r.next(e.call(t,o,s++))}))})}var qc=Array.isArray;function Kc(e,t){return qc(t)?e.apply(void 0,Me([],He(t))):e(t)}function Ls(e){return x(function(t){return Kc(e,t)})}var Xc=Array.isArray,Gc=Object.getPrototypeOf,Yc=Object.prototype,Qc=Object.keys;function Jc(e){if(e.length===1){var t=e[0];if(Xc(t))return{args:t,keys:null};if(Zc(t)){var n=Qc(t);return{args:n.map(function(r){return t[r]}),keys:n}}}return{args:e,keys:null}}function Zc(e){return e&&typeof e=="object"&&Gc(e)===Yc}function el(e,t){return e.reduce(function(n,r,s){return n[r]=t[s],n},{})}function ue(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=tn(e),r=cr(e),s=Jc(e),o=s.args,i=s.keys;if(o.length===0)return vt([],n);var a=new D(js(o,n,i?function(l){return el(i,l)}:je));return r?a.pipe(Ls(r)):a}function js(e,t,n){return n===void 0&&(n=je),function(r){Ns(t,function(){for(var s=e.length,o=new Array(s),i=s,a=s,l=function(u){Ns(t,function(){var h=vt(e[u],t),p=!1;h.subscribe(G(r,function(v){o[u]=v,p||(p=!0,a--),a||r.next(n(o.slice()))},function(){--i||r.complete()}))},r)},c=0;c<s;c++)l(c)},r)}}function Ns(e,t,n){e?ft(n,e,t):t()}function tl(e,t,n,r,s,o,i,a){var l=[],c=0,u=0,h=!1,p=function(){h&&!l.length&&!c&&t.complete()},v=function(f){return c<r?d(f):l.push(f)},d=function(f){c++;var b=!1;le(n(f,u++)).subscribe(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,v,function(){h=!0,p()})),function(){}}function z(e,t,n){return n===void 0&&(n=1/0),Q(t)?z(function(r,s){return x(function(o,i){return t(r,o,s,i)})(le(e(r,s)))},n):(typeof t=="number"&&(n=t),J(function(r,s){return tl(r,s,e,n)}))}function $n(e){return e===void 0&&(e=1/0),z(je,e)}function nl(){return $n(1)}function ct(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return nl()(vt(e,tn(e)))}function nn(e){return new D(function(t){le(e()).subscribe(t)})}function En(e,t,n){return e===void 0&&(e=0),n===void 0&&(n=Ac),new D(function(r){var s=Wc(e)?+e-n.now():e;s<0&&(s=0);var o=0;return n.schedule(function(){r.closed||(r.next(o++),r.complete())},s)})}function Qe(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=tn(e),r=Cc(e,1/0),s=e;return s.length?s.length===1?le(s[0]):$n(r)(vt(s,n)):Ye}var rl=new D(Ee),sl=Array.isArray;function Vs(e){return e.length===1&&sl(e[0])?e[0]:e}function Be(e,t){return J(function(n,r){var s=0;n.subscribe(G(r,function(o){return e.call(t,o,s++)&&r.next(o)}))})}function ol(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e=Vs(e),e.length===1?le(e[0]):new D(il(e))}function il(e){return function(t){for(var n=[],r=function(o){n.push(le(e[o]).subscribe(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 de(e){return J(function(t,n){var r=null,s=!1,o;r=t.subscribe(G(n,void 0,void 0,function(i){o=le(e(i,de(e)(t))),r?(r.unsubscribe(),r=null,o.subscribe(n)):s=!0})),s&&(r.unsubscribe(),r=null,o.subscribe(n))})}function al(e,t,n,r,s){return function(o,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 Ps(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=cr(e);return n?ys(Ps.apply(void 0,Me([],He(e))),Ls(n)):J(function(r,s){js(Me([r],He(Vs(e))))(s)})}function cl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Ps.apply(void 0,Me([],He(e)))}function Fs(e,t){return Q(t)?z(e,t,1):z(e,1)}function Ws(e,t){return t===void 0&&(t=xs),J(function(n,r){var s=null,o=null,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 te(e){return e<=0?function(){return Ye}:J(function(t,n){var r=0;t.subscribe(G(n,function(s){++r<=e&&(n.next(s),e<=r&&n.complete())}))})}function kn(){return J(function(e,t){e.subscribe(G(t,Ee))})}function ll(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&&le(t).subscribe(G(r,function(){return s.clear()},Ee))})}function he(e,t){return t===void 0&&(t=je),e=e??ul,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 ul(e,t){return e===t}function qs(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(n){return ct(n,K.apply(void 0,Me([],He(e))))}}function dl(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()}),le(e(a,s++)).subscribe(o))},function(){i=!0,!o&&r.complete()}))})}function lr(e){return J(function(t,n){try{t.subscribe(n)}finally{n.add(e)}})}function hl(){return J(function(e,t){var n,r=!1;e.subscribe(G(t,function(s){var o=n;n=s,r&&t.next([o,s]),r=!0}))})}function rn(e,t){return J(al(e,t,arguments.length>=2,!0))}function bt(e){e===void 0&&(e={});var t=e.connector,n=t===void 0?function(){return new ye}:t,r=e.resetOnError,s=r===void 0?!0:r,o=e.resetOnComplete,i=o===void 0?!0:o,a=e.resetOnRefCountZero,l=a===void 0?!0:a;return function(c){var u,h,p,v=0,d=!1,f=!1,b=function(){h?.unsubscribe(),h=void 0},y=function(){b(),u=p=void 0,d=f=!1},m=function(){var g=u;y(),g?.unsubscribe()};return J(function(g,w){v++,!f&&!d&&b();var E=p=p??n();w.add(function(){v--,v===0&&!f&&!d&&(h=ur(m,l))}),E.subscribe(w),!u&&v>0&&(u=new qt({next:function($){return E.next($)},error:function($){f=!0,b(),h=ur(y,s,$),E.error($)},complete:function(){d=!0,b(),h=ur(y,i),E.complete()}}),le(g).subscribe(u))})(c)}}function ur(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(t===!0){e();return}if(t!==!1){var s=new qt({next:function(){s.unsubscribe(),e()}});return le(t.apply(void 0,Me([],He(n)))).subscribe(s)}}function sn(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 en(i,t,n)},resetOnError:!0,resetOnComplete:!1,resetOnRefCountZero:a})}function Ks(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=tn(e);return J(function(r,s){(n?ct(e,r,n):ct(e,r)).subscribe(s)})}function Tt(e,t){return J(function(n,r){var s=null,o=0,i=!1,a=function(){return i&&!s&&r.complete()};n.subscribe(G(r,function(l){s?.unsubscribe();var c=0,u=o++;le(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 pl(){return Tt(je)}function dr(e){return J(function(t,n){le(e).subscribe(G(n,function(){return n.complete()},Ee)),!n.closed&&t.subscribe(n)})}function Ht(e,t){return t===void 0&&(t=!1),J(function(n,r){var s=0;n.subscribe(G(r,function(o){var i=e(o,s++);(i||t)&&r.next(o),!i&&r.complete()}))})}function Kt(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 Xs(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=cr(e);return J(function(r,s){for(var o=e.length,i=new Array(o),a=e.map(function(){return!1}),l=!1,c=function(h){le(e[h]).subscribe(G(s,function(p){i[h]=p,!l&&!a[h]&&(a[h]=!0,(l=a.every(je))&&(a=null))},Ee))},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 Gs="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]=Gs[r>>4]+Gs[r&15]}return t.join("")}const hr={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15};function ee(e){const t=e.length%2,n=(e[1]==="x"?2:0)+t,r=(e.length-n)/2+t,s=new Uint8Array(r);t&&(s[0]=0|hr[e[2]]);for(let o=0;o<r;){const i=n+o*2,a=hr[e[i]],l=hr[e[i+1]];s[t+o++]=a<<4|l}return s}function mt(e,t){return Object.fromEntries(Object.entries(e).map(([n,r])=>[n,t(r,n)]))}const oe=e=>{const t=e.reduce((r,s)=>r+s.byteLength,0),n=new Uint8Array(t);for(let r=0,s=0;r<e.length;r++){const o=e[r];n.set(o,s),s+=o.byteLength}return n},V=Function.prototype;let Ys=class extends Error{constructor(){super("Abort Error"),this.name="AbortError"}};var fl=Object.defineProperty,vl=(e,t,n)=>t in e?fl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qs=(e,t,n)=>vl(e,typeof t!="symbol"?t+"":t,n);let Js=class extends Error{constructor(t){super(t.message),Qs(this,"code"),Qs(this,"data"),this.code=t.code,this.data=t.data,this.name="RpcError"}};const Zs=e=>!("method"in e),eo=()=>{const e=new Map;return{has:e.has.bind(e),subscribe(t,n){e.set(t,n)},unsubscribe(t){e.delete(t)},next(t,n){e.get(t)?.next(n)},error(t,n){const r=e.get(t);r&&(e.delete(t),r.error(n))},errorAll(t){const n=[...e.values()];e.clear(),n.forEach(r=>{r.error(t)})}}};let pr=class extends Error{constructor(){super("Client destroyed"),this.name="DestroyedError"}},bl=1;const fr=(e,t)=>{let n=bl++;const r=new Map,s=eo();let o=null;const i=(u,h,p)=>{o.send({jsonrpc:"2.0",id:u,method:h,params:p})};function a(u){if(Zs(u)){const{id:h}=u,p=r.get(h);return p?(r.delete(h),"error"in u?p.onError(new Js(u.error)):p.onSuccess(u.result,(v,d)=>{const f=v;return s.subscribe(f,d),()=>{s.unsubscribe(f)}})):void 0}if(u.id===void 0){const{params:h}=u,{subscription:p,result:v,error:d}=h;p&&s.has(p)&&("result"in h||d)?d?s.error(p,new Js(d)):s.next(p,v):t?.(u)}else console.warn("Error parsing incomming message: "+JSON.stringify(u))}o=e(a);const l=()=>{o?.disconnect(),o=null,s.errorAll(new pr),r.forEach(u=>u.onError(new pr)),r.clear()};let c=1;return{request:(u,h,p)=>{if(!o)throw new Error("Not connected");const v=`${n}-${c++}`;return p&&r.set(v,p),i(v,u,h),()=>{r.delete(v)}},disconnect:l}};var ml=Object.defineProperty,yl=(e,t,n)=>t in e?ml(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,on=(e,t,n)=>yl(e,t+"",n);const to=class rc extends Error{constructor(){super("ChainHead stopped"),this.name=rc.errorName}};on(to,"errorName","StopError");let no=to;const ro=class sc extends Error{constructor(){super("ChainHead disjointed"),this.name=sc.errorName}};on(ro,"errorName","DisjointError");let xn=ro;const so=class oc extends Error{constructor(){super("ChainHead operations limit reached"),this.name=oc.errorName}};on(so,"errorName","OperationLimitError");let Sn=so;const oo=class ic extends Error{constructor(t){super(t),this.name=ic.errorName}};on(oo,"errorName","OperationError");let io=oo;const ao=class ac extends Error{constructor(){super("ChainHead operation inaccessible"),this.name=ac.errorName}};on(ao,"errorName","OperationInaccessibleError");let In=ao;const Ue={body:"",call:"",continue:"",follow:"",header:"",stopOperation:"",storage:"",unfollow:"",unpin:"",followEvent:""},Bn={chainName:"",genesisHash:"",properties:""},vr={broadcast:"",stop:""};Object.entries({chainHead:Ue,chainSpec:Bn,transaction:vr}).forEach(([e,t])=>{Object.keys(t).forEach(n=>{t[n]=`${e}_v1_${n}`})});var gl=Object.defineProperty,wl=(e,t,n)=>t in e?gl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,br=(e,t,n)=>wl(e,t+"",n);const co=class cc extends Error{constructor(t){super(`Invalid BlockHash: ${t}`),this.name=cc.errorName}};br(co,"errorName","BlockHashNotFoundError");let lo=co;const uo=class lc extends Error{constructor(t){super(`Storage Error: ${t}`),this.name=lc.errorName}};br(uo,"errorName","StorageError");let $l=uo;const ho=class uc extends Error{constructor(t){super(`Call Error: ${t}`),this.name=uc.errorName}};br(ho,"errorName","CallError");let El=ho;const Xt=()=>{},kl=e=>(t,n)=>{let r=!1,s=()=>{r=!0};return e(vr.broadcast,[t],{onSuccess:o=>{o!==null?(s=()=>{e(vr.stop,[o]),s=Xt},r&&s()):r||n(new Error("Max # of broadcasted transactions has been reached"))},onError:n}),()=>{s()}};function xl(){let e=()=>{},t=()=>{};return{promise:new Promise((n,r)=>{e=n,t=r}),res:e,rej:t}}const Gt=e=>(...t)=>new Promise((n,r)=>{let s=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 Ys)};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)}),po=(e,t)=>n=>Gt((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 Sn);const{operationId:p}=u,v=()=>{n(Ue.stopOperation,[p])};if(!i)return v();let d=Xt;const f=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 io(m.error)):m.event==="operationInaccessible"?s(new In):c(y,f,b)},error:b}),a=()=>{i&&(d(),v())}},onError:s}),()=>{a()}}),Sl=po(Ue.body,e=>[[e],(t,n)=>{n(t.value)}]),Il=po(Ue.call,(e,t,n)=>[[e,t,n],(r,s)=>{s(r.output)}]),Bl=e=>t=>new Promise((n,r)=>{e(Ue.header,[t],{onSuccess:n,onError:r})}),fo=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 Sn);const{operationId:p}=u,v=()=>{e(Ue.stopOperation,[p])};if(!l)return v();const d=h(u.operationId,{next:y=>{switch(y.event){case"operationStorageItems":{s(y.items);break}case"operationStorageDone":{b();break}case"operationError":{f(new io(y.error));break}case"operationInaccessible":{f(new In);break}default:e(Ue.continue,[y.operationId])}},error:o});c=()=>{d(),e(Ue.stopOperation,[u.operationId])};const f=y=>{c=V,d(),o(y)},b=()=>{c=V,d(),i()};a(u.discardedItems)},onError:o}),()=>{c()}},Al=e=>{const t=fo(e);return Gt((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 Sn))});return u})},Ol=e=>t=>t.length>0?new Promise((n,r)=>{e(Ue.unpin,[t],{onSuccess(){n()},onError:r})}):Promise.resolve();function Cl(e){return e.operationId!==void 0}function _l(e){return(t,n,r)=>{const s=eo(),o=new Set,i=xl();let a=i.promise,l=Xt;const c=d=>{e(Ue.unfollow,[d])},u=d=>{l(),a!==null&&(d&&(a instanceof Promise?a.then(f=>{typeof f=="string"&&c(f)}):c(a)),a=null,o.forEach(f=>{f()}),o.clear(),s.errorAll(new xn))},h=d=>{if(Cl(d))return s.next(d.operationId,d);switch(d.event){case"stop":return r(new no),u(!1);case"initialized":case"newBlock":case"bestBlockChanged":case"finalized":const{event:f,...b}=d;return n({type:f,...b})}},p=d=>{r(d),u(!(d instanceof pr))};e(Ue.follow,[t],{onSuccess:(d,f)=>{a instanceof Promise&&(a=d,l=f(d,{next:h,error:p})),i.res(d)},onError:d=>{a=null,i.res(d),r(d)}});const v=(d,f,b)=>{const y=()=>{b?.onError(new xn)};if(a===null)return y(),Xt;const m=w=>{if(!b)return e(d,[w,...f]);o.add(y);const E=(k,S)=>a===null?(S.error(new xn),Xt):(s.subscribe(k,S),()=>{s.unsubscribe(k)}),$=e(d,[w,...f],{onSuccess:k=>{o.delete(y),b.onSuccess(k,E)},onError:k=>{o.delete(y),b.onError(k)}});return()=>{o.delete(y),$()}};if(typeof a=="string")return m(a);let g=Xt;return a.then(w=>{if(w instanceof Error)return y();a&&(g=m(w))}),()=>{g()}};return{unfollow(){u(!0)},body:Sl(v),call:Il(v),header:Bl(v),storage:Al(v),storageSubscription:fo(v),unpin:Ol(v),_request:v}}}const Rl=e=>{const t=Gt((r,s,o,i)=>e(o,i,{onSuccess:r,onError:s}));let n=null;return async()=>n||(n=Promise.all([t(Bn.chainName,[]),t(Bn.genesisHash,[]),t(Bn.properties,[])]).then(([r,s,o])=>({name:r,genesisHash:s,properties:o})))},Tl=e=>(t,n,r,s,o,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"?f():d(new $l(b.error))},error:o}),v=()=>{l=V,p()};l=()=>{v(),h()};const d=b=>{v(),o(b)},f=()=>{v(),i()}},onError:o}),()=>{l()}},Hl=e=>Gt((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})}),vo=()=>e=>e,bo=()=>(e,t)=>{if(e===null)throw new lo(t);return e},Ml=e=>{const t=(u,...h)=>e(`archive_v1_${u}`,...h),n=u=>h=>Gt((p,v,...d)=>t(u,d,{onSuccess:f=>{try{p(h(f,...d))}catch(b){v(b)}},onError:v})),r=n("header")(bo()),s=n("body")(bo()),o=Tl(t),i=Hl(o),a=n("call")((u,h)=>{if(!u)throw new lo(h);if(!u.success)throw new El(u.error);return u.value}),l=n("finalizedHeight")(vo()),c=n("hashByHeight")(vo());return{header:r,body:s,storageSubscription:o,storage:i,call:a,finalizedHeight:l,hashByHeight:c}},Ul=e=>{const{request:t,disconnect:n}=fr(e);return{archive:Ml(t),chainHead:_l(t),transaction:kl(t),getChainSpecData:Rl(t),destroy:n,request:Gt((r,s,o,i)=>t(o,i,{onSuccess:r,onError:s})),_request:t}};var zl=Object.defineProperty,Dl=(e,t,n)=>t in e?zl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mo=(e,t,n)=>Dl(e,typeof t!="symbol"?t+"":t,n);let Ll=class{constructor(){mo(this,"first"),mo(this,"last")}getRemoveFn(t){return()=>{t.prev?t.prev.next=t.next:this.first=t.next,t.next?t.next.prev=t.prev:this.last=t.prev,delete t.prev,delete t.next}}push(t){const n={value:t};return this.last===void 0?this.last=this.first=n:(this.last.next=n,n.prev=this.last,this.last=n),this.getRemoveFn(n)}unshift(t){return this.first={value:t,next:this.first},this.first.next&&(this.first.next.prev=this.first),this.last||(this.last=this.first),this.getRemoveFn(this.first)}pop(){const t=this.first?.value;return this.first&&(this.first=this.first.next,this.first?(delete this.first.prev?.next,delete this.first.prev):this.last=void 0),t}isEmpty(){return!this.first}};const jl=()=>{const e=new Map,t=(h,p)=>{e.set(h,()=>{e.delete(h),p()})},n=h=>{e.get(h)?.()},r=new Ll,s=r.unshift.bind(r),o=r.push.bind(r),i=(h,p)=>{const v=p?s:o;t(h.source$,v(h))},a=()=>{const h=r.pop();h&&(e.delete(h.source$),l(h))},l=h=>{const{source$:p,observer:v}=h;let d=!1;const f=p.subscribe({next(b){v.next(b)},error(b){(d=b instanceof Error&&b.name===Sn.errorName)?i(h,!0):v.error(b)},complete(){v.complete()}});f.closed?d||a():t(p,()=>{f.unsubscribe(),a()})},c=(h=!1)=>p=>new D(v=>{const d={observer:v,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 mr=e=>{const t=e.pipe(de(n=>n instanceof Error&&n.name===In.errorName?En(750).pipe(Fs(()=>t)):Rt(()=>n)));return t},Nl=new Set(["best","finalized",null]),Vl=(e,t,n)=>r=>(s,...o)=>{if(!Nl.has(s))return mr(r(s,...o)).pipe(n(s));const i=(s==="best"?t:e).pipe(te(1),z(a=>r(a,...o).pipe(n(a))),de(a=>a instanceof Je?i:Rt(()=>a)));return mr(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}}),Pl=e=>t=>(...n)=>e()[t](...n);var ve=(e=>(e[e.Initializing=0]="Initializing",e[e.Ready=1]="Ready",e[e.RecoveringInit=2]="RecoveringInit",e[e.RecoveringFin=3]="RecoveringFin",e))(ve||{});function An(e,t,n){return(r,...s)=>{let o;const i=()=>new Je(r,n),a=t(r,...s).pipe(x(c=>({type:"val",value:c})),qs({type:"end"})),l=e.pipe(Ht(c=>!c.blocks.has(r)),x(c=>{if(c.blocks.get(c.finalized).number>=o.number)throw i()}),kn());return e.pipe(x(c=>c.state.type===ve.Ready),he(),Tt(c=>c?(o||(o=e.state.blocks.get(r)),o?ct(l,a):Rt(i)):rl),Ht(c=>c.type==="val"),x(c=>c.value))}}const Fl=(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($n(),t(i));return n};var Wl=Object.defineProperty,ql=(e,t,n)=>t in e?Wl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yo=(e,t,n)=>(ql(e,typeof t!="symbol"?t+"":t,n),n),yr={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15};function Kl(e){const t=e.length%2,n=(e[1]==="x"?2:0)+t,r=(e.length-n)/2+t,s=new Uint8Array(r);t&&(s[0]=0|yr[e[2]]);for(let o=0;o<r;){const i=n+o*2,a=yr[e[i]],l=yr[e[i+1]];s[t+o++]=a<<4|l}return s}var go=class extends Uint8Array{constructor(e){super(e),yo(this,"i",0),yo(this,"v"),this.v=new DataView(e)}},ze=e=>t=>e(t instanceof go?t:new go(t instanceof Uint8Array?t.buffer:typeof t=="string"?Kl(t).buffer:t)),Ze=e=>{const t=e.length;let n=0;for(let s=0;s<t;s++)n+=e[s].length;const r=new Uint8Array(n);for(let s=0,o=0;s<t;s++){const i=e[s];r.set(i,o),o+=i.byteLength}return r};function On(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},Cn=(e,t)=>n=>e(t(n)),_n=(e,t)=>n=>t(e(n)),Ne=([e,t],n,r)=>X(Cn(e,n),_n(t,r));function Xl(e,t){return ze(n=>{const r=n.v[t](n.i,!0);return n.i+=e,r})}function Gl(e,t){return n=>{const r=new Uint8Array(e);return new DataView(r.buffer)[t](0,n,!0),r}}function yt(e,t,n){return X(Gl(e,n),Xl(e,t))}var P=yt(1,"getUint8","setUint8"),et=yt(2,"getUint16","setUint16"),Ve=yt(4,"getUint32","setUint32"),an=yt(8,"getBigUint64","setBigUint64"),Yl=yt(1,"getInt8","setInt8"),Ql=yt(2,"getInt16","setInt16"),Jl=yt(4,"getInt32","setInt32"),Zl=yt(8,"getBigInt64","setBigInt64"),wo=e=>{const t=new Uint8Array(16),n=new DataView(t.buffer);return n.setBigInt64(0,e,!0),n.setBigInt64(8,e>>64n,!0),t},$o=e=>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}),Eo=X(wo,$o("getBigUint64")),eu=X(wo,$o("getBigInt64")),ko=e=>{const t=new Uint8Array(32),n=new DataView(t.buffer);return n.setBigInt64(0,e,!0),n.setBigInt64(8,e>>64n,!0),n.setBigInt64(16,e>>128n,!0),n.setBigInt64(24,e>>192n,!0),t},xo=e=>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}),tu=X(ko,xo("getBigUint64")),nu=X(ko,xo("getBigInt64")),ru=Ne(P,e=>e?1:0,Boolean),su=[P[1],et[1],Ve[1]],ou=ze(e=>{const t=e[e.i],n=t&3;if(n<3)return su[n](e)>>>2;const r=(t>>>2)+4;e.i++;let s=0n;const o=r/8|0;let i=0n;for(let l=0;l<o;l++)s=an[1](e)<<i|s,i+=64n;let a=r%8;return a>3&&(s=BigInt(Ve[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}),iu=1n<<56n,au=1<<24,cu=256,lu=4294967295n,uu=64,du=16384,hu=1<<30,pu=e=>{if(e<0)throw new Error(`Wrong compact input (${e})`);const t=Number(e)<<2;if(e<uu)return P[0](t);if(e<du)return et[0](t|1);if(e<hu)return Ve[0](t|2);let n=[new Uint8Array(1)],r=BigInt(e);for(;r>=iu;)n.push(an[0](r)),r>>=64n;r>=au&&(n.push(Ve[0](Number(r&lu))),r>>=32n);let s=Number(r);s>=cu&&(n.push(et[0](s)),s>>=16),s&&n.push(P[0](s));const o=Ze(n);return o[0]=o.length-5<<2|3,o},pe=X(pu,ou),fu=new TextEncoder,vu=e=>{const t=fu.encode(e);return Ze([pe.enc(t.length),t])},bu=new TextDecoder,mu=ze(e=>{let t=pe.dec(e);const n=new DataView(e.buffer,e.i,t);return e.i+=t,bu.decode(n)}),W=X(vu,mu),yu=()=>{},gu=new Uint8Array(0),M=X(()=>gu,yu),So=e=>e===void 0?t=>Ze([pe.enc(t.length),t]):t=>t.length===e?t:t.slice(0,e),Io=e=>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(So(e),Io(e));ne.enc=So,ne.dec=Io;var Bo=(e,t)=>{const n=Object.keys(e),r=new Map(t?.map((o,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)])},Ao=(e,t)=>{const n=Object.keys(e),r=new Map(t?.map((s,o)=>[s,n[o]])??n.map((s,o)=>[o,s]));return ze(s=>{const o=P.dec(s),i=r.get(o),a=e[i];return{tag:i,value:a(s)}})},ke=(e,...t)=>X(Bo(On(e,([n])=>n),...t),Ao(On(e,([,n])=>n),...t));ke.enc=Bo,ke.dec=Ao;var Oo=e=>ze(t=>P[1](t)>0?e(t):void 0),Co=e=>t=>{const n=new Uint8Array(1);return t===void 0?n:(n[0]=1,Ze([n,e(t)]))},xe=e=>X(Co(e[0]),Oo(e[1]));xe.enc=Co,xe.dec=Oo;var _o=(e,t)=>ze(n=>{const r=P[1](n)===0,o=(r?e:t)(n);return{success:r,value:o}}),Ro=(e,t)=>({success:n,value:r})=>Ze([P[0](n?0:1),(n?e:t)(r)]),cn=(e,t)=>X(Ro(e[0],t[0]),_o(e[1],t[1]));cn.dec=_o,cn.enc=Ro;var To=(...e)=>ze(t=>e.map(n=>n(t))),Ho=(...e)=>t=>Ze(e.map((n,r)=>n(t[r]))),De=(...e)=>X(Ho(...e.map(([t])=>t)),To(...e.map(([,t])=>t)));De.enc=Ho,De.dec=To;var Mo=e=>{const t=Object.keys(e);return Cn(De.enc(...Object.values(e)),n=>t.map(r=>n[r]))},Uo=e=>{const t=Object.keys(e);return _n(De.dec(...Object.values(e)),n=>Object.fromEntries(n.map((r,s)=>[t[s],r])))},U=e=>X(Mo(On(e,t=>t[0])),Uo(On(e,t=>t[1])));U.enc=Mo,U.dec=Uo;var zo=(e,t)=>t>=0?n=>Ze(n.map(e)):n=>Ze([pe.enc(n.length),Ze(n.map(e))]),Do=(e,t)=>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(zo(e[0],t),Do(e[1],t));L.enc=zo,L.dec=Do;/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function wu(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Lo(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(n=>typeof n=="string"):t.every(n=>Number.isSafeInteger(n)):!1}function gr(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function jo(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function wr(e){if(!Array.isArray(e))throw new Error("array expected")}function No(e,t){if(!Lo(!0,t))throw new Error(`${e}: array of strings expected`)}function $u(e,t){if(!Lo(!1,t))throw new Error(`${e}: array of numbers expected`)}function Eu(...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 ku(e){const t=typeof e=="string"?e.split(""):e,n=t.length;No("alphabet",t);const r=new Map(t.map((s,o)=>[s,o]));return{encode:s=>(wr(s),s.map(o=>{if(!Number.isSafeInteger(o)||o<0||o>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${o}". Allowed: ${e}`);return t[o]})),decode:s=>(wr(s),s.map(o=>{gr("alphabet.decode",o);const i=r.get(o);if(i===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${e}`);return i}))}}function xu(e=""){return gr("join",e),{encode:t=>(No("join.decode",t),t.join(e)),decode:t=>(gr("join.decode",t),t.split(e))}}function Vo(e,t,n){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(wr(e),!e.length)return[];let r=0;const s=[],o=Array.from(e,a=>{if(jo(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 v=p/n;a=p%n;const d=Math.floor(v);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 Su(e){jo(e);const t=2**8;return{encode:n=>{if(!wu(n))throw new Error("radix.encode input should be Uint8Array");return Vo(Array.from(n),t,e)},decode:n=>($u("radix.decode",n),Uint8Array.from(Vo(n,e,t)))}}const Po=(e=>Eu(Su(58),ku(e),xu("")))("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 Bu(e){return Uint8Array.from(Ae(e))}function ln(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function $r(e,t){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 Au(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 gt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Rn(e,t){return e<<32-t|e>>>t}const Fo=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Wo(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const ut=Fo?e=>e:e=>Wo(e)>>>0;function Ou(e){for(let t=0;t<e.length;t++)e[t]=Wo(e[t]);return e}const ge=Fo?e=>e:Ou;function Er(e,t={}){const n=(s,o)=>e(o).update(s).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=s=>e(s),Object.assign(n,t),Object.freeze(n)}const Cu=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]);function wt(e,t,n,r,s){return e=e+t+s|0,r=Rn(r^e,16),n=n+r|0,t=Rn(t^n,12),{a:e,b:t,c:n,d:r}}function $t(e,t,n,r,s){return e=e+t+s|0,r=Rn(r^e,8),n=n+r|0,t=Rn(t^n,7),{a:e,b:t,c:n,d:r}}const _u=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Tn=BigInt(2**32-1),qo=BigInt(32);function Hn(e,t=!1){return t?{h:Number(e&Tn),l:Number(e>>qo&Tn)}:{h:Number(e>>qo&Tn)|0,l:Number(e&Tn)|0}}function Ru(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}=Hn(e[o],t);[r[o],s[o]]=[i,a]}return[r,s]}const Ko=(e,t,n)=>e>>>n|t<<32-n,Xo=(e,t,n)=>e<<32-n|t>>>n,Tu=(e,t,n)=>e<<64-n|t>>>n-32,Hu=(e,t,n)=>e>>>n-32|t<<64-n,Mu=(e,t)=>t,Uu=(e,t)=>e,zu=(e,t,n)=>e<<n|t>>>32-n,Du=(e,t,n)=>t<<n|e>>>32-n,Lu=(e,t,n)=>t<<n-32|e>>>64-n,ju=(e,t,n)=>e<<n-32|t>>>64-n;function Go(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const Yo=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Qo=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,se=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),O=new Uint32Array(32);function Et(e,t,n,r,s,o){const 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],v=O[2*n+1],d=O[2*r],f=O[2*r+1],b=Yo(l,u,i);c=Qo(b,c,h,a),l=b|0,{Dh:f,Dl:d}={Dh:f^c,Dl:d^l},{Dh:f,Dl:d}={Dh:Mu(f,d),Dl:Uu(f)},{h:v,l:p}=Go(v,p,f,d),{Bh:h,Bl:u}={Bh:h^v,Bl:u^p},{Bh:h,Bl:u}={Bh:Ko(h,u,24),Bl:Xo(h,u,24)},O[2*e]=l,O[2*e+1]=c,O[2*t]=u,O[2*t+1]=h,O[2*n]=p,O[2*n+1]=v,O[2*r]=d,O[2*r+1]=f}function kt(e,t,n,r,s,o){const 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],v=O[2*n+1],d=O[2*r],f=O[2*r+1],b=Yo(l,u,i);c=Qo(b,c,h,a),l=b|0,{Dh:f,Dl:d}={Dh:f^c,Dl:d^l},{Dh:f,Dl:d}={Dh:Ko(f,d,16),Dl:Xo(f,d,16)},{h:v,l:p}=Go(v,p,f,d),{Bh:h,Bl:u}={Bh:h^v,Bl:u^p},{Bh:h,Bl:u}={Bh:Tu(h,u,63),Bl:Hu(h,u,63)},O[2*e]=l,O[2*e+1]=c,O[2*t]=u,O[2*t+1]=h,O[2*n]=p,O[2*n+1]=v,O[2*r]=d,O[2*r+1]=f}function Nu(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 Jo{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){ln(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&&(ge(s),this.compress(s,0,!1),ge(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));ge(h);for(let p=0;l+n<o;p+=s.length,l+=n)this.length+=n,this.compress(h,p,!1);ge(h);continue}r.set(t.subarray(l,l+c),this.pos),this.pos+=c,this.length+=c,l+=c}return this}digestInto(t){ln(this),$r(t,this);const{pos:n,buffer32:r}=this;if(this.finished=!0,gt(this.buffer.subarray(n)),ge(r),this.compress(r,0,!0),ge(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 Vu extends Jo{v0l=se[0]|0;v0h=se[1]|0;v1l=se[2]|0;v1h=se[3]|0;v2l=se[4]|0;v2h=se[5]|0;v3l=se[6]|0;v3h=se[7]|0;v4l=se[8]|0;v4h=se[9]|0;v5l=se[10]|0;v5h=se[11]|0;v6l=se[12]|0;v6h=se[13]|0;v7l=se[14]|0;v7h=se[15]|0;constructor(t={}){const n=t.dkLen===void 0?64:t.dkLen;super(128,n),Nu(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:v,v6h:d,v7l:f,v7h:b}=this;return[t,n,r,s,o,i,a,l,c,u,h,p,v,d,f,b]}set(t,n,r,s,o,i,a,l,c,u,h,p,v,d,f,b){this.v0l=t|0,this.v0h=n|0,this.v1l=r|0,this.v1h=s|0,this.v2l=o|0,this.v2h=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=v|0,this.v6h=d|0,this.v7l=f|0,this.v7h=b|0}compress(t,n,r){this.get().forEach((l,c)=>O[c]=l),O.set(se,16);let{h:s,l:o}=Hn(BigInt(this.length));O[24]=se[8]^o,O[25]=se[9]^s,r&&(O[28]=~O[28],O[29]=~O[29]);let i=0;const a=Cu;for(let l=0;l<12;l++)Et(0,4,8,12,t,n+2*a[i++]),kt(0,4,8,12,t,n+2*a[i++]),Et(1,5,9,13,t,n+2*a[i++]),kt(1,5,9,13,t,n+2*a[i++]),Et(2,6,10,14,t,n+2*a[i++]),kt(2,6,10,14,t,n+2*a[i++]),Et(3,7,11,15,t,n+2*a[i++]),kt(3,7,11,15,t,n+2*a[i++]),Et(0,5,10,15,t,n+2*a[i++]),kt(0,5,10,15,t,n+2*a[i++]),Et(1,6,11,12,t,n+2*a[i++]),kt(1,6,11,12,t,n+2*a[i++]),Et(2,7,8,13,t,n+2*a[i++]),kt(2,7,8,13,t,n+2*a[i++]),Et(3,4,9,14,t,n+2*a[i++]),kt(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],gt(O)}destroy(){this.destroyed=!0,gt(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const Mn=Er(e=>new Vu(e));function Zo(e,t,n,r,s,o,i,a,l,c,u,h,p,v,d,f,b,y,m,g){let w=0;for(let E=0;E<r;E++)({a:s,b:l,c:p,d:b}=wt(s,l,p,b,n[t+e[w++]])),{a:s,b:l,c:p,d:b}=$t(s,l,p,b,n[t+e[w++]]),{a:o,b:c,c:v,d:y}=wt(o,c,v,y,n[t+e[w++]]),{a:o,b:c,c:v,d:y}=$t(o,c,v,y,n[t+e[w++]]),{a:i,b:u,c:d,d:m}=wt(i,u,d,m,n[t+e[w++]]),{a:i,b:u,c:d,d:m}=$t(i,u,d,m,n[t+e[w++]]),{a,b:h,c:f,d:g}=wt(a,h,f,g,n[t+e[w++]]),{a,b:h,c:f,d:g}=$t(a,h,f,g,n[t+e[w++]]),{a:s,b:c,c:d,d:g}=wt(s,c,d,g,n[t+e[w++]]),{a:s,b:c,c:d,d:g}=$t(s,c,d,g,n[t+e[w++]]),{a:o,b:u,c:f,d:b}=wt(o,u,f,b,n[t+e[w++]]),{a:o,b:u,c:f,d:b}=$t(o,u,f,b,n[t+e[w++]]),{a:i,b:h,c:p,d:y}=wt(i,h,p,y,n[t+e[w++]]),{a:i,b:h,c:p,d:y}=$t(i,h,p,y,n[t+e[w++]]),{a,b:l,c:v,d:m}=wt(a,l,v,m,n[t+e[w++]]),{a,b:l,c:v,d:m}=$t(a,l,v,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:v,v10:d,v11:f,v12:b,v13:y,v14:m,v15:g}}const ei=new TextEncoder().encode("SS58PRE"),kr=2,ti=e=>{try{const t=Po.decode(e),n=t.subarray(0,t[0]&64?2:1),r=t.subarray(n.length,t.length-kr),s=t.subarray(n.length+r.length),o=Mn(Uint8Array.of(...ei,...n,...r),{dkLen:64}).subarray(0,kr);return s[0]===o[0]&&s[1]===o[1]?{isValid:!0,ss58Format:Pu(n),publicKey:r.slice()}:{isValid:!1}}catch{return{isValid:!1}}},Pu=e=>{const t=new DataView(e.buffer,e.byteOffset,e.byteLength);return t.byteLength===1?t.getUint8(0):t.getUint16(0)},Fu=e=>{let t={},n=0,r=0;const s=()=>{n===r?(t={},n=r=0):(r=n,setTimeout(s,0))};return o=>{var i,a;++n===1&&s();let l=t;const c=o.length-1;for(let u=0;u<=c;u++)l=l[i=o[u]]||(l[i]={});return l[a=o[c]]||(l[a]=e(o))}},ni=e=>{const t=e<64?Uint8Array.of(e):Uint8Array.of((e&252)>>2|64,e>>8|(e&3)<<6);return Fu(n=>{const r=Mn(Uint8Array.of(...ei,...t,...n),{dkLen:64}).subarray(0,kr);return Po.encode(Uint8Array.of(...t,...n,...r))})};function Wu(e,t){return n=>{const r=ti(n);if(!r.isValid)throw new Error("Invalid checksum");const{publicKey:s}=r;if(s.length!==e)throw new Error("Invalid public key length");return s}}const un=(e=42,t=32)=>Ne(ne(t),Wu(t),ni(e)),R=Ne(pe,e=>e,Number),Un=Ne(pe,e=>e,BigInt),qu=new TextEncoder,Ku=new TextDecoder,Xu=De(R,ne(1/0))[1],zn={toText:e=>Ku.decode(e),toHex:e=>Y(e),toOpaque:e=>oe([pe[0](e.length),e]),fromText:e=>qu.encode(e),fromHex:e=>ee(e),fromOpaque:e=>{const t=typeof e=="string"?ee(e):e;try{const[n,r]=Xu(t);if(n===r.length)return r}catch{}throw new Error("Invalid opaque bytes")}},ri=e=>Ne(ne(e),ee,Y),Gu=lt(e=>{const t=R.dec(e),n=Math.ceil(t/8);return{bytes:ne(n).dec(e),bitsLen:t}}),Yu=e=>{if(e.bitsLen>e.bytes.length*8)throw new Error(`Not enough bytes. (bitsLen:${e.bitsLen}, bytesLen:${e.bytes.length})`);const t=R.enc(e.bitsLen),n=new Uint8Array(e.bytes.length+t.length);return n.set(t,0),n.set(e.bytes,t.length),n},Qu=X(Yu,Gu),Ju=Ne(P,e=>e.charCodeAt(0),String.fromCharCode),si=e=>{const t=ne.enc(e);return n=>t(ee(n))},oi=e=>{const t=ne.dec(e);return n=>Y(t(n))},we=e=>X(si(e),oi(e));we.enc=si,we.dec=oi;const ii=new TextEncoder,Zu=new TextDecoder,ed=e=>Ne(ne(e),t=>ii.encode(t),t=>Zu.decode(t)),ai=e=>{let t=n=>{const r=e();return t=r,r(n)};return n=>t(n)},ci=e=>{let t=n=>{const r=e(),s=r;return t=r,s(n)};return n=>t(n)},xr=e=>X(ai(()=>e().enc),ci(()=>e().dec)),td={is(e,t){return e.type===t},as(e,t){if(t!==e.type)throw new Error(`Enum.as(enum, ${t}) used with actual type ${e.type}`);return e}},Dn=Object.assign((e,t)=>({type:e,value:t}),td),nd=new Proxy({},{get(e,t){return n=>Dn(t,n)}}),re=(e,t)=>{const n=e;return n.inner=t,n},li=(...e)=>{const t=ke.enc(...e);return re(n=>t({tag:n.type,value:n.value}),e[0])},ui=(...e)=>{const t=ke.dec(...e);return re(n=>{const{tag:r,value:s}=t(n);return Dn(r,s)},e[0])},Se=(e,...t)=>re(X(li(mt(e,([n])=>n),...t),ui(mt(e,([,n])=>n),...t)),e);Se.enc=li,Se.dec=ui;const Sr=(e,...t)=>re(ke(e,...t),e);Sr.enc=(e,...t)=>re(ke.enc(e,...t),e),Sr.dec=(e,...t)=>re(ke.dec(e,...t),e);const tt={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},dt=_u.slice(),di=(()=>{const e=Array.from({length:16},(r,s)=>s),t=r=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map(s=>r[s]),n=[];for(let r=0,s=e;r<7;r++,s=t(s))n.push(...s);return Uint8Array.from(n)})();class Ir extends Jo{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=Bu(r);this.IV=zt(i),ge(this.IV),this.flags=n|tt.KEYED_HASH}else if(o){Ae(s,void 0,"context");const i=s,a=new Ir({dkLen:32},tt.DERIVE_KEY_CONTEXT).update(i).digest();this.IV=zt(a),ge(this.IV),this.flags=n|tt.DERIVE_KEY_MATERIAL}else this.IV=dt.slice(),this.flags=n;this.state=this.IV.slice(),this.bufferOut=Au(this.bufferOut32)}get(){return[]}set(){}b2Compress(t,n,r,s=0){const{state:o,pos:i}=this,{h:a,l}=Hn(BigInt(t),!0),{v0:c,v1:u,v2:h,v3:p,v4:v,v5:d,v6:f,v7:b,v8:y,v9:m,v10:g,v11:w,v12:E,v13:$,v14:k,v15:S}=Zo(di,s,r,7,o[0],o[1],o[2],o[3],o[4],o[5],o[6],o[7],dt[0],dt[1],dt[2],dt[3],a,l,i,n);o[0]=c^y,o[1]=u^m,o[2]=h^g,o[3]=p^w,o[4]=v^E,o[5]=d^$,o[6]=f^k,o[7]=b^S}compress(t,n=0,r=!1){let s=this.flags;if(this.chunkPos||(s|=tt.CHUNK_START),(this.chunkPos===15||r)&&(s|=tt.CHUNK_END),r||(this.pos=this.blockLen),this.b2Compress(this.chunksDone,s,t,n),this.chunkPos+=1,this.chunkPos===16||r){let o=this.state;this.state=this.IV.slice();for(let 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,gt(this.state,this.buffer32,this.IV,this.bufferOut32),gt(...this.stack)}b2CompressOut(){const{state:t,pos:n,flags:r,buffer32:s,bufferOut32:o}=this,{h:i,l:a}=Hn(BigInt(this.chunkOut++));ge(s);const{v0:l,v1:c,v2:u,v3:h,v4:p,v5:v,v6:d,v7:f,v8:b,v9:y,v10:m,v11:g,v12:w,v13:E,v14:$,v15:k}=Zo(di,0,s,7,t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],dt[0],dt[1],dt[2],dt[3],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]=v^E,o[6]=d^$,o[7]=f^k,o[8]=t[0]^b,o[9]=t[1]^y,o[10]=t[2]^m,o[11]=t[3]^g,o[12]=t[4]^w,o[13]=t[5]^E,o[14]=t[6]^$,o[15]=t[7]^k,ge(s),ge(o),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,gt(this.buffer.subarray(this.pos));let t=this.flags|tt.ROOT;this.stack.length?(t|=tt.PARENT,ge(this.buffer32),this.compress(this.buffer32,0,!0),ge(this.buffer32),this.chunksDone=0,this.pos=this.blockLen):t|=(this.chunkPos?0:tt.CHUNK_START)|tt.CHUNK_END,this.flags=t,this.b2CompressOut()}writeInto(t){ln(this,!1),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($r(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 rd=Er((e={})=>new Ir(e)),sd=BigInt(0),dn=BigInt(1),od=BigInt(2),id=BigInt(7),ad=BigInt(256),cd=BigInt(113),hi=[],pi=[],fi=[];for(let e=0,t=dn,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],hi.push(2*(5*r+n)),pi.push((e+1)*(e+2)/2%64);let s=sd;for(let o=0;o<7;o++)t=(t<<dn^(t>>id)*cd)%ad,t&od&&(s^=dn<<(dn<<BigInt(o))-dn);fi.push(s)}const vi=Ru(fi,!0),ld=vi[0],ud=vi[1],bi=(e,t,n)=>n>32?Lu(e,t,n):zu(e,t,n),mi=(e,t,n)=>n>32?ju(e,t,n):Du(e,t,n);function dd(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=bi(c,u,1)^n[a],p=mi(c,u,1)^n[a+1];for(let v=0;v<50;v+=10)e[i+v]^=h,e[i+v+1]^=p}let s=e[2],o=e[3];for(let i=0;i<24;i++){const a=pi[i],l=bi(s,o,a),c=mi(s,o,a),u=hi[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]^=ld[r],e[1]^=ud[r]}gt(n)}class Br{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(){ge(this.state32),dd(this.state32,this.rounds),ge(this.state32),this.posOut=0,this.pos=0}update(t){ln(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){ln(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($r(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,gt(this.state)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:s,rounds:o,enableXOF:i}=this;return t||=new Br(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 Ln=((e,t,n,r={})=>Er(()=>new Br(t,e,n),r))(1,136,32),yi=e=>{const t=e.slice(2),n=Y(Ln(ii.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("")}`},hd=ne(20)[1],gi=X(e=>{const t=ee(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(yi(n)!==e)throw new Error(`Invalid checksum found on EthAddress(${e})`);return t},lt(e=>yi(Y(hd(e))))),be=e=>re(U(e),e);be.enc=e=>re(U.enc(e),e),be.dec=e=>re(U.dec(e),e);const Pe=(...e)=>re(De(...e),e);Pe.enc=(...e)=>re(De.enc(...e),e),Pe.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 jn=(e,t)=>re(cn(e,t),{ok:e,ko:t});jn.enc=(e,t)=>re(cn.enc(e,t),{ok:e,ko:t}),jn.dec=(e,t)=>re(cn.dec(e,t),{ok:e,ko:t});const xt=e=>re(xe(e),e);xt.enc=e=>re(xe.enc(e),e),xt.dec=e=>re(xe.dec(e),e);const wi=(e=!0)=>lt(t=>{const n=R.dec(t),r=Math.ceil(n/8),s=ne(r).dec(t),o=new Array(n);let 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}),$i=(e=!0)=>t=>{const n=R.enc(t.length),r=Math.ceil(t.length/8),s=new Uint8Array(r);for(let o=0;o<r;o++){let 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 oe([n,s])},Nn=e=>X($i(e),wi(e));Nn.enc=$i,Nn.dec=wi;const Ei=new TextEncoder,ki=new TextDecoder,pd=Ne(ne(4),Ei.encode.bind(Ei),ki.decode.bind(ki)),Ar=be({engine:pd,payload:we()}),fd=Se({other:ne(),consensus:Ar,seal:Ar,preRuntime:Ar,runtimeUpdated:M},[0,4,5,6,8]),Or=we(32),Vn=be({parentHash:Or,number:R,stateRoot:Or,extrinsicRoot:Or,digests:Oe(fd)}),Ce=L(W),xi=xe(W),vd=ke({bool:M,char:M,str:M,u8:M,u16:M,u32:M,u64:M,u128:M,u256:M,i8:M,i16:M,i32:M,i64:M,i128:M,i256:M}),Si=L(U({name:xi,type:R,typeName:xi,docs:Ce})),bd=U({len:Ve,type:R}),md=U({bitStoreType:R,bitOrderType:R}),yd=L(U({name:W,fields:Si,index:P,docs:Ce})),gd=ke({composite:Si,variant:yd,sequence:R,array:bd,tuple:L(R),primitive:vd,compact:R,bitSequence:md}),wd=U({name:W,type:xe(R)}),$d=L(wd),Ed=U({id:R,path:Ce,params:$d,def:gd,docs:Ce}),Pn=L(Ed),Yt=ke({NotDeprecated:M,DeprecatedWithoutNote:M,Deprecated:U({note:W,since:xe(W)})}),kd=L(U({index:P,deprecation:ke({DeprecatedWithoutNote:M,Deprecated:U({note:W,since:xe(W)})},[1,2])})),Cr={name:W,inputs:L(U({name:W,type:R})),output:R,docs:Ce},xd=U({name:W,methods:L(U(Cr)),docs:Ce}),Sd=U({name:W,methods:L(U({...Cr,deprecationInfo:Yt})),docs:Ce,version:R,deprecationInfo:Yt}),Id=U({id:we(32),...Cr,deprecationInfo:Yt}),Bd=ke({Blake2128:M,Blake2256:M,Blake2128Concat:M,Twox128:M,Twox256:M,Twox64Concat:M,Identity:M}),Ad=L(Bd),Od=U({hashers:Ad,key:R,value:R}),Ii={name:W,modifier:P,type:ke({plain:R,map:Od}),fallback:we(),docs:Ce},_r=xe(R),Bi={name:W,storage:xe(U({prefix:W,items:L(U(Ii))})),calls:_r,events:_r,constants:L(U({name:W,type:R,value:we(),docs:Ce})),errors:_r,index:P},Cd={...Bi,docs:Ce},Rr=xe(U({type:R,deprecationInfo:kd})),_d={name:W,storage:xe(U({prefix:W,items:L(U({...Ii,deprecationInfo:Yt}))})),calls:Rr,events:Rr,constants:L(U({name:W,type:R,value:we(),docs:Ce,deprecationInfo:Yt})),errors:Rr,associatedTypes:L(U({name:W,type:R,docs:Ce})),viewFns:L(Id),index:P,docs:Ce,deprecationInfo:Yt},Rd=new Uint8Array,Ai=e=>X(()=>Rd,()=>e),Td=U({type:R,version:P,signedExtensions:L(U({identifier:W,type:R,additionalSigned:R}))}),Oi=U({lookup:Pn,pallets:L(U({...Bi,docs:Ai([])})),extrinsic:Td,type:R,apis:Ai([])}),Hd=U({version:P,address:R,call:R,signature:R,extra:R,signedExtensions:L(U({identifier:W,type:R,additionalSigned:R}))}),Ci=U({lookup:Pn,pallets:L(U(Cd)),extrinsic:Hd,type:R,apis:L(xd),outerEnums:U({call:R,event:R,error:R}),custom:L(De(W,U({type:R,value:we()})))}),Md=U({version:L(P),address:R,call:R,signature:R,signedExtensionsByVersion:L(De(P,L(R))),signedExtensions:L(U({identifier:W,type:R,additionalSigned:R}))}),_i=U({lookup:Pn,pallets:L(U(_d)),extrinsic:Md,apis:L(Sd),outerEnums:U({call:R,event:R,error:R}),custom:L(De(W,U({type:R,value:we()})))}),Ri=()=>{throw new Error("Unsupported metadata version!")},Ie=X(Ri,Ri),Dt=U({magicNumber:Ve,metadata:ke({v0:Ie,v1:Ie,v2:Ie,v3:Ie,v4:Ie,v5:Ie,v6:Ie,v7:Ie,v8:Ie,v9:Ie,v10:Ie,v11:Ie,v12:Ie,v13:Ie,v14:Oi,v15:Ci,v16:_i})}),Tr=ne(),Ud=xe(Tr),zd=De(pe,Tr),Ti=e=>{try{return Dt.dec(e)}catch{}try{return Dt.dec(Ud.dec(e))}catch{}try{return Dt.dec(Tr.dec(e))}catch{}try{return Dt.dec(zd.dec(e)[1])}catch{}throw null},Fn=e=>{if("magicNumber"in e&&(e=e.metadata),"tag"in e){if(e.tag!=="v14"&&e.tag!=="v15"&&e.tag!=="v16")throw new Error("Only metadata 14, 15, and 16 are supported");e=e.value}if("signedExtensionsByVersion"in e.extrinsic){const{extrinsic:{signedExtensions:s,signedExtensionsByVersion:o,...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"},Hr=Ne(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`)}),Dd={dkLen:32},jt=e=>Mn(e,Dd),Ld={dkLen:16},Mr=e=>Mn(e,Ld),Hi=e=>oe([Mr(e),e]),jd={dkLen:32},Mi=e=>rd(e,jd),Nd=e=>oe([Mi(e),e]),Ui=e=>e,Nt=(e,t,n,r)=>new DataView(new Uint16Array([e,t,n,r]).buffer).getBigUint64(0,!0),Ur=2n**64n-1n,me=(e,t)=>e<<t&Ur|e>>64n-t,F=(e,t)=>e*t&Ur,ie=(e,t)=>e+t&Ur,ae=11400714785074694791n,_e=14029467366897019727n,zi=1609587929392839161n,hn=9650029242287828579n,Di=2870177450012600261n;function St(e,t=0n){let n=ie(ie(t,ae),_e),r=ie(t,_e),s=t,o=t-ae,i=e.length,a=0,l=null;(function(){let p=0,v=p+i;if(i){if(l=new Uint8Array(32),i<32){l.set(e.subarray(0,i),a),a+=i;return}if(p<=v-32){const d=v-32;do{let f;f=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(me(ie(n,F(f,_e)),31n),ae),p+=8,f=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(me(ie(r,F(f,_e)),31n),ae),p+=8,f=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(me(ie(s,F(f,_e)),31n),ae),p+=8,f=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(me(ie(o,F(f,_e)),31n),ae),p+=8}while(p<=d)}p<v&&(l.set(e.subarray(p,v),a),a=v-p)}})(),e=l||e;let c,u=0;for(i>=32?(c=me(n,1n),c=ie(c,me(r,7n)),c=ie(c,me(s,12n)),c=ie(c,me(o,18n)),n=F(me(F(n,_e),31n),ae),c=c^n,c=ie(F(c,ae),hn),r=F(me(F(r,_e),31n),ae),c=c^r,c=ie(F(c,ae),hn),s=F(me(F(s,_e),31n),ae),c=c^s,c=ie(F(c,ae),hn),o=F(me(F(o,_e),31n),ae),c=c^o,c=ie(F(c,ae),hn)):c=ie(t,Di),c=ie(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(me(F(p,_e),31n),ae),c=ie(F(me(c^p,27n),ae),hn),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),ae);c=ie(F(me(c^p,23n),_e),zi),u+=4}for(;u<a;){const p=F(Nt(e[u++],0,0,0),Di);c=F(me(c^p,11n),ae)}let h=c>>33n;return c=F(c^h,_e),h=c>>29n,c=F(c^h,zi),h=c>>32n,c^=h,c}const Wn=e=>{const t=new Uint8Array(16),n=new DataView(t.buffer);return n.setBigUint64(0,St(e),!0),n.setBigUint64(8,St(e,1n),!0),t},Li=e=>{const t=new Uint8Array(32),n=new DataView(t.buffer);return n.setBigUint64(0,St(e),!0),n.setBigUint64(8,St(e,1n),!0),n.setBigUint64(16,St(e,2n),!0),n.setBigUint64(24,St(e,3n),!0),t},ji=e=>oe([an.enc(St(e)),e]),Ni=new TextEncoder,Vd=new Map([[Ui,0],[ji,8],[Hi,16],[Mr,-16],[jt,-32],[Wn,-16],[Li,-32]]),Vi=e=>{const t=Wn(Ni.encode(e));return(n,...r)=>{const s=oe([t,Wn(Ni.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=ee(l.slice(o.length)),u=new Array(r.length);for(let h=0,p=0;h<r.length;h++){const[v,d]=r[h],f=Vd.get(d);if(f==null)throw new Error("Unknown hasher");if(f<0){const b=f*-1;u[h]=Y(c.slice(p,p+b)),p+=b}else p+=f,u[h]=v.dec(c.slice(p)),p+=v.enc(u[h]).length}return u},a=r.map(([{enc:l},c])=>u=>c(l(u)));return{enc:(...l)=>Y(oe([s,...l.map((c,u)=>a[u](c))])),dec:i}}},Pd=zn.fromText("modlpy/utilisuba"),Fd=({threshold:e,signatories:t})=>{const n=Pi(t),r=oe([Pd,pe.enc(n.length),...n,et.enc(e)]);return jt(r)},Pi=e=>e.slice().sort((t,n)=>{for(let r=0;;r++){const s=r>=t.length,o=r>=n.length;if(s&&o)return 0;if(s)return-1;if(o)return 1;if(t[r]!==n[r])return t[r]>n[r]?1:-1}}),It={Leaf:"Leaf",Branch:"Branch",BranchWithVal:"BranchWithVal",LeafWithHash:"LeafWithHash",BranchWithHash:"BranchWithHash",Empty:"Empty",Reserved:"Reserved"},Fi=we().dec,Wd=we(1/0).dec,qd=we(32).dec,Wi=P.dec,Kd=e=>{const t=Wi(e);let n=6;const r=t>>n,s=r?r===1?It.Leaf:r===2?It.Branch:It.BranchWithVal:t>>--n?It.LeafWithHash:t>>--n?It.BranchWithHash:t?It.Reserved:It.Empty;let o=t&255>>8-n;if(o===2**n-1){let i;do o+=i=Wi(e);while(i===255)}return{type:s,partialKey:we(Math.ceil(o/2)).dec(e).slice(o%2?3:2)}},qi=lt(e=>{const t=Kd(e),{type:n}=t;if(n==="Empty"||n==="Reserved")return t;if(n==="Leaf"||n==="LeafWithHash")return{...t,value:Wd(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=Fi(e)),n==="BranchWithHash"&&(o=qd(e));const i={...t,children:Object.fromEntries(s.map(a=>[a,Fi(e)]))};return o!==null&&(i.value=o),i}),Ki=e=>lt(t=>{const n=Y(e(new Uint8Array(t.buffer)));try{return{hash:n,...qi(t)}}catch{return{type:"Raw",hash:n,value:""}}}),Xi=(e,t=jt)=>{const n=e.map(Ki(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 Gi=Object.freeze({__proto__:null,AccountId:un,Binary:zn,BitSeq:Nn,Blake2128:Mr,Blake2128Concat:Hi,Blake2256:jt,Blake3256:Mi,Blake3256Concat:Nd,Bytes:ne,Enum:Dn,Hex:we,Identity:Ui,Keccak256:Ln,Option:xt,Result:jn,ScaleEnum:Sr,Self:xr,SizedBytes:ri,Storage:Vi,Struct:be,TrieNodeHeaders:It,TrieNodeWithHash:Ki,Tuple:Pe,Twox128:Wn,Twox256:Li,Twox64Concat:ji,Variant:Se,Vector:Oe,_Enum:nd,_void:M,bitSequence:Qu,blockHeader:Vn,bool:ru,char:Ju,compact:pe,compactBn:Un,compactNumber:R,createCodec:X,createDecoder:lt,decAnyMetadata:Ti,enhanceCodec:Ne,enhanceDecoder:_n,enhanceEncoder:Cn,ethAccount:gi,extrinsicFormat:Hr,fixedStr:ed,fromBufferToBase58:ni,getMultisigAccountId:Fd,getSs58AddressInfo:ti,h64:St,i128:eu,i16:Ql,i256:nu,i32:Jl,i64:Zl,i8:Yl,metadata:Dt,selfDecoder:ci,selfEncoder:ai,sortMultisigSignatories:Pi,str:W,trieNodeDec:qi,u128:Eo,u16:et,u256:tu,u32:Ve,u64:an,u8:P,unifyMetadata:Fn,v14:Oi,v14Lookup:Pn,v15:Ci,v16:_i,validateProofs:Xi});const Xd=[jt,Ln],Gd=(e,t)=>Xd.find(n=>Y(n(ee(e)))===t)||(()=>{throw new Error("Unsupported hasher")}),Yd=e=>{const t=(n,r,s)=>{const o=n[r.idx],i=n[s.idx];if(n.length===2)return K([[o,r.id],[i,s.id]]);const a=r.idx+Math.floor((s.idx-r.idx)/2);return e(n[a]).pipe(z(l=>{const c={id:l,idx:a};return c.id===r.id?t(n,c,s):c.id===s.id?t(n,r,c):ue([t(n,r,c),t(n,c,s)]).pipe(x(([u,[h,...p]])=>[...u,...p]))}))};return n=>{const[r]=n;if(n.length===1)return e(r).pipe(x(o=>[[r,o]]));const s=n.length-1;return ue([r,n[s]].map(e)).pipe(z(([o,i])=>o===i?K([[r,o]]):t(n,{idx:0,id:o},{idx:s,id:i})))}},Qd=(e,t,n)=>{const r=Yd(t),s=l=>nn(()=>e().header(l)),o=new en(1),i=l=>{if(l.type==="initialized"){const[c]=l.finalizedBlockHashes;return ue([s(c),r(l.finalizedBlockHashes)]).pipe(x(([u,h])=>{o.closed||(o.next(Gd(u,c)),o.complete());const{number:p,parentHash:v,digests:d}=Vn.dec(u);return{type:"initialized",finalizedBlockHashes:l.finalizedBlockHashes,runtimeChanges:new Map(h),number:p,parentHash:v,hasNewRuntime:d.some(f=>f.type==="runtimeUpdated")}}))}if(l.type==="newBlock"&&l.newRuntime)return t(l.blockHash).pipe(x(c=>({...l,codeHash:c})))},a=l=>new D(c=>{let u=null,h;const p=f=>u?.push(f)||v(f),v=f=>{const b=i(f);b?(u=[],h=b.subscribe({next:y=>{const m=[...u];u=null,c.next(y),m.forEach(p)},error:n})):c.next(f)},d=l.subscribe(f=>{f.type==="stop-error"?(h?.unsubscribe(),u=null,c.next(f)):p(f)});return()=>{h?.unsubscribe(),d.unsubscribe()}});return{getHeader:l=>s(l).pipe(x(Vn[1])),hasher$:o.asObservable(),enhancer:a}},Jd=(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((v,d)=>o().storage(v,"hash","0x3a636f6465",null,d)));let a=Ee,l;const{hasher$:c,enhancer:u,getHeader:h}=Qd(o,i,v=>{console.warn("ChainHead subfollow request failed, retrying\u2026",v),l=setTimeout(()=>a(),250)}),p=new D(v=>{if(r)return v.complete();const d=()=>{let f=[];n=e(!0,b=>{f?f.push(b):v.next(b)},b=>{n=null,!r&&(b instanceof Error&&b.name===no.errorName?(d(),v.next({type:"stop-error"})):(console.warn("ChainHead follow request failed, retrying\u2026",b),l=setTimeout(d,250)))}),f.forEach(b=>v.next(b)),f=null};a=()=>{v.next({type:"stop-error"}),clearTimeout(l),n?.unfollow(),d()},d(),s=()=>{r=!0,clearTimeout(l),v.complete(),n?.unfollow()}}).pipe(u,bt());return{getHeader:h,hasher$:c,getFollower:o,follow$:p,unfollow:()=>{s()}}},Zd=e=>Y(Ve.enc(e)),Yi=ne(),eh=xt(Yi),th=Oe(Ve).dec,Qi=e=>{const t=e("Metadata_metadata_versions","").pipe(x(th),de(()=>K([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(Yi.dec)):e("Metadata_metadata_at_version",Zd(s)).pipe(x(o=>eh.dec(o)))};return t.pipe(z(n))},Ji=(e,t)=>e.type==="array"&&e.len===t&&e.value.type==="primitive"&&e.value.value==="u8",Bt={type:"void"},nh=(e,t=()=>null)=>{const n=new Map,r=new Set,s=u=>h=>{let p=n.get(h);if(p)return p;if(r.has(h)){const d={id:h};return n.set(h,d),d}r.add(h);const v=u(h);return p=n.get(h),p?Object.assign(p,v):(p={id:h,...v},n.set(h,p)),r.delete(h),p};let o=!0,i=!0;const a=s(u=>{const h=t(e[u]);if(h)return h;const{def:p,path:v,params:d}=e[u];if(p.tag==="composite"){if(p.value.length===0)return Bt;if(p.value.length===1){const f=a(p.value[0].type);return o&&v.at(-1)==="AccountId32"&&Ji(f,32)?(o=!1,{type:"AccountId32"}):i&&v.at(-1)==="AccountId20"&&Ji(f,20)?(i=!1,{type:"AccountId20"}):f}return l(p.value)}if(p.tag==="variant"){if(v.length===1&&v[0]==="Option"&&d.length===1&&d[0].name==="T"){const y=a(d[0].type);return y.type==="void"?{type:"primitive",value:"bool"}:{type:"option",value:y}}if(v.length===1&&v[0]==="Result"&&d.length===2&&d[0].name==="T"&&d[1].name==="E")return{type:"result",value:{ok:a(d[0].type),ko:a(d[1].type)}};if(p.value.length===0)return Bt;const f={},b={};return p.value.forEach(y=>{const m=y.name;if(b[m]=y.docs,y.fields.length===0){f[m]={...Bt,idx:y.index};return}if(y.fields.length===1&&!y.fields[0].name){f[m]={type:"lookupEntry",value:a(y.fields[0].type),idx:y.index};return}f[m]={...l(y.fields),idx:y.index}}),{type:"enum",value:f,innerDocs:b}}if(p.tag==="sequence")return{type:"sequence",value:a(p.value)};if(p.tag==="array"){const{len:f}=p.value,b=a(p.value.type);return!f||b.type==="void"?Bt:f>1?{type:"array",value:b,len:p.value.len}:b}if(p.tag==="tuple")return p.value.length===0?Bt:p.value.length>1?c(p.value.map(f=>a(f)),p.value.map(f=>e[f].docs)):a(p.value[0]);if(p.tag==="primitive")return{type:"primitive",value:p.value.tag};if(p.tag==="compact"){const f=a(p.value);return f.type==="void"?Bt:{type:"compact",isBig:Number(f.value.slice(1))>32,size:f.value}}return{type:p.tag,isLSB:(e[p.value.bitOrderType].path.at(-1)??"LSB").toUpperCase().startsWith("LSB")}}),l=u=>{let h=!0;const p={},v={};return u.forEach((d,f)=>{h=h&&!!d.name;const b=d.name||f,y=a(d.type);y.type!=="void"&&(p[b]=y,v[b]=d.docs)}),h?{type:"struct",value:p,innerDocs:v}:c(Object.values(p),Object.values(v))},c=(u,h)=>{if(u.every(p=>p.id===u[0].id)&&h.every(p=>!p.length)){const[p]=u;return p.type==="void"?Bt:{type:"array",value:u[0],len:u.length}}return{type:"tuple",value:u,innerDocs:h}};return a},Zi=e=>{const t=nh(e.lookup,({def:r})=>{if(r.tag==="composite"){const s=n(r);if(s)return{type:"enum",innerDocs:{},value:Object.fromEntries(e.pallets.map(o=>[o.name,o.errors==null?{...Bt,idx:o.index}:{type:"lookupEntry",value:t(o.errors.type),idx:o.index}])),byteLength:s}}return null});function n(r){if(!(r.value.length===2&&r.value[0].name==="index"&&r.value[1].name==="error"))return null;const s=t(r.value[0].type),o=t(r.value[1].type);return s.type==="primitive"&&s.value==="u8"&&o.type==="array"&&o.value.type==="primitive"&&o.value.value==="u8"?1+o.len:null}return Object.assign(t,{metadata:e,call:"call"in e.extrinsic?e.extrinsic.call:e.lookup[e.extrinsic.type]?.params.find(r=>r.name==="Call")?.type??null})},rh=(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},sh=ne(),oh=(e,t,n,r)=>{if(e.type==="primitive")return Gi[e.value];if(e.type==="void")return M;if(e.type==="AccountId32")return r;if(e.type==="AccountId20")return gi;if(e.type==="compact")return e.isBig?Un:R;if(e.type==="bitSequence")return Nn(e.isLSB);const s=p=>ea(p,t,n,r),o=(p,v)=>{const d=s(p);return v?Oe(d,v):Oe(d)},i=p=>Pe(...p.map(s)),a=p=>{const v=Object.fromEntries(Object.entries(p).map(([d,f])=>[d,s(f)]));return be(v)};if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return sh;if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?ri(e.len):o(e.value,e.len);if(e.type==="sequence")return o(e.value);if(e.type==="tuple")return i(e.value);if(e.type==="struct")return a(e.value);if(e.type==="option")return xt(s(e.value));if(e.type==="result")return jn(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,v)=>[p,l[v]])),u=Object.values(e.value).map(p=>p.idx),h=u.every((p,v)=>p===v)?Se(c):Se(c,u);return e.byteLength?ih(h,e.byteLength):h},ea=rh(oh,xr,e=>e),ta=(e,t=un())=>{const n=new Map,r=s=>ea(e(s),n,new Set,t);return s=>r(s)},ih=(e,t)=>{const n=ne(t);return X(r=>n.enc(e.enc(r)),r=>e.dec(n.dec(r)))},ah=Ne(M,()=>{},()=>null),ch=e=>{const{metadata:t}=e;let n=ta(e);const r=t.pallets.find(p=>p.name==="System")?.constants.find(p=>p.name==="SS58Prefix");let s;if(r)try{const p=n(r.type).dec(r.value);typeof p=="number"&&(s=p,n=ta(e,un(p)))}catch{}const o=new Map,i=(p,v)=>{let d=o.get(p);d||o.set(p,d=Vi(p));const f=t.pallets.find(S=>S.name===p).storage.items.find(S=>S.name===v),b=S=>S===M?ah:S,y=(S,B,...I)=>{const _=d(...I),[,...T]=I;return{args:Pe(...T.map(([j])=>j)),keys:_,value:B,len:S,fallback:f.modifier===1?B.dec(f.fallback):void 0}};if(f.type.tag==="plain")return y(0,b(n(f.type.value)),v);const{key:m,value:g,hashers:w}=f.type.value,E=b(n(g)),$=w.map(S=>Gi[S.tag]),k=(()=>{if($.length===1)return[[n(m),$[0]]];const S=e(m);switch(S.type){case"array":return $.map(B=>[n(S.value.id),B]);case"tuple":return S.value.map((B,I)=>[n(B.id),$[I]]);default:throw new Error("Invalid key type")}})();return y($.length,E,v,...k)},a=p=>{switch(p.type){case"void":return M;case"lookupEntry":return n(p.value.id);case"tuple":return Pe(...Object.values(p.value).map(v=>n(v.id)));case"struct":return be(mt(p.value,v=>n(v.id)));case"array":return Oe(n(p.value.id),p.len)}},l=(p,v)=>{const d=t.pallets.find(f=>f.name===p).constants.find(f=>f.name===v);return n(d.type)},c=p=>(v,d)=>{const f=t.pallets.find(m=>m.name===v),b=e(f[p].type);if(b.type!=="enum")throw null;const y=b.value[d];return{location:[f.index,y.idx],codec:a(b.value[d])}},u=(p,v)=>{const d=t.pallets.find(f=>f.name===p)?.viewFns.find(f=>f.name===v);if(!d)throw null;return{args:Pe(...d.inputs.map(f=>n(f.type))),value:n(d.output)}},h=(p,v)=>{const d=t.apis.find(f=>f.name===p)?.methods.find(f=>f.name===v);if(!d)throw null;return{args:Pe(...d.inputs.map(f=>n(f.type))),value:n(d.output)}};return{buildDefinition:n,buildStorage:i,buildEvent:c("events"),buildError:c("errors"),buildViewFn:u,buildRuntimeCall:h,buildCall:c("calls"),buildConstant:l,ss58Prefix:s}},lh=(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}]})),uh=(e,t)=>{const n=lh(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=mt(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:mt(e.extrinsic.signedExtensions,a=>Object.fromEntries(a.map(({identifier:l,...c})=>[l,c])))}},zr="CheckMortality",na=(e,t,n)=>{const r=Zi(e),s=ch(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=hh(r.metadata,s),c=u=>{const h=l(u);return"extra"in h&&h.extra[zr]||{mortal:!1}};return{mappedMeta:uh(e,r),assetId:a,metadataRaw:t,codeHash:n,lookup:r,dynamicBuilder:s,events:{key:o.keys.enc(),dec:o.value.dec},accountId:un(s.ss58Prefix),getMortalityFromTx:c,extVersions:e.extrinsic.version}},Dr=ne(1/0).dec,dh=_n(et[1],e=>{const t=2<<e%16,n=Math.max(t>>12,1),r=(e>>4)*n;return{mortal:!0,period:t,phase:r}}),ra=lt(e=>{const t=P.dec(e);if(t===0)return{mortal:!1};const n=P.dec(e);return dh(Uint8Array.from([t,n]))}),hh=(e,t)=>{const n=be.dec(Object.fromEntries(e.extrinsic.signedExtensions[0].map(a=>[a.identifier,a.identifier===zr?ra: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=be.dec({address:r,signature:s,extra:n,callData:Dr});return lt(a=>{const l=R.dec(a),{type:c,version:u}=Hr[1](a);if(c==="bare")return{len:l,version:u,type:c,callData:Dr(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=be.dec(Object.fromEntries(d.map(f=>[f.identifier,f.identifier===zr?ra:t.buildDefinition(f.type)[1]])))}else p=n;const v=p(a);return{len:l,type:c,version:u,extensionVersion:h,extra:v,callData:Dr(a)}})},ph=e=>t=>{const n=(...r)=>{let s;try{s=e()}catch(o){return Rt(o)}return s?t(s,...r).pipe(de(o=>{if(o instanceof Je)return n(...r);if(o instanceof Error&&o.name===In.errorName)return En(750).pipe(z(()=>n(...r)));throw o})):Ye};return n},fh=(e,t,n)=>{const r=(s,o)=>t(s).pipe(de(()=>K(null)),z(i=>i?K(i):o.pipe(Kt(a=>{n(s,a)}))),x(i=>({codeHash:s,metadataRaw:i,metadata:Fn(Dt.dec(i))})));return(s,o)=>{const i=new Set([o]),a={},l=ph(()=>{if(!i.size)throw a;return i.has(o)?o:[...i].at(-1)}),c=r(s,Qi(l(e)).pipe(de(h=>h===a?Ye:Rt(()=>h)))).pipe(x(({metadata:h,metadataRaw:p,codeHash:v})=>na(h,p,v)),sn(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}},pn=bt({connector:()=>new en(1),resetOnError:!0,resetOnComplete:!0,resetOnRefCountZero:!0}),fn=({hash:e,number:t,parent:n,hasNewRuntime:r})=>({hash:e,number:t,parent:n,hasNewRuntime:r}),vh=(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(fn(m))},u=m=>{l(m,[...m.blocks.values()].filter(w=>w.recovering).map(w=>w.hash));const g="pendingBlocks"in m.state?m.state.pendingBlocks:[];m.state={type:ve.Ready},g.forEach(c)},h=new ye,p=h.pipe(dl(()=>En(0)),x(()=>({type:"cleanup"}))),v=sa(),d=()=>(l(v,[...v.blocks.values()].map(m=>m.hash)),Object.assign(v,sa())),f=Qe(s,p,e).pipe(rn((m,g)=>{const w=$=>{l(m,$),i($)},E=(...$)=>{const k=m.blocks.get(m.finalized)?.number??-1,S=$.filter(({refCount:B,recovering:I,number:_,pruned:T})=>!B&&!I&&(T||_<k)).map(({hash:B})=>B);S.length&&w(S)};switch(g.type){case"initialized":if(m.state.type!==ve.Initializing&&m.state.type!==ve.RecoveringInit)throw new Error("Initialized event out of order");m.state.type===ve.RecoveringInit&&!g.finalizedBlockHashes.some(I=>m.blocks.has(I))&&(d(),o.next(null));const $=m.blocks.get(m.finalized)?.number??-1,k=g.finalizedBlockHashes.length-1,S=[];$>g.number+k?m.state={type:ve.RecoveringFin,target:$,pendingBlocks:S}:(m.state={type:ve.Initializing,pendingBlocks:S},m.finalized=g.finalizedBlockHashes[k]);let B=m.finalizedRuntime.codeHash;return g.finalizedBlockHashes.forEach((I,_)=>{const T=m.blocks.get(I);if(T)T.recovering=!1;else{const j=g.number+_,Z=j>$,ce=g.runtimeChanges.get(I),$e=ce&&!m.runtimes[ce]&&Z;$e&&(B=ce);const ot=_===0?g.parentHash:g.finalizedBlockHashes[_-1],At={hash:I,hasNewRuntime:_?g.runtimeChanges.has(I):g.hasNewRuntime,parent:ot,children:new Set(_===k?[]:[g.finalizedBlockHashes[_+1]]),pruned:!1,runtime:B,refCount:0,number:j,recovering:!1};m.blocks.set(I,At),$e&&(m.finalizedRuntime=m.runtimes[ce]=y(ce,I)),m.runtimes[B].usages.add(I),Z&&S.push(At)}}),m;case"stop-error":if(m.state.type===ve.Initializing)return d();for(const I of m.blocks.values())I.recovering=!0;return m.state={type:ve.RecoveringInit},m;case"newBlock":{const{parentBlockHash:I,blockHash:_}=g;if(m.blocks.has(_))m.blocks.get(_).recovering=!1;else{const T=m.blocks.get(I);T.children.add(_);const j=T.number+1,Z={hash:_,number:j,parent:I,children:new Set,runtime:T.runtime,pruned:!1,refCount:0,recovering:!1,hasNewRuntime:!!g.newRuntime};if(m.blocks.set(_,Z),g.newRuntime){const{codeHash:ce}=g;Z.runtime=ce,m.runtimes[ce]=y(ce,_)}m.runtimes[Z.runtime].addBlock(_),"pendingBlocks"in m.state?m.state.pendingBlocks.push(Z):c(Z)}return m}case"bestBlockChanged":return m.state.type===ve.RecoveringFin||(m.best=g.bestBlockHash,m.state.type===ve.Initializing&&u(m)),m;case"finalized":{const I=g.finalizedBlockHashes.slice(-1)[0];let _=!1;if(m.state.type===ve.RecoveringFin){if(m.blocks.get(I).number<m.state.target)return m;_=!0}m.finalized=I;const{blocks:T}=m;return T.get(m.best).number<T.get(m.finalized).number&&(m.best=m.finalized),m.finalizedRuntime=m.runtimes[T.get(m.finalized).runtime],g.prunedBlockHashes.forEach(j=>{const Z=m.blocks.get(j);Z&&(Z.pruned=!0)}),_&&u(m),m.state.type===ve.Ready&&h.next(),m}case"cleanup":return E(...m.blocks.values()),m;case"blockUsage":{const I=m.blocks.get(g.value.hash);return I&&(I.refCount+=g.value.type==="hold"?1:-1,E(I)),m}}},v),x(m=>({...m})),Kt({error(m){o.error(m)}}),pn),b=Object.assign(f,{state:v}),y=fh(An(b,t,"pinned-blocks"),n,r);return b},sa=()=>({best:"",finalized:"",runtimes:{},blocks:new Map,finalizedRuntime:{},state:{type:ve.Initializing,pendingBlocks:[]}}),oa=(e,t,n,r,s,o)=>{const i=new Map,a=v=>{i.get(v)?.(),i.delete(v)},l=new D(v=>{const d=t.subscribe({next:({hash:f})=>{i.set(f,o(f))},complete(){v.error(new Error("Tracking stopped"))}});return d.add(e.pipe(x(f=>f.finalized),he()).subscribe(()=>{e.state.blocks.forEach(({pruned:f,hash:b})=>{f&&a(b)})})),d.add(()=>[...i.keys()].forEach(a)),d}),c=v=>dr(e.pipe(Be(({blocks:d})=>d.get(v)?.pruned??!0))),u=(v,d,f)=>{if(f)return K({hash:v,found:{type:!1,validity:null}});const b=c(v);return n(v).pipe(z(y=>{const m=y.findIndex(g=>bh(g,d));return m>-1?b(s(v)).pipe(x(g=>({hash:v,found:{type:!0,index:m,events:g}}))):r(v,d).pipe(x(g=>({hash:v,found:{type:!1,validity:g}})))}),b,lr(()=>a(v)))},h=v=>{[...e.state.blocks.get(v)?.children.keys()??[]].forEach(h),a(v)},p=(v,d,f)=>u(v,d,f.has(v)).pipe(z(b=>{const{found:y}=b,m=y.type||y.validity?.success===!1;return m&&h(v),m?K(b):e.pipe(c(v),z(g=>g.blocks.get(v).children),ll(),z(g=>p(g,d,f)))}));return v=>Qe(l,e.pipe(te(1),z(d=>p(d.finalized,v,new Set(d.blocks.keys())))))},bh=(e,t)=>e.length===t.length&&e.every((n,r)=>t[r]===n),mh=new Uint8Array([2]),yh=(e,t)=>Y(oe([mh,e,ee(t)])),ia="TaggedTransactionQueue",aa="validate_transaction",[,gh]=Se({InvalidTransaction:Se({Call:M,Payment:M,Future:M,Stale:M,BadProof:M,AncientBirthBlock:M,ExhaustsResources:M,Custom:P,BadMandatory:M,MandatoryValidation:M,BadSigner:M}),UnknownTransaction:Se({CannotLookup:M,NoUnsignedValidator:M,Custom:P})}),wh=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=gh(e)}catch{n={type:"UnknownInvalidTx"}}return{success:!1,value:n}}),$h=(e,t)=>(n,r)=>{const s=t(n).pipe(x(o=>{try{return o.dynamicBuilder.buildRuntimeCall(ia,aa).value[1]}catch{return wh}}));return e(n,`${ia}_${aa}`,yh(r,n)).pipe(Xs(s),x(([o,i])=>i(o)))},Eh=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}),kh=e=>t=>new D(n=>{const r=t.subscribe({next(o){n.next(o)},error(o){n.error(o)},complete(){n.complete()}}),s=()=>r.unsubscribe();return()=>{Promise.resolve().then(s)}}),ca=(e,t=1/0)=>n=>new D(r=>{let s;const o=new Map,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 v=c++;o.delete(v),u!==v&&a.set(v,[]);let d=!1,f=p.subscribe({next(b){u===v?r.next(b):a.get(v).push(b)},complete(){if(d=!0,i.delete(v),v===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(v,f)};return s=new _t,s.add(n.subscribe({next(p){const v=l++;o.set(v,nn(()=>e(p,v))),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()}}),xh=(e,t,n)=>{const{withRecovery:r,withRecoveryFn:s}=jl(),{getFollower:o,unfollow:i,follow$:a,getHeader:l,hasher$:c}=Jd(e,s),u=Pl(o),h=new ye,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}),v=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))),f=A=>o().unpin(A).catch(C=>{if(!(C instanceof Error&&C.name===xn.errorName))throw C}),b=(A,C)=>d(v(An(g,s(Mt(A)),`stop-${C}`)),C),y=new Map,m=new ye,g=vh(a,(...A)=>v(s(Mt(u("call"))))(...A).pipe(x(ee)),t,n,h,m,A=>{f(A).catch(C=>{console.error("unpin",C)}),A.forEach(C=>{y.delete(C)})},A=>{y.delete(A)}),w=d(v(A=>g.state.runtimes[g.state.blocks.get(A).runtime].runtime),"getRuntimeCtx"),E=A=>C=>C.pipe(ca(H=>w(A(H)).pipe(x(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 Ot;const Xe=H.pipe(bt({connector:()=>Ot=new en}),Kt({complete(){N.set(C,Ot)}}),kh());return N.set(C,Xe),Xe},k=Object.assign(g.pipe(Be(A=>A.state.type===ve.Ready)),{state:g.state}),S=k.pipe(he((A,C)=>A.finalized===C.finalized),rn((A,C)=>{let H=C.blocks.get(C.finalized);const 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},[]),$n(),x(fn),pn),B=k.pipe(he((A,C)=>A.best===C.best),x(A=>fn(A.blocks.get(A.best))),pn),I=k.pipe(he((A,C)=>A.finalized===C.finalized&&A.best===C.best),rn((A,C)=>{const H=Te=>A.get(Te)||fn(C.blocks.get(Te)),N=H(C.best),fe=H(C.finalized),Ot=N.number-fe.number+1,Xe=new Array(Ot);for(let Te=0,nr=N.hash;Te<Ot;Te++)Xe[Te]=H(nr),nr=Xe[Te].parent;return new Map(Xe.map(Te=>[Te.hash,Te]))},new Map),x(A=>[...A.values()]),pn),_=k.pipe(he((A,C)=>A.finalizedRuntime===C.finalizedRuntime),Tt(({finalizedRuntime:{runtime:A}})=>A.pipe(Eh(null))),pn),T=_.pipe(x(A=>A?.lookup.metadata??null)),j=Vl(S.pipe(x(A=>A.hash)),B.pipe(x(A=>A.hash)),p),Z=b(u("body"),"body"),ce=A=>mr($(A,"body",Z(A))).pipe(x(C=>C.map(ee))),$e=b(u("storage"),"storage"),ot=j(d((A,C,H,N=null,fe)=>{const Ot=g.state.blocks.get(A);return g.state.runtimes[Ot.runtime].runtime.pipe(z(Xe=>{const Te=H(Xe);return $(A,`storage-${C}-${Te}-${N??""}`,$e(A,C,Te,N)).pipe(fe?x(nr=>fe(nr,Xe)):je)}),x(Xe=>({block:fn(Ot),value:Xe})))},"storage")),At=Fl(o,r),dv=j(d(An(g,(A,C,H)=>At(A,C,H??null,!1),"storageQueries"),"storageQueries")),hv=d(An(g,l,"header"),"header"),tc=A=>ot(A,"value",C=>C.events.key,null,(C,H)=>C?H.events.dec(C):[]).pipe(x(C=>C.value)),pv=b(u("call"),"call"),nc=j((A,C,H)=>$(A,`call-${C}-${H}`,pv(A,C,H).pipe(x(ee)))),ds=$h(nc,w),fv=_.pipe(Be(Boolean),te(1),z(A=>{const{enc:C}=A.dynamicBuilder.buildStorage("System","BlockHash").keys;let H;try{H=C(0)}catch{H=C(0n)}return ot(null,"value",()=>H,null).pipe(x(N=>N.value))}),sn(1));Qe(_,I).subscribe({error(){}});const vv=A=>g.state.runtimes[A]?.runtime??K(null),tr=(A,C=!1)=>{let H=A||"finalized";if(H=g.state[H]||H,!g.state.blocks.has(H)){if(C)throw new Je(H,"holdBlock");return Ee}h.next({type:"blockUsage",value:{type:"hold",hash:H}});let N=()=>{h.next({type:"blockUsage",value:{type:"release",hash:H}}),N=Ee};return()=>{N()}},bv=A=>C=>new D(H=>{const N=C.subscribe(H);return N.closed||N.add(tr(A)),N}),hs=m.pipe(Ht(Boolean)),mv=oa(k,hs,ce,ds,tc,tr),yv=oa(g,hs,ce,ds,()=>K(),tr);return{follow$:a,unfollow:i,finalized$:S,best$:B,bestBlocks$:I,newBlocks$:ct(k.pipe(te(1),z(({blocks:A,finalized:C})=>{const H=N=>{const fe=A.get(N);return fe?[fe,...Array.from(fe.children).flatMap(H)]:[]};return H(C)})),hs),runtime$:_,metadata$:T,genesis$:fv,hasher$:c,getRuntime$:vv,header$:hv,body$:ce,call$:nc,storage$:ot,storageQueries$:dv,eventsAt$:tc,withHodl:bv,holdBlock:tr,trackTx$:mv,trackTxWithoutEvents$:yv,validateTx$:ds,pinnedBlocks$:k,withRuntime:E,getRuntimeContext$:j(w)}};var Sh=e=>t=>new D(n=>e(Y(t),r=>{n.error(r)}));const Ih=({storageSubscription:e,...t})=>n=>{const r={},s=Mt(t.storage),o=(v,d,f)=>Mt(t.call)(v,d,f).pipe(x(ee)),i=Mt(t.header),a=v=>Mt(t.body)(v).pipe(x(d=>d.map(ee))),l=v=>i(v).pipe(x(Vn[1])),c=v=>s(v,"hash","0x3a636f6465",null).pipe(x(d=>d)),u=(v,d)=>n(v).pipe(de(()=>K(null)),z(f=>f?K(f):Qi((...b)=>o(d,...b)).pipe(x(b=>na(Fn(Dt.dec(b)),b,v)))),Kt(f=>{r[v]=f})),h=v=>c(v).pipe(z(d=>{const f=r[d];return f?K(f):u(d,v)})),p=(v,d,f,b=null,y)=>h(v).pipe(z(m=>s(v,d,f(m),b).pipe(x(g=>y?y(g,m):g))));return{body$:a,header$:l,storage$:p,storageQueries$:(v,d,f)=>new D(b=>e(v,d,f||null,y=>b.next(y),y=>b.error(y),()=>{b.complete()})),call$:o,eventsAt$:v=>p(v,"value",d=>d.events.key,null,(d,f)=>f.events.dec(d)),getRuntimeContext$:h}},Bh=()=>K(null),Ah=(e,{getMetadata:t,setMetadata:n}={})=>({chainHead$:()=>xh(e.chainHead,t||Bh,n||Ee),archive:Ih(e.archive),broadcastTx$:Sh(e.transaction),destroy:e.destroy}),Oh=(e,t)=>e.pipe(Ht(n=>n.blocks.has(t)),he((n,r)=>n.finalized===r.finalized&&n.best===r.best),x(n=>{if(n.blocks.get(t).number>n.blocks.get(n.best).number)return null;const{number:r}=n.blocks.get(t);let s=n.blocks.get(n.best),o=n.finalized===s.hash;for(;s.number>r;)s=n.blocks.get(s.parent),o=o||n.finalized===s.hash;return o?"finalized":s.hash===t?"best":null}),he(),Ht(n=>n!=="finalized",!0)),Vt=(e,t)=>(n,...r)=>e(n,...r).pipe(de(s=>{if(!(s instanceof Je))throw s;return t(n,...r).pipe(de(o=>{throw console.warn(o),s}))})),ht=R,Ch=Oe(Pe(W,ht)),q={bool:"boolean",str:"string",num:"number",big:"bigint",bits:"bitseq",void:"void"},_h=Se(Object.fromEntries(Object.values(q).map(e=>[e,M]))),Rh=Oe(Pe(W,Se({inline:xr(()=>Lr),lookup:ht}))),Th=Oe(ht),Hh=be({typeRef:ht,length:xt(ht)}),Mh=xt(ht),Uh=ht,zh=be({ok:ht,ko:ht}),Lr=Se({struct:Ch,terminal:_h,enum:Rh,tuple:Th,array:Hh,binary:Mh,option:Uh,result:zh}),Dh={i256:q.big,i128:q.big,i64:q.big,i32:q.num,i16:q.num,i8:q.num,u256:q.big,u128:q.big,u64:q.big,u32:q.num,u16:q.num,u8:q.num,bool:q.bool,char:q.str,str:q.str},vn=e=>({type:"terminal",value:{type:e}});function jr(e,t=()=>{}){switch(e.type){case"AccountId20":case"AccountId32":return vn(q.str);case"array":return e.value.type==="primitive"&&e.value.value==="u8"?{type:"binary",value:e.len}:(t(e.value.id),{type:"array",value:{typeRef:e.value.id,length:e.len}});case"bitSequence":return vn(q.bits);case"compact":return vn(e.isBig?q.big:q.num);case"enum":return{type:"enum",value:Object.entries(e.value).map(([n,r])=>r.type!=="lookupEntry"?[n,{type:"inline",value:jr(r,t)}]:(t(r.value.id),[n,{type:"lookup",value:r.value.id}]))};case"struct":{const n=Object.entries(e.value).map(([r,s])=>[r,s.id]);return n.forEach(([,r])=>t(r)),{type:"struct",value:n}}case"tuple":{const n=e.value.map(r=>r.id);return n.forEach(t),{type:"tuple",value:n}}case"option":return t(e.value.id),{type:"option",value:e.value.id};case"primitive":return vn(Dh[e.value]);case"result":return t(e.value.ok.id),t(e.value.ko.id),{type:"result",value:{ok:e.value.ok.id,ko:e.value.ko.id}};case"sequence":return e.value.type==="primitive"&&e.value.value==="u8"?{type:"binary",value:void 0}:(t(e.value.id),{type:"array",value:{typeRef:e.value.id}});case"void":return vn(q.void)}}function Nr(e,t,n){if(t.type==="option"&&e==null)return!0;const r=(o,i)=>Nr(o,i,n),s=o=>{switch(o.value.type){case q.str:case q.big:case q.bool:case q.num:return typeof e===o.value.type;case q.bits:return typeof e=="object"&&e!=null&&typeof e.bitsLen=="number"&&e.bytes instanceof Uint8Array;case q.void:return!0}};switch(t.type){case"terminal":return s(t);case"binary":return t.value==null?e instanceof Uint8Array:typeof e=="string"&&e.startsWith("0x");case"array":if(!Array.isArray(e))return!1;const o=e;return t.value.length!=null&&o.length<t.value.length?!1:o.slice(0,t.value.length).every(c=>r(c,n(t.value.typeRef)));case"enum":if(!e)return!1;const 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 Lh=Object.defineProperty,jh=(e,t,n)=>t in e?Lh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Nh=(e,t,n)=>jh(e,t+"",n);let la=class{constructor(t=[]){Nh(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 Vr(e,t,n,r,s,o=!1){if(!n&&!e)return Fe(3,[]);if(!n)return Fe(2,[]);if(!e)return Fe(n.type==="option"?2:0,[]);s.has(n)||s.set(n,new Map);const i=s.get(n);if(i.has(e)){const l=i.get(e);return l==null?{level:3,changes:[],assumptions:new la([[e,n]])}:Fe(l.level,l.changes)}i.set(e,null);const a=Vh(e,n,(l,c)=>Vr(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 Vh(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"?qn(s(e,t.value,"some"),2):e.type==="option"?qn(s(e.value,t,"some"),1):Fe(0,[]);switch(t.type){case"terminal":return Fe(t.value.type===e.value.type?3:0,[]);case"binary":return Fr(ha(e.value,t.value));case"array":const o=e,i=Fr(ha(o.value.length,t.value.length));return Pr([i,()=>s(o.value.typeRef,t.value.typeRef,"value")],r);case"enum":{const h=e,p=Object.fromEntries(t.value.map(([f,b])=>[f,b.value]));let v=da(h.value.map(([f,b])=>()=>f in p?s(b.value,p[f],f):Fe(0,[{id:[typeof b.value=="number"?b.value:null,null],level:0,path:f}])));if(h.value.length===t.value.length)return v;v=qn(v,2);const d=new Set(h.value.map(([f])=>f));return v.changes=[...v.changes,...t.value.filter(([f])=>!d.has(f)).map(([f,b])=>({id:[null,typeof b=="number"?b:null],level:0,path:f}))],v}case"option":return Ph(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 qn(Pr(t.value.map(([h,p])=>()=>s(l[h],p,h)),r),c);case"tuple":{const h=e,p=Fr(Fh(h.value,t.value));return Pr([p,...t.value.map((v,d)=>()=>s(h.value[d],v,String(d)))],r)}case"result":const u=e;return da([s(u.value.ok,t.value.ok,"ok"),s(u.value.ko,t.value.ko,"ko")])}}const qn=(e,t)=>({...e,level:Math.min(e.level,t)}),Ph=(e,t)=>({...e,level:Math.max(e.level,t)}),ua=new la,Fe=(e,t)=>({level:e,changes:t,assumptions:ua}),Pr=(e,t)=>{let n=Fe(3,[]);for(const r of e){const s=typeof r=="function"?r():r;if(!t&&s.level===0)return s;s.level!==3&&(n.changes=[...n.changes,...s.changes]),n.assumptions.addAll(s.assumptions.values),n.level=Math.min(n.level,s.level)}return n},da=e=>{if(!e.length)return Fe(3,[]);let t=!1,n=Fe(3,[]);for(const r of e){const s=typeof r=="function"?r():r;if(s.level!==3&&(n.changes=[...n.changes,...s.changes]),s.level===0){n.level=Math.min(n.level,1);continue}t=!0,n.assumptions.addAll(s.assumptions.values),n.level=Math.min(n.level,s.level)}return t?n:Fe(0,n.changes)},Fr=e=>({assumptions:ua,changes:e===3?[]:[{id:[null,null],level:e,path:"length"}],level:e}),Fh=(e,t)=>t.length===e.length?3:e.length>=t.length?2:0,ha=(e,t)=>t===e?3:t==null||e>=t?2:e==null?1:0,pa=Se({lookup:R,typedef:Lr}),Qt=e=>({type:"lookup",value:e}),Wr=e=>({type:"typedef",value:e}),Kn=Wr({type:"terminal",value:{type:q.void}}),Wh=be({args:pa,values:pa});function qh(e){if(e.type.tag==="plain")return{args:Kn,values:Qt(e.type.value)};const{key:t,value:n}=e.type.value;return{args:Qt(t),values:Qt(n)}}function fa(e){return{args:Wr({type:"tuple",value:e.inputs.map(t=>t.type)}),values:Qt(e.output)}}function Kh(e){return e.type==="lookupEntry"?Qt(e.value.id):Wr(jr(e))}function Xh(e){return{args:Kn,values:Qt(e)}}function Gh(e,t,n,r,s,o){const i=(a,l)=>a.type==="lookup"?l(a.value):a.value;return{args:Vr(i(e.args,t),t,i(n.args,r),r,s,o),values:Vr(i(n.values,r),r,i(e.values,t),t,s,o)}}function va(e,t,n){const r=e.type==="lookup"?t(e.value):e.value;return Nr(n,r,t)}const Xn=e=>{const t=new WeakMap,n={};return r=>{const s=r??n,o=t.get(s)||e(r);return t.set(s,o),o}},Yh=Oe(Wh),Qh=Oe(Lr),[,Jh]=Pe(Yh,Qh);var Le=(e=>(e.Storage="storage",e.Tx="tx",e.Event="events",e.Const="constants",e.ViewFns="viewFns",e.Api="apis",e))(Le||{});const Zh=async({metadataTypes:e,descriptors:t})=>{const[[n,r],s]=await Promise.all([e.then(Jh),t]);return{getTypeDefNode:o=>r[o],getEntryPointNode:(o,i,a)=>{const l=s[o]?.[i]?.[a];return l==null?l:n[l]}}},ba=(e,t)=>{const n=Kh(e),[r,s]=t==="args"?[n,Kn]:[Kn,n];return{args:r,values:s}},ma=Xn(({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=jr(e(i))),a)};return{getTypeDefNode:o,getEntryPointNode:(i,a,l)=>{switch(i){case"storage":{const c=n[a]?.storage.get(l);return c&&qh(c)}case"tx":{const c=n[a]?.call.get(l);return c&&ba(c,"args")}case"events":{const c=n[a]?.event.get(l);return c&&ba(c,"values")}case"viewFns":{const c=n[a]?.view.get(l);return c&&fa(c)}case"apis":{const c=r[a]?.get(l);return c&&fa(c)}case"constants":{const c=n[a]?.const.get(l);return c&&Xh(c.type)}}},isAssetCompat:i=>t==null||Nr(i,o(t),o)}}),ya=(e,t,n,r)=>{if(!e)return null;const{getEntryPointNode:s,getTypeDefNode:o}=e;return{entry:s(t,n,r),getter:o}},ep=bt({connector:()=>new en(1),resetOnError:!0,resetOnComplete:!0,resetOnRefCountZero:!0});function We(e,t){return new Promise((n,r)=>{let s=null,o=!1;const i=t?()=>{s?.unsubscribe(),r(new Ys)}:Ee;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 qr=Symbol("EMPTY_VALUE"),Kr=e=>t=>new D(n=>{let r=0,s=null,o=qr,i=!1;const a=()=>{const c=e(o,r++);o=qr,s=c.subscribe({next(u){n.next(u)},error(u){n.error(u)},complete(){o!==qr?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 ga={};const tp=e=>t=>new D(n=>{let r=ga,s=t.subscribe({next(o){n.next(r=o)},error(o){n.error(o)},complete(){r===ga?n.complete():s=e(r).subscribe(n)}});return()=>{s.unsubscribe()}}),Pt=e=>typeof e=="object"&&e!==null&&Object.entries(e).every(([t,n])=>t==="at"&&(n===void 0||typeof n=="string")||t==="signal"&&(n===void 0||n instanceof AbortSignal)),np=()=>{const e=new xc(new ye);return[e.pipe(pl()),()=>Kt({next:t=>e.value.next(t),error:t=>{e.value.error(t),e.next(new ye)},complete:()=>{e.value.complete(),e.next(new ye)}})]},rp={},wa=e=>new Proxy(rp,{get(t,n){return e(n)}}),nt=e=>{const t={};return wa(n=>(t[n]||(t[n]={}),wa(r=>(t[n][r]||(t[n][r]=e(n,r)),t[n][r]))))},Gn={level:pt.Incompatible,isCompatible:()=>!1,isValueCompatible:()=>!1},sp={args:Gn,value:Gn,isCompatible:()=>!1},op={level:pt.Identical,isCompatible:()=>!0,isValueCompatible:()=>!0},Yn=e=>(t=pt.BackwardsCompatible)=>e>=t,ip=(e,t,n,r)=>{let s;if(!r.entry)s=sp;else{const{args:o}=r.entry,i=l=>va(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}=Gh(n.entry,n.getter,r.entry,r.getter,t);s={args:{level:c.level,isValueCompatible:a,isCompatible:Yn(c.level)},value:u.level===pt.Incompatible?Gn:{level:u.level,isValueCompatible:u.level>pt.Partial?()=>!0:h=>va(l,n.getter,h),isCompatible:Yn(u.level)}}}else{const l=pt.Partial;s={args:{level:l,isValueCompatible:a,isCompatible:Yn(l)},value:n?Gn:op}}}return e===Le.Storage||e===Le.Api||e===Le.ViewFns?Object.assign(s,{isCompatible:Yn(Math.min(s.args.level,s.value.level))}):e===Le.Tx?s.args:s.value},ap=Xn(e=>{let t=null;const n=(e?Zh(e):Promise.resolve(null)).then(s=>t=s),r=Xn(s=>{const o=new Map,i=ma(s),a=l=>nt((c,u)=>ip(l,o,ya(t,l,c,u),ya(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=>ma(s).isAssetCompat}}),$a=({mappedMeta:e,dynamicBuilder:t},n,r)=>{const s=e.pallets[n].const.get(r);if(!s)throw new Error(`Runtime entry Constant(${n}.${r}) not found`);return t.buildConstant(n,r).dec(s.value)},cp=(e,t,n,r)=>({at:s,signal:o}={})=>We(ue([n.getRuntimeContext$(s||null),r]).pipe(x(([i,a])=>{const l=$a(i,e,t);if(a(i).isValueCompatible(l))return l;throw new Error(`Incompatible entry Const(${e}.${t})`)})),o),lp=(e,t,n,r)=>{const s=()=>new Error(`Incompatible runtime entry Event(${e}.${t})`),o=(a,l)=>n.eventsAt$(a).pipe(x(c=>c.filter(u=>u.event.type===e&&u.event.value.type===t).map(u=>{if(!l(u.event.value.value))throw s();return{original:u,payload:u.event.value.value}}))),i=ue([n.finalized$,r]).pipe(n.withRuntime(([a])=>a.hash),ca(([[a,l],c])=>{if(!c.mappedMeta.pallets[e]?.event.has(t))throw new Error(`Runtime entry Event(${e}.${t}) not found`);const{isValueCompatible:u}=l(c);return o(a.hash,u).pipe(x(h=>({block:a,events:h})))}),ep);return{watch:()=>i,get:a=>at(ue([r,n.getRuntimeContext$(a)]).pipe(te(1),Tt(([l,c])=>o(a,l(c).isValueCompatible)))),filter:a=>a.filter(({event:l})=>l.type===e&&l.value.type===t).map(l=>({original:l,payload:l.event.value.value}))}},up=(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=ue([n.getRuntimeContext$(h),r]).pipe(z(([v,d])=>{let f;try{f=v.dynamicBuilder.buildRuntimeCall(e,t)}catch{throw new Error(`Runtime entry RuntimeCall(${s}) not found`)}const b=d(v);if(!b.args.isValueCompatible(i))throw o();return n.call$(h,s,Y(f.args.enc(i))).pipe(x(f.value.dec),x(y=>{if(!b.value.isValueCompatible(y))throw o();return y}))}),n.withHodl(h));return We(p,c)}},Ea=(e,t,n,r,s)=>{let o;try{o=e.buildCall(n,r)}catch{throw new Error(`Runtime entry Tx(${n}.${r}) not found`)}if(!t(s))throw new Error(`Incompatible runtime entry Tx(${n}.${r})`);const{location:i,codec:[a]}=o;return oe([new Uint8Array(i),a(s)])},ka=(e,t,n,r)=>{const s=()=>new Error(`Incompatible runtime entry Storage(${t}.${n})`);let o;try{o=e.dynamicBuilder.buildStorage(t,n)}catch{throw s()}return(...i)=>{if(i.length===o.len&&!r(i))throw s();return o.keys.enc(...i)}},Xr=()=>new Error("Unkown signer"),dp=e=>{const{extrinsic:t}=e,n=Zi(e);let r,s;if("address"in t)r=n(t.address),s=n(t.signature);else{const o=Object.fromEntries(e.lookup[t.type].params.filter(i=>i.type!=null).map(i=>[i.name,n(i.type)]));if(r=o.Address,s=o.Signature,!r||!s)throw Xr()}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 Xr();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 Xr()},hp={Ed25519:0,Sr25519:1,Ecdsa:2},pp=(e,t,n,r,s,o)=>{const[i,a]=dp(e),l=oe([Hr.enc({version:4,type:"signed"}),i===1?t:new Uint8Array([...a,...t]),i===1||!o?n:new Uint8Array([hp[o],...n]),...r,s]);return oe([pe.enc(l.length),l])},[Qn,bn]=["<Bytes>","</Bytes>"].map(e=>zn.fromText(e)),fp=e=>async t=>{let n=!0,r;for(r=0;n&&r<Qn.length;r++)n=Qn[r]===t[r];n=n&&r===Qn.length;const s=t.length-bn.length;for(r=0;n&&r<bn.length;r++)n=bn[r]===t[s+r];return n=n&&r===bn.length,e(n?t:oe([Qn,t,bn]))};function vp(e,t,n){return{publicKey:e,signTx:async(r,s,o,i,a=jt)=>{const l=Fn(Ti(o)),c=[],u=[];l.extrinsic.signedExtensions[0].map(({identifier:v})=>{const d=s[v];if(!d)throw new Error(`Missing ${v} signed extension`);c.push(d.value),u.push(d.additionalSigned)});const h=oe([r,...c,...u]),p=await n(h.length>256?a(h):h);return pp(l,e,p,c,r,t)},signBytes:fp(n)}}Uint8Array.from([1]);const bp=(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 mp(e){let t=0;for(;!(e&1);)t++,e>>=1;return t}const yp=e=>1<<Math.ceil(Math.log2(e)),gp=Cn(ne(2)[0],e=>{const t=Math.min(Math.max(yp(e.period),4),65536),n=e.startAtBlock%t,r=Math.max(t>>12,1),s=Math.min(Math.max(mp(t)-1,1),15),o=n/r<<4;return et[0](s|o)}),[wp]=be({tip:pe,asset:xt(ne(1/0))}),xa=new Uint8Array,Gr=Uint8Array.from([0]),Yr=e=>({value:e,additionalSigned:xa}),Qr=e=>({value:xa,additionalSigned:e}),Jr=(e,t)=>({value:e,additionalSigned:t}),$p=(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=bp(t,n),h=v=>{const[d,f]=r[v],b=a[v];try{return mt({value:d,additionalSigned:f},(y,m)=>{const g=b?.[m];return g instanceof Uint8Array?g:y(g)})}catch{if(b)throw new Error(`Wrong input received for ${v}`);return c.push(v),null}},p=mt(r,([v,d],f)=>{if(a[f])return h(f);switch(f){case"CheckNonce":return Yr(v(i));case"CheckMortality":return s.mortal?Jr(gp({period:s.period,startAtBlock:s.startAtBlock.height}),ee(s.startAtBlock.hash)):Jr(Gr,e);case"ChargeTransactionPayment":return Yr(v(o));case"ChargeAssetTxPayment":return Yr(wp({tip:o,asset:l.asset}));case"CheckGenesis":return Qr(e);case"CheckMetadataHash":return Jr(Gr,Gr);case"CheckSpecVersion":return Qr(d(u.spec_version));case"CheckTxVersion":return Qr(d(u.transaction_version));default:return h(f)}});return c.forEach(v=>{delete p[v]}),mt(p,(v,d)=>({...v,identifier:d}))}},Sa="AccountNonceApi_account_nonce",Ep={1:P.dec,2:et.dec,4:Ve.dec,8:an.dec},kp=(e,t,n)=>e(n,Sa,t).pipe(x(r=>{const s=Ep[r.length];if(!s)throw new Error(`${Sa} retrieved wrong data`);return s(r)})),xp=(e,t)=>e.pinnedBlocks$.pipe(Ws(0),x(n=>{const r=s=>{const o=n.blocks.get(s);if(!o)return null;if(o.hasNewRuntime)return o;for(const i of o.children){const a=r(i);if(a)return a}return null};return r(t)?.hash??t}),he()),Sp=(e,t,n,r,s,o={})=>ue([o.nonce!=null?K(o.nonce):Ip(e,Y(t.publicKey)),xp(e,r.hash).pipe(Tt(e.getRuntimeContext$)),e.genesis$]).pipe(te(1),z(([i,a,l])=>{const c=$p(ee(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(rn((i,a)=>a.parent===i?a.hash:i,o),Ks(o),he()),r=o=>n(o).pipe(te(2),Tt(i=>kp(e.call$,t,i))),s=o=>ue(o.map(i=>r(i).pipe(x(a=>({success:!0,value:a})),de(a=>K({success:!1,value:a}))))).pipe(te(1));return e.pinnedBlocks$.pipe(te(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)}),Tt(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 Bp=Object.defineProperty,Ap=(e,t,n)=>t in e?Bp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Op=(e,t,n)=>Ap(e,t+"",n);const Cp=(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 v=s.blocks.get(l);if(!v)break;c=r.get(l=v.parent),u--}if(!c)return;const h=u<=s.blocks.get(s.finalized).number,p=c.found.type;if(p&&o?.found&&o.hash===c.hash){h&&n.complete();return}n.next(o=c.found.type?{found:p,hash:c.hash,number:u,index:c.found.index,events:c.found.events}:{found:p,validity:c.found.validity}),h&&(p?n.complete():c.found.validity?.success===!1&&n.error(new Ia(c.found.validity.value)))},a=t.pipe(he((l,c)=>l.finalized===c.finalized&&l.best===c.best)).subscribe({next:l=>{s=l,r.size!==0&&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)),_p=(e,t)=>{const n=e.filter(s=>s.phase.type==="ApplyExtrinsic"&&s.phase.value===t).map(s=>({...s,...s.event})),r=n[n.length-1];return r.type==="System"&&r.value.type==="ExtrinsicFailed"?{ok:!1,events:n,dispatchError:r.value.value.dispatch_error}:{ok:!0,events:n}};class Ia extends Error{constructor(t){super(JSON.stringify(t,(n,r)=>typeof r=="bigint"?r.toString():r instanceof Uint8Array?Y(r):r,2)),Op(this,"error"),this.name="InvalidTxError",this.error=t}}const Zr=(e,t,n,r=!1)=>e.hasher$.pipe(z(s=>{const o=Y(s(n)),i=(d,f)=>({type:d,txHash:o,...f}),a=e.pinnedBlocks$.state,l=d=>{if(!d.mortal)return 0;const{phase:f,period:b}=d,y=a.blocks.get(a.best).number;return Math.floor((Math.max(y,f)-f)/b)*b+f},c=d=>{let f=[...a.blocks.values()].filter(m=>!m.pruned&&!m.children.size);const b=Math.max(...f.map(({number:m})=>m));f=f.filter(({number:m})=>m>=b-1);const y=a.blocks.get(a.finalized);return f=y.children?[y,...f]:f,f.filter(m=>m.number>=d)},u=({hash:d})=>e.validateTx$(d,n),h=nn(()=>a.finalizedRuntime.runtime.pipe(x(d=>d.getMortalityFromTx(n)),x(l),x(c),z(d=>{let f;return Qe(...d.map(b=>ol(u(b),e.finalized$.pipe(Ht(y=>{if(y.number<b.number)return!0;let m=y;for(;m.number>b.number;){const g=a.blocks.get(m.parent);if(!g)return!1;m=g}return m.hash===y.hash}),kn(),qs({success:null}))))).pipe(Be((b,y)=>{if(b.success===!1&&(f??(f=new Ia(b.value))),b.success)return!0;if(y===d.length-1&&f)throw f;return!1}),te(1))}),kn())),p=new D(d=>{const f=e.trackTx$(n).subscribe(d);return f.add(t(n).subscribe({error(b){d.error(b)}})),f}),v=Cp(p,e.pinnedBlocks$).pipe(x(d=>d.found?i("txBestBlocksState",{found:!0,block:{index:d.index,number:d.number,hash:d.hash},..._p(d.events,d.index)}):i("txBestBlocksState",{found:!1,isValid:d.validity?.success!==!1})));return ct(r?K(i("signed",{})):Ye,h,K(i("broadcasted",{})),v.pipe(tp(({found:d,type:f,...b})=>d?K(i("finalized",b)):Ye)))})),Ba=async(e,t,n,r)=>Fc(Zr(e,t,n)).then(s=>{if(s.type!=="finalized")throw null;const o={...s};return delete o.type,o}),Rp=un().enc,Tp=new Uint8Array(64),Hp=new Uint8Array(65),Mp=e=>()=>e?Hp:Tp,[,Up]=be({weight:be({ref_time:Un,proof_size:Un}),class:Se({Normal:M,Operational:M,Mandatory:M}),partial_fee:Eo}),es=(e,t,n,r,s,o)=>{const i=c=>ue([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:v})=>{const d=Ea(h,v,e,t,c);return{callData:d,bare:oe([pe.enc(d.length+1),new Uint8Array(p.slice(-1)),d])}})),l=(c,u)=>c===void 0?K(void 0):i(u).pipe(x(({ctx:h,isAssetCompat:p})=>{if(!p(c))throw new Error("Incompatible runtime asset");const{dynamicBuilder:v,assetId:d}=h;if(d)return v.buildDefinition(d).enc(c)}));return c=>{const u=(y,{...m},g)=>ue([a(c,g.hash),l(m.asset,g.hash)]).pipe(z(([w,E])=>Sp(n,y,w.callData,g,m.customSignedExtensions||{},{...m,asset:E}))),h=(y,{at:m,...g}={})=>{const w=n.pinnedBlocks$.state.blocks.get(m);return m&&!w?Rt(()=>new Error(`Uknown block ${m}`)):(w?K(w):n.finalized$).pipe(te(1),z(E=>u(y,g,E).pipe(x($=>({tx:$,block:E})))))},p=(y,m)=>at(h(y,m)).then(g=>g.tx),v=(y,m)=>at(h(y,m)).then(({tx:g,block:w})=>Ba(n,r,g,w.hash)),d=(y,m)=>h(y,m).pipe(z(({tx:g})=>Zr(n,r,g,!0))),f=async(y,m)=>{typeof y=="string"&&(y=y.startsWith("0x")?ee(y):Rp(y));const g=y.length===20,w=vp(y,g?"Ecdsa":"Sr25519",Mp(g)),E=await p(w,m),$=Y(oe([E,Ve.enc(E.length)])),k=n.getRuntimeContext$(null).pipe(x(B=>{try{return B.dynamicBuilder.buildRuntimeCall("TransactionPaymentApi","query_info").value[1]}catch{return Up}})),S=n.call$(null,"TransactionPaymentApi_query_info",$);return at(ue([S,k]).pipe(x(([B,I])=>I(B))))},b=()=>at(a(c,null).pipe(x(({callData:y})=>y)));return{getPaymentInfo:f,getEstimatedFees:async(y,m)=>(await f(y,m)).partial_fee,decodedCall:{type:e,value:Dn(t,c)},getEncodedData:b,getBareTx:()=>at(a(c,null).pipe(x(({bare:y})=>y))),sign:p,signSubmitAndWatch:d,signAndSubmit:v}}},zp=(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 es(c,u,e,t,n("tx",c,u),s)(h)}catch{throw new Error("Invalid call data")}};return({at:i,signal:a}={})=>We(e.getRuntimeContext$(i??null).pipe(z(Xn(async l=>{const c=await r(l);return{id:l.codeHash,txFromCallData:o(l),constants:nt((u,h)=>$a(l,u,h)),query:nt((u,h)=>({getKey:ka(l,u,h,c.query[u][h].args.isValueCompatible)})),tx:nt((u,h)=>({getEncodedData:p=>Ea(l.dynamicBuilder,c.tx[u][h].isValueCompatible,u,h,p)})),compat:c}}))),a)},Dp=(e,t,n,r,s)=>{const o=e==="System"&&t==="Number",i=e==="System"&&t==="BlockHash",a=n.runtime$.pipe(Be(Boolean),te(1),x(({dynamicBuilder:d})=>typeof d.buildStorage("System","Number").value.dec(new Uint8Array(32))=="bigint"?BigInt:je),sn()),l=()=>new Error(`Incompatible runtime entry Storage(${e}.${t})`),c=d=>new Error(`Invalid Arguments calling ${e}.${t}(${d})`),u=d=>{try{return d.dynamicBuilder.buildStorage(e,t)}catch{throw new Error(`Runtime entry Storage(${e}.${t}) not found`)}},h=(...d)=>{const f=d.at(-1),b=Pt(f),[y,m]=b?[d.slice(0,-1),d.at(-1).at==="best"]:[d,!1];return n[m?"best$":"finalized$"].pipe(Kr(()=>p(...y,m?{at:"best"}:{})),rn((g,{value:w,block:E})=>g?{block:E,value:g.value.raw===w.raw?g.value:w}:{block:E,value:w},null),x(g=>({block:g.block,value:g.value.mapped})))},p=(...d)=>{const f=d[d.length-1],b=Pt(f),{at:y}=b?f:{},m=y??null,g=vt(s).pipe(z(w=>n.storage$(m,"value",E=>{const $=u(E),k=w(E),S=d.length===$.len?d:d.slice(0,-1);if(d!==S&&!b)throw c(d);if(!k.args.isValueCompatible(S))throw l();return $.keys.enc(...S)},null,(E,$)=>{const k=u($),{value:{isValueCompatible:S}}=w($),B=E===null?k.fallback:k.value.dec(E);if(!S(B))throw l();return{raw:E,mapped:B}})),n.withHodl(m));return o?n.pinnedBlocks$.pipe(x(w=>{const E=m==="finalized"||!m?w.finalized:m==="best"?w.best:m,$=w.blocks.get(E);if(!$)throw new Je(E,"System.Number");return $}),he((w,E)=>w.number===E.number),cl(a),x(([w,E])=>({block:w,value:{raw:w.number.toString(),mapped:E(w.number)}})),de(w=>{if(w instanceof Je)return g;throw w})):i&&Number(d[0])===0?ue([n.genesis$,n.pinnedBlocks$.pipe(x(w=>{const E=m==="finalized"||!m?w.finalized:m==="best"?w.best:m,$=w.blocks.get(E);if(!$)throw new Je(E,"System.BlockHash");return $}),te(1))]).pipe(x(([w,E])=>({block:E,value:{raw:w,mapped:w}}))):g},v=async(...d)=>{const f=d[d.length-1],b=Pt(f),{signal:y}=b?f:{};return We(p(...d).pipe(x(m=>m.value.mapped)),y)};return{getKey:(...d)=>at(ue([n.getRuntimeContext$(null),s]).pipe(x(([f,b])=>ka(f,e,t,b(f).args.isValueCompatible)(...d)))),getValue:v,getValues:(d,f)=>Promise.all(d.map(b=>v(...f?[...b,f]:b))),getEntries:async(...d)=>{const f=d[d.length-1],b=Pt(f),{signal:y,at:m}=b?f:{},g=m??null,w=vt(s).pipe(z(E=>n.storage$(g,"descendantsValues",$=>{const k=E($),S=u($);if(!k.isCompatible(pt.Partial))throw l();if(d.length>S.len)throw c(d);const B=d.length>0&&b?d.slice(0,-1):d;if(d.length===S.len&&B===d)throw c(d);return S.keys.enc(...B)},null,($,k)=>{const S=u(k),B=E(k),I=$.map(({key:_,value:T})=>({keyArgs:S.keys.dec(_),value:S.value.dec(T)}));if(B.value.level===pt.Partial&&I.some(({value:_})=>!B.value.isValueCompatible(_)))throw l();return I})),x(E=>E.value),n.withHodl(g));return We(w,y)},watchValue:h,watchEntries:(...d)=>{const f=d.at(-1),b=Pt(f);return r(e,t,b?d.slice(0,-1):d,b&&f.at==="best")}}},Aa="RuntimeViewFunction",Oa="execute_view_function",ts=Aa+"_"+Oa,Lp=(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=ue([n.getRuntimeContext$(u),r]).pipe(z(([p,v])=>{let d;try{d=p.dynamicBuilder.buildRuntimeCall(Aa,Oa)}catch{throw new Error(`Runtime entry RuntimeCall(${ts}) not found`)}let f;try{f=p.dynamicBuilder.buildViewFn(e,t)}catch{throw new Error(`Runtime entry ViewFn(${e}.${t}) not found`)}const b=v(p);if(!b.args.isValueCompatible(o))throw s();const y=f.args.enc(o),m=oe([ee(p.mappedMeta.pallets[e].view.get(t).id),R.enc(y.length),y]);return n.call$(u,ts,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(${ts}) type`)}}),x(({success:g,value:w})=>{if(!g)throw new Error(`ViewFn API Error: ${w.type}`);const E=f.value.dec(w);if(!b.value.isValueCompatible(E))throw s();return E}))}),n.withHodl(u));return We(h,l)}};var jp=Object.defineProperty,Np=(e,t,n)=>t in e?jp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,rt=(e,t,n)=>(Np(e,typeof t!="symbol"?t+"":t,n),n),ns=Symbol("SUSPENSE"),Vp=class extends Promise{constructor(e){super(e)}},Ca=class extends Error{constructor(){super(),this.name="NoSubscribersError"}},_a=class extends Error{constructor(){super(),this.name="EmptyObservableError"}},Re={},Jn=class extends D{constructor(e,t,n=Ee){super(r=>{const s=new Zt({next:r.next.bind(r),error:r.error.bind(r),complete:Ee});this.refCount++;let o;r.add(()=>{var 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 Ca),this.promise=null))}),this.subject?(o=this.subject.subscribe(s),this.currentValue!==Re&&r.next(this.currentValue)):(this.subject=new ye,o=this.subject.subscribe(s),this.subscription=null,this.subscription=new Zt({next:i=>{this.promise&&i!==ns&&(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===ns&&(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 _a),this.promise=null),this.currentValue!==Re)return this.subject.complete();if(t===Re){const i=this.subject;return this.subject=null,i.error(new _a)}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 Jn?s:new Jn(s,Re)}),rt(this,"getRefCount",()=>this.refCount),rt(this,"getValue",()=>{if(this.promise)return this.promise.p;if(this.currentValue!==Re&&this.currentValue!==ns)return this.currentValue;if(this.defaultValue!==Re)return this.defaultValue;if(this.refCount===0)throw new Ca;const r=new Vp((s,o)=>{this.promise={res:s,rej:o,p:null}});return this.promise.p=r,r}),rt(this,"getDefaultValue",()=>this.defaultValue),t===Re&&delete this.getDefaultValue}};function Ra(e,t){t.getValue=e.getValue,t.getRefCount=e.getRefCount,t.pipeState=e.pipeState,e.getDefaultValue&&(t.getDefaultValue=e.getDefaultValue)}function Pp(e,t){const n=new Fp,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 Jn(e(...o),r(...o),()=>{n.delete(i)}),c=new D(h=>{const p=n.get(i);let v=l;return p?p!==c&&(v=p,Ra(v,c)):n.set(i,u),v.subscribe(h)});Ra(l,c);const u=c;return n.set(i,u),u};return(...o)=>s(o)}var Fp=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 Wp(e,t){return new Jn(e,t)}var rs=(...e)=>(typeof e[0]=="function"?Pp:Wp)(e[0],e.length>1?e[1]:Re);const Ta=(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))}},Ha=(e,t,n,r=!1)=>{try{let s=r?e:n.blocks.get(e).parent;for(;s&&!t[s];)s=n.blocks.get(s).parent;return s?t[s]:null}catch{return null}},qp=(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)},Kp=(e,t,n)=>{const r=rs((a,l,c)=>{const u=qp(a,l),h=(b,y)=>{const m=Oh(e,y.hash).pipe(Be(g=>!g),te(1));return t(y.hash,"closestDescendantMerkleValue",()=>c).pipe(z(g=>{const w=g.value;return w===b?.rootHash?K({...b,block:y,deltas:null,prev:b.block.hash}):t(y.hash,"descendantsValues",()=>c).pipe(n(()=>y.hash),x(([E,$])=>[E.value,u($)]),x(([E,$])=>({prev:b&&b.block.hash,rootHash:w,block:y,patcher:$,...Ta(b?.entries??[],E,$)})))}),dr(m),de(g=>g instanceof Je?Ye:Rt(()=>g)))},p=e.pipe(he((b,y)=>b.finalized===y.finalized),Kr(({blocks:b,finalized:y})=>h(null,b.get(y))),te(1),x(b=>({blocks:{[b.block.hash]:b},finalized:b.block.hash}))),[v,d]=np(),f=e.pipe(he((b,y)=>b.best===y.best),Xs(v),Kr(([b,y])=>{const{best:m}=b,{blocks:g}=y;let w=g[m]?null:m;if(!w)return Ye;const E=Ha(w,g,b);return E?h(E,b.blocks.get(w)).pipe(x($=>(g[w]=$,y))):(w=b.finalized,h(g[y.finalized],b.blocks.get(w)).pipe(x($=>($.prev=null,{blocks:{[w]:$},finalized:w}))))}));return Qe(p,f).pipe(d())}),s=a=>(l,c,u)=>{const h=r(l,c,u),p=a?"finalized":"best";return ue([h,e.pipe(he((v,d)=>v[p]===d[p]))]).pipe(x(([v,d])=>{const f=Ha(d[p],v.blocks,d,!0);return f&&{update:f,state:v}}),Be(Boolean),he((v,d)=>v.update===d.update),Ks(null),hl(),z(([v,d])=>{if(!v)return[d.update];const{update:f}=v,{state:b,update:y}=d;let m=y;const g=[];for(;m&&m.block.number>f.block.number;)g.unshift(m),m=m.prev?b.blocks[m.prev]:null;if(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 f===m?g:[{...y,...f.rootHash===y.rootHash?{entries:f.entries,deltas:null}:Ta(f.entries,y.entries,y.patcher)}]}))},o=rs(s(!0)),i=rs(s(!1));return(a,l,c,u)=>{const h=u?i:o;return e.pipe(te(1),z(p=>p.runtimes[p.blocks.get(p[u?"best":"finalized"]).runtime].runtime),x(p=>p.dynamicBuilder.buildStorage(a,l).keys.enc(...c))).pipe(te(1),z(p=>h(a,l,p)),x(({block:{hash:p,number:v,parent:d},deltas:f,entries:b},y)=>{const m=y>0?f:{deleted:[],upserted:b};return{block:{hash:p,number:v,parent:d},entries:b.map(ss),deltas:m&&{deleted:m.deleted.map(ss),upserted:m.upserted.map(ss)}}}))}},ss=e=>e.dec,Xp=/^(?:0x)?((?:[0-9a-fA-F][0-9a-fA-F])+)$/,Ma=(e,t,n)=>{const r=ap(n),{getClientCompat:s,getIsAsssetCompat:o}=r,i=zp(e,t,r),a=Kp(e.pinnedBlocks$,e.storage$,e.withRuntime),l=nt((d,f)=>Dp(d,f,e,a,s("query",d,f))),c=nt((d,f)=>es(d,f,e,t,s("tx",d,f),o)),u=nt((d,f)=>lp(d,f,e,s("event",d,f))),h=nt((d,f)=>cp(d,f,e,s("constants",d,f))),p=nt((d,f)=>up(d,f,e,s("apis",d,f))),v=nt((d,f)=>Lp(d,f,e,s("view",d,f)));return{tx:c,constants:h,apis:p,view:v,query:l,event:u,txFromCallData:(d,{at:f,signal:b}={})=>We(e.getRuntimeContext$(f??null).pipe(x(({dynamicBuilder:y,lookup:m})=>{try{const{type:g,value:{type:w,value:E}}=y.buildDefinition(m.call).dec(d);return es(g,w,e,t,s("tx",g,w),o)(E)}catch{throw new Error("createTx: invalid call data")}})),b),getStaticApis:i}};function Gp(e,{getMetadata:t,setMetadata:n}={}){const r=Ul(e),s=Ah(r,{getMetadata:t?B=>vt(t(B)):void 0,setMetadata:n}),{getChainSpecData:o}=r,i=B=>(I,..._)=>ue([B(I,..._),c.header$(I).pipe(x(({number:T,parentHash:j})=>({hash:I,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$:nn(o).pipe(x(({genesisHash:B})=>B),de(()=>a),sn(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=(B,I,_)=>new D(T=>{let j=null,Z=null;const ce=()=>{Z!=null&&r.request(I,[Z])};return r._request(B,_,{onSuccess:($e,ot)=>{if(Z=$e,T.closed){ce();return}j=ot(Z,{next:At=>T.next(At),error:At=>T.error(At)})},onError($e){T.error($e)}}),()=>{ce(),j?.()}});let v;const d=new WeakMap,{broadcastTx$:f}=s,b=B=>u.getRuntimeContext$(B).pipe(x(I=>I.metadataRaw)),{holdBlock:y,finalized$:m,bestBlocks$:g,body$:w,header$:E,storage$:$,unfollow:k}=u,S={getChainSpecData:o,getMetadata$:b,getMetadata:(B,I)=>We(b(B),I),blocks$:u.newBlocks$,hodlBlock:B=>y(B,!0),finalizedBlock$:m,getFinalizedBlock:()=>at(m),bestBlocks$:u.bestBlocks$,getBestBlocks:()=>at(g),getBlockBody$:w,getBlockBody:(B,I)=>We(w(B),I),getBlockHeader$:E,getBlockHeader:(B,I)=>We(E(B),I),submit:(...B)=>Ba(u,f,...B),submitAndWatch:B=>Zr(u,f,B),getTypedApi:B=>{if(d.has(B))return d.get(B);const I=Ma(u,f);return d.set(B,I),I},getUnsafeApi:()=>(v??(v=Ma(u,f)),v),rawQuery:(B,{at:I,signal:_}={})=>We($(I??null,"value",()=>{const T=B.match(Xp)?.[1];return T?`0x${T}`:Y(zn.fromText(B))}).pipe(x(T=>T.value)),_),destroy:()=>{k(),s.destroy()},_request:h,_subscribe:p};return S.___INTERNAL_DO_NOT_USE=u,S}const st={body:"",call:"",continue:"",follow:"",header:"",stopOperation:"",storage:"",unfollow:"",unpin:""},os={body:"",call:"",finalizedHeight:"",genesisHash:"",hashByHeight:"",header:"",stopStorage:"",storage:""},is={broadcast:"",stop:""},Ua={chainName:"",genesisHash:"",properties:""};Object.entries({chainHead:st,chainSpec:Ua,transaction:is,archive:os}).forEach(([e,t])=>{Object.keys(t).forEach(n=>{t[n]=`${e}_v1_${n}`})});const Zn=sn({refCount:!0,bufferSize:1}),Yp=({allHeads$:e,finalized$:t,getHeader$:n,hasher$:r,getRecursiveHeader:s})=>{const o={blocks:new Map,prevFin:"",finalized:"",best:""},i=($,k=[])=>(k.push($),o.blocks.get($).children.forEach(S=>{i(S,k)}),k),a=$=>{const{blocks:k}=o,{hash:S,parent:B}=$,I={...$,children:new Set,usages:new Set};return k.set(S,I),k.get(B)?.children.add(S),I},l=()=>{o.best=o.finalized;let $=0;const{finalized:k,blocks:S}=o;i(k).map(B=>S.get(B)).forEach(B=>{B.number>$&&($=B.number,o.best=B.hash)})},c=new Map,u=$=>{const k=[...c.get($).children];c.delete($),k.forEach(u)},h=($,k=[])=>{const S=c.get($);return S.header&&(k.push(S.header),S.children.forEach(B=>{h(B,k)})),k},p=new ye,v=$=>p.error($),d=t.pipe(Fs(($,k)=>{const{hash:S}=$;return k||(a($),o.finalized=o.best=$.hash),o.blocks.has(S)?K(S):p.pipe(Be(B=>B===S),Ws(0),te(1))}),bt());e.subscribe($=>{const{parent:k,hash:S,number:B}=$;o.blocks.has(S)||!B||(o.blocks.has(k)?(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(I=>{let _=c.get(I.hash);if(!_)return!1;_.header=I;const T=o.blocks.get(o.finalized);if(T&&I.number<=T.number){for(;c.has(_.header?.parent??"");)_=c.get(_.header.parent);return u(_.hash),!1}if(o.blocks.has(I.parent)){let Z=o.blocks.get(I.parent);const ce=Z.number-T.number;for(let $e=0;$e<ce;$e++){const ot=o.blocks.get(Z.parent);if(!ot)break;Z=ot}return Z===T?h(I.hash).forEach($e=>{c.delete($e.hash),a($e),p.next($e.hash)}):u(I.hash),!1}const j=c.get(I.parent);return j?(j.children.add(I.hash),!1):(c.set(I.parent,{hash:I.parent,header:null,children:new Set([I.hash])}),!0)})).subscribe({error:v})),c.get(k).children.add(S)))},v);const f=()=>{const $=[],k=[],{blocks:S,finalized:B,prevFin:I}=o;let _=S.get(B),T=S.get(_.parent);for(;T&&(k.push(_.hash),T.children.forEach(j=>{j!==_.hash&&i(j,$)}),_=T,_.hash!==I);)T=S.get(_.parent);return k.reverse(),{event:"finalized",prunedBlockHashes:$,finalizedBlockHashes:k}};let b=new Set;const y=$=>{const k=o.blocks.get($);return b.forEach(S=>{k.usages.add(S)}),{event:"newBlock",blockHash:$,parentBlockHash:k.parent,newRuntime:k.hasUpgrade?{}:null}},m=($,k)=>{const{blocks:S}=o,B=S.get($);if(!B||B.usages.size>0)return;const{parent:I,children:_}=B;k!==!0&&_.forEach(T=>m(T,!1)),k!==!1&&m(I,!0),(!S.has(I)||!B.children.size)&&(S.get(I)?.children.delete($),S.delete($))},g=Qe(p.pipe(x($=>({type:"new",value:o.blocks.get($)}))),d.pipe(x($=>({type:"fin",value:$})))).pipe(z($=>{if($.type==="new"){const B=$.value,{hash:I}=B;a(B);const _=[y(I)];return B.number>o.blocks.get(o.best).number&&(o.best=I,_.push({event:"bestBlockChanged",bestBlockHash:I})),_}o.prevFin=o.finalized,o.finalized=$.value;let k=o.best;l();const S=[f()];return k!==o.best&&S.unshift({event:"bestBlockChanged",bestBlockHash:o.best}),S}),bt()),w=nn(()=>o.blocks.size?[null]:d.pipe(te(1),x(()=>null))).pipe(Zn),E=d.pipe(x($=>o.blocks.get($)),Zn);return Qe(g,E).subscribe({error:v}),{clean:()=>{c.clear(),o.blocks.clear()},upstream:$=>{const k=()=>{const{blocks:I,finalized:_}=o,T=[];let j=I.get(_);for(;j&&T.length<10;)T.push(j.hash),j.usages.add($),j=I.get(j.parent);return T.reverse(),{event:"initialized",finalizedBlockHashes:T}},S=I=>{const _=o.blocks.get(I);_&&(_.usages.delete($),m(I))},B=w.pipe(z(()=>{const{best:I,finalized:_}=o,T=i(_).slice(1).map(y);return T.push({event:"bestBlockChanged",bestBlockHash:I}),[k(),...T]}));return{blocks$:ct(B,g).pipe(Kt({subscribe:()=>{b.add($)},finalize:()=>{b.delete($)}}),bt()),getHeader:I=>o.blocks.get(I)?.header??null,isPinned:I=>!!o.blocks.get(I)?.usages.has($),unpin:S}},finalized$:E,getHeader$:$=>{const k=o.blocks.get($);return k?K(k):n($)},hasher$:r}},za=e=>({parentHash:t,number:n,stateRoot:r,extrinsicsRoot:s,digest:o})=>{const i=Number(n),a=o.logs.map(ee),l=oe([ee(t),pe.enc(i),ee(r),ee(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)}},Da=[jt,Ln],Qp=Da.map(za),Jp=e=>{throw new Error("Hasher not supported")},Zp=e=>t=>Da[Qp.findIndex(n=>n(e).hash===t)]||Jp,La=e=>t=>new D(n=>{let r,s=[],o=!1;const i=new _t;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}),ef={},tf=(e,t)=>{const n=new ye,r=n.pipe(z(h=>t("chain_getBlockHash",[h.number]).pipe(x(Zp(h)))),Zn),s=r.pipe(x(za),Zn),o=ys(La(s),x(([h,p])=>h(p))),i=(h,p,v=!1)=>new D(d=>{const f=m=>{d.error(m)};let b=null,y=v;return e(h,[],{onSuccess:(m,g)=>{const w=g(m,{next:$=>{y&&(y=!1,n.next($),n.complete()),d.next($)},error:f}),E=()=>{w();try{e(p,[m],{onError:V,onSuccess:V})}catch{}};b!==null?E():b=E},onError(){f(ef)}}),()=>{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(z(p=>ct(K(p),u(p.parent))));return{allHeads$:a,finalized$:l,hasher$:r,getRecursiveHeader:u,getHeader$:c}},nf=(e,t)=>Yp(tf(e,t)),rf=e=>(t,n)=>e("state_getReadProof",[[n],t]).pipe(z(r=>{const s=Xi(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]})),sf=e=>{const t=(m,g,w,E)=>e(m,g,{onSuccess:w,onError:E}),n=(m,g)=>new D(w=>t(m,g,E=>{w.next(E),w.complete()},E=>{w.error(E)}));let r=null;const s=()=>(r??(r=nf(e,n)),{...r,getBlocks:r.upstream}),o=()=>r?.clean(),i=(m,g,w)=>n("state_call",[g,w,m]),a=(m,g)=>{const w=$=>n("state_getKeysPaged",[g,1e3,$||void 0,m]).pipe(z(k=>{const S=k[0]===$?k.slice(1):k,B=k.length<1e3?Ye:w(k.at(-1));return Qe(K(S),B)})),E=($,k=0)=>$.length?n("state_queryStorageAt",[$,m]).pipe(x(([{changes:S}])=>S),de(S=>{if(k>3)throw S;const B=Math.floor($.length/2);return Qe(E($.slice(0,B),++k),E($.slice(B),k))})):Ye;return w().pipe(z($=>E($)))},l=(m,g)=>a(m,g).pipe(La(s().hasher$),x(([w,E])=>E.map(([$,k])=>[$,Y(w(ee(k)))]))),c=rf(n),[u,h]=["state_getStorage","state_getStorageHash"].map(m=>(g,w)=>n(m,[w,g])),p=n("rpc_methods",[]),v=n("system_name",[]),d=n("system_properties",[]),f=m=>n("chain_getBlock",[m]),b=m=>n("chain_getBlockHash",[m]),y=b(0);return{subscribeBlocks:s,getBlockHash$:b,stgValue:u,stgHash:h,stgDescendantValues:a,stgDescendantHashes:l,stgClosestDescendant:c,runtimeCall:i,getBody:f,chainName:v,properties:d,genesisHash:y,methods:p,request:t,obsRequest:n,clean:o}};let of=1;const Jt=()=>`${of++}${Date.now()}`,af=new Set(["value","hash","closestDescendantMerkleValue","descendantsValues","descendantsHashes"]),ja=e=>Array.isArray(e)&&e.every(t=>typeof t=="object"&&typeof t.key=="string"&&af.has(t.type)),Na=(e,t,n)=>Qe(...n.map(({key:r,type:s})=>{switch(s){case"value":return e.stgValue(t,r).pipe(Be(Boolean),x(o=>[{key:r,value:o}]));case"hash":return e.stgHash(t,r).pipe(Be(Boolean),x(o=>[{key:r,hash:o}]));case"descendantsValues":return e.stgDescendantValues(t,r).pipe(x(o=>o.map(([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(Be(Boolean),x(o=>[{key:r,closestDescendantMerkleValue:o}]))}})),mn=e=>e instanceof Error?e.message:typeof e=="string"?e:"Unhandled exception",{body:cf,call:lf,finalizedHeight:uf,genesisHash:df,hashByHeight:hf,header:pf,stopStorage:ff,storage:vf}=os,bf=(e,t,n,r)=>{const s=new Map,o=(a,l,c)=>{const u=Jt();a(u);const h=v=>{r("archive_v1_storageEvent",u,v)},p=Na(e,l,c).pipe(lr(()=>{s.delete(u)})).subscribe(v=>{v.forEach(d=>h({event:"storage",...d}))},v=>{h({event:"storageError",error:mn(v)})},()=>{h({event:"storageDone"})});p.closed||s.set(u,p)},i=(a,l,c)=>{const u=f=>{t(a,f)},h=f=>{f.subscribe({next:u,error:b=>{n(a,b.code??-1,mn(b))}})},[p,v,d]=c;switch(l){case cf:return h(e.getBody(p).pipe(x(({block:f})=>f.extrinsics)));case lf:return h(e.runtimeCall(p,v,d).pipe(x(f=>({success:!0,value:f}))));case uf:return h(e.subscribeBlocks().finalized$.pipe(x(f=>f.number),te(1)));case df:return h(e.genesisHash);case hf:return h(e.getBlockHash$(p).pipe(x(f=>[f])));case pf:return h(e.subscribeBlocks().getHeader$(p).pipe(x(f=>f.header)));case ff:{const f=s.get(p);return f?f.unsubscribe():n(a,-32602,"Invalid args")}case vf:return ja(v)?o(u,p,v):n(a,-32602,"Invalid args")}throw null};return i.stop=()=>{[...s].forEach(([,a])=>a.unsubscribe()),s.clear()},i},mf=(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:yf,broadcast:gf}=is,wf=(e,t)=>{const n=new Map,r=(s,o,i)=>{if(o===yf){const[a]=i;n.get(a)?.unsubscribe(),n.delete(a),t(s,null)}else if(o===gf){const a=Jt();n.set(a,e.obsRequest("author_submitExtrinsic",i).pipe(de((l,c)=>ct(En(5e3),c)),dr(e.subscribeBlocks().finalized$.pipe(kn(),de(()=>(n.delete(a),[null]))))).subscribe()),t(s,a)}else throw null};return r.stop=()=>{n.forEach(s=>s.unsubscribe()),n.clear()},r},{follow:$f,header:Ef,storage:Va,body:as,call:Pa,unfollow:kf,stopOperation:xf,unpin:Sf}=st,If=(e,t,n,r)=>{const s=new Map,o=d=>{if(s.size===2)return n(d,-32800,"Limit reached");const f=Jt(),b=E=>r("chainHead_v1_followEvent",f,E),y=e.subscribeBlocks().getBlocks(f),m=new Map;s.set(f,{id:f,up:y,operations:m,cleanUp:()=>{w()}}),t(d,f);let g=null,w=()=>{w=V,g?.unsubscribe(),g=null,m.forEach(E=>{E()}),m.clear(),s.delete(f)};g=y.blocks$.subscribe({next(E){b(E)},error(){w(),b({event:"stop"})}}),g.closed&&(g=null)},i=(d,f)=>{s.get(f)?.cleanUp(),t(d,"null")},a=(d,f,b)=>{const y=s.get(f)?.operations.get(b);y&&y(),t(d,"null")},l=({up:{getHeader:d}},f,b)=>f(d(b)),c=({up:{unpin:d}},f,b)=>{(typeof b=="string"?[b]:b).forEach(d),f(null)},u=({operations:d,id:f},b,y,m,g)=>{const w=Jt();b({result:"started",operationId:w});const E=(k,S=!1)=>r(Pa,f,S?{operationId:w,event:"operationError",error:k}:{operationId:w,event:"operationCallDone",output:k}),$=e.runtimeCall(y,m,g).subscribe(k=>{d.delete(w),E(k)},k=>{d.delete(w),E(mn(k),!0)});$.closed||d.set(w,()=>{$.unsubscribe(),d.delete(w)})},h=({operations:d,id:f},b,y)=>{const m=Jt();b({result:"started",operationId:m});const g=e.getBody(y).subscribe(({block:{extrinsics:w}})=>{d.delete(m),r(as,f,{event:"operationBodyDone",operationId:m,value:w})},w=>{d.delete(m),r(as,f,{event:"operationError",operationId:m,error:mn(w)})});g.closed||d.set(m,()=>{g.unsubscribe(),d.delete(m)})},p=({operations:d,id:f},b,y,m)=>{const g=Jt();b({result:"started",operationId:g});const w=$=>{r(Va,f,$)},E=Na(e,y,m).pipe(lr(()=>{d.delete(g)})).subscribe($=>{w({event:"operationStorageItems",operationId:g,items:$})},$=>{w({event:"operationError",operationId:g,error:mn($)})},()=>{w({event:"operationStorageDone",operationId:g})});E.closed||d.set(g,()=>{E.unsubscribe()})},v=(d,f,b)=>{if(f===$f)return o(d);const[y,...m]=b,g=s.get(y);if(!g)return n(d,-32602,"Ivalid followSubscription");const w=E=>{t(d,E)};switch(f){case kf:return i(d,y);case xf:return a(d,y,m[0]);case Sf:{const[E]=m;return(Array.isArray(E)?E:[E]).some($=>typeof $!="string")?n(d,-32602,"Invalid args"):c(g,w,E)}default:{const[E,...$]=m;if(!g.up.isPinned(E))return n(d,-32801,"Block not pinned");switch(f){case Ef:return l(g,w,E);case as:return h(g,w,E);case Pa:{const[k,S]=$;return typeof k!="string"||typeof S!="string"?n(d,-32602,"Invalid args"):u(g,w,E,k,S)}case Va:{const[k]=$;return ja(k)?p(g,w,E,k):n(d,-32602,"Invalid args")}}}}throw null};return v.stop=()=>{s.forEach(d=>{d.cleanUp()})},v},Fa=new Set([st,Ua,os,is].map(e=>Object.values(e)).flat()),Bf=e=>(t,n)=>{let r=V,s=V;const o=e(b=>{s(b)},b=>{r(),n(b)}),{disconnect:i,request:a}=fr(b=>(s=b,o),t),l=sf(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}})},v={chainSpec:()=>mf(l,u,h),chainHead:()=>If(l,u,h,p),archive:()=>bf(l,u,h,p),transaction:()=>wf(l,u)},d={},f=b=>b in d?d[b]:b in v?d[b]=v[b]():null;return r=()=>{d.chainHead?.stop(),d.archive?.stop(),d.transaction?.stop(),l.clean()},{send:b=>{if(!b)return;const{id:y,method:m,params:g}=b;if(y!==null&&typeof y!="string"&&typeof y!="number"||typeof m!="string"){console.warn(`Invalid message:
4
- ${JSON.stringify(b)}`);return}if(m==="rpc_methods")return l.methods.subscribe(({methods:$})=>{u(y,{methods:[...Fa,...$.filter(k=>!Fa.has(k))]})},$=>{console.error($),h(y,-32602,"Invalid")});const[w]=m.split("_"),E=f(w);if(E)try{return E(y,m,g)}catch($){if($!==null)throw $}l.request(m,g,$=>{u(y,$)},$=>{h(y,$?.code||-1,$?.message||"")})},disconnect:()=>{r(),i()}}},{follow:Af,unfollow:Of}=st,Wa=()=>({latest:Date.now(),count:0}),Cf=e=>(t,n)=>{const r=new Map,s=new Map,o=new Set;let i=Wa();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:v}=h;if(s.get(p)){s.delete(p);const d=r.get(v);if(d){r.delete(v),t(h),t(d);return}o.add(v);const f=o.size+s.size;if(f>2)console.warn(`Too many chainHead follow subscriptions (${f})`);else if(h.error){console.warn(`chainHead follow failed on the ${f} sub`),l();return}}}else{const{subscription:p,result:v}=h.params;if(v?.event==="stop"){const d=Date.now()-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=Wa(),l())},h=>{a(),n(h)});return{send(h){const{method:p}=h;p===Af?s.set(h.id,h):p===Of&&o.delete(h.params[0]),c(h)},disconnect:u}},{follow:_f,unpin:Rf,unfollow:Tf}=st,Hf=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 v=c.params.result,{event:d}=v;if(d==="initialized"&&v.finalizedBlockHashes.forEach(f=>{h.add(f)}),d==="newBlock"){const{parentBlockHash:f}=v;if(!h.has(f)){const m=p.get(f)??[];m.push(c),p.set(f,m);return}const b=v.blockHash;h.add(v.blockHash),t(c);const y=p.get(b);y&&(p.delete(b),y.forEach(m=>{h.add(m.params.result.blockHash),t(m)}));return}d==="stop"&&(h.delete(u),o.delete(u))}t(c)}},i(n));return{send:c=>{const u=c.params[0];switch(c.method){case _f:r.add(c.id);break;case Rf:const[h,p]=c.params;p.forEach(v=>{s.get(h)?.delete(v),o.get(h)?.delete(v)});break;case Tf:s.delete(u),o.delete(u);break}a(c)},disconnect:i(l)}},{follow:Mf,unpin:Uf,unfollow:zf}=st,Df=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 v=c.params.result,{event:d}=v;if(d==="initialized"&&v.finalizedBlockHashes.forEach(f=>{h.add(f)}),d==="finalized"&&(v.prunedBlockHashes=v.prunedBlockHashes.filter(f=>h.has(f))),d==="newBlock"){h.add(v.blockHash);const f=v.blockHash,b=p.get(f);if(b){p.delete(f),t(c),Promise.resolve().then(()=>{t(b)});return}}if(d==="bestBlockChanged"){const f=v.bestBlockHash;if(!h.has(f)){o.get(u).set(f,c);return}}d==="stop"&&(h.delete(u),o.delete(u))}t(c)}},i(n));return{send:c=>{const u=c.params[0];switch(c.method){case Mf:r.add(c.id);break;case Uf:const[h,p]=c.params;p.forEach(v=>{s.get(h)?.delete(v),o.get(h)?.delete(v)});break;case zf:s.delete(u),o.delete(u);break}a(c)},disconnect:i(l)}},{follow:Lf,body:jf,call:Nf,storage:Vf,unfollow:Pf,stopOperation:Ff}=st,Wf=new Set(["BodyDone","CallDone","StorageDone","Inaccessible","Error"].map(e=>"operation"+e)),qa=e=>Wf.has(e.params?.result?.event),qf=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 v=s.get(h);if(v!==void 0){s.delete(h);const d=u.result?.operationId;if(d!==void 0&&o.has(v)){const f=o.get(v);f.add(d);const b=i.get(v)?.get(d);b&&(b.forEach(t),i.get(v).delete(d),qa(b.at(-1))&&f.delete(d))}}}else{const{subscription:h,result:p}=u.params,v=o.get(h);if(v){const{operationId:d}=u.params.result;if(d!==void 0)if(v.has(d))qa(u)&&v.delete(d);else{const f=i.get(h),b=f.get(d)??[];b.push(u),f.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 Lf:r.add(u.id);break;case jf:case Nf:case Vf:s.set(u.id,h);break;case Pf:o.delete(h),i.delete(h);break;case Ff:o.get(h)?.delete(u.params[1])}l(u)},disconnect:a(c)}},Kf=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),Xf=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}},cs=(...e)=>t=>e.reduce((n,r)=>r(n),t),Ka=e=>({jsonrpc:"2.0",...e}),Gf=(e,t,n,r={})=>Ka({method:"chainHead_v1_followEvent",params:{subscription:e,result:{event:t,operationId:n,...r}}}),Yf=new Set(["newBlock","bestBlockChanged","stop"]),Qf=cs(qf,Xf,Kf,Hf,Df,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 v=setTimeout(()=>{s.delete(c),t(Gf(c,"bestBlockChanged",void 0,{bestBlockHash:h.finalizedBlockHashes.at(-1)}))},500);s.set(c,()=>{s.delete(c),clearTimeout(v)})}else Yf.has(p)&&u()}}t(l)},o(n));return{send(l){switch(l.method){case st.follow:r.add(l.id);break;case st.unfollow:s.get(l.params[0])?.()}i(l)},disconnect:o(a)}},Cf),Xa=["chainHead","transaction","chainSpec","archive"].map(e=>`${e}_v1`),Jf=e=>{const t=Object.fromEntries(Xa.map(n=>[n,!!e.find(r=>r.startsWith(n))]));return n=>{const r=Zf(n),s=Qf(r()),o=Bf(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 Xa)if(u.method.startsWith(h)){t[h]?l.send(u):c.send(u);return}l.send(u)},disconnect(){l.disconnect(),c.disconnect()}}}}},Zf=e=>{const t=new ye,n=new ye;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(Be(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,v=n.pipe(Be(d=>d.id===p),te(1)).subscribe(d=>{if(i(d),!v)throw new Error("unreachable");u.delete(v)});u.add(v),s?.send(h)},disconnect(){l.unsubscribe(),c.unsubscribe(),u.forEach(h=>h.unsubscribe()),r--,r===0&&(s?.disconnect(),s=null)}}}},ev=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:v}=fr(d=>(s=d,{...h,disconnect:V}));return l&&(a=e(d=>{a=V,d?({send:i,disconnect:p}=d((f,b)=>(u=y=>{c(),b(y)},s=f,h))(n,r),o.forEach(i),o=[]):u()},v)),{send:d=>{i(d)},disconnect:()=>{c(),p()}}},Ga="rpc_methods",tv=e=>t=>(n,r)=>{const s={methods:e},{send:o,disconnect:i}=t(n,r);return{disconnect:i,send(a){a.id&&a.method===Ga?n(Ka({id:a.id,result:s})):o(a)}}},nv=cs(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=>ev((t,n)=>{let r=0,s=V;const o=()=>{r++,s=n(Ga,[],{onSuccess:({methods:i})=>{t(cs(tv(i),e(i)))},onError:()=>{if(r>3)t(null);else{const i=setTimeout(o,500);s=()=>clearTimeout(i)}}})};return o(),()=>s()}))(Jf));var qe=(e=>(e.CONNECTING="CONNECTING",e.CONNECTED="CONNECTED",e.ERROR="ERROR",e.CLOSE="CLOSE",e))(qe||{}),Ke=(e=>(e.CONNECTING="CONNECTING",e.CONNECTED="CONNECTED",e.TIMEOUT="TIMEOUT",e.STALE="STALE",e.ERROR="ERROR",e.CLOSE="CLOSE",e.DISCONNECT="DISCONNECT",e.IN="IN",e.OUT="OUT",e))(Ke||{});let rv=0;const Ya=()=>`proxyOpaque${rv++}`,er=e=>({jsonrpc:"2.0",...e}),ls=e=>({jsonrpc:"2.0",...e}),Qa=()=>`___proxyInternalId__${Ya()}`,sv=e=>{let t={type:1,activeBroadcasts:new Map,pending:[]};const n=s=>{let o=!0;if(t.type===0){if(Zs(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(er({id:Qa(),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(ls({id:i,result:null})),t.type===0&&h&&h.upToken&&t.connection.send(er({id:i,method:o,params:[h.upToken]}));return}if(c==="broadcast"){const u=Ya();t.activeBroadcasts.set(u,{tx:a[0],synToken:u}),t.type===0&&(t.pendingBroadcasts.set(i,u),t.connection.send(s)),e(ls({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(er({method:"chainHead_v1_follow",params:{subscription:h,result:{event:"stop",internal:!0}}}))}),l.clear();for(const h of a.values())h.type===1?n(ls({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=Qa();t.pendingBroadcasts.set(h,u.synToken),t.connection.send(er({id:h,method:"transaction_v1_broadcast",params:[u.tx]}))}}),o.forEach(r)}}},us=()=>{},Ja=250,ov=e=>t=>{let n=sv(t),r=Date.now(),s=0,o;const i=()=>s&&2**Math.min(5,s)*Ja;let a=us,l=()=>{const u=setTimeout(()=>{let h=!0;const p=e(v=>{h=!1,a=us,v?n&&n.connect((d,f)=>{let b=!0;return v(d,y=>{if(b){b=!1;const m=Date.now()-r;s+=m>Ja+i()?-s:1,r+=m,f(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=us,n?.disconnect(),n=null}}},iv=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()}}},av=(e,t,n,r)=>{const s=r?i=>r({type:i}):V,o=r?(i,a)=>r({type:i,msg:a}):V;return iv(i=>{const[a,l]=e();r?.({type:Ke.CONNECTING,url:a.url});let c=()=>{c=V,d(),i(null)},u=!0,h;const p=()=>{clearTimeout(h);const[g,w]=u?[n,Ke.TIMEOUT]:[t,Ke.STALE];u=!1,h=setTimeout(()=>{s(w),c({type:qe.ERROR,event:{type:"timeout"}})},g)},v=()=>{clearTimeout(h)};p();let d=()=>{v()};const f=g=>{r?.({type:Ke.ERROR,error:g}),c({type:qe.ERROR,event:g})},b=g=>{s(Ke.CLOSE),c({type:qe.CLOSE,event:g})},y=()=>{s(Ke.DISCONNECT),d();try{a.addEventListener("error",V,{once:!0}),a.close()}catch{}},m=()=>{s(Ke.CONNECTED),l(),p(),a.removeEventListener("open",m),i((g,w)=>{d=()=>{d=V,v(),a.removeEventListener("error",f),a.removeEventListener("ping",p),a.removeEventListener("message",E),a.removeEventListener("close",b)},c=$=>{c=V,d(),w($)};const E=$=>{p(),typeof $.data=="string"&&(o(Ke.IN,$.data),g(JSON.parse($.data)))};return a.addEventListener("ping",p),a.addEventListener("message",E),a.addEventListener("error",f),a.addEventListener("close",b),{send($){const k=JSON.stringify($);o(Ke.OUT,k),a.send(k)},disconnect:y}})};return d=()=>{d=V,v(),a.removeEventListener("error",f),a.removeEventListener("close",b),a.removeEventListener("open",m)},a.addEventListener("open",m),a.addEventListener("error",f),y})},cv={onStatusChanged:V,timeout:5e3,heartbeatTimeout:4e4,middleware:je},Za=(e,t)=>{const{onStatusChanged:n,timeout:r,heartbeatTimeout:s,middleware:o,logger:i}={...cv,...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:qe.CLOSE,event:null},v;const d=m=>n(p=m),f=o(av(()=>{v=h?.url;const m=u??a[c++%a.length];return u=void 0,d({type:qe.CONNECTING,uri:m}),[h=new l(m),()=>{d({type:qe.CONNECTED,uri:m})}]},s,r,i)),b=(m,g)=>f(m,w=>{d({type:qe.ERROR,event:w}),g(w)}),y=ov(m=>{if(!v||h.url!==v)return m(b),V;const g=setTimeout(m,250,b);return()=>{clearTimeout(g)}});return Object.assign(y,{switch:m=>{p.type!==qe.CLOSE&&(u=m,p.type!==qe.ERROR&&h&&h.close())},getStatus:()=>p})},lv=(e,t={})=>Za(e,t),ec=(e,t={})=>Za(e,{...t,middleware:nv}),uv=(e,t={})=>{const n=ec(e,t),r=Gp(n,t);return Object.assign(r,{switch:n.switch,getStatus:n.getStatus})};it.SocketEvents=Ke,it.WsEvent=qe,it.createWsClient=uv,it.getWsProvider=ec,it.getWsRawProvider=lv}));
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 _t=(function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,n,r,s,o;if(!this.closed){this.closed=!0;var 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(f){t={error:f}}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(f){o=f instanceof sr?f.errors:[f]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var p=Ft(h),v=p.next();!v.done;v=p.next()){var d=v.value;try{ms(d)}catch(f){o=o??[],f instanceof sr?o=Me(Me([],He(o)),He(f.errors)):o.push(f)}}}catch(f){r={error:f}}finally{try{v&&!v.done&&(s=p.return)&&s.call(p)}finally{if(r)throw r.error}}}if(o)throw new sr(o)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)ms(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})(),vs=_t.EMPTY;function bs(e){return e instanceof _t||e&&"closed"in e&&Q(e.remove)&&Q(e.add)&&Q(e.unsubscribe)}function ms(e){Q(e)?e():e.unsubscribe()}var fc={Promise:void 0},vc={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,Me([e,t],He(n)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function ys(e){vc.setTimeout(function(){throw e})}function Ee(){}function wn(e){e()}var en=(function(e){Ge(t,e);function t(n){var r=e.call(this)||this;return r.isStopped=!1,n?(r.destination=n,bs(n)&&n.add(r)):r.destination=yc,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})(_t),bc=(function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var n=this.partialObserver;if(n.next)try{n.next(t)}catch(r){$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){Ge(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 bc(i),o}return t})(en);function $n(e){ys(e)}function mc(e){throw e}var yc={closed:!0,next:Ee,error:mc,complete:Ee},or=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function je(e){return e}function gs(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return ws(e)}function ws(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=wc(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=$s(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[or]=function(){return this},e.prototype.pipe=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return ws(t)(this)},e.prototype.toPromise=function(t){var n=this;return t=$s(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 $s(e){var t;return(t=e??fc.Promise)!==null&&t!==void 0?t:Promise}function gc(e){return e&&Q(e.next)&&Q(e.error)&&Q(e.complete)}function wc(e){return e&&e instanceof en||gc(e)&&bs(e)}function $c(e){return Q(e?.lift)}function J(e){return function(t){if($c(t))return t.lift(function(n){try{return e(n,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function G(e,t,n,r,s){return new Ec(e,t,n,r,s)}var Ec=(function(e){Ge(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})(en),kc=rr(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),ye=(function(e){Ge(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 Es(this,this);return r.operator=n,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new kc},t.prototype.next=function(n){var r=this;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?vs:(this.currentObservers=null,a.push(n),new _t(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 Es(n,r)},t})(D),Es=(function(e){Ge(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:vs},t})(ye),xc=(function(e){Ge(t,e);function t(n){var r=e.call(this)||this;return r._value=n,r}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(n){var r=e.prototype._subscribe.call(this,n);return!r.closed&&n.next(this._value),r},t.prototype.getValue=function(){var n=this,r=n.hasError,s=n.thrownError,o=n._value;if(r)throw s;return this._throwIfClosed(),o},t.prototype.next=function(n){e.prototype.next.call(this,this._value=n)},t})(ye),ir={now:function(){return(ir.delegate||Date).now()},delegate:void 0},tn=(function(e){Ge(t,e);function t(n,r,s){n===void 0&&(n=1/0),r===void 0&&(r=1/0),s===void 0&&(s=ir);var o=e.call(this)||this;return o._bufferSize=n,o._windowTime=r,o._timestampProvider=s,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=r===1/0,o._bufferSize=Math.max(1,n),o._windowTime=Math.max(1,r),o}return t.prototype.next=function(n){var r=this,s=r.isStopped,o=r._buffer,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})(ye),Sc=(function(e){Ge(t,e);function t(n,r){return e.call(this)||this}return t.prototype.schedule=function(n,r){return this},t})(_t),ks={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},Ic=(function(e){Ge(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),ks.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&&ks.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})(Sc),xs=(function(){function e(t,n){n===void 0&&(n=e.now),this.schedulerActionCtor=t,this.now=n}return e.prototype.schedule=function(t,n,r){return n===void 0&&(n=0),new this.schedulerActionCtor(this,t).schedule(r,n)},e.now=ir.now,e})(),Bc=(function(e){Ge(t,e);function t(n,r){r===void 0&&(r=xs.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})(xs),Ss=new Bc(Ic),Ac=Ss,Ye=new D(function(e){return e.complete()});function Oc(e){return e&&Q(e.schedule)}function ar(e){return e[e.length-1]}function cr(e){return Q(ar(e))?e.pop():void 0}function nn(e){return Oc(ar(e))?e.pop():void 0}function Cc(e,t){return typeof ar(e)=="number"?e.pop():t}var Is=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function Bs(e){return Q(e?.then)}function As(e){return Q(e[or])}function Os(e){return Symbol.asyncIterator&&Q(e?.[Symbol.asyncIterator])}function Cs(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function _c(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var _s=_c();function Rs(e){return Q(e?.[_s])}function Ts(e){return hc(this,arguments,function(){var n,r,s,o;return fs(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 Hs(e){return Q(e?.getReader)}function ue(e){if(e instanceof D)return e;if(e!=null){if(As(e))return Rc(e);if(Is(e))return Tc(e);if(Bs(e))return Hc(e);if(Os(e))return Ms(e);if(Rs(e))return Mc(e);if(Hs(e))return Uc(e)}throw Cs(e)}function Rc(e){return new D(function(t){var n=e[or]();if(Q(n.subscribe))return n.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Tc(e){return new D(function(t){for(var n=0;n<e.length&&!t.closed;n++)t.next(e[n]);t.complete()})}function Hc(e){return new D(function(t){e.then(function(n){t.closed||(t.next(n),t.complete())},function(n){return t.error(n)}).then(null,ys)})}function Mc(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 Ms(e){return new D(function(t){zc(e,t).catch(function(n){return t.error(n)})})}function Uc(e){return Ms(Ts(e))}function zc(e,t){var n,r,s,o;return dc(this,void 0,void 0,function(){var i,a;return fs(this,function(l){switch(l.label){case 0:l.trys.push([0,5,6,11]),n=pc(e),l.label=1;case 1:return[4,n.next()];case 2:if(r=l.sent(),!!r.done)return[3,4];if(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 Us(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 zs(e,t){return t===void 0&&(t=0),J(function(n,r){r.add(e.schedule(function(){return n.subscribe(r)},t))})}function Dc(e,t){return ue(e).pipe(zs(t),Us(t))}function Lc(e,t){return ue(e).pipe(zs(t),Us(t))}function jc(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 Nc(e,t){return new D(function(n){var r;return ft(n,t,function(){r=e[_s](),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 Ds(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 Vc(e,t){return Ds(Ts(e),t)}function Pc(e,t){if(e!=null){if(As(e))return Dc(e,t);if(Is(e))return jc(e,t);if(Bs(e))return Lc(e,t);if(Os(e))return Ds(e,t);if(Rs(e))return Nc(e,t);if(Hs(e))return Vc(e,t)}throw Cs(e)}function vt(e,t){return t?Pc(e,t):ue(e)}function K(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=nn(e);return vt(e,n)}function Rt(e,t){var n=Q(e)?e:function(){return e},r=function(s){return s.error(n())};return new D(r)}var Ls=rr(function(e){return function(){e(this),this.name="EmptyError",this.message="no elements in sequence"}});function Fc(e,t){return new Promise(function(n,r){var s=!1,o;e.subscribe({next:function(i){o=i,s=!0},error:r,complete:function(){s?n(o):r(new Ls)}})})}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 Ls)}});e.subscribe(s)})}function Wc(e){return e instanceof Date&&!isNaN(e)}function x(e,t){return J(function(n,r){var s=0;n.subscribe(G(r,function(o){r.next(e.call(t,o,s++))}))})}var qc=Array.isArray;function Kc(e,t){return qc(t)?e.apply(void 0,Me([],He(t))):e(t)}function js(e){return x(function(t){return Kc(e,t)})}var Xc=Array.isArray,Gc=Object.getPrototypeOf,Yc=Object.prototype,Qc=Object.keys;function Jc(e){if(e.length===1){var t=e[0];if(Xc(t))return{args:t,keys:null};if(Zc(t)){var n=Qc(t);return{args:n.map(function(r){return t[r]}),keys:n}}}return{args:e,keys:null}}function Zc(e){return e&&typeof e=="object"&&Gc(e)===Yc}function el(e,t){return e.reduce(function(n,r,s){return n[r]=t[s],n},{})}function de(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=nn(e),r=cr(e),s=Jc(e),o=s.args,i=s.keys;if(o.length===0)return vt([],n);var a=new D(Ns(o,n,i?function(l){return el(i,l)}:je));return r?a.pipe(js(r)):a}function Ns(e,t,n){return n===void 0&&(n=je),function(r){Vs(t,function(){for(var s=e.length,o=new Array(s),i=s,a=s,l=function(u){Vs(t,function(){var h=vt(e[u],t),p=!1;h.subscribe(G(r,function(v){o[u]=v,p||(p=!0,a--),a||r.next(n(o.slice()))},function(){--i||r.complete()}))},r)},c=0;c<s;c++)l(c)},r)}}function Vs(e,t,n){e?ft(n,e,t):t()}function tl(e,t,n,r,s,o,i,a){var l=[],c=0,u=0,h=!1,p=function(){h&&!l.length&&!c&&t.complete()},v=function(f){return c<r?d(f):l.push(f)},d=function(f){c++;var b=!1;ue(n(f,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,v,function(){h=!0,p()})),function(){}}function z(e,t,n){return n===void 0&&(n=1/0),Q(t)?z(function(r,s){return x(function(o,i){return t(r,o,s,i)})(ue(e(r,s)))},n):(typeof t=="number"&&(n=t),J(function(r,s){return tl(r,s,e,n)}))}function En(e){return e===void 0&&(e=1/0),z(je,e)}function nl(){return En(1)}function ct(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return nl()(vt(e,nn(e)))}function rn(e){return new D(function(t){ue(e()).subscribe(t)})}function kn(e,t,n){return e===void 0&&(e=0),n===void 0&&(n=Ac),new D(function(r){var s=Wc(e)?+e-n.now():e;s<0&&(s=0);var o=0;return n.schedule(function(){r.closed||(r.next(o++),r.complete())},s)})}function Qe(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=nn(e),r=Cc(e,1/0),s=e;return s.length?s.length===1?ue(s[0]):En(r)(vt(s,n)):Ye}var rl=new D(Ee),sl=Array.isArray;function Ps(e){return e.length===1&&sl(e[0])?e[0]:e}function Be(e,t){return J(function(n,r){var s=0;n.subscribe(G(r,function(o){return e.call(t,o,s++)&&r.next(o)}))})}function ol(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e=Ps(e),e.length===1?ue(e[0]):new D(il(e))}function il(e){return function(t){for(var n=[],r=function(o){n.push(ue(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 oe(e){return J(function(t,n){var r=null,s=!1,o;r=t.subscribe(G(n,void 0,void 0,function(i){o=ue(e(i,oe(e)(t))),r?(r.unsubscribe(),r=null,o.subscribe(n)):s=!0})),s&&(r.unsubscribe(),r=null,o.subscribe(n))})}function al(e,t,n,r,s){return function(o,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 Fs(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=cr(e);return n?gs(Fs.apply(void 0,Me([],He(e))),js(n)):J(function(r,s){Ns(Me([r],He(Ps(e))))(s)})}function cl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Fs.apply(void 0,Me([],He(e)))}function Ws(e,t){return Q(t)?z(e,t,1):z(e,1)}function qs(e,t){return t===void 0&&(t=Ss),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 te(e){return e<=0?function(){return Ye}: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,Ee))})}function ll(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&&ue(t).subscribe(G(r,function(){return s.clear()},Ee))})}function he(e,t){return t===void 0&&(t=je),e=e??ul,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 ul(e,t){return e===t}function Ks(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(n){return ct(n,K.apply(void 0,Me([],He(e))))}}function dl(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()}),ue(e(a,s++)).subscribe(o))},function(){i=!0,!o&&r.complete()}))})}function lr(e){return J(function(t,n){try{t.subscribe(n)}finally{n.add(e)}})}function hl(){return J(function(e,t){var n,r=!1;e.subscribe(G(t,function(s){var o=n;n=s,r&&t.next([o,s]),r=!0}))})}function sn(e,t){return J(al(e,t,arguments.length>=2,!0))}function bt(e){e===void 0&&(e={});var t=e.connector,n=t===void 0?function(){return new ye}:t,r=e.resetOnError,s=r===void 0?!0:r,o=e.resetOnComplete,i=o===void 0?!0:o,a=e.resetOnRefCountZero,l=a===void 0?!0:a;return function(c){var u,h,p,v=0,d=!1,f=!1,b=function(){h?.unsubscribe(),h=void 0},y=function(){b(),u=p=void 0,d=f=!1},m=function(){var g=u;y(),g?.unsubscribe()};return J(function(g,$){v++,!f&&!d&&b();var E=p=p??n();$.add(function(){v--,v===0&&!f&&!d&&(h=ur(m,l))}),E.subscribe($),!u&&v>0&&(u=new qt({next:function(w){return E.next(w)},error:function(w){f=!0,b(),h=ur(y,s,w),E.error(w)},complete:function(){d=!0,b(),h=ur(y,i),E.complete()}}),ue(g).subscribe(u))})(c)}}function ur(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(t===!0){e();return}if(t!==!1){var s=new qt({next:function(){s.unsubscribe(),e()}});return ue(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 tn(i,t,n)},resetOnError:!0,resetOnComplete:!1,resetOnRefCountZero:a})}function Xs(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=nn(e);return J(function(r,s){(n?ct(e,r,n):ct(e,r)).subscribe(s)})}function Tt(e,t){return J(function(n,r){var s=null,o=0,i=!1,a=function(){return i&&!s&&r.complete()};n.subscribe(G(r,function(l){s?.unsubscribe();var c=0,u=o++;ue(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 pl(){return Tt(je)}function dr(e){return J(function(t,n){ue(e).subscribe(G(n,function(){return n.complete()},Ee)),!n.closed&&t.subscribe(n)})}function Ht(e,t){return t===void 0&&(t=!1),J(function(n,r){var s=0;n.subscribe(G(r,function(o){var i=e(o,s++);(i||t)&&r.next(o),!i&&r.complete()}))})}function Kt(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 Gs(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=cr(e);return J(function(r,s){for(var o=e.length,i=new Array(o),a=e.map(function(){return!1}),l=!1,c=function(h){ue(e[h]).subscribe(G(s,function(p){i[h]=p,!l&&!a[h]&&(a[h]=!0,(l=a.every(je))&&(a=null))},Ee))},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 Ys="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]=Ys[r>>4]+Ys[r&15]}return t.join("")}const hr={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15};function ee(e){const t=e.length%2,n=(e[1]==="x"?2:0)+t,r=(e.length-n)/2+t,s=new Uint8Array(r);t&&(s[0]=0|hr[e[2]]);for(let o=0;o<r;){const i=n+o*2,a=hr[e[i]],l=hr[e[i+1]];s[t+o++]=a<<4|l}return s}function mt(e,t){return Object.fromEntries(Object.entries(e).map(([n,r])=>[n,t(r,n)]))}const ie=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 Qs=class extends Error{constructor(){super("Abort Error"),this.name="AbortError"}};var fl=Object.defineProperty,vl=(e,t,n)=>t in e?fl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Js=(e,t,n)=>vl(e,typeof t!="symbol"?t+"":t,n);let Zs=class extends Error{constructor(t){super(t.message),Js(this,"code"),Js(this,"data"),this.code=t.code,this.data=t.data,this.name="RpcError"}};const eo=e=>!("method"in e),to=()=>{const e=new Map;return{has:e.has.bind(e),subscribe(t,n){e.set(t,n)},unsubscribe(t){e.delete(t)},next(t,n){e.get(t)?.next(n)},error(t,n){const r=e.get(t);r&&(e.delete(t),r.error(n))},errorAll(t){const n=[...e.values()];e.clear(),n.forEach(r=>{r.error(t)})}}};let pr=class extends Error{constructor(){super("Client destroyed"),this.name="DestroyedError"}},bl=1;const fr=(e,t)=>{let n=bl++;const r=new Map,s=to();let o=null;const i=(u,h,p)=>{o.send({jsonrpc:"2.0",id:u,method:h,params:p})};function a(u){if(eo(u)){const{id:h}=u,p=r.get(h);return p?(r.delete(h),"error"in u?p.onError(new Zs(u.error)):p.onSuccess(u.result,(v,d)=>{const f=v;return s.subscribe(f,d),()=>{s.unsubscribe(f)}})):void 0}if(u.id===void 0){const{params:h}=u,{subscription:p,result:v,error:d}=h;p&&s.has(p)&&("result"in h||d)?d?s.error(p,new Zs(d)):s.next(p,v):t?.(u)}else console.warn("Error parsing incomming message: "+JSON.stringify(u))}o=e(a);const l=()=>{o?.disconnect(),o=null,s.errorAll(new pr),r.forEach(u=>u.onError(new pr)),r.clear()};let c=1;return{request:(u,h,p)=>{if(!o)throw new Error("Not connected");const v=`${n}-${c++}`;return p&&r.set(v,p),i(v,u,h),()=>{r.delete(v)}},disconnect:l}};var ml=Object.defineProperty,yl=(e,t,n)=>t in e?ml(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,an=(e,t,n)=>yl(e,t+"",n);const no=class rc extends Error{constructor(){super("ChainHead stopped"),this.name=rc.errorName}};an(no,"errorName","StopError");let ro=no;const so=class sc extends Error{constructor(){super("ChainHead disjointed"),this.name=sc.errorName}};an(so,"errorName","DisjointError");let Sn=so;const oo=class oc extends Error{constructor(){super("ChainHead operations limit reached"),this.name=oc.errorName}};an(oo,"errorName","OperationLimitError");let In=oo;const io=class ic extends Error{constructor(t){super(t),this.name=ic.errorName}};an(io,"errorName","OperationError");let ao=io;const co=class ac extends Error{constructor(){super("ChainHead operation inaccessible"),this.name=ac.errorName}};an(co,"errorName","OperationInaccessibleError");let Bn=co;const Ue={body:"",call:"",continue:"",follow:"",header:"",stopOperation:"",storage:"",unfollow:"",unpin:"",followEvent:""},An={chainName:"",genesisHash:"",properties:""},vr={broadcast:"",stop:""};Object.entries({chainHead:Ue,chainSpec:An,transaction:vr}).forEach(([e,t])=>{Object.keys(t).forEach(n=>{t[n]=`${e}_v1_${n}`})});var gl=Object.defineProperty,wl=(e,t,n)=>t in e?gl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,br=(e,t,n)=>wl(e,t+"",n);const lo=class cc extends Error{constructor(t){super(`Invalid BlockHash: ${t}`),this.name=cc.errorName}};br(lo,"errorName","BlockHashNotFoundError");let uo=lo;const ho=class lc extends Error{constructor(t){super(`Storage Error: ${t}`),this.name=lc.errorName}};br(ho,"errorName","StorageError");let $l=ho;const po=class uc extends Error{constructor(t){super(`Call Error: ${t}`),this.name=uc.errorName}};br(po,"errorName","CallError");let El=po;const Xt=()=>{},kl=e=>(t,n)=>{let r=!1,s=()=>{r=!0};return e(vr.broadcast,[t],{onSuccess:o=>{o!==null?(s=()=>{e(vr.stop,[o]),s=Xt},r&&s()):r||n(new Error("Max # of broadcasted transactions has been reached"))},onError:n}),()=>{s()}};function xl(){let e=()=>{},t=()=>{};return{promise:new Promise((n,r)=>{e=n,t=r}),res:e,rej:t}}const Gt=e=>(...t)=>new Promise((n,r)=>{let s=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 Qs)};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)}),fo=(e,t)=>n=>Gt((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 In);const{operationId:p}=u,v=()=>{n(Ue.stopOperation,[p])};if(!i)return v();let d=Xt;const f=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 ao(m.error)):m.event==="operationInaccessible"?s(new Bn):c(y,f,b)},error:b}),a=()=>{i&&(d(),v())}},onError:s}),()=>{a()}}),Sl=fo(Ue.body,e=>[[e],(t,n)=>{n(t.value)}]),Il=fo(Ue.call,(e,t,n)=>[[e,t,n],(r,s)=>{s(r.output)}]),Bl=e=>t=>new Promise((n,r)=>{e(Ue.header,[t],{onSuccess:n,onError:r})}),vo=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 In);const{operationId:p}=u,v=()=>{e(Ue.stopOperation,[p])};if(!l)return v();const d=h(u.operationId,{next:y=>{switch(y.event){case"operationStorageItems":{s(y.items);break}case"operationStorageDone":{b();break}case"operationError":{f(new ao(y.error));break}case"operationInaccessible":{f(new Bn);break}default:e(Ue.continue,[y.operationId])}},error:o});c=()=>{d(),e(Ue.stopOperation,[u.operationId])};const f=y=>{c=V,d(),o(y)},b=()=>{c=V,d(),i()};a(u.discardedItems)},onError:o}),()=>{c()}},Al=e=>{const t=vo(e);return Gt((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 In))});return u})},Ol=e=>t=>t.length>0?new Promise((n,r)=>{e(Ue.unpin,[t],{onSuccess(){n()},onError:r})}):Promise.resolve();function Cl(e){return e.operationId!==void 0}function _l(e){return(t,n,r)=>{const s=to(),o=new Set,i=xl();let a=i.promise,l=Xt;const c=d=>{e(Ue.unfollow,[d])},u=d=>{l(),a!==null&&(d&&(a instanceof Promise?a.then(f=>{typeof f=="string"&&c(f)}):c(a)),a=null,o.forEach(f=>{f()}),o.clear(),s.errorAll(new Sn))},h=d=>{if(Cl(d))return s.next(d.operationId,d);switch(d.event){case"stop":return r(new ro),u(!1);case"initialized":case"newBlock":case"bestBlockChanged":case"finalized":const{event:f,...b}=d;return n({type:f,...b})}},p=d=>{r(d),u(!(d instanceof pr))};e(Ue.follow,[t],{onSuccess:(d,f)=>{a instanceof Promise&&(a=d,l=f(d,{next:h,error:p})),i.res(d)},onError:d=>{a=null,i.res(d),r(d)}});const v=(d,f,b)=>{const y=()=>{b?.onError(new Sn)};if(a===null)return y(),Xt;const m=$=>{if(!b)return e(d,[$,...f]);o.add(y);const E=(k,S)=>a===null?(S.error(new Sn),Xt):(s.subscribe(k,S),()=>{s.unsubscribe(k)}),w=e(d,[$,...f],{onSuccess:k=>{o.delete(y),b.onSuccess(k,E)},onError:k=>{o.delete(y),b.onError(k)}});return()=>{o.delete(y),w()}};if(typeof a=="string")return m(a);let g=Xt;return a.then($=>{if($ instanceof Error)return y();a&&(g=m($))}),()=>{g()}};return{unfollow(){u(!0)},body:Sl(v),call:Il(v),header:Bl(v),storage:Al(v),storageSubscription:vo(v),unpin:Ol(v),_request:v}}}const Rl=e=>{const t=Gt((r,s,o,i)=>e(o,i,{onSuccess:r,onError:s}));let n=null;return async()=>n||(n=Promise.all([t(An.chainName,[]),t(An.genesisHash,[]),t(An.properties,[])]).then(([r,s,o])=>({name:r,genesisHash:s,properties:o})))},Tl=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"?f():d(new $l(b.error))},error:o}),v=()=>{l=V,p()};l=()=>{v(),h()};const d=b=>{v(),o(b)},f=()=>{v(),i()}},onError:o}),()=>{l()}},Hl=e=>Gt((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})}),bo=()=>e=>e,mo=()=>(e,t)=>{if(e===null)throw new uo(t);return e},Ml=e=>{const t=(u,...h)=>e(`archive_v1_${u}`,...h),n=u=>h=>Gt((p,v,...d)=>t(u,d,{onSuccess:f=>{try{p(h(f,...d))}catch(b){v(b)}},onError:v})),r=n("header")(mo()),s=n("body")(mo()),o=Tl(t),i=Hl(o),a=n("call")((u,h)=>{if(!u)throw new uo(h);if(!u.success)throw new El(u.error);return u.value}),l=n("finalizedHeight")(bo()),c=n("hashByHeight")(bo());return{header:r,body:s,storageSubscription:o,storage:i,call:a,finalizedHeight:l,hashByHeight:c}},Ul=e=>{const{request:t,disconnect:n}=fr(e);return{archive:Ml(t),chainHead:_l(t),transaction:kl(t),getChainSpecData:Rl(t),destroy:n,request:Gt((r,s,o,i)=>t(o,i,{onSuccess:r,onError:s})),_request:t}};var zl=Object.defineProperty,Dl=(e,t,n)=>t in e?zl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yo=(e,t,n)=>Dl(e,typeof t!="symbol"?t+"":t,n);let Ll=class{constructor(){yo(this,"first"),yo(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 jl=()=>{const e=new Map,t=(h,p)=>{e.set(h,()=>{e.delete(h),p()})},n=h=>{e.get(h)?.()},r=new Ll,s=r.unshift.bind(r),o=r.push.bind(r),i=(h,p)=>{const v=p?s:o;t(h.source$,v(h))},a=()=>{const h=r.pop();h&&(e.delete(h.source$),l(h))},l=h=>{const{source$:p,observer:v}=h;let d=!1;const f=p.subscribe({next(b){v.next(b)},error(b){(d=b instanceof Error&&b.name===In.errorName)?i(h,!0):v.error(b)},complete(){v.complete()}});f.closed?d||a():t(p,()=>{f.unsubscribe(),a()})},c=(h=!1)=>p=>new D(v=>{const d={observer:v,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 mr=e=>{const t=e.pipe(oe(n=>n instanceof Error&&n.name===Bn.errorName?kn(750).pipe(Ws(()=>t)):Rt(()=>n)));return t},Nl=new Set(["best","finalized",null]),Vl=(e,t,n)=>r=>(s,...o)=>{if(!Nl.has(s))return mr(r(s,...o)).pipe(n(s));const i=(s==="best"?t:e).pipe(te(1),z(a=>r(a,...o).pipe(n(a))),oe(a=>a instanceof Je?i:Rt(()=>a)));return mr(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}}),Pl=e=>t=>(...n)=>e()[t](...n);var ve=(e=>(e[e.Initializing=0]="Initializing",e[e.Ready=1]="Ready",e[e.RecoveringInit=2]="RecoveringInit",e[e.RecoveringFin=3]="RecoveringFin",e))(ve||{});function On(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})),Ks({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===ve.Ready),he(),Tt(c=>c?(o||(o=e.state.blocks.get(r)),o?ct(l,a):Rt(i)):rl),Ht(c=>c.type==="val"),x(c=>c.value))}}const Fl=(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 Wl=Object.defineProperty,ql=(e,t,n)=>t in e?Wl(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,go=(e,t,n)=>(ql(e,typeof t!="symbol"?t+"":t,n),n),yr={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15};function Kl(e){const t=e.length%2,n=(e[1]==="x"?2:0)+t,r=(e.length-n)/2+t,s=new Uint8Array(r);t&&(s[0]=0|yr[e[2]]);for(let o=0;o<r;){const i=n+o*2,a=yr[e[i]],l=yr[e[i+1]];s[t+o++]=a<<4|l}return s}var wo=class extends Uint8Array{constructor(e){super(e),go(this,"i",0),go(this,"v"),this.v=new DataView(e)}},ze=e=>t=>e(t instanceof wo?t:new wo(t instanceof Uint8Array?t.buffer:typeof t=="string"?Kl(t).buffer:t)),Ze=e=>{const t=e.length;let n=0;for(let s=0;s<t;s++)n+=e[s].length;const r=new Uint8Array(n);for(let s=0,o=0;s<t;s++){const i=e[s];r.set(i,o),o+=i.byteLength}return r};function Cn(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},_n=(e,t)=>n=>e(t(n)),Rn=(e,t)=>n=>t(e(n)),Ne=([e,t],n,r)=>X(_n(e,n),Rn(t,r));function Xl(e,t){return ze(n=>{const r=n.v[t](n.i,!0);return n.i+=e,r})}function Gl(e,t){return n=>{const r=new Uint8Array(e);return new DataView(r.buffer)[t](0,n,!0),r}}function yt(e,t,n){return X(Gl(e,n),Xl(e,t))}var P=yt(1,"getUint8","setUint8"),et=yt(2,"getUint16","setUint16"),Ve=yt(4,"getUint32","setUint32"),cn=yt(8,"getBigUint64","setBigUint64"),Yl=yt(1,"getInt8","setInt8"),Ql=yt(2,"getInt16","setInt16"),Jl=yt(4,"getInt32","setInt32"),Zl=yt(8,"getBigInt64","setBigInt64"),$o=e=>{const t=new Uint8Array(16),n=new DataView(t.buffer);return n.setBigInt64(0,e,!0),n.setBigInt64(8,e>>64n,!0),t},Eo=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}),ko=X($o,Eo("getBigUint64")),eu=X($o,Eo("getBigInt64")),xo=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},So=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}),tu=X(xo,So("getBigUint64")),nu=X(xo,So("getBigInt64")),ru=Ne(P,e=>e?1:0,Boolean),su=[P[1],et[1],Ve[1]],ou=ze(e=>{const t=e[e.i],n=t&3;if(n<3)return su[n](e)>>>2;const r=(t>>>2)+4;e.i++;let s=0n;const o=r/8|0;let 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(Ve[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}),iu=1n<<56n,au=1<<24,cu=256,lu=4294967295n,uu=64,du=16384,hu=1<<30,pu=e=>{if(e<0)throw new Error(`Wrong compact input (${e})`);const t=Number(e)<<2;if(e<uu)return P[0](t);if(e<du)return et[0](t|1);if(e<hu)return Ve[0](t|2);let n=[new Uint8Array(1)],r=BigInt(e);for(;r>=iu;)n.push(cn[0](r)),r>>=64n;r>=au&&(n.push(Ve[0](Number(r&lu))),r>>=32n);let s=Number(r);s>=cu&&(n.push(et[0](s)),s>>=16),s&&n.push(P[0](s));const o=Ze(n);return o[0]=o.length-5<<2|3,o},pe=X(pu,ou),fu=new TextEncoder,vu=e=>{const t=fu.encode(e);return Ze([pe.enc(t.length),t])},bu=new TextDecoder,mu=ze(e=>{let t=pe.dec(e);const n=new DataView(e.buffer,e.i,t);return e.i+=t,bu.decode(n)}),W=X(vu,mu),yu=()=>{},gu=new Uint8Array(0),M=X(()=>gu,yu),Io=e=>e===void 0?t=>Ze([pe.enc(t.length),t]):t=>t.length===e?t:t.slice(0,e),Bo=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(Io(e),Bo(e));ne.enc=Io,ne.dec=Bo;var Ao=(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)])},Oo=(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)}})},ke=(e,...t)=>X(Ao(Cn(e,([n])=>n),...t),Oo(Cn(e,([,n])=>n),...t));ke.enc=Ao,ke.dec=Oo;var Co=e=>ze(t=>P[1](t)>0?e(t):void 0),_o=e=>t=>{const n=new Uint8Array(1);return t===void 0?n:(n[0]=1,Ze([n,e(t)]))},xe=e=>X(_o(e[0]),Co(e[1]));xe.enc=_o,xe.dec=Co;var Ro=(e,t)=>ze(n=>{const r=P[1](n)===0,o=(r?e:t)(n);return{success:r,value:o}}),To=(e,t)=>({success:n,value:r})=>Ze([P[0](n?0:1),(n?e:t)(r)]),ln=(e,t)=>X(To(e[0],t[0]),Ro(e[1],t[1]));ln.dec=Ro,ln.enc=To;var Ho=(...e)=>ze(t=>e.map(n=>n(t))),Mo=(...e)=>t=>Ze(e.map((n,r)=>n(t[r]))),De=(...e)=>X(Mo(...e.map(([t])=>t)),Ho(...e.map(([,t])=>t)));De.enc=Mo,De.dec=Ho;var Uo=e=>{const t=Object.keys(e);return _n(De.enc(...Object.values(e)),n=>t.map(r=>n[r]))},zo=e=>{const t=Object.keys(e);return Rn(De.dec(...Object.values(e)),n=>Object.fromEntries(n.map((r,s)=>[t[s],r])))},U=e=>X(Uo(Cn(e,t=>t[0])),zo(Cn(e,t=>t[1])));U.enc=Uo,U.dec=zo;var Do=(e,t)=>t>=0?n=>Ze(n.map(e)):n=>Ze([pe.enc(n.length),Ze(n.map(e))]),Lo=(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(Do(e[0],t),Lo(e[1],t));L.enc=Do,L.dec=Lo;/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function wu(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function jo(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(n=>typeof n=="string"):t.every(n=>Number.isSafeInteger(n)):!1}function gr(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function No(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function wr(e){if(!Array.isArray(e))throw new Error("array expected")}function Vo(e,t){if(!jo(!0,t))throw new Error(`${e}: array of strings expected`)}function $u(e,t){if(!jo(!1,t))throw new Error(`${e}: array of numbers expected`)}function Eu(...e){const t=o=>o,n=(o,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 ku(e){const t=typeof e=="string"?e.split(""):e,n=t.length;Vo("alphabet",t);const r=new Map(t.map((s,o)=>[s,o]));return{encode:s=>(wr(s),s.map(o=>{if(!Number.isSafeInteger(o)||o<0||o>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${o}". Allowed: ${e}`);return t[o]})),decode:s=>(wr(s),s.map(o=>{gr("alphabet.decode",o);const i=r.get(o);if(i===void 0)throw new Error(`Unknown letter: "${o}". Allowed: ${e}`);return i}))}}function xu(e=""){return gr("join",e),{encode:t=>(Vo("join.decode",t),t.join(e)),decode:t=>(gr("join.decode",t),t.split(e))}}function Po(e,t,n){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(wr(e),!e.length)return[];let r=0;const s=[],o=Array.from(e,a=>{if(No(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 v=p/n;a=p%n;const d=Math.floor(v);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 Su(e){No(e);const t=2**8;return{encode:n=>{if(!wu(n))throw new Error("radix.encode input should be Uint8Array");return Po(Array.from(n),t,e)},decode:n=>($u("radix.decode",n),Uint8Array.from(Po(n,e,t)))}}const Fo=(e=>Eu(Su(58),ku(e),xu("")))("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 Bu(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 $r(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 Au(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 gt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Tn(e,t){return e<<32-t|e>>>t}const Wo=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function qo(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const ut=Wo?e=>e:e=>qo(e)>>>0;function Ou(e){for(let t=0;t<e.length;t++)e[t]=qo(e[t]);return e}const ge=Wo?e=>e:Ou;function Er(e,t={}){const n=(s,o)=>e(o).update(s).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=s=>e(s),Object.assign(n,t),Object.freeze(n)}const Cu=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]);function wt(e,t,n,r,s){return e=e+t+s|0,r=Tn(r^e,16),n=n+r|0,t=Tn(t^n,12),{a:e,b:t,c:n,d:r}}function $t(e,t,n,r,s){return e=e+t+s|0,r=Tn(r^e,8),n=n+r|0,t=Tn(t^n,7),{a:e,b:t,c:n,d:r}}const _u=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Hn=BigInt(2**32-1),Ko=BigInt(32);function Mn(e,t=!1){return t?{h:Number(e&Hn),l:Number(e>>Ko&Hn)}:{h:Number(e>>Ko&Hn)|0,l:Number(e&Hn)|0}}function Ru(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}=Mn(e[o],t);[r[o],s[o]]=[i,a]}return[r,s]}const Xo=(e,t,n)=>e>>>n|t<<32-n,Go=(e,t,n)=>e<<32-n|t>>>n,Tu=(e,t,n)=>e<<64-n|t>>>n-32,Hu=(e,t,n)=>e>>>n-32|t<<64-n,Mu=(e,t)=>t,Uu=(e,t)=>e,zu=(e,t,n)=>e<<n|t>>>32-n,Du=(e,t,n)=>t<<n|e>>>32-n,Lu=(e,t,n)=>t<<n-32|e>>>64-n,ju=(e,t,n)=>e<<n-32|t>>>64-n;function Yo(e,t,n,r){const s=(t>>>0)+(r>>>0);return{h:e+n+(s/2**32|0)|0,l:s|0}}const Qo=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Jo=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,se=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),O=new Uint32Array(32);function Et(e,t,n,r,s,o){const 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],v=O[2*n+1],d=O[2*r],f=O[2*r+1],b=Qo(l,u,i);c=Jo(b,c,h,a),l=b|0,{Dh:f,Dl:d}={Dh:f^c,Dl:d^l},{Dh:f,Dl:d}={Dh:Mu(f,d),Dl:Uu(f)},{h:v,l:p}=Yo(v,p,f,d),{Bh:h,Bl:u}={Bh:h^v,Bl:u^p},{Bh:h,Bl:u}={Bh:Xo(h,u,24),Bl:Go(h,u,24)},O[2*e]=l,O[2*e+1]=c,O[2*t]=u,O[2*t+1]=h,O[2*n]=p,O[2*n+1]=v,O[2*r]=d,O[2*r+1]=f}function kt(e,t,n,r,s,o){const 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],v=O[2*n+1],d=O[2*r],f=O[2*r+1],b=Qo(l,u,i);c=Jo(b,c,h,a),l=b|0,{Dh:f,Dl:d}={Dh:f^c,Dl:d^l},{Dh:f,Dl:d}={Dh:Xo(f,d,16),Dl:Go(f,d,16)},{h:v,l:p}=Yo(v,p,f,d),{Bh:h,Bl:u}={Bh:h^v,Bl:u^p},{Bh:h,Bl:u}={Bh:Tu(h,u,63),Bl:Hu(h,u,63)},O[2*e]=l,O[2*e+1]=c,O[2*t]=u,O[2*t+1]=h,O[2*n]=p,O[2*n+1]=v,O[2*r]=d,O[2*r+1]=f}function Nu(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 Zo{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&&(ge(s),this.compress(s,0,!1),ge(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));ge(h);for(let p=0;l+n<o;p+=s.length,l+=n)this.length+=n,this.compress(h,p,!1);ge(h);continue}r.set(t.subarray(l,l+c),this.pos),this.pos+=c,this.length+=c,l+=c}return this}digestInto(t){un(this),$r(t,this);const{pos:n,buffer32:r}=this;if(this.finished=!0,gt(this.buffer.subarray(n)),ge(r),this.compress(r,0,!0),ge(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 Vu extends Zo{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),Nu(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:v,v6h:d,v7l:f,v7h:b}=this;return[t,n,r,s,o,i,a,l,c,u,h,p,v,d,f,b]}set(t,n,r,s,o,i,a,l,c,u,h,p,v,d,f,b){this.v0l=t|0,this.v0h=n|0,this.v1l=r|0,this.v1h=s|0,this.v2l=o|0,this.v2h=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=v|0,this.v6h=d|0,this.v7l=f|0,this.v7h=b|0}compress(t,n,r){this.get().forEach((l,c)=>O[c]=l),O.set(se,16);let{h:s,l:o}=Mn(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=Cu;for(let l=0;l<12;l++)Et(0,4,8,12,t,n+2*a[i++]),kt(0,4,8,12,t,n+2*a[i++]),Et(1,5,9,13,t,n+2*a[i++]),kt(1,5,9,13,t,n+2*a[i++]),Et(2,6,10,14,t,n+2*a[i++]),kt(2,6,10,14,t,n+2*a[i++]),Et(3,7,11,15,t,n+2*a[i++]),kt(3,7,11,15,t,n+2*a[i++]),Et(0,5,10,15,t,n+2*a[i++]),kt(0,5,10,15,t,n+2*a[i++]),Et(1,6,11,12,t,n+2*a[i++]),kt(1,6,11,12,t,n+2*a[i++]),Et(2,7,8,13,t,n+2*a[i++]),kt(2,7,8,13,t,n+2*a[i++]),Et(3,4,9,14,t,n+2*a[i++]),kt(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],gt(O)}destroy(){this.destroyed=!0,gt(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const Un=Er(e=>new Vu(e));function ei(e,t,n,r,s,o,i,a,l,c,u,h,p,v,d,f,b,y,m,g){let $=0;for(let E=0;E<r;E++)({a:s,b:l,c:p,d:b}=wt(s,l,p,b,n[t+e[$++]])),{a:s,b:l,c:p,d:b}=$t(s,l,p,b,n[t+e[$++]]),{a:o,b:c,c:v,d:y}=wt(o,c,v,y,n[t+e[$++]]),{a:o,b:c,c:v,d:y}=$t(o,c,v,y,n[t+e[$++]]),{a:i,b:u,c:d,d:m}=wt(i,u,d,m,n[t+e[$++]]),{a:i,b:u,c:d,d:m}=$t(i,u,d,m,n[t+e[$++]]),{a,b:h,c:f,d:g}=wt(a,h,f,g,n[t+e[$++]]),{a,b:h,c:f,d:g}=$t(a,h,f,g,n[t+e[$++]]),{a:s,b:c,c:d,d:g}=wt(s,c,d,g,n[t+e[$++]]),{a:s,b:c,c:d,d:g}=$t(s,c,d,g,n[t+e[$++]]),{a:o,b:u,c:f,d:b}=wt(o,u,f,b,n[t+e[$++]]),{a:o,b:u,c:f,d:b}=$t(o,u,f,b,n[t+e[$++]]),{a:i,b:h,c:p,d:y}=wt(i,h,p,y,n[t+e[$++]]),{a:i,b:h,c:p,d:y}=$t(i,h,p,y,n[t+e[$++]]),{a,b:l,c:v,d:m}=wt(a,l,v,m,n[t+e[$++]]),{a,b:l,c:v,d:m}=$t(a,l,v,m,n[t+e[$++]]);return{v0:s,v1:o,v2:i,v3:a,v4:l,v5:c,v6:u,v7:h,v8:p,v9:v,v10:d,v11:f,v12:b,v13:y,v14:m,v15:g}}const ti=new TextEncoder().encode("SS58PRE"),kr=2,ni=e=>{try{const t=Fo.decode(e),n=t.subarray(0,t[0]&64?2:1),r=t.subarray(n.length,t.length-kr),s=t.subarray(n.length+r.length),o=Un(Uint8Array.of(...ti,...n,...r),{dkLen:64}).subarray(0,kr);return s[0]===o[0]&&s[1]===o[1]?{isValid:!0,ss58Format:Pu(n),publicKey:r.slice()}:{isValid:!1}}catch{return{isValid:!1}}},Pu=e=>{const t=new DataView(e.buffer,e.byteOffset,e.byteLength);return t.byteLength===1?t.getUint8(0):t.getUint16(0)},Fu=e=>{let t={},n=0,r=0;const s=()=>{n===r?(t={},n=r=0):(r=n,setTimeout(s,0))};return o=>{var i,a;++n===1&&s();let l=t;const c=o.length-1;for(let u=0;u<=c;u++)l=l[i=o[u]]||(l[i]={});return l[a=o[c]]||(l[a]=e(o))}},ri=e=>{const t=e<64?Uint8Array.of(e):Uint8Array.of((e&252)>>2|64,e>>8|(e&3)<<6);return Fu(n=>{const r=Un(Uint8Array.of(...ti,...t,...n),{dkLen:64}).subarray(0,kr);return Fo.encode(Uint8Array.of(...t,...n,...r))})};function Wu(e,t){return n=>{const r=ni(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)=>Ne(ne(t),Wu(t),ri(e)),R=Ne(pe,e=>e,Number),zn=Ne(pe,e=>e,BigInt),qu=new TextEncoder,Ku=new TextDecoder,Xu=De(R,ne(1/0))[1],Yt={toText:e=>Ku.decode(e),toHex:e=>Y(e),toOpaque:e=>ie([pe[0](e.length),e]),fromText:e=>qu.encode(e),fromHex:e=>ee(e),fromOpaque:e=>{const t=typeof e=="string"?ee(e):e;try{const[n,r]=Xu(t);if(n===r.length)return r}catch{}throw new Error("Invalid opaque bytes")}},si=e=>Ne(ne(e),ee,Y),Gu=lt(e=>{const t=R.dec(e),n=Math.ceil(t/8);return{bytes:ne(n).dec(e),bitsLen:t}}),Yu=e=>{if(e.bitsLen>e.bytes.length*8)throw new Error(`Not enough bytes. (bitsLen:${e.bitsLen}, bytesLen:${e.bytes.length})`);const t=R.enc(e.bitsLen),n=new Uint8Array(e.bytes.length+t.length);return n.set(t,0),n.set(e.bytes,t.length),n},Qu=X(Yu,Gu),Ju=Ne(P,e=>e.charCodeAt(0),String.fromCharCode),oi=e=>{const t=ne.enc(e);return n=>t(ee(n))},ii=e=>{const t=ne.dec(e);return n=>Y(t(n))},we=e=>X(oi(e),ii(e));we.enc=oi,we.dec=ii;const ai=new TextEncoder,Zu=new TextDecoder,ed=e=>Ne(ne(e),t=>ai.encode(t),t=>Zu.decode(t)),ci=e=>{let t=n=>{const r=e();return t=r,r(n)};return n=>t(n)},li=e=>{let t=n=>{const r=e(),s=r;return t=r,s(n)};return n=>t(n)},xr=e=>X(ci(()=>e().enc),li(()=>e().dec)),td={is(e,t){return e.type===t},as(e,t){if(t!==e.type)throw new Error(`Enum.as(enum, ${t}) used with actual type ${e.type}`);return e}},Dn=Object.assign((e,t)=>({type:e,value:t}),td),nd=new Proxy({},{get(e,t){return n=>Dn(t,n)}}),re=(e,t)=>{const n=e;return n.inner=t,n},ui=(...e)=>{const t=ke.enc(...e);return re(n=>t({tag:n.type,value:n.value}),e[0])},di=(...e)=>{const t=ke.dec(...e);return re(n=>{const{tag:r,value:s}=t(n);return Dn(r,s)},e[0])},Se=(e,...t)=>re(X(ui(mt(e,([n])=>n),...t),di(mt(e,([,n])=>n),...t)),e);Se.enc=ui,Se.dec=di;const Sr=(e,...t)=>re(ke(e,...t),e);Sr.enc=(e,...t)=>re(ke.enc(e,...t),e),Sr.dec=(e,...t)=>re(ke.dec(e,...t),e);const tt={CHUNK_START:1,CHUNK_END:2,PARENT:4,ROOT:8,KEYED_HASH:16,DERIVE_KEY_CONTEXT:32,DERIVE_KEY_MATERIAL:64},dt=_u.slice(),hi=(()=>{const e=Array.from({length:16},(r,s)=>s),t=r=>[2,6,3,10,7,0,4,13,1,11,12,5,9,14,15,8].map(s=>r[s]),n=[];for(let r=0,s=e;r<7;r++,s=t(s))n.push(...s);return Uint8Array.from(n)})();class Ir extends Zo{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=Bu(r);this.IV=zt(i),ge(this.IV),this.flags=n|tt.KEYED_HASH}else if(o){Ae(s,void 0,"context");const i=s,a=new Ir({dkLen:32},tt.DERIVE_KEY_CONTEXT).update(i).digest();this.IV=zt(a),ge(this.IV),this.flags=n|tt.DERIVE_KEY_MATERIAL}else this.IV=dt.slice(),this.flags=n;this.state=this.IV.slice(),this.bufferOut=Au(this.bufferOut32)}get(){return[]}set(){}b2Compress(t,n,r,s=0){const{state:o,pos:i}=this,{h:a,l}=Mn(BigInt(t),!0),{v0:c,v1:u,v2:h,v3:p,v4:v,v5:d,v6:f,v7:b,v8:y,v9:m,v10:g,v11:$,v12:E,v13:w,v14:k,v15:S}=ei(hi,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^$,o[4]=v^E,o[5]=d^w,o[6]=f^k,o[7]=b^S}compress(t,n=0,r=!1){let s=this.flags;if(this.chunkPos||(s|=tt.CHUNK_START),(this.chunkPos===15||r)&&(s|=tt.CHUNK_END),r||(this.pos=this.blockLen),this.b2Compress(this.chunksDone,s,t,n),this.chunkPos+=1,this.chunkPos===16||r){let o=this.state;this.state=this.IV.slice();for(let 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,gt(this.state,this.buffer32,this.IV,this.bufferOut32),gt(...this.stack)}b2CompressOut(){const{state:t,pos:n,flags:r,buffer32:s,bufferOut32:o}=this,{h:i,l:a}=Mn(BigInt(this.chunkOut++));ge(s);const{v0:l,v1:c,v2:u,v3:h,v4:p,v5:v,v6:d,v7:f,v8:b,v9:y,v10:m,v11:g,v12:$,v13:E,v14:w,v15:k}=ei(hi,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^$,o[5]=v^E,o[6]=d^w,o[7]=f^k,o[8]=t[0]^b,o[9]=t[1]^y,o[10]=t[2]^m,o[11]=t[3]^g,o[12]=t[4]^$,o[13]=t[5]^E,o[14]=t[6]^w,o[15]=t[7]^k,ge(s),ge(o),this.posOut=0}finish(){if(this.finished)return;this.finished=!0,gt(this.buffer.subarray(this.pos));let t=this.flags|tt.ROOT;this.stack.length?(t|=tt.PARENT,ge(this.buffer32),this.compress(this.buffer32,0,!0),ge(this.buffer32),this.chunksDone=0,this.pos=this.blockLen):t|=(this.chunkPos?0:tt.CHUNK_START)|tt.CHUNK_END,this.flags=t,this.b2CompressOut()}writeInto(t){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($r(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 rd=Er((e={})=>new Ir(e)),sd=BigInt(0),hn=BigInt(1),od=BigInt(2),id=BigInt(7),ad=BigInt(256),cd=BigInt(113),pi=[],fi=[],vi=[];for(let e=0,t=hn,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],pi.push(2*(5*r+n)),fi.push((e+1)*(e+2)/2%64);let s=sd;for(let o=0;o<7;o++)t=(t<<hn^(t>>id)*cd)%ad,t&od&&(s^=hn<<(hn<<BigInt(o))-hn);vi.push(s)}const bi=Ru(vi,!0),ld=bi[0],ud=bi[1],mi=(e,t,n)=>n>32?Lu(e,t,n):zu(e,t,n),yi=(e,t,n)=>n>32?ju(e,t,n):Du(e,t,n);function dd(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=mi(c,u,1)^n[a],p=yi(c,u,1)^n[a+1];for(let v=0;v<50;v+=10)e[i+v]^=h,e[i+v+1]^=p}let s=e[2],o=e[3];for(let i=0;i<24;i++){const a=fi[i],l=mi(s,o,a),c=yi(s,o,a),u=pi[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]^=ld[r],e[1]^=ud[r]}gt(n)}class Br{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(){ge(this.state32),dd(this.state32,this.rounds),ge(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($r(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,gt(this.state)}_cloneInto(t){const{blockLen:n,suffix:r,outputLen:s,rounds:o,enableXOF:i}=this;return t||=new Br(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 Ln=((e,t,n,r={})=>Er(()=>new Br(t,e,n),r))(1,136,32),gi=e=>{const t=e.slice(2),n=Y(Ln(ai.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("")}`},hd=ne(20)[1],wi=X(e=>{const t=ee(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(gi(n)!==e)throw new Error(`Invalid checksum found on EthAddress(${e})`);return t},lt(e=>gi(Y(hd(e))))),be=e=>re(U(e),e);be.enc=e=>re(U.enc(e),e),be.dec=e=>re(U.dec(e),e);const Pe=(...e)=>re(De(...e),e);Pe.enc=(...e)=>re(De.enc(...e),e),Pe.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 jn=(e,t)=>re(ln(e,t),{ok:e,ko:t});jn.enc=(e,t)=>re(ln.enc(e,t),{ok:e,ko:t}),jn.dec=(e,t)=>re(ln.dec(e,t),{ok:e,ko:t});const xt=e=>re(xe(e),e);xt.enc=e=>re(xe.enc(e),e),xt.dec=e=>re(xe.dec(e),e);const $i=(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}),Ei=(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 ie([n,s])},Nn=e=>X(Ei(e),$i(e));Nn.enc=Ei,Nn.dec=$i;const ki=new TextEncoder,xi=new TextDecoder,pd=Ne(ne(4),ki.encode.bind(ki),xi.decode.bind(xi)),Ar=be({engine:pd,payload:we()}),fd=Se({other:ne(),consensus:Ar,seal:Ar,preRuntime:Ar,runtimeUpdated:M},[0,4,5,6,8]),Or=we(32),Vn=be({parentHash:Or,number:R,stateRoot:Or,extrinsicRoot:Or,digests:Oe(fd)}),Ce=L(W),Si=xe(W),vd=ke({bool:M,char:M,str:M,u8:M,u16:M,u32:M,u64:M,u128:M,u256:M,i8:M,i16:M,i32:M,i64:M,i128:M,i256:M}),Ii=L(U({name:Si,type:R,typeName:Si,docs:Ce})),bd=U({len:Ve,type:R}),md=U({bitStoreType:R,bitOrderType:R}),yd=L(U({name:W,fields:Ii,index:P,docs:Ce})),gd=ke({composite:Ii,variant:yd,sequence:R,array:bd,tuple:L(R),primitive:vd,compact:R,bitSequence:md}),wd=U({name:W,type:xe(R)}),$d=L(wd),Ed=U({id:R,path:Ce,params:$d,def:gd,docs:Ce}),Pn=L(Ed),Qt=ke({NotDeprecated:M,DeprecatedWithoutNote:M,Deprecated:U({note:W,since:xe(W)})}),kd=L(U({index:P,deprecation:ke({DeprecatedWithoutNote:M,Deprecated:U({note:W,since:xe(W)})},[1,2])})),Cr={name:W,inputs:L(U({name:W,type:R})),output:R,docs:Ce},xd=U({name:W,methods:L(U(Cr)),docs:Ce}),Sd=U({name:W,methods:L(U({...Cr,deprecationInfo:Qt})),docs:Ce,version:R,deprecationInfo:Qt}),Id=U({id:we(32),...Cr,deprecationInfo:Qt}),Bd=ke({Blake2128:M,Blake2256:M,Blake2128Concat:M,Twox128:M,Twox256:M,Twox64Concat:M,Identity:M}),Ad=L(Bd),Od=U({hashers:Ad,key:R,value:R}),Bi={name:W,modifier:P,type:ke({plain:R,map:Od}),fallback:we(),docs:Ce},_r=xe(R),Ai={name:W,storage:xe(U({prefix:W,items:L(U(Bi))})),calls:_r,events:_r,constants:L(U({name:W,type:R,value:we(),docs:Ce})),errors:_r,index:P},Cd={...Ai,docs:Ce},Rr=xe(U({type:R,deprecationInfo:kd})),_d={name:W,storage:xe(U({prefix:W,items:L(U({...Bi,deprecationInfo:Qt}))})),calls:Rr,events:Rr,constants:L(U({name:W,type:R,value:we(),docs:Ce,deprecationInfo:Qt})),errors:Rr,associatedTypes:L(U({name:W,type:R,docs:Ce})),viewFns:L(Id),index:P,docs:Ce,deprecationInfo:Qt},Rd=new Uint8Array,Oi=e=>X(()=>Rd,()=>e),Td=U({type:R,version:P,signedExtensions:L(U({identifier:W,type:R,additionalSigned:R}))}),Ci=U({lookup:Pn,pallets:L(U({...Ai,docs:Oi([])})),extrinsic:Td,type:R,apis:Oi([])}),Hd=U({version:P,address:R,call:R,signature:R,extra:R,signedExtensions:L(U({identifier:W,type:R,additionalSigned:R}))}),_i=U({lookup:Pn,pallets:L(U(Cd)),extrinsic:Hd,type:R,apis:L(xd),outerEnums:U({call:R,event:R,error:R}),custom:L(De(W,U({type:R,value:we()})))}),Md=U({version:L(P),address:R,call:R,signature:R,signedExtensionsByVersion:L(De(P,L(R))),signedExtensions:L(U({identifier:W,type:R,additionalSigned:R}))}),Ri=U({lookup:Pn,pallets:L(U(_d)),extrinsic:Md,apis:L(Sd),outerEnums:U({call:R,event:R,error:R}),custom:L(De(W,U({type:R,value:we()})))}),Ti=()=>{throw new Error("Unsupported metadata version!")},Ie=X(Ti,Ti),Dt=U({magicNumber:Ve,metadata:ke({v0:Ie,v1:Ie,v2:Ie,v3:Ie,v4:Ie,v5:Ie,v6:Ie,v7:Ie,v8:Ie,v9:Ie,v10:Ie,v11:Ie,v12:Ie,v13:Ie,v14:Ci,v15:_i,v16:Ri})}),Tr=ne(),Ud=xe(Tr),zd=De(pe,Tr),Hi=e=>{try{return Dt.dec(e)}catch{}try{return Dt.dec(Ud.dec(e))}catch{}try{return Dt.dec(Tr.dec(e))}catch{}try{return Dt.dec(zd.dec(e)[1])}catch{}throw null},Fn=e=>{if("magicNumber"in e&&(e=e.metadata),"tag"in e){if(e.tag!=="v14"&&e.tag!=="v15"&&e.tag!=="v16")throw new Error("Only metadata 14, 15, and 16 are supported");e=e.value}if("signedExtensionsByVersion"in e.extrinsic){const{extrinsic:{signedExtensions:s,signedExtensionsByVersion:o,...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"},Hr=Ne(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`)}),Dd={dkLen:32},jt=e=>Un(e,Dd),Ld={dkLen:16},Mr=e=>Un(e,Ld),Mi=e=>ie([Mr(e),e]),jd={dkLen:32},Ui=e=>rd(e,jd),Nd=e=>ie([Ui(e),e]),zi=e=>e,Nt=(e,t,n,r)=>new DataView(new Uint16Array([e,t,n,r]).buffer).getBigUint64(0,!0),Ur=2n**64n-1n,me=(e,t)=>e<<t&Ur|e>>64n-t,F=(e,t)=>e*t&Ur,ae=(e,t)=>e+t&Ur,ce=11400714785074694791n,_e=14029467366897019727n,Di=1609587929392839161n,pn=9650029242287828579n,Li=2870177450012600261n;function St(e,t=0n){let n=ae(ae(t,ce),_e),r=ae(t,_e),s=t,o=t-ce,i=e.length,a=0,l=null;(function(){let p=0,v=p+i;if(i){if(l=new Uint8Array(32),i<32){l.set(e.subarray(0,i),a),a+=i;return}if(p<=v-32){const d=v-32;do{let f;f=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(me(ae(n,F(f,_e)),31n),ce),p+=8,f=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(me(ae(r,F(f,_e)),31n),ce),p+=8,f=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(me(ae(s,F(f,_e)),31n),ce),p+=8,f=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(me(ae(o,F(f,_e)),31n),ce),p+=8}while(p<=d)}p<v&&(l.set(e.subarray(p,v),a),a=v-p)}})(),e=l||e;let c,u=0;for(i>=32?(c=me(n,1n),c=ae(c,me(r,7n)),c=ae(c,me(s,12n)),c=ae(c,me(o,18n)),n=F(me(F(n,_e),31n),ce),c=c^n,c=ae(F(c,ce),pn),r=F(me(F(r,_e),31n),ce),c=c^r,c=ae(F(c,ce),pn),s=F(me(F(s,_e),31n),ce),c=c^s,c=ae(F(c,ce),pn),o=F(me(F(o,_e),31n),ce),c=c^o,c=ae(F(c,ce),pn)):c=ae(t,Li),c=ae(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(me(F(p,_e),31n),ce),c=ae(F(me(c^p,27n),ce),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),ce);c=ae(F(me(c^p,23n),_e),Di),u+=4}for(;u<a;){const p=F(Nt(e[u++],0,0,0),Li);c=F(me(c^p,11n),ce)}let h=c>>33n;return c=F(c^h,_e),h=c>>29n,c=F(c^h,Di),h=c>>32n,c^=h,c}const Wn=e=>{const t=new Uint8Array(16),n=new DataView(t.buffer);return n.setBigUint64(0,St(e),!0),n.setBigUint64(8,St(e,1n),!0),t},ji=e=>{const t=new Uint8Array(32),n=new DataView(t.buffer);return n.setBigUint64(0,St(e),!0),n.setBigUint64(8,St(e,1n),!0),n.setBigUint64(16,St(e,2n),!0),n.setBigUint64(24,St(e,3n),!0),t},Ni=e=>ie([cn.enc(St(e)),e]),Vi=new TextEncoder,Vd=new Map([[zi,0],[Ni,8],[Mi,16],[Mr,-16],[jt,-32],[Wn,-16],[ji,-32]]),Pi=e=>{const t=Wn(Vi.encode(e));return(n,...r)=>{const s=ie([t,Wn(Vi.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=ee(l.slice(o.length)),u=new Array(r.length);for(let h=0,p=0;h<r.length;h++){const[v,d]=r[h],f=Vd.get(d);if(f==null)throw new Error("Unknown hasher");if(f<0){const b=f*-1;u[h]=Y(c.slice(p,p+b)),p+=b}else p+=f,u[h]=v.dec(c.slice(p)),p+=v.enc(u[h]).length}return u},a=r.map(([{enc:l},c])=>u=>c(l(u)));return{enc:(...l)=>Y(ie([s,...l.map((c,u)=>a[u](c))])),dec:i}}},Pd=Yt.fromText("modlpy/utilisuba"),Fd=({threshold:e,signatories:t})=>{const n=Fi(t),r=ie([Pd,pe.enc(n.length),...n,et.enc(e)]);return jt(r)},Fi=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"},Wi=we().dec,Wd=we(1/0).dec,qd=we(32).dec,qi=P.dec,Kd=e=>{const t=qi(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=qi(e);while(i===255)}return{type:s,partialKey:we(Math.ceil(o/2)).dec(e).slice(o%2?3:2)}},Ki=lt(e=>{const t=Kd(e),{type:n}=t;if(n==="Empty"||n==="Reserved")return t;if(n==="Leaf"||n==="LeafWithHash")return{...t,value:Wd(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=Wi(e)),n==="BranchWithHash"&&(o=qd(e));const i={...t,children:Object.fromEntries(s.map(a=>[a,Wi(e)]))};return o!==null&&(i.value=o),i}),Xi=e=>lt(t=>{const n=Y(e(new Uint8Array(t.buffer)));try{return{hash:n,...Ki(t)}}catch{return{type:"Raw",hash:n,value:""}}}),Gi=(e,t=jt)=>{const n=e.map(Xi(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 Yi=Object.freeze({__proto__:null,AccountId:dn,Binary:Yt,BitSeq:Nn,Blake2128:Mr,Blake2128Concat:Mi,Blake2256:jt,Blake3256:Ui,Blake3256Concat:Nd,Bytes:ne,Enum:Dn,Hex:we,Identity:zi,Keccak256:Ln,Option:xt,Result:jn,ScaleEnum:Sr,Self:xr,SizedBytes:si,Storage:Pi,Struct:be,TrieNodeHeaders:It,TrieNodeWithHash:Xi,Tuple:Pe,Twox128:Wn,Twox256:ji,Twox64Concat:Ni,Variant:Se,Vector:Oe,_Enum:nd,_void:M,bitSequence:Qu,blockHeader:Vn,bool:ru,char:Ju,compact:pe,compactBn:zn,compactNumber:R,createCodec:X,createDecoder:lt,decAnyMetadata:Hi,enhanceCodec:Ne,enhanceDecoder:Rn,enhanceEncoder:_n,ethAccount:wi,extrinsicFormat:Hr,fixedStr:ed,fromBufferToBase58:ri,getMultisigAccountId:Fd,getSs58AddressInfo:ni,h64:St,i128:eu,i16:Ql,i256:nu,i32:Jl,i64:Zl,i8:Yl,metadata:Dt,selfDecoder:li,selfEncoder:ci,sortMultisigSignatories:Fi,str:W,trieNodeDec:Ki,u128:ko,u16:et,u256:tu,u32:Ve,u64:cn,u8:P,unifyMetadata:Fn,v14:Ci,v14Lookup:Pn,v15:_i,v16:Ri,validateProofs:Gi});const Xd=[jt,Ln],Gd=(e,t)=>Xd.find(n=>Y(n(ee(e)))===t)||(()=>{throw new Error("Unsupported hasher")}),Yd=e=>{const t=(n,r,s)=>{const o=n[r.idx],i=n[s.idx];if(n.length===2)return K([[o,r.id],[i,s.id]]);const a=r.idx+Math.floor((s.idx-r.idx)/2);return e(n[a]).pipe(z(l=>{const c={id:l,idx:a};return c.id===r.id?t(n,c,s):c.id===s.id?t(n,r,c):de([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 de([r,n[s]].map(e)).pipe(z(([o,i])=>o===i?K([[r,o]]):t(n,{idx:0,id:o},{idx:s,id:i})))}},Qd=(e,t,n)=>{const r=Yd(t),s=l=>rn(()=>e().header(l)),o=new tn(1),i=l=>{if(l.type==="initialized"){const[c]=l.finalizedBlockHashes;return de([s(c),r(l.finalizedBlockHashes)]).pipe(x(([u,h])=>{o.closed||(o.next(Gd(u,c)),o.complete());const{number:p,parentHash:v,digests:d}=Vn.dec(u);return{type:"initialized",finalizedBlockHashes:l.finalizedBlockHashes,runtimeChanges:new Map(h),number:p,parentHash:v,hasNewRuntime:d.some(f=>f.type==="runtimeUpdated")}}))}if(l.type==="newBlock"&&l.newRuntime)return t(l.blockHash).pipe(x(c=>({...l,codeHash:c})))},a=l=>new D(c=>{let u=null,h;const p=f=>u?.push(f)||v(f),v=f=>{const b=i(f);b?(u=[],h=b.subscribe({next:y=>{const m=[...u];u=null,c.next(y),m.forEach(p)},error:n})):c.next(f)},d=l.subscribe(f=>{f.type==="stop-error"?(h?.unsubscribe(),u=null,c.next(f)):p(f)});return()=>{h?.unsubscribe(),d.unsubscribe()}});return{getHeader:l=>s(l).pipe(x(Vn[1])),hasher$:o.asObservable(),enhancer:a}},Jd=(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((v,d)=>o().storage(v,"hash","0x3a636f6465",null,d)));let a=Ee,l;const{hasher$:c,enhancer:u,getHeader:h}=Qd(o,i,v=>{console.warn("ChainHead subfollow request failed, retrying\u2026",v),l=setTimeout(()=>a(),250)}),p=new D(v=>{if(r)return v.complete();const d=()=>{let f=[];n=e(!0,b=>{f?f.push(b):v.next(b)},b=>{n=null,!r&&(b instanceof Error&&b.name===ro.errorName?(d(),v.next({type:"stop-error"})):(console.warn("ChainHead follow request failed, retrying\u2026",b),l=setTimeout(d,250)))}),f.forEach(b=>v.next(b)),f=null};a=()=>{v.next({type:"stop-error"}),clearTimeout(l),n?.unfollow(),d()},d(),s=()=>{r=!0,clearTimeout(l),v.complete(),n?.unfollow()}}).pipe(u,bt());return{getHeader:h,hasher$:c,getFollower:o,follow$:p,unfollow:()=>{s()}}},Zd=e=>Y(Ve.enc(e)),Qi=ne(),eh=xt(Qi),th=Oe(Ve).dec,Ji=e=>{const t=e("Metadata_metadata_versions","").pipe(x(th),oe(()=>K([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(Qi.dec)):e("Metadata_metadata_at_version",Zd(s)).pipe(x(o=>eh.dec(o)))};return t.pipe(z(n))},Zi=(e,t)=>e.type==="array"&&e.len===t&&e.value.type==="primitive"&&e.value.value==="u8",Bt={type:"void"},nh=(e,t=()=>null)=>{const n=new Map,r=new Set,s=u=>h=>{let p=n.get(h);if(p)return p;if(r.has(h)){const d={id:h};return n.set(h,d),d}r.add(h);const v=u(h);return p=n.get(h),p?Object.assign(p,v):(p={id:h,...v},n.set(h,p)),r.delete(h),p};let o=!0,i=!0;const a=s(u=>{const h=t(e[u]);if(h)return h;const{def:p,path:v,params:d}=e[u];if(p.tag==="composite"){if(p.value.length===0)return Bt;if(p.value.length===1){const f=a(p.value[0].type);return o&&v.at(-1)==="AccountId32"&&Zi(f,32)?(o=!1,{type:"AccountId32"}):i&&v.at(-1)==="AccountId20"&&Zi(f,20)?(i=!1,{type:"AccountId20"}):f}return l(p.value)}if(p.tag==="variant"){if(v.length===1&&v[0]==="Option"&&d.length===1&&d[0].name==="T"){const y=a(d[0].type);return y.type==="void"?{type:"primitive",value:"bool"}:{type:"option",value:y}}if(v.length===1&&v[0]==="Result"&&d.length===2&&d[0].name==="T"&&d[1].name==="E")return{type:"result",value:{ok:a(d[0].type),ko:a(d[1].type)}};if(p.value.length===0)return Bt;const f={},b={};return p.value.forEach(y=>{const m=y.name;if(b[m]=y.docs,y.fields.length===0){f[m]={...Bt,idx:y.index};return}if(y.fields.length===1&&!y.fields[0].name){f[m]={type:"lookupEntry",value:a(y.fields[0].type),idx:y.index};return}f[m]={...l(y.fields),idx:y.index}}),{type:"enum",value:f,innerDocs:b}}if(p.tag==="sequence")return{type:"sequence",value:a(p.value)};if(p.tag==="array"){const{len:f}=p.value,b=a(p.value.type);return!f||b.type==="void"?Bt:f>1?{type:"array",value:b,len:p.value.len}:b}if(p.tag==="tuple")return p.value.length===0?Bt:p.value.length>1?c(p.value.map(f=>a(f)),p.value.map(f=>e[f].docs)):a(p.value[0]);if(p.tag==="primitive")return{type:"primitive",value:p.value.tag};if(p.tag==="compact"){const f=a(p.value);return f.type==="void"?Bt:{type:"compact",isBig:Number(f.value.slice(1))>32,size:f.value}}return{type:p.tag,isLSB:(e[p.value.bitOrderType].path.at(-1)??"LSB").toUpperCase().startsWith("LSB")}}),l=u=>{let h=!0;const p={},v={};return u.forEach((d,f)=>{h=h&&!!d.name;const b=d.name||f,y=a(d.type);y.type!=="void"&&(p[b]=y,v[b]=d.docs)}),h?{type:"struct",value:p,innerDocs:v}:c(Object.values(p),Object.values(v))},c=(u,h)=>{if(u.every(p=>p.id===u[0].id)&&h.every(p=>!p.length)){const[p]=u;return p.type==="void"?Bt:{type:"array",value:u[0],len:u.length}}return{type:"tuple",value:u,innerDocs:h}};return a},ea=e=>{const t=nh(e.lookup,({def:r})=>{if(r.tag==="composite"){const s=n(r);if(s)return{type:"enum",innerDocs:{},value:Object.fromEntries(e.pallets.map(o=>[o.name,o.errors==null?{...Bt,idx:o.index}:{type:"lookupEntry",value:t(o.errors.type),idx:o.index}])),byteLength:s}}return null});function n(r){if(!(r.value.length===2&&r.value[0].name==="index"&&r.value[1].name==="error"))return null;const s=t(r.value[0].type),o=t(r.value[1].type);return s.type==="primitive"&&s.value==="u8"&&o.type==="array"&&o.value.type==="primitive"&&o.value.value==="u8"?1+o.len:null}return Object.assign(t,{metadata:e,call:"call"in e.extrinsic?e.extrinsic.call:e.lookup[e.extrinsic.type]?.params.find(r=>r.name==="Call")?.type??null})},rh=(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},sh=ne(),oh=(e,t,n,r)=>{if(e.type==="primitive")return Yi[e.value];if(e.type==="void")return M;if(e.type==="AccountId32")return r;if(e.type==="AccountId20")return wi;if(e.type==="compact")return e.isBig?zn:R;if(e.type==="bitSequence")return Nn(e.isLSB);const s=p=>ta(p,t,n,r),o=(p,v)=>{const d=s(p);return v?Oe(d,v):Oe(d)},i=p=>Pe(...p.map(s)),a=p=>{const v=Object.fromEntries(Object.entries(p).map(([d,f])=>[d,s(f)]));return be(v)};if(e.type==="sequence"&&e.value.type==="primitive"&&e.value.value==="u8")return sh;if(e.type==="array")return e.value.type==="primitive"&&e.value.value==="u8"?si(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 xt(s(e.value));if(e.type==="result")return jn(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,v)=>[p,l[v]])),u=Object.values(e.value).map(p=>p.idx),h=u.every((p,v)=>p===v)?Se(c):Se(c,u);return e.byteLength?ih(h,e.byteLength):h},ta=rh(oh,xr,e=>e),na=(e,t=dn())=>{const n=new Map,r=s=>ta(e(s),n,new Set,t);return s=>r(s)},ih=(e,t)=>{const n=ne(t);return X(r=>n.enc(e.enc(r)),r=>e.dec(n.dec(r)))},ah=Ne(M,()=>{},()=>null),ch=e=>{const{metadata:t}=e;let n=na(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=na(e,dn(p)))}catch{}const o=new Map,i=(p,v)=>{let d=o.get(p);d||o.set(p,d=Pi(p));const f=t.pallets.find(S=>S.name===p).storage.items.find(S=>S.name===v),b=S=>S===M?ah:S,y=(S,B,...I)=>{const _=d(...I),[,...T]=I;return{args:Pe(...T.map(([j])=>j)),keys:_,value:B,len:S,fallback:f.modifier===1?B.dec(f.fallback):void 0}};if(f.type.tag==="plain")return y(0,b(n(f.type.value)),v);const{key:m,value:g,hashers:$}=f.type.value,E=b(n(g)),w=$.map(S=>Yi[S.tag]),k=(()=>{if(w.length===1)return[[n(m),w[0]]];const S=e(m);switch(S.type){case"array":return w.map(B=>[n(S.value.id),B]);case"tuple":return S.value.map((B,I)=>[n(B.id),w[I]]);default:throw new Error("Invalid key type")}})();return y(w.length,E,v,...k)},a=p=>{switch(p.type){case"void":return M;case"lookupEntry":return n(p.value.id);case"tuple":return Pe(...Object.values(p.value).map(v=>n(v.id)));case"struct":return be(mt(p.value,v=>n(v.id)));case"array":return Oe(n(p.value.id),p.len)}},l=(p,v)=>{const d=t.pallets.find(f=>f.name===p).constants.find(f=>f.name===v);return n(d.type)},c=p=>(v,d)=>{const f=t.pallets.find(m=>m.name===v),b=e(f[p].type);if(b.type!=="enum")throw null;const y=b.value[d];return{location:[f.index,y.idx],codec:a(b.value[d])}},u=(p,v)=>{const d=t.pallets.find(f=>f.name===p)?.viewFns.find(f=>f.name===v);if(!d)throw null;return{args:Pe(...d.inputs.map(f=>n(f.type))),value:n(d.output)}},h=(p,v)=>{const d=t.apis.find(f=>f.name===p)?.methods.find(f=>f.name===v);if(!d)throw null;return{args:Pe(...d.inputs.map(f=>n(f.type))),value:n(d.output)}};return{buildDefinition:n,buildStorage:i,buildEvent:c("events"),buildError:c("errors"),buildViewFn:u,buildRuntimeCall:h,buildCall:c("calls"),buildConstant:l,ss58Prefix:s}},lh=(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}]})),uh=(e,t)=>{const n=lh(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=mt(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:mt(e.extrinsic.signedExtensions,a=>Object.fromEntries(a.map(({identifier:l,...c})=>[l,c])))}},zr="CheckMortality",ra=(e,t,n)=>{const r=ea(e),s=ch(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=hh(r.metadata,s),c=u=>{const h=l(u);return"extra"in h&&h.extra[zr]||{mortal:!1}};return{mappedMeta:uh(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}},Dr=ne(1/0).dec,dh=Rn(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}}),sa=lt(e=>{const t=P.dec(e);if(t===0)return{mortal:!1};const n=P.dec(e);return dh(Uint8Array.from([t,n]))}),hh=(e,t)=>{const n=be.dec(Object.fromEntries(e.extrinsic.signedExtensions[0].map(a=>[a.identifier,a.identifier===zr?sa: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=be.dec({address:r,signature:s,extra:n,callData:Dr});return lt(a=>{const l=R.dec(a),{type:c,version:u}=Hr[1](a);if(c==="bare")return{len:l,version:u,type:c,callData:Dr(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=be.dec(Object.fromEntries(d.map(f=>[f.identifier,f.identifier===zr?sa:t.buildDefinition(f.type)[1]])))}else p=n;const v=p(a);return{len:l,type:c,version:u,extensionVersion:h,extra:v,callData:Dr(a)}})},ph=e=>t=>{const n=(...r)=>{let s;try{s=e()}catch(o){return Rt(o)}return s?t(s,...r).pipe(oe(o=>{if(o instanceof Je)return n(...r);if(o instanceof Error&&o.name===Bn.errorName)return kn(750).pipe(z(()=>n(...r)));throw o})):Ye};return n},fh=(e,t,n)=>{const r=(s,o)=>t(s).pipe(oe(()=>K(null)),z(i=>i?K(i):o.pipe(Kt(a=>{n(s,a)}))),x(i=>({codeHash:s,metadataRaw:i,metadata:Fn(Dt.dec(i))})));return(s,o)=>{const i=new Set([o]),a={},l=ph(()=>{if(!i.size)throw a;return i.has(o)?o:[...i].at(-1)}),c=r(s,Ji(l(e)).pipe(oe(h=>h===a?Ye:Rt(()=>h)))).pipe(x(({metadata:h,metadataRaw:p,codeHash:v})=>ra(h,p,v)),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 tn(1),resetOnError:!0,resetOnComplete:!0,resetOnRefCountZero:!0}),vn=({hash:e,number:t,parent:n,hasNewRuntime:r})=>({hash:e,number:t,parent:n,hasNewRuntime:r}),vh=(e,t,n,r,s,o,i,a)=>{const l=({blocks:m,runtimes:g},$)=>{$.forEach(E=>{m.get(m.get(E).parent)?.children.delete(E),m.delete(E),a(E)}),Object.entries(g).map(([E,w])=>({key:E,usages:w.deleteBlocks($)})).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($=>$.recovering).map($=>$.hash));const g="pendingBlocks"in m.state?m.state.pendingBlocks:[];m.state={type:ve.Ready},g.forEach(c)},h=new ye,p=h.pipe(dl(()=>kn(0)),x(()=>({type:"cleanup"}))),v=oa(),d=()=>(l(v,[...v.blocks.values()].map(m=>m.hash)),Object.assign(v,oa())),f=Qe(s,p,e).pipe(sn((m,g)=>{const $=w=>{l(m,w),i(w)},E=(...w)=>{const k=m.blocks.get(m.finalized)?.number??-1,S=w.filter(({refCount:B,recovering:I,number:_,pruned:T})=>!B&&!I&&(T||_<k)).map(({hash:B})=>B);S.length&&$(S)};switch(g.type){case"initialized":if(m.state.type!==ve.Initializing&&m.state.type!==ve.RecoveringInit)throw new Error("Initialized event out of order");m.state.type===ve.RecoveringInit&&!g.finalizedBlockHashes.some(I=>m.blocks.has(I))&&(d(),o.next(null));const w=m.blocks.get(m.finalized)?.number??-1,k=g.finalizedBlockHashes.length-1,S=[];w>g.number+k?m.state={type:ve.RecoveringFin,target:w,pendingBlocks:S}:(m.state={type:ve.Initializing,pendingBlocks:S},m.finalized=g.finalizedBlockHashes[k]);let B=m.finalizedRuntime.codeHash;return g.finalizedBlockHashes.forEach((I,_)=>{const T=m.blocks.get(I);if(T)T.recovering=!1;else{const j=g.number+_,Z=j>w,le=g.runtimeChanges.get(I),$e=le&&!m.runtimes[le]&&Z;$e&&(B=le);const ot=_===0?g.parentHash:g.finalizedBlockHashes[_-1],At={hash:I,hasNewRuntime:_?g.runtimeChanges.has(I):g.hasNewRuntime,parent:ot,children:new Set(_===k?[]:[g.finalizedBlockHashes[_+1]]),pruned:!1,runtime:B,refCount:0,number:j,recovering:!1};m.blocks.set(I,At),$e&&(m.finalizedRuntime=m.runtimes[le]=y(le,I)),m.runtimes[B].usages.add(I),Z&&S.push(At)}}),m;case"stop-error":if(m.state.type===ve.Initializing)return d();for(const I of m.blocks.values())I.recovering=!0;return m.state={type:ve.RecoveringInit},m;case"newBlock":{const{parentBlockHash:I,blockHash:_}=g;if(m.blocks.has(_))m.blocks.get(_).recovering=!1;else{const T=m.blocks.get(I);T.children.add(_);const j=T.number+1,Z={hash:_,number:j,parent:I,children:new Set,runtime:T.runtime,pruned:!1,refCount:0,recovering:!1,hasNewRuntime:!!g.newRuntime};if(m.blocks.set(_,Z),g.newRuntime){const{codeHash:le}=g;Z.runtime=le,m.runtimes[le]=y(le,_)}m.runtimes[Z.runtime].addBlock(_),"pendingBlocks"in m.state?m.state.pendingBlocks.push(Z):c(Z)}return m}case"bestBlockChanged":return m.state.type===ve.RecoveringFin||(m.best=g.bestBlockHash,m.state.type===ve.Initializing&&u(m)),m;case"finalized":{const I=g.finalizedBlockHashes.slice(-1)[0];let _=!1;if(m.state.type===ve.RecoveringFin){if(m.blocks.get(I).number<m.state.target)return m;_=!0}m.finalized=I;const{blocks:T}=m;return T.get(m.best).number<T.get(m.finalized).number&&(m.best=m.finalized),m.finalizedRuntime=m.runtimes[T.get(m.finalized).runtime],g.prunedBlockHashes.forEach(j=>{const Z=m.blocks.get(j);Z&&(Z.pruned=!0)}),_&&u(m),m.state.type===ve.Ready&&h.next(),m}case"cleanup":return E(...m.blocks.values()),m;case"blockUsage":{const I=m.blocks.get(g.value.hash);return I&&(I.refCount+=g.value.type==="hold"?1:-1,E(I)),m}}},v),x(m=>({...m})),Kt({error(m){o.error(m)}}),fn),b=Object.assign(f,{state:v}),y=fh(On(b,t,"pinned-blocks"),n,r);return b},oa=()=>({best:"",finalized:"",runtimes:{},blocks:new Map,finalizedRuntime:{},state:{type:ve.Initializing,pendingBlocks:[]}}),ia=(e,t,n,r,s,o)=>{const i=new Map,a=v=>{i.get(v)?.(),i.delete(v)},l=new D(v=>{const d=t.subscribe({next:({hash:f})=>{i.set(f,o(f))},complete(){v.error(new Error("Tracking stopped"))}});return d.add(e.pipe(x(f=>f.finalized),he()).subscribe(()=>{e.state.blocks.forEach(({pruned:f,hash:b})=>{f&&a(b)})})),d.add(()=>[...i.keys()].forEach(a)),d}),c=v=>dr(e.pipe(Be(({blocks:d})=>d.get(v)?.pruned??!0))),u=(v,d,f)=>{if(f)return K({hash:v,found:{type:!1,validity:null}});const b=c(v);return n(v).pipe(z(y=>{const m=y.findIndex(g=>bh(g,d));return m>-1?b(s(v)).pipe(x(g=>({hash:v,found:{type:!0,index:m,events:g}}))):r(v,d).pipe(x(g=>({hash:v,found:{type:!1,validity:g}})))}),b,lr(()=>a(v)))},h=v=>{[...e.state.blocks.get(v)?.children.keys()??[]].forEach(h),a(v)},p=(v,d,f)=>u(v,d,f.has(v)).pipe(z(b=>{const{found:y}=b,m=y.type||y.validity?.success===!1;return m&&h(v),m?K(b):e.pipe(c(v),z(g=>g.blocks.get(v).children),ll(),z(g=>p(g,d,f)))}));return v=>Qe(l,e.pipe(te(1),z(d=>p(d.finalized,v,new Set(d.blocks.keys())))))},bh=(e,t)=>e.length===t.length&&e.every((n,r)=>t[r]===n),mh=new Uint8Array([2]),yh=(e,t)=>Y(ie([mh,e,ee(t)])),aa="TaggedTransactionQueue",ca="validate_transaction",[,gh]=Se({InvalidTransaction:Se({Call:M,Payment:M,Future:M,Stale:M,BadProof:M,AncientBirthBlock:M,ExhaustsResources:M,Custom:P,BadMandatory:M,MandatoryValidation:M,BadSigner:M}),UnknownTransaction:Se({CannotLookup:M,NoUnsignedValidator:M,Custom:P})}),wh=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=gh(e)}catch{n={type:"UnknownInvalidTx"}}return{success:!1,value:n}}),$h=(e,t)=>(n,r)=>{const s=t(n).pipe(x(o=>{try{return o.dynamicBuilder.buildRuntimeCall(aa,ca).value[1]}catch{return wh}}));return e(n,`${aa}_${ca}`,yh(r,n)).pipe(Gs(s),x(([o,i])=>i(o)))},Eh=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}),kh=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)}}),la=(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 v=c++;o.delete(v),u!==v&&a.set(v,[]);let d=!1,f=p.subscribe({next(b){u===v?r.next(b):a.get(v).push(b)},complete(){if(d=!0,i.delete(v),v===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(v,f)};return s=new _t,s.add(n.subscribe({next(p){const v=l++;o.set(v,rn(()=>e(p,v))),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()}}),xh=(e,t,n)=>{const{withRecovery:r,withRecoveryFn:s}=jl(),{getFollower:o,unfollow:i,follow$:a,getHeader:l,hasher$:c}=Jd(e,s),u=Pl(o),h=new ye,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}),v=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))),f=A=>o().unpin(A).catch(C=>{if(!(C instanceof Error&&C.name===Sn.errorName))throw C}),b=(A,C)=>d(v(On(g,s(Mt(A)),`stop-${C}`)),C),y=new Map,m=new ye,g=vh(a,(...A)=>v(s(Mt(u("call"))))(...A).pipe(x(ee)),t,n,h,m,A=>{f(A).catch(C=>{console.error("unpin",C)}),A.forEach(C=>{y.delete(C)})},A=>{y.delete(A)}),$=d(v(A=>g.state.runtimes[g.state.blocks.get(A).runtime].runtime),"getRuntimeCtx"),E=A=>C=>C.pipe(la(H=>$(A(H)).pipe(x(N=>[H,N])))),w=(A,C,H)=>{const N=y.get(A)??new Map,fe=N.get(C);if(fe)return fe;y.set(A,N);let Ot;const Xe=H.pipe(bt({connector:()=>Ot=new tn}),Kt({complete(){N.set(C,Ot)}}),kh());return N.set(C,Xe),Xe},k=Object.assign(g.pipe(Be(A=>A.state.type===ve.Ready)),{state:g.state}),S=k.pipe(he((A,C)=>A.finalized===C.finalized),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),B=k.pipe(he((A,C)=>A.best===C.best),x(A=>vn(A.blocks.get(A.best))),fn),I=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),Ot=N.number-fe.number+1,Xe=new Array(Ot);for(let Te=0,nr=N.hash;Te<Ot;Te++)Xe[Te]=H(nr),nr=Xe[Te].parent;return new Map(Xe.map(Te=>[Te.hash,Te]))},new Map),x(A=>[...A.values()]),fn),_=k.pipe(he((A,C)=>A.finalizedRuntime===C.finalizedRuntime),Tt(({finalizedRuntime:{runtime:A}})=>A.pipe(Eh(null))),fn),T=_.pipe(x(A=>A?.lookup.metadata??null)),j=Vl(S.pipe(x(A=>A.hash)),B.pipe(x(A=>A.hash)),p),Z=b(u("body"),"body"),le=A=>mr(w(A,"body",Z(A))).pipe(x(C=>C.map(ee))),$e=b(u("storage"),"storage"),ot=j(d((A,C,H,N=null,fe)=>{const Ot=g.state.blocks.get(A);return g.state.runtimes[Ot.runtime].runtime.pipe(z(Xe=>{const Te=H(Xe);return w(A,`storage-${C}-${Te}-${N??""}`,$e(A,C,Te,N)).pipe(fe?x(nr=>fe(nr,Xe)):je)}),x(Xe=>({block:vn(Ot),value:Xe})))},"storage")),At=Fl(o,r),dv=j(d(On(g,(A,C,H)=>At(A,C,H??null,!1),"storageQueries"),"storageQueries")),hv=d(On(g,l,"header"),"header"),tc=A=>ot(A,"value",C=>C.events.key,null,(C,H)=>C?H.events.dec(C):[]).pipe(x(C=>C.value)),pv=b(u("call"),"call"),nc=j((A,C,H)=>w(A,`call-${C}-${H}`,pv(A,C,H).pipe(x(ee)))),hs=$h(nc,$),fv=_.pipe(Be(Boolean),te(1),z(A=>{const{enc:C}=A.dynamicBuilder.buildStorage("System","BlockHash").keys;let H;try{H=C(0)}catch{H=C(0n)}return ot(null,"value",()=>H,null).pipe(x(N=>N.value))}),on(1));Qe(_,I).subscribe({error(){}});const vv=A=>g.state.runtimes[A]?.runtime??K(null),tr=(A,C=!1)=>{let H=A||"finalized";if(H=g.state[H]||H,!g.state.blocks.has(H)){if(C)throw new Je(H,"holdBlock");return Ee}h.next({type:"blockUsage",value:{type:"hold",hash:H}});let N=()=>{h.next({type:"blockUsage",value:{type:"release",hash:H}}),N=Ee};return()=>{N()}},bv=A=>C=>new D(H=>{const N=C.subscribe(H);return N.closed||N.add(tr(A)),N}),ps=m.pipe(Ht(Boolean)),mv=ia(k,ps,le,hs,tc,tr),yv=ia(g,ps,le,hs,()=>K(),tr);return{follow$:a,unfollow:i,finalized$:S,best$:B,bestBlocks$:I,newBlocks$:ct(k.pipe(te(1),z(({blocks:A,finalized:C})=>{const H=N=>{const fe=A.get(N);return fe?[fe,...Array.from(fe.children).flatMap(H)]:[]};return H(C)})),ps),runtime$:_,metadata$:T,genesis$:fv,hasher$:c,getRuntime$:vv,header$:hv,body$:le,call$:nc,storage$:ot,storageQueries$:dv,eventsAt$:tc,withHodl:bv,holdBlock:tr,trackTx$:mv,trackTxWithoutEvents$:yv,validateTx$:hs,pinnedBlocks$:k,withRuntime:E,getRuntimeContext$:j($)}};var Sh=e=>t=>new D(n=>e(Y(t),r=>{n.error(r)}));const Ih=({storageSubscription:e,...t})=>n=>{const r={},s=Mt(t.storage),o=(v,d,f)=>Mt(t.call)(v,d,f).pipe(x(ee)),i=Mt(t.header),a=v=>Mt(t.body)(v).pipe(x(d=>d.map(ee))),l=v=>i(v).pipe(x(Vn[1])),c=v=>s(v,"hash","0x3a636f6465",null).pipe(x(d=>d)),u=(v,d)=>n(v).pipe(oe(()=>K(null)),z(f=>f?K(f):Ji((...b)=>o(d,...b)).pipe(x(b=>ra(Fn(Dt.dec(b)),b,v)))),Kt(f=>{r[v]=f})),h=v=>c(v).pipe(z(d=>{const f=r[d];return f?K(f):u(d,v)})),p=(v,d,f,b=null,y)=>h(v).pipe(z(m=>s(v,d,f(m),b).pipe(x(g=>y?y(g,m):g))));return{body$:a,header$:l,storage$:p,storageQueries$:(v,d,f)=>new D(b=>e(v,d,f||null,y=>b.next(y),y=>b.error(y),()=>{b.complete()})),call$:o,eventsAt$:v=>p(v,"value",d=>d.events.key,null,(d,f)=>f.events.dec(d)),getRuntimeContext$:h}},Bh=()=>K(null),Ah=(e,{getMetadata:t,setMetadata:n}={})=>({chainHead$:()=>xh(e.chainHead,t||Bh,n||Ee),archive:Ih(e.archive),broadcastTx$:Sh(e.transaction),destroy:e.destroy}),Oh=(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(oe(s=>{if(!(s instanceof Je))throw s;return t(n,...r).pipe(oe(o=>{throw console.warn(o),s}))})),ht=R,Ch=Oe(Pe(W,ht)),q={bool:"boolean",str:"string",num:"number",big:"bigint",bits:"bitseq",void:"void"},_h=Se(Object.fromEntries(Object.values(q).map(e=>[e,M]))),Rh=Oe(Pe(W,Se({inline:xr(()=>Lr),lookup:ht}))),Th=Oe(ht),Hh=be({typeRef:ht,length:xt(ht)}),Mh=xt(ht),Uh=ht,zh=be({ok:ht,ko:ht}),Lr=Se({struct:Ch,terminal:_h,enum:Rh,tuple:Th,array:Hh,binary:Mh,option:Uh,result:zh}),Dh={i256:q.big,i128:q.big,i64:q.big,i32:q.num,i16:q.num,i8:q.num,u256:q.big,u128:q.big,u64:q.big,u32:q.num,u16:q.num,u8:q.num,bool:q.bool,char:q.str,str:q.str},bn=e=>({type:"terminal",value:{type:e}});function jr(e,t=()=>{}){switch(e.type){case"AccountId20":case"AccountId32":return bn(q.str);case"array":return e.value.type==="primitive"&&e.value.value==="u8"?{type:"binary",value:e.len}:(t(e.value.id),{type:"array",value:{typeRef:e.value.id,length:e.len}});case"bitSequence":return bn(q.bits);case"compact":return bn(e.isBig?q.big:q.num);case"enum":return{type:"enum",value:Object.entries(e.value).map(([n,r])=>r.type!=="lookupEntry"?[n,{type:"inline",value:jr(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(Dh[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(q.void)}}function Nr(e,t,n){if(t.type==="option"&&e==null)return!0;const r=(o,i)=>Nr(o,i,n),s=o=>{switch(o.value.type){case q.str:case q.big:case q.bool:case q.num:return typeof e===o.value.type;case q.bits:return typeof e=="object"&&e!=null&&typeof e.bitsLen=="number"&&e.bytes instanceof Uint8Array;case q.void:return!0}};switch(t.type){case"terminal":return s(t);case"binary":return t.value==null?e instanceof Uint8Array:typeof e=="string"&&e.startsWith("0x");case"array":if(!Array.isArray(e))return!1;const o=e;return t.value.length!=null&&o.length<t.value.length?!1:o.slice(0,t.value.length).every(c=>r(c,n(t.value.typeRef)));case"enum":if(!e)return!1;const 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 Lh=Object.defineProperty,jh=(e,t,n)=>t in e?Lh(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Nh=(e,t,n)=>jh(e,t+"",n);let ua=class{constructor(t=[]){Nh(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 Vr(e,t,n,r,s,o=!1){if(!n&&!e)return Fe(3,[]);if(!n)return Fe(2,[]);if(!e)return Fe(n.type==="option"?2:0,[]);s.has(n)||s.set(n,new Map);const i=s.get(n);if(i.has(e)){const l=i.get(e);return l==null?{level:3,changes:[],assumptions:new ua([[e,n]])}:Fe(l.level,l.changes)}i.set(e,null);const a=Vh(e,n,(l,c)=>Vr(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 Vh(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"?qn(s(e,t.value,"some"),2):e.type==="option"?qn(s(e.value,t,"some"),1):Fe(0,[]);switch(t.type){case"terminal":return Fe(t.value.type===e.value.type?3:0,[]);case"binary":return Fr(pa(e.value,t.value));case"array":const o=e,i=Fr(pa(o.value.length,t.value.length));return Pr([i,()=>s(o.value.typeRef,t.value.typeRef,"value")],r);case"enum":{const h=e,p=Object.fromEntries(t.value.map(([f,b])=>[f,b.value]));let v=ha(h.value.map(([f,b])=>()=>f in p?s(b.value,p[f],f):Fe(0,[{id:[typeof b.value=="number"?b.value:null,null],level:0,path:f}])));if(h.value.length===t.value.length)return v;v=qn(v,2);const d=new Set(h.value.map(([f])=>f));return v.changes=[...v.changes,...t.value.filter(([f])=>!d.has(f)).map(([f,b])=>({id:[null,typeof b=="number"?b:null],level:0,path:f}))],v}case"option":return Ph(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 qn(Pr(t.value.map(([h,p])=>()=>s(l[h],p,h)),r),c);case"tuple":{const h=e,p=Fr(Fh(h.value,t.value));return Pr([p,...t.value.map((v,d)=>()=>s(h.value[d],v,String(d)))],r)}case"result":const u=e;return ha([s(u.value.ok,t.value.ok,"ok"),s(u.value.ko,t.value.ko,"ko")])}}const qn=(e,t)=>({...e,level:Math.min(e.level,t)}),Ph=(e,t)=>({...e,level:Math.max(e.level,t)}),da=new ua,Fe=(e,t)=>({level:e,changes:t,assumptions:da}),Pr=(e,t)=>{let n=Fe(3,[]);for(const r of e){const s=typeof r=="function"?r():r;if(!t&&s.level===0)return s;s.level!==3&&(n.changes=[...n.changes,...s.changes]),n.assumptions.addAll(s.assumptions.values),n.level=Math.min(n.level,s.level)}return n},ha=e=>{if(!e.length)return Fe(3,[]);let t=!1,n=Fe(3,[]);for(const r of e){const s=typeof r=="function"?r():r;if(s.level!==3&&(n.changes=[...n.changes,...s.changes]),s.level===0){n.level=Math.min(n.level,1);continue}t=!0,n.assumptions.addAll(s.assumptions.values),n.level=Math.min(n.level,s.level)}return t?n:Fe(0,n.changes)},Fr=e=>({assumptions:da,changes:e===3?[]:[{id:[null,null],level:e,path:"length"}],level:e}),Fh=(e,t)=>t.length===e.length?3:e.length>=t.length?2:0,pa=(e,t)=>t===e?3:t==null||e>=t?2:e==null?1:0,fa=Se({lookup:R,typedef:Lr}),Jt=e=>({type:"lookup",value:e}),Wr=e=>({type:"typedef",value:e}),Kn=Wr({type:"terminal",value:{type:q.void}}),Wh=be({args:fa,values:fa});function qh(e){if(e.type.tag==="plain")return{args:Kn,values:Jt(e.type.value)};const{key:t,value:n}=e.type.value;return{args:Jt(t),values:Jt(n)}}function va(e){return{args:Wr({type:"tuple",value:e.inputs.map(t=>t.type)}),values:Jt(e.output)}}function Kh(e){return e.type==="lookupEntry"?Jt(e.value.id):Wr(jr(e))}function Xh(e){return{args:Kn,values:Jt(e)}}function Gh(e,t,n,r,s,o){const i=(a,l)=>a.type==="lookup"?l(a.value):a.value;return{args:Vr(i(e.args,t),t,i(n.args,r),r,s,o),values:Vr(i(n.values,r),r,i(e.values,t),t,s,o)}}function ba(e,t,n){const r=e.type==="lookup"?t(e.value):e.value;return Nr(n,r,t)}const Xn=e=>{const t=new WeakMap,n={};return r=>{const s=r??n,o=t.get(s)||e(r);return t.set(s,o),o}},Yh=Oe(Wh),Qh=Oe(Lr),[,Jh]=Pe(Yh,Qh);var Le=(e=>(e.Storage="storage",e.Tx="tx",e.Event="events",e.Const="constants",e.ViewFns="viewFns",e.Api="apis",e))(Le||{});const Zh=async({metadataTypes:e,descriptors:t})=>{const[[n,r],s]=await Promise.all([e.then(Jh),t]);return{getTypeDefNode:o=>r[o],getEntryPointNode:(o,i,a)=>{const l=s[o]?.[i]?.[a];return l==null?l:n[l]}}},ma=(e,t)=>{const n=Kh(e),[r,s]=t==="args"?[n,Kn]:[Kn,n];return{args:r,values:s}},ya=Xn(({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=jr(e(i))),a)};return{getTypeDefNode:o,getEntryPointNode:(i,a,l)=>{switch(i){case"storage":{const c=n[a]?.storage.get(l);return c&&qh(c)}case"tx":{const c=n[a]?.call.get(l);return c&&ma(c,"args")}case"events":{const c=n[a]?.event.get(l);return c&&ma(c,"values")}case"viewFns":{const c=n[a]?.view.get(l);return c&&va(c)}case"apis":{const c=r[a]?.get(l);return c&&va(c)}case"constants":{const c=n[a]?.const.get(l);return c&&Xh(c.type)}}},isAssetCompat:i=>t==null||Nr(i,o(t),o)}}),ga=(e,t,n,r)=>{if(!e)return null;const{getEntryPointNode:s,getTypeDefNode:o}=e;return{entry:s(t,n,r),getter:o}},ep=bt({connector:()=>new tn(1),resetOnError:!0,resetOnComplete:!0,resetOnRefCountZero:!0});function We(e,t){return new Promise((n,r)=>{let s=null,o=!1;const i=t?()=>{s?.unsubscribe(),r(new Qs)}:Ee;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 qr=Symbol("EMPTY_VALUE"),Kr=e=>t=>new D(n=>{let r=0,s=null,o=qr,i=!1;const a=()=>{const c=e(o,r++);o=qr,s=c.subscribe({next(u){n.next(u)},error(u){n.error(u)},complete(){o!==qr?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 wa={};const tp=e=>t=>new D(n=>{let r=wa,s=t.subscribe({next(o){n.next(r=o)},error(o){n.error(o)},complete(){r===wa?n.complete():s=e(r).subscribe(n)}});return()=>{s.unsubscribe()}}),Pt=e=>typeof e=="object"&&e!==null&&Object.entries(e).every(([t,n])=>t==="at"&&(n===void 0||typeof n=="string")||t==="signal"&&(n===void 0||n instanceof AbortSignal)),np=()=>{const e=new xc(new ye);return[e.pipe(pl()),()=>Kt({next:t=>e.value.next(t),error:t=>{e.value.error(t),e.next(new ye)},complete:()=>{e.value.complete(),e.next(new ye)}})]},rp={},$a=e=>new Proxy(rp,{get(t,n){return e(n)}}),nt=e=>{const t={};return $a(n=>(t[n]||(t[n]={}),$a(r=>(t[n][r]||(t[n][r]=e(n,r)),t[n][r]))))},Gn={level:pt.Incompatible,isCompatible:()=>!1,isValueCompatible:()=>!1},sp={args:Gn,value:Gn,isCompatible:()=>!1},op={level:pt.Identical,isCompatible:()=>!0,isValueCompatible:()=>!0},Yn=e=>(t=pt.BackwardsCompatible)=>e>=t,ip=(e,t,n,r)=>{let s;if(!r.entry)s=sp;else{const{args:o}=r.entry,i=l=>ba(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}=Gh(n.entry,n.getter,r.entry,r.getter,t);s={args:{level:c.level,isValueCompatible:a,isCompatible:Yn(c.level)},value:u.level===pt.Incompatible?Gn:{level:u.level,isValueCompatible:u.level>pt.Partial?()=>!0:h=>ba(l,n.getter,h),isCompatible:Yn(u.level)}}}else{const l=pt.Partial;s={args:{level:l,isValueCompatible:a,isCompatible:Yn(l)},value:n?Gn:op}}}return e===Le.Storage||e===Le.Api||e===Le.ViewFns?Object.assign(s,{isCompatible:Yn(Math.min(s.args.level,s.value.level))}):e===Le.Tx?s.args:s.value},ap=Xn(e=>{let t=null;const n=(e?Zh(e):Promise.resolve(null)).then(s=>t=s),r=Xn(s=>{const o=new Map,i=ya(s),a=l=>nt((c,u)=>ip(l,o,ga(t,l,c,u),ga(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=>ya(s).isAssetCompat}}),Ea=({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)},cp=(e,t,n,r)=>({at:s,signal:o}={})=>We(de([n.getRuntimeContext$(s||null),r]).pipe(x(([i,a])=>{const l=Ea(i,e,t);if(a(i).isValueCompatible(l))return l;throw new Error(`Incompatible entry Const(${e}.${t})`)})),o),lp=(e,t,n,r)=>{const s=()=>new Error(`Incompatible runtime entry Event(${e}.${t})`),o=(a,l)=>n.eventsAt$(a).pipe(x(c=>c.filter(u=>u.event.type===e&&u.event.value.type===t).map(u=>{if(!l(u.event.value.value))throw s();return{original:u,payload:u.event.value.value}}))),i=de([n.finalized$,r]).pipe(n.withRuntime(([a])=>a.hash),la(([[a,l],c])=>{if(!c.mappedMeta.pallets[e]?.event.has(t))throw new Error(`Runtime entry Event(${e}.${t}) not found`);const{isValueCompatible:u}=l(c);return o(a.hash,u).pipe(x(h=>({block:a,events:h})))}),ep);return{watch:()=>i,get:a=>at(de([r,n.getRuntimeContext$(a)]).pipe(te(1),Tt(([l,c])=>o(a,l(c).isValueCompatible)))),filter:a=>a.filter(({event:l})=>l.type===e&&l.value.type===t).map(l=>({original:l,payload:l.event.value.value}))}},up=(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=de([n.getRuntimeContext$(h),r]).pipe(z(([v,d])=>{let f;try{f=v.dynamicBuilder.buildRuntimeCall(e,t)}catch{throw new Error(`Runtime entry RuntimeCall(${s}) not found`)}const b=d(v);if(!b.args.isValueCompatible(i))throw o();return n.call$(h,s,Y(f.args.enc(i))).pipe(x(f.value.dec),x(y=>{if(!b.value.isValueCompatible(y))throw o();return y}))}),n.withHodl(h));return We(p,c)}},ka=(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 ie([new Uint8Array(i),a(s)])},xa=(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)}},Xr=()=>new Error("Unkown signer"),dp=e=>{const{extrinsic:t}=e,n=ea(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 Xr()}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 Xr();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 Xr()},hp={Ed25519:0,Sr25519:1,Ecdsa:2},pp=(e,t,n,r,s,o)=>{const[i,a]=dp(e),l=ie([Hr.enc({version:4,type:"signed"}),i===1?t:new Uint8Array([...a,...t]),i===1||!o?n:new Uint8Array([hp[o],...n]),...r,s]);return ie([pe.enc(l.length),l])},[Qn,mn]=["<Bytes>","</Bytes>"].map(e=>Yt.fromText(e)),fp=e=>async t=>{let n=!0,r;for(r=0;n&&r<Qn.length;r++)n=Qn[r]===t[r];n=n&&r===Qn.length;const s=t.length-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:ie([Qn,t,mn]))};function vp(e,t,n){return{publicKey:e,signTx:async(r,s,o,i,a=jt)=>{const l=Fn(Hi(o)),c=[],u=[];l.extrinsic.signedExtensions[0].map(({identifier:v})=>{const d=s[v];if(!d)throw new Error(`Missing ${v} signed extension`);c.push(d.value),u.push(d.additionalSigned)});const h=ie([r,...c,...u]),p=await n(h.length>256?a(h):h);return pp(l,e,p,c,r,t)},signBytes:fp(n)}}Uint8Array.from([1]);const bp=(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 mp(e){let t=0;for(;!(e&1);)t++,e>>=1;return t}const yp=e=>1<<Math.ceil(Math.log2(e)),gp=_n(ne(2)[0],e=>{const t=Math.min(Math.max(yp(e.period),4),65536),n=e.startAtBlock%t,r=Math.max(t>>12,1),s=Math.min(Math.max(mp(t)-1,1),15),o=n/r<<4;return et[0](s|o)}),[wp]=be({tip:pe,asset:xt(ne(1/0))}),Sa=new Uint8Array,Gr=Uint8Array.from([0]),Yr=e=>({value:e,additionalSigned:Sa}),Qr=e=>({value:Sa,additionalSigned:e}),Jr=(e,t)=>({value:e,additionalSigned:t}),$p=(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=bp(t,n),h=v=>{const[d,f]=r[v],b=a[v];try{return mt({value:d,additionalSigned:f},(y,m)=>{const g=b?.[m];return g instanceof Uint8Array?g:y(g)})}catch{if(b)throw new Error(`Wrong input received for ${v}`);return c.push(v),null}},p=mt(r,([v,d],f)=>{if(a[f])return h(f);switch(f){case"CheckNonce":return Yr(v(i));case"CheckMortality":return s.mortal?Jr(gp({period:s.period,startAtBlock:s.startAtBlock.height}),ee(s.startAtBlock.hash)):Jr(Gr,e);case"ChargeTransactionPayment":return Yr(v(o));case"ChargeAssetTxPayment":return Yr(wp({tip:o,asset:l.asset}));case"CheckGenesis":return Qr(e);case"CheckMetadataHash":return Jr(Gr,Gr);case"CheckSpecVersion":return Qr(d(u.spec_version));case"CheckTxVersion":return Qr(d(u.transaction_version));default:return h(f)}});return c.forEach(v=>{delete p[v]}),mt(p,(v,d)=>({...v,identifier:d}))}},Ia="AccountNonceApi_account_nonce",Ep={1:P.dec,2:et.dec,4:Ve.dec,8:cn.dec},kp=(e,t,n)=>e(n,Ia,t).pipe(x(r=>{const s=Ep[r.length];if(!s)throw new Error(`${Ia} retrieved wrong data`);return s(r)})),xp=(e,t)=>e.pinnedBlocks$.pipe(qs(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()),Sp=(e,t,n,r,s,o={})=>de([o.nonce!=null?K(o.nonce):Ip(e,Y(t.publicKey)),xp(e,r.hash).pipe(Tt(e.getRuntimeContext$)),e.genesis$]).pipe(te(1),z(([i,a,l])=>{const c=$p(ee(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),Xs(o),he()),r=o=>n(o).pipe(te(2),Tt(i=>kp(e.call$,t,i))),s=o=>de(o.map(i=>r(i).pipe(x(a=>({success:!0,value:a})),oe(a=>K({success:!1,value:a}))))).pipe(te(1));return e.pinnedBlocks$.pipe(te(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)}),Tt(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 Bp=Object.defineProperty,Ap=(e,t,n)=>t in e?Bp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Op=(e,t,n)=>Ap(e,t+"",n);const Cp=(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 v=s.blocks.get(l);if(!v)break;c=r.get(l=v.parent),u--}if(!c)return;const h=u<=s.blocks.get(s.finalized).number,p=c.found.type;if(p&&o?.found&&o.hash===c.hash){h&&n.complete();return}n.next(o=c.found.type?{found:p,hash:c.hash,number:u,index:c.found.index,events:c.found.events}:{found:p,validity:c.found.validity}),h&&(p?n.complete():c.found.validity?.success===!1&&n.error(new Ba(c.found.validity.value)))},a=t.pipe(he((l,c)=>l.finalized===c.finalized&&l.best===c.best)).subscribe({next:l=>{s=l,r.size!==0&&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)),_p=(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 Ba extends Error{constructor(t){super(JSON.stringify(t,(n,r)=>typeof r=="bigint"?r.toString():r instanceof Uint8Array?Y(r):r,2)),Op(this,"error"),this.name="InvalidTxError",this.error=t}}const Zr=(e,t,n,r=!1)=>e.hasher$.pipe(z(s=>{const o=Y(s(n)),i=(d,f)=>({type:d,txHash:o,...f}),a=e.pinnedBlocks$.state,l=d=>{if(!d.mortal)return 0;const{phase:f,period:b}=d,y=a.blocks.get(a.best).number;return Math.floor((Math.max(y,f)-f)/b)*b+f},c=d=>{let f=[...a.blocks.values()].filter(m=>!m.pruned&&!m.children.size);const b=Math.max(...f.map(({number:m})=>m));f=f.filter(({number:m})=>m>=b-1);const y=a.blocks.get(a.finalized);return f=y.children?[y,...f]:f,f.filter(m=>m.number>=d)},u=({hash:d})=>e.validateTx$(d,n),h=rn(()=>a.finalizedRuntime.runtime.pipe(x(d=>d.getMortalityFromTx(n)),x(l),x(c),z(d=>{let f;return Qe(...d.map(b=>ol(u(b),e.finalized$.pipe(Ht(y=>{if(y.number<b.number)return!0;let m=y;for(;m.number>b.number;){const g=a.blocks.get(m.parent);if(!g)return!1;m=g}return m.hash===y.hash}),xn(),Ks({success:null}))))).pipe(Be((b,y)=>{if(b.success===!1&&(f??(f=new Ba(b.value))),b.success)return!0;if(y===d.length-1&&f)throw f;return!1}),te(1))}),xn())),p=new D(d=>{const f=e.trackTx$(n).subscribe(d);return f.add(t(n).subscribe({error(b){d.error(b)}})),f}),v=Cp(p,e.pinnedBlocks$).pipe(x(d=>d.found?i("txBestBlocksState",{found:!0,block:{index:d.index,number:d.number,hash:d.hash},..._p(d.events,d.index)}):i("txBestBlocksState",{found:!1,isValid:d.validity?.success!==!1})));return ct(r?K(i("signed",{})):Ye,h,K(i("broadcasted",{})),v.pipe(tp(({found:d,type:f,...b})=>d?K(i("finalized",b)):Ye)))})),Aa=async(e,t,n,r)=>Fc(Zr(e,t,n)).then(s=>{if(s.type!=="finalized")throw null;const o={...s};return delete o.type,o}),Rp=dn().enc,Tp=new Uint8Array(64),Hp=new Uint8Array(65),Mp=e=>()=>e?Hp:Tp,[,Up]=be({weight:be({ref_time:zn,proof_size:zn}),class:Se({Normal:M,Operational:M,Mandatory:M}),partial_fee:ko}),es=(e,t,n,r,s,o)=>{const i=c=>de([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:v})=>{const d=ka(h,v,e,t,c);return{callData:d,bare:ie([pe.enc(d.length+1),new Uint8Array(p.slice(-1)),d])}})),l=(c,u)=>c===void 0?K(void 0):i(u).pipe(x(({ctx:h,isAssetCompat:p})=>{if(!p(c))throw new Error("Incompatible runtime asset");const{dynamicBuilder:v,assetId:d}=h;if(d)return v.buildDefinition(d).enc(c)}));return c=>{const u=(y,{...m},g)=>de([a(c,g.hash),l(m.asset,g.hash)]).pipe(z(([$,E])=>Sp(n,y,$.callData,g,m.customSignedExtensions||{},{...m,asset:E}))),h=(y,{at:m,...g}={})=>{const $=n.pinnedBlocks$.state.blocks.get(m);return m&&!$?Rt(()=>new Error(`Uknown block ${m}`)):($?K($):n.finalized$).pipe(te(1),z(E=>u(y,g,E).pipe(x(w=>({tx:w,block:E})))))},p=(y,m)=>at(h(y,m)).then(g=>g.tx),v=(y,m)=>at(h(y,m)).then(({tx:g,block:$})=>Aa(n,r,g,$.hash)),d=(y,m)=>h(y,m).pipe(z(({tx:g})=>Zr(n,r,g,!0))),f=async(y,m)=>{typeof y=="string"&&(y=y.startsWith("0x")?ee(y):Rp(y));const g=y.length===20,$=vp(y,g?"Ecdsa":"Sr25519",Mp(g)),E=await p($,m),w=Y(ie([E,Ve.enc(E.length)])),k=n.getRuntimeContext$(null).pipe(x(B=>{try{return B.dynamicBuilder.buildRuntimeCall("TransactionPaymentApi","query_info").value[1]}catch{return Up}})),S=n.call$(null,"TransactionPaymentApi_query_info",w);return at(de([S,k]).pipe(x(([B,I])=>I(B))))},b=()=>at(a(c,null).pipe(x(({callData:y})=>y)));return{getPaymentInfo:f,getEstimatedFees:async(y,m)=>(await f(y,m)).partial_fee,decodedCall:{type:e,value:Dn(t,c)},getEncodedData:b,getBareTx:()=>at(a(c,null).pipe(x(({bare:y})=>y))),sign:p,signSubmitAndWatch:d,signAndSubmit:v}}},zp=(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 es(c,u,e,t,n("tx",c,u),s)(h)}catch{throw new Error("Invalid call data")}};return({at:i,signal:a}={})=>We(e.getRuntimeContext$(i??null).pipe(z(Xn(async l=>{const c=await r(l);return{id:l.codeHash,txFromCallData:o(l),constants:nt((u,h)=>Ea(l,u,h)),query:nt((u,h)=>({getKey:xa(l,u,h,c.query[u][h].args.isValueCompatible)})),tx:nt((u,h)=>({getEncodedData:p=>ka(l.dynamicBuilder,c.tx[u][h].isValueCompatible,u,h,p)})),compat:c}}))),a)},Dp=(e,t,n,r,s)=>{const o=e==="System"&&t==="Number",i=e==="System"&&t==="BlockHash",a=n.runtime$.pipe(Be(Boolean),te(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 f=d.at(-1),b=Pt(f),[y,m]=b?[d.slice(0,-1),d.at(-1).at==="best"]:[d,!1];return n[m?"best$":"finalized$"].pipe(Kr(()=>p(...y,m?{at:"best"}:{})),sn((g,{value:$,block:E})=>g?{block:E,value:g.value.raw===$.raw?g.value:$}:{block:E,value:$},null),x(g=>({block:g.block,value:g.value.mapped})))},p=(...d)=>{const f=d[d.length-1],b=Pt(f),{at:y}=b?f:{},m=y??null,g=vt(s).pipe(z($=>n.storage$(m,"value",E=>{const w=u(E),k=$(E),S=d.length===w.len?d:d.slice(0,-1);if(d!==S&&!b)throw c(d);if(!k.args.isValueCompatible(S))throw l();return w.keys.enc(...S)},null,(E,w)=>{const k=u(w),{value:{isValueCompatible:S}}=$(w),B=E===null?k.fallback:k.value.dec(E);if(!S(B))throw l();return{raw:E,mapped:B}})),n.withHodl(m));return o?n.pinnedBlocks$.pipe(x($=>{const E=m==="finalized"||!m?$.finalized:m==="best"?$.best:m,w=$.blocks.get(E);if(!w)throw new Je(E,"System.Number");return w}),he(($,E)=>$.number===E.number),cl(a),x(([$,E])=>({block:$,value:{raw:$.number.toString(),mapped:E($.number)}})),oe($=>{if($ instanceof Je)return g;throw $})):i&&Number(d[0])===0?de([n.genesis$,n.pinnedBlocks$.pipe(x($=>{const E=m==="finalized"||!m?$.finalized:m==="best"?$.best:m,w=$.blocks.get(E);if(!w)throw new Je(E,"System.BlockHash");return w}),te(1))]).pipe(x(([$,E])=>({block:E,value:{raw:$,mapped:$}}))):g},v=async(...d)=>{const f=d[d.length-1],b=Pt(f),{signal:y}=b?f:{};return We(p(...d).pipe(x(m=>m.value.mapped)),y)};return{getKey:(...d)=>at(de([n.getRuntimeContext$(null),s]).pipe(x(([f,b])=>xa(f,e,t,b(f).args.isValueCompatible)(...d)))),getValue:v,getValues:(d,f)=>Promise.all(d.map(b=>v(...f?[...b,f]:b))),getEntries:async(...d)=>{const f=d[d.length-1],b=Pt(f),{signal:y,at:m}=b?f:{},g=m??null,$=vt(s).pipe(z(E=>n.storage$(g,"descendantsValues",w=>{const k=E(w),S=u(w);if(!k.isCompatible(pt.Partial))throw l();if(d.length>S.len)throw c(d);const B=d.length>0&&b?d.slice(0,-1):d;if(d.length===S.len&&B===d)throw c(d);return S.keys.enc(...B)},null,(w,k)=>{const S=u(k),B=E(k),I=w.map(({key:_,value:T})=>({keyArgs:S.keys.dec(_),value:S.value.dec(T)}));if(B.value.level===pt.Partial&&I.some(({value:_})=>!B.value.isValueCompatible(_)))throw l();return I})),x(E=>E.value),n.withHodl(g));return We($,y)},watchValue:h,watchEntries:(...d)=>{const f=d.at(-1),b=Pt(f);return r(e,t,b?d.slice(0,-1):d,b&&f.at==="best")}}},Oa="RuntimeViewFunction",Ca="execute_view_function",ts=Oa+"_"+Ca,Lp=(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=de([n.getRuntimeContext$(u),r]).pipe(z(([p,v])=>{let d;try{d=p.dynamicBuilder.buildRuntimeCall(Oa,Ca)}catch{throw new Error(`Runtime entry RuntimeCall(${ts}) not found`)}let f;try{f=p.dynamicBuilder.buildViewFn(e,t)}catch{throw new Error(`Runtime entry ViewFn(${e}.${t}) not found`)}const b=v(p);if(!b.args.isValueCompatible(o))throw s();const y=f.args.enc(o),m=ie([ee(p.mappedMeta.pallets[e].view.get(t).id),R.enc(y.length),y]);return n.call$(u,ts,Y(m)).pipe(x(g=>{try{const $=d.value.dec(g);if(!("success"in $&&"value"in $)||!("type"in $.value)&&!($.value instanceof Uint8Array))throw null;return $}catch{throw new Error(`Unexpected RuntimeCall(${ts}) type`)}}),x(({success:g,value:$})=>{if(!g)throw new Error(`ViewFn API Error: ${$.type}`);const E=f.value.dec($);if(!b.value.isValueCompatible(E))throw s();return E}))}),n.withHodl(u));return We(h,l)}};var jp=Object.defineProperty,Np=(e,t,n)=>t in e?jp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,rt=(e,t,n)=>(Np(e,typeof t!="symbol"?t+"":t,n),n),ns=Symbol("SUSPENSE"),Vp=class extends Promise{constructor(e){super(e)}},_a=class extends Error{constructor(){super(),this.name="NoSubscribersError"}},Ra=class extends Error{constructor(){super(),this.name="EmptyObservableError"}},Re={},Jn=class extends D{constructor(e,t,n=Ee){super(r=>{const s=new en({next:r.next.bind(r),error:r.error.bind(r),complete:Ee});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 _a),this.promise=null))}),this.subject?(o=this.subject.subscribe(s),this.currentValue!==Re&&r.next(this.currentValue)):(this.subject=new ye,o=this.subject.subscribe(s),this.subscription=null,this.subscription=new en({next:i=>{this.promise&&i!==ns&&(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===ns&&(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 Ra),this.promise=null),this.currentValue!==Re)return this.subject.complete();if(t===Re){const i=this.subject;return this.subject=null,i.error(new Ra)}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 Jn?s:new Jn(s,Re)}),rt(this,"getRefCount",()=>this.refCount),rt(this,"getValue",()=>{if(this.promise)return this.promise.p;if(this.currentValue!==Re&&this.currentValue!==ns)return this.currentValue;if(this.defaultValue!==Re)return this.defaultValue;if(this.refCount===0)throw new _a;const r=new Vp((s,o)=>{this.promise={res:s,rej:o,p:null}});return this.promise.p=r,r}),rt(this,"getDefaultValue",()=>this.defaultValue),t===Re&&delete this.getDefaultValue}};function Ta(e,t){t.getValue=e.getValue,t.getRefCount=e.getRefCount,t.pipeState=e.pipeState,e.getDefaultValue&&(t.getDefaultValue=e.getDefaultValue)}function Pp(e,t){const n=new Fp,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 Jn(e(...o),r(...o),()=>{n.delete(i)}),c=new D(h=>{const p=n.get(i);let v=l;return p?p!==c&&(v=p,Ta(v,c)):n.set(i,u),v.subscribe(h)});Ta(l,c);const u=c;return n.set(i,u),u};return(...o)=>s(o)}var Fp=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 Wp(e,t){return new Jn(e,t)}var rs=(...e)=>(typeof e[0]=="function"?Pp:Wp)(e[0],e.length>1?e[1]:Re);const Ha=(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))}},Ma=(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}},qp=(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)},Kp=(e,t,n)=>{const r=rs((a,l,c)=>{const u=qp(a,l),h=(b,y)=>{const m=Oh(e,y.hash).pipe(Be(g=>!g),te(1));return t(y.hash,"closestDescendantMerkleValue",()=>c).pipe(z(g=>{const $=g.value;return $===b?.rootHash?K({...b,block:y,deltas:null,prev:b.block.hash}):t(y.hash,"descendantsValues",()=>c).pipe(n(()=>y.hash),x(([E,w])=>[E.value,u(w)]),x(([E,w])=>({prev:b&&b.block.hash,rootHash:$,block:y,patcher:w,...Ha(b?.entries??[],E,w)})))}),dr(m),oe(g=>g instanceof Je?Ye:Rt(()=>g)))},p=e.pipe(he((b,y)=>b.finalized===y.finalized),Kr(({blocks:b,finalized:y})=>h(null,b.get(y))),te(1),x(b=>({blocks:{[b.block.hash]:b},finalized:b.block.hash}))),[v,d]=np(),f=e.pipe(he((b,y)=>b.best===y.best),Gs(v),Kr(([b,y])=>{const{best:m}=b,{blocks:g}=y;let $=g[m]?null:m;if(!$)return Ye;const E=Ma($,g,b);return E?h(E,b.blocks.get($)).pipe(x(w=>(g[$]=w,y))):($=b.finalized,h(g[y.finalized],b.blocks.get($)).pipe(x(w=>(w.prev=null,{blocks:{[$]:w},finalized:$}))))}));return Qe(p,f).pipe(d())}),s=a=>(l,c,u)=>{const h=r(l,c,u),p=a?"finalized":"best";return de([h,e.pipe(he((v,d)=>v[p]===d[p]))]).pipe(x(([v,d])=>{const f=Ma(d[p],v.blocks,d,!0);return f&&{update:f,state:v}}),Be(Boolean),he((v,d)=>v.update===d.update),Xs(null),hl(),z(([v,d])=>{if(!v)return[d.update];const{update:f}=v,{state:b,update:y}=d;let m=y;const g=[];for(;m&&m.block.number>f.block.number;)g.unshift(m),m=m.prev?b.blocks[m.prev]:null;if(a&&(b.finalized=y.block.hash,g.length)){const{blocks:$}=b;Object.keys($).forEach(E=>{$[E].block.number<g[0].block.number&&delete $[E]})}return f===m?g:[{...y,...f.rootHash===y.rootHash?{entries:f.entries,deltas:null}:Ha(f.entries,y.entries,y.patcher)}]}))},o=rs(s(!0)),i=rs(s(!1));return(a,l,c,u)=>{const h=u?i:o;return e.pipe(te(1),z(p=>p.runtimes[p.blocks.get(p[u?"best":"finalized"]).runtime].runtime),x(p=>p.dynamicBuilder.buildStorage(a,l).keys.enc(...c))).pipe(te(1),z(p=>h(a,l,p)),x(({block:{hash:p,number:v,parent:d},deltas:f,entries:b},y)=>{const m=y>0?f:{deleted:[],upserted:b};return{block:{hash:p,number:v,parent:d},entries:b.map(ss),deltas:m&&{deleted:m.deleted.map(ss),upserted:m.upserted.map(ss)}}}))}},ss=e=>e.dec,Xp=/^(?:0x)?((?:[0-9a-fA-F][0-9a-fA-F])+)$/,Ua=(e,t,n)=>{const r=ap(n),{getClientCompat:s,getIsAsssetCompat:o}=r,i=zp(e,t,r),a=Kp(e.pinnedBlocks$,e.storage$,e.withRuntime),l=nt((d,f)=>Dp(d,f,e,a,s("query",d,f))),c=nt((d,f)=>es(d,f,e,t,s("tx",d,f),o)),u=nt((d,f)=>lp(d,f,e,s("event",d,f))),h=nt((d,f)=>cp(d,f,e,s("constants",d,f))),p=nt((d,f)=>up(d,f,e,s("apis",d,f))),v=nt((d,f)=>Lp(d,f,e,s("view",d,f)));return{tx:c,constants:h,apis:p,view:v,query:l,event:u,txFromCallData:(d,{at:f,signal:b}={})=>We(e.getRuntimeContext$(f??null).pipe(x(({dynamicBuilder:y,lookup:m})=>{try{const{type:g,value:{type:$,value:E}}=y.buildDefinition(m.call).dec(d);return es(g,$,e,t,s("tx",g,$),o)(E)}catch{throw new Error("createTx: invalid call data")}})),b),getStaticApis:i}};function Gp(e,{getMetadata:t,setMetadata:n}={}){const r=Ul(e),s=Ah(r,{getMetadata:t?B=>vt(t(B)):void 0,setMetadata:n}),{getChainSpecData:o}=r,i=B=>(I,..._)=>de([B(I,..._),c.header$(I).pipe(x(({number:T,parentHash:j})=>({hash:I,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$:rn(o).pipe(x(({genesisHash:B})=>B),oe(()=>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=(B,I,_)=>new D(T=>{let j=null,Z=null;const le=()=>{Z!=null&&r.request(I,[Z])};return r._request(B,_,{onSuccess:($e,ot)=>{if(Z=$e,T.closed){le();return}j=ot(Z,{next:At=>T.next(At),error:At=>T.error(At)})},onError($e){T.error($e)}}),()=>{le(),j?.()}});let v;const d=new WeakMap,{broadcastTx$:f}=s,b=B=>u.getRuntimeContext$(B).pipe(x(I=>I.metadataRaw)),{holdBlock:y,finalized$:m,bestBlocks$:g,body$:$,header$:E,storage$:w,unfollow:k}=u,S={getChainSpecData:o,getMetadata$:b,getMetadata:(B,I)=>We(b(B),I),blocks$:u.newBlocks$,hodlBlock:B=>y(B,!0),finalizedBlock$:m,getFinalizedBlock:()=>at(m),bestBlocks$:u.bestBlocks$,getBestBlocks:()=>at(g),getBlockBody$:$,getBlockBody:(B,I)=>We($(B),I),getBlockHeader$:E,getBlockHeader:(B,I)=>We(E(B),I),submit:(...B)=>Aa(u,f,...B),submitAndWatch:B=>Zr(u,f,B),getTypedApi:B=>{if(d.has(B))return d.get(B);const I=Ua(u,f);return d.set(B,I),I},getUnsafeApi:()=>(v??(v=Ua(u,f)),v),rawQuery:(B,{at:I,signal:_}={})=>We(w(I??null,"value",()=>{const T=B.match(Xp)?.[1];return T?`0x${T}`:Y(Yt.fromText(B))}).pipe(x(T=>T.value)),_),destroy:()=>{k(),s.destroy()},_request:h,_subscribe:p};return S.___INTERNAL_DO_NOT_USE=u,S}const st={body:"",call:"",continue:"",follow:"",header:"",stopOperation:"",storage:"",unfollow:"",unpin:""},os={body:"",call:"",finalizedHeight:"",genesisHash:"",hashByHeight:"",header:"",stopStorage:"",storage:""},is={broadcast:"",stop:""},za={chainName:"",genesisHash:"",properties:""};Object.entries({chainHead:st,chainSpec:za,transaction:is,archive:os}).forEach(([e,t])=>{Object.keys(t).forEach(n=>{t[n]=`${e}_v1_${n}`})});const as=e=>t=>new D(n=>{let r,s=[],o=!1;const i=new _t;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}),Zn=on({refCount:!0,bufferSize:1}),Yp=({allHeads$:e,finalized$:t,getHeader$:n,hasher$:r,getRecursiveHeader:s})=>{const o={blocks:new Map,prevFin:"",finalized:"",best:""},i=(w,k=[])=>(k.push(w),o.blocks.get(w).children.forEach(S=>{i(S,k)}),k),a=w=>{const{blocks:k}=o,{hash:S,parent:B}=w,I={...w,children:new Set,usages:new Set};return k.set(S,I),k.get(B)?.children.add(S),I},l=()=>{o.best=o.finalized;let w=0;const{finalized:k,blocks:S}=o;i(k).map(B=>S.get(B)).forEach(B=>{B.number>w&&(w=B.number,o.best=B.hash)})},c=new Map,u=w=>{const k=[...c.get(w).children];c.delete(w),k.forEach(u)},h=(w,k=[])=>{const S=c.get(w);return S.header&&(k.push(S.header),S.children.forEach(B=>{h(B,k)})),k},p=new ye,v=w=>p.error(w),d=t.pipe(Ws((w,k)=>{const{hash:S}=w;return k||(a(w),o.finalized=o.best=w.hash),o.blocks.has(S)?K(S):p.pipe(Be(B=>B===S),qs(0),te(1))}),bt());e.subscribe(w=>{const{parent:k,hash:S,number:B}=w;o.blocks.has(S)||!B||(o.blocks.has(k)?(a(w),p.next(S)):(c.set(S,{hash:w.hash,header:w,children:new Set}),c.has(k)||(c.set(k,{hash:k,header:null,children:new Set}),s(k).pipe(Ht(I=>{let _=c.get(I.hash);if(!_)return!1;_.header=I;const T=o.blocks.get(o.finalized);if(T&&I.number<=T.number){for(;c.has(_.header?.parent??"");)_=c.get(_.header.parent);return u(_.hash),!1}if(o.blocks.has(I.parent)){let Z=o.blocks.get(I.parent);const le=Z.number-T.number;for(let $e=0;$e<le;$e++){const ot=o.blocks.get(Z.parent);if(!ot)break;Z=ot}return Z===T?h(I.hash).forEach($e=>{c.delete($e.hash),a($e),p.next($e.hash)}):u(I.hash),!1}const j=c.get(I.parent);return j?(j.children.add(I.hash),!1):(c.set(I.parent,{hash:I.parent,header:null,children:new Set([I.hash])}),!0)})).subscribe({error:v})),c.get(k).children.add(S)))},v);const f=()=>{const w=[],k=[],{blocks:S,finalized:B,prevFin:I}=o;let _=S.get(B),T=S.get(_.parent);for(;T&&(k.push(_.hash),T.children.forEach(j=>{j!==_.hash&&i(j,w)}),_=T,_.hash!==I);)T=S.get(_.parent);return k.reverse(),{event:"finalized",prunedBlockHashes:w,finalizedBlockHashes:k}};let b=new Set;const y=w=>{const k=o.blocks.get(w);return b.forEach(S=>{k.usages.add(S)}),{event:"newBlock",blockHash:w,parentBlockHash:k.parent,newRuntime:k.hasUpgrade?{}:null}},m=(w,k)=>{const{blocks:S}=o,B=S.get(w);if(!B||B.usages.size>0)return;const{parent:I,children:_}=B;k!==!0&&_.forEach(T=>m(T,!1)),k!==!1&&m(I,!0),(!S.has(I)||!B.children.size)&&(S.get(I)?.children.delete(w),S.delete(w))},g=Qe(p.pipe(x(w=>({type:"new",value:o.blocks.get(w)}))),d.pipe(x(w=>({type:"fin",value:w})))).pipe(z(w=>{if(w.type==="new"){const B=w.value,{hash:I}=B;a(B);const _=[y(I)];return B.number>o.blocks.get(o.best).number&&(o.best=I,_.push({event:"bestBlockChanged",bestBlockHash:I})),_}o.prevFin=o.finalized,o.finalized=w.value;let k=o.best;l();const S=[f()];return k!==o.best&&S.unshift({event:"bestBlockChanged",bestBlockHash:o.best}),S}),bt()),$=rn(()=>o.blocks.size?[null]:d.pipe(te(1),x(()=>null))).pipe(Zn),E=d.pipe(x(w=>o.blocks.get(w)),Zn);return Qe(g,E).subscribe({error:v}),{clean:()=>{c.clear(),o.blocks.clear()},upstream:w=>{const k=()=>{const{blocks:I,finalized:_}=o,T=[];let j=I.get(_);for(;j&&T.length<10;)T.push(j.hash),j.usages.add(w),j=I.get(j.parent);return T.reverse(),{event:"initialized",finalizedBlockHashes:T}},S=I=>{const _=o.blocks.get(I);_&&(_.usages.delete(w),m(I))},B=$.pipe(z(()=>{const{best:I,finalized:_}=o,T=i(_).slice(1).map(y);return T.push({event:"bestBlockChanged",bestBlockHash:I}),[k(),...T]}));return{blocks$:ct(B,g).pipe(Kt({subscribe:()=>{b.add(w)},finalize:()=>{b.delete(w)}}),bt()),getHeader:I=>o.blocks.get(I)?.header??null,isPinned:I=>!!o.blocks.get(I)?.usages.has(w),unpin:S}},finalized$:E,getHeader$:w=>{const k=o.blocks.get(w);return k?K(k):n(w)},hasher$:r}},Da=e=>({parentHash:t,number:n,stateRoot:r,extrinsicsRoot:s,digest:o})=>{const i=Number(n),a=o.logs.map(ee),l=ie([ee(t),pe.enc(i),ee(r),ee(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)}},La=[jt,Ln],Qp=La.map(Da),Jp=e=>{throw new Error("Hasher not supported")},Zp=e=>t=>La[Qp.findIndex(n=>n(e).hash===t)]||Jp,ef={},tf=(e,t)=>{const n=new ye,r=n.pipe(z(h=>t("chain_getBlockHash",[h.number]).pipe(x(Zp(h)))),Zn),s=r.pipe(x(Da),Zn),o=gs(as(s),x(([h,p])=>h(p))),i=(h,p,v=!1)=>new D(d=>{const f=m=>{d.error(m)};let b=null,y=v;return e(h,[],{onSuccess:(m,g)=>{const $=g(m,{next:w=>{y&&(y=!1,n.next(w),n.complete()),d.next(w)},error:f}),E=()=>{$();try{e(p,[m],{onError:V,onSuccess:V})}catch{}};b!==null?E():b=E},onError(){f(ef)}}),()=>{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(z(p=>ct(K(p),u(p.parent))));return{allHeads$:a,finalized$:l,hasher$:r,getRecursiveHeader:u,getHeader$:c}},nf=(e,t)=>Yp(tf(e,t)),rf=e=>(t,n)=>e("state_getReadProof",[[n],t]).pipe(z(r=>{const s=Gi(r.proof);if(!s)throw new Error("Invalid Proof");const{rootHash:o,proofs: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]})),sf=e=>{const t=(g,$,E,w)=>e(g,$,{onSuccess:E,onError:w}),n=(g,$)=>new D(E=>t(g,$,w=>{E.next(w),E.complete()},w=>{E.error(w)}));let r=null;const s=()=>(r??(r=nf(e,n)),{...r,getBlocks:r.upstream}),o=()=>r?.clean(),i=(g,$,E)=>n("state_call",[$,E,g]),a=(g,$)=>{const E=k=>n("state_getKeysPaged",[$,1e3,k||void 0,g]).pipe(z(S=>{const B=S[0]===k?S.slice(1):S,I=S.length<1e3?Ye:E(S.at(-1));return Qe(K(B),I)})),w=(k,S=0)=>k.length?n("state_queryStorageAt",[k,g]).pipe(x(([{changes:B}])=>B),oe(B=>{if(S>3)throw B;const I=Math.floor(k.length/2);return Qe(w(k.slice(0,I),++S),w(k.slice(I),S))})):Ye;return E().pipe(z(k=>w(k)))},l=(g,$)=>a(g,$).pipe(as(s().hasher$),x(([E,w])=>w.map(([k,S])=>[k,Y(E(ee(S)))]))),c=rf(n),[u,h]=["state_getStorage","state_getStorageHash"].map(g=>($,E)=>n(g,[E,$])),p=(g,$)=>h(g,$).pipe(oe(E=>{if(E instanceof Error&&E.message==="Method not found")return u(g,$).pipe(as(s().hasher$),x(([w,k])=>k==null?null:Yt.toHex(w(Yt.fromHex(k)))));throw E})),v=n("rpc_methods",[]),d=n("system_name",[]),f=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:f,genesisHash:m,methods:v,request:t,obsRequest:n,clean:o}};let of=1;const Zt=()=>`${of++}${Date.now()}`,af=new Set(["value","hash","closestDescendantMerkleValue","descendantsValues","descendantsHashes"]),ja=e=>Array.isArray(e)&&e.every(t=>typeof t=="object"&&typeof t.key=="string"&&af.has(t.type)),Na=(e,t,n)=>Qe(...n.map(({key:r,type:s})=>{switch(s){case"value":return e.stgValue(t,r).pipe(Be(Boolean),x(o=>[{key:r,value:o}]));case"hash":return e.stgHash(t,r).pipe(Be(Boolean),x(o=>[{key:r,hash:o}]));case"descendantsValues":return e.stgDescendantValues(t,r).pipe(x(o=>o.map(([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(Be(Boolean),x(o=>[{key:r,closestDescendantMerkleValue:o}]))}})),yn=e=>e instanceof Error?e.message:typeof e=="string"?e:"Unhandled exception",{body:cf,call:lf,finalizedHeight:uf,genesisHash:df,hashByHeight:hf,header:pf,stopStorage:ff,storage:vf}=os,bf=(e,t,n,r)=>{const s=new Map,o=(a,l,c)=>{const u=Zt();a(u);const h=v=>{r("archive_v1_storageEvent",u,v)},p=Na(e,l,c).pipe(lr(()=>{s.delete(u)})).subscribe(v=>{v.forEach(d=>h({event:"storage",...d}))},v=>{h({event:"storageError",error:yn(v)})},()=>{h({event:"storageDone"})});p.closed||s.set(u,p)},i=(a,l,c)=>{const u=f=>{t(a,f)},h=f=>{f.subscribe({next:u,error:b=>{n(a,b.code??-1,yn(b))}})},[p,v,d]=c;switch(l){case cf:return h(e.getBody(p).pipe(x(({block:f})=>f.extrinsics)));case lf:return h(e.runtimeCall(p,v,d).pipe(x(f=>({success:!0,value:f}))));case uf:return h(e.subscribeBlocks().finalized$.pipe(x(f=>f.number),te(1)));case df:return h(e.genesisHash);case hf:return h(e.getBlockHash$(p).pipe(x(f=>[f])));case pf:return h(e.subscribeBlocks().getHeader$(p).pipe(x(f=>f.header)));case ff:{const f=s.get(p);return f?f.unsubscribe():n(a,-32602,"Invalid args")}case vf:return ja(v)?o(u,p,v):n(a,-32602,"Invalid args")}throw null};return i.stop=()=>{[...s].forEach(([,a])=>a.unsubscribe()),s.clear()},i},mf=(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:yf,broadcast:gf}=is,wf=(e,t)=>{const n=new Map,r=(s,o,i)=>{if(o===yf){const[a]=i;n.get(a)?.unsubscribe(),n.delete(a),t(s,null)}else if(o===gf){const a=Zt();n.set(a,e.obsRequest("author_submitExtrinsic",i).pipe(oe((l,c)=>ct(kn(5e3),c)),dr(e.subscribeBlocks().finalized$.pipe(xn(),oe(()=>(n.delete(a),[null]))))).subscribe()),t(s,a)}else throw null};return r.stop=()=>{n.forEach(s=>s.unsubscribe()),n.clear()},r},{follow:$f,header:Ef,storage:Va,body:cs,call:Pa,unfollow:kf,stopOperation:xf,unpin:Sf}=st,If=(e,t,n,r)=>{const s=new Map,o=d=>{if(s.size===2)return n(d,-32800,"Limit reached");const f=Zt(),b=E=>r("chainHead_v1_followEvent",f,E),y=e.subscribeBlocks().getBlocks(f),m=new Map;s.set(f,{id:f,up:y,operations:m,cleanUp:()=>{$()}}),t(d,f);let g=null,$=()=>{$=V,g?.unsubscribe(),g=null,m.forEach(E=>{E()}),m.clear(),s.delete(f)};g=y.blocks$.subscribe({next(E){b(E)},error(){$(),b({event:"stop"})}}),g.closed&&(g=null)},i=(d,f)=>{s.get(f)?.cleanUp(),t(d,"null")},a=(d,f,b)=>{const y=s.get(f)?.operations.get(b);y&&y(),t(d,"null")},l=({up:{getHeader:d}},f,b)=>f(d(b)),c=({up:{unpin:d}},f,b)=>{(typeof b=="string"?[b]:b).forEach(d),f(null)},u=({operations:d,id:f},b,y,m,g)=>{const $=Zt();b({result:"started",operationId:$});const E=(k,S=!1)=>r(Pa,f,S?{operationId:$,event:"operationError",error:k}:{operationId:$,event:"operationCallDone",output:k}),w=e.runtimeCall(y,m,g).subscribe(k=>{d.delete($),E(k)},k=>{d.delete($),E(yn(k),!0)});w.closed||d.set($,()=>{w.unsubscribe(),d.delete($)})},h=({operations:d,id:f},b,y)=>{const m=Zt();b({result:"started",operationId:m});const g=e.getBody(y).subscribe(({block:{extrinsics:$}})=>{d.delete(m),r(cs,f,{event:"operationBodyDone",operationId:m,value:$})},$=>{d.delete(m),r(cs,f,{event:"operationError",operationId:m,error:yn($)})});g.closed||d.set(m,()=>{g.unsubscribe(),d.delete(m)})},p=({operations:d,id:f},b,y,m)=>{const g=Zt();b({result:"started",operationId:g});const $=w=>{r(Va,f,w)},E=Na(e,y,m).pipe(lr(()=>{d.delete(g)})).subscribe(w=>{$({event:"operationStorageItems",operationId:g,items:w})},w=>{$({event:"operationError",operationId:g,error:yn(w)})},()=>{$({event:"operationStorageDone",operationId:g})});E.closed||d.set(g,()=>{E.unsubscribe()})},v=(d,f,b)=>{if(f===$f)return o(d);const[y,...m]=b,g=s.get(y);if(!g)return console.log("Invalid followSubscription",d,f,b),n(d,-32602,"Ivalid followSubscription");const $=E=>{t(d,E)};switch(f){case kf:return i(d,y);case xf:return a(d,y,m[0]);case Sf:{const[E]=m;return(Array.isArray(E)?E:[E]).some(w=>typeof w!="string")?n(d,-32602,"Invalid args"):c(g,$,E)}default:{const[E,...w]=m;if(!g.up.isPinned(E))return n(d,-32801,"Block not pinned");switch(f){case Ef:return l(g,$,E);case cs:return h(g,$,E);case Pa:{const[k,S]=w;return typeof k!="string"||typeof S!="string"?n(d,-32602,"Invalid args"):u(g,$,E,k,S)}case Va:{const[k]=w;return ja(k)?p(g,$,E,k):n(d,-32602,"Invalid args")}}}}throw null};return v.stop=()=>{s.forEach(d=>{d.cleanUp()})},v},Fa=new Set([st,za,os,is].map(e=>Object.values(e)).flat()),Bf=e=>(t,n)=>{let r=V,s=V;const o=e(b=>{s(b)},b=>{r(),n(b)}),{disconnect:i,request:a}=fr(b=>(s=b,o),t),l=sf(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}})},v={chainSpec:()=>mf(l,u,h),chainHead:()=>If(l,u,h,p),archive:()=>bf(l,u,h,p),transaction:()=>wf(l,u)},d={},f=b=>b in d?d[b]:b in v?d[b]=v[b]():null;return r=()=>{d.chainHead?.stop(),d.archive?.stop(),d.transaction?.stop(),l.clean()},{send:b=>{if(!b)return;const{id:y,method:m,params:g}=b;if(y!==null&&typeof y!="string"&&typeof y!="number"||typeof m!="string"){console.warn(`Invalid message:
4
+ ${JSON.stringify(b)}`);return}if(m==="rpc_methods")return l.methods.subscribe(({methods:w})=>{u(y,{methods:[...Fa,...w.filter(k=>!Fa.has(k))]})},w=>{console.error(w),h(y,-32602,"Invalid")});const[$]=m.split("_"),E=f($);if(E)try{return E(y,m,g)}catch(w){if(w!==null)throw w}l.request(m,g,w=>{u(y,w)},w=>{h(y,w?.code||-1,w?.message||"")})},disconnect:()=>{r(),i()}}},{follow:Af,unfollow:Of}=st,Wa=()=>({latest:Date.now(),count:0}),Cf=e=>(t,n)=>{const r=new Map,s=new Map,o=new Set;let i=Wa();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:v}=h;if(s.get(p)){s.delete(p);const d=r.get(v);if(d){r.delete(v),t(h),t(d);return}o.add(v);const f=o.size+s.size;if(f>2)console.warn(`Too many chainHead follow subscriptions (${f})`);else if(h.error){console.warn(`chainHead follow failed on the ${f} sub`),l();return}}}else{const{subscription:p,result:v}=h.params;if(v?.event==="stop"){const d=Date.now()-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=Wa(),l())},h=>{a(),n(h)});return{send(h){const{method:p}=h;p===Af?s.set(h.id,h):p===Of&&o.delete(h.params[0]),c(h)},disconnect:u}},{follow:_f,unpin:Rf,unfollow:Tf}=st,Hf=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 v=c.params.result,{event:d}=v;if(d==="initialized"&&v.finalizedBlockHashes.forEach(f=>{h.add(f)}),d==="newBlock"){const{parentBlockHash:f}=v;if(!h.has(f)){const m=p.get(f)??[];m.push(c),p.set(f,m);return}const b=v.blockHash;h.add(v.blockHash),t(c);const y=p.get(b);y&&(p.delete(b),y.forEach(m=>{h.add(m.params.result.blockHash),t(m)}));return}d==="stop"&&(h.delete(u),o.delete(u))}t(c)}},i(n));return{send:c=>{const u=c.params[0];switch(c.method){case _f:r.add(c.id);break;case Rf:const[h,p]=c.params;p.forEach(v=>{s.get(h)?.delete(v),o.get(h)?.delete(v)});break;case Tf:s.delete(u),o.delete(u);break}a(c)},disconnect:i(l)}},{follow:Mf,unpin:Uf,unfollow:zf}=st,Df=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 v=c.params.result,{event:d}=v;if(d==="initialized"&&v.finalizedBlockHashes.forEach(f=>{h.add(f)}),d==="finalized"&&(v.prunedBlockHashes=v.prunedBlockHashes.filter(f=>h.has(f))),d==="newBlock"){h.add(v.blockHash);const f=v.blockHash,b=p.get(f);if(b){p.delete(f),t(c),Promise.resolve().then(()=>{t(b)});return}}if(d==="bestBlockChanged"){const f=v.bestBlockHash;if(!h.has(f)){o.get(u).set(f,c);return}}d==="stop"&&(h.delete(u),o.delete(u))}t(c)}},i(n));return{send:c=>{const u=c.params[0];switch(c.method){case Mf:r.add(c.id);break;case Uf:const[h,p]=c.params;p.forEach(v=>{s.get(h)?.delete(v),o.get(h)?.delete(v)});break;case zf:s.delete(u),o.delete(u);break}a(c)},disconnect:i(l)}},{follow:Lf,body:jf,call:Nf,storage:Vf,unfollow:Pf,stopOperation:Ff}=st,Wf=new Set(["BodyDone","CallDone","StorageDone","Inaccessible","Error"].map(e=>"operation"+e)),qa=e=>Wf.has(e.params?.result?.event),qf=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 v=s.get(h);if(v!==void 0){s.delete(h);const d=u.result?.operationId;if(d!==void 0&&o.has(v)){const f=o.get(v);f.add(d);const b=i.get(v)?.get(d);b&&(b.forEach(t),i.get(v).delete(d),qa(b.at(-1))&&f.delete(d))}}}else{const{subscription:h,result:p}=u.params,v=o.get(h);if(v){const{operationId:d}=u.params.result;if(d!==void 0)if(v.has(d))qa(u)&&v.delete(d);else{const f=i.get(h),b=f.get(d)??[];b.push(u),f.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 Lf:r.add(u.id);break;case jf:case Nf:case Vf:s.set(u.id,h);break;case Pf:o.delete(h),i.delete(h);break;case Ff:o.get(h)?.delete(u.params[1])}l(u)},disconnect:a(c)}},Kf=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),Xf=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}},ls=(...e)=>t=>e.reduce((n,r)=>r(n),t),Ka=e=>({jsonrpc:"2.0",...e}),Gf=(e,t,n,r={})=>Ka({method:"chainHead_v1_followEvent",params:{subscription:e,result:{event:t,operationId:n,...r}}}),Yf=new Set(["newBlock","bestBlockChanged","stop"]),Qf=ls(qf,Xf,Kf,Hf,Df,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 v=setTimeout(()=>{s.delete(c),t(Gf(c,"bestBlockChanged",void 0,{bestBlockHash:h.finalizedBlockHashes.at(-1)}))},500);s.set(c,()=>{s.delete(c),clearTimeout(v)})}else Yf.has(p)&&u()}}t(l)},o(n));return{send(l){switch(l.method){case st.follow:r.add(l.id);break;case st.unfollow:s.get(l.params[0])?.()}i(l)},disconnect:o(a)}},Cf),Xa=["chainHead","transaction","chainSpec","archive"].map(e=>`${e}_v1`),Jf=e=>{const t=Object.fromEntries(Xa.map(n=>[n,!!e.find(r=>r.startsWith(n))]));return n=>{const r=Zf(n),s=Qf(r()),o=Bf(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 Xa)if(u.method.startsWith(h)){t[h]?l.send(u):c.send(u);return}l.send(u)},disconnect(){l.disconnect(),c.disconnect()}}}}},Zf=e=>{const t=new ye,n=new ye;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(Be(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,v=n.pipe(Be(d=>d.id===p),te(1)).subscribe(d=>{if(i(d),!v)throw new Error("unreachable");u.delete(v)});u.add(v),s?.send(h)},disconnect(){l.unsubscribe(),c.unsubscribe(),u.forEach(h=>h.unsubscribe()),r--,r===0&&(s?.disconnect(),s=null)}}}},ev=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:v}=fr(d=>(s=d,{...h,disconnect:V}));return l&&(a=e(d=>{a=V,d?({send:i,disconnect:p}=d((f,b)=>(u=y=>{c(),b(y)},s=f,h))(n,r),o.forEach(i),o=[]):u()},v)),{send:d=>{i(d)},disconnect:()=>{c(),p()}}},Ga="rpc_methods",tv=e=>t=>(n,r)=>{const s={methods:e},{send:o,disconnect:i}=t(n,r);return{disconnect:i,send(a){a.id&&a.method===Ga?n(Ka({id:a.id,result:s})):o(a)}}},nv=ls(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=>ev((t,n)=>{let r=0,s=V;const o=()=>{r++,s=n(Ga,[],{onSuccess:({methods:i})=>{t(ls(tv(i),e(i)))},onError:()=>{if(r>3)t(null);else{const i=setTimeout(o,500);s=()=>clearTimeout(i)}}})};return o(),()=>s()}))(Jf));var qe=(e=>(e.CONNECTING="CONNECTING",e.CONNECTED="CONNECTED",e.ERROR="ERROR",e.CLOSE="CLOSE",e))(qe||{}),Ke=(e=>(e.CONNECTING="CONNECTING",e.CONNECTED="CONNECTED",e.TIMEOUT="TIMEOUT",e.STALE="STALE",e.ERROR="ERROR",e.CLOSE="CLOSE",e.DISCONNECT="DISCONNECT",e.IN="IN",e.OUT="OUT",e))(Ke||{});let rv=0;const Ya=()=>`proxyOpaque${rv++}`,er=e=>({jsonrpc:"2.0",...e}),us=e=>({jsonrpc:"2.0",...e}),Qa=()=>`___proxyInternalId__${Ya()}`,sv=e=>{let t={type:1,activeBroadcasts:new Map,pending:[]};const n=s=>{let o=!0;if(t.type===0){if(eo(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(er({id:Qa(),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(us({id:i,result:null})),t.type===0&&h&&h.upToken&&t.connection.send(er({id:i,method:o,params:[h.upToken]}));return}if(c==="broadcast"){const u=Ya();t.activeBroadcasts.set(u,{tx:a[0],synToken:u}),t.type===0&&(t.pendingBroadcasts.set(i,u),t.connection.send(s)),e(us({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(er({method:"chainHead_v1_follow",params:{subscription:h,result:{event:"stop",internal:!0}}}))}),l.clear();for(const h of a.values())h.type===1?n(us({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=Qa();t.pendingBroadcasts.set(h,u.synToken),t.connection.send(er({id:h,method:"transaction_v1_broadcast",params:[u.tx]}))}}),o.forEach(r)}}},ds=()=>{},Ja=250,ov=e=>t=>{let n=sv(t),r=Date.now(),s=0,o;const i=()=>s&&2**Math.min(5,s)*Ja;let a=ds,l=()=>{const u=setTimeout(()=>{let h=!0;const p=e(v=>{h=!1,a=ds,v?n&&n.connect((d,f)=>{let b=!0;return v(d,y=>{if(b){b=!1;const m=Date.now()-r;s+=m>Ja+i()?-s:1,r+=m,f(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=ds,n?.disconnect(),n=null}}},iv=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()}}},av=(e,t,n,r)=>{const s=r?i=>r({type:i}):V,o=r?(i,a)=>r({type:i,msg:a}):V;return iv(i=>{const[a,l]=e();r?.({type:Ke.CONNECTING,url:a.url});let c=()=>{c=V,d(),i(null)},u=!0,h;const p=()=>{clearTimeout(h);const[g,$]=u?[n,Ke.TIMEOUT]:[t,Ke.STALE];u=!1,h=setTimeout(()=>{s($),c({type:qe.ERROR,event:{type:"timeout"}})},g)},v=()=>{clearTimeout(h)};p();let d=()=>{v()};const f=g=>{r?.({type:Ke.ERROR,error:g}),c({type:qe.ERROR,event:g})},b=g=>{s(Ke.CLOSE),c({type:qe.CLOSE,event:g})},y=()=>{s(Ke.DISCONNECT),d();try{a.addEventListener("error",V,{once:!0}),a.close()}catch{}},m=()=>{s(Ke.CONNECTED),l(),p(),a.removeEventListener("open",m),i((g,$)=>{d=()=>{d=V,v(),a.removeEventListener("error",f),a.removeEventListener("ping",p),a.removeEventListener("message",E),a.removeEventListener("close",b)},c=w=>{c=V,d(),$(w)};const E=w=>{p(),typeof w.data=="string"&&(o(Ke.IN,w.data),g(JSON.parse(w.data)))};return a.addEventListener("ping",p),a.addEventListener("message",E),a.addEventListener("error",f),a.addEventListener("close",b),{send(w){const k=JSON.stringify(w);o(Ke.OUT,k),a.send(k)},disconnect:y}})};return d=()=>{d=V,v(),a.removeEventListener("error",f),a.removeEventListener("close",b),a.removeEventListener("open",m)},a.addEventListener("open",m),a.addEventListener("error",f),y})},cv={onStatusChanged:V,timeout:5e3,heartbeatTimeout:4e4,middleware:je},Za=(e,t)=>{const{onStatusChanged:n,timeout:r,heartbeatTimeout:s,middleware:o,logger:i}={...cv,...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:qe.CLOSE,event:null},v;const d=m=>n(p=m),f=o(av(()=>{v=h?.url;const m=u??a[c++%a.length];return u=void 0,d({type:qe.CONNECTING,uri:m}),[h=new l(m),()=>{d({type:qe.CONNECTED,uri:m})}]},s,r,i)),b=(m,g)=>f(m,$=>{d({type:qe.ERROR,event:$}),g($)}),y=ov(m=>{if(!v||h.url!==v)return m(b),V;const g=setTimeout(m,250,b);return()=>{clearTimeout(g)}});return Object.assign(y,{switch:m=>{p.type!==qe.CLOSE&&(u=m,p.type!==qe.ERROR&&h&&h.close())},getStatus:()=>p})},lv=(e,t={})=>Za(e,t),ec=(e,t={})=>Za(e,{...t,middleware:nv}),uv=(e,t={})=>{const n=ec(e,t),r=Gp(n,t);return Object.assign(r,{switch:n.switch,getStatus:n.getStatus})};it.SocketEvents=Ke,it.WsEvent=qe,it.createWsClient=uv,it.getWsProvider=ec,it.getWsRawProvider=lv}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polkadot-api",
3
- "version": "2.0.2-canary.552fbc3",
3
+ "version": "2.0.2",
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.20.3-canary.552fbc3",
117
- "@polkadot-api/ink-contracts": "0.6.2-canary.552fbc3",
118
- "@polkadot-api/known-chains": "0.11.2-canary.552fbc3",
119
- "@polkadot-api/logs-provider": "0.2.1-canary.552fbc3",
120
- "@polkadot-api/metadata-builders": "0.14.2-canary.552fbc3",
121
- "@polkadot-api/json-rpc-provider": "0.2.1-canary.552fbc3",
122
- "@polkadot-api/observable-client": "0.18.5-canary.552fbc3",
123
- "@polkadot-api/pjs-signer": "0.7.2-canary.552fbc3",
124
- "@polkadot-api/metadata-compatibility": "0.6.2-canary.552fbc3",
125
- "@polkadot-api/polkadot-signer": "0.1.7-canary.552fbc3",
126
- "@polkadot-api/signer": "0.3.2-canary.552fbc3",
127
- "@polkadot-api/sm-provider": "0.3.1-canary.552fbc3",
128
- "@polkadot-api/smoldot": "0.4.1-canary.552fbc3",
129
- "@polkadot-api/substrate-bindings": "0.20.2-canary.552fbc3",
130
- "@polkadot-api/substrate-client": "0.7.1-canary.552fbc3",
131
- "@polkadot-api/utils": "0.4.1-canary.552fbc3",
132
- "@polkadot-api/ws-middleware": "0.3.2-canary.552fbc3",
133
- "@polkadot-api/ws-provider": "0.9.1-canary.552fbc3"
116
+ "@polkadot-api/cli": "0.20.3",
117
+ "@polkadot-api/ink-contracts": "0.6.1",
118
+ "@polkadot-api/json-rpc-provider": "0.2.0",
119
+ "@polkadot-api/known-chains": "0.11.2",
120
+ "@polkadot-api/logs-provider": "0.2.0",
121
+ "@polkadot-api/metadata-builders": "0.14.1",
122
+ "@polkadot-api/metadata-compatibility": "0.6.1",
123
+ "@polkadot-api/observable-client": "0.18.4",
124
+ "@polkadot-api/pjs-signer": "0.7.1",
125
+ "@polkadot-api/polkadot-signer": "0.1.6",
126
+ "@polkadot-api/signer": "0.3.1",
127
+ "@polkadot-api/sm-provider": "0.3.0",
128
+ "@polkadot-api/smoldot": "0.4.0",
129
+ "@polkadot-api/utils": "0.4.0",
130
+ "@polkadot-api/ws-middleware": "0.3.2",
131
+ "@polkadot-api/substrate-client": "0.7.0",
132
+ "@polkadot-api/substrate-bindings": "0.20.1",
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.4-canary.552fbc3"
137
+ "@polkadot-api/codegen": "0.22.3"
138
138
  },
139
139
  "scripts": {
140
140
  "build-core": "tsc --noEmit && rollup -c",