@kingdomchain/wallet-client 0.6.0 → 0.6.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.
package/dist/index.d.ts CHANGED
@@ -700,7 +700,9 @@ declare function fetchFeeGrantGranter(restUrl: string, grantee: string): Promise
700
700
 
701
701
  declare class CitizenTxError extends Error {
702
702
  readonly code: CitizenTxErrorCode;
703
- constructor(message: string, code: CitizenTxErrorCode, cause?: unknown);
703
+ /** Raw on-chain log from a failed DeliverTx/indexed tx, when available. */
704
+ readonly rawLog?: string;
705
+ constructor(message: string, code: CitizenTxErrorCode, cause?: unknown, rawLog?: string);
704
706
  }
705
707
  type CitizenTxErrorCode = "INSUFFICIENT_FEE" | "INSUFFICIENT_BALANCE" | "SEQUENCE_MISMATCH" | "TX_FAILED" | "TIMEOUT" | "INVALID_INPUT";
706
708
  interface BroadcastConfirmOptions {
package/dist/index.js CHANGED
@@ -3273,12 +3273,15 @@ async function fetchFeeGrantGranter(restUrl, grantee) {
3273
3273
  }
3274
3274
  }
3275
3275
  var CitizenTxError = class extends Error {
3276
- constructor(message, code, cause) {
3276
+ constructor(message, code, cause, rawLog) {
3277
3277
  super(message, { cause });
3278
3278
  this.code = code;
3279
3279
  this.name = "CitizenTxError";
3280
+ this.rawLog = rawLog;
3280
3281
  }
3281
3282
  code;
3283
+ /** Raw on-chain log from a failed DeliverTx/indexed tx, when available. */
3284
+ rawLog;
3282
3285
  };
3283
3286
  var DEFAULT_GAS = "200000";
3284
3287
  var DEFAULT_FEE_UKDR = "5000";
@@ -3349,13 +3352,33 @@ function citizenTxErrorMessage(code) {
3349
3352
  return "The transaction could not be completed. Please try again.";
3350
3353
  }
3351
3354
  }
3355
+ function withTimeout(promise, ms, label) {
3356
+ let timer;
3357
+ const timeout = new Promise((_, reject) => {
3358
+ timer = setTimeout(
3359
+ () => reject(new Error(`[citizenTx] ${label} did not respond within ${ms}ms`)),
3360
+ ms
3361
+ );
3362
+ });
3363
+ return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
3364
+ }
3352
3365
  async function broadcastAndConfirmTx(client, signerAddress, messages, fee, memo = "", options = {}) {
3353
3366
  const pollIntervalMs = options.pollIntervalMs ?? 1500;
3354
3367
  const timeoutMs = options.timeoutMs ?? 9e4;
3355
3368
  let deliverTx;
3356
3369
  try {
3357
- deliverTx = await client.signAndBroadcast(signerAddress, messages, fee, memo);
3370
+ console.log("[citizenTx] signAndBroadcast: starting", { signerAddress, messages });
3371
+ deliverTx = await withTimeout(
3372
+ client.signAndBroadcast(signerAddress, messages, fee, memo),
3373
+ 2e4,
3374
+ "signAndBroadcast"
3375
+ );
3376
+ console.log("[citizenTx] signAndBroadcast: settled", {
3377
+ code: deliverTx.code,
3378
+ hash: deliverTx.transactionHash
3379
+ });
3358
3380
  } catch (err) {
3381
+ console.error("[citizenTx] broadcast threw or timed out before inclusion:", err);
3359
3382
  const message = err instanceof Error ? err.message : String(err);
3360
3383
  if (message.toLowerCase().includes("insufficient")) {
3361
3384
  throw new CitizenTxError(citizenTxErrorMessage("INSUFFICIENT_FEE"), "INSUFFICIENT_FEE", err);
@@ -3363,17 +3386,26 @@ async function broadcastAndConfirmTx(client, signerAddress, messages, fee, memo
3363
3386
  throw new CitizenTxError(citizenTxErrorMessage("TX_FAILED"), "TX_FAILED", err);
3364
3387
  }
3365
3388
  if (deliverTx.code !== 0) {
3389
+ console.error("[citizenTx] deliverTx failed:", {
3390
+ code: deliverTx.code,
3391
+ rawLog: deliverTx.rawLog
3392
+ });
3366
3393
  const code = classifyBroadcastFailure(deliverTx.rawLog ?? "", deliverTx.code);
3367
- throw new CitizenTxError(citizenTxErrorMessage(code), code);
3394
+ throw new CitizenTxError(citizenTxErrorMessage(code), code, void 0, deliverTx.rawLog ?? "");
3368
3395
  }
3369
3396
  const hash = deliverTx.transactionHash;
3370
3397
  const deadline = Date.now() + timeoutMs;
3371
3398
  while (Date.now() < deadline) {
3372
- const indexed = await client.getTx(hash);
3399
+ console.log("[citizenTx] getTx poll: checking", { hash });
3400
+ const indexed = await withTimeout(client.getTx(hash), 15e3, `getTx(${hash})`);
3373
3401
  if (indexed) {
3374
3402
  if (indexed.code !== 0) {
3403
+ console.error("[citizenTx] indexed tx failed:", {
3404
+ code: indexed.code,
3405
+ rawLog: indexed.rawLog
3406
+ });
3375
3407
  const code = classifyBroadcastFailure(indexed.rawLog ?? "", indexed.code);
3376
- throw new CitizenTxError(citizenTxErrorMessage(code), code);
3408
+ throw new CitizenTxError(citizenTxErrorMessage(code), code, void 0, indexed.rawLog ?? "");
3377
3409
  }
3378
3410
  return {
3379
3411
  hash,