aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/common.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-06-13 19:55:48 +0200
committerFlorian Dold <florian@dold.me>2024-06-13 19:55:48 +0200
commit331ff2a22ddbe7512e3a54235a986e7275b88920 (patch)
treebdd255d988059ecde9c147367cabab70b8c7a315 /packages/taler-wallet-core/src/common.ts
parent10aa5e767a35d39d6612f5e4addf4e04f3241a42 (diff)
wallet-core: remove coinAllocationId, simplify coin history store
Diffstat (limited to 'packages/taler-wallet-core/src/common.ts')
-rw-r--r--packages/taler-wallet-core/src/common.ts32
1 files changed, 8 insertions, 24 deletions
diff --git a/packages/taler-wallet-core/src/common.ts b/packages/taler-wallet-core/src/common.ts
index 13c875575..9f63c74d5 100644
--- a/packages/taler-wallet-core/src/common.ts
+++ b/packages/taler-wallet-core/src/common.ts
@@ -74,9 +74,9 @@ export interface CoinsSpendInfo {
contributions: AmountJson[];
refreshReason: RefreshReason;
/**
- * Identifier for what the coin has been spent for.
+ * Transaction for which the coin is spent.
*/
- allocationId: TransactionIdStr;
+ transactionId: TransactionIdStr;
}
export async function makeCoinsVisible(
@@ -149,11 +149,16 @@ export async function makeCoinAvailable(
await tx.coinAvailability.put(car);
}
+/**
+ * Spend coins. Marks the coins as used, adds a coin history items
+ * and creates refresh group.
+ */
export async function spendCoins(
wex: WalletExecutionContext,
tx: WalletDbReadWriteTransaction<
[
"coins",
+ "coinHistory",
"coinAvailability",
"refreshGroups",
"refreshSessions",
@@ -194,28 +199,7 @@ export async function spendCoins(
`age denom info is missing for ${coin.maxAge}`,
);
const contrib = csi.contributions[i];
- if (coin.status !== CoinStatus.Fresh) {
- const alloc = coin.spendAllocation;
- if (!alloc) {
- continue;
- }
- if (alloc.id !== csi.allocationId) {
- // FIXME: assign error code
- logger.info("conflicting coin allocation ID");
- logger.info(`old ID: ${alloc.id}, new ID: ${csi.allocationId}`);
- throw Error("conflicting coin allocation (id)");
- }
- if (0 !== Amounts.cmp(alloc.amount, contrib)) {
- // FIXME: assign error code
- throw Error("conflicting coin allocation (contrib)");
- }
- continue;
- }
coin.status = CoinStatus.Dormant;
- coin.spendAllocation = {
- id: csi.allocationId,
- amount: Amounts.stringify(contrib),
- };
const remaining = Amounts.sub(denom.value, contrib);
if (remaining.saturated) {
throw Error("not enough remaining balance on coin for payment");
@@ -247,7 +231,7 @@ export async function spendCoins(
Amounts.currencyOf(csi.contributions[0]),
refreshCoinPubs,
csi.refreshReason,
- csi.allocationId,
+ csi.transactionId,
);
}