@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
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
import { a as isUnsupportedRpcValue, i as UnsupportedRpcValue, o as ThruputError, s as isThruputError } from "./decimal-CoHOISys.js";
|
|
2
|
+
import { g as toBase58, i as toHex0x } from "./hex-B8D-jBgz.js";
|
|
3
|
+
import { C as contractDecodeFailed, I as withTransactionFacts, M as receiptFacts, T as errorText, a as readContractArtifactSpec, i as deriveContractAddress, o as bytesEqual$1, u as hashContract, w as contractVerificationFailed } from "./contract-BOlNskwd.js";
|
|
4
|
+
import { r as rpcIncompatible, t as classifyReadError } from "./readError-B3Rz7rgs.js";
|
|
5
|
+
import { C as validateTimer, S as beforeDeadline, a as assertTransactionSuccess, d as isLocalRequestError, f as reasonAfterDispatch, g as createSubmissionEvidence, h as transactionOutcomeUnknown, i as assertTransactionAdmission, m as transactionNotSubmitted, u as isCancellation, w as waitDelay } from "./sendInvocation-DBaNWhr3.js";
|
|
6
|
+
import { a as spec, r as DefaultWallet } from "./dev_wallet-D9LuPZ-h.js";
|
|
7
|
+
import { ContractType, HogexecPrecompiledNativeContracts, calldata, codec, contractEntrypointID, deserialize, gasAmount, serialize, sha256Hash } from "@thruputchain/protocol";
|
|
8
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
9
|
+
//#region src/actions/public/waitForTransactionReceipt.ts
|
|
10
|
+
/**
|
|
11
|
+
* Observation stopped: code `transactionOutcomeUnknown`. Neither a timeout nor
|
|
12
|
+
* cancellation proves that the transaction did not execute.
|
|
13
|
+
*/
|
|
14
|
+
function outcomeUnknown(transactionHash, reason, timedOut, cause, knownCommitment, lastStatus) {
|
|
15
|
+
return new ThruputError("transactionOutcomeUnknown", timedOut ? `Timed out waiting for transaction ${toBase58(transactionHash)}` : `Could not observe transaction ${toBase58(transactionHash)}`, {
|
|
16
|
+
context: {
|
|
17
|
+
...knownCommitment ? { knownCommitment } : {},
|
|
18
|
+
...lastStatus ? { lastStatus } : {}
|
|
19
|
+
},
|
|
20
|
+
...cause === void 0 ? {} : { cause },
|
|
21
|
+
transaction: {
|
|
22
|
+
hash: transactionHash,
|
|
23
|
+
outcome: "unknown",
|
|
24
|
+
reason
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/** The observation deadline. Private, so read-error handling never retries it. */
|
|
29
|
+
var ObservationTimeout = class extends Error {};
|
|
30
|
+
/** The reason for a timeout: the last read failure or node status, when known. */
|
|
31
|
+
function timeoutReason(lastFailure, lastStatus) {
|
|
32
|
+
if (lastFailure !== void 0) return "disconnected";
|
|
33
|
+
if (lastStatus === void 0) return "timeout";
|
|
34
|
+
if (lastStatus instanceof UnsupportedRpcValue) return "statusUnknown";
|
|
35
|
+
if (lastStatus.status === "unknown" || lastStatus.status === "other") return "statusUnknown";
|
|
36
|
+
if (lastStatus.status === "recentFailure") return "recentFailure";
|
|
37
|
+
return "timeout";
|
|
38
|
+
}
|
|
39
|
+
const equal = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
|
|
40
|
+
/**
|
|
41
|
+
* Return any committed receipt, including failed execution. Never sign or resubmit.
|
|
42
|
+
* When observation stops, throws code `transactionOutcomeUnknown` with
|
|
43
|
+
* `transaction.reason` set to why it stopped.
|
|
44
|
+
*/
|
|
45
|
+
async function waitForTransactionReceipt(client, transactionHash, options = {}) {
|
|
46
|
+
return await observe(client, transactionHash, options, false);
|
|
47
|
+
}
|
|
48
|
+
/** Observe commitment independently of receipt availability or execution success. */
|
|
49
|
+
async function waitForCommitment(client, transactionHash, options = {}) {
|
|
50
|
+
return await observe(client, transactionHash, options, true);
|
|
51
|
+
}
|
|
52
|
+
function snapshotStatus(status) {
|
|
53
|
+
const copy = (value) => {
|
|
54
|
+
if (value instanceof UnsupportedRpcValue) return new UnsupportedRpcValue(structuredClone(value.raw));
|
|
55
|
+
if (Array.isArray(value)) return value.map(copy);
|
|
56
|
+
if (ArrayBuffer.isView(value)) return structuredClone(value);
|
|
57
|
+
if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, copy(entry)]));
|
|
58
|
+
return value;
|
|
59
|
+
};
|
|
60
|
+
return copy(status);
|
|
61
|
+
}
|
|
62
|
+
async function observe(client, hash, options, commitmentOnly) {
|
|
63
|
+
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
64
|
+
const interval = options.pollingIntervalMs ?? 250;
|
|
65
|
+
validateTimer(timeoutMs, "timeoutMs");
|
|
66
|
+
validateTimer(interval, "pollingIntervalMs");
|
|
67
|
+
const transactionHash = new Uint8Array(hash);
|
|
68
|
+
const networkHash = new Uint8Array(options.expectedNetworkHash ?? client.discovery.network.networkHash);
|
|
69
|
+
if (transactionHash.length !== 32 || networkHash.length !== 32) throw new RangeError("Transaction and network hashes must contain 32 bytes");
|
|
70
|
+
let commitment;
|
|
71
|
+
let lastStatus;
|
|
72
|
+
if (options.knownCommitment) {
|
|
73
|
+
const known = options.knownCommitment;
|
|
74
|
+
if (!equal(known.transactionHash, transactionHash) || !equal(known.networkHash, networkHash) || typeof known.blockHeight !== "bigint" || known.blockHeight < 0n || known.blockHeight > 9223372036854775807n) throw new TypeError("knownCommitment does not match the transaction hash and network");
|
|
75
|
+
commitment = {
|
|
76
|
+
transactionHash: transactionHash.slice(),
|
|
77
|
+
networkHash: networkHash.slice(),
|
|
78
|
+
blockHeight: known.blockHeight
|
|
79
|
+
};
|
|
80
|
+
lastStatus = {
|
|
81
|
+
status: "committed",
|
|
82
|
+
blockHeight: known.blockHeight
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
client.requireMethods([
|
|
86
|
+
"getNetworkInfo",
|
|
87
|
+
"getTransactionReceipt",
|
|
88
|
+
"getTransactionStatus"
|
|
89
|
+
]);
|
|
90
|
+
const deadline = performance.now() + timeoutMs;
|
|
91
|
+
let lastFailure;
|
|
92
|
+
let failures = 0;
|
|
93
|
+
let timedOut = false;
|
|
94
|
+
let stopReason;
|
|
95
|
+
const stop = (reason, error) => {
|
|
96
|
+
stopReason = reason;
|
|
97
|
+
return error;
|
|
98
|
+
};
|
|
99
|
+
const timeout = () => {
|
|
100
|
+
timedOut = true;
|
|
101
|
+
return new ObservationTimeout("Transaction observation timed out");
|
|
102
|
+
};
|
|
103
|
+
const run = (operation) => beforeDeadline(operation, deadline, options.signal, timeout);
|
|
104
|
+
const retain = (blockHeight) => {
|
|
105
|
+
if (commitment && commitment.blockHeight !== blockHeight) throw stop("commitmentConflict", rpcIncompatible("commitment", "Conflicting commitment heights for the same transaction"));
|
|
106
|
+
commitment = {
|
|
107
|
+
transactionHash: transactionHash.slice(),
|
|
108
|
+
networkHash: networkHash.slice(),
|
|
109
|
+
blockHeight
|
|
110
|
+
};
|
|
111
|
+
lastStatus = {
|
|
112
|
+
status: "committed",
|
|
113
|
+
blockHeight
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
try {
|
|
117
|
+
while (true) {
|
|
118
|
+
let retryAfterMs;
|
|
119
|
+
let networkVerified = false;
|
|
120
|
+
let failed = false;
|
|
121
|
+
try {
|
|
122
|
+
if (!equal((await run((signal) => client.getNetworkInfo({}, { signal }))).networkHash, networkHash)) throw stop("networkChanged", rpcIncompatible("network", "Observation endpoint network changed"));
|
|
123
|
+
networkVerified = true;
|
|
124
|
+
if (commitmentOnly && commitment) return structuredClone(commitment);
|
|
125
|
+
const receipt = await run((signal) => client.getTransactionReceipt({ transactionHash }, { signal }));
|
|
126
|
+
if (receipt) {
|
|
127
|
+
retain(receipt.blockHeight);
|
|
128
|
+
return commitmentOnly ? structuredClone(commitment) : receipt;
|
|
129
|
+
}
|
|
130
|
+
} catch (cause) {
|
|
131
|
+
if (cause instanceof ObservationTimeout || options.signal?.aborted) throw cause;
|
|
132
|
+
lastFailure = cause;
|
|
133
|
+
failed = true;
|
|
134
|
+
if (isThruputError(cause, "nativeRpcError") && cause.context.data) {
|
|
135
|
+
const data = cause.context.data;
|
|
136
|
+
if (data.kind === "backendDataInvalid" && data.observation) {
|
|
137
|
+
retain(data.observation.blockHeight);
|
|
138
|
+
if (commitmentOnly) return structuredClone(commitment);
|
|
139
|
+
}
|
|
140
|
+
if ("retryAfterMs" in data) retryAfterMs = data.retryAfterMs;
|
|
141
|
+
}
|
|
142
|
+
if (options.signal?.aborted || classifyReadError(cause, options) !== "transient") throw cause;
|
|
143
|
+
}
|
|
144
|
+
let observedStatus;
|
|
145
|
+
if (networkVerified) try {
|
|
146
|
+
const status = await run((signal) => client.getTransactionStatus({ transactionHash }, { signal }));
|
|
147
|
+
if (!(status instanceof UnsupportedRpcValue) && status.status === "committed") retain(status.blockHeight);
|
|
148
|
+
else if (!commitment) lastStatus = snapshotStatus(status);
|
|
149
|
+
observedStatus = status;
|
|
150
|
+
} catch (cause) {
|
|
151
|
+
if (cause instanceof ObservationTimeout || isThruputError(cause, "rpcIncompatible") || isThruputError(cause, "rpcValueInvalid") || isThruputError(cause, "rpcRequestInvalid") || classifyReadError(cause, options) === "permanent") throw cause;
|
|
152
|
+
options.signal?.throwIfAborted();
|
|
153
|
+
lastFailure = cause;
|
|
154
|
+
failed = true;
|
|
155
|
+
if (isThruputError(cause, "nativeRpcError") && cause.context.data && "retryAfterMs" in cause.context.data) {
|
|
156
|
+
const hint = cause.context.data.retryAfterMs;
|
|
157
|
+
if (hint !== void 0 && (retryAfterMs === void 0 || hint > retryAfterMs)) retryAfterMs = hint;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (observedStatus !== void 0) options.onStatus?.(observedStatus);
|
|
161
|
+
if (failed) failures++;
|
|
162
|
+
else {
|
|
163
|
+
failures = 0;
|
|
164
|
+
lastFailure = void 0;
|
|
165
|
+
}
|
|
166
|
+
if (commitmentOnly && commitment) return structuredClone(commitment);
|
|
167
|
+
const backoff = failures ? Math.min(5e3, Math.max(1, interval) * 2 ** Math.min(failures - 1, 8)) * (.5 + Math.random() / 2) : interval;
|
|
168
|
+
const remaining = deadline - performance.now();
|
|
169
|
+
if (retryAfterMs !== void 0 && retryAfterMs > BigInt(Math.max(0, Math.floor(remaining)))) throw timeout();
|
|
170
|
+
const delay = Math.max(backoff, Number(retryAfterMs ?? 0n));
|
|
171
|
+
await run((signal) => waitDelay(Math.min(delay, Math.max(0, remaining)), signal));
|
|
172
|
+
}
|
|
173
|
+
} catch (cause) {
|
|
174
|
+
const reason = options.signal?.aborted ? "cancelled" : timedOut ? timeoutReason(lastFailure, lastStatus) : stopReason ?? "observationFailed";
|
|
175
|
+
throw outcomeUnknown(transactionHash, reason, timedOut && reason !== "cancelled", cause instanceof ObservationTimeout ? lastFailure : cause, commitment && structuredClone(commitment), lastStatus);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/actions/public/requestAirdrop.ts
|
|
180
|
+
/** Perform exactly one faucet call. It neither polls nor repeats an ambiguous attempt. */
|
|
181
|
+
async function requestAirdropAttempt(client, request, options = {}) {
|
|
182
|
+
return client.faucet_requestAirdrop(request, options);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Call the faucet once, then observe a returned pending hash using read-only calls.
|
|
186
|
+
* When funding stops, throws code `fundingStopped` without permission to call the
|
|
187
|
+
* faucet again. `transaction` is present when the faucet identified a
|
|
188
|
+
* transaction; reconcile with `context.request.clientNonce`.
|
|
189
|
+
*/
|
|
190
|
+
async function requestAirdrop(client, options) {
|
|
191
|
+
const timeoutMs = options.timeoutMs ?? 6e4;
|
|
192
|
+
validateTimer(timeoutMs, "timeoutMs");
|
|
193
|
+
const request = {
|
|
194
|
+
recipient: new Uint8Array(options.recipient),
|
|
195
|
+
clientNonce: options.clientNonce ? new Uint8Array(options.clientNonce) : crypto.getRandomValues(new Uint8Array(16)),
|
|
196
|
+
networkHash: new Uint8Array(options.expectedNetworkHash ?? client.discovery.network.networkHash)
|
|
197
|
+
};
|
|
198
|
+
if (request.recipient.length !== 32 || request.networkHash.length !== 32 || request.clientNonce.length < 1 || request.clientNonce.length > 32) throw new RangeError("Funding requires 32-byte addresses/hashes and a 1–32 byte nonce");
|
|
199
|
+
client.requireMethods([
|
|
200
|
+
"faucet_requestAirdrop",
|
|
201
|
+
"getNetworkInfo",
|
|
202
|
+
"getTransactionReceipt",
|
|
203
|
+
"getTransactionStatus"
|
|
204
|
+
]);
|
|
205
|
+
const deadline = performance.now() + timeoutMs;
|
|
206
|
+
let lastResponse;
|
|
207
|
+
let timedOut = false;
|
|
208
|
+
const timeout = () => {
|
|
209
|
+
timedOut = true;
|
|
210
|
+
return new DOMException("Funding observation timed out", "TimeoutError");
|
|
211
|
+
};
|
|
212
|
+
const run = (operation) => beforeDeadline(operation, deadline, options.signal, timeout);
|
|
213
|
+
let phase = "network";
|
|
214
|
+
try {
|
|
215
|
+
if ((await run((signal) => client.getNetworkInfo({}, { signal }))).networkHash.some((v, i) => v !== request.networkHash[i])) throw rpcIncompatible("network", "Funding endpoint network does not match");
|
|
216
|
+
phase = "faucet";
|
|
217
|
+
lastResponse = await run((signal) => requestAirdropAttempt(client, {
|
|
218
|
+
recipient: request.recipient,
|
|
219
|
+
clientNonce: request.clientNonce
|
|
220
|
+
}, { signal }));
|
|
221
|
+
if (isUnsupportedRpcValue(lastResponse)) throw unsupported("Unsupported faucet response", lastResponse);
|
|
222
|
+
if (lastResponse.attemptStatus === "succeeded") {
|
|
223
|
+
if (isUnsupportedRpcValue(lastResponse.execution)) throw unsupported("Unsupported faucet execution outcome", lastResponse.execution);
|
|
224
|
+
return lastResponse;
|
|
225
|
+
}
|
|
226
|
+
if (!lastResponse.transactionHash) throw new Error("The faucet attempt is pending without a transaction");
|
|
227
|
+
phase = "observe";
|
|
228
|
+
const receipt = await waitForTransactionReceipt(client, lastResponse.transactionHash, {
|
|
229
|
+
expectedNetworkHash: request.networkHash,
|
|
230
|
+
timeoutMs: Math.max(0, deadline - performance.now()),
|
|
231
|
+
signal: options.signal
|
|
232
|
+
});
|
|
233
|
+
assertTransactionSuccess(receipt);
|
|
234
|
+
return {
|
|
235
|
+
attemptStatus: "succeeded",
|
|
236
|
+
recipient: lastResponse.recipient,
|
|
237
|
+
rawAmount: lastResponse.rawAmount,
|
|
238
|
+
transactionHash: receipt.transactionHash,
|
|
239
|
+
blockHeight: receipt.blockHeight,
|
|
240
|
+
execution: receipt.execution
|
|
241
|
+
};
|
|
242
|
+
} catch (cause) {
|
|
243
|
+
const cancelled = isCancellation(cause, options.signal);
|
|
244
|
+
const response = isUnsupportedRpcValue(lastResponse) ? void 0 : lastResponse;
|
|
245
|
+
const native = !cancelled && phase === "faucet" && isThruputError(cause, "nativeRpcError") ? cause.context.data : void 0;
|
|
246
|
+
const observed = !cancelled && phase === "observe" && isThruputError(cause) && cause.transaction && response?.transactionHash && bytesEqual(cause.transaction.hash, response.transactionHash) ? cause.transaction : void 0;
|
|
247
|
+
const receipt = observed?.receipt ?? (native && "receipt" in native ? native.receipt : void 0);
|
|
248
|
+
const hash = receipt?.transactionHash ?? observed?.hash ?? (native && "transactionHash" in native ? native.transactionHash : void 0) ?? response?.transactionHash;
|
|
249
|
+
const signed = native && "signedTransaction" in native ? native.signedTransaction : void 0;
|
|
250
|
+
const submission = signed && hash ? fundingSubmission(signed, request.networkHash, hash) : void 0;
|
|
251
|
+
const reason = options.signal?.aborted ? "cancelled" : timedOut ? "timeout" : native ? classifyReadError(cause) === "transient" ? "disconnected" : "nodeRejected" : "observationFailed";
|
|
252
|
+
const extra = submission ? { submission } : {};
|
|
253
|
+
const transaction = receipt ? {
|
|
254
|
+
...receiptFacts(receipt, reason),
|
|
255
|
+
...extra
|
|
256
|
+
} : observed ? {
|
|
257
|
+
hash: observed.hash,
|
|
258
|
+
outcome: observed.outcome,
|
|
259
|
+
reason: observed.reason
|
|
260
|
+
} : hash ? {
|
|
261
|
+
hash,
|
|
262
|
+
outcome: "unknown",
|
|
263
|
+
reason: response?.attemptStatus === "succeeded" ? "outcomeUnsupported" : reason,
|
|
264
|
+
...extra
|
|
265
|
+
} : void 0;
|
|
266
|
+
const committed = receipt ?? (response?.attemptStatus === "succeeded" ? response : void 0);
|
|
267
|
+
const knownCommitment = observed && isThruputError(cause, "transactionOutcomeUnknown") ? cause.context.knownCommitment : committed ? {
|
|
268
|
+
networkHash: request.networkHash.slice(),
|
|
269
|
+
transactionHash: new Uint8Array(committed.transactionHash),
|
|
270
|
+
blockHeight: committed.blockHeight
|
|
271
|
+
} : void 0;
|
|
272
|
+
throw new ThruputError("fundingStopped", "Funding observation stopped", {
|
|
273
|
+
context: {
|
|
274
|
+
request,
|
|
275
|
+
...lastResponse === void 0 ? {} : { lastResponse },
|
|
276
|
+
...knownCommitment ? { knownCommitment } : {}
|
|
277
|
+
},
|
|
278
|
+
cause,
|
|
279
|
+
...transaction ? { transaction } : {}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/** Signed faucet bytes as submission evidence, when they match the hash. */
|
|
284
|
+
function fundingSubmission(signedTransaction, networkHash, hash) {
|
|
285
|
+
try {
|
|
286
|
+
const evidence = createSubmissionEvidence(signedTransaction, networkHash);
|
|
287
|
+
return bytesEqual(evidence.transactionHash, hash) ? evidence : void 0;
|
|
288
|
+
} catch {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function bytesEqual(left, right) {
|
|
293
|
+
return left.length === right.length && left.every((byte, i) => byte === right[i]);
|
|
294
|
+
}
|
|
295
|
+
function unsupported(message, value) {
|
|
296
|
+
return new ThruputError("rpcValueUnsupported", message, { context: { value } });
|
|
297
|
+
}
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/actions/public/getContractEvents.ts
|
|
300
|
+
/**
|
|
301
|
+
* Fetch exactly one page using a generated event's filter and decoder.
|
|
302
|
+
*
|
|
303
|
+
* No additional pages are fetched. Pass the returned cursor into the next call
|
|
304
|
+
* with the same filters. Malformed events and unexpected signatures throw
|
|
305
|
+
* code `contractDecodeFailed` rather than silently disappearing from the page.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```ts
|
|
309
|
+
* const page = await getContractEvents(client, {
|
|
310
|
+
* event: thruput_erc20_if.v0_1.events.TransferEvent,
|
|
311
|
+
* addresses: [tokenAddress],
|
|
312
|
+
* topics: { to: accountAddress },
|
|
313
|
+
* start: { order: "ascending", anchor: { kind: "atBeginning" } },
|
|
314
|
+
* limit: 20,
|
|
315
|
+
* }, { signal });
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
async function getContractEvents(client, query, options) {
|
|
319
|
+
options?.signal?.throwIfAborted();
|
|
320
|
+
const { event, addresses, topics, ...pageQuery } = query;
|
|
321
|
+
const page = await client.getEvents({
|
|
322
|
+
...pageQuery,
|
|
323
|
+
filters: [event.filter({
|
|
324
|
+
addresses,
|
|
325
|
+
topics
|
|
326
|
+
})]
|
|
327
|
+
}, options);
|
|
328
|
+
return {
|
|
329
|
+
...page,
|
|
330
|
+
events: page.events.map(({ event: raw, ...identity }) => {
|
|
331
|
+
const decoded = event.decode(raw);
|
|
332
|
+
if (decoded === null) throw contractDecodeFailed("Event query returned an unexpected event signature");
|
|
333
|
+
return {
|
|
334
|
+
...decoded,
|
|
335
|
+
...identity,
|
|
336
|
+
address: raw.address
|
|
337
|
+
};
|
|
338
|
+
})
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/actions/public/historyWalk.ts
|
|
343
|
+
const compare = (a, b) => {
|
|
344
|
+
for (let i = 0; i < 3; i++) {
|
|
345
|
+
if (a[i] < b[i]) return -1;
|
|
346
|
+
if (a[i] > b[i]) return 1;
|
|
347
|
+
}
|
|
348
|
+
return 0;
|
|
349
|
+
};
|
|
350
|
+
/** Shared cross-page checks; single-page shape, filter and identity checks belong to RpcClient. */
|
|
351
|
+
async function* walkHistory(fetch, kind, scope, options) {
|
|
352
|
+
const order = "start" in scope ? scope.start.order : scope.order;
|
|
353
|
+
let cursor, watermark, lowerBound, upperBound, last;
|
|
354
|
+
const cursors = /* @__PURE__ */ new Set(), identities = /* @__PURE__ */ new Set();
|
|
355
|
+
for (;;) {
|
|
356
|
+
options.signal?.throwIfAborted();
|
|
357
|
+
const page = await fetch(cursor);
|
|
358
|
+
options.signal?.throwIfAborted();
|
|
359
|
+
const fail = (message) => {
|
|
360
|
+
throw new ThruputError("historyWalkFailed", message, { context: { page } });
|
|
361
|
+
};
|
|
362
|
+
const rows = kind === "events" ? page.events : page.transactions;
|
|
363
|
+
if (watermark === void 0) {
|
|
364
|
+
watermark = page.latestIndexedBlockHeight;
|
|
365
|
+
lowerBound = "start" in scope && order === "ascending" && scope.start.anchor.kind === "atHeight" ? scope.start.anchor.blockHeight : page.oldestIndexedBlockHeight;
|
|
366
|
+
upperBound = "start" in scope && order === "descending" && scope.start.anchor.kind === "atHeight" && scope.start.anchor.blockHeight < watermark ? scope.start.anchor.blockHeight : watermark;
|
|
367
|
+
}
|
|
368
|
+
if ("blockHeight" in scope) {
|
|
369
|
+
if (scope.blockHeight < page.oldestIndexedBlockHeight || scope.blockHeight > page.latestIndexedBlockHeight) fail("Requested block is outside current indexed coverage");
|
|
370
|
+
} else {
|
|
371
|
+
if (page.latestIndexedBlockHeight < watermark) fail("History coverage regressed below the initial watermark");
|
|
372
|
+
if (page.oldestIndexedBlockHeight > lowerBound) fail("History retention no longer covers the requested range");
|
|
373
|
+
}
|
|
374
|
+
for (const row of rows) {
|
|
375
|
+
if ("blockHeight" in scope ? row.blockHeight !== scope.blockHeight : row.blockHeight > upperBound || row.blockHeight < lowerBound) fail("History row is outside the fixed walk scope");
|
|
376
|
+
const hash = toHex0x(row.transactionHash), sequence = kind === "events" ? row.sequenceNumber : 0;
|
|
377
|
+
const identity = kind === "events" ? `${hash}/${sequence}` : hash;
|
|
378
|
+
if (identities.has(identity)) fail("History returned a duplicate identity across pages");
|
|
379
|
+
const key = [
|
|
380
|
+
row.blockHeight,
|
|
381
|
+
hash,
|
|
382
|
+
sequence
|
|
383
|
+
];
|
|
384
|
+
if (last && (order === "ascending" ? compare(last, key) >= 0 : compare(last, key) <= 0)) fail("History order did not advance across pages");
|
|
385
|
+
identities.add(identity);
|
|
386
|
+
last = key;
|
|
387
|
+
}
|
|
388
|
+
const next = page.nextCursor;
|
|
389
|
+
if (next !== null) {
|
|
390
|
+
if (cursors.has(next)) fail("History returned a repeated pagination cursor");
|
|
391
|
+
cursors.add(next);
|
|
392
|
+
}
|
|
393
|
+
yield page;
|
|
394
|
+
if (next === null) {
|
|
395
|
+
options.signal?.throwIfAborted();
|
|
396
|
+
if ("blockHeight" in scope) return;
|
|
397
|
+
return {
|
|
398
|
+
watermarkBlockHeight: watermark,
|
|
399
|
+
...order === "ascending" && lowerBound <= watermark ? { completedThroughBlockHeight: watermark } : {}
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
cursor = next;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
//#endregion
|
|
406
|
+
//#region src/actions/public/iterateEventPages.ts
|
|
407
|
+
/** Start a fixed event range. Saved opaque cursors remain available through getEvents. */
|
|
408
|
+
function iterateEventPages(client, query, options = {}) {
|
|
409
|
+
const snapshot = structuredClone(query);
|
|
410
|
+
if (!snapshot.start || snapshot.cursor !== void 0) throw new TypeError("Event walks require an explicit start");
|
|
411
|
+
return walkHistory((cursor) => client.getEvents(cursor === void 0 ? snapshot : {
|
|
412
|
+
filters: snapshot.filters,
|
|
413
|
+
limit: snapshot.limit,
|
|
414
|
+
cursor
|
|
415
|
+
}, options), "events", { start: snapshot.start }, options);
|
|
416
|
+
}
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/actions/public/readViews.ts
|
|
419
|
+
/**
|
|
420
|
+
* Read generated method requests against one shared committed snapshot.
|
|
421
|
+
* Contract aborts and faults are outcomes. Transport, freshness, and decoding
|
|
422
|
+
* failures reject the group. Calls are never split or emulated with separate views.
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
* ```ts
|
|
426
|
+
* const result = await client.readViews({ calls: [
|
|
427
|
+
* ERC20.v0_1.totalSupply.viewRequest({ address: token }),
|
|
428
|
+
* ERC20.v0_1.getBalanceOf.viewRequest({ address: token, args: { addr: owner } }),
|
|
429
|
+
* ] });
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
async function readViews(client, request, options) {
|
|
433
|
+
options?.signal?.throwIfAborted();
|
|
434
|
+
const calls = request.calls.map((call) => {
|
|
435
|
+
if ("minStateBlockHeight" in call) throw new TypeError("Set minStateBlockHeight on readViews, not on a prepared call");
|
|
436
|
+
return {
|
|
437
|
+
request: call.request,
|
|
438
|
+
name: call.method.name,
|
|
439
|
+
decode: call.method.decodeViewOutcome
|
|
440
|
+
};
|
|
441
|
+
});
|
|
442
|
+
const response = await client.simulateInvocations({
|
|
443
|
+
invocations: calls.map((call) => call.request),
|
|
444
|
+
...request.minStateBlockHeight === void 0 ? {} : { minStateBlockHeight: request.minStateBlockHeight }
|
|
445
|
+
}, options);
|
|
446
|
+
const results = calls.map((call, index) => {
|
|
447
|
+
try {
|
|
448
|
+
return call.decode({
|
|
449
|
+
...response.results[index],
|
|
450
|
+
stateBlockHeight: response.stateBlockHeight
|
|
451
|
+
});
|
|
452
|
+
} catch (cause) {
|
|
453
|
+
throw contractDecodeFailed(`Failed to decode readViews result ${index} (${call.name})`, { cause });
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
return {
|
|
457
|
+
stateBlockHeight: response.stateBlockHeight,
|
|
458
|
+
results
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region src/actions/public/iterateTransactionPages.ts
|
|
463
|
+
/** Transactions sent by this root address; incoming transfers use token events. */
|
|
464
|
+
function iterateTransactionsByRootAddress(client, query, options = {}) {
|
|
465
|
+
const snapshot = structuredClone(query);
|
|
466
|
+
if (!snapshot.start || snapshot.cursor !== void 0) throw new TypeError("Root-address walks require an explicit start");
|
|
467
|
+
return walkHistory((cursor) => client.getTransactionsByRootAddress(cursor === void 0 ? snapshot : {
|
|
468
|
+
address: snapshot.address,
|
|
469
|
+
limit: snapshot.limit,
|
|
470
|
+
cursor
|
|
471
|
+
}, options), "transactions", { start: snapshot.start }, options);
|
|
472
|
+
}
|
|
473
|
+
/** Walk one covered block. Completion never establishes a whole-chain checkpoint. */
|
|
474
|
+
function iterateTransactionsByBlock(client, query, options = {}) {
|
|
475
|
+
const snapshot = structuredClone(query);
|
|
476
|
+
if (!snapshot.start || snapshot.cursor !== void 0) throw new TypeError("Block walks require an explicit start");
|
|
477
|
+
return walkHistory((cursor) => client.getTransactionsByBlock(cursor === void 0 ? snapshot : {
|
|
478
|
+
blockHeight: snapshot.blockHeight,
|
|
479
|
+
limit: snapshot.limit,
|
|
480
|
+
cursor
|
|
481
|
+
}, options), "transactions", {
|
|
482
|
+
blockHeight: snapshot.blockHeight,
|
|
483
|
+
order: snapshot.start.order
|
|
484
|
+
}, options);
|
|
485
|
+
}
|
|
486
|
+
//#endregion
|
|
487
|
+
//#region src/actions/public/getContractSpec.ts
|
|
488
|
+
/**
|
|
489
|
+
* Resolve a current deployment and verify its embedded spec against its hash.
|
|
490
|
+
* Missing artifacts and invalid responses throw; neither means no deployment.
|
|
491
|
+
* The snapshot does not establish which implementation produced historical events.
|
|
492
|
+
*/
|
|
493
|
+
async function getContractSpec(client, request, options) {
|
|
494
|
+
client.requireMethods(["getContractDeployment", "getContractArtifact"]);
|
|
495
|
+
const address = new Uint8Array(request.address);
|
|
496
|
+
const result = await client.getContractDeployment({ address }, options);
|
|
497
|
+
if (!bytesEqual$1(address, result.address)) throw contractVerificationFailed("Contract deployment address mismatch");
|
|
498
|
+
if (result.deployment === null) return {
|
|
499
|
+
...result,
|
|
500
|
+
artifactSpec: null
|
|
501
|
+
};
|
|
502
|
+
return {
|
|
503
|
+
...result,
|
|
504
|
+
artifactSpec: await readDeploymentSpec(client, result.deployment, options)
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
/** Shared identity validation for explicit deployments and effective contract selection. */
|
|
508
|
+
async function readDeploymentSpec(client, deployment, options) {
|
|
509
|
+
const artifact = await client.getContractArtifact({ hash: deployment.hash }, options);
|
|
510
|
+
if (!bytesEqual$1(artifact.hash, deployment.hash)) throw contractVerificationFailed("Contract artifact response hash mismatch");
|
|
511
|
+
const artifactSpec = readContractArtifactSpec(artifact.contractXdr, sha256Hash(deployment.hash));
|
|
512
|
+
const contract = deserialize(artifact.contractXdr, codec.Contract);
|
|
513
|
+
const size = contract.contract_type === ContractType.kRv32 ? contract.rv32_contract.data.length : 0;
|
|
514
|
+
if (contract.contract_type !== deployment.contractType || size !== deployment.size) throw contractVerificationFailed("Contract artifact does not match deployment metadata");
|
|
515
|
+
return artifactSpec;
|
|
516
|
+
}
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region src/actions/public/getEffectiveContractSpec.ts
|
|
519
|
+
const nativeWalletHash = hashContract({
|
|
520
|
+
contract_type: ContractType.kNative,
|
|
521
|
+
native_contract_id: HogexecPrecompiledNativeContracts.kNativeContractDefaultWallet
|
|
522
|
+
});
|
|
523
|
+
/**
|
|
524
|
+
* Discover current contract selection without inferring authorization or historical identity.
|
|
525
|
+
* Root context allows the chain-configured fallback; nested excludes that fallback.
|
|
526
|
+
* Transaction-local deployments are outside this committed-state reading.
|
|
527
|
+
*/
|
|
528
|
+
async function getEffectiveContractSpec(client, request, options) {
|
|
529
|
+
client.requireMethods(["getEffectiveContract", "getContractArtifact"]);
|
|
530
|
+
const address = new Uint8Array(request.address);
|
|
531
|
+
const context = request.context;
|
|
532
|
+
const result = await client.getEffectiveContract({
|
|
533
|
+
address,
|
|
534
|
+
context
|
|
535
|
+
}, options);
|
|
536
|
+
if (!bytesEqual$1(address, result.address) || result.context !== context) throw contractVerificationFailed("Effective contract request identity mismatch");
|
|
537
|
+
if (result.selection instanceof UnsupportedRpcValue) throw new ThruputError("rpcValueUnsupported", "Unsupported effective contract selection", { context: { value: result.selection } });
|
|
538
|
+
if (result.selection === null) return {
|
|
539
|
+
...result,
|
|
540
|
+
artifactSpec: null,
|
|
541
|
+
nativeInterface: null
|
|
542
|
+
};
|
|
543
|
+
if (context === "nested" && result.selection.source === "networkDefault") throw contractVerificationFailed("Network default cannot apply to a nested invocation");
|
|
544
|
+
const contract = result.selection.contract;
|
|
545
|
+
const artifactSpec = await readDeploymentSpec(client, contract, options);
|
|
546
|
+
const nativeInterface = artifactSpec.kind === "native" && bytesEqual$1(contract.hash, nativeWalletHash) ? {
|
|
547
|
+
name: "DefaultWallet",
|
|
548
|
+
spec
|
|
549
|
+
} : null;
|
|
550
|
+
return {
|
|
551
|
+
...result,
|
|
552
|
+
artifactSpec,
|
|
553
|
+
nativeInterface
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
//#endregion
|
|
557
|
+
//#region src/actions/public/decodeWalletRequests.ts
|
|
558
|
+
/**
|
|
559
|
+
* Interpret a known DefaultWallet root using built-in binding descriptors.
|
|
560
|
+
* Call only after identifying the root as DefaultWallet; matching selectors
|
|
561
|
+
* alone do not establish wallet identity. Malformed recognized inputs throw,
|
|
562
|
+
* as does an `execute` that mints or forwards auth tokens.
|
|
563
|
+
*/
|
|
564
|
+
function decodeDefaultWalletRequests(root) {
|
|
565
|
+
if (bytesEqual$1(root.entrypoint, DefaultWallet.v0_1.execute.entrypoint)) {
|
|
566
|
+
const { mints, calls } = DefaultWallet.v0_1.execute.decodeArgs(root.calldata);
|
|
567
|
+
if (mints.length > 0 || calls.some((call) => call.tokens.length > 0)) throw new Error("DefaultWallet.execute mints or forwards auth tokens, which requested calls cannot represent");
|
|
568
|
+
return {
|
|
569
|
+
wrapper: "DefaultWallet.execute",
|
|
570
|
+
requestedCalls: calls.map((call) => ({
|
|
571
|
+
invoked_address: call.target,
|
|
572
|
+
entrypoint: contractEntrypointID(call.entrypoint),
|
|
573
|
+
gas_limit: gasAmount(call.gas_limit),
|
|
574
|
+
calldata: calldata(call.calldata)
|
|
575
|
+
}))
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
if (bytesEqual$1(root.entrypoint, DefaultWallet.v0_1.deploy.entrypoint)) {
|
|
579
|
+
const args = DefaultWallet.v0_1.deploy.decodeArgs(root.calldata);
|
|
580
|
+
const init = args.initializer;
|
|
581
|
+
return {
|
|
582
|
+
wrapper: "DefaultWallet.deploy",
|
|
583
|
+
requestedCalls: init ? [{
|
|
584
|
+
invoked_address: deriveContractAddress(root.invoked_address, sha256Hash(args.nonce), sha256Hash(args.contractHash)),
|
|
585
|
+
entrypoint: contractEntrypointID(init.entrypoint),
|
|
586
|
+
gas_limit: gasAmount(init.gas_limit),
|
|
587
|
+
calldata: calldata(init.calldata)
|
|
588
|
+
}] : []
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
return null;
|
|
592
|
+
}
|
|
593
|
+
//#endregion
|
|
594
|
+
//#region src/actions/public/readTransactionInput.ts
|
|
595
|
+
/**
|
|
596
|
+
* Read and authenticate a retained Transaction, including its root invocation.
|
|
597
|
+
* Unavailable does not prove nonexecution. A matching body hash authenticates
|
|
598
|
+
* neither signatures nor the reported block height, and does not imply success.
|
|
599
|
+
*/
|
|
600
|
+
async function readTransactionInput(client, request, options) {
|
|
601
|
+
client.requireMethods(["getTransactionInput"]);
|
|
602
|
+
const hash = new Uint8Array(request.transactionHash);
|
|
603
|
+
const result = await client.getTransactionInput({ transactionHash: hash }, options);
|
|
604
|
+
if (result instanceof UnsupportedRpcValue || result.status === "unavailable") return result;
|
|
605
|
+
try {
|
|
606
|
+
if (result.transactionXdr.length > 4 * 1024 * 1024) throw new Error("Transaction input exceeds 4 MiB");
|
|
607
|
+
if (!bytesEqual$1(result.transactionHash, hash) || !bytesEqual$1(sha256(result.transactionXdr), hash)) throw new Error("Retained transaction input hash mismatch");
|
|
608
|
+
const transaction = deserialize(result.transactionXdr, codec.Transaction);
|
|
609
|
+
if (!bytesEqual$1(serialize(transaction, codec.Transaction), result.transactionXdr)) throw new Error("Noncanonical Transaction XDR");
|
|
610
|
+
return {
|
|
611
|
+
...result,
|
|
612
|
+
transaction
|
|
613
|
+
};
|
|
614
|
+
} catch (cause) {
|
|
615
|
+
throw contractVerificationFailed(errorText(cause) ?? "Invalid transaction input", { cause });
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
//#endregion
|
|
619
|
+
//#region src/actions/wallet/sendTransaction.ts
|
|
620
|
+
/**
|
|
621
|
+
* Serialize and submit once through the native RPC boundary.
|
|
622
|
+
* Every failure has `transaction` facts with the signed bytes and destination
|
|
623
|
+
* discovery network; that network does not prove the signing network of an
|
|
624
|
+
* already-signed envelope. Unknown admission throws code
|
|
625
|
+
* `transactionAdmissionUnsupported`. RPC and transport failures keep their
|
|
626
|
+
* code, with outcome `unknown`, or `notSubmitted` for a local request error.
|
|
627
|
+
*/
|
|
628
|
+
async function sendTransaction(client, signedTx, options) {
|
|
629
|
+
const evidence = createSubmissionEvidence(serialize(signedTx, codec.SignedTransaction), client.discovery.network.networkHash);
|
|
630
|
+
if (options?.signal?.aborted) throw transactionNotSubmitted(evidence, "cancelled", options.signal.reason);
|
|
631
|
+
let result;
|
|
632
|
+
try {
|
|
633
|
+
result = await client.sendTransaction({ signedTransaction: evidence.signedTransaction }, options);
|
|
634
|
+
} catch (cause) {
|
|
635
|
+
const signal = options?.signal;
|
|
636
|
+
if (isCancellation(cause, signal)) throw transactionOutcomeUnknown(evidence, "cancelled", cause);
|
|
637
|
+
const local = isLocalRequestError(cause, signal);
|
|
638
|
+
const reason = local ? "requestInvalid" : reasonAfterDispatch(cause, signal);
|
|
639
|
+
if (!isThruputError(cause)) throw transactionOutcomeUnknown(evidence, reason, cause);
|
|
640
|
+
throw withTransactionFacts(cause, {
|
|
641
|
+
hash: evidence.transactionHash,
|
|
642
|
+
outcome: local ? "notSubmitted" : "unknown",
|
|
643
|
+
reason,
|
|
644
|
+
submission: evidence
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
assertTransactionAdmission(result, evidence);
|
|
648
|
+
return sha256Hash(result.transactionHash);
|
|
649
|
+
}
|
|
650
|
+
//#endregion
|
|
651
|
+
export { getContractSpec as a, readViews as c, requestAirdrop as d, requestAirdropAttempt as f, getEffectiveContractSpec as i, iterateEventPages as l, waitForTransactionReceipt as m, readTransactionInput as n, iterateTransactionsByBlock as o, waitForCommitment as p, decodeDefaultWalletRequests as r, iterateTransactionsByRootAddress as s, sendTransaction as t, getContractEvents as u };
|
|
652
|
+
|
|
653
|
+
//# sourceMappingURL=actions-UEYKD22C.js.map
|