@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,30 +1,193 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const require_readError = require("./readError-
|
|
5
|
-
const require_sendInvocation = require("./sendInvocation-
|
|
6
|
-
const require_dev_wallet = require("./dev_wallet-
|
|
1
|
+
const require_decimal = require("./decimal-BX7abv5J.cjs");
|
|
2
|
+
const require_hex = require("./hex-CSDZ9d6z.cjs");
|
|
3
|
+
const require_contract = require("./contract-D_vxUudr.cjs");
|
|
4
|
+
const require_readError = require("./readError-COcEDNoZ.cjs");
|
|
5
|
+
const require_sendInvocation = require("./sendInvocation-185ZJrta.cjs");
|
|
6
|
+
const require_dev_wallet = require("./dev_wallet-BVChhV6j.cjs");
|
|
7
7
|
let _thruputchain_protocol = require("@thruputchain/protocol");
|
|
8
8
|
let _noble_hashes_sha2_js = require("@noble/hashes/sha2.js");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
let _thruputchain_protocol_utils = require("@thruputchain/protocol/utils");
|
|
10
|
+
//#region src/actions/public/waitForTransactionReceipt.ts
|
|
11
|
+
/**
|
|
12
|
+
* Observation stopped: code `transactionOutcomeUnknown`. Neither a timeout nor
|
|
13
|
+
* cancellation proves that the transaction did not execute.
|
|
14
|
+
*/
|
|
15
|
+
function outcomeUnknown(transactionHash, reason, timedOut, cause, knownCommitment, lastStatus) {
|
|
16
|
+
return new require_decimal.ThruputError("transactionOutcomeUnknown", timedOut ? `Timed out waiting for transaction ${(0, _thruputchain_protocol_utils.toBase58)(transactionHash)}` : `Could not observe transaction ${(0, _thruputchain_protocol_utils.toBase58)(transactionHash)}`, {
|
|
17
|
+
context: {
|
|
18
|
+
...knownCommitment ? { knownCommitment } : {},
|
|
19
|
+
...lastStatus ? { lastStatus } : {}
|
|
20
|
+
},
|
|
21
|
+
...cause === void 0 ? {} : { cause },
|
|
22
|
+
transaction: {
|
|
23
|
+
hash: transactionHash,
|
|
24
|
+
outcome: "unknown",
|
|
25
|
+
reason
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** The observation deadline. Private, so read-error handling never retries it. */
|
|
30
|
+
var ObservationTimeout = class extends Error {};
|
|
31
|
+
/** The reason for a timeout: the last read failure or node status, when known. */
|
|
32
|
+
function timeoutReason(lastFailure, lastStatus) {
|
|
33
|
+
if (lastFailure !== void 0) return "disconnected";
|
|
34
|
+
if (lastStatus === void 0) return "timeout";
|
|
35
|
+
if (lastStatus instanceof require_decimal.UnsupportedRpcValue) return "statusUnknown";
|
|
36
|
+
if (lastStatus.status === "unknown" || lastStatus.status === "other") return "statusUnknown";
|
|
37
|
+
if (lastStatus.status === "recentFailure") return "recentFailure";
|
|
38
|
+
return "timeout";
|
|
39
|
+
}
|
|
40
|
+
const equal = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
|
|
41
|
+
/**
|
|
42
|
+
* Return any committed receipt, including failed execution. Never sign or resubmit.
|
|
43
|
+
* When observation stops, throws code `transactionOutcomeUnknown` with
|
|
44
|
+
* `transaction.reason` set to why it stopped.
|
|
45
|
+
*/
|
|
46
|
+
async function waitForTransactionReceipt(client, transactionHash, options = {}) {
|
|
47
|
+
return await observe(client, transactionHash, options, false);
|
|
48
|
+
}
|
|
49
|
+
/** Observe commitment independently of receipt availability or execution success. */
|
|
50
|
+
async function waitForCommitment(client, transactionHash, options = {}) {
|
|
51
|
+
return await observe(client, transactionHash, options, true);
|
|
52
|
+
}
|
|
53
|
+
function snapshotStatus(status) {
|
|
54
|
+
const copy = (value) => {
|
|
55
|
+
if (value instanceof require_decimal.UnsupportedRpcValue) return new require_decimal.UnsupportedRpcValue(structuredClone(value.raw));
|
|
56
|
+
if (Array.isArray(value)) return value.map(copy);
|
|
57
|
+
if (ArrayBuffer.isView(value)) return structuredClone(value);
|
|
58
|
+
if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, copy(entry)]));
|
|
59
|
+
return value;
|
|
60
|
+
};
|
|
61
|
+
return copy(status);
|
|
62
|
+
}
|
|
63
|
+
async function observe(client, hash, options, commitmentOnly) {
|
|
64
|
+
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
65
|
+
const interval = options.pollingIntervalMs ?? 250;
|
|
66
|
+
require_sendInvocation.validateTimer(timeoutMs, "timeoutMs");
|
|
67
|
+
require_sendInvocation.validateTimer(interval, "pollingIntervalMs");
|
|
68
|
+
const transactionHash = new Uint8Array(hash);
|
|
69
|
+
const networkHash = new Uint8Array(options.expectedNetworkHash ?? client.discovery.network.networkHash);
|
|
70
|
+
if (transactionHash.length !== 32 || networkHash.length !== 32) throw new RangeError("Transaction and network hashes must contain 32 bytes");
|
|
71
|
+
let commitment;
|
|
72
|
+
let lastStatus;
|
|
73
|
+
if (options.knownCommitment) {
|
|
74
|
+
const known = options.knownCommitment;
|
|
75
|
+
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");
|
|
76
|
+
commitment = {
|
|
77
|
+
transactionHash: transactionHash.slice(),
|
|
78
|
+
networkHash: networkHash.slice(),
|
|
79
|
+
blockHeight: known.blockHeight
|
|
80
|
+
};
|
|
81
|
+
lastStatus = {
|
|
82
|
+
status: "committed",
|
|
83
|
+
blockHeight: known.blockHeight
|
|
84
|
+
};
|
|
21
85
|
}
|
|
22
|
-
|
|
86
|
+
client.requireMethods([
|
|
87
|
+
"getNetworkInfo",
|
|
88
|
+
"getTransactionReceipt",
|
|
89
|
+
"getTransactionStatus"
|
|
90
|
+
]);
|
|
91
|
+
const deadline = performance.now() + timeoutMs;
|
|
92
|
+
let lastFailure;
|
|
93
|
+
let failures = 0;
|
|
94
|
+
let timedOut = false;
|
|
95
|
+
let stopReason;
|
|
96
|
+
const stop = (reason, error) => {
|
|
97
|
+
stopReason = reason;
|
|
98
|
+
return error;
|
|
99
|
+
};
|
|
100
|
+
const timeout = () => {
|
|
101
|
+
timedOut = true;
|
|
102
|
+
return new ObservationTimeout("Transaction observation timed out");
|
|
103
|
+
};
|
|
104
|
+
const run = (operation) => require_sendInvocation.beforeDeadline(operation, deadline, options.signal, timeout);
|
|
105
|
+
const retain = (blockHeight) => {
|
|
106
|
+
if (commitment && commitment.blockHeight !== blockHeight) throw stop("commitmentConflict", require_readError.rpcIncompatible("commitment", "Conflicting commitment heights for the same transaction"));
|
|
107
|
+
commitment = {
|
|
108
|
+
transactionHash: transactionHash.slice(),
|
|
109
|
+
networkHash: networkHash.slice(),
|
|
110
|
+
blockHeight
|
|
111
|
+
};
|
|
112
|
+
lastStatus = {
|
|
113
|
+
status: "committed",
|
|
114
|
+
blockHeight
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
try {
|
|
118
|
+
while (true) {
|
|
119
|
+
let retryAfterMs;
|
|
120
|
+
let networkVerified = false;
|
|
121
|
+
let failed = false;
|
|
122
|
+
try {
|
|
123
|
+
if (!equal((await run((signal) => client.getNetworkInfo({}, { signal }))).networkHash, networkHash)) throw stop("networkChanged", require_readError.rpcIncompatible("network", "Observation endpoint network changed"));
|
|
124
|
+
networkVerified = true;
|
|
125
|
+
if (commitmentOnly && commitment) return structuredClone(commitment);
|
|
126
|
+
const receipt = await run((signal) => client.getTransactionReceipt({ transactionHash }, { signal }));
|
|
127
|
+
if (receipt) {
|
|
128
|
+
retain(receipt.blockHeight);
|
|
129
|
+
return commitmentOnly ? structuredClone(commitment) : receipt;
|
|
130
|
+
}
|
|
131
|
+
} catch (cause) {
|
|
132
|
+
if (cause instanceof ObservationTimeout || options.signal?.aborted) throw cause;
|
|
133
|
+
lastFailure = cause;
|
|
134
|
+
failed = true;
|
|
135
|
+
if (require_decimal.isThruputError(cause, "nativeRpcError") && cause.context.data) {
|
|
136
|
+
const data = cause.context.data;
|
|
137
|
+
if (data.kind === "backendDataInvalid" && data.observation) {
|
|
138
|
+
retain(data.observation.blockHeight);
|
|
139
|
+
if (commitmentOnly) return structuredClone(commitment);
|
|
140
|
+
}
|
|
141
|
+
if ("retryAfterMs" in data) retryAfterMs = data.retryAfterMs;
|
|
142
|
+
}
|
|
143
|
+
if (options.signal?.aborted || require_readError.classifyReadError(cause, options) !== "transient") throw cause;
|
|
144
|
+
}
|
|
145
|
+
let observedStatus;
|
|
146
|
+
if (networkVerified) try {
|
|
147
|
+
const status = await run((signal) => client.getTransactionStatus({ transactionHash }, { signal }));
|
|
148
|
+
if (!(status instanceof require_decimal.UnsupportedRpcValue) && status.status === "committed") retain(status.blockHeight);
|
|
149
|
+
else if (!commitment) lastStatus = snapshotStatus(status);
|
|
150
|
+
observedStatus = status;
|
|
151
|
+
} catch (cause) {
|
|
152
|
+
if (cause instanceof ObservationTimeout || require_decimal.isThruputError(cause, "rpcIncompatible") || require_decimal.isThruputError(cause, "rpcValueInvalid") || require_decimal.isThruputError(cause, "rpcRequestInvalid") || require_readError.classifyReadError(cause, options) === "permanent") throw cause;
|
|
153
|
+
options.signal?.throwIfAborted();
|
|
154
|
+
lastFailure = cause;
|
|
155
|
+
failed = true;
|
|
156
|
+
if (require_decimal.isThruputError(cause, "nativeRpcError") && cause.context.data && "retryAfterMs" in cause.context.data) {
|
|
157
|
+
const hint = cause.context.data.retryAfterMs;
|
|
158
|
+
if (hint !== void 0 && (retryAfterMs === void 0 || hint > retryAfterMs)) retryAfterMs = hint;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (observedStatus !== void 0) options.onStatus?.(observedStatus);
|
|
162
|
+
if (failed) failures++;
|
|
163
|
+
else {
|
|
164
|
+
failures = 0;
|
|
165
|
+
lastFailure = void 0;
|
|
166
|
+
}
|
|
167
|
+
if (commitmentOnly && commitment) return structuredClone(commitment);
|
|
168
|
+
const backoff = failures ? Math.min(5e3, Math.max(1, interval) * 2 ** Math.min(failures - 1, 8)) * (.5 + Math.random() / 2) : interval;
|
|
169
|
+
const remaining = deadline - performance.now();
|
|
170
|
+
if (retryAfterMs !== void 0 && retryAfterMs > BigInt(Math.max(0, Math.floor(remaining)))) throw timeout();
|
|
171
|
+
const delay = Math.max(backoff, Number(retryAfterMs ?? 0n));
|
|
172
|
+
await run((signal) => require_sendInvocation.waitDelay(Math.min(delay, Math.max(0, remaining)), signal));
|
|
173
|
+
}
|
|
174
|
+
} catch (cause) {
|
|
175
|
+
const reason = options.signal?.aborted ? "cancelled" : timedOut ? timeoutReason(lastFailure, lastStatus) : stopReason ?? "observationFailed";
|
|
176
|
+
throw outcomeUnknown(transactionHash, reason, timedOut && reason !== "cancelled", cause instanceof ObservationTimeout ? lastFailure : cause, commitment && structuredClone(commitment), lastStatus);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/actions/public/requestAirdrop.ts
|
|
23
181
|
/** Perform exactly one faucet call. It neither polls nor repeats an ambiguous attempt. */
|
|
24
182
|
async function requestAirdropAttempt(client, request, options = {}) {
|
|
25
183
|
return client.faucet_requestAirdrop(request, options);
|
|
26
184
|
}
|
|
27
|
-
/**
|
|
185
|
+
/**
|
|
186
|
+
* Call the faucet once, then observe a returned pending hash using read-only calls.
|
|
187
|
+
* When funding stops, throws code `fundingStopped` without permission to call the
|
|
188
|
+
* faucet again. `transaction` is present when the faucet identified a
|
|
189
|
+
* transaction; reconcile with `context.request.clientNonce`.
|
|
190
|
+
*/
|
|
28
191
|
async function requestAirdrop(client, options) {
|
|
29
192
|
const timeoutMs = options.timeoutMs ?? 6e4;
|
|
30
193
|
require_sendInvocation.validateTimer(timeoutMs, "timeoutMs");
|
|
@@ -42,21 +205,28 @@ async function requestAirdrop(client, options) {
|
|
|
42
205
|
]);
|
|
43
206
|
const deadline = performance.now() + timeoutMs;
|
|
44
207
|
let lastResponse;
|
|
45
|
-
|
|
208
|
+
let timedOut = false;
|
|
209
|
+
const timeout = () => {
|
|
210
|
+
timedOut = true;
|
|
211
|
+
return new DOMException("Funding observation timed out", "TimeoutError");
|
|
212
|
+
};
|
|
46
213
|
const run = (operation) => require_sendInvocation.beforeDeadline(operation, deadline, options.signal, timeout);
|
|
214
|
+
let phase = "network";
|
|
47
215
|
try {
|
|
48
|
-
if ((await run((signal) => client.getNetworkInfo({}, { signal }))).networkHash.some((v, i) => v !== request.networkHash[i])) throw
|
|
216
|
+
if ((await run((signal) => client.getNetworkInfo({}, { signal }))).networkHash.some((v, i) => v !== request.networkHash[i])) throw require_readError.rpcIncompatible("network", "Funding endpoint network does not match");
|
|
217
|
+
phase = "faucet";
|
|
49
218
|
lastResponse = await run((signal) => requestAirdropAttempt(client, {
|
|
50
219
|
recipient: request.recipient,
|
|
51
220
|
clientNonce: request.clientNonce
|
|
52
221
|
}, { signal }));
|
|
53
|
-
if (lastResponse
|
|
222
|
+
if (require_decimal.isUnsupportedRpcValue(lastResponse)) throw unsupported("Unsupported faucet response", lastResponse);
|
|
54
223
|
if (lastResponse.attemptStatus === "succeeded") {
|
|
55
|
-
if (lastResponse.execution
|
|
224
|
+
if (require_decimal.isUnsupportedRpcValue(lastResponse.execution)) throw unsupported("Unsupported faucet execution outcome", lastResponse.execution);
|
|
56
225
|
return lastResponse;
|
|
57
226
|
}
|
|
58
|
-
if (!lastResponse.transactionHash) throw new Error("
|
|
59
|
-
|
|
227
|
+
if (!lastResponse.transactionHash) throw new Error("The faucet attempt is pending without a transaction");
|
|
228
|
+
phase = "observe";
|
|
229
|
+
const receipt = await waitForTransactionReceipt(client, lastResponse.transactionHash, {
|
|
60
230
|
expectedNetworkHash: request.networkHash,
|
|
61
231
|
timeoutMs: Math.max(0, deadline - performance.now()),
|
|
62
232
|
signal: options.signal
|
|
@@ -71,15 +241,61 @@ async function requestAirdrop(client, options) {
|
|
|
71
241
|
execution: receipt.execution
|
|
72
242
|
};
|
|
73
243
|
} catch (cause) {
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
244
|
+
const cancelled = require_sendInvocation.isCancellation(cause, options.signal);
|
|
245
|
+
const response = require_decimal.isUnsupportedRpcValue(lastResponse) ? void 0 : lastResponse;
|
|
246
|
+
const native = !cancelled && phase === "faucet" && require_decimal.isThruputError(cause, "nativeRpcError") ? cause.context.data : void 0;
|
|
247
|
+
const observed = !cancelled && phase === "observe" && require_decimal.isThruputError(cause) && cause.transaction && response?.transactionHash && bytesEqual(cause.transaction.hash, response.transactionHash) ? cause.transaction : void 0;
|
|
248
|
+
const receipt = observed?.receipt ?? (native && "receipt" in native ? native.receipt : void 0);
|
|
249
|
+
const hash = receipt?.transactionHash ?? observed?.hash ?? (native && "transactionHash" in native ? native.transactionHash : void 0) ?? response?.transactionHash;
|
|
250
|
+
const signed = native && "signedTransaction" in native ? native.signedTransaction : void 0;
|
|
251
|
+
const submission = signed && hash ? fundingSubmission(signed, request.networkHash, hash) : void 0;
|
|
252
|
+
const reason = options.signal?.aborted ? "cancelled" : timedOut ? "timeout" : native ? require_readError.classifyReadError(cause) === "transient" ? "disconnected" : "nodeRejected" : "observationFailed";
|
|
253
|
+
const extra = submission ? { submission } : {};
|
|
254
|
+
const transaction = receipt ? {
|
|
255
|
+
...require_contract.receiptFacts(receipt, reason),
|
|
256
|
+
...extra
|
|
257
|
+
} : observed ? {
|
|
258
|
+
hash: observed.hash,
|
|
259
|
+
outcome: observed.outcome,
|
|
260
|
+
reason: observed.reason
|
|
261
|
+
} : hash ? {
|
|
262
|
+
hash,
|
|
263
|
+
outcome: "unknown",
|
|
264
|
+
reason: response?.attemptStatus === "succeeded" ? "outcomeUnsupported" : reason,
|
|
265
|
+
...extra
|
|
266
|
+
} : void 0;
|
|
267
|
+
const committed = receipt ?? (response?.attemptStatus === "succeeded" ? response : void 0);
|
|
268
|
+
const knownCommitment = observed && require_decimal.isThruputError(cause, "transactionOutcomeUnknown") ? cause.context.knownCommitment : committed ? {
|
|
77
269
|
networkHash: request.networkHash.slice(),
|
|
78
|
-
transactionHash: new Uint8Array(
|
|
79
|
-
blockHeight:
|
|
80
|
-
} : void 0
|
|
270
|
+
transactionHash: new Uint8Array(committed.transactionHash),
|
|
271
|
+
blockHeight: committed.blockHeight
|
|
272
|
+
} : void 0;
|
|
273
|
+
throw new require_decimal.ThruputError("fundingStopped", "Funding observation stopped", {
|
|
274
|
+
context: {
|
|
275
|
+
request,
|
|
276
|
+
...lastResponse === void 0 ? {} : { lastResponse },
|
|
277
|
+
...knownCommitment ? { knownCommitment } : {}
|
|
278
|
+
},
|
|
279
|
+
cause,
|
|
280
|
+
...transaction ? { transaction } : {}
|
|
281
|
+
});
|
|
81
282
|
}
|
|
82
283
|
}
|
|
284
|
+
/** Signed faucet bytes as submission evidence, when they match the hash. */
|
|
285
|
+
function fundingSubmission(signedTransaction, networkHash, hash) {
|
|
286
|
+
try {
|
|
287
|
+
const evidence = require_sendInvocation.createSubmissionEvidence(signedTransaction, networkHash);
|
|
288
|
+
return bytesEqual(evidence.transactionHash, hash) ? evidence : void 0;
|
|
289
|
+
} catch {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function bytesEqual(left, right) {
|
|
294
|
+
return left.length === right.length && left.every((byte, i) => byte === right[i]);
|
|
295
|
+
}
|
|
296
|
+
function unsupported(message, value) {
|
|
297
|
+
return new require_decimal.ThruputError("rpcValueUnsupported", message, { context: { value } });
|
|
298
|
+
}
|
|
83
299
|
//#endregion
|
|
84
300
|
//#region src/actions/public/getContractEvents.ts
|
|
85
301
|
/**
|
|
@@ -87,7 +303,7 @@ async function requestAirdrop(client, options) {
|
|
|
87
303
|
*
|
|
88
304
|
* No additional pages are fetched. Pass the returned cursor into the next call
|
|
89
305
|
* with the same filters. Malformed events and unexpected signatures throw
|
|
90
|
-
*
|
|
306
|
+
* code `contractDecodeFailed` rather than silently disappearing from the page.
|
|
91
307
|
*
|
|
92
308
|
* @example
|
|
93
309
|
* ```ts
|
|
@@ -114,7 +330,7 @@ async function getContractEvents(client, query, options) {
|
|
|
114
330
|
...page,
|
|
115
331
|
events: page.events.map(({ event: raw, ...identity }) => {
|
|
116
332
|
const decoded = event.decode(raw);
|
|
117
|
-
if (decoded === null) throw
|
|
333
|
+
if (decoded === null) throw require_contract.contractDecodeFailed("Event query returned an unexpected event signature");
|
|
118
334
|
return {
|
|
119
335
|
...decoded,
|
|
120
336
|
...identity,
|
|
@@ -125,14 +341,6 @@ async function getContractEvents(client, query, options) {
|
|
|
125
341
|
}
|
|
126
342
|
//#endregion
|
|
127
343
|
//#region src/actions/public/historyWalk.ts
|
|
128
|
-
var HistoryWalkError = class extends Error {
|
|
129
|
-
page;
|
|
130
|
-
constructor(message, page) {
|
|
131
|
-
super(message);
|
|
132
|
-
this.page = page;
|
|
133
|
-
this.name = "HistoryWalkError";
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
344
|
const compare = (a, b) => {
|
|
137
345
|
for (let i = 0; i < 3; i++) {
|
|
138
346
|
if (a[i] < b[i]) return -1;
|
|
@@ -150,7 +358,7 @@ async function* walkHistory(fetch, kind, scope, options) {
|
|
|
150
358
|
const page = await fetch(cursor);
|
|
151
359
|
options.signal?.throwIfAborted();
|
|
152
360
|
const fail = (message) => {
|
|
153
|
-
throw new
|
|
361
|
+
throw new require_decimal.ThruputError("historyWalkFailed", message, { context: { page } });
|
|
154
362
|
};
|
|
155
363
|
const rows = kind === "events" ? page.events : page.transactions;
|
|
156
364
|
if (watermark === void 0) {
|
|
@@ -243,7 +451,7 @@ async function readViews(client, request, options) {
|
|
|
243
451
|
stateBlockHeight: response.stateBlockHeight
|
|
244
452
|
});
|
|
245
453
|
} catch (cause) {
|
|
246
|
-
throw
|
|
454
|
+
throw require_contract.contractDecodeFailed(`Failed to decode readViews result ${index} (${call.name})`, { cause });
|
|
247
455
|
}
|
|
248
456
|
});
|
|
249
457
|
return {
|
|
@@ -287,7 +495,7 @@ async function getContractSpec(client, request, options) {
|
|
|
287
495
|
client.requireMethods(["getContractDeployment", "getContractArtifact"]);
|
|
288
496
|
const address = new Uint8Array(request.address);
|
|
289
497
|
const result = await client.getContractDeployment({ address }, options);
|
|
290
|
-
if (!require_contract.bytesEqual(address, result.address)) throw
|
|
498
|
+
if (!require_contract.bytesEqual(address, result.address)) throw require_contract.contractVerificationFailed("Contract deployment address mismatch");
|
|
291
499
|
if (result.deployment === null) return {
|
|
292
500
|
...result,
|
|
293
501
|
artifactSpec: null
|
|
@@ -300,11 +508,11 @@ async function getContractSpec(client, request, options) {
|
|
|
300
508
|
/** Shared identity validation for explicit deployments and effective contract selection. */
|
|
301
509
|
async function readDeploymentSpec(client, deployment, options) {
|
|
302
510
|
const artifact = await client.getContractArtifact({ hash: deployment.hash }, options);
|
|
303
|
-
if (!require_contract.bytesEqual(artifact.hash, deployment.hash)) throw
|
|
511
|
+
if (!require_contract.bytesEqual(artifact.hash, deployment.hash)) throw require_contract.contractVerificationFailed("Contract artifact response hash mismatch");
|
|
304
512
|
const artifactSpec = require_contract.readContractArtifactSpec(artifact.contractXdr, (0, _thruputchain_protocol.sha256Hash)(deployment.hash));
|
|
305
513
|
const contract = (0, _thruputchain_protocol.deserialize)(artifact.contractXdr, _thruputchain_protocol.codec.Contract);
|
|
306
514
|
const size = contract.contract_type === _thruputchain_protocol.ContractType.kRv32 ? contract.rv32_contract.data.length : 0;
|
|
307
|
-
if (contract.contract_type !== deployment.contractType || size !== deployment.size) throw
|
|
515
|
+
if (contract.contract_type !== deployment.contractType || size !== deployment.size) throw require_contract.contractVerificationFailed("Contract artifact does not match deployment metadata");
|
|
308
516
|
return artifactSpec;
|
|
309
517
|
}
|
|
310
518
|
//#endregion
|
|
@@ -326,14 +534,14 @@ async function getEffectiveContractSpec(client, request, options) {
|
|
|
326
534
|
address,
|
|
327
535
|
context
|
|
328
536
|
}, options);
|
|
329
|
-
if (!require_contract.bytesEqual(address, result.address) || result.context !== context) throw
|
|
330
|
-
if (result.selection instanceof
|
|
537
|
+
if (!require_contract.bytesEqual(address, result.address) || result.context !== context) throw require_contract.contractVerificationFailed("Effective contract request identity mismatch");
|
|
538
|
+
if (result.selection instanceof require_decimal.UnsupportedRpcValue) throw new require_decimal.ThruputError("rpcValueUnsupported", "Unsupported effective contract selection", { context: { value: result.selection } });
|
|
331
539
|
if (result.selection === null) return {
|
|
332
540
|
...result,
|
|
333
541
|
artifactSpec: null,
|
|
334
542
|
nativeInterface: null
|
|
335
543
|
};
|
|
336
|
-
if (context === "nested" && result.selection.source === "networkDefault") throw
|
|
544
|
+
if (context === "nested" && result.selection.source === "networkDefault") throw require_contract.contractVerificationFailed("Network default cannot apply to a nested invocation");
|
|
337
545
|
const contract = result.selection.contract;
|
|
338
546
|
const artifactSpec = await readDeploymentSpec(client, contract, options);
|
|
339
547
|
const nativeInterface = artifactSpec.kind === "native" && require_contract.bytesEqual(contract.hash, nativeWalletHash) ? {
|
|
@@ -351,11 +559,13 @@ async function getEffectiveContractSpec(client, request, options) {
|
|
|
351
559
|
/**
|
|
352
560
|
* Interpret a known DefaultWallet root using built-in binding descriptors.
|
|
353
561
|
* Call only after identifying the root as DefaultWallet; matching selectors
|
|
354
|
-
* alone do not establish wallet identity. Malformed recognized inputs throw
|
|
562
|
+
* alone do not establish wallet identity. Malformed recognized inputs throw,
|
|
563
|
+
* as does an `execute` that mints or forwards auth tokens.
|
|
355
564
|
*/
|
|
356
565
|
function decodeDefaultWalletRequests(root) {
|
|
357
566
|
if (require_contract.bytesEqual(root.entrypoint, require_dev_wallet.DefaultWallet.v0_1.execute.entrypoint)) {
|
|
358
|
-
const { calls } = require_dev_wallet.DefaultWallet.v0_1.execute.decodeArgs(root.calldata);
|
|
567
|
+
const { mints, calls } = require_dev_wallet.DefaultWallet.v0_1.execute.decodeArgs(root.calldata);
|
|
568
|
+
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");
|
|
359
569
|
return {
|
|
360
570
|
wrapper: "DefaultWallet.execute",
|
|
361
571
|
requestedCalls: calls.map((call) => ({
|
|
@@ -392,7 +602,7 @@ async function readTransactionInput(client, request, options) {
|
|
|
392
602
|
client.requireMethods(["getTransactionInput"]);
|
|
393
603
|
const hash = new Uint8Array(request.transactionHash);
|
|
394
604
|
const result = await client.getTransactionInput({ transactionHash: hash }, options);
|
|
395
|
-
if (result instanceof
|
|
605
|
+
if (result instanceof require_decimal.UnsupportedRpcValue || result.status === "unavailable") return result;
|
|
396
606
|
try {
|
|
397
607
|
if (result.transactionXdr.length > 4 * 1024 * 1024) throw new Error("Transaction input exceeds 4 MiB");
|
|
398
608
|
if (!require_contract.bytesEqual(result.transactionHash, hash) || !require_contract.bytesEqual((0, _noble_hashes_sha2_js.sha256)(result.transactionXdr), hash)) throw new Error("Retained transaction input hash mismatch");
|
|
@@ -403,40 +613,42 @@ async function readTransactionInput(client, request, options) {
|
|
|
403
613
|
transaction
|
|
404
614
|
};
|
|
405
615
|
} catch (cause) {
|
|
406
|
-
throw
|
|
616
|
+
throw require_contract.contractVerificationFailed(require_contract.errorText(cause) ?? "Invalid transaction input", { cause });
|
|
407
617
|
}
|
|
408
618
|
}
|
|
409
619
|
//#endregion
|
|
410
620
|
//#region src/actions/wallet/sendTransaction.ts
|
|
411
621
|
/**
|
|
412
622
|
* Serialize and submit once through the native RPC boundary.
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
623
|
+
* Every failure has `transaction` facts with the signed bytes and destination
|
|
624
|
+
* discovery network; that network does not prove the signing network of an
|
|
625
|
+
* already-signed envelope. Unknown admission throws code
|
|
626
|
+
* `transactionAdmissionUnsupported`. RPC and transport failures keep their
|
|
627
|
+
* code, with outcome `unknown`, or `notSubmitted` for a local request error.
|
|
416
628
|
*/
|
|
417
629
|
async function sendTransaction(client, signedTx, options) {
|
|
418
630
|
const evidence = require_sendInvocation.createSubmissionEvidence((0, _thruputchain_protocol.serialize)(signedTx, _thruputchain_protocol.codec.SignedTransaction), client.discovery.network.networkHash);
|
|
419
|
-
|
|
631
|
+
if (options?.signal?.aborted) throw require_sendInvocation.transactionNotSubmitted(evidence, "cancelled", options.signal.reason);
|
|
632
|
+
let result;
|
|
420
633
|
try {
|
|
421
|
-
|
|
634
|
+
result = await client.sendTransaction({ signedTransaction: evidence.signedTransaction }, options);
|
|
422
635
|
} catch (cause) {
|
|
423
|
-
|
|
636
|
+
const signal = options?.signal;
|
|
637
|
+
if (require_sendInvocation.isCancellation(cause, signal)) throw require_sendInvocation.transactionOutcomeUnknown(evidence, "cancelled", cause);
|
|
638
|
+
const local = require_sendInvocation.isLocalRequestError(cause, signal);
|
|
639
|
+
const reason = local ? "requestInvalid" : require_sendInvocation.reasonAfterDispatch(cause, signal);
|
|
640
|
+
if (!require_decimal.isThruputError(cause)) throw require_sendInvocation.transactionOutcomeUnknown(evidence, reason, cause);
|
|
641
|
+
throw require_contract.withTransactionFacts(cause, {
|
|
642
|
+
hash: evidence.transactionHash,
|
|
643
|
+
outcome: local ? "notSubmitted" : "unknown",
|
|
644
|
+
reason,
|
|
645
|
+
submission: evidence
|
|
646
|
+
});
|
|
424
647
|
}
|
|
648
|
+
require_sendInvocation.assertTransactionAdmission(result, evidence);
|
|
425
649
|
return (0, _thruputchain_protocol.sha256Hash)(result.transactionHash);
|
|
426
650
|
}
|
|
427
651
|
//#endregion
|
|
428
|
-
Object.defineProperty(exports, "FundingObservationError", {
|
|
429
|
-
enumerable: true,
|
|
430
|
-
get: function() {
|
|
431
|
-
return FundingObservationError;
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
Object.defineProperty(exports, "HistoryWalkError", {
|
|
435
|
-
enumerable: true,
|
|
436
|
-
get: function() {
|
|
437
|
-
return HistoryWalkError;
|
|
438
|
-
}
|
|
439
|
-
});
|
|
440
652
|
Object.defineProperty(exports, "decodeDefaultWalletRequests", {
|
|
441
653
|
enumerable: true,
|
|
442
654
|
get: function() {
|
|
@@ -509,5 +721,17 @@ Object.defineProperty(exports, "sendTransaction", {
|
|
|
509
721
|
return sendTransaction;
|
|
510
722
|
}
|
|
511
723
|
});
|
|
724
|
+
Object.defineProperty(exports, "waitForCommitment", {
|
|
725
|
+
enumerable: true,
|
|
726
|
+
get: function() {
|
|
727
|
+
return waitForCommitment;
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
Object.defineProperty(exports, "waitForTransactionReceipt", {
|
|
731
|
+
enumerable: true,
|
|
732
|
+
get: function() {
|
|
733
|
+
return waitForTransactionReceipt;
|
|
734
|
+
}
|
|
735
|
+
});
|
|
512
736
|
|
|
513
|
-
//# sourceMappingURL=actions-
|
|
737
|
+
//# sourceMappingURL=actions-B2gV8Vzr.cjs.map
|