@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.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +144 -109
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +144 -109
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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 = "
|
|
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
|
-
|
|
223
|
+
// Generic error handling wrapper for RPC calls
|
|
224
|
+
async handleRpcCall(method, params, errorMessage, useProxy = false, allowNull = true) {
|
|
224
225
|
try {
|
|
225
|
-
const
|
|
226
|
-
|
|
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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
amount
|
|
264
|
-
|
|
265
|
-
|
|
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.
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
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.
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
nonce
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
sender:
|
|
321
|
-
nonce
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
transaction
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
}
|