@thruputchain/client 0.27.0 → 0.29.0

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.
Files changed (181) hide show
  1. package/README.md +120 -22
  2. package/dist/{actions-DK_XBeVy.cjs → actions-B2gV8Vzr.cjs} +297 -73
  3. package/dist/actions-B2gV8Vzr.cjs.map +1 -0
  4. package/dist/actions-UEYKD22C.js +653 -0
  5. package/dist/actions-UEYKD22C.js.map +1 -0
  6. package/dist/actions.cjs +4 -8
  7. package/dist/actions.d.cts +4 -4
  8. package/dist/actions.d.ts +4 -4
  9. package/dist/actions.js +3 -3
  10. package/dist/{artifact-BM_MVzhL.d.ts → artifact-RIAPVmVX.d.cts} +4 -3
  11. package/dist/artifact-RIAPVmVX.d.cts.map +1 -0
  12. package/dist/{artifact-BM_MVzhL.d.cts → artifact-RIAPVmVX.d.ts} +4 -3
  13. package/dist/artifact-RIAPVmVX.d.ts.map +1 -0
  14. package/dist/{contract-Cu8Qv94_.js → contract-BOlNskwd.js} +235 -87
  15. package/dist/contract-BOlNskwd.js.map +1 -0
  16. package/dist/{contract-DPm2BJTu.cjs → contract-D_vxUudr.cjs} +281 -109
  17. package/dist/contract-D_vxUudr.cjs.map +1 -0
  18. package/dist/contract.cjs +1 -5
  19. package/dist/contract.d.cts +4 -4
  20. package/dist/contract.d.ts +4 -4
  21. package/dist/contract.js +2 -2
  22. package/dist/contracts.cjs +5 -5
  23. package/dist/contracts.d.cts +19 -4
  24. package/dist/contracts.d.cts.map +1 -1
  25. package/dist/contracts.d.ts +19 -4
  26. package/dist/contracts.d.ts.map +1 -1
  27. package/dist/contracts.js +4 -4
  28. package/dist/decimal-BX7abv5J.cjs +171 -0
  29. package/dist/decimal-BX7abv5J.cjs.map +1 -0
  30. package/dist/decimal-CoHOISys.js +124 -0
  31. package/dist/decimal-CoHOISys.js.map +1 -0
  32. package/dist/{dev_wallet-BcvX_xT4.cjs → dev_wallet-BVChhV6j.cjs} +85 -6
  33. package/dist/dev_wallet-BVChhV6j.cjs.map +1 -0
  34. package/dist/{dev_wallet-B5R5JJaw.js → dev_wallet-D9LuPZ-h.js} +84 -5
  35. package/dist/dev_wallet-D9LuPZ-h.js.map +1 -0
  36. package/dist/{execution-C8oQgpO3.d.cts → execution-pSt6k620.d.cts} +23 -50
  37. package/dist/execution-pSt6k620.d.cts.map +1 -0
  38. package/dist/{execution-DsZzqv_C.d.ts → execution-uiuFPV0d.d.ts} +23 -50
  39. package/dist/execution-uiuFPV0d.d.ts.map +1 -0
  40. package/dist/{hex-DIcaALXL.js → hex-B8D-jBgz.js} +2 -2
  41. package/dist/{hex-DIcaALXL.js.map → hex-B8D-jBgz.js.map} +1 -1
  42. package/dist/{hex-DkGpiZ5e.cjs → hex-CSDZ9d6z.cjs} +2 -2
  43. package/dist/{hex-DkGpiZ5e.cjs.map → hex-CSDZ9d6z.cjs.map} +1 -1
  44. package/dist/{index-rrP1HJ2Z.d.cts → index-B1efA-Y_.d.ts} +24 -21
  45. package/dist/index-B1efA-Y_.d.ts.map +1 -0
  46. package/dist/{index-Zaz-e8Sy.d.ts → index-BGmH_Sm7.d.cts} +12 -62
  47. package/dist/index-BGmH_Sm7.d.cts.map +1 -0
  48. package/dist/{index-CHnfHuQo.d.ts → index-BZ5j5P5d.d.ts} +11 -9
  49. package/dist/index-BZ5j5P5d.d.ts.map +1 -0
  50. package/dist/{index-BmQN3jAS.d.cts → index-BfYEEVHm.d.cts} +3 -13
  51. package/dist/index-BfYEEVHm.d.cts.map +1 -0
  52. package/dist/{index-CuzB95QT.d.cts → index-BhOeIyrZ.d.cts} +11 -9
  53. package/dist/index-BhOeIyrZ.d.cts.map +1 -0
  54. package/dist/{index-B5KqSHeL.d.cts → index-BsvYcU_Y.d.cts} +2 -2
  55. package/dist/{index-B5KqSHeL.d.cts.map → index-BsvYcU_Y.d.cts.map} +1 -1
  56. package/dist/{index-hqEnT64w.d.ts → index-Btl_jMCT.d.ts} +3 -13
  57. package/dist/index-Btl_jMCT.d.ts.map +1 -0
  58. package/dist/{index-C3qDR1J5.d.cts → index-CG-q0j9w.d.ts} +12 -62
  59. package/dist/index-CG-q0j9w.d.ts.map +1 -0
  60. package/dist/index-CPtBvHE8.d.ts +145 -0
  61. package/dist/index-CPtBvHE8.d.ts.map +1 -0
  62. package/dist/{index-CKqC9N4o.d.ts → index-DBKsOzCN.d.cts} +24 -21
  63. package/dist/index-DBKsOzCN.d.cts.map +1 -0
  64. package/dist/index-Xre-0Jka.d.cts +145 -0
  65. package/dist/index-Xre-0Jka.d.cts.map +1 -0
  66. package/dist/index.cjs +39 -68
  67. package/dist/index.cjs.map +1 -1
  68. package/dist/index.d.cts +12 -17
  69. package/dist/index.d.cts.map +1 -1
  70. package/dist/index.d.ts +12 -17
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +27 -38
  73. package/dist/index.js.map +1 -1
  74. package/dist/provider.cjs +3 -3
  75. package/dist/provider.cjs.map +1 -1
  76. package/dist/provider.d.cts +2 -1
  77. package/dist/provider.d.ts +2 -1
  78. package/dist/provider.js +3 -3
  79. package/dist/provider.js.map +1 -1
  80. package/dist/{codec-BOjoJjC5.js → readError-B3Rz7rgs.js} +673 -56
  81. package/dist/readError-B3Rz7rgs.js.map +1 -0
  82. package/dist/{codec-C4LJ0g8v.cjs → readError-COcEDNoZ.cjs} +677 -96
  83. package/dist/readError-COcEDNoZ.cjs.map +1 -0
  84. package/dist/requestAirdrop-DBCOST2B.d.ts +1818 -0
  85. package/dist/requestAirdrop-DBCOST2B.d.ts.map +1 -0
  86. package/dist/requestAirdrop-T1eVn3l5.d.cts +1818 -0
  87. package/dist/requestAirdrop-T1eVn3l5.d.cts.map +1 -0
  88. package/dist/sendInvocation-185ZJrta.cjs +583 -0
  89. package/dist/sendInvocation-185ZJrta.cjs.map +1 -0
  90. package/dist/sendInvocation-DBaNWhr3.js +439 -0
  91. package/dist/sendInvocation-DBaNWhr3.js.map +1 -0
  92. package/dist/signed-op.cjs +2 -2
  93. package/dist/signed-op.d.cts +2 -2
  94. package/dist/signed-op.d.ts +1 -1
  95. package/dist/signed-op.js +2 -2
  96. package/dist/{signedOp-BDUZhfJn.cjs → signedOp-CVyeJ5ig.cjs} +3 -3
  97. package/dist/{signedOp-BDUZhfJn.cjs.map → signedOp-CVyeJ5ig.cjs.map} +1 -1
  98. package/dist/{signedOp-Kx8u8_3I.js → signedOp-D6WYZG9j.js} +3 -3
  99. package/dist/{signedOp-Kx8u8_3I.js.map → signedOp-D6WYZG9j.js.map} +1 -1
  100. package/dist/{signed_op-CAcYYRm6.cjs → signed_op-BBsDKOlD.cjs} +4 -4
  101. package/dist/{signed_op-CAcYYRm6.cjs.map → signed_op-BBsDKOlD.cjs.map} +1 -1
  102. package/dist/{signed_op-BrLxDrDb.d.cts → signed_op-BvbOHWKK.d.ts} +3 -3
  103. package/dist/{signed_op-DbRq3_Hb.d.ts.map → signed_op-BvbOHWKK.d.ts.map} +1 -1
  104. package/dist/{signed_op-DbRq3_Hb.d.ts → signed_op-DoHFpSH4.d.cts} +3 -3
  105. package/dist/{signed_op-BrLxDrDb.d.cts.map → signed_op-DoHFpSH4.d.cts.map} +1 -1
  106. package/dist/{signed_op-Dxn7-lRu.js → signed_op-h9X9-vBL.js} +3 -3
  107. package/dist/{signed_op-Dxn7-lRu.js.map → signed_op-h9X9-vBL.js.map} +1 -1
  108. package/dist/transport-BhWZxHcz.cjs +528 -0
  109. package/dist/transport-BhWZxHcz.cjs.map +1 -0
  110. package/dist/transport-EyDYuibb.js +504 -0
  111. package/dist/transport-EyDYuibb.js.map +1 -0
  112. package/dist/transport.cjs +6 -13
  113. package/dist/transport.d.cts +3 -3
  114. package/dist/transport.d.ts +3 -3
  115. package/dist/transport.js +4 -4
  116. package/dist/types-VYjJcTip.d.cts +161 -0
  117. package/dist/types-VYjJcTip.d.cts.map +1 -0
  118. package/dist/types-VYjJcTip.d.ts +161 -0
  119. package/dist/types-VYjJcTip.d.ts.map +1 -0
  120. package/dist/{validation-eXATmgO0.js → validation-BLQ64Dfh.js} +3 -3
  121. package/dist/validation-BLQ64Dfh.js.map +1 -0
  122. package/dist/{validation-4w-vDGAi.cjs → validation-CZqtmMLJ.cjs} +3 -3
  123. package/dist/validation-CZqtmMLJ.cjs.map +1 -0
  124. package/dist/{wallet-5wt9wLG3.js → wallet-NlZiI4-3.js} +161 -77
  125. package/dist/wallet-NlZiI4-3.js.map +1 -0
  126. package/dist/{wallet-Blh7oas7.cjs → wallet-UvyXtxh5.cjs} +161 -77
  127. package/dist/wallet-UvyXtxh5.cjs.map +1 -0
  128. package/dist/wallet.cjs +2 -8
  129. package/dist/wallet.d.cts +4 -3
  130. package/dist/wallet.d.ts +4 -3
  131. package/dist/wallet.js +3 -3
  132. package/package.json +2 -2
  133. package/dist/actions-1LmkZcfS.js +0 -430
  134. package/dist/actions-1LmkZcfS.js.map +0 -1
  135. package/dist/actions-DK_XBeVy.cjs.map +0 -1
  136. package/dist/artifact-BM_MVzhL.d.cts.map +0 -1
  137. package/dist/artifact-BM_MVzhL.d.ts.map +0 -1
  138. package/dist/client-DocSdzOL.d.cts +0 -790
  139. package/dist/client-DocSdzOL.d.cts.map +0 -1
  140. package/dist/client-DocSdzOL.d.ts +0 -790
  141. package/dist/client-DocSdzOL.d.ts.map +0 -1
  142. package/dist/codec-BOjoJjC5.js.map +0 -1
  143. package/dist/codec-C4LJ0g8v.cjs.map +0 -1
  144. package/dist/contract-Cu8Qv94_.js.map +0 -1
  145. package/dist/contract-DPm2BJTu.cjs.map +0 -1
  146. package/dist/dev_wallet-B5R5JJaw.js.map +0 -1
  147. package/dist/dev_wallet-BcvX_xT4.cjs.map +0 -1
  148. package/dist/execution-C8oQgpO3.d.cts.map +0 -1
  149. package/dist/execution-DsZzqv_C.d.ts.map +0 -1
  150. package/dist/index-BmQN3jAS.d.cts.map +0 -1
  151. package/dist/index-C3qDR1J5.d.cts.map +0 -1
  152. package/dist/index-CHnfHuQo.d.ts.map +0 -1
  153. package/dist/index-CIHK7Ew9.d.cts +0 -303
  154. package/dist/index-CIHK7Ew9.d.cts.map +0 -1
  155. package/dist/index-CIHK7Ew9.d.ts +0 -303
  156. package/dist/index-CIHK7Ew9.d.ts.map +0 -1
  157. package/dist/index-CKqC9N4o.d.ts.map +0 -1
  158. package/dist/index-CuzB95QT.d.cts.map +0 -1
  159. package/dist/index-Zaz-e8Sy.d.ts.map +0 -1
  160. package/dist/index-hqEnT64w.d.ts.map +0 -1
  161. package/dist/index-rrP1HJ2Z.d.cts.map +0 -1
  162. package/dist/readError-Cz3bveZa.cjs +0 -622
  163. package/dist/readError-Cz3bveZa.cjs.map +0 -1
  164. package/dist/readError-Z5zuylri.js +0 -569
  165. package/dist/readError-Z5zuylri.js.map +0 -1
  166. package/dist/readViews-BvMHbiaF.d.ts +0 -609
  167. package/dist/readViews-BvMHbiaF.d.ts.map +0 -1
  168. package/dist/readViews-CQOY5v4o.d.cts +0 -609
  169. package/dist/readViews-CQOY5v4o.d.cts.map +0 -1
  170. package/dist/sendInvocation-8TEMrJ_M.cjs +0 -661
  171. package/dist/sendInvocation-8TEMrJ_M.cjs.map +0 -1
  172. package/dist/sendInvocation-CkeMyLk1.js +0 -505
  173. package/dist/sendInvocation-CkeMyLk1.js.map +0 -1
  174. package/dist/transport-DqlfAsuH.cjs +0 -279
  175. package/dist/transport-DqlfAsuH.cjs.map +0 -1
  176. package/dist/transport-PstrCcBv.js +0 -261
  177. package/dist/transport-PstrCcBv.js.map +0 -1
  178. package/dist/validation-4w-vDGAi.cjs.map +0 -1
  179. package/dist/validation-eXATmgO0.js.map +0 -1
  180. package/dist/wallet-5wt9wLG3.js.map +0 -1
  181. package/dist/wallet-Blh7oas7.cjs.map +0 -1
@@ -1,10 +1,105 @@
1
- const require_codec = require("./codec-C4LJ0g8v.cjs");
2
- const require_hex = require("./hex-DkGpiZ5e.cjs");
1
+ const require_decimal = require("./decimal-BX7abv5J.cjs");
2
+ const require_hex = require("./hex-CSDZ9d6z.cjs");
3
3
  let _thruputchain_protocol = require("@thruputchain/protocol");
4
4
  let _noble_hashes_sha2_js = require("@noble/hashes/sha2.js");
5
5
  let _thruputchain_xdr = require("@thruputchain/xdr");
6
6
  let _thruputchain_contract_spec = require("@thruputchain/contract-spec");
7
7
  let _thruputchain_protocol_utils = require("@thruputchain/protocol/utils");
8
+ //#region src/errors/transaction.ts
9
+ /** Every {@link TransactionOutcome}, for example to validate stored values. */
10
+ const transactionOutcomes = Object.freeze([
11
+ "succeeded",
12
+ "failed",
13
+ "notSubmitted",
14
+ "unknown"
15
+ ]);
16
+ /** Every {@link TransactionReason}, for example to validate stored values. */
17
+ const transactionReasons = Object.freeze([
18
+ "aborted",
19
+ "faulted",
20
+ "executionFailed",
21
+ "resultUndecodable",
22
+ "resultUnavailable",
23
+ "cancelled",
24
+ "timeout",
25
+ "persistenceFailed",
26
+ "notDispatched",
27
+ "requestInvalid",
28
+ "nodeRejected",
29
+ "submissionFailed",
30
+ "disconnected",
31
+ "statusUnknown",
32
+ "recentFailure",
33
+ "networkChanged",
34
+ "commitmentConflict",
35
+ "observationFailed",
36
+ "admissionUnsupported",
37
+ "outcomeUnsupported"
38
+ ]);
39
+ /** Reason for each known failed execution result. */
40
+ const failedResults = {
41
+ abort: "aborted",
42
+ fault: "faulted",
43
+ nonDeterministicError: "executionFailed",
44
+ failedGasSponsorship: "executionFailed",
45
+ other: "executionFailed"
46
+ };
47
+ /**
48
+ * Facts from a committed receipt. A successful execution uses
49
+ * `successReason`, because the error is about a later step.
50
+ * @internal
51
+ */
52
+ function receiptFacts(receipt, successReason, submission) {
53
+ const { execution } = receipt;
54
+ const result = require_decimal.isUnsupportedRpcValue(execution) ? void 0 : execution.result;
55
+ const [outcome, reason] = result === "return" ? ["succeeded", successReason] : result !== void 0 && Object.hasOwn(failedResults, result) ? ["failed", failedResults[result]] : ["unknown", "outcomeUnsupported"];
56
+ return {
57
+ hash: receipt.transactionHash,
58
+ outcome,
59
+ reason,
60
+ receipt,
61
+ ...submission ? { submission } : {}
62
+ };
63
+ }
64
+ /**
65
+ * Execution succeeded, but its return data did not decode.
66
+ * @internal
67
+ */
68
+ function transactionResultUndecodable(receipt, cause, submission) {
69
+ return new require_decimal.ThruputError("transactionResultUndecodable", `Transaction ${(0, _thruputchain_protocol_utils.toBase58)(receipt.transactionHash)} committed, but result decoding failed`, {
70
+ cause,
71
+ transaction: receiptFacts(receipt, "resultUndecodable", submission)
72
+ });
73
+ }
74
+ /**
75
+ * Add transaction facts to a `ThruputError` that has none, keeping its code.
76
+ * An error with facts for another transaction, for example an abort reason, is
77
+ * wrapped instead, so its facts never describe this transaction.
78
+ * @internal
79
+ */
80
+ function withTransactionFacts(error, transaction) {
81
+ if (!require_decimal.isThruputError(error)) return error;
82
+ if (error.transaction) {
83
+ if (bytesEqual$1(error.transaction.hash, transaction.hash)) return error;
84
+ const notSubmitted = transaction.outcome === "notSubmitted";
85
+ return new require_decimal.ThruputError(notSubmitted ? "transactionNotSubmitted" : "transactionOutcomeUnknown", `Could not complete transaction ${(0, _thruputchain_protocol_utils.toBase58)(transaction.hash)}`, {
86
+ cause: error,
87
+ transaction: {
88
+ ...transaction,
89
+ outcome: notSubmitted ? "notSubmitted" : "unknown"
90
+ }
91
+ });
92
+ }
93
+ return new require_decimal.ThruputError(error.code, error.message, {
94
+ context: error.context,
95
+ ...error.cause === void 0 ? {} : { cause: error.cause },
96
+ transaction
97
+ });
98
+ }
99
+ function bytesEqual$1(left, right) {
100
+ return left.length === right.length && left.every((byte, i) => byte === right[i]);
101
+ }
102
+ //#endregion
8
103
  //#region src/contract/spec.ts
9
104
  /**
10
105
  * Lookup key for a named type: every segment of its spec id.
@@ -31,20 +126,18 @@ function formatSpecId(id) {
31
126
  }
32
127
  //#endregion
33
128
  //#region src/contract/errors.ts
34
- /** Error raised when contract bytes do not match their declared ABI type. */
35
- var ContractDecodeError = class extends Error {
36
- constructor(message, options) {
37
- super(message, options);
38
- this.name = "ContractDecodeError";
39
- }
40
- };
41
- /** Retrieved bytes or response metadata failed identity/canonical validation. */
42
- var ContractVerificationError = class extends Error {
43
- constructor(message, options) {
44
- super(message, options);
45
- this.name = "ContractVerificationError";
46
- }
47
- };
129
+ /** Contract bytes do not match their declared ABI type. */
130
+ function contractDecodeFailed(message, options) {
131
+ return new require_decimal.ThruputError("contractDecodeFailed", message, options);
132
+ }
133
+ /** Retrieved bytes or response metadata failed identity or canonical checks. */
134
+ function contractVerificationFailed(message, options) {
135
+ return new require_decimal.ThruputError("contractVerificationFailed", message, options);
136
+ }
137
+ /** Text of an error for a wrapping message. */
138
+ function errorText(cause) {
139
+ return cause instanceof Error ? cause.message : void 0;
140
+ }
48
141
  //#endregion
49
142
  //#region src/contract/valueLimits.ts
50
143
  function contractValueLimits(inputBytes) {
@@ -283,7 +376,8 @@ function decodeCalldata(spec, interfaceName, methodName, data, namedCodecs) {
283
376
  if (r.remaining !== 0) throw new Error(`Trailing data after decoding "${methodName}": ${r.remaining} bytes remaining`);
284
377
  return result;
285
378
  } catch (cause) {
286
- throw new ContractDecodeError(`Failed to decode calldata for "${interfaceName}.${methodName}"${cause instanceof Error ? `: ${cause.message}` : ""}`, { cause });
379
+ const text = errorText(cause);
380
+ throw contractDecodeFailed(`Failed to decode calldata for "${interfaceName}.${methodName}"${text === void 0 ? "" : `: ${text}`}`, { cause });
287
381
  }
288
382
  }
289
383
  function assertOwnArrayElements(value) {
@@ -557,20 +651,28 @@ function decodeComplete(valueCodec, data, label) {
557
651
  if (reader.remaining !== 0) throw new Error(`${reader.remaining} trailing bytes`);
558
652
  return value;
559
653
  } catch (cause) {
560
- if (cause instanceof ContractDecodeError) throw cause;
561
- throw new ContractDecodeError(`Failed to decode ${label}${cause instanceof Error ? `: ${cause.message}` : ""}`, { cause });
654
+ if (require_decimal.isThruputError(cause, "contractDecodeFailed")) throw cause;
655
+ const text = errorText(cause);
656
+ throw contractDecodeFailed(`Failed to decode ${label}${text === void 0 ? "" : `: ${text}`}`, { cause });
562
657
  }
563
658
  }
564
659
  //#endregion
565
660
  //#region src/actions/viewFreshness.ts
566
- /** Reject a successful view that violates the caller's snapshot constraint. */
661
+ /**
662
+ * Reject a successful view that violates the caller's snapshot constraint.
663
+ * A node that cannot serve the floor answers `stateHeightUnavailable`, so a
664
+ * lower height breaks the response contract: code `rpcValueInvalid`.
665
+ */
567
666
  function assertViewFreshness(height, minHeight) {
568
- if (minHeight !== void 0 && height < minHeight) throw new Error(`View response height ${height} is below the requested minimum ${minHeight}`);
667
+ if (minHeight !== void 0 && height < minHeight) throw new require_decimal.ThruputError("rpcValueInvalid", `View response height ${height} is below the requested minimum ${minHeight}`, { context: {
668
+ path: "/result/stateBlockHeight",
669
+ raw: height
670
+ } });
569
671
  }
570
672
  //#endregion
571
673
  //#region src/actions/viewAuthClaim.ts
572
674
  function u32(value, name) {
573
- require_codec.serializeU64(value, name);
675
+ require_decimal.serializeU64(value, name);
574
676
  if (value > 4294967295n) throw new RangeError(`${name} must fit uint32`);
575
677
  return Number(value);
576
678
  }
@@ -585,7 +687,7 @@ function toAssumedAuth(claim) {
585
687
  case _thruputchain_protocol.AuthClaimType.kPubkeySignature: {
586
688
  const { pubkey_hash, nonce } = claim.pubkey_preimage;
587
689
  if (!(pubkey_hash instanceof Uint8Array) || pubkey_hash.length !== 32) throw new TypeError("Assumed pubkey hash must contain 32 bytes");
588
- require_codec.serializeU64(nonce, "accountNonce");
690
+ require_decimal.serializeU64(nonce, "accountNonce");
589
691
  return {
590
692
  kind: "pubkeySignature",
591
693
  pubkeyHash: pubkey_hash.slice(),
@@ -597,26 +699,23 @@ function toAssumedAuth(claim) {
597
699
  }
598
700
  //#endregion
599
701
  //#region src/contract/method.ts
600
- /** Error thrown by the view API for aborts, faults, or unsupported outcomes. */
601
- var ContractViewError = class extends Error {
602
- outcome;
603
- constructor(outcome) {
604
- const selector = outcome.kind === "abort" ? exceptionSelector(outcome.exception) : void 0;
605
- super(outcome.kind === "abort" ? `Contract view aborted with ${formatException(outcome.exception, selector)}` : outcome.kind === "unsupported" ? "Unsupported contract simulation outcome" : "Contract view faulted");
606
- this.name = "ContractViewError";
607
- this.outcome = outcome;
608
- }
609
- };
610
- /** Error thrown when a root contract receipt does not produce a typed return. */
611
- var ContractReceiptError = class extends Error {
612
- outcome;
613
- constructor(outcome) {
614
- const selector = outcome.kind === "abort" ? exceptionSelector(outcome.exception) : void 0;
615
- super(outcome.kind === "abort" ? `Contract transaction ${(0, _thruputchain_protocol_utils.toBase58)(outcome.transactionHash)} aborted with ${formatException(outcome.exception, selector)}` : `Contract transaction ${(0, _thruputchain_protocol_utils.toBase58)(outcome.transactionHash)} did not return a supported successful result`);
616
- this.name = "ContractReceiptError";
617
- this.outcome = outcome;
618
- }
619
- };
702
+ function viewFailed(method, outcome) {
703
+ return new require_decimal.ThruputError("contractViewFailed", outcome.kind === "abort" ? `Contract view aborted with ${formatException(outcome.exception, exceptionSelector(outcome.exception))}` : outcome.kind === "unsupported" ? "Unsupported contract simulation outcome" : "Contract view faulted", { context: {
704
+ method: method.name,
705
+ entrypoint: method.entrypoint,
706
+ outcome
707
+ } });
708
+ }
709
+ function callFailed(method, outcome, receipt) {
710
+ return new require_decimal.ThruputError("contractCallFailed", outcome.kind === "abort" ? `Contract transaction ${(0, _thruputchain_protocol_utils.toBase58)(outcome.transactionHash)} aborted with ${formatException(outcome.exception, exceptionSelector(outcome.exception))}` : `Contract transaction ${(0, _thruputchain_protocol_utils.toBase58)(outcome.transactionHash)} did not return a supported successful result`, {
711
+ context: {
712
+ method: method.name,
713
+ entrypoint: method.entrypoint,
714
+ outcome
715
+ },
716
+ transaction: receiptFacts(receipt, "resultUndecodable")
717
+ });
718
+ }
620
719
  function formatException(exception, selector) {
621
720
  if (exception && typeof exception === "object" && "name" in exception && typeof exception.name === "string" && "value" in exception) {
622
721
  const value = typeof exception.value === "bigint" ? `${exception.value}n` : JSON.stringify(exception.value, (_, v) => typeof v === "bigint" ? `${v}n` : v);
@@ -711,11 +810,12 @@ function defineContractMethodWithExceptions(definition, exceptionBySelector) {
711
810
  try {
712
811
  return [argument.publicName, argument.codec.decode(reader)];
713
812
  } catch (cause) {
714
- const detail = cause instanceof Error ? `: ${cause.message}` : "";
715
- throw new ContractDecodeError(`${name}: argument "${argument.publicName}"${detail}`, { cause });
813
+ const text = errorText(cause);
814
+ const detail = text === void 0 ? "" : `: ${text}`;
815
+ throw contractDecodeFailed(`${name}: argument "${argument.publicName}"${detail}`, { cause });
716
816
  }
717
817
  }));
718
- if (reader.remaining !== 0) throw new ContractDecodeError(`${name}: ${reader.remaining} trailing calldata bytes`);
818
+ if (reader.remaining !== 0) throw contractDecodeFailed(`${name}: ${reader.remaining} trailing calldata bytes`);
719
819
  return argumentCodecs.length === 0 ? void 0 : args;
720
820
  },
721
821
  decodeReturn(data) {
@@ -731,22 +831,38 @@ function defineContractMethodWithExceptions(definition, exceptionBySelector) {
731
831
  events: receipt.events
732
832
  };
733
833
  const execution = receipt.execution;
734
- if (execution instanceof require_codec.UnsupportedRpcValue) return {
834
+ if (require_decimal.isUnsupportedRpcValue(execution)) return {
735
835
  kind: "unsupported",
736
836
  raw: receipt,
737
837
  ...metadata
738
838
  };
739
- if (execution.result === "return") return {
740
- kind: "return",
741
- value: method.decodeReturn(execution.returnData),
742
- ...metadata
743
- };
744
- if (execution.result === "abort") return {
745
- kind: "abort",
746
- exception: method.decodeException(execution.abortData),
747
- abortData: execution.abortData,
748
- ...metadata
749
- };
839
+ if (execution.result === "return") {
840
+ let value;
841
+ try {
842
+ value = method.decodeReturn(execution.returnData);
843
+ } catch (error) {
844
+ throw transactionResultUndecodable(receipt, error);
845
+ }
846
+ return {
847
+ kind: "return",
848
+ value,
849
+ ...metadata
850
+ };
851
+ }
852
+ if (execution.result === "abort") {
853
+ let exception;
854
+ try {
855
+ exception = method.decodeException(execution.abortData);
856
+ } catch (error) {
857
+ throw withTransactionFacts(error, receiptFacts(receipt, "resultUndecodable"));
858
+ }
859
+ return {
860
+ kind: "abort",
861
+ exception,
862
+ abortData: execution.abortData,
863
+ ...metadata
864
+ };
865
+ }
750
866
  return {
751
867
  kind: "failure",
752
868
  execution,
@@ -761,11 +877,11 @@ function defineContractMethodWithExceptions(definition, exceptionBySelector) {
761
877
  blockHeight: outcome.blockHeight,
762
878
  events: outcome.events
763
879
  };
764
- throw new ContractReceiptError(outcome);
880
+ throw callFailed(method, outcome, receipt);
765
881
  },
766
882
  decodeView(response) {
767
883
  const outcome = method.decodeViewOutcome(response);
768
- if (outcome.kind !== "return") throw new ContractViewError(outcome);
884
+ if (outcome.kind !== "return") throw viewFailed(method, outcome);
769
885
  return {
770
886
  value: outcome.value,
771
887
  stateBlockHeight: outcome.stateBlockHeight,
@@ -776,7 +892,7 @@ function defineContractMethodWithExceptions(definition, exceptionBySelector) {
776
892
  async viewOutcome(options) {
777
893
  options.signal?.throwIfAborted();
778
894
  const minStateBlockHeight = options.minStateBlockHeight;
779
- if (minStateBlockHeight !== void 0) require_codec.serializeHeight(minStateBlockHeight);
895
+ if (minStateBlockHeight !== void 0) require_decimal.serializeHeight(minStateBlockHeight);
780
896
  const request = {
781
897
  ...options.assumedAuth === void 0 ? {} : { assumedAuth: toAssumedAuth(options.assumedAuth) },
782
898
  address: options.address,
@@ -790,7 +906,7 @@ function defineContractMethodWithExceptions(definition, exceptionBySelector) {
790
906
  return method.decodeViewOutcome(response);
791
907
  },
792
908
  decodeViewOutcome(response) {
793
- if (response.output instanceof require_codec.UnsupportedRpcValue) return {
909
+ if (require_decimal.isUnsupportedRpcValue(response.output)) return {
794
910
  kind: "unsupported",
795
911
  raw: response,
796
912
  stateBlockHeight: response.stateBlockHeight,
@@ -829,7 +945,21 @@ function defineContractMethodWithExceptions(definition, exceptionBySelector) {
829
945
  gasUsed: outcome.gasUsed,
830
946
  events: outcome.events
831
947
  };
832
- throw new ContractViewError(outcome);
948
+ throw viewFailed(method, outcome);
949
+ },
950
+ decodeError(error) {
951
+ if (!require_decimal.isThruputError(error, "contractViewFailed") && !require_decimal.isThruputError(error, "contractCallFailed")) return void 0;
952
+ const { method: failedName, entrypoint: failed, outcome } = error.context;
953
+ if (failedName !== name || failed.length !== entrypoint.length || failed.some((byte, index) => byte !== entrypoint[index])) return void 0;
954
+ if (outcome.kind !== "abort") return outcome;
955
+ try {
956
+ return {
957
+ ...outcome,
958
+ exception: method.decodeException(outcome.abortData)
959
+ };
960
+ } catch {
961
+ return;
962
+ }
833
963
  }
834
964
  };
835
965
  return method;
@@ -872,7 +1002,8 @@ function decodeException(data, exceptionBySelector) {
872
1002
  ...variant === void 0 ? {} : { variant }
873
1003
  };
874
1004
  } catch (cause) {
875
- throw new ContractDecodeError(`Failed to decode contract exception${cause instanceof Error ? `: ${cause.message}` : ""}`, { cause });
1005
+ const text = errorText(cause);
1006
+ throw contractDecodeFailed(`Failed to decode contract exception${text === void 0 ? "" : `: ${text}`}`, { cause });
876
1007
  }
877
1008
  }
878
1009
  //#endregion
@@ -898,8 +1029,8 @@ function createContractCallDecoder(spec) {
898
1029
  });
899
1030
  for (const method of iface.methods) {
900
1031
  const key = deriveEntrypointID(iface.name, iface.vers, method.name).join(",");
901
- if (methods.has(key)) throw new ContractDecodeError("Duplicate method selector in contract spec");
902
- if (new Set(method.args.map((arg) => arg.name)).size !== method.args.length) throw new ContractDecodeError("Duplicate argument name in contract spec");
1032
+ if (methods.has(key)) throw contractDecodeFailed("Duplicate method selector in contract spec");
1033
+ if (new Set(method.args.map((arg) => arg.name)).size !== method.args.length) throw contractDecodeFailed("Duplicate argument name in contract spec");
903
1034
  const descriptor = defineContractMethodWithExceptions({
904
1035
  interfaceName: iface.name,
905
1036
  interfaceVersion: iface.vers,
@@ -968,7 +1099,7 @@ function createContractEventDecoder(spec) {
968
1099
  const signatures = /* @__PURE__ */ new Set();
969
1100
  const events = spec.events.map((event) => {
970
1101
  const key = event.signature.join(",");
971
- if (signatures.has(key)) throw new ContractDecodeError("Duplicate event signature in contract spec");
1102
+ if (signatures.has(key)) throw contractDecodeFailed("Duplicate event signature in contract spec");
972
1103
  signatures.add(key);
973
1104
  return defineContractEvent({
974
1105
  name: formatSpecId(event.name),
@@ -1053,8 +1184,9 @@ function defineContractEvent(definition) {
1053
1184
  fields: decodedFields
1054
1185
  };
1055
1186
  } catch (cause) {
1056
- if (cause instanceof ContractDecodeError) throw cause;
1057
- throw new ContractDecodeError(`Failed to decode ${eventName}${cause instanceof Error ? `: ${cause.message}` : ""}`, { cause });
1187
+ if (require_decimal.isThruputError(cause, "contractDecodeFailed")) throw cause;
1188
+ const text = errorText(cause);
1189
+ throw contractDecodeFailed(`Failed to decode ${eventName}${text === void 0 ? "" : `: ${text}`}`, { cause });
1058
1190
  }
1059
1191
  },
1060
1192
  filter(input) {
@@ -1160,7 +1292,8 @@ function encodeTopic(topic, value, eventName) {
1160
1292
  topic.codec.encode(writer, value);
1161
1293
  assertScalarRange(topic, value);
1162
1294
  } catch (cause) {
1163
- const detail = cause instanceof Error ? `: ${cause.message}` : "";
1295
+ const text = errorText(cause);
1296
+ const detail = text === void 0 ? "" : `: ${text}`;
1164
1297
  throw new Error(`${eventName} topic "${topic.name}" failed to encode${detail}`, { cause });
1165
1298
  }
1166
1299
  return (0, _thruputchain_xdr.fixedBytes)(writer.finish(), 32);
@@ -1214,16 +1347,16 @@ const contractSpecCodecLimits = {
1214
1347
  * This bounds the generated decoder before it recurses or allocates lists.
1215
1348
  */
1216
1349
  function preflightContractSpec(bytes) {
1217
- if (bytes.length > 16 * 1024 * 1024) throw new ContractDecodeError("Contract spec exceeds byte limit (16777216)");
1350
+ if (bytes.length > 16 * 1024 * 1024) throw contractDecodeFailed("Contract spec exceeds byte limit (16777216)");
1218
1351
  const reader = new _thruputchain_xdr.XdrReader(bytes);
1219
1352
  let work = 1e5;
1220
1353
  const spend = (count) => {
1221
1354
  work -= count;
1222
- if (work < 0) throw new ContractDecodeError("Contract spec exceeds work limit (100000)");
1355
+ if (work < 0) throw contractDecodeFailed("Contract spec exceeds work limit (100000)");
1223
1356
  };
1224
1357
  const list = (item) => {
1225
1358
  const count = Number(reader.readUint32());
1226
- if (count > Math.floor(reader.remaining / 4)) throw new ContractDecodeError("Truncated contract spec collection");
1359
+ if (count > Math.floor(reader.remaining / 4)) throw contractDecodeFailed("Truncated contract spec collection");
1227
1360
  spend(count);
1228
1361
  for (let i = 0; i < count; i++) item();
1229
1362
  };
@@ -1234,7 +1367,7 @@ function preflightContractSpec(bytes) {
1234
1367
  _thruputchain_contract_spec.codec.ContractSpecId.decode(reader);
1235
1368
  };
1236
1369
  const type = (depth = 1) => {
1237
- if (depth > 64) throw new ContractDecodeError("Contract spec exceeds type nesting limit (64)");
1370
+ if (depth > 64) throw contractDecodeFailed("Contract spec exceeds type nesting limit (64)");
1238
1371
  spend(1);
1239
1372
  const kind = Number(reader.readInt32());
1240
1373
  switch (kind) {
@@ -1269,7 +1402,7 @@ function preflightContractSpec(bytes) {
1269
1402
  case _thruputchain_contract_spec.ContractTypeKind.SignedToken:
1270
1403
  if (reader.readBool()) type(depth + 1);
1271
1404
  return;
1272
- default: throw new ContractDecodeError(`Unknown contract spec type ${kind}`);
1405
+ default: throw contractDecodeFailed(`Unknown contract spec type ${kind}`);
1273
1406
  }
1274
1407
  };
1275
1408
  const field = () => {
@@ -1316,11 +1449,11 @@ function preflightContractSpec(bytes) {
1316
1449
  case _thruputchain_contract_spec.ContractUnionCaseKind.UnionCaseStruct:
1317
1450
  list(field);
1318
1451
  break;
1319
- default: throw new ContractDecodeError(`Unknown contract spec union case ${kind}`);
1452
+ default: throw contractDecodeFailed(`Unknown contract spec union case ${kind}`);
1320
1453
  }
1321
1454
  });
1322
1455
  break;
1323
- default: throw new ContractDecodeError(`Unknown contract spec definition ${kind}`);
1456
+ default: throw contractDecodeFailed(`Unknown contract spec definition ${kind}`);
1324
1457
  }
1325
1458
  });
1326
1459
  list(() => {
@@ -1329,26 +1462,39 @@ function preflightContractSpec(bytes) {
1329
1462
  list(field);
1330
1463
  list(field);
1331
1464
  });
1332
- if (reader.remaining !== 0) throw new ContractDecodeError("Trailing contract spec bytes");
1465
+ if (reader.remaining !== 0) throw contractDecodeFailed("Trailing contract spec bytes");
1333
1466
  } catch (cause) {
1334
- if (cause instanceof ContractDecodeError) throw cause;
1335
- throw new ContractDecodeError("Invalid contract spec XDR", { cause });
1467
+ if (require_decimal.isThruputError(cause, "contractDecodeFailed")) throw cause;
1468
+ throw contractDecodeFailed("Invalid contract spec XDR", { cause });
1336
1469
  }
1337
1470
  }
1338
1471
  //#endregion
1339
1472
  //#region src/contract/artifact.ts
1473
+ const v5V6Layout = {
1474
+ headerBytes: 128,
1475
+ codeSizeOffset: 52
1476
+ };
1477
+ const rv32Layouts = new Map([
1478
+ [5, v5V6Layout],
1479
+ [6, v5V6Layout],
1480
+ [7, {
1481
+ headerBytes: 120,
1482
+ codeSizeOffset: 44
1483
+ }]
1484
+ ]);
1340
1485
  /**
1341
1486
  * Verify complete Contract XDR against the requested hash, then read its spec.
1342
1487
  * Rejects malformed known envelopes. Unknown versions remain explicit results.
1343
- * Reads v5 as having no spec. In v6, validates all extension framing and skips
1344
- * unknown kinds. Only the contract-spec extension body is interpreted.
1488
+ * Reads RV32 artifact formats v5, v6 and v7. Reads v5 as having no spec. In v6
1489
+ * and v7, validates all extension framing and skips unknown kinds. Only the
1490
+ * contract-spec extension body is interpreted.
1345
1491
  * This proves byte identity, not deployment, executable validity, or spec truth.
1346
1492
  */
1347
1493
  function readContractArtifactSpec(contractXdr, expectedHash) {
1348
1494
  try {
1349
1495
  return readArtifact(contractXdr, expectedHash);
1350
1496
  } catch (cause) {
1351
- throw new ContractVerificationError(cause instanceof Error ? cause.message : "Invalid contract artifact", { cause });
1497
+ throw contractVerificationFailed(errorText(cause) ?? "Invalid contract artifact", { cause });
1352
1498
  }
1353
1499
  }
1354
1500
  function readArtifact(contractXdr, expectedHash) {
@@ -1365,14 +1511,16 @@ function readArtifact(contractXdr, expectedHash) {
1365
1511
  if (artifact.length < 12 || !bytesEqual(artifact.subarray(0, 8), new TextEncoder().encode("GHRV32A1"))) throw new Error("Invalid RV32 artifact header");
1366
1512
  const header = new DataView(artifact.buffer, artifact.byteOffset, artifact.byteLength);
1367
1513
  const formatVersion = header.getUint32(8, true);
1368
- if (formatVersion !== 5 && formatVersion !== 6) return {
1514
+ const layout = rv32Layouts.get(formatVersion);
1515
+ if (layout === void 0) return {
1369
1516
  kind: "unsupportedFormat",
1370
1517
  formatVersion
1371
1518
  };
1372
- if (artifact.length < 128 || header.getUint32(12, true) !== 128) throw new Error("Invalid RV32 header size");
1373
- const codeSize = header.getUint32(52, true);
1374
- const memorySize = header.getUint32(56, true);
1375
- const sectionsEnd = 128 + codeSize + memorySize;
1519
+ const { headerBytes, codeSizeOffset } = layout;
1520
+ if (artifact.length < headerBytes || header.getUint32(12, true) !== headerBytes) throw new Error("Invalid RV32 header size");
1521
+ const codeSize = header.getUint32(codeSizeOffset, true);
1522
+ const memorySize = header.getUint32(codeSizeOffset + 4, true);
1523
+ const sectionsEnd = headerBytes + codeSize + memorySize;
1376
1524
  if (sectionsEnd > artifact.length) throw new Error("Invalid RV32 section layout");
1377
1525
  if (formatVersion === 5) {
1378
1526
  if (sectionsEnd !== artifact.length) throw new Error("Invalid RV32 v5 section layout");
@@ -1468,40 +1616,28 @@ function getContract(options) {
1468
1616
  }]));
1469
1617
  }
1470
1618
  //#endregion
1471
- Object.defineProperty(exports, "ContractDecodeError", {
1472
- enumerable: true,
1473
- get: function() {
1474
- return ContractDecodeError;
1475
- }
1476
- });
1477
- Object.defineProperty(exports, "ContractReceiptError", {
1478
- enumerable: true,
1479
- get: function() {
1480
- return ContractReceiptError;
1481
- }
1482
- });
1483
- Object.defineProperty(exports, "ContractVerificationError", {
1619
+ Object.defineProperty(exports, "buildNamedCodecs", {
1484
1620
  enumerable: true,
1485
1621
  get: function() {
1486
- return ContractVerificationError;
1622
+ return buildNamedCodecs;
1487
1623
  }
1488
1624
  });
1489
- Object.defineProperty(exports, "ContractViewError", {
1625
+ Object.defineProperty(exports, "bytesEqual", {
1490
1626
  enumerable: true,
1491
1627
  get: function() {
1492
- return ContractViewError;
1628
+ return bytesEqual;
1493
1629
  }
1494
1630
  });
1495
- Object.defineProperty(exports, "buildNamedCodecs", {
1631
+ Object.defineProperty(exports, "contractDecodeFailed", {
1496
1632
  enumerable: true,
1497
1633
  get: function() {
1498
- return buildNamedCodecs;
1634
+ return contractDecodeFailed;
1499
1635
  }
1500
1636
  });
1501
- Object.defineProperty(exports, "bytesEqual", {
1637
+ Object.defineProperty(exports, "contractVerificationFailed", {
1502
1638
  enumerable: true,
1503
1639
  get: function() {
1504
- return bytesEqual;
1640
+ return contractVerificationFailed;
1505
1641
  }
1506
1642
  });
1507
1643
  Object.defineProperty(exports, "createContractCallDecoder", {
@@ -1564,6 +1700,12 @@ Object.defineProperty(exports, "encodeCalldata", {
1564
1700
  return encodeCalldata;
1565
1701
  }
1566
1702
  });
1703
+ Object.defineProperty(exports, "errorText", {
1704
+ enumerable: true,
1705
+ get: function() {
1706
+ return errorText;
1707
+ }
1708
+ });
1567
1709
  Object.defineProperty(exports, "formatSpecId", {
1568
1710
  enumerable: true,
1569
1711
  get: function() {
@@ -1600,6 +1742,12 @@ Object.defineProperty(exports, "readContractArtifactSpec", {
1600
1742
  return readContractArtifactSpec;
1601
1743
  }
1602
1744
  });
1745
+ Object.defineProperty(exports, "receiptFacts", {
1746
+ enumerable: true,
1747
+ get: function() {
1748
+ return receiptFacts;
1749
+ }
1750
+ });
1603
1751
  Object.defineProperty(exports, "resolveCodec", {
1604
1752
  enumerable: true,
1605
1753
  get: function() {
@@ -1624,5 +1772,29 @@ Object.defineProperty(exports, "topicRepresentation", {
1624
1772
  return topicRepresentation;
1625
1773
  }
1626
1774
  });
1775
+ Object.defineProperty(exports, "transactionOutcomes", {
1776
+ enumerable: true,
1777
+ get: function() {
1778
+ return transactionOutcomes;
1779
+ }
1780
+ });
1781
+ Object.defineProperty(exports, "transactionReasons", {
1782
+ enumerable: true,
1783
+ get: function() {
1784
+ return transactionReasons;
1785
+ }
1786
+ });
1787
+ Object.defineProperty(exports, "transactionResultUndecodable", {
1788
+ enumerable: true,
1789
+ get: function() {
1790
+ return transactionResultUndecodable;
1791
+ }
1792
+ });
1793
+ Object.defineProperty(exports, "withTransactionFacts", {
1794
+ enumerable: true,
1795
+ get: function() {
1796
+ return withTransactionFacts;
1797
+ }
1798
+ });
1627
1799
 
1628
- //# sourceMappingURL=contract-DPm2BJTu.cjs.map
1800
+ //# sourceMappingURL=contract-D_vxUudr.cjs.map