@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.
- package/README.md +112 -17
- package/dist/{actions-B5-CjpEF.cjs → actions-B2gV8Vzr.cjs} +297 -73
- package/dist/actions-B2gV8Vzr.cjs.map +1 -0
- package/dist/actions-UEYKD22C.js +653 -0
- package/dist/actions-UEYKD22C.js.map +1 -0
- package/dist/actions.cjs +4 -8
- package/dist/actions.d.cts +4 -4
- package/dist/actions.d.ts +4 -4
- package/dist/actions.js +3 -3
- package/dist/{artifact-BM_MVzhL.d.ts → artifact-RIAPVmVX.d.cts} +4 -3
- package/dist/artifact-RIAPVmVX.d.cts.map +1 -0
- package/dist/{artifact-BM_MVzhL.d.cts → artifact-RIAPVmVX.d.ts} +4 -3
- package/dist/artifact-RIAPVmVX.d.ts.map +1 -0
- package/dist/{contract-D77iA2iY.js → contract-BOlNskwd.js} +235 -87
- package/dist/contract-BOlNskwd.js.map +1 -0
- package/dist/{contract-DSu2UPPm.cjs → contract-D_vxUudr.cjs} +281 -109
- package/dist/contract-D_vxUudr.cjs.map +1 -0
- package/dist/contract.cjs +1 -5
- package/dist/contract.d.cts +4 -4
- package/dist/contract.d.ts +4 -4
- package/dist/contract.js +2 -2
- package/dist/contracts.cjs +5 -5
- package/dist/contracts.d.cts +19 -4
- package/dist/contracts.d.cts.map +1 -1
- package/dist/contracts.d.ts +19 -4
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +4 -4
- package/dist/decimal-BX7abv5J.cjs +171 -0
- package/dist/decimal-BX7abv5J.cjs.map +1 -0
- package/dist/decimal-CoHOISys.js +124 -0
- package/dist/decimal-CoHOISys.js.map +1 -0
- package/dist/{dev_wallet-CAbOSrak.cjs → dev_wallet-BVChhV6j.cjs} +85 -6
- package/dist/dev_wallet-BVChhV6j.cjs.map +1 -0
- package/dist/{dev_wallet-CU3RpQLm.js → dev_wallet-D9LuPZ-h.js} +84 -5
- package/dist/dev_wallet-D9LuPZ-h.js.map +1 -0
- package/dist/{execution-J5jkXhV1.d.cts → execution-pSt6k620.d.cts} +23 -50
- package/dist/execution-pSt6k620.d.cts.map +1 -0
- package/dist/{execution-XJ0iwFaX.d.ts → execution-uiuFPV0d.d.ts} +23 -50
- package/dist/execution-uiuFPV0d.d.ts.map +1 -0
- package/dist/{hex-DIcaALXL.js → hex-B8D-jBgz.js} +2 -2
- package/dist/{hex-DIcaALXL.js.map → hex-B8D-jBgz.js.map} +1 -1
- package/dist/{hex-DkGpiZ5e.cjs → hex-CSDZ9d6z.cjs} +2 -2
- package/dist/{hex-DkGpiZ5e.cjs.map → hex-CSDZ9d6z.cjs.map} +1 -1
- package/dist/{index-soFVQX9j.d.cts → index-B1efA-Y_.d.ts} +24 -21
- package/dist/index-B1efA-Y_.d.ts.map +1 -0
- package/dist/{index-C3HVRvQd.d.ts → index-BGmH_Sm7.d.cts} +12 -62
- package/dist/index-BGmH_Sm7.d.cts.map +1 -0
- package/dist/{index-Bb01ytjJ.d.ts → index-BZ5j5P5d.d.ts} +11 -9
- package/dist/index-BZ5j5P5d.d.ts.map +1 -0
- package/dist/{index-CedOvhGY.d.cts → index-BfYEEVHm.d.cts} +3 -13
- package/dist/index-BfYEEVHm.d.cts.map +1 -0
- package/dist/{index-CtjWsAXV.d.cts → index-BhOeIyrZ.d.cts} +11 -9
- package/dist/index-BhOeIyrZ.d.cts.map +1 -0
- package/dist/{index-B5KqSHeL.d.cts → index-BsvYcU_Y.d.cts} +2 -2
- package/dist/{index-B5KqSHeL.d.cts.map → index-BsvYcU_Y.d.cts.map} +1 -1
- package/dist/{index-DeS1S0m-.d.ts → index-Btl_jMCT.d.ts} +3 -13
- package/dist/index-Btl_jMCT.d.ts.map +1 -0
- package/dist/{index-CtjZ61tl.d.cts → index-CG-q0j9w.d.ts} +12 -62
- package/dist/index-CG-q0j9w.d.ts.map +1 -0
- package/dist/index-CPtBvHE8.d.ts +145 -0
- package/dist/index-CPtBvHE8.d.ts.map +1 -0
- package/dist/{index-DfmDUk5Y.d.ts → index-DBKsOzCN.d.cts} +24 -21
- package/dist/index-DBKsOzCN.d.cts.map +1 -0
- package/dist/index-Xre-0Jka.d.cts +145 -0
- package/dist/index-Xre-0Jka.d.cts.map +1 -0
- package/dist/index.cjs +39 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -17
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +12 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -38
- package/dist/index.js.map +1 -1
- package/dist/provider.cjs +3 -3
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.cts +2 -1
- package/dist/provider.d.ts +2 -1
- package/dist/provider.js +3 -3
- package/dist/provider.js.map +1 -1
- package/dist/{codec-Bxlt1gKO.js → readError-B3Rz7rgs.js} +359 -56
- package/dist/readError-B3Rz7rgs.js.map +1 -0
- package/dist/{codec-BcK8ASsg.cjs → readError-COcEDNoZ.cjs} +363 -96
- package/dist/readError-COcEDNoZ.cjs.map +1 -0
- package/dist/requestAirdrop-DBCOST2B.d.ts +1818 -0
- package/dist/requestAirdrop-DBCOST2B.d.ts.map +1 -0
- package/dist/requestAirdrop-T1eVn3l5.d.cts +1818 -0
- package/dist/requestAirdrop-T1eVn3l5.d.cts.map +1 -0
- package/dist/sendInvocation-185ZJrta.cjs +583 -0
- package/dist/sendInvocation-185ZJrta.cjs.map +1 -0
- package/dist/sendInvocation-DBaNWhr3.js +439 -0
- package/dist/sendInvocation-DBaNWhr3.js.map +1 -0
- package/dist/signed-op.cjs +2 -2
- package/dist/signed-op.d.cts +2 -2
- package/dist/signed-op.d.ts +1 -1
- package/dist/signed-op.js +2 -2
- package/dist/{signedOp-DAucp6xg.cjs → signedOp-CVyeJ5ig.cjs} +3 -3
- package/dist/{signedOp-DAucp6xg.cjs.map → signedOp-CVyeJ5ig.cjs.map} +1 -1
- package/dist/{signedOp-DpmUpH-e.js → signedOp-D6WYZG9j.js} +3 -3
- package/dist/{signedOp-DpmUpH-e.js.map → signedOp-D6WYZG9j.js.map} +1 -1
- package/dist/{signed_op-_lR85dn2.cjs → signed_op-BBsDKOlD.cjs} +4 -4
- package/dist/{signed_op-_lR85dn2.cjs.map → signed_op-BBsDKOlD.cjs.map} +1 -1
- package/dist/{signed_op-D2usgASc.d.cts → signed_op-BvbOHWKK.d.ts} +3 -3
- package/dist/{signed_op-zGq4eBo8.d.ts.map → signed_op-BvbOHWKK.d.ts.map} +1 -1
- package/dist/{signed_op-zGq4eBo8.d.ts → signed_op-DoHFpSH4.d.cts} +3 -3
- package/dist/{signed_op-D2usgASc.d.cts.map → signed_op-DoHFpSH4.d.cts.map} +1 -1
- package/dist/{signed_op-CwN-_CXw.js → signed_op-h9X9-vBL.js} +3 -3
- package/dist/{signed_op-CwN-_CXw.js.map → signed_op-h9X9-vBL.js.map} +1 -1
- package/dist/transport-BhWZxHcz.cjs +528 -0
- package/dist/transport-BhWZxHcz.cjs.map +1 -0
- package/dist/transport-EyDYuibb.js +504 -0
- package/dist/transport-EyDYuibb.js.map +1 -0
- package/dist/transport.cjs +6 -13
- package/dist/transport.d.cts +3 -3
- package/dist/transport.d.ts +3 -3
- package/dist/transport.js +4 -4
- package/dist/types-VYjJcTip.d.cts +161 -0
- package/dist/types-VYjJcTip.d.cts.map +1 -0
- package/dist/types-VYjJcTip.d.ts +161 -0
- package/dist/types-VYjJcTip.d.ts.map +1 -0
- package/dist/{validation-eXATmgO0.js → validation-BLQ64Dfh.js} +3 -3
- package/dist/validation-BLQ64Dfh.js.map +1 -0
- package/dist/{validation-4w-vDGAi.cjs → validation-CZqtmMLJ.cjs} +3 -3
- package/dist/validation-CZqtmMLJ.cjs.map +1 -0
- package/dist/{wallet-BNKgOXrF.js → wallet-NlZiI4-3.js} +161 -77
- package/dist/wallet-NlZiI4-3.js.map +1 -0
- package/dist/{wallet-7R5M_7h4.cjs → wallet-UvyXtxh5.cjs} +161 -77
- package/dist/wallet-UvyXtxh5.cjs.map +1 -0
- package/dist/wallet.cjs +2 -8
- package/dist/wallet.d.cts +4 -3
- package/dist/wallet.d.ts +4 -3
- package/dist/wallet.js +3 -3
- package/package.json +2 -2
- package/dist/actions-B5-CjpEF.cjs.map +0 -1
- package/dist/actions-C1SMLWO5.js +0 -430
- package/dist/actions-C1SMLWO5.js.map +0 -1
- package/dist/artifact-BM_MVzhL.d.cts.map +0 -1
- package/dist/artifact-BM_MVzhL.d.ts.map +0 -1
- package/dist/client-jOZxB8yW.d.cts +0 -798
- package/dist/client-jOZxB8yW.d.cts.map +0 -1
- package/dist/client-jOZxB8yW.d.ts +0 -798
- package/dist/client-jOZxB8yW.d.ts.map +0 -1
- package/dist/codec-BcK8ASsg.cjs.map +0 -1
- package/dist/codec-Bxlt1gKO.js.map +0 -1
- package/dist/contract-D77iA2iY.js.map +0 -1
- package/dist/contract-DSu2UPPm.cjs.map +0 -1
- package/dist/dev_wallet-CAbOSrak.cjs.map +0 -1
- package/dist/dev_wallet-CU3RpQLm.js.map +0 -1
- package/dist/execution-J5jkXhV1.d.cts.map +0 -1
- package/dist/execution-XJ0iwFaX.d.ts.map +0 -1
- package/dist/index-Bb01ytjJ.d.ts.map +0 -1
- package/dist/index-C3HVRvQd.d.ts.map +0 -1
- package/dist/index-CIHK7Ew9.d.cts +0 -303
- package/dist/index-CIHK7Ew9.d.cts.map +0 -1
- package/dist/index-CIHK7Ew9.d.ts +0 -303
- package/dist/index-CIHK7Ew9.d.ts.map +0 -1
- package/dist/index-CedOvhGY.d.cts.map +0 -1
- package/dist/index-CtjWsAXV.d.cts.map +0 -1
- package/dist/index-CtjZ61tl.d.cts.map +0 -1
- package/dist/index-DeS1S0m-.d.ts.map +0 -1
- package/dist/index-DfmDUk5Y.d.ts.map +0 -1
- package/dist/index-soFVQX9j.d.cts.map +0 -1
- package/dist/readError-CCVlmBhj.cjs +0 -624
- package/dist/readError-CCVlmBhj.cjs.map +0 -1
- package/dist/readError-D1dppovI.js +0 -571
- package/dist/readError-D1dppovI.js.map +0 -1
- package/dist/readViews-DbWELMMq.d.cts +0 -609
- package/dist/readViews-DbWELMMq.d.cts.map +0 -1
- package/dist/readViews-nV3jbpYc.d.ts +0 -609
- package/dist/readViews-nV3jbpYc.d.ts.map +0 -1
- package/dist/sendInvocation-Dsr9ij5P.cjs +0 -661
- package/dist/sendInvocation-Dsr9ij5P.cjs.map +0 -1
- package/dist/sendInvocation-tBmf8haQ.js +0 -505
- package/dist/sendInvocation-tBmf8haQ.js.map +0 -1
- package/dist/transport-5FPeNwuv.cjs +0 -279
- package/dist/transport-5FPeNwuv.cjs.map +0 -1
- package/dist/transport-IrhVlS4w.js +0 -261
- package/dist/transport-IrhVlS4w.js.map +0 -1
- package/dist/validation-4w-vDGAi.cjs.map +0 -1
- package/dist/validation-eXATmgO0.js.map +0 -1
- package/dist/wallet-7R5M_7h4.cjs.map +0 -1
- package/dist/wallet-BNKgOXrF.js.map +0 -1
|
@@ -1,9 +1,104 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { g as toBase58, i as toHex0x } from "./hex-
|
|
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
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
|
560
|
-
|
|
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
|
-
/**
|
|
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
|
|
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
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
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
|
|
714
|
-
|
|
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
|
|
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
|
|
833
|
+
if (isUnsupportedRpcValue(execution)) return {
|
|
734
834
|
kind: "unsupported",
|
|
735
835
|
raw: receipt,
|
|
736
836
|
...metadata
|
|
737
837
|
};
|
|
738
|
-
if (execution.result === "return")
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
901
|
-
if (new Set(method.args.map((arg) => arg.name)).size !== method.args.length) throw
|
|
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
|
|
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
|
|
1056
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
1451
|
+
default: throw contractDecodeFailed(`Unknown contract spec union case ${kind}`);
|
|
1319
1452
|
}
|
|
1320
1453
|
});
|
|
1321
1454
|
break;
|
|
1322
|
-
default: throw
|
|
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
|
|
1464
|
+
if (reader.remaining !== 0) throw contractDecodeFailed("Trailing contract spec bytes");
|
|
1332
1465
|
} catch (cause) {
|
|
1333
|
-
if (cause
|
|
1334
|
-
throw
|
|
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
|
|
1343
|
-
*
|
|
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
|
|
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
|
-
|
|
1513
|
+
const layout = rv32Layouts.get(formatVersion);
|
|
1514
|
+
if (layout === void 0) return {
|
|
1368
1515
|
kind: "unsupportedFormat",
|
|
1369
1516
|
formatVersion
|
|
1370
1517
|
};
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
const
|
|
1374
|
-
const
|
|
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 {
|
|
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-
|
|
1620
|
+
//# sourceMappingURL=contract-BOlNskwd.js.map
|