gn-provider 1.1.1 → 1.1.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.
@@ -13,7 +13,7 @@ export declare class GNProvider extends Provider {
13
13
  constructor(network: scryptlib.bsv.Networks.Network, apiKey?: string);
14
14
  get apiPrefix(): string;
15
15
  isConnected(): boolean;
16
- connect(): Promise<this>;
16
+ connect: () => Promise<this>;
17
17
  private _getHeaders;
18
18
  updateNetwork(network: scryptlib.bsv.Networks.Network): void;
19
19
  getNetwork(): scryptlib.bsv.Networks.Network;
@@ -72,24 +72,26 @@ class GNProvider extends abstract_provider_1.Provider {
72
72
  constructor(network, apiKey = '') {
73
73
  super();
74
74
  this._isConnected = false;
75
- // Inicializa propiedades primero
76
- this._network = network;
77
- this._apiKey = apiKey;
78
- this._isConnected = false;
79
- // Configura EventEmitter
80
- Object.setPrototypeOf(this, events_1.EventEmitter.prototype);
81
- // Conexión directa
82
- this.connect().catch(console.error);
83
- }
84
- get apiPrefix() {
85
- const networkStr = this._network.name === scryptlib.bsv.Networks.mainnet.name ? 'main' : 'test';
86
- return `https://api.whatsonchain.com/v1/bsv/${networkStr}`;
87
- }
88
- isConnected() {
89
- return this._isConnected;
90
- }
91
- connect() {
92
- return __awaiter(this, void 0, void 0, function* () {
75
+ /*async connect(): Promise<this> {
76
+ try {
77
+ const headers = this._getHeaders();
78
+ const res = await superagent.get(`${this.apiPrefix}/woc`)
79
+ .timeout(3000)
80
+ .set(headers);
81
+
82
+ if (res.ok && res.text === "Whats On Chain") {
83
+ this._isConnected = true;
84
+ this.emit(ProviderEvent.Connected, true);
85
+ return this;
86
+ }
87
+ throw new Error(res.body?.msg || res.text);
88
+ } catch (error: any) {
89
+ this._isConnected = false;
90
+ this.emit(ProviderEvent.Connected, false);
91
+ throw new Error(`connect failed: ${error.message || "unknown error"}`);
92
+ }
93
+ }*/
94
+ this.connect = () => __awaiter(this, void 0, void 0, function* () {
93
95
  var _a;
94
96
  try {
95
97
  const headers = this._getHeaders();
@@ -109,6 +111,21 @@ class GNProvider extends abstract_provider_1.Provider {
109
111
  throw new Error(`connect failed: ${error.message || "unknown error"}`);
110
112
  }
111
113
  });
114
+ // Inicializa propiedades primero
115
+ this._network = network;
116
+ this._apiKey = apiKey;
117
+ this._isConnected = false;
118
+ // Configura EventEmitter
119
+ Object.setPrototypeOf(this, events_1.EventEmitter.prototype);
120
+ // Conexión directa
121
+ this.connect().catch(console.error);
122
+ }
123
+ get apiPrefix() {
124
+ const networkStr = this._network.name === scryptlib.bsv.Networks.mainnet.name ? 'main' : 'test';
125
+ return `https://api.whatsonchain.com/v1/bsv/${networkStr}`;
126
+ }
127
+ isConnected() {
128
+ return this._isConnected;
112
129
  }
113
130
  _getHeaders() {
114
131
  return Object.assign({ 'Content-Type': 'application/json' }, (this._apiKey ? { 'woc-api-key': this._apiKey } : {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gn-provider",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "files": [
5
5
  "dist",
6
6
  "scripts",