@thruputchain/client 0.28.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 +112 -17
  2. package/dist/{actions-B5-CjpEF.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-D77iA2iY.js → contract-BOlNskwd.js} +235 -87
  15. package/dist/contract-BOlNskwd.js.map +1 -0
  16. package/dist/{contract-DSu2UPPm.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-CAbOSrak.cjs → dev_wallet-BVChhV6j.cjs} +85 -6
  33. package/dist/dev_wallet-BVChhV6j.cjs.map +1 -0
  34. package/dist/{dev_wallet-CU3RpQLm.js → dev_wallet-D9LuPZ-h.js} +84 -5
  35. package/dist/dev_wallet-D9LuPZ-h.js.map +1 -0
  36. package/dist/{execution-J5jkXhV1.d.cts → execution-pSt6k620.d.cts} +23 -50
  37. package/dist/execution-pSt6k620.d.cts.map +1 -0
  38. package/dist/{execution-XJ0iwFaX.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-soFVQX9j.d.cts → index-B1efA-Y_.d.ts} +24 -21
  45. package/dist/index-B1efA-Y_.d.ts.map +1 -0
  46. package/dist/{index-C3HVRvQd.d.ts → index-BGmH_Sm7.d.cts} +12 -62
  47. package/dist/index-BGmH_Sm7.d.cts.map +1 -0
  48. package/dist/{index-Bb01ytjJ.d.ts → index-BZ5j5P5d.d.ts} +11 -9
  49. package/dist/index-BZ5j5P5d.d.ts.map +1 -0
  50. package/dist/{index-CedOvhGY.d.cts → index-BfYEEVHm.d.cts} +3 -13
  51. package/dist/index-BfYEEVHm.d.cts.map +1 -0
  52. package/dist/{index-CtjWsAXV.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-DeS1S0m-.d.ts → index-Btl_jMCT.d.ts} +3 -13
  57. package/dist/index-Btl_jMCT.d.ts.map +1 -0
  58. package/dist/{index-CtjZ61tl.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-DfmDUk5Y.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-Bxlt1gKO.js → readError-B3Rz7rgs.js} +359 -56
  81. package/dist/readError-B3Rz7rgs.js.map +1 -0
  82. package/dist/{codec-BcK8ASsg.cjs → readError-COcEDNoZ.cjs} +363 -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-DAucp6xg.cjs → signedOp-CVyeJ5ig.cjs} +3 -3
  97. package/dist/{signedOp-DAucp6xg.cjs.map → signedOp-CVyeJ5ig.cjs.map} +1 -1
  98. package/dist/{signedOp-DpmUpH-e.js → signedOp-D6WYZG9j.js} +3 -3
  99. package/dist/{signedOp-DpmUpH-e.js.map → signedOp-D6WYZG9j.js.map} +1 -1
  100. package/dist/{signed_op-_lR85dn2.cjs → signed_op-BBsDKOlD.cjs} +4 -4
  101. package/dist/{signed_op-_lR85dn2.cjs.map → signed_op-BBsDKOlD.cjs.map} +1 -1
  102. package/dist/{signed_op-D2usgASc.d.cts → signed_op-BvbOHWKK.d.ts} +3 -3
  103. package/dist/{signed_op-zGq4eBo8.d.ts.map → signed_op-BvbOHWKK.d.ts.map} +1 -1
  104. package/dist/{signed_op-zGq4eBo8.d.ts → signed_op-DoHFpSH4.d.cts} +3 -3
  105. package/dist/{signed_op-D2usgASc.d.cts.map → signed_op-DoHFpSH4.d.cts.map} +1 -1
  106. package/dist/{signed_op-CwN-_CXw.js → signed_op-h9X9-vBL.js} +3 -3
  107. package/dist/{signed_op-CwN-_CXw.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-BNKgOXrF.js → wallet-NlZiI4-3.js} +161 -77
  125. package/dist/wallet-NlZiI4-3.js.map +1 -0
  126. package/dist/{wallet-7R5M_7h4.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-B5-CjpEF.cjs.map +0 -1
  134. package/dist/actions-C1SMLWO5.js +0 -430
  135. package/dist/actions-C1SMLWO5.js.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-jOZxB8yW.d.cts +0 -798
  139. package/dist/client-jOZxB8yW.d.cts.map +0 -1
  140. package/dist/client-jOZxB8yW.d.ts +0 -798
  141. package/dist/client-jOZxB8yW.d.ts.map +0 -1
  142. package/dist/codec-BcK8ASsg.cjs.map +0 -1
  143. package/dist/codec-Bxlt1gKO.js.map +0 -1
  144. package/dist/contract-D77iA2iY.js.map +0 -1
  145. package/dist/contract-DSu2UPPm.cjs.map +0 -1
  146. package/dist/dev_wallet-CAbOSrak.cjs.map +0 -1
  147. package/dist/dev_wallet-CU3RpQLm.js.map +0 -1
  148. package/dist/execution-J5jkXhV1.d.cts.map +0 -1
  149. package/dist/execution-XJ0iwFaX.d.ts.map +0 -1
  150. package/dist/index-Bb01ytjJ.d.ts.map +0 -1
  151. package/dist/index-C3HVRvQd.d.ts.map +0 -1
  152. package/dist/index-CIHK7Ew9.d.cts +0 -303
  153. package/dist/index-CIHK7Ew9.d.cts.map +0 -1
  154. package/dist/index-CIHK7Ew9.d.ts +0 -303
  155. package/dist/index-CIHK7Ew9.d.ts.map +0 -1
  156. package/dist/index-CedOvhGY.d.cts.map +0 -1
  157. package/dist/index-CtjWsAXV.d.cts.map +0 -1
  158. package/dist/index-CtjZ61tl.d.cts.map +0 -1
  159. package/dist/index-DeS1S0m-.d.ts.map +0 -1
  160. package/dist/index-DfmDUk5Y.d.ts.map +0 -1
  161. package/dist/index-soFVQX9j.d.cts.map +0 -1
  162. package/dist/readError-CCVlmBhj.cjs +0 -624
  163. package/dist/readError-CCVlmBhj.cjs.map +0 -1
  164. package/dist/readError-D1dppovI.js +0 -571
  165. package/dist/readError-D1dppovI.js.map +0 -1
  166. package/dist/readViews-DbWELMMq.d.cts +0 -609
  167. package/dist/readViews-DbWELMMq.d.cts.map +0 -1
  168. package/dist/readViews-nV3jbpYc.d.ts +0 -609
  169. package/dist/readViews-nV3jbpYc.d.ts.map +0 -1
  170. package/dist/sendInvocation-Dsr9ij5P.cjs +0 -661
  171. package/dist/sendInvocation-Dsr9ij5P.cjs.map +0 -1
  172. package/dist/sendInvocation-tBmf8haQ.js +0 -505
  173. package/dist/sendInvocation-tBmf8haQ.js.map +0 -1
  174. package/dist/transport-5FPeNwuv.cjs +0 -279
  175. package/dist/transport-5FPeNwuv.cjs.map +0 -1
  176. package/dist/transport-IrhVlS4w.js +0 -261
  177. package/dist/transport-IrhVlS4w.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-7R5M_7h4.cjs.map +0 -1
  181. package/dist/wallet-BNKgOXrF.js.map +0 -1
@@ -1,9 +1,104 @@
1
- import { l as serializeHeight, r as UnsupportedRpcValue, u as serializeU64 } from "./codec-Bxlt1gKO.js";
2
- import { g as toBase58, i as toHex0x } from "./hex-DIcaALXL.js";
1
+ import { a as isUnsupportedRpcValue, n as serializeHeight, o as ThruputError, r as serializeU64, s as isThruputError } from "./decimal-CoHOISys.js";
2
+ import { g as toBase58, i as toHex0x } from "./hex-B8D-jBgz.js";
3
3
  import { AuthClaimType, BoolCodec, ContractType, CxsReader, CxsWriter, FixedArrayCodec, Int128Codec, Int256Codec, Int32Codec, Int64Codec, OptionCodec, Uint128Codec, Uint256Codec, Uint32Codec, Uint64Codec, VarArrayCodec, VoidCodec, calldata, codec, contractAddress, contractEntrypointID, deserialize, kMaxEventLength, serialize, sha256Hash } from "@thruputchain/protocol";
4
4
  import { sha256 } from "@noble/hashes/sha2.js";
5
5
  import { CxsReader as CxsReader$1, CxsWriter as CxsWriter$1, FixedOpaqueCodec, Uint8Codec, VarOpaqueCodec, XdrReader, fixedArray, fixedArray as fixedArray$1, fixedBytes, fixedBytes as fixedBytes$1, withCodecBudget } from "@thruputchain/xdr";
6
6
  import { ContractMethodEffect, ContractMethodEffect as ContractMethodEffect$1, ContractTypeDefKind, ContractTypeDefKind as ContractTypeDefKind$1, ContractTypeKind, ContractTypeKind as ContractTypeKind$1, ContractUnionCaseKind, ContractUnionCaseKind as ContractUnionCaseKind$1, codec as codec$1 } from "@thruputchain/contract-spec";
7
+ //#region src/errors/transaction.ts
8
+ /** Every {@link TransactionOutcome}, for example to validate stored values. */
9
+ const transactionOutcomes = Object.freeze([
10
+ "succeeded",
11
+ "failed",
12
+ "notSubmitted",
13
+ "unknown"
14
+ ]);
15
+ /** Every {@link TransactionReason}, for example to validate stored values. */
16
+ const transactionReasons = Object.freeze([
17
+ "aborted",
18
+ "faulted",
19
+ "executionFailed",
20
+ "resultUndecodable",
21
+ "resultUnavailable",
22
+ "cancelled",
23
+ "timeout",
24
+ "persistenceFailed",
25
+ "notDispatched",
26
+ "requestInvalid",
27
+ "nodeRejected",
28
+ "submissionFailed",
29
+ "disconnected",
30
+ "statusUnknown",
31
+ "recentFailure",
32
+ "networkChanged",
33
+ "commitmentConflict",
34
+ "observationFailed",
35
+ "admissionUnsupported",
36
+ "outcomeUnsupported"
37
+ ]);
38
+ /** Reason for each known failed execution result. */
39
+ const failedResults = {
40
+ abort: "aborted",
41
+ fault: "faulted",
42
+ nonDeterministicError: "executionFailed",
43
+ failedGasSponsorship: "executionFailed",
44
+ other: "executionFailed"
45
+ };
46
+ /**
47
+ * Facts from a committed receipt. A successful execution uses
48
+ * `successReason`, because the error is about a later step.
49
+ * @internal
50
+ */
51
+ function receiptFacts(receipt, successReason, submission) {
52
+ const { execution } = receipt;
53
+ const result = isUnsupportedRpcValue(execution) ? void 0 : execution.result;
54
+ const [outcome, reason] = result === "return" ? ["succeeded", successReason] : result !== void 0 && Object.hasOwn(failedResults, result) ? ["failed", failedResults[result]] : ["unknown", "outcomeUnsupported"];
55
+ return {
56
+ hash: receipt.transactionHash,
57
+ outcome,
58
+ reason,
59
+ receipt,
60
+ ...submission ? { submission } : {}
61
+ };
62
+ }
63
+ /**
64
+ * Execution succeeded, but its return data did not decode.
65
+ * @internal
66
+ */
67
+ function transactionResultUndecodable(receipt, cause, submission) {
68
+ return new ThruputError("transactionResultUndecodable", `Transaction ${toBase58(receipt.transactionHash)} committed, but result decoding failed`, {
69
+ cause,
70
+ transaction: receiptFacts(receipt, "resultUndecodable", submission)
71
+ });
72
+ }
73
+ /**
74
+ * Add transaction facts to a `ThruputError` that has none, keeping its code.
75
+ * An error with facts for another transaction, for example an abort reason, is
76
+ * wrapped instead, so its facts never describe this transaction.
77
+ * @internal
78
+ */
79
+ function withTransactionFacts(error, transaction) {
80
+ if (!isThruputError(error)) return error;
81
+ if (error.transaction) {
82
+ if (bytesEqual$1(error.transaction.hash, transaction.hash)) return error;
83
+ const notSubmitted = transaction.outcome === "notSubmitted";
84
+ return new ThruputError(notSubmitted ? "transactionNotSubmitted" : "transactionOutcomeUnknown", `Could not complete transaction ${toBase58(transaction.hash)}`, {
85
+ cause: error,
86
+ transaction: {
87
+ ...transaction,
88
+ outcome: notSubmitted ? "notSubmitted" : "unknown"
89
+ }
90
+ });
91
+ }
92
+ return new ThruputError(error.code, error.message, {
93
+ context: error.context,
94
+ ...error.cause === void 0 ? {} : { cause: error.cause },
95
+ transaction
96
+ });
97
+ }
98
+ function bytesEqual$1(left, right) {
99
+ return left.length === right.length && left.every((byte, i) => byte === right[i]);
100
+ }
101
+ //#endregion
7
102
  //#region src/contract/spec.ts
8
103
  /**
9
104
  * Lookup key for a named type: every segment of its spec id.
@@ -30,20 +125,18 @@ function formatSpecId(id) {
30
125
  }
31
126
  //#endregion
32
127
  //#region src/contract/errors.ts
33
- /** Error raised when contract bytes do not match their declared ABI type. */
34
- var ContractDecodeError = class extends Error {
35
- constructor(message, options) {
36
- super(message, options);
37
- this.name = "ContractDecodeError";
38
- }
39
- };
40
- /** Retrieved bytes or response metadata failed identity/canonical validation. */
41
- var ContractVerificationError = class extends Error {
42
- constructor(message, options) {
43
- super(message, options);
44
- this.name = "ContractVerificationError";
45
- }
46
- };
128
+ /** Contract bytes do not match their declared ABI type. */
129
+ function contractDecodeFailed(message, options) {
130
+ return new ThruputError("contractDecodeFailed", message, options);
131
+ }
132
+ /** Retrieved bytes or response metadata failed identity or canonical checks. */
133
+ function contractVerificationFailed(message, options) {
134
+ return new ThruputError("contractVerificationFailed", message, options);
135
+ }
136
+ /** Text of an error for a wrapping message. */
137
+ function errorText(cause) {
138
+ return cause instanceof Error ? cause.message : void 0;
139
+ }
47
140
  //#endregion
48
141
  //#region src/contract/valueLimits.ts
49
142
  function contractValueLimits(inputBytes) {
@@ -282,7 +375,8 @@ function decodeCalldata(spec, interfaceName, methodName, data, namedCodecs) {
282
375
  if (r.remaining !== 0) throw new Error(`Trailing data after decoding "${methodName}": ${r.remaining} bytes remaining`);
283
376
  return result;
284
377
  } catch (cause) {
285
- throw new ContractDecodeError(`Failed to decode calldata for "${interfaceName}.${methodName}"${cause instanceof Error ? `: ${cause.message}` : ""}`, { cause });
378
+ const text = errorText(cause);
379
+ throw contractDecodeFailed(`Failed to decode calldata for "${interfaceName}.${methodName}"${text === void 0 ? "" : `: ${text}`}`, { cause });
286
380
  }
287
381
  }
288
382
  function assertOwnArrayElements(value) {
@@ -556,15 +650,23 @@ function decodeComplete(valueCodec, data, label) {
556
650
  if (reader.remaining !== 0) throw new Error(`${reader.remaining} trailing bytes`);
557
651
  return value;
558
652
  } catch (cause) {
559
- if (cause instanceof ContractDecodeError) throw cause;
560
- throw new ContractDecodeError(`Failed to decode ${label}${cause instanceof Error ? `: ${cause.message}` : ""}`, { cause });
653
+ if (isThruputError(cause, "contractDecodeFailed")) throw cause;
654
+ const text = errorText(cause);
655
+ throw contractDecodeFailed(`Failed to decode ${label}${text === void 0 ? "" : `: ${text}`}`, { cause });
561
656
  }
562
657
  }
563
658
  //#endregion
564
659
  //#region src/actions/viewFreshness.ts
565
- /** Reject a successful view that violates the caller's snapshot constraint. */
660
+ /**
661
+ * Reject a successful view that violates the caller's snapshot constraint.
662
+ * A node that cannot serve the floor answers `stateHeightUnavailable`, so a
663
+ * lower height breaks the response contract: code `rpcValueInvalid`.
664
+ */
566
665
  function assertViewFreshness(height, minHeight) {
567
- if (minHeight !== void 0 && height < minHeight) throw new Error(`View response height ${height} is below the requested minimum ${minHeight}`);
666
+ if (minHeight !== void 0 && height < minHeight) throw new ThruputError("rpcValueInvalid", `View response height ${height} is below the requested minimum ${minHeight}`, { context: {
667
+ path: "/result/stateBlockHeight",
668
+ raw: height
669
+ } });
568
670
  }
569
671
  //#endregion
570
672
  //#region src/actions/viewAuthClaim.ts
@@ -596,26 +698,23 @@ function toAssumedAuth(claim) {
596
698
  }
597
699
  //#endregion
598
700
  //#region src/contract/method.ts
599
- /** Error thrown by the view API for aborts, faults, or unsupported outcomes. */
600
- var ContractViewError = class extends Error {
601
- outcome;
602
- constructor(outcome) {
603
- const selector = outcome.kind === "abort" ? exceptionSelector(outcome.exception) : void 0;
604
- super(outcome.kind === "abort" ? `Contract view aborted with ${formatException(outcome.exception, selector)}` : outcome.kind === "unsupported" ? "Unsupported contract simulation outcome" : "Contract view faulted");
605
- this.name = "ContractViewError";
606
- this.outcome = outcome;
607
- }
608
- };
609
- /** Error thrown when a root contract receipt does not produce a typed return. */
610
- var ContractReceiptError = class extends Error {
611
- outcome;
612
- constructor(outcome) {
613
- const selector = outcome.kind === "abort" ? exceptionSelector(outcome.exception) : void 0;
614
- super(outcome.kind === "abort" ? `Contract transaction ${toBase58(outcome.transactionHash)} aborted with ${formatException(outcome.exception, selector)}` : `Contract transaction ${toBase58(outcome.transactionHash)} did not return a supported successful result`);
615
- this.name = "ContractReceiptError";
616
- this.outcome = outcome;
617
- }
618
- };
701
+ function viewFailed(method, outcome) {
702
+ return new 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: {
703
+ method: method.name,
704
+ entrypoint: method.entrypoint,
705
+ outcome
706
+ } });
707
+ }
708
+ function callFailed(method, outcome, receipt) {
709
+ return new ThruputError("contractCallFailed", outcome.kind === "abort" ? `Contract transaction ${toBase58(outcome.transactionHash)} aborted with ${formatException(outcome.exception, exceptionSelector(outcome.exception))}` : `Contract transaction ${toBase58(outcome.transactionHash)} did not return a supported successful result`, {
710
+ context: {
711
+ method: method.name,
712
+ entrypoint: method.entrypoint,
713
+ outcome
714
+ },
715
+ transaction: receiptFacts(receipt, "resultUndecodable")
716
+ });
717
+ }
619
718
  function formatException(exception, selector) {
620
719
  if (exception && typeof exception === "object" && "name" in exception && typeof exception.name === "string" && "value" in exception) {
621
720
  const value = typeof exception.value === "bigint" ? `${exception.value}n` : JSON.stringify(exception.value, (_, v) => typeof v === "bigint" ? `${v}n` : v);
@@ -710,11 +809,12 @@ function defineContractMethodWithExceptions(definition, exceptionBySelector) {
710
809
  try {
711
810
  return [argument.publicName, argument.codec.decode(reader)];
712
811
  } catch (cause) {
713
- const detail = cause instanceof Error ? `: ${cause.message}` : "";
714
- throw new ContractDecodeError(`${name}: argument "${argument.publicName}"${detail}`, { cause });
812
+ const text = errorText(cause);
813
+ const detail = text === void 0 ? "" : `: ${text}`;
814
+ throw contractDecodeFailed(`${name}: argument "${argument.publicName}"${detail}`, { cause });
715
815
  }
716
816
  }));
717
- if (reader.remaining !== 0) throw new ContractDecodeError(`${name}: ${reader.remaining} trailing calldata bytes`);
817
+ if (reader.remaining !== 0) throw contractDecodeFailed(`${name}: ${reader.remaining} trailing calldata bytes`);
718
818
  return argumentCodecs.length === 0 ? void 0 : args;
719
819
  },
720
820
  decodeReturn(data) {
@@ -730,22 +830,38 @@ function defineContractMethodWithExceptions(definition, exceptionBySelector) {
730
830
  events: receipt.events
731
831
  };
732
832
  const execution = receipt.execution;
733
- if (execution instanceof UnsupportedRpcValue) return {
833
+ if (isUnsupportedRpcValue(execution)) return {
734
834
  kind: "unsupported",
735
835
  raw: receipt,
736
836
  ...metadata
737
837
  };
738
- if (execution.result === "return") return {
739
- kind: "return",
740
- value: method.decodeReturn(execution.returnData),
741
- ...metadata
742
- };
743
- if (execution.result === "abort") return {
744
- kind: "abort",
745
- exception: method.decodeException(execution.abortData),
746
- abortData: execution.abortData,
747
- ...metadata
748
- };
838
+ if (execution.result === "return") {
839
+ let value;
840
+ try {
841
+ value = method.decodeReturn(execution.returnData);
842
+ } catch (error) {
843
+ throw transactionResultUndecodable(receipt, error);
844
+ }
845
+ return {
846
+ kind: "return",
847
+ value,
848
+ ...metadata
849
+ };
850
+ }
851
+ if (execution.result === "abort") {
852
+ let exception;
853
+ try {
854
+ exception = method.decodeException(execution.abortData);
855
+ } catch (error) {
856
+ throw withTransactionFacts(error, receiptFacts(receipt, "resultUndecodable"));
857
+ }
858
+ return {
859
+ kind: "abort",
860
+ exception,
861
+ abortData: execution.abortData,
862
+ ...metadata
863
+ };
864
+ }
749
865
  return {
750
866
  kind: "failure",
751
867
  execution,
@@ -760,11 +876,11 @@ function defineContractMethodWithExceptions(definition, exceptionBySelector) {
760
876
  blockHeight: outcome.blockHeight,
761
877
  events: outcome.events
762
878
  };
763
- throw new ContractReceiptError(outcome);
879
+ throw callFailed(method, outcome, receipt);
764
880
  },
765
881
  decodeView(response) {
766
882
  const outcome = method.decodeViewOutcome(response);
767
- if (outcome.kind !== "return") throw new ContractViewError(outcome);
883
+ if (outcome.kind !== "return") throw viewFailed(method, outcome);
768
884
  return {
769
885
  value: outcome.value,
770
886
  stateBlockHeight: outcome.stateBlockHeight,
@@ -789,7 +905,7 @@ function defineContractMethodWithExceptions(definition, exceptionBySelector) {
789
905
  return method.decodeViewOutcome(response);
790
906
  },
791
907
  decodeViewOutcome(response) {
792
- if (response.output instanceof UnsupportedRpcValue) return {
908
+ if (isUnsupportedRpcValue(response.output)) return {
793
909
  kind: "unsupported",
794
910
  raw: response,
795
911
  stateBlockHeight: response.stateBlockHeight,
@@ -828,7 +944,21 @@ function defineContractMethodWithExceptions(definition, exceptionBySelector) {
828
944
  gasUsed: outcome.gasUsed,
829
945
  events: outcome.events
830
946
  };
831
- throw new ContractViewError(outcome);
947
+ throw viewFailed(method, outcome);
948
+ },
949
+ decodeError(error) {
950
+ if (!isThruputError(error, "contractViewFailed") && !isThruputError(error, "contractCallFailed")) return void 0;
951
+ const { method: failedName, entrypoint: failed, outcome } = error.context;
952
+ if (failedName !== name || failed.length !== entrypoint.length || failed.some((byte, index) => byte !== entrypoint[index])) return void 0;
953
+ if (outcome.kind !== "abort") return outcome;
954
+ try {
955
+ return {
956
+ ...outcome,
957
+ exception: method.decodeException(outcome.abortData)
958
+ };
959
+ } catch {
960
+ return;
961
+ }
832
962
  }
833
963
  };
834
964
  return method;
@@ -871,7 +1001,8 @@ function decodeException(data, exceptionBySelector) {
871
1001
  ...variant === void 0 ? {} : { variant }
872
1002
  };
873
1003
  } catch (cause) {
874
- throw new ContractDecodeError(`Failed to decode contract exception${cause instanceof Error ? `: ${cause.message}` : ""}`, { cause });
1004
+ const text = errorText(cause);
1005
+ throw contractDecodeFailed(`Failed to decode contract exception${text === void 0 ? "" : `: ${text}`}`, { cause });
875
1006
  }
876
1007
  }
877
1008
  //#endregion
@@ -897,8 +1028,8 @@ function createContractCallDecoder(spec) {
897
1028
  });
898
1029
  for (const method of iface.methods) {
899
1030
  const key = deriveEntrypointID(iface.name, iface.vers, method.name).join(",");
900
- if (methods.has(key)) throw new ContractDecodeError("Duplicate method selector in contract spec");
901
- if (new Set(method.args.map((arg) => arg.name)).size !== method.args.length) throw new ContractDecodeError("Duplicate argument name in contract spec");
1031
+ if (methods.has(key)) throw contractDecodeFailed("Duplicate method selector in contract spec");
1032
+ if (new Set(method.args.map((arg) => arg.name)).size !== method.args.length) throw contractDecodeFailed("Duplicate argument name in contract spec");
902
1033
  const descriptor = defineContractMethodWithExceptions({
903
1034
  interfaceName: iface.name,
904
1035
  interfaceVersion: iface.vers,
@@ -967,7 +1098,7 @@ function createContractEventDecoder(spec) {
967
1098
  const signatures = /* @__PURE__ */ new Set();
968
1099
  const events = spec.events.map((event) => {
969
1100
  const key = event.signature.join(",");
970
- if (signatures.has(key)) throw new ContractDecodeError("Duplicate event signature in contract spec");
1101
+ if (signatures.has(key)) throw contractDecodeFailed("Duplicate event signature in contract spec");
971
1102
  signatures.add(key);
972
1103
  return defineContractEvent({
973
1104
  name: formatSpecId(event.name),
@@ -1052,8 +1183,9 @@ function defineContractEvent(definition) {
1052
1183
  fields: decodedFields
1053
1184
  };
1054
1185
  } catch (cause) {
1055
- if (cause instanceof ContractDecodeError) throw cause;
1056
- throw new ContractDecodeError(`Failed to decode ${eventName}${cause instanceof Error ? `: ${cause.message}` : ""}`, { cause });
1186
+ if (isThruputError(cause, "contractDecodeFailed")) throw cause;
1187
+ const text = errorText(cause);
1188
+ throw contractDecodeFailed(`Failed to decode ${eventName}${text === void 0 ? "" : `: ${text}`}`, { cause });
1057
1189
  }
1058
1190
  },
1059
1191
  filter(input) {
@@ -1159,7 +1291,8 @@ function encodeTopic(topic, value, eventName) {
1159
1291
  topic.codec.encode(writer, value);
1160
1292
  assertScalarRange(topic, value);
1161
1293
  } catch (cause) {
1162
- const detail = cause instanceof Error ? `: ${cause.message}` : "";
1294
+ const text = errorText(cause);
1295
+ const detail = text === void 0 ? "" : `: ${text}`;
1163
1296
  throw new Error(`${eventName} topic "${topic.name}" failed to encode${detail}`, { cause });
1164
1297
  }
1165
1298
  return fixedBytes(writer.finish(), 32);
@@ -1213,16 +1346,16 @@ const contractSpecCodecLimits = {
1213
1346
  * This bounds the generated decoder before it recurses or allocates lists.
1214
1347
  */
1215
1348
  function preflightContractSpec(bytes) {
1216
- if (bytes.length > 16 * 1024 * 1024) throw new ContractDecodeError("Contract spec exceeds byte limit (16777216)");
1349
+ if (bytes.length > 16 * 1024 * 1024) throw contractDecodeFailed("Contract spec exceeds byte limit (16777216)");
1217
1350
  const reader = new XdrReader(bytes);
1218
1351
  let work = 1e5;
1219
1352
  const spend = (count) => {
1220
1353
  work -= count;
1221
- if (work < 0) throw new ContractDecodeError("Contract spec exceeds work limit (100000)");
1354
+ if (work < 0) throw contractDecodeFailed("Contract spec exceeds work limit (100000)");
1222
1355
  };
1223
1356
  const list = (item) => {
1224
1357
  const count = Number(reader.readUint32());
1225
- if (count > Math.floor(reader.remaining / 4)) throw new ContractDecodeError("Truncated contract spec collection");
1358
+ if (count > Math.floor(reader.remaining / 4)) throw contractDecodeFailed("Truncated contract spec collection");
1226
1359
  spend(count);
1227
1360
  for (let i = 0; i < count; i++) item();
1228
1361
  };
@@ -1233,7 +1366,7 @@ function preflightContractSpec(bytes) {
1233
1366
  codec$1.ContractSpecId.decode(reader);
1234
1367
  };
1235
1368
  const type = (depth = 1) => {
1236
- if (depth > 64) throw new ContractDecodeError("Contract spec exceeds type nesting limit (64)");
1369
+ if (depth > 64) throw contractDecodeFailed("Contract spec exceeds type nesting limit (64)");
1237
1370
  spend(1);
1238
1371
  const kind = Number(reader.readInt32());
1239
1372
  switch (kind) {
@@ -1268,7 +1401,7 @@ function preflightContractSpec(bytes) {
1268
1401
  case ContractTypeKind.SignedToken:
1269
1402
  if (reader.readBool()) type(depth + 1);
1270
1403
  return;
1271
- default: throw new ContractDecodeError(`Unknown contract spec type ${kind}`);
1404
+ default: throw contractDecodeFailed(`Unknown contract spec type ${kind}`);
1272
1405
  }
1273
1406
  };
1274
1407
  const field = () => {
@@ -1315,11 +1448,11 @@ function preflightContractSpec(bytes) {
1315
1448
  case ContractUnionCaseKind.UnionCaseStruct:
1316
1449
  list(field);
1317
1450
  break;
1318
- default: throw new ContractDecodeError(`Unknown contract spec union case ${kind}`);
1451
+ default: throw contractDecodeFailed(`Unknown contract spec union case ${kind}`);
1319
1452
  }
1320
1453
  });
1321
1454
  break;
1322
- default: throw new ContractDecodeError(`Unknown contract spec definition ${kind}`);
1455
+ default: throw contractDecodeFailed(`Unknown contract spec definition ${kind}`);
1323
1456
  }
1324
1457
  });
1325
1458
  list(() => {
@@ -1328,26 +1461,39 @@ function preflightContractSpec(bytes) {
1328
1461
  list(field);
1329
1462
  list(field);
1330
1463
  });
1331
- if (reader.remaining !== 0) throw new ContractDecodeError("Trailing contract spec bytes");
1464
+ if (reader.remaining !== 0) throw contractDecodeFailed("Trailing contract spec bytes");
1332
1465
  } catch (cause) {
1333
- if (cause instanceof ContractDecodeError) throw cause;
1334
- throw new ContractDecodeError("Invalid contract spec XDR", { cause });
1466
+ if (isThruputError(cause, "contractDecodeFailed")) throw cause;
1467
+ throw contractDecodeFailed("Invalid contract spec XDR", { cause });
1335
1468
  }
1336
1469
  }
1337
1470
  //#endregion
1338
1471
  //#region src/contract/artifact.ts
1472
+ const v5V6Layout = {
1473
+ headerBytes: 128,
1474
+ codeSizeOffset: 52
1475
+ };
1476
+ const rv32Layouts = new Map([
1477
+ [5, v5V6Layout],
1478
+ [6, v5V6Layout],
1479
+ [7, {
1480
+ headerBytes: 120,
1481
+ codeSizeOffset: 44
1482
+ }]
1483
+ ]);
1339
1484
  /**
1340
1485
  * Verify complete Contract XDR against the requested hash, then read its spec.
1341
1486
  * Rejects malformed known envelopes. Unknown versions remain explicit results.
1342
- * Reads v5 as having no spec. In v6, validates all extension framing and skips
1343
- * unknown kinds. Only the contract-spec extension body is interpreted.
1487
+ * Reads RV32 artifact formats v5, v6 and v7. Reads v5 as having no spec. In v6
1488
+ * and v7, validates all extension framing and skips unknown kinds. Only the
1489
+ * contract-spec extension body is interpreted.
1344
1490
  * This proves byte identity, not deployment, executable validity, or spec truth.
1345
1491
  */
1346
1492
  function readContractArtifactSpec(contractXdr, expectedHash) {
1347
1493
  try {
1348
1494
  return readArtifact(contractXdr, expectedHash);
1349
1495
  } catch (cause) {
1350
- throw new ContractVerificationError(cause instanceof Error ? cause.message : "Invalid contract artifact", { cause });
1496
+ throw contractVerificationFailed(errorText(cause) ?? "Invalid contract artifact", { cause });
1351
1497
  }
1352
1498
  }
1353
1499
  function readArtifact(contractXdr, expectedHash) {
@@ -1364,14 +1510,16 @@ function readArtifact(contractXdr, expectedHash) {
1364
1510
  if (artifact.length < 12 || !bytesEqual(artifact.subarray(0, 8), new TextEncoder().encode("GHRV32A1"))) throw new Error("Invalid RV32 artifact header");
1365
1511
  const header = new DataView(artifact.buffer, artifact.byteOffset, artifact.byteLength);
1366
1512
  const formatVersion = header.getUint32(8, true);
1367
- if (formatVersion !== 5 && formatVersion !== 6) return {
1513
+ const layout = rv32Layouts.get(formatVersion);
1514
+ if (layout === void 0) return {
1368
1515
  kind: "unsupportedFormat",
1369
1516
  formatVersion
1370
1517
  };
1371
- if (artifact.length < 128 || header.getUint32(12, true) !== 128) throw new Error("Invalid RV32 header size");
1372
- const codeSize = header.getUint32(52, true);
1373
- const memorySize = header.getUint32(56, true);
1374
- const sectionsEnd = 128 + codeSize + memorySize;
1518
+ const { headerBytes, codeSizeOffset } = layout;
1519
+ if (artifact.length < headerBytes || header.getUint32(12, true) !== headerBytes) throw new Error("Invalid RV32 header size");
1520
+ const codeSize = header.getUint32(codeSizeOffset, true);
1521
+ const memorySize = header.getUint32(codeSizeOffset + 4, true);
1522
+ const sectionsEnd = headerBytes + codeSize + memorySize;
1375
1523
  if (sectionsEnd > artifact.length) throw new Error("Invalid RV32 section layout");
1376
1524
  if (formatVersion === 5) {
1377
1525
  if (sectionsEnd !== artifact.length) throw new Error("Invalid RV32 v5 section layout");
@@ -1467,6 +1615,6 @@ function getContract(options) {
1467
1615
  }]));
1468
1616
  }
1469
1617
  //#endregion
1470
- export { ContractUnionCaseKind$1 as A, isSignedToken as C, ContractMethodEffect$1 as D, ContractVerificationError as E, specIdKey as M, ContractTypeDefKind$1 as O, resolveCodec as S, ContractDecodeError as T, buildNamedCodecs as _, readContractArtifactSpec as a, decodeCalldata as b, defineContractEvent as c, createContractCallDecoder as d, ContractReceiptError as f, createContractCodecContext as g, createContractCodec as h, deriveContractAddress as i, formatSpecId as j, ContractTypeKind$1 as k, topicRepresentation as l, defineContractMethod as m, fixedBytes$1 as n, bytesEqual as o, ContractViewError as p, getContract as r, createContractEventDecoder as s, fixedArray$1 as t, hashContract as u, deriveEntrypointID as v, signedToken as w, encodeCalldata as x, majorVersionFromSemver as y };
1618
+ export { formatSpecId as A, contractDecodeFailed as C, ContractTypeDefKind$1 as D, ContractMethodEffect$1 as E, transactionResultUndecodable as F, withTransactionFacts as I, receiptFacts as M, transactionOutcomes as N, ContractTypeKind$1 as O, transactionReasons as P, signedToken as S, errorText as T, majorVersionFromSemver as _, readContractArtifactSpec as a, resolveCodec as b, defineContractEvent as c, createContractCallDecoder as d, defineContractMethod as f, deriveEntrypointID as g, buildNamedCodecs as h, deriveContractAddress as i, specIdKey as j, ContractUnionCaseKind$1 as k, topicRepresentation as l, createContractCodecContext as m, fixedBytes$1 as n, bytesEqual as o, createContractCodec as p, getContract as r, createContractEventDecoder as s, fixedArray$1 as t, hashContract as u, decodeCalldata as v, contractVerificationFailed as w, isSignedToken as x, encodeCalldata as y };
1471
1619
 
1472
- //# sourceMappingURL=contract-D77iA2iY.js.map
1620
+ //# sourceMappingURL=contract-BOlNskwd.js.map