@vleap/warps-adapter-fastset 0.1.0-alpha.16 → 0.1.0-alpha.18

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.mjs CHANGED
@@ -211,7 +211,7 @@ var Wallet = class _Wallet {
211
211
  BigInt.prototype.toJSON = function() {
212
212
  return Number(this);
213
213
  };
214
- var FASTSET_VALIDATOR_URL = "http://157.90.201.117:8765";
214
+ var FASTSET_VALIDATOR_URL = "https://rpc.fastset.xyz";
215
215
  var FASTSET_PROXY_URL = "http://136.243.61.168:44444";
216
216
  var FastsetClient = class {
217
217
  constructor(config) {
@@ -220,56 +220,55 @@ var FastsetClient = class {
220
220
  proxyUrl: FASTSET_PROXY_URL
221
221
  };
222
222
  }
223
- async getAccountInfo(address) {
223
+ // Generic error handling wrapper for RPC calls
224
+ async handleRpcCall(method, params, errorMessage, useProxy = false, allowNull = true) {
224
225
  try {
225
- const addressBytes = Wallet.decodeBech32Address(address);
226
- const response = await this.requestValidator("set_getAccountInfo", {
227
- address: Array.from(addressBytes)
228
- });
226
+ const response = useProxy ? await this.requestProxy(method, params) : await this.requestValidator(method, params);
227
+ console.log(`RPC call to ${method} successful:`, response.result);
229
228
  return response.result;
230
229
  } catch (error) {
230
+ console.error(`${errorMessage}:`, error);
231
+ if (!allowNull) throw error;
231
232
  return null;
232
233
  }
233
234
  }
235
+ async getAccountInfo(address) {
236
+ const addressBytes = Wallet.decodeBech32Address(address);
237
+ return this.handleRpcCall("set_getAccountInfo", [Array.from(addressBytes)], `Failed to get account info for address ${address}`);
238
+ }
234
239
  async getNextNonce(senderAddress) {
235
240
  const accountInfo = await this.getAccountInfo(senderAddress);
236
241
  return accountInfo?.next_nonce ?? 0;
237
242
  }
238
243
  async getAssetBalance(accountId, assetId) {
239
- try {
240
- const response = await this.requestValidator("vsl_getAssetBalance", {
241
- account_id: accountId,
242
- assert_id: assetId
243
- });
244
- return response.result;
245
- } catch (error) {
246
- return null;
247
- }
244
+ return this.handleRpcCall(
245
+ "vsl_getAssetBalance",
246
+ [accountId, assetId],
247
+ `Failed to get asset balance for account ${accountId}, asset ${assetId}`
248
+ );
248
249
  }
249
250
  async getAssetBalances(accountId) {
250
- try {
251
- const response = await this.requestValidator("vsl_getAssetBalances", {
252
- account_id: accountId
253
- });
254
- return response.result;
255
- } catch (error) {
256
- return null;
257
- }
251
+ return this.handleRpcCall("vsl_getAssetBalances", [accountId], `Failed to get asset balances for account ${accountId}`);
258
252
  }
259
253
  async fundFromFaucet(recipientAddress, amount) {
260
254
  const recipientBytes = Wallet.decodeBech32Address(recipientAddress);
261
- const response = await this.requestProxy("faucetDrip", {
262
- recipient: Array.from(recipientBytes),
263
- amount
264
- });
265
- return response.result;
255
+ return this.handleRpcCall(
256
+ "faucetDrip",
257
+ [Array.from(recipientBytes), amount],
258
+ `Failed to fund from faucet for address ${recipientAddress}`,
259
+ true,
260
+ false
261
+ );
266
262
  }
267
263
  async submitTransaction(request) {
268
- const response = await this.requestValidator("set_submitTransaction", {
269
- transaction: request.transaction,
270
- signature: Array.from(request.signature)
271
- });
272
- const result = response.result;
264
+ const response = await this.handleRpcCall(
265
+ "set_submitTransaction",
266
+ [request.transaction, Array.from(request.signature)],
267
+ "Failed to submit transaction",
268
+ false,
269
+ false
270
+ );
271
+ const result = response;
273
272
  return {
274
273
  transaction_hash: new Uint8Array(result.transaction_hash),
275
274
  validator: new Uint8Array(result.validator),
@@ -277,93 +276,105 @@ var FastsetClient = class {
277
276
  };
278
277
  }
279
278
  async submitCertificate(request) {
280
- await this.requestValidator("set_submitTransactionCertificate", {
281
- transaction: request.transaction,
282
- signature: Array.from(request.signature),
283
- validator_signatures: request.validator_signatures.map(([validator, signature]) => [Array.from(validator), Array.from(signature)])
284
- });
279
+ await this.handleRpcCall(
280
+ "set_submitTransactionCertificate",
281
+ [
282
+ request.transaction,
283
+ Array.from(request.signature),
284
+ request.validator_signatures.map(([validator, signature]) => [Array.from(validator), Array.from(signature)])
285
+ ],
286
+ "Failed to submit certificate",
287
+ false,
288
+ false
289
+ );
285
290
  }
286
291
  async executeTransfer(senderPrivateKey, recipient, amount, userData) {
287
- const senderPublicKey = await getPublicKey(senderPrivateKey);
288
- const senderAddress = Wallet.encodeBech32Address(senderPublicKey);
289
- const nonce = await this.getNextNonce(senderAddress);
290
- const recipientBytes = Wallet.decodeBech32Address(recipient);
291
- const transaction = {
292
- sender: senderPublicKey,
293
- nonce,
294
- timestamp_nanos: BigInt(Date.now()) * 1000000n,
295
- claim: {
296
- Transfer: {
297
- recipient: { FastSet: recipientBytes },
298
- amount,
299
- user_data: userData ?? null
292
+ try {
293
+ console.log(`Executing transfer from sender to ${recipient} for amount ${amount}`);
294
+ const senderPublicKey = getPublicKey(senderPrivateKey);
295
+ const senderAddress = Wallet.encodeBech32Address(senderPublicKey);
296
+ console.log(`Sender address: ${senderAddress}`);
297
+ const nonce = await this.getNextNonce(senderAddress);
298
+ console.log(`Using nonce: ${nonce}`);
299
+ const recipientBytes = Wallet.decodeBech32Address(recipient);
300
+ console.log(`Recipient decoded successfully`);
301
+ const transaction = {
302
+ sender: senderPublicKey,
303
+ nonce,
304
+ timestamp_nanos: BigInt(Date.now()) * 1000000n,
305
+ claim: {
306
+ Transfer: {
307
+ recipient: { FastSet: recipientBytes },
308
+ amount,
309
+ user_data: userData ?? null
310
+ }
300
311
  }
301
- }
302
- };
303
- const signature = await this.signTransaction(transaction, senderPrivateKey);
304
- const submitResponse = await this.submitTransaction({
305
- transaction,
306
- signature
307
- });
308
- await this.submitCertificate({
309
- transaction,
310
- signature,
311
- validator_signatures: [[submitResponse.validator, submitResponse.signature]]
312
- });
313
- return submitResponse.transaction_hash;
312
+ };
313
+ console.log("Signing transaction...");
314
+ const signature = await this.signTransaction(transaction, senderPrivateKey);
315
+ console.log("Submitting transaction...");
316
+ const submitResponse = await this.submitTransaction({
317
+ transaction,
318
+ signature
319
+ });
320
+ console.log("Submitting certificate...");
321
+ await this.submitCertificate({
322
+ transaction,
323
+ signature,
324
+ validator_signatures: [[submitResponse.validator, submitResponse.signature]]
325
+ });
326
+ console.log(`Transfer executed successfully. Transaction hash: ${submitResponse.transaction_hash}`);
327
+ return submitResponse.transaction_hash;
328
+ } catch (error) {
329
+ console.error(`Failed to execute transfer to ${recipient}:`, error);
330
+ throw error;
331
+ }
314
332
  }
315
333
  async submitClaim(senderPrivateKey, claim) {
316
- const senderPublicKey = await getPublicKey(senderPrivateKey);
317
- const senderAddress = Wallet.encodeBech32Address(senderPublicKey);
318
- const nonce = await this.getNextNonce(senderAddress);
319
- const transaction = {
320
- sender: senderPublicKey,
321
- nonce,
322
- timestamp_nanos: BigInt(Date.now()) * 1000000n,
323
- claim
324
- };
325
- const signature = await this.signTransaction(transaction, senderPrivateKey);
326
- const submitResponse = await this.submitTransaction({
327
- transaction,
328
- signature
329
- });
330
- await this.submitCertificate({
331
- transaction,
332
- signature,
333
- validator_signatures: [[submitResponse.validator, submitResponse.signature]]
334
- });
335
- return submitResponse.transaction_hash;
334
+ try {
335
+ console.log("Submitting claim...");
336
+ const senderPublicKey = await getPublicKey(senderPrivateKey);
337
+ const senderAddress = Wallet.encodeBech32Address(senderPublicKey);
338
+ console.log(`Claim sender address: ${senderAddress}`);
339
+ const nonce = await this.getNextNonce(senderAddress);
340
+ console.log(`Using nonce: ${nonce}`);
341
+ const transaction = {
342
+ sender: senderPublicKey,
343
+ nonce,
344
+ timestamp_nanos: BigInt(Date.now()) * 1000000n,
345
+ claim
346
+ };
347
+ console.log("Signing claim transaction...");
348
+ const signature = await this.signTransaction(transaction, senderPrivateKey);
349
+ console.log("Submitting claim transaction...");
350
+ const submitResponse = await this.submitTransaction({
351
+ transaction,
352
+ signature
353
+ });
354
+ console.log("Submitting claim certificate...");
355
+ await this.submitCertificate({
356
+ transaction,
357
+ signature,
358
+ validator_signatures: [[submitResponse.validator, submitResponse.signature]]
359
+ });
360
+ console.log(`Claim submitted successfully. Transaction hash: ${submitResponse.transaction_hash}`);
361
+ return submitResponse.transaction_hash;
362
+ } catch (error) {
363
+ console.error("Failed to submit claim:", error);
364
+ throw error;
365
+ }
336
366
  }
337
367
  async signTransaction(transaction, privateKey) {
338
368
  return await TransactionSigner.signTransaction(transaction, privateKey);
339
369
  }
340
370
  async getTransactionStatus(txHash) {
341
- try {
342
- const response = await this.requestValidator("set_getTransactionStatus", {
343
- hash: txHash
344
- });
345
- return response.result;
346
- } catch (error) {
347
- return null;
348
- }
371
+ return this.handleRpcCall("set_getTransactionStatus", [txHash], `Failed to get transaction status for hash ${txHash}`);
349
372
  }
350
373
  async getTransactionInfo(txHash) {
351
- try {
352
- const response = await this.requestValidator("set_getTransactionInfo", {
353
- hash: txHash
354
- });
355
- return response.result;
356
- } catch (error) {
357
- return null;
358
- }
374
+ return this.handleRpcCall("set_getTransactionInfo", [txHash], `Failed to get transaction info for hash ${txHash}`);
359
375
  }
360
376
  async getNetworkInfo() {
361
- try {
362
- const response = await this.requestValidator("set_getNetworkInfo", {});
363
- return response.result;
364
- } catch (error) {
365
- return null;
366
- }
377
+ return this.handleRpcCall("set_getNetworkInfo", [], "Failed to get network info");
367
378
  }
368
379
  async requestValidator(method, params) {
369
380
  return this.request(this.config.validatorUrl, method, params);
@@ -373,27 +384,45 @@ var FastsetClient = class {
373
384
  }
374
385
  async request(url, method, params) {
375
386
  try {
387
+ if (params !== null && params !== void 0) {
388
+ if (Array.isArray(params)) {
389
+ for (let i = 0; i < params.length; i++) {
390
+ if (params[i] === void 0) {
391
+ throw new Error(`Parameter at index ${i} is undefined`);
392
+ }
393
+ }
394
+ } else if (typeof params === "object") {
395
+ const paramObj = params;
396
+ for (const [key, value] of Object.entries(paramObj)) {
397
+ if (value === void 0) {
398
+ throw new Error(`Parameter '${key}' is undefined`);
399
+ }
400
+ }
401
+ }
402
+ }
376
403
  const request = {
377
404
  jsonrpc: "2.0",
378
405
  id: 1,
379
406
  method,
380
407
  params
381
408
  };
409
+ console.log(`Making RPC request to ${method} with params:`, params);
382
410
  const response = await fetch(url, {
383
411
  method: "POST",
384
412
  headers: { "Content-Type": "application/json" },
385
413
  body: JSON.stringify(request, this.jsonReplacer)
386
414
  });
387
415
  if (!response.ok) {
388
- throw new Error(`HTTP request failed: ${response.statusText}`);
416
+ throw new Error(`HTTP request failed: ${response.status} ${response.statusText}`);
389
417
  }
390
418
  const jsonResponse = await response.json();
391
419
  if (jsonResponse.error) {
392
- throw new Error(`RPC error: ${jsonResponse.error.message}`);
420
+ throw new Error(`RPC error: ${jsonResponse.error.message} (code: ${jsonResponse.error.code})`);
393
421
  }
422
+ console.log(`RPC request to ${method} successful:`, jsonResponse.result);
394
423
  return jsonResponse;
395
424
  } catch (error) {
396
- console.error(`Fastset RPC request failed: ${error}`);
425
+ console.error(`Fastset RPC request failed for method ${method}:`, error);
397
426
  throw error;
398
427
  }
399
428
  }
@@ -461,6 +490,12 @@ var WarpFastsetDataLoader = class {
461
490
  }
462
491
  return assets;
463
492
  }
493
+ async getAsset(identifier) {
494
+ return null;
495
+ }
496
+ async getAction(identifier, awaitCompleted = false) {
497
+ return null;
498
+ }
464
499
  async getAccountActions(address, options) {
465
500
  return [];
466
501
  }