aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/taler-wallet-core/src/reward.ts167
-rw-r--r--packages/taler-wallet-core/src/transactions.ts75
2 files changed, 6 insertions, 236 deletions
diff --git a/packages/taler-wallet-core/src/reward.ts b/packages/taler-wallet-core/src/reward.ts
index b8cf41326..85e8c6606 100644
--- a/packages/taler-wallet-core/src/reward.ts
+++ b/packages/taler-wallet-core/src/reward.ts
@@ -40,12 +40,9 @@ import {
import { RewardRecord, RewardRecordStatus } from "./db.js";
import {
constructTransactionIdentifier,
- notifyTransition,
} from "./transactions.js";
import { InternalWalletState, WalletExecutionContext } from "./wallet.js";
-const logger = new Logger("operations/tip.ts");
-
export class RewardTransactionContext implements TransactionContext {
public transactionId: TransactionIdStr;
public taskId: TaskIdStr;
@@ -65,177 +62,23 @@ export class RewardTransactionContext implements TransactionContext {
}
async deleteTransaction(): Promise<void> {
- const { wex, walletRewardId } = this;
- await wex.db.runReadWriteTx(["rewards", "tombstones"], async (tx) => {
- const tipRecord = await tx.rewards.get(walletRewardId);
- if (tipRecord) {
- await tx.rewards.delete(walletRewardId);
- await tx.tombstones.put({
- id: TombstoneTag.DeleteReward + ":" + walletRewardId,
- });
- }
- });
+ throw Error("unsupported operation");
}
async suspendTransaction(): Promise<void> {
- const { wex, walletRewardId, transactionId, taskId } = this;
- const transitionInfo = await wex.db.runReadWriteTx(
- ["rewards"],
- async (tx) => {
- const tipRec = await tx.rewards.get(walletRewardId);
- if (!tipRec) {
- logger.warn(`transaction tip ${walletRewardId} not found`);
- return;
- }
- let newStatus: RewardRecordStatus | undefined = undefined;
- switch (tipRec.status) {
- case RewardRecordStatus.Done:
- case RewardRecordStatus.SuspendedPickup:
- case RewardRecordStatus.Aborted:
- case RewardRecordStatus.DialogAccept:
- case RewardRecordStatus.Failed:
- break;
- case RewardRecordStatus.PendingPickup:
- newStatus = RewardRecordStatus.SuspendedPickup;
- break;
-
- default:
- assertUnreachable(tipRec.status);
- }
- if (newStatus != null) {
- const oldTxState = computeRewardTransactionStatus(tipRec);
- tipRec.status = newStatus;
- const newTxState = computeRewardTransactionStatus(tipRec);
- await tx.rewards.put(tipRec);
- return {
- oldTxState,
- newTxState,
- };
- }
- return undefined;
- },
- );
- notifyTransition(wex, transactionId, transitionInfo);
+ throw Error("unsupported operation");
}
async abortTransaction(): Promise<void> {
- const { wex, walletRewardId, transactionId } = this;
- const transitionInfo = await wex.db.runReadWriteTx(
- ["rewards"],
- async (tx) => {
- const tipRec = await tx.rewards.get(walletRewardId);
- if (!tipRec) {
- logger.warn(`transaction tip ${walletRewardId} not found`);
- return;
- }
- let newStatus: RewardRecordStatus | undefined = undefined;
- switch (tipRec.status) {
- case RewardRecordStatus.Done:
- case RewardRecordStatus.Aborted:
- case RewardRecordStatus.PendingPickup:
- case RewardRecordStatus.DialogAccept:
- case RewardRecordStatus.Failed:
- break;
- case RewardRecordStatus.SuspendedPickup:
- newStatus = RewardRecordStatus.Aborted;
- break;
- default:
- assertUnreachable(tipRec.status);
- }
- if (newStatus != null) {
- const oldTxState = computeRewardTransactionStatus(tipRec);
- tipRec.status = newStatus;
- const newTxState = computeRewardTransactionStatus(tipRec);
- await tx.rewards.put(tipRec);
- return {
- oldTxState,
- newTxState,
- };
- }
- return undefined;
- },
- );
- notifyTransition(wex, transactionId, transitionInfo);
+ throw Error("unsupported operation");
}
async resumeTransaction(): Promise<void> {
- const { wex: ws, walletRewardId, transactionId, taskId: retryTag } = this;
- const transitionInfo = await ws.db.runReadWriteTx(
- ["rewards"],
- async (tx) => {
- const rewardRec = await tx.rewards.get(walletRewardId);
- if (!rewardRec) {
- logger.warn(`transaction reward ${walletRewardId} not found`);
- return;
- }
- let newStatus: RewardRecordStatus | undefined = undefined;
- switch (rewardRec.status) {
- case RewardRecordStatus.Done:
- case RewardRecordStatus.PendingPickup:
- case RewardRecordStatus.Aborted:
- case RewardRecordStatus.DialogAccept:
- case RewardRecordStatus.Failed:
- break;
- case RewardRecordStatus.SuspendedPickup:
- newStatus = RewardRecordStatus.PendingPickup;
- break;
- default:
- assertUnreachable(rewardRec.status);
- }
- if (newStatus != null) {
- const oldTxState = computeRewardTransactionStatus(rewardRec);
- rewardRec.status = newStatus;
- const newTxState = computeRewardTransactionStatus(rewardRec);
- await tx.rewards.put(rewardRec);
- return {
- oldTxState,
- newTxState,
- };
- }
- return undefined;
- },
- );
- notifyTransition(ws, transactionId, transitionInfo);
+ throw Error("unsupported operation");
}
async failTransaction(): Promise<void> {
- const { wex: ws, walletRewardId, transactionId, taskId: retryTag } = this;
- const transitionInfo = await ws.db.runReadWriteTx(
- ["rewards"],
- async (tx) => {
- const tipRec = await tx.rewards.get(walletRewardId);
- if (!tipRec) {
- logger.warn(`transaction tip ${walletRewardId} not found`);
- return;
- }
- let newStatus: RewardRecordStatus | undefined = undefined;
- switch (tipRec.status) {
- case RewardRecordStatus.Done:
- case RewardRecordStatus.Aborted:
- case RewardRecordStatus.Failed:
- break;
- case RewardRecordStatus.PendingPickup:
- case RewardRecordStatus.DialogAccept:
- case RewardRecordStatus.SuspendedPickup:
- newStatus = RewardRecordStatus.Failed;
- break;
- default:
- assertUnreachable(tipRec.status);
- }
- if (newStatus != null) {
- const oldTxState = computeRewardTransactionStatus(tipRec);
- tipRec.status = newStatus;
- const newTxState = computeRewardTransactionStatus(tipRec);
- await tx.rewards.put(tipRec);
- return {
- oldTxState,
- newTxState,
- };
- }
- return undefined;
- },
- );
- notifyTransition(ws, transactionId, transitionInfo);
+ throw Error("unsupported operation");
}
}
diff --git a/packages/taler-wallet-core/src/transactions.ts b/packages/taler-wallet-core/src/transactions.ts
index 1660c8d09..7ece43dc5 100644
--- a/packages/taler-wallet-core/src/transactions.ts
+++ b/packages/taler-wallet-core/src/transactions.ts
@@ -322,19 +322,7 @@ export async function getTransactionById(
}
case TransactionType.Reward: {
- const tipId = parsedTx.walletRewardId;
- return await wex.db.runReadWriteTx(
- ["rewards", "operationRetries"],
- async (tx) => {
- const tipRecord = await tx.rewards.get(tipId);
- if (!tipRecord) throw Error("not found");
-
- const retries = await tx.operationRetries.get(
- TaskIdentifiers.forTipPickup(tipRecord),
- );
- return buildTransactionForTip(tipRecord, retries);
- },
- );
+ throw Error("unsupported operation");
}
case TransactionType.Deposit: {
@@ -923,31 +911,6 @@ function buildTransactionForDeposit(
};
}
-function buildTransactionForTip(
- tipRecord: RewardRecord,
- ort?: OperationRetryRecord,
-): Transaction {
- checkLogicInvariant(!!tipRecord.acceptedTimestamp);
-
- const txState = computeRewardTransactionStatus(tipRecord);
- return {
- type: TransactionType.Reward,
- txState,
- txActions: computeTipTransactionActions(tipRecord),
- amountEffective: isUnsuccessfulTransaction(txState)
- ? Amounts.stringify(Amounts.zeroOfAmount(tipRecord.rewardAmountEffective))
- : Amounts.stringify(tipRecord.rewardAmountEffective),
- amountRaw: Amounts.stringify(tipRecord.rewardAmountRaw),
- timestamp: timestampPreciseFromDb(tipRecord.acceptedTimestamp),
- transactionId: constructTransactionIdentifier({
- tag: TransactionType.Reward,
- walletRewardId: tipRecord.walletRewardId,
- }),
- merchantBaseUrl: tipRecord.merchantBaseUrl,
- ...(ort?.lastError ? { error: ort.lastError } : {}),
- };
-}
-
async function lookupMaybeContractData(
tx: WalletDbReadOnlyTransaction<["purchases", "contractTerms"]>,
proposalId: string,
@@ -1444,26 +1407,6 @@ export async function getTransactions(
),
);
});
-
- //FIXME: remove rewards
- await iterRecordsForReward(tx, filter, async (tipRecord) => {
- if (
- shouldSkipCurrency(
- transactionsRequest,
- Amounts.parseOrThrow(tipRecord.rewardAmountRaw).currency,
- [tipRecord.exchangeBaseUrl],
- )
- ) {
- return;
- }
- if (!tipRecord.acceptedTimestamp) {
- return;
- }
- const opId = TaskIdentifiers.forTipPickup(tipRecord);
- const retryRecord = await tx.operationRetries.get(opId);
- transactions.push(buildTransactionForTip(tipRecord, retryRecord));
- });
- //ends REMOVE REWARDS
},
);
@@ -1904,22 +1847,6 @@ async function iterRecordsForDeposit(
}
}
-async function iterRecordsForReward(
- tx: WalletDbReadOnlyTransaction<["rewards"]>,
- filter: TransactionRecordFilter,
- f: (r: RewardRecord) => Promise<void>,
-): Promise<void> {
- if (filter.onlyState === "nonfinal") {
- const keyRange = GlobalIDB.KeyRange.bound(
- OPERATION_STATUS_ACTIVE_FIRST,
- OPERATION_STATUS_ACTIVE_LAST,
- );
- await tx.rewards.indexes.byStatus.iter(keyRange).forEachAsync(f);
- } else {
- await tx.rewards.indexes.byStatus.iter().forEachAsync(f);
- }
-}
-
async function iterRecordsForRefund(
tx: WalletDbReadOnlyTransaction<["refundGroups"]>,
filter: TransactionRecordFilter,