diff options
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 28 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/peer-to-peer.ts | 5 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/transactions.ts | 73 |
3 files changed, 88 insertions, 18 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 3f97be045..903dfa47d 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -1180,9 +1180,9 @@ export const WALLET_BACKUP_STATE_KEY = "walletBackupState"; */ export type ConfigRecord = | { - key: typeof WALLET_BACKUP_STATE_KEY; - value: WalletBackupConfState; - } + key: typeof WALLET_BACKUP_STATE_KEY; + value: WalletBackupConfState; + } | { key: "currencyDefaultsApplied"; value: boolean }; export interface WalletBackupConfState { @@ -1243,6 +1243,7 @@ export interface WgInfoBankManual { export interface WgInfoBankPeerPull { withdrawalType: WithdrawalRecordType.PeerPullCredit; + contractTerms: any; /** * Needed to quickly construct the taler:// URI for the counterparty * without a join. @@ -1252,6 +1253,8 @@ export interface WgInfoBankPeerPull { export interface WgInfoBankPeerPush { withdrawalType: WithdrawalRecordType.PeerPushCredit; + + contractTerms: any; } export interface WgInfoBankRecoup { @@ -1445,17 +1448,17 @@ export enum BackupProviderStateTag { export type BackupProviderState = | { - tag: BackupProviderStateTag.Provisional; - } + tag: BackupProviderStateTag.Provisional; + } | { - tag: BackupProviderStateTag.Ready; - nextBackupTimestamp: TalerProtocolTimestamp; - } + tag: BackupProviderStateTag.Ready; + nextBackupTimestamp: TalerProtocolTimestamp; + } | { - tag: BackupProviderStateTag.Retrying; - retryInfo: RetryInfo; - lastError?: TalerErrorDetail; - }; + tag: BackupProviderStateTag.Retrying; + retryInfo: RetryInfo; + lastError?: TalerErrorDetail; + }; export interface BackupProviderTerms { supportedProtocolVersion: string; @@ -1630,6 +1633,7 @@ export interface PeerPushPaymentInitiationRecord { amount: AmountString; + contractTerms: any; /** * Purse public key. Used as the primary key to look * up this record. diff --git a/packages/taler-wallet-core/src/operations/peer-to-peer.ts b/packages/taler-wallet-core/src/operations/peer-to-peer.ts index 88bfecd3b..275258081 100644 --- a/packages/taler-wallet-core/src/operations/peer-to-peer.ts +++ b/packages/taler-wallet-core/src/operations/peer-to-peer.ts @@ -263,6 +263,7 @@ export async function initiatePeerToPeerPush( await tx.peerPushPaymentInitiations.add({ amount: Amounts.stringify(instructedAmount), contractPriv: econtractResp.contractPriv, + contractTerms, exchangeBaseUrl: sel.exchangeBaseUrl, mergePriv: mergePair.priv, mergePub: mergePair.pub, @@ -536,6 +537,7 @@ export async function acceptPeerPushPayment( amount, wgInfo: { withdrawalType: WithdrawalRecordType.PeerPushCredit, + contractTerms: peerInc.contractTerms, }, exchangeBaseUrl: peerInc.exchangeBaseUrl, reserveStatus: ReserveRecordStatus.QueryingStatus, @@ -552,7 +554,7 @@ export async function acceptPeerPushPayment( export async function acceptPeerPullPayment( ws: InternalWalletState, req: AcceptPeerPullPaymentRequest, -) { +): Promise<void> { const peerPullInc = await ws.db .mktx((x) => ({ peerPullPaymentIncoming: x.peerPullPaymentIncoming })) .runReadOnly(async (tx) => { @@ -808,6 +810,7 @@ export async function initiatePeerRequestForPay( amount: Amounts.parseOrThrow(req.amount), wgInfo: { withdrawalType: WithdrawalRecordType.PeerPullCredit, + contractTerms, contractPriv: econtractResp.contractPriv, }, exchangeBaseUrl: req.exchangeBaseUrl, diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index 8eff945c5..11f47d8a0 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -59,6 +59,8 @@ export enum TombstoneTag { DeleteRefreshGroup = "delete-refresh-group", DeleteDepositGroup = "delete-deposit-group", DeleteRefund = "delete-refund", + DeletePeerPullDebit = "delete-peer-pull-debit", + DeletePeerPushDebit = "delete-peer-push-debit", } /** @@ -144,6 +146,7 @@ export async function getTransactions( .runReadOnly(async (tx) => { tx.peerPushPaymentInitiations.iter().forEachAsync(async (pi) => { const amount = Amounts.parseOrThrow(pi.amount); + if (shouldSkipCurrency(transactionsRequest, amount.currency)) { return; } @@ -155,6 +158,11 @@ export async function getTransactions( amountEffective: pi.amount, amountRaw: pi.amount, exchangeBaseUrl: pi.exchangeBaseUrl, + info: { + expiration: pi.contractTerms.purse_expiration, + summary: pi.contractTerms.summary, + completed: Amounts.isZero(amount), + }, frozen: false, pending: !pi.purseCreated, timestamp: pi.timestampCreated, @@ -180,6 +188,7 @@ export async function getTransactions( if (!pi.accepted) { return; } + transactions.push({ type: TransactionType.PeerPullDebit, amountEffective: Amounts.stringify(amount), @@ -187,10 +196,15 @@ export async function getTransactions( exchangeBaseUrl: pi.exchangeBaseUrl, frozen: false, pending: false, + info: { + expiration: pi.contractTerms.purse_expiration, + summary: pi.contractTerms.summary, + completed: pi.paid + }, timestamp: pi.timestampCreated, transactionId: makeEventId( TransactionType.PeerPullDebit, - pi.pursePub, + pi.peerPullPaymentIncomingId, ), }); }); @@ -217,6 +231,11 @@ export async function getTransactions( exchangeBaseUrl: wsr.exchangeBaseUrl, pending: !wsr.timestampFinish, timestamp: wsr.timestampStart, + info: { + expiration: wsr.wgInfo.contractTerms.purse_expiration, + summary: wsr.wgInfo.contractTerms.summary, + completed: !!wsr.timestampFinish + }, talerUri: constructPayPullUri({ exchangeBaseUrl: wsr.exchangeBaseUrl, contractPriv: wsr.wgInfo.contractPriv, @@ -237,6 +256,11 @@ export async function getTransactions( amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue), amountRaw: Amounts.stringify(wsr.rawWithdrawalAmount), exchangeBaseUrl: wsr.exchangeBaseUrl, + info: { + expiration: wsr.wgInfo.contractTerms.purse_expiration, + summary: wsr.wgInfo.contractTerms.summary, + completed: !!wsr.timestampFinish, + }, pending: !wsr.timestampFinish, timestamp: wsr.timestampStart, transactionId: makeEventId( @@ -567,9 +591,9 @@ export async function deleteTransaction( ws: InternalWalletState, transactionId: string, ): Promise<void> { - const [type, ...rest] = transactionId.split(":"); - - if (type === TransactionType.Withdrawal) { + const [typeStr, ...rest] = transactionId.split(":"); + const type = typeStr as TransactionType; + if (type === TransactionType.Withdrawal || type === TransactionType.PeerPullCredit || type === TransactionType.PeerPushCredit) { const withdrawalGroupId = rest[0]; await ws.db .mktx((x) => ({ @@ -686,7 +710,46 @@ export async function deleteTransaction( }); } }); + } else if (type === TransactionType.PeerPullDebit) { + const peerPullPaymentIncomingId = rest[0]; + await ws.db + .mktx((x) => ({ + peerPullPaymentIncoming: x.peerPullPaymentIncoming, + tombstones: x.tombstones, + })) + .runReadWrite(async (tx) => { + const debit = await tx.peerPullPaymentIncoming.get(peerPullPaymentIncomingId); + if (debit) { + await tx.peerPullPaymentIncoming.delete(peerPullPaymentIncomingId); + await tx.tombstones.put({ + id: makeEventId( + TombstoneTag.DeletePeerPullDebit, + peerPullPaymentIncomingId, + ), + }); + } + }); + } else if (type === TransactionType.PeerPushDebit) { + const pursePub = rest[0]; + await ws.db + .mktx((x) => ({ + peerPushPaymentInitiations: x.peerPushPaymentInitiations, + tombstones: x.tombstones, + })) + .runReadWrite(async (tx) => { + const debit = await tx.peerPushPaymentInitiations.get(pursePub); + if (debit) { + await tx.peerPushPaymentInitiations.delete(pursePub); + await tx.tombstones.put({ + id: makeEventId( + TombstoneTag.DeletePeerPushDebit, + pursePub, + ), + }); + } + }); } else { - throw Error(`can't delete a '${type}' transaction`); + const unknownTxType: never = type; + throw Error(`can't delete a '${unknownTxType}' transaction`); } } |