@bsv/wallet-toolbox-client 2.2.0 → 2.3.1
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/out/src/SetupClient.js +1 -1
- package/out/src/SetupClient.js.map +1 -1
- package/out/src/WalletPermissionsManager.d.ts.map +1 -1
- package/out/src/WalletPermissionsManager.js +0 -2
- package/out/src/WalletPermissionsManager.js.map +1 -1
- package/out/src/storage/StorageProvider.d.ts +1 -4
- package/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/out/src/storage/StorageProvider.js +14 -26
- package/out/src/storage/StorageProvider.js.map +1 -1
- package/out/src/storage/methods/createAction.d.ts.map +1 -1
- package/out/src/storage/methods/createAction.js +40 -56
- package/out/src/storage/methods/createAction.js.map +1 -1
- package/out/src/storage/methods/processAction.d.ts.map +1 -1
- package/out/src/storage/methods/processAction.js +2 -3
- package/out/src/storage/methods/processAction.js.map +1 -1
- package/out/src/storage/methods/reviewStatusIdb.d.ts +2 -2
- package/out/src/storage/methods/reviewStatusIdb.d.ts.map +1 -1
- package/out/src/storage/methods/reviewStatusIdb.js +38 -51
- package/out/src/storage/methods/reviewStatusIdb.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,74 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.reviewStatusIdb = reviewStatusIdb;
|
|
4
|
-
const provenTxReqStatusesSafeForInputRestore = new Set(['invalid', 'doubleSpend']);
|
|
5
4
|
/**
|
|
5
|
+
* Looks for unpropagated state:
|
|
6
|
+
*
|
|
6
7
|
* 1. set transactions to 'failed' if not already failed and provenTxReq with matching txid has status of 'invalid'.
|
|
8
|
+
* 2. sets transactions to 'completed' if provenTx with matching txid exists and current provenTxId is null.
|
|
9
|
+
* 3. sets outputs to spendable true, spentBy undefined if spentBy is a transaction with status 'failed'.
|
|
10
|
+
*
|
|
11
|
+
* @param storage
|
|
12
|
+
* @param args
|
|
13
|
+
* @returns
|
|
7
14
|
*/
|
|
8
|
-
async function
|
|
15
|
+
async function reviewStatusIdb(storage, args) {
|
|
16
|
+
const r = { log: '' };
|
|
17
|
+
// 1. set transactions to 'failed' if not already failed and provenTxReq with matching txid has status of 'invalid'.
|
|
9
18
|
const invalidTxids = [];
|
|
10
|
-
await storage.filterProvenTxReqs({ partial: { status: 'invalid' } }, txReq => {
|
|
19
|
+
await storage.filterProvenTxReqs({ partial: { status: 'invalid' }, trx: args.trx }, txReq => {
|
|
11
20
|
invalidTxids.push(txReq.txid);
|
|
12
21
|
});
|
|
13
22
|
for (const txid of invalidTxids) {
|
|
14
|
-
const txs = await storage.findTransactions({ partial: { txid } });
|
|
23
|
+
const txs = await storage.findTransactions({ partial: { txid }, trx: args.trx });
|
|
15
24
|
for (const tx of txs) {
|
|
16
25
|
if (tx.status !== 'failed') {
|
|
17
26
|
r.log += `transaction ${tx.transactionId} updated to status of 'failed' was ${tx.status}\n`;
|
|
18
|
-
await storage.updateTransactionStatus('failed', tx.transactionId);
|
|
27
|
+
await storage.updateTransactionStatus('failed', tx.transactionId, undefined, undefined, args.trx);
|
|
19
28
|
}
|
|
20
29
|
}
|
|
21
30
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
// 2. sets transactions to 'completed' if provenTx with matching txid exists and current provenTxId is null.
|
|
32
|
+
const provenTxs = {};
|
|
33
|
+
await storage.filterProvenTxs({ partial: {}, trx: args.trx }, provenTx => {
|
|
34
|
+
provenTxs[provenTx.txid] = provenTx.provenTxId;
|
|
35
|
+
});
|
|
36
|
+
for (const [txid, provenTxId] of Object.entries(provenTxs)) {
|
|
37
|
+
const txs = await storage.findTransactions({ partial: { txid }, trx: args.trx });
|
|
38
|
+
for (const tx of txs) {
|
|
39
|
+
if (tx.provenTxId == null) {
|
|
40
|
+
r.log += `transaction ${tx.transactionId} updated to status of 'completed' with provenTxId ${provenTxId}\n`;
|
|
41
|
+
await storage.updateTransaction(tx.transactionId, { status: 'completed', provenTxId }, args.trx);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// 3. sets outputs to spendable true, spentBy undefined if spentBy is a transaction with status 'failed'.
|
|
46
|
+
const failedTxs = await storage.findTransactions({ partial: { status: 'failed' }, trx: args.trx });
|
|
31
47
|
for (const tx of failedTxs) {
|
|
32
|
-
|
|
33
|
-
let hasBlockingReq = false;
|
|
48
|
+
let blocked = false;
|
|
34
49
|
if (tx.txid != null && tx.txid !== '') {
|
|
35
|
-
const reqs = await storage.findProvenTxReqs({ partial: { txid: tx.txid } });
|
|
36
|
-
|
|
50
|
+
const reqs = await storage.findProvenTxReqs({ partial: { txid: tx.txid }, trx: args.trx });
|
|
51
|
+
blocked = reqs.some(req => !['invalid', 'doubleSpend'].includes(req.status));
|
|
37
52
|
}
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Looks for unpropagated state:
|
|
45
|
-
*
|
|
46
|
-
* 1. set transactions to 'failed' if not already failed and provenTxReq with matching txid has status of 'invalid'.
|
|
47
|
-
* 2. sets outputs to spendable true, spentBy undefined if spentBy is a terminal failed transaction.
|
|
48
|
-
* 3. sets outputs generated by terminal failed transactions to spendable false, spentBy undefined.
|
|
49
|
-
*
|
|
50
|
-
* @param storage
|
|
51
|
-
* @param args
|
|
52
|
-
* @returns
|
|
53
|
-
*/
|
|
54
|
-
async function reviewStatusIdb(storage, args) {
|
|
55
|
-
const r = { log: '' };
|
|
56
|
-
await failTransactionsForInvalidReqs(storage, r);
|
|
57
|
-
const { failedTransactionIds, safeFailedTransactionIds } = await collectFailedTransactionIds(storage);
|
|
58
|
-
const outputs = await storage.findOutputs({ partial: {}, trx: args.trx });
|
|
59
|
-
for (const output of outputs) {
|
|
60
|
-
// An output generated by any failed tx (even one still reconcilable from an active req) is
|
|
61
|
-
// not a valid input to restore, matching the SQL `source.status = 'failed'` guard.
|
|
62
|
-
const generatedByFailedTx = failedTransactionIds.has(output.transactionId);
|
|
63
|
-
const generatedBySafeFailedTx = safeFailedTransactionIds.has(output.transactionId);
|
|
64
|
-
const spentBySafeFailedTx = output.spentBy != null && safeFailedTransactionIds.has(output.spentBy);
|
|
65
|
-
if (spentBySafeFailedTx && !generatedByFailedTx) {
|
|
53
|
+
if (blocked)
|
|
54
|
+
continue;
|
|
55
|
+
const outputs = await storage.findOutputs({ partial: { userId: tx.userId, spentBy: tx.transactionId }, trx: args.trx });
|
|
56
|
+
for (const output of outputs) {
|
|
66
57
|
await storage.updateOutput(output.outputId, { spendable: true, spentBy: undefined }, args.trx);
|
|
67
|
-
r.log += `output ${output.outputId}
|
|
68
|
-
}
|
|
69
|
-
if (generatedBySafeFailedTx && (output.spendable || output.spentBy != null)) {
|
|
70
|
-
await storage.updateOutput(output.outputId, { spendable: false, spentBy: undefined }, args.trx);
|
|
71
|
-
r.log += `output ${output.outputId} updated to not spendable because transaction is failed\n`;
|
|
58
|
+
r.log += `output ${output.outputId} released from failed transaction ${tx.transactionId}\n`;
|
|
72
59
|
}
|
|
73
60
|
}
|
|
74
61
|
return r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reviewStatusIdb.js","sourceRoot":"","sources":["../../../../../src/storage/methods/reviewStatusIdb.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"reviewStatusIdb.js","sourceRoot":"","sources":["../../../../../src/storage/methods/reviewStatusIdb.ts"],"names":[],"mappings":";;AAcA,0CAsDC;AAjED;;;;;;;;;;GAUG;AACI,KAAK,UAAU,eAAe,CACnC,OAAmB,EACnB,IAA6C;IAE7C,MAAM,CAAC,GAAoB,EAAE,GAAG,EAAE,EAAE,EAAE,CAAA;IAEtC,oHAAoH;IACpH,MAAM,YAAY,GAAa,EAAE,CAAA;IACjC,MAA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O,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QACvH,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;YAC9F,CAAC,CAAC,GAAG,IAAI,UAAU,MAAM,CAAC,QAAQ,qCAAqC,EAAE,CAAC,aAAa,IAAI,CAAA;QAC7F,CAAC;IACH,CAAC;IAED,OAAO,CAAC,CAAA;AACV,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/wallet-toolbox-client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "Client only Wallet Storage",
|
|
5
5
|
"main": "./out/src/index.client.js",
|
|
6
6
|
"types": "./out/src/index.client.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"idb": "^8.0.2"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@bsv/sdk": "^2"
|
|
28
|
+
"@bsv/sdk": "^2.1.6"
|
|
29
29
|
},
|
|
30
30
|
"peerDependenciesMeta": {
|
|
31
31
|
"@bsv/sdk": {
|