gn-provider 1.2.1 → 1.2.3

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.
@@ -5,9 +5,6 @@ declare enum ProviderEvent {
5
5
  Connected = "connected",
6
6
  NetworkChange = "networkChange"
7
7
  }
8
- export type UTXOWithHeight = UTXO & {
9
- height: number;
10
- };
11
8
  export declare class GNProvider extends Provider {
12
9
  emit: (event: ProviderEvent, ...args: any[]) => boolean;
13
10
  private _network;
@@ -24,7 +21,7 @@ export declare class GNProvider extends Provider {
24
21
  protected _ready: () => Promise<void>;
25
22
  sendRawTransaction: (rawTxHex: string) => Promise<TxHash>;
26
23
  sendTransaction: (signedTx: scryptlib.bsv.Transaction) => Promise<string>;
27
- listUnspent: (address: AddressOption, options?: UtxoQueryOptions) => Promise<UTXOWithHeight[]>;
24
+ listUnspent: (address: AddressOption, options?: UtxoQueryOptions) => Promise<UTXO[]>;
28
25
  getBalance: (address: AddressOption) => Promise<{
29
26
  confirmed: number;
30
27
  unconfirmed: number;
@@ -47,11 +47,15 @@ const events_1 = require("events");
47
47
  const scryptlib = __importStar(require("scryptlib"));
48
48
  const abstract_provider_1 = require("scrypt-ts/dist/bsv/abstract-provider");
49
49
  const superagent = __importStar(require("superagent"));
50
+ const utils_1 = require("scrypt-ts/dist/bsv/utils");
50
51
  var ProviderEvent;
51
52
  (function (ProviderEvent) {
52
53
  ProviderEvent["Connected"] = "connected";
53
54
  ProviderEvent["NetworkChange"] = "networkChange";
54
55
  })(ProviderEvent || (ProviderEvent = {}));
56
+ /*export type UTXOWithHeight = UTXO & {
57
+ height: number;
58
+ };*/
55
59
  class GNProvider extends abstract_provider_1.Provider {
56
60
  constructor(network, apiKey = '') {
57
61
  super();
@@ -178,16 +182,20 @@ class GNProvider extends abstract_provider_1.Provider {
178
182
  this.listUnspent = (address, options) => __awaiter(this, void 0, void 0, function* () {
179
183
  yield this._ready();
180
184
  const headers = this._getHeaders();
181
- const res = yield superagent.get(`${this.apiPrefix()}/address/${address}/unspent`)
182
- .set(headers);
183
- return res.body.map((item) => ({
184
- txId: item.tx_hash,
185
- outputIndex: item.tx_pos,
186
- satoshis: item.value,
187
- script: scryptlib.bsv.Script.buildPublicKeyHashOut(address).toHex(),
188
- height: item.height
189
- }));
190
- //return options ? filterUTXO(utxos, options) : utxos;
185
+ try {
186
+ const res = yield superagent.get(`${this.apiPrefix()}/address/${address}/unspent`)
187
+ .set(headers);
188
+ const utxos = res.body.map((item) => ({
189
+ txId: item.tx_hash,
190
+ outputIndex: item.tx_pos,
191
+ satoshis: item.value,
192
+ script: item.script, // ✅ CORRECTO - script real de la blockchain //scryptlib.bsv.Script.buildPublicKeyHashOut(address).toHex(),
193
+ }));
194
+ return options ? (0, utils_1.filterUTXO)(utxos, options) : utxos;
195
+ }
196
+ catch (error) {
197
+ throw new Error(`Failed to list UTXOs for address ${address}: ${error.message}`);
198
+ }
191
199
  });
192
200
  this.getBalance = (address) => __awaiter(this, void 0, void 0, function* () {
193
201
  try {
@@ -209,6 +217,7 @@ class GNProvider extends abstract_provider_1.Provider {
209
217
  }
210
218
  });
211
219
  this.getTransaction = (txHash) => __awaiter(this, void 0, void 0, function* () {
220
+ var _a;
212
221
  yield this._ready();
213
222
  const headers = this._getHeaders();
214
223
  try {
@@ -220,7 +229,10 @@ class GNProvider extends abstract_provider_1.Provider {
220
229
  throw new Error(`Transaction not found: ${txHash}`);
221
230
  }
222
231
  catch (error) {
223
- throw new Error(`Error fetching transaction: ${error.message}`);
232
+ if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
233
+ throw new Error(`Transaction not found: ${txHash}`);
234
+ }
235
+ throw new Error(`Error fetching transaction ${txHash}: ${error.message}`);
224
236
  }
225
237
  });
226
238
  this.needIgnoreError = (inMsg) => {
@@ -228,6 +240,8 @@ class GNProvider extends abstract_provider_1.Provider {
228
240
  return true;
229
241
  if (inMsg.includes('txn-already-known'))
230
242
  return true;
243
+ if (inMsg.includes('Missing inputs'))
244
+ return true;
231
245
  return false;
232
246
  };
233
247
  this.friendlyBIP22RejectionMsg = (inMsg) => {
@@ -243,7 +257,8 @@ class GNProvider extends abstract_provider_1.Provider {
243
257
  'bad-txns-inputs-too-large': 'Transaction inputs too large.',
244
258
  'bad-txns-fee-negative': 'Transaction network fee is negative.',
245
259
  'bad-txns-fee-outofrange': 'Transaction network fee is out of range.',
246
- 'mandatory-script-verify-flag-failed': 'Script evaluation failed.'
260
+ 'mandatory-script-verify-flag-failed': 'Script evaluation failed.',
261
+ 'Missing inputs': 'Transaction inputs are missing or already spent.'
247
262
  };
248
263
  for (const [key, msg] of Object.entries(messages)) {
249
264
  if (inMsg.includes(key))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gn-provider",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "files": [
5
5
  "dist",
6
6
  "scripts",