From ac8f116780a860c8f4acfdf5553bf90d76afe236 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 9 Aug 2022 15:00:45 +0200 Subject: implement peer to peer push payments --- .../src/operations/backup/export.ts | 24 --- .../src/operations/backup/import.ts | 185 ++++++++++----------- 2 files changed, 92 insertions(+), 117 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/backup') diff --git a/packages/taler-wallet-core/src/operations/backup/export.ts b/packages/taler-wallet-core/src/operations/backup/export.ts index d4c822972..c77ce1a85 100644 --- a/packages/taler-wallet-core/src/operations/backup/export.ts +++ b/packages/taler-wallet-core/src/operations/backup/export.ts @@ -88,7 +88,6 @@ export async function exportBackup( backupProviders: x.backupProviders, tips: x.tips, recoupGroups: x.recoupGroups, - reserves: x.reserves, withdrawalGroups: x.withdrawalGroups, })) .runReadWrite(async (tx) => { @@ -128,29 +127,6 @@ export async function exportBackup( }); }); - await tx.reserves.iter().forEach((reserve) => { - const backupReserve: BackupReserve = { - initial_selected_denoms: reserve.initialDenomSel.selectedDenoms.map( - (x) => ({ - count: x.count, - denom_pub_hash: x.denomPubHash, - }), - ), - initial_withdrawal_group_id: reserve.initialWithdrawalGroupId, - instructed_amount: Amounts.stringify(reserve.instructedAmount), - reserve_priv: reserve.reservePriv, - timestamp_created: reserve.timestampCreated, - withdrawal_groups: - withdrawalGroupsByReserve[reserve.reservePub] ?? [], - // FIXME! - timestamp_last_activity: reserve.timestampCreated, - }; - const backupReserves = (backupReservesByExchange[ - reserve.exchangeBaseUrl - ] ??= []); - backupReserves.push(backupReserve); - }); - await tx.tips.iter().forEach((tip) => { backupTips.push({ exchange_base_url: tip.exchangeBaseUrl, diff --git a/packages/taler-wallet-core/src/operations/backup/import.ts b/packages/taler-wallet-core/src/operations/backup/import.ts index e099fae57..f26c42770 100644 --- a/packages/taler-wallet-core/src/operations/backup/import.ts +++ b/packages/taler-wallet-core/src/operations/backup/import.ts @@ -236,7 +236,6 @@ export async function importBackup( backupProviders: x.backupProviders, tips: x.tips, recoupGroups: x.recoupGroups, - reserves: x.reserves, withdrawalGroups: x.withdrawalGroups, tombstones: x.tombstones, depositGroups: x.depositGroups, @@ -427,94 +426,98 @@ export async function importBackup( } } - for (const backupReserve of backupExchangeDetails.reserves) { - const reservePub = - cryptoComp.reservePrivToPub[backupReserve.reserve_priv]; - const ts = makeEventId(TombstoneTag.DeleteReserve, reservePub); - if (tombstoneSet.has(ts)) { - continue; - } - checkLogicInvariant(!!reservePub); - const existingReserve = await tx.reserves.get(reservePub); - const instructedAmount = Amounts.parseOrThrow( - backupReserve.instructed_amount, - ); - if (!existingReserve) { - let bankInfo: ReserveBankInfo | undefined; - if (backupReserve.bank_info) { - bankInfo = { - exchangePaytoUri: backupReserve.bank_info.exchange_payto_uri, - statusUrl: backupReserve.bank_info.status_url, - confirmUrl: backupReserve.bank_info.confirm_url, - }; - } - await tx.reserves.put({ - currency: instructedAmount.currency, - instructedAmount, - exchangeBaseUrl: backupExchangeDetails.base_url, - reservePub, - reservePriv: backupReserve.reserve_priv, - bankInfo, - timestampCreated: backupReserve.timestamp_created, - timestampBankConfirmed: - backupReserve.bank_info?.timestamp_bank_confirmed, - timestampReserveInfoPosted: - backupReserve.bank_info?.timestamp_reserve_info_posted, - senderWire: backupReserve.sender_wire, - retryInfo: RetryInfo.reset(), - lastError: undefined, - initialWithdrawalGroupId: - backupReserve.initial_withdrawal_group_id, - initialWithdrawalStarted: - backupReserve.withdrawal_groups.length > 0, - // FIXME! - reserveStatus: ReserveRecordStatus.QueryingStatus, - initialDenomSel: await getDenomSelStateFromBackup( - tx, - backupExchangeDetails.base_url, - backupReserve.initial_selected_denoms, - ), - // FIXME! - operationStatus: OperationStatus.Pending, - }); - } - for (const backupWg of backupReserve.withdrawal_groups) { - const ts = makeEventId( - TombstoneTag.DeleteWithdrawalGroup, - backupWg.withdrawal_group_id, - ); - if (tombstoneSet.has(ts)) { - continue; - } - const existingWg = await tx.withdrawalGroups.get( - backupWg.withdrawal_group_id, - ); - if (!existingWg) { - await tx.withdrawalGroups.put({ - denomsSel: await getDenomSelStateFromBackup( - tx, - backupExchangeDetails.base_url, - backupWg.selected_denoms, - ), - exchangeBaseUrl: backupExchangeDetails.base_url, - lastError: undefined, - rawWithdrawalAmount: Amounts.parseOrThrow( - backupWg.raw_withdrawal_amount, - ), - reservePub, - retryInfo: RetryInfo.reset(), - secretSeed: backupWg.secret_seed, - timestampStart: backupWg.timestamp_created, - timestampFinish: backupWg.timestamp_finish, - withdrawalGroupId: backupWg.withdrawal_group_id, - denomSelUid: backupWg.selected_denoms_id, - operationStatus: backupWg.timestamp_finish - ? OperationStatus.Finished - : OperationStatus.Pending, - }); - } - } - } + + // FIXME: import reserves with new schema + + // for (const backupReserve of backupExchangeDetails.reserves) { + // const reservePub = + // cryptoComp.reservePrivToPub[backupReserve.reserve_priv]; + // const ts = makeEventId(TombstoneTag.DeleteReserve, reservePub); + // if (tombstoneSet.has(ts)) { + // continue; + // } + // checkLogicInvariant(!!reservePub); + // const existingReserve = await tx.reserves.get(reservePub); + // const instructedAmount = Amounts.parseOrThrow( + // backupReserve.instructed_amount, + // ); + // if (!existingReserve) { + // let bankInfo: ReserveBankInfo | undefined; + // if (backupReserve.bank_info) { + // bankInfo = { + // exchangePaytoUri: backupReserve.bank_info.exchange_payto_uri, + // statusUrl: backupReserve.bank_info.status_url, + // confirmUrl: backupReserve.bank_info.confirm_url, + // }; + // } + // await tx.reserves.put({ + // currency: instructedAmount.currency, + // instructedAmount, + // exchangeBaseUrl: backupExchangeDetails.base_url, + // reservePub, + // reservePriv: backupReserve.reserve_priv, + // bankInfo, + // timestampCreated: backupReserve.timestamp_created, + // timestampBankConfirmed: + // backupReserve.bank_info?.timestamp_bank_confirmed, + // timestampReserveInfoPosted: + // backupReserve.bank_info?.timestamp_reserve_info_posted, + // senderWire: backupReserve.sender_wire, + // retryInfo: RetryInfo.reset(), + // lastError: undefined, + // initialWithdrawalGroupId: + // backupReserve.initial_withdrawal_group_id, + // initialWithdrawalStarted: + // backupReserve.withdrawal_groups.length > 0, + // // FIXME! + // reserveStatus: ReserveRecordStatus.QueryingStatus, + // initialDenomSel: await getDenomSelStateFromBackup( + // tx, + // backupExchangeDetails.base_url, + // backupReserve.initial_selected_denoms, + // ), + // // FIXME! + // operationStatus: OperationStatus.Pending, + // }); + // } + // for (const backupWg of backupReserve.withdrawal_groups) { + // const ts = makeEventId( + // TombstoneTag.DeleteWithdrawalGroup, + // backupWg.withdrawal_group_id, + // ); + // if (tombstoneSet.has(ts)) { + // continue; + // } + // const existingWg = await tx.withdrawalGroups.get( + // backupWg.withdrawal_group_id, + // ); + // if (!existingWg) { + // await tx.withdrawalGroups.put({ + // denomsSel: await getDenomSelStateFromBackup( + // tx, + // backupExchangeDetails.base_url, + // backupWg.selected_denoms, + // ), + // exchangeBaseUrl: backupExchangeDetails.base_url, + // lastError: undefined, + // rawWithdrawalAmount: Amounts.parseOrThrow( + // backupWg.raw_withdrawal_amount, + // ), + // reservePub, + // retryInfo: RetryInfo.reset(), + // secretSeed: backupWg.secret_seed, + // timestampStart: backupWg.timestamp_created, + // timestampFinish: backupWg.timestamp_finish, + // withdrawalGroupId: backupWg.withdrawal_group_id, + // denomSelUid: backupWg.selected_denoms_id, + // operationStatus: backupWg.timestamp_finish + // ? OperationStatus.Finished + // : OperationStatus.Pending, + // }); + // } + // } + // } + } for (const backupProposal of backupBlob.proposals) { @@ -920,10 +923,6 @@ export async function importBackup( } else if (type === TombstoneTag.DeleteRefund) { // Nothing required, will just prevent display // in the transactions list - } else if (type === TombstoneTag.DeleteReserve) { - // FIXME: Once we also have account (=kyc) reserves, - // we need to check if the reserve is an account before deleting here - await tx.reserves.delete(rest[0]); } else if (type === TombstoneTag.DeleteTip) { await tx.tips.delete(rest[0]); } else if (type === TombstoneTag.DeleteWithdrawalGroup) { -- cgit v1.2.3