UNPKG

@kanalabs/solver-lp-sdk

Version:
47 lines (46 loc) 2.2 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.waitForTransactionConfirmation = exports.hexToBytes = void 0; function hexToBytes(hex) { // Remove 0x prefix if present hex = hex.startsWith('0x') ? hex.slice(2) : hex; const bytes = new Uint8Array(hex.length / 2); for (let i = 0; i < hex.length; i += 2) { bytes[i / 2] = parseInt(hex.substr(i, 2), 16); } return bytes; } exports.hexToBytes = hexToBytes; function waitForTransactionConfirmation(provider, txnDigest, maxRetries = 10, retryDelay = 2000) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { ; for (let i = 0; i < maxRetries; i++) { try { const status = yield provider.getTransactionBlock({ digest: txnDigest, options: { showEffects: true }, }); if (((_b = (_a = status.effects) === null || _a === void 0 ? void 0 : _a.status) === null || _b === void 0 ? void 0 : _b.status) === "success") { return status; } } catch (error) { if (i === maxRetries - 1) throw error; } yield new Promise((resolve) => setTimeout(resolve, retryDelay)); } throw new Error(`Transaction ${txnDigest} could not be confirmed after ${maxRetries} attempts.`); }); } exports.waitForTransactionConfirmation = waitForTransactionConfirmation;