@chironbuilder/ootle-sdk 0.1.29 → 0.2.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/dist/bucketStealthTransfer.d.ts +12 -0
- package/dist/bucketStealthTransfer.d.ts.map +1 -0
- package/dist/bucketStealthTransfer.js +57 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/indexerDecode.d.ts +23 -0
- package/dist/indexerDecode.d.ts.map +1 -0
- package/dist/indexerDecode.js +68 -0
- package/dist/storage.d.ts +11 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/utxoScan.d.ts +24 -39
- package/dist/utxoScan.d.ts.map +1 -1
- package/dist/utxoScan.js +136 -133
- package/dist/wallet.d.ts +28 -8
- package/dist/wallet.d.ts.map +1 -1
- package/dist/wallet.js +166 -82
- package/package.json +8 -8
- package/vendor/ootle-wasm-patched/chiron-0.49.2.patch +199 -0
- package/vendor/ootle-wasm-patched/ootle_wasm.d.ts +53 -35
- package/vendor/ootle-wasm-patched/ootle_wasm.js +1 -1
- package/vendor/ootle-wasm-patched/ootle_wasm_bg.js +158 -45
- package/vendor/ootle-wasm-patched/ootle_wasm_bg.wasm +0 -0
- package/vendor/ootle-wasm-patched/ootle_wasm_bg.wasm.d.ts +15 -12
- package/vendor/ootle-wasm-patched/package.json +3 -3
- package/vendor/ootle-patched/README.md +0 -67
- package/vendor/ootle-patched/dist/index.d.ts +0 -2158
- package/vendor/ootle-patched/dist/index.js +0 -1389
- package/vendor/ootle-patched/node_modules/@tari-project/ootle-wasm/README.md +0 -128
- package/vendor/ootle-patched/node_modules/@tari-project/ootle-wasm/ootle_wasm.d.ts +0 -436
- package/vendor/ootle-patched/node_modules/@tari-project/ootle-wasm/ootle_wasm.js +0 -9
- package/vendor/ootle-patched/node_modules/@tari-project/ootle-wasm/ootle_wasm_bg.js +0 -1450
- package/vendor/ootle-patched/node_modules/@tari-project/ootle-wasm/ootle_wasm_bg.wasm +0 -0
- package/vendor/ootle-patched/node_modules/@tari-project/ootle-wasm/package.json +0 -30
- package/vendor/ootle-patched/package.json +0 -23
package/dist/wallet.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Mask, OotleWallet, StealthInput, StealthInputsStatement, StealthOutputsStatement, StealthTransfer, StealthTransferStatement, TARI_RESOURCE_ADDRESS, TransactionBuilder, WalletStealthAuthorizer, WasmStealthCrypto, XTR_FAUCET_CLAIM_RESOURCE_ADDRESS, XTR_FAUCET_COMPONENT_ADDRESS, XTR_FAUCET_VAULT_ADDRESS, amountLiteral, createOutput, decryptOwnedUtxo, defaultIndexerUrl, getVaultIdsForAccount, resolveMaxEpoch, resolveTransaction, resourceAddressLiteral, generateSealKeypair, sealTransaction, sendTransaction, serializeUnsignedTx, signTransaction, stealthUtxoSubstateId, submitTransaction, } from "@tari-project/ootle";
|
|
2
2
|
import { IndexerProvider } from "@tari-project/ootle-indexer";
|
|
3
3
|
import { SecretKeyWallet } from "@tari-project/ootle-secret-key-wallet";
|
|
4
|
-
import { buildScriptPathWitness, buildStealthTransferStatement, createStealthOutputWitness, parseOotleAddress, publicKeyFromSecretKey,
|
|
5
|
-
// Burn-claim / confidential-withdraw crypto helpers
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
|
|
4
|
+
import { buildScriptPathWitness, buildStealthTransferStatement, createStealthOutputWitness, parseOotleAddress, publicKeyFromSecretKey, stealthDhSecret, validateStealthTransfer, } from "@tari-project/ootle-wasm";
|
|
5
|
+
// Burn-claim / confidential-withdraw crypto helpers are not in upstream @tari-project/ootle-wasm;
|
|
6
|
+
// they are stable pure-crypto wrappers over tari_ootle_wallet_crypto, kept in the vendored build.
|
|
7
|
+
// `schnorrSign` (Ristretto Schnorr, for off-chain ownership proofs) was removed upstream in 0.48
|
|
8
|
+
// when transaction signing moved to sr25519; the patched build keeps it. Rebuilt from v0.49.2 +
|
|
9
|
+
// vendor/ootle-wasm-patched/chiron-0.49.2.patch.
|
|
10
|
+
import { burnClaimStealthSecret, createConfidentialWithdrawProofLiteral, schnorrSign, validateBurnClaimOwnershipProof, } from "@chironbuilder/ootle-wasm-legacy";
|
|
11
|
+
// withdrawStealthAndExecute needs a revealed output left on the workspace as a bucket, which
|
|
12
|
+
// upstream StealthTransfer doesn't offer; BucketStealthTransfer adds just that step.
|
|
13
|
+
import { BucketStealthTransfer } from "./bucketStealthTransfer.js";
|
|
14
|
+
import { decodeExecuteResultDeep, fetchSubstatesDecoded, getSubstateDecoded, getTransactionResultDecoded } from "./indexerDecode.js";
|
|
13
15
|
import { componentAddressFromWalletAddress, deriveAccountComponentAddress } from "./componentAddress.js";
|
|
14
16
|
import { scanTransactionsForOwnedOutputs, sumConfidentialCommitments } from "./confidential.js";
|
|
15
17
|
import { deriveAccountKeys } from "./derivation.js";
|
|
@@ -21,6 +23,29 @@ import { addPendingShield, addShieldedOutput, clearUtxoScanPageCursor, getHtlcJo
|
|
|
21
23
|
import { withTimeout } from "./timeout.js";
|
|
22
24
|
import { scanUtxosDelta, scanUtxosPage } from "./utxoScan.js";
|
|
23
25
|
import { fromHex, toHex } from "./vault.js";
|
|
26
|
+
/**
|
|
27
|
+
* A transaction the network committed with only its fee phase: the fee was charged (so a private fee's
|
|
28
|
+
* input is spent and its change output exists) but the operation itself was rejected. The message
|
|
29
|
+
* keeps the "accepted the fee but rejected the rest" wording callers already match on.
|
|
30
|
+
*/
|
|
31
|
+
export class FeeCommittedError extends Error {
|
|
32
|
+
transactionId;
|
|
33
|
+
constructor(transactionId, detail) {
|
|
34
|
+
super(`Transaction ${transactionId} accepted the fee but rejected the rest: ${detail}`);
|
|
35
|
+
this.transactionId = transactionId;
|
|
36
|
+
this.name = "FeeCommittedError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** The fee committed on-chain but recording it locally failed; the pending entry must be kept so
|
|
40
|
+
* `recoverPendingShields()` can finish the job. */
|
|
41
|
+
export class FeeBookkeepingError extends Error {
|
|
42
|
+
transactionId;
|
|
43
|
+
constructor(transactionId, cause) {
|
|
44
|
+
super(`Transaction ${transactionId} charged its private fee but the wallet could not record the change output: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
45
|
+
this.transactionId = transactionId;
|
|
46
|
+
this.name = "FeeBookkeepingError";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
24
49
|
/** A private fee's bookkeeping, in the journal's serializable form. */
|
|
25
50
|
function journalFee(feeType, fee) {
|
|
26
51
|
if (!fee || feeType.kind !== "private")
|
|
@@ -46,7 +71,7 @@ async function fetchResourceMetadata(provider, resourceIds) {
|
|
|
46
71
|
const nameByResource = new Map();
|
|
47
72
|
if (resourceIds.length === 0)
|
|
48
73
|
return { divisibilityByResource, symbolByResource, nameByResource };
|
|
49
|
-
const { substates } = await withTimeout(provider
|
|
74
|
+
const { substates } = await withTimeout(fetchSubstatesDecoded(provider, resourceIds), 15_000, "reading token decimal precision");
|
|
50
75
|
for (const id of resourceIds) {
|
|
51
76
|
const value = substates[id]?.substate;
|
|
52
77
|
const resource = value && "Resource" in value ? value.Resource : undefined;
|
|
@@ -269,7 +294,7 @@ export class OotleAccount {
|
|
|
269
294
|
const unspentRecords = (await listShieldedOutputs(localAccountId(this.index))).filter((r) => !r.spent);
|
|
270
295
|
const liveness = await Promise.all(unspentRecords.map(async (record) => {
|
|
271
296
|
try {
|
|
272
|
-
await withTimeout(provider
|
|
297
|
+
await withTimeout(getSubstateDecoded(provider, stealthUtxoSubstateId(record.resourceAddress, fromHex(record.commitment))), 15_000, "checking a shielded output");
|
|
273
298
|
return true;
|
|
274
299
|
}
|
|
275
300
|
catch {
|
|
@@ -286,7 +311,7 @@ export class OotleAccount {
|
|
|
286
311
|
return [];
|
|
287
312
|
const parsed = [];
|
|
288
313
|
if (vaultIds.length > 0) {
|
|
289
|
-
const { substates } = await withTimeout(provider
|
|
314
|
+
const { substates } = await withTimeout(fetchSubstatesDecoded(provider, vaultIds), 15_000, "fetching vault balances");
|
|
290
315
|
for (const id of vaultIds) {
|
|
291
316
|
const substate = substates[id];
|
|
292
317
|
const value = substate?.substate;
|
|
@@ -415,6 +440,18 @@ export class OotleAccount {
|
|
|
415
440
|
return withTransactionId(result);
|
|
416
441
|
}
|
|
417
442
|
catch (e) {
|
|
443
|
+
// The fee phase committed even though the main instructions failed: the private fee's UTXO is
|
|
444
|
+
// spent and its change exists. Record that now, and don't retry -- the retry would reuse the
|
|
445
|
+
// spent fee input.
|
|
446
|
+
if (e instanceof FeeCommittedError && privateFee && feeType.kind === "private") {
|
|
447
|
+
try {
|
|
448
|
+
await this.recordPrivateFeeSpend(accountId, feeType.feeResourceAddress, privateFee, e.transactionId);
|
|
449
|
+
}
|
|
450
|
+
catch (recordError) {
|
|
451
|
+
throw new FeeBookkeepingError(e.transactionId, recordError);
|
|
452
|
+
}
|
|
453
|
+
throw e;
|
|
454
|
+
}
|
|
418
455
|
if (!(e instanceof Error) || attempt >= maxRetries)
|
|
419
456
|
throw e;
|
|
420
457
|
// No amount of retrying fixes an empty fee vault — surface this immediately instead of
|
|
@@ -520,7 +557,9 @@ export class OotleAccount {
|
|
|
520
557
|
throw new Error(`HTTP ${res.status}: ${body?.error?.message ?? text ?? res.statusText}`);
|
|
521
558
|
if (body?.error)
|
|
522
559
|
throw new Error(`${body.error.code}: ${body.error.message}`);
|
|
523
|
-
const
|
|
560
|
+
const raw = body;
|
|
561
|
+
// 0.48+: `result` is a base64 CBOR ExecuteResult.
|
|
562
|
+
const response = { ...raw, result: decodeExecuteResultDeep(raw.result) };
|
|
524
563
|
// A rejected dry-run comes back as a normal HTTP 200 with the rejection embedded in the
|
|
525
564
|
// result (there's nothing to poll — dry runs never reach consensus). Throwing here, in the
|
|
526
565
|
// same "Transaction {id} was rejected: {reason}" shape `sendTransaction`'s own polling throws
|
|
@@ -615,7 +654,7 @@ export class OotleAccount {
|
|
|
615
654
|
const provider = await this.getProvider();
|
|
616
655
|
let recipientExists = true;
|
|
617
656
|
try {
|
|
618
|
-
await withTimeout(provider
|
|
657
|
+
await withTimeout(getSubstateDecoded(provider, recipient), 15_000, "checking the recipient's account");
|
|
619
658
|
}
|
|
620
659
|
catch (e) {
|
|
621
660
|
// A timeout means the indexer is degraded, not that the account is missing — creating one
|
|
@@ -763,7 +802,7 @@ export class OotleAccount {
|
|
|
763
802
|
`max_epoch=${typeof t.max_epoch}:${JSON.stringify(t.max_epoch)}`,
|
|
764
803
|
`nonce=${typeof t.nonce}:${JSON.stringify(t.nonce)}`,
|
|
765
804
|
`dry_run=${JSON.stringify(t.dry_run)}`,
|
|
766
|
-
`
|
|
805
|
+
`main_signer=${JSON.stringify(t.main_signer)}`,
|
|
767
806
|
`blobs=${Array.isArray(t.blobs) ? `array[${t.blobs.length}]` : typeof t.blobs}`,
|
|
768
807
|
`inputs=${JSON.stringify(t.inputs)}`,
|
|
769
808
|
`fee_instructions=${JSON.stringify(t.fee_instructions)?.slice(0, 400)}`,
|
|
@@ -838,17 +877,23 @@ export class OotleAccount {
|
|
|
838
877
|
// already passes `this.network` for exactly this reason).
|
|
839
878
|
const { transactionId, spec, privateFee } = await this.prepareSignSubmit(builder, provider, account, maxFee, feeType);
|
|
840
879
|
const ownCommitment = extractOutputCommitment(spec, 0);
|
|
841
|
-
await addPendingShield({ transactionId, accountId, resourceAddress, amount: amount.toString(), ownCommitment, memo });
|
|
880
|
+
await addPendingShield({ transactionId, accountId, resourceAddress, amount: amount.toString(), ownCommitment, memo, privateFee: journalFee(feeType, privateFee) });
|
|
881
|
+
let keepPending = false;
|
|
842
882
|
try {
|
|
843
|
-
const response = await withTimeout(pollTransactionResult(provider, transactionId), 60_000, "submitting the shield transaction");
|
|
883
|
+
const response = await this.pollRecordingFee(accountId, feeType, privateFee, transactionId, () => withTimeout(pollTransactionResult(provider, transactionId), 60_000, "submitting the shield transaction"));
|
|
844
884
|
await recordKnownVersions(response);
|
|
845
885
|
await recordKnownShieldedOutput(accountId, resourceAddress, ownCommitment, amount, transactionId, memo);
|
|
846
886
|
if (privateFee && feeType.kind === "private") {
|
|
847
887
|
await this.recordPrivateFeeSpend(accountId, feeType.feeResourceAddress, privateFee, transactionId);
|
|
848
888
|
}
|
|
849
889
|
}
|
|
890
|
+
catch (e) {
|
|
891
|
+
keepPending = e instanceof FeeBookkeepingError;
|
|
892
|
+
throw e;
|
|
893
|
+
}
|
|
850
894
|
finally {
|
|
851
|
-
|
|
895
|
+
if (!keepPending)
|
|
896
|
+
await removePendingShield(transactionId);
|
|
852
897
|
}
|
|
853
898
|
// The commitment and its substate id are returned, not just the transaction id, because they are
|
|
854
899
|
// the only durable handle on the output this created -- and with a non-zero
|
|
@@ -875,7 +920,7 @@ export class OotleAccount {
|
|
|
875
920
|
*/
|
|
876
921
|
async signOwnershipProof(resourceAddress, substateId, challenge) {
|
|
877
922
|
const provider = await this.getProvider();
|
|
878
|
-
const response = await provider
|
|
923
|
+
const response = await getSubstateDecoded(provider, substateId);
|
|
879
924
|
// Ootle 0.47 nests the Utxo under `state.up.substate` (older responses carried it as
|
|
880
925
|
// `substate` directly) -- `utxoOf` reads either, same as every other substate reader here.
|
|
881
926
|
// Before this, the hard-coded `response.state.Utxo` read `undefined` on 0.47, so every
|
|
@@ -889,7 +934,7 @@ export class OotleAccount {
|
|
|
889
934
|
throw new Error("This output isn't key-authorized (it's spent by a script condition, not a signature) -- there's no key to prove ownership of.");
|
|
890
935
|
}
|
|
891
936
|
const senderPublicNonce = fromHex(utxo.output.output.public_nonce);
|
|
892
|
-
const oneTimeSecret = stealthDhSecret(this.network, this.ownerSecret, senderPublicNonce);
|
|
937
|
+
const oneTimeSecret = stealthDhSecret(this.network, this.ownerSecret, await this.signer.getViewSecret(), senderPublicNonce);
|
|
893
938
|
try {
|
|
894
939
|
const oneTimePublicKey = publicKeyFromSecretKey(oneTimeSecret);
|
|
895
940
|
if (toHex(oneTimePublicKey) !== expectedAuthKeyHex) {
|
|
@@ -1002,9 +1047,11 @@ export class OotleAccount {
|
|
|
1002
1047
|
spentCommitments: commitments,
|
|
1003
1048
|
ownCommitment,
|
|
1004
1049
|
memo,
|
|
1050
|
+
privateFee: journalFee(feeType, privateFee),
|
|
1005
1051
|
});
|
|
1052
|
+
let keepPending = false;
|
|
1006
1053
|
try {
|
|
1007
|
-
const response = await withTimeout(pollTransactionResult(provider, transactionId), 60_000, "submitting the unshield transaction");
|
|
1054
|
+
const response = await this.pollRecordingFee(accountId, feeType, privateFee, transactionId, () => withTimeout(pollTransactionResult(provider, transactionId), 60_000, "submitting the unshield transaction"));
|
|
1008
1055
|
await recordKnownVersions(response);
|
|
1009
1056
|
await recordKnownShieldedOutput(accountId, resourceAddress, ownCommitment, remainder, transactionId, memo);
|
|
1010
1057
|
for (const commitment of commitments) {
|
|
@@ -1014,8 +1061,13 @@ export class OotleAccount {
|
|
|
1014
1061
|
await this.recordPrivateFeeSpend(accountId, feeType.feeResourceAddress, privateFee, transactionId);
|
|
1015
1062
|
}
|
|
1016
1063
|
}
|
|
1064
|
+
catch (e) {
|
|
1065
|
+
keepPending = e instanceof FeeBookkeepingError;
|
|
1066
|
+
throw e;
|
|
1067
|
+
}
|
|
1017
1068
|
finally {
|
|
1018
|
-
|
|
1069
|
+
if (!keepPending)
|
|
1070
|
+
await removePendingShield(transactionId);
|
|
1019
1071
|
}
|
|
1020
1072
|
return { transactionId };
|
|
1021
1073
|
}
|
|
@@ -1056,7 +1108,7 @@ export class OotleAccount {
|
|
|
1056
1108
|
const builder = await this.buildWithdrawStealthAndExecute(provider, account, resourceAddress, amount, workspaceVarName, followUpInstructions, relatedComponents);
|
|
1057
1109
|
const viewSecret = await this.signer.getViewSecret();
|
|
1058
1110
|
const { transactionId, privateFee } = await this.prepareSignSubmit(builder, provider, account, maxFee, feeType, { viewSecret });
|
|
1059
|
-
const response = await withTimeout(pollTransactionResult(provider, transactionId), 60_000, "submitting the transaction");
|
|
1111
|
+
const response = await this.pollRecordingFee(localAccountId(this.index), feeType, privateFee, transactionId, () => withTimeout(pollTransactionResult(provider, transactionId), 60_000, "submitting the transaction"));
|
|
1060
1112
|
await recordKnownVersions(response);
|
|
1061
1113
|
if (privateFee && feeType.kind === "private") {
|
|
1062
1114
|
await this.recordPrivateFeeSpend(localAccountId(this.index), feeType.feeResourceAddress, privateFee, transactionId);
|
|
@@ -1093,18 +1145,13 @@ export class OotleAccount {
|
|
|
1093
1145
|
// stealth output back to this account -- the same proven-working shape -- alongside the real
|
|
1094
1146
|
// amount as a revealed bucket.
|
|
1095
1147
|
const dust = 1n;
|
|
1096
|
-
let builder = new
|
|
1148
|
+
let builder = new BucketStealthTransfer(provider, resourceAddress)
|
|
1097
1149
|
.withBuilder((b) => b.addInput({ substate_id: resourceAddress, version: null }))
|
|
1098
1150
|
.spendRevealedInput(account, amount + dust)
|
|
1099
1151
|
.toStealthOutput(createOutput({ destination: walletAddress, amount: dust, resourceAddress }))
|
|
1100
|
-
|
|
1101
|
-
//
|
|
1102
|
-
|
|
1103
|
-
// `unshield`/`sendPrivately` fold this into `toRevealedOutput(amount, pubkey)`, but the
|
|
1104
|
-
// legacy builder's `toRevealedOutputAsBucket` takes no receiver, so set it explicitly. The
|
|
1105
|
-
// bucket is consumed by `followUpInstructions` in this same transaction, which is always
|
|
1106
|
-
// signed with the account key — see `accountPublicKey`'s own doc comment (tari-ootle#2645).
|
|
1107
|
-
.withRevealedReceiver(this.accountPublicKey)
|
|
1152
|
+
// The revealed bucket names the key allowed to take it (tari-ootle#2645); it is consumed by
|
|
1153
|
+
// `followUpInstructions` in this same transaction, always signed with the account key.
|
|
1154
|
+
.toRevealedOutputAsBucket(amount, workspaceVarName, this.accountPublicKey)
|
|
1108
1155
|
.andThen(followUpInstructions);
|
|
1109
1156
|
// `spendRevealedInput` withdraws from this account's vault but doesn't register it as an input
|
|
1110
1157
|
// (only the account component), so the engine rejects the withdraw with `vault_… not found`.
|
|
@@ -1230,7 +1277,7 @@ export class OotleAccount {
|
|
|
1230
1277
|
const authorized = await WalletStealthAuthorizer.fromSpec(wallet, spec, { viewSecret, crypto: new WasmStealthCrypto(this.network) }).prepare(provider);
|
|
1231
1278
|
const envelope = privateFee ? await this.sealWithPrivateFee(authorized, privateFee.feeSigner) : await authorized.seal();
|
|
1232
1279
|
const transactionId = await submitTransaction(provider, envelope);
|
|
1233
|
-
const response = await withTimeout(pollTransactionResult(provider, transactionId), 60_000, "submitting the redemption transaction");
|
|
1280
|
+
const response = await this.pollRecordingFee(localAccountId(this.index), feeType, privateFee, transactionId, () => withTimeout(pollTransactionResult(provider, transactionId), 60_000, "submitting the redemption transaction"));
|
|
1234
1281
|
await recordKnownVersions(response);
|
|
1235
1282
|
if (privateFee && feeType.kind === "private") {
|
|
1236
1283
|
await this.recordPrivateFeeSpend(localAccountId(this.index), feeType.feeResourceAddress, privateFee, transactionId);
|
|
@@ -1308,7 +1355,7 @@ export class OotleAccount {
|
|
|
1308
1355
|
const viewSecret = await this.signer.getViewSecret();
|
|
1309
1356
|
const commitment = fromHex(feeCommitmentHex);
|
|
1310
1357
|
const substateId = stealthUtxoSubstateId(feeResourceAddress, commitment);
|
|
1311
|
-
const substate = await provider
|
|
1358
|
+
const substate = await getSubstateDecoded(provider, substateId);
|
|
1312
1359
|
const decrypted = await decryptOwnedUtxo(crypto, viewSecret, substate, substateId);
|
|
1313
1360
|
if (!decrypted) {
|
|
1314
1361
|
throw new Error(`buildPrivateFeeInstructions: cannot decrypt ${substateId} -- it doesn't belong to this account, or is already spent.`);
|
|
@@ -1347,7 +1394,7 @@ export class OotleAccount {
|
|
|
1347
1394
|
// (decryptOwnedUtxo above didn't return it) rather than parsed out of the substate response
|
|
1348
1395
|
// type, whose shape `decryptOwnedUtxo` already validated once. Same convention
|
|
1349
1396
|
// `redeemStealthOutputWithPrivateFee` used before this was extracted.
|
|
1350
|
-
const feeSubstate = await provider
|
|
1397
|
+
const feeSubstate = await getSubstateDecoded(provider, substateId);
|
|
1351
1398
|
const feeNonce = utxoOf(feeSubstate).output
|
|
1352
1399
|
.output.public_nonce;
|
|
1353
1400
|
const feeSigner = {
|
|
@@ -1355,7 +1402,7 @@ export class OotleAccount {
|
|
|
1355
1402
|
getPublicKey: async () => parseOotleAddress(walletAddress).owner_key,
|
|
1356
1403
|
signTransaction: async (tx, sealPublicKey) => {
|
|
1357
1404
|
const json = serializeUnsignedTx(tx);
|
|
1358
|
-
const sig = await this.signer.addStealthSignature(json, fromHex(feeNonce), sealPublicKey, { crypto });
|
|
1405
|
+
const sig = await this.signer.addStealthSignature(json, fromHex(feeNonce), sealPublicKey, { crypto, viewSecret: await this.signer.getViewSecret() });
|
|
1359
1406
|
return [sig];
|
|
1360
1407
|
},
|
|
1361
1408
|
};
|
|
@@ -1400,6 +1447,27 @@ export class OotleAccount {
|
|
|
1400
1447
|
await recordKnownShieldedOutput(accountId, feeResourceAddress, fee.feeChangeCommitment, fee.feeChangeAmount, transactionId);
|
|
1401
1448
|
await markShieldedOutputSpent(accountId, fee.spentCommitment);
|
|
1402
1449
|
}
|
|
1450
|
+
/**
|
|
1451
|
+
* Runs `poll`; if the transaction committed with only its fee phase, records the private fee's
|
|
1452
|
+
* spend and change first (they exist on-chain whatever happened to the main instructions), then
|
|
1453
|
+
* rethrows. A bookkeeping failure surfaces as `FeeBookkeepingError` so the caller keeps its pending entry.
|
|
1454
|
+
*/
|
|
1455
|
+
async pollRecordingFee(accountId, feeType, privateFee, transactionId, poll) {
|
|
1456
|
+
try {
|
|
1457
|
+
return await poll();
|
|
1458
|
+
}
|
|
1459
|
+
catch (e) {
|
|
1460
|
+
if (e instanceof FeeCommittedError && privateFee && feeType.kind === "private") {
|
|
1461
|
+
try {
|
|
1462
|
+
await this.recordPrivateFeeSpend(accountId, feeType.feeResourceAddress, privateFee, transactionId);
|
|
1463
|
+
}
|
|
1464
|
+
catch (recordError) {
|
|
1465
|
+
throw new FeeBookkeepingError(transactionId, recordError);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
throw e;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1403
1471
|
/**
|
|
1404
1472
|
* Selects and builds everything needed to pay a transaction's fee privately, or returns `null`
|
|
1405
1473
|
* for `{ kind: "transparent" }` -- the single entry point every fee-paying method (`execute()`
|
|
@@ -1495,7 +1563,7 @@ export class OotleAccount {
|
|
|
1495
1563
|
continue;
|
|
1496
1564
|
try {
|
|
1497
1565
|
const substateId = stealthUtxoSubstateId(resourceAddress, fromHex(record.commitment));
|
|
1498
|
-
if (await decryptOwnedUtxo(crypto, viewSecret, await provider
|
|
1566
|
+
if (await decryptOwnedUtxo(crypto, viewSecret, await getSubstateDecoded(provider, substateId), substateId))
|
|
1499
1567
|
return true;
|
|
1500
1568
|
}
|
|
1501
1569
|
catch {
|
|
@@ -1537,7 +1605,7 @@ export class OotleAccount {
|
|
|
1537
1605
|
const walletAddress = await this.getWalletAddress();
|
|
1538
1606
|
const inputs = await Promise.all(commitments.map(async (commitmentHex) => {
|
|
1539
1607
|
const substateId = stealthUtxoSubstateId(resourceAddress, fromHex(commitmentHex));
|
|
1540
|
-
const substate = await provider
|
|
1608
|
+
const substate = await getSubstateDecoded(provider, substateId);
|
|
1541
1609
|
const decrypted = await decryptOwnedUtxo(crypto, viewSecret, substate, substateId);
|
|
1542
1610
|
if (!decrypted)
|
|
1543
1611
|
throw new Error(`sendPrivately: cannot decrypt ${substateId} -- it isn't this account's, or it is already spent.`);
|
|
@@ -1584,7 +1652,7 @@ export class OotleAccount {
|
|
|
1584
1652
|
for (const input of inputs)
|
|
1585
1653
|
builder.addInput({ substate_id: input.substateId, version: null });
|
|
1586
1654
|
const unsignedBody = builder.buildUnsignedTransaction();
|
|
1587
|
-
unsignedBody.
|
|
1655
|
+
unsignedBody.main_signer = "SealSigner";
|
|
1588
1656
|
unsignedBody.dry_run = dryRun;
|
|
1589
1657
|
const unsignedTx = await resolveTransaction(provider, unsignedBody);
|
|
1590
1658
|
unsignedTx.inputs = dedupeInputs(unsignedTx.inputs);
|
|
@@ -1593,7 +1661,7 @@ export class OotleAccount {
|
|
|
1593
1661
|
getPublicKey: async () => parseOotleAddress(walletAddress).owner_key,
|
|
1594
1662
|
signTransaction: async (tx, sealPublicKey) => {
|
|
1595
1663
|
const json = serializeUnsignedTx(tx);
|
|
1596
|
-
return [await this.signer.addStealthSignature(json, fromHex(input.nonce), sealPublicKey, { crypto })];
|
|
1664
|
+
return [await this.signer.addStealthSignature(json, fromHex(input.nonce), sealPublicKey, { crypto, viewSecret: await this.signer.getViewSecret() })];
|
|
1597
1665
|
},
|
|
1598
1666
|
}));
|
|
1599
1667
|
const signed = await signTransaction(signers, unsignedTx, sealKeypair);
|
|
@@ -1686,7 +1754,7 @@ export class OotleAccount {
|
|
|
1686
1754
|
continue;
|
|
1687
1755
|
try {
|
|
1688
1756
|
const substateId = stealthUtxoSubstateId(record.resourceAddress, fromHex(record.commitment));
|
|
1689
|
-
const substate = await provider
|
|
1757
|
+
const substate = await getSubstateDecoded(provider, substateId);
|
|
1690
1758
|
const decrypted = await decryptOwnedUtxo(crypto, viewSecret, substate, substateId);
|
|
1691
1759
|
if (!decrypted)
|
|
1692
1760
|
unreadable.add(record.commitment); // doesn't decrypt as ours -- don't offer it either
|
|
@@ -1810,6 +1878,7 @@ export class OotleAccount {
|
|
|
1810
1878
|
if (!res.ok || body?.error || !body?.result) {
|
|
1811
1879
|
throw new Error(`The dry run failed: ${body?.error?.message ?? text ?? res.statusText}`);
|
|
1812
1880
|
}
|
|
1881
|
+
body.result = decodeExecuteResultDeep(body.result);
|
|
1813
1882
|
const outcome = body.result.finalize.result;
|
|
1814
1883
|
if (typeof outcome === "object" && outcome !== null) {
|
|
1815
1884
|
if ("Reject" in outcome)
|
|
@@ -1829,7 +1898,7 @@ export class OotleAccount {
|
|
|
1829
1898
|
const viewSecret = await this.signer.getViewSecret();
|
|
1830
1899
|
const commitment = fromHex(commitmentHex);
|
|
1831
1900
|
const substateId = stealthUtxoSubstateId(resourceAddress, commitment);
|
|
1832
|
-
const substate = await provider
|
|
1901
|
+
const substate = await getSubstateDecoded(provider, substateId);
|
|
1833
1902
|
const decrypted = await decryptOwnedUtxo(crypto, viewSecret, substate, substateId);
|
|
1834
1903
|
if (!decrypted) {
|
|
1835
1904
|
throw new Error(`redeemStealthOutputWithPrivateFee: cannot decrypt ${substateId} -- it doesn't belong to this account, or is already spent.`);
|
|
@@ -1875,7 +1944,7 @@ export class OotleAccount {
|
|
|
1875
1944
|
// The redeemed input's one-time key co-signs the same way the fee input's does inside
|
|
1876
1945
|
// `buildPrivateFeeInstructions` -- see this method's own doc comment for why no ordinary
|
|
1877
1946
|
// account-key signature is added.
|
|
1878
|
-
const redeemedSubstate = await provider
|
|
1947
|
+
const redeemedSubstate = await getSubstateDecoded(provider, redeemed.substateId);
|
|
1879
1948
|
const redeemedNonce = utxoOf(redeemedSubstate)
|
|
1880
1949
|
.output.output.public_nonce;
|
|
1881
1950
|
const redeemedSigner = {
|
|
@@ -1883,7 +1952,7 @@ export class OotleAccount {
|
|
|
1883
1952
|
getPublicKey: async () => parseOotleAddress(walletAddress).owner_key,
|
|
1884
1953
|
signTransaction: async (tx, sealPublicKey) => {
|
|
1885
1954
|
const json = serializeUnsignedTx(tx);
|
|
1886
|
-
const sig = await this.signer.addStealthSignature(json, fromHex(redeemedNonce), sealPublicKey, { crypto });
|
|
1955
|
+
const sig = await this.signer.addStealthSignature(json, fromHex(redeemedNonce), sealPublicKey, { crypto, viewSecret: await this.signer.getViewSecret() });
|
|
1887
1956
|
return [sig];
|
|
1888
1957
|
},
|
|
1889
1958
|
};
|
|
@@ -2061,7 +2130,7 @@ export class OotleAccount {
|
|
|
2061
2130
|
if (record.resourceAddress !== resourceAddress)
|
|
2062
2131
|
throw new Error(`htlcFund: ${commitment.slice(0, 12)}… holds ${record.resourceAddress}, not ${resourceAddress}.`);
|
|
2063
2132
|
const substateId = stealthUtxoSubstateId(resourceAddress, fromHex(record.commitment));
|
|
2064
|
-
const decrypted = await decryptOwnedUtxo(crypto, viewSecret, await provider
|
|
2133
|
+
const decrypted = await decryptOwnedUtxo(crypto, viewSecret, await getSubstateDecoded(provider, substateId), substateId);
|
|
2065
2134
|
if (!decrypted || decrypted.value !== BigInt(record.amount)) {
|
|
2066
2135
|
throw new Error(`htlcFund: ${commitment.slice(0, 12)}… is not spendable as recorded (already spent, or its on-chain value differs).`);
|
|
2067
2136
|
}
|
|
@@ -2088,7 +2157,7 @@ export class OotleAccount {
|
|
|
2088
2157
|
const substateId = stealthUtxoSubstateId(resourceAddress, fromHex(commitmentHex));
|
|
2089
2158
|
let substate = null;
|
|
2090
2159
|
try {
|
|
2091
|
-
substate = await provider
|
|
2160
|
+
substate = await getSubstateDecoded(provider, substateId);
|
|
2092
2161
|
}
|
|
2093
2162
|
catch {
|
|
2094
2163
|
substate = null;
|
|
@@ -2144,7 +2213,7 @@ export class OotleAccount {
|
|
|
2144
2213
|
const { hashLockHex, refundEpoch } = describeHtlcConditions(conditions);
|
|
2145
2214
|
const provider = await this.getProvider();
|
|
2146
2215
|
const substateId = stealthUtxoSubstateId(resourceAddress, fromHex(commitmentHex));
|
|
2147
|
-
const decrypted = await decryptOwnedUtxo(new WasmStealthCrypto(this.network), await this.signer.getViewSecret(), await provider
|
|
2216
|
+
const decrypted = await decryptOwnedUtxo(new WasmStealthCrypto(this.network), await this.signer.getViewSecret(), await getSubstateDecoded(provider, substateId), substateId);
|
|
2148
2217
|
if (!decrypted)
|
|
2149
2218
|
throw new Error("htlcClaim: the HTLC output no longer decrypts — it may have just been claimed or refunded.");
|
|
2150
2219
|
const walletAddress = await this.getWalletAddress();
|
|
@@ -2369,7 +2438,7 @@ export class OotleAccount {
|
|
|
2369
2438
|
continue;
|
|
2370
2439
|
}
|
|
2371
2440
|
}
|
|
2372
|
-
const response = await provider
|
|
2441
|
+
const response = await getTransactionResultDecoded(provider, txId);
|
|
2373
2442
|
const result = response.result;
|
|
2374
2443
|
if (result === "Pending") {
|
|
2375
2444
|
out.push(current);
|
|
@@ -2381,7 +2450,7 @@ export class OotleAccount {
|
|
|
2381
2450
|
out.push(current);
|
|
2382
2451
|
continue;
|
|
2383
2452
|
}
|
|
2384
|
-
const outcome = result.Finalized.execution_result?.finalize.result;
|
|
2453
|
+
const outcome = decodeExecuteResultDeep(result.Finalized.execution_result)?.finalize.result;
|
|
2385
2454
|
if (outcome && typeof outcome === "object" && "Accept" in outcome) {
|
|
2386
2455
|
await this.finalizeHtlcEntry({ ...entry, transactionId: txId }, response);
|
|
2387
2456
|
current = (await getHtlcJournalEntry(entry.id)) ?? current;
|
|
@@ -2516,9 +2585,11 @@ export class OotleAccount {
|
|
|
2516
2585
|
amount: changeAmount.toString(),
|
|
2517
2586
|
spentCommitments: commitments,
|
|
2518
2587
|
ownCommitment,
|
|
2588
|
+
privateFee: journalFee(feeType, privateFee),
|
|
2519
2589
|
});
|
|
2590
|
+
let keepPending = false;
|
|
2520
2591
|
try {
|
|
2521
|
-
const response = await withTimeout(pollTransactionResult(provider, transactionId), 60_000, "submitting the private send");
|
|
2592
|
+
const response = await this.pollRecordingFee(accountId, feeType, privateFee, transactionId, () => withTimeout(pollTransactionResult(provider, transactionId), 60_000, "submitting the private send"));
|
|
2522
2593
|
await recordKnownVersions(response);
|
|
2523
2594
|
if (ownCommitment)
|
|
2524
2595
|
await recordKnownShieldedOutput(accountId, resourceAddress, ownCommitment, changeAmount, transactionId);
|
|
@@ -2529,8 +2600,13 @@ export class OotleAccount {
|
|
|
2529
2600
|
await this.recordPrivateFeeSpend(accountId, feeType.feeResourceAddress, privateFee, transactionId);
|
|
2530
2601
|
}
|
|
2531
2602
|
}
|
|
2603
|
+
catch (e) {
|
|
2604
|
+
keepPending = e instanceof FeeBookkeepingError;
|
|
2605
|
+
throw e;
|
|
2606
|
+
}
|
|
2532
2607
|
finally {
|
|
2533
|
-
|
|
2608
|
+
if (!keepPending)
|
|
2609
|
+
await removePendingShield(transactionId);
|
|
2534
2610
|
}
|
|
2535
2611
|
return {
|
|
2536
2612
|
transactionId,
|
|
@@ -2561,7 +2637,7 @@ export class OotleAccount {
|
|
|
2561
2637
|
}
|
|
2562
2638
|
const provider = await this.getProvider();
|
|
2563
2639
|
const substateId = stealthUtxoSubstateId(resourceAddress, fromHex(commitmentHex));
|
|
2564
|
-
const substate = await provider
|
|
2640
|
+
const substate = await getSubstateDecoded(provider, substateId);
|
|
2565
2641
|
const viewSecret = await this.signer.getViewSecret();
|
|
2566
2642
|
const decrypted = await decryptOwnedUtxo(new WasmStealthCrypto(this.network), viewSecret, substate, substateId);
|
|
2567
2643
|
if (!decrypted) {
|
|
@@ -2632,7 +2708,7 @@ export class OotleAccount {
|
|
|
2632
2708
|
const vaultIds = await getVaultIdsForAccount(provider, account);
|
|
2633
2709
|
if (vaultIds.length === 0)
|
|
2634
2710
|
return false;
|
|
2635
|
-
const { substates } = await withTimeout(provider
|
|
2711
|
+
const { substates } = await withTimeout(fetchSubstatesDecoded(provider, vaultIds), 15_000, "checking this account's vaults");
|
|
2636
2712
|
for (const id of vaultIds) {
|
|
2637
2713
|
const value = substates[id]?.substate;
|
|
2638
2714
|
if (!value || !("Vault" in value))
|
|
@@ -2661,7 +2737,7 @@ export class OotleAccount {
|
|
|
2661
2737
|
const ownerPublicKey = this.accountPublicKey;
|
|
2662
2738
|
const inputs = await Promise.all(commitments.map(async (commitmentHex) => {
|
|
2663
2739
|
const substateId = stealthUtxoSubstateId(resourceAddress, fromHex(commitmentHex));
|
|
2664
|
-
const substate = await provider
|
|
2740
|
+
const substate = await getSubstateDecoded(provider, substateId);
|
|
2665
2741
|
const decrypted = await decryptOwnedUtxo(crypto, viewSecret, substate, substateId);
|
|
2666
2742
|
if (!decrypted)
|
|
2667
2743
|
throw new Error(`unshield: cannot decrypt ${substateId} -- it isn't this account's, or it is already spent.`);
|
|
@@ -2702,7 +2778,7 @@ export class OotleAccount {
|
|
|
2702
2778
|
for (const input of inputs)
|
|
2703
2779
|
builder.addInput({ substate_id: input.substateId, version: null });
|
|
2704
2780
|
const unsignedBody = builder.buildUnsignedTransaction();
|
|
2705
|
-
unsignedBody.
|
|
2781
|
+
unsignedBody.main_signer = "SealSigner";
|
|
2706
2782
|
const unsignedTx = await resolveTransaction(provider, unsignedBody);
|
|
2707
2783
|
unsignedTx.inputs = dedupeInputs(unsignedTx.inputs);
|
|
2708
2784
|
const signers = inputs.map((input) => ({
|
|
@@ -2710,7 +2786,7 @@ export class OotleAccount {
|
|
|
2710
2786
|
getPublicKey: async () => parseOotleAddress(walletAddress).owner_key,
|
|
2711
2787
|
signTransaction: async (tx, sealPublicKey) => {
|
|
2712
2788
|
const json = serializeUnsignedTx(tx);
|
|
2713
|
-
return [await this.signer.addStealthSignature(json, fromHex(input.nonce), sealPublicKey, { crypto })];
|
|
2789
|
+
return [await this.signer.addStealthSignature(json, fromHex(input.nonce), sealPublicKey, { crypto, viewSecret: await this.signer.getViewSecret() })];
|
|
2714
2790
|
},
|
|
2715
2791
|
}));
|
|
2716
2792
|
const signed = await signTransaction(signers, unsignedTx, { secret_key: this.ownerSecret, public_key: ownerPublicKey });
|
|
@@ -2758,7 +2834,7 @@ export class OotleAccount {
|
|
|
2758
2834
|
const walletAddress = await this.getWalletAddress();
|
|
2759
2835
|
const inputs = await Promise.all(commitments.map(async (commitmentHex) => {
|
|
2760
2836
|
const substateId = stealthUtxoSubstateId(resourceAddress, fromHex(commitmentHex));
|
|
2761
|
-
const substate = await provider
|
|
2837
|
+
const substate = await getSubstateDecoded(provider, substateId);
|
|
2762
2838
|
const decrypted = await decryptOwnedUtxo(crypto, viewSecret, substate, substateId);
|
|
2763
2839
|
if (!decrypted)
|
|
2764
2840
|
throw new Error(`unshield: cannot decrypt ${substateId} -- it isn't this account's, or it is already spent.`);
|
|
@@ -2824,7 +2900,7 @@ export class OotleAccount {
|
|
|
2824
2900
|
for (const input of inputs)
|
|
2825
2901
|
builder.addInput({ substate_id: input.substateId, version: null });
|
|
2826
2902
|
const unsignedBody = builder.buildUnsignedTransaction();
|
|
2827
|
-
unsignedBody.
|
|
2903
|
+
unsignedBody.main_signer = "SealSigner";
|
|
2828
2904
|
unsignedBody.dry_run = dryRun;
|
|
2829
2905
|
const unsignedTx = await resolveTransaction(provider, unsignedBody);
|
|
2830
2906
|
unsignedTx.inputs = dedupeInputs(unsignedTx.inputs);
|
|
@@ -2833,7 +2909,7 @@ export class OotleAccount {
|
|
|
2833
2909
|
getPublicKey: async () => parseOotleAddress(walletAddress).owner_key,
|
|
2834
2910
|
signTransaction: async (tx, sealPublicKey) => {
|
|
2835
2911
|
const json = serializeUnsignedTx(tx);
|
|
2836
|
-
return [await this.signer.addStealthSignature(json, fromHex(input.nonce), sealPublicKey, { crypto })];
|
|
2912
|
+
return [await this.signer.addStealthSignature(json, fromHex(input.nonce), sealPublicKey, { crypto, viewSecret: await this.signer.getViewSecret() })];
|
|
2837
2913
|
},
|
|
2838
2914
|
}));
|
|
2839
2915
|
const signed = await signTransaction(signers, unsignedTx, sealKeypair);
|
|
@@ -2910,7 +2986,7 @@ export class OotleAccount {
|
|
|
2910
2986
|
// The seal key `s` is the transaction's only signer, so it must be authorized as the main
|
|
2911
2987
|
// signer; the TS builder leaves that off by default.
|
|
2912
2988
|
const unsignedBody = builder.buildUnsignedTransaction();
|
|
2913
|
-
unsignedBody.
|
|
2989
|
+
unsignedBody.main_signer = "SealSigner";
|
|
2914
2990
|
unsignedBody.dry_run = dryRun;
|
|
2915
2991
|
const unsignedTx = await resolveTransaction(provider, unsignedBody);
|
|
2916
2992
|
unsignedTx.inputs = dedupeInputs(unsignedTx.inputs);
|
|
@@ -2937,6 +3013,7 @@ export class OotleAccount {
|
|
|
2937
3013
|
if (!res.ok || body?.error || !body?.result) {
|
|
2938
3014
|
throw new Error(`Could not estimate the ${what} fee: ${body?.error?.message ?? text ?? res.statusText}`);
|
|
2939
3015
|
}
|
|
3016
|
+
body.result = decodeExecuteResultDeep(body.result);
|
|
2940
3017
|
const finalize = body.result.finalize;
|
|
2941
3018
|
const outcome = finalize.result;
|
|
2942
3019
|
if (typeof outcome === "object" && outcome !== null && "Reject" in outcome) {
|
|
@@ -3155,7 +3232,7 @@ export class OotleAccount {
|
|
|
3155
3232
|
const checkTransaction = async (transactionId) => {
|
|
3156
3233
|
let response;
|
|
3157
3234
|
try {
|
|
3158
|
-
response = await provider
|
|
3235
|
+
response = await getTransactionResultDecoded(provider, transactionId);
|
|
3159
3236
|
}
|
|
3160
3237
|
catch {
|
|
3161
3238
|
return;
|
|
@@ -3163,7 +3240,7 @@ export class OotleAccount {
|
|
|
3163
3240
|
const result = response.result;
|
|
3164
3241
|
if (result === "Pending" || "Rejected" in result)
|
|
3165
3242
|
return;
|
|
3166
|
-
const outcome = result.Finalized.execution_result?.finalize.result;
|
|
3243
|
+
const outcome = decodeExecuteResultDeep(result.Finalized.execution_result)?.finalize.result;
|
|
3167
3244
|
const upSubstates = outcome && typeof outcome === "object" && "Accept" in outcome
|
|
3168
3245
|
? outcome.Accept.up_substates
|
|
3169
3246
|
: outcome && typeof outcome === "object" && "AcceptFeeRejectRest" in outcome
|
|
@@ -3177,7 +3254,7 @@ export class OotleAccount {
|
|
|
3177
3254
|
const commitment = substateId.slice(prefix.length);
|
|
3178
3255
|
if (knownCommitments.has(commitment))
|
|
3179
3256
|
continue;
|
|
3180
|
-
const decrypted = await decryptOwnedUtxo(crypto, viewSecret, await provider
|
|
3257
|
+
const decrypted = await decryptOwnedUtxo(crypto, viewSecret, await getSubstateDecoded(provider, substateId), substateId);
|
|
3181
3258
|
if (!decrypted)
|
|
3182
3259
|
continue;
|
|
3183
3260
|
const memo = fromMemo(decrypted.memo);
|
|
@@ -3229,15 +3306,14 @@ export class OotleAccount {
|
|
|
3229
3306
|
* directly, so it finds any output that exists on-chain right now regardless of how old it is or
|
|
3230
3307
|
* how it was created.
|
|
3231
3308
|
*
|
|
3232
|
-
* **Full
|
|
3233
|
-
*
|
|
3234
|
-
*
|
|
3235
|
-
*
|
|
3309
|
+
* **Full mode (default):** Sweeps every live UTXO of the resource (`POST /utxos/stream` with
|
|
3310
|
+
* `unspent_only`, from genesis; 0.48 removed `GET /utxos`). Each call reads at most `maxPages`
|
|
3311
|
+
* passes and saves its cursor, so a large set is covered across several calls; the cursor is
|
|
3312
|
+
* cleared once every shard is read, and the next call starts a fresh sweep.
|
|
3236
3313
|
*
|
|
3237
|
-
* **Incremental mode** (`mode: "delta"`):
|
|
3238
|
-
*
|
|
3239
|
-
*
|
|
3240
|
-
* Spent updates from it are recorded as *inferred* spends, which a later sighting can undo.
|
|
3314
|
+
* **Incremental mode** (`mode: "delta"`): `POST /utxos/stream` from saved shard watermarks,
|
|
3315
|
+
* including spends. Spent updates are recorded as *inferred* spends, which a later sighting can
|
|
3316
|
+
* undo.
|
|
3241
3317
|
*
|
|
3242
3318
|
* Any owned output seen in the live set that a local record had marked spent only on an
|
|
3243
3319
|
* indexer's say-so is revived (see `reviveShieldedOutput`).
|
|
@@ -3527,7 +3603,7 @@ export function isSpentElsewhere(record, error, now = Date.now()) {
|
|
|
3527
3603
|
/** Whether a stealth UTXO no longer exists (the indexer says not found). Any other failure: assume it does. */
|
|
3528
3604
|
async function utxoGone(provider, resourceAddress, commitmentHex) {
|
|
3529
3605
|
try {
|
|
3530
|
-
await provider
|
|
3606
|
+
await getSubstateDecoded(provider, stealthUtxoSubstateId(resourceAddress, fromHex(commitmentHex)));
|
|
3531
3607
|
return false;
|
|
3532
3608
|
}
|
|
3533
3609
|
catch (e) {
|
|
@@ -3646,7 +3722,7 @@ export async function recoverPendingShields(provider) {
|
|
|
3646
3722
|
const pending = await listPendingShields();
|
|
3647
3723
|
for (const p of pending) {
|
|
3648
3724
|
try {
|
|
3649
|
-
const response = await provider
|
|
3725
|
+
const response = await getTransactionResultDecoded(provider, p.transactionId);
|
|
3650
3726
|
const result = response.result;
|
|
3651
3727
|
if (result === "Pending")
|
|
3652
3728
|
continue; // still in flight -- leave it for next time
|
|
@@ -3654,8 +3730,16 @@ export async function recoverPendingShields(provider) {
|
|
|
3654
3730
|
await removePendingShield(p.transactionId);
|
|
3655
3731
|
continue;
|
|
3656
3732
|
}
|
|
3657
|
-
const outcome = result.Finalized.execution_result?.finalize.result;
|
|
3733
|
+
const outcome = decodeExecuteResultDeep(result.Finalized.execution_result)?.finalize.result;
|
|
3658
3734
|
const succeeded = outcome && typeof outcome === "object" && "Accept" in outcome;
|
|
3735
|
+
const committed = result.Finalized.final_decision === "Commit";
|
|
3736
|
+
const feeOnly = committed && !!outcome && typeof outcome === "object" && "AcceptFeeRejectRest" in outcome;
|
|
3737
|
+
// The fee phase commits on its own, so a private fee's UTXO is spent and its change exists
|
|
3738
|
+
// whether the whole transaction succeeded or only its fee half did.
|
|
3739
|
+
if (p.privateFee && committed && (succeeded || feeOnly)) {
|
|
3740
|
+
await recordKnownShieldedOutput(p.accountId, p.privateFee.feeResourceAddress, p.privateFee.changeCommitment, BigInt(p.privateFee.changeAmount), p.transactionId);
|
|
3741
|
+
await markShieldedOutputSpent(p.accountId, p.privateFee.spentCommitment);
|
|
3742
|
+
}
|
|
3659
3743
|
if (succeeded) {
|
|
3660
3744
|
await recordKnownVersions(response);
|
|
3661
3745
|
if (p.ownCommitment) {
|
|
@@ -3667,8 +3751,8 @@ export async function recoverPendingShields(provider) {
|
|
|
3667
3751
|
}
|
|
3668
3752
|
}
|
|
3669
3753
|
}
|
|
3670
|
-
// Reject / AcceptFeeRejectRest:
|
|
3671
|
-
// recover -- just stop waiting on it.
|
|
3754
|
+
// Reject / AcceptFeeRejectRest: the operation's own outputs were never created, nothing more
|
|
3755
|
+
// to recover -- just stop waiting on it.
|
|
3672
3756
|
await removePendingShield(p.transactionId);
|
|
3673
3757
|
}
|
|
3674
3758
|
catch {
|
|
@@ -3773,7 +3857,7 @@ async function recordKnownVersions(response) {
|
|
|
3773
3857
|
const result = response.result;
|
|
3774
3858
|
if (result === "Pending" || "Rejected" in result)
|
|
3775
3859
|
return;
|
|
3776
|
-
const outcome = result.Finalized.execution_result?.finalize.result;
|
|
3860
|
+
const outcome = decodeExecuteResultDeep(result.Finalized.execution_result)?.finalize.result;
|
|
3777
3861
|
const upSubstates = outcome && typeof outcome === "object" && "Accept" in outcome
|
|
3778
3862
|
? outcome.Accept.up_substates
|
|
3779
3863
|
: outcome && typeof outcome === "object" && "AcceptFeeRejectRest" in outcome
|
|
@@ -3811,7 +3895,7 @@ function withTransactionId(response) {
|
|
|
3811
3895
|
const result = response.result;
|
|
3812
3896
|
if (result === "Pending" || "Rejected" in result)
|
|
3813
3897
|
return response;
|
|
3814
|
-
const transactionHash = result.Finalized.execution_result?.finalize.transaction_hash;
|
|
3898
|
+
const transactionHash = decodeExecuteResultDeep(result.Finalized.execution_result)?.finalize.transaction_hash;
|
|
3815
3899
|
return transactionHash !== undefined ? { ...response, transactionId: transactionHash } : response;
|
|
3816
3900
|
}
|
|
3817
3901
|
/**
|
|
@@ -3848,7 +3932,7 @@ export async function pollTransactionResult(provider, transactionId, timeoutMs =
|
|
|
3848
3932
|
for (;;) {
|
|
3849
3933
|
let response;
|
|
3850
3934
|
try {
|
|
3851
|
-
response = await provider
|
|
3935
|
+
response = await getTransactionResultDecoded(provider, transactionId);
|
|
3852
3936
|
}
|
|
3853
3937
|
catch (err) {
|
|
3854
3938
|
// A transaction the indexer hasn't ingested yet (submitted moments ago, not yet in its
|
|
@@ -3885,13 +3969,13 @@ export async function pollTransactionResult(provider, transactionId, timeoutMs =
|
|
|
3885
3969
|
const details = result.Finalized.abort_details ? `: ${result.Finalized.abort_details}` : "";
|
|
3886
3970
|
throw new Error(`Transaction ${transactionId} was aborted (${reason})${details}`);
|
|
3887
3971
|
}
|
|
3888
|
-
const outcome = result.Finalized.execution_result?.finalize.result;
|
|
3972
|
+
const outcome = decodeExecuteResultDeep(result.Finalized.execution_result)?.finalize.result;
|
|
3889
3973
|
if (outcome && typeof outcome === "object") {
|
|
3890
3974
|
if ("Reject" in outcome) {
|
|
3891
3975
|
throw new Error(`Transaction ${transactionId} was rejected: ${JSON.stringify(outcome.Reject)}`);
|
|
3892
3976
|
}
|
|
3893
3977
|
if ("AcceptFeeRejectRest" in outcome) {
|
|
3894
|
-
throw new
|
|
3978
|
+
throw new FeeCommittedError(transactionId, JSON.stringify(outcome.AcceptFeeRejectRest));
|
|
3895
3979
|
}
|
|
3896
3980
|
}
|
|
3897
3981
|
return response;
|
|
@@ -3992,7 +4076,7 @@ function describeResolvedTx(resolved) {
|
|
|
3992
4076
|
const keys = Object.keys(tx).join(",");
|
|
3993
4077
|
const inputs = Array.isArray(tx.inputs) ? tx.inputs : [];
|
|
3994
4078
|
const sample = inputs.slice(0, 3).map((i) => JSON.stringify(i)).join(" ");
|
|
3995
|
-
const missing = ["network", "fee_instructions", "instructions", "inputs", "max_epoch", "
|
|
4079
|
+
const missing = ["network", "fee_instructions", "instructions", "inputs", "max_epoch", "main_signer", "dry_run", "blobs", "nonce"]
|
|
3996
4080
|
.filter((k) => !(k in tx));
|
|
3997
4081
|
return [
|
|
3998
4082
|
`keys=[${keys}]`,
|