@palliora.org/chainsdk 0.3.0 → 0.3.1

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/dist/index.d.cts CHANGED
@@ -816,8 +816,6 @@ declare function watchForSubmissionReceipt(requestId: string, timeoutMs?: number
816
816
  */
817
817
  declare function getAgreementCreatedRequestId(blockHeight: number, extrinsicIndex: number): Promise<string | null>;
818
818
 
819
- declare const provider: WsProvider;
820
-
821
819
  interface ComputeContract {
822
820
  contract_type: "Active" | "Dormant";
823
821
  guardians: GuardianAddress[];
@@ -1258,6 +1256,7 @@ declare let PALLIORA_WS: string;
1258
1256
  declare let PALLIORA_RPC_URL: string;
1259
1257
  declare let DEBUG: boolean;
1260
1258
  declare let TX_WAIT_FINALIZATION: boolean;
1259
+ declare let provider: WsProvider;
1261
1260
  declare function configure(opts: {
1262
1261
  pallioraWs?: string;
1263
1262
  pallioraRpcUrl?: string;
package/dist/index.d.ts CHANGED
@@ -816,8 +816,6 @@ declare function watchForSubmissionReceipt(requestId: string, timeoutMs?: number
816
816
  */
817
817
  declare function getAgreementCreatedRequestId(blockHeight: number, extrinsicIndex: number): Promise<string | null>;
818
818
 
819
- declare const provider: WsProvider;
820
-
821
819
  interface ComputeContract {
822
820
  contract_type: "Active" | "Dormant";
823
821
  guardians: GuardianAddress[];
@@ -1258,6 +1256,7 @@ declare let PALLIORA_WS: string;
1258
1256
  declare let PALLIORA_RPC_URL: string;
1259
1257
  declare let DEBUG: boolean;
1260
1258
  declare let TX_WAIT_FINALIZATION: boolean;
1259
+ declare let provider: WsProvider;
1261
1260
  declare function configure(opts: {
1262
1261
  pallioraWs?: string;
1263
1262
  pallioraRpcUrl?: string;
package/dist/index.js CHANGED
@@ -756,16 +756,19 @@ function assert(condition, message) {
756
756
  }
757
757
 
758
758
  // src/config.ts
759
+ import { WsProvider } from "@polkadot/api";
759
760
  var env = typeof process !== "undefined" && process.env ? process.env : {};
760
761
  var PALLIORA_WS = env.PALLIORA_WS || "wss://manas-rpc.palliora.org";
761
762
  var PALLIORA_RPC_URL = env.PALLIORA_RPC_URL || "wss://manas-rpc.palliora.org";
762
763
  var DEBUG = env.DEBUG === "true" || false;
763
764
  var TX_WAIT_FINALIZATION = env.TX_WAIT_FINALIZATION === "true" || false;
765
+ var provider = new WsProvider(PALLIORA_WS, 1e4);
764
766
  function configure(opts) {
765
767
  if (opts.pallioraWs !== void 0) PALLIORA_WS = opts.pallioraWs;
766
768
  if (opts.pallioraRpcUrl !== void 0) PALLIORA_RPC_URL = opts.pallioraRpcUrl;
767
769
  if (opts.debug !== void 0) DEBUG = opts.debug;
768
770
  if (opts.txWaitFinalization !== void 0) TX_WAIT_FINALIZATION = opts.txWaitFinalization;
771
+ provider = new WsProvider(PALLIORA_WS, 1e4);
769
772
  }
770
773
 
771
774
  // src/utils/helper.ts
@@ -867,20 +870,24 @@ var tokenToBigint = toAtomicPaliAmount;
867
870
 
868
871
  // src/chain/singleton.ts
869
872
  import { ApiPromise, Keyring as Keyring2 } from "@polkadot/api";
870
-
871
- // src/chain/wsProvider.ts
872
- import { WsProvider } from "@polkadot/api";
873
- var provider = new WsProvider(PALLIORA_WS, 1e4);
874
-
875
- // src/chain/singleton.ts
876
873
  import { waitReady as waitReady2 } from "@polkadot/wasm-crypto";
877
874
  var api = null;
875
+ var apiUrl = null;
878
876
  var keyring = null;
879
877
  var encKeyring = null;
880
878
  var apiListenersAttached = false;
881
879
  var apiTeardownInProgress = false;
882
880
  async function getApi(cb) {
883
881
  if (!provider) return;
882
+ if (api && PALLIORA_WS !== apiUrl) {
883
+ const staleApi = api;
884
+ api = null;
885
+ apiUrl = null;
886
+ apiListenersAttached = false;
887
+ apiTeardownInProgress = false;
888
+ await staleApi.disconnect().catch(() => {
889
+ });
890
+ }
884
891
  if (!api) {
885
892
  api = await ApiPromise.create({
886
893
  provider,
@@ -888,6 +895,7 @@ async function getApi(cb) {
888
895
  types: API_TYPES,
889
896
  signedExtensions: API_EXTENSIONS
890
897
  });
898
+ apiUrl = PALLIORA_WS;
891
899
  }
892
900
  const isNode = typeof process !== "undefined" && typeof process.exit === "function";
893
901
  const isTest = typeof process !== "undefined" && process.env?.NODE_ENV === "test";