gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: add providers filter to runBa


From: gnunet
Subject: [taler-wallet-core] branch master updated: add providers filter to runBackupCycle
Date: Wed, 07 Jul 2021 18:28:39 +0200

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new ebfc7975 add providers filter to runBackupCycle
ebfc7975 is described below

commit ebfc79756f14b08ac3735b2746ac48fd3483b5e4
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Wed Jul 7 13:28:02 2021 -0300

    add providers filter to runBackupCycle
---
 packages/taler-util/src/helpers.ts                 | 15 ++++++++++++++
 .../src/operations/backup/index.ts                 | 23 ++++++++++++++++++++--
 packages/taler-wallet-core/src/wallet.ts           |  4 +++-
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/packages/taler-util/src/helpers.ts 
b/packages/taler-util/src/helpers.ts
index 53a9a43d..089602c9 100644
--- a/packages/taler-util/src/helpers.ts
+++ b/packages/taler-util/src/helpers.ts
@@ -110,3 +110,18 @@ export function strcmp(s1: string, s2: string): number {
 export function j2s(x: any): string {
   return JSON.stringify(x, undefined, 2);
 }
+
+/**
+ * Use this to filter null or undefined from an array in a type-safe fashion
+ * 
+ * example:
+ * const array: Array<T | undefined> = [undefined, null]
+ * const filtered: Array<T> = array.filter(notEmpty)
+ * 
+ * @param value 
+ * @returns 
+ */
+export function notEmpty<T>(value: T | null | undefined): value is T {
+  return value !== null && value !== undefined;
+}
+
diff --git a/packages/taler-wallet-core/src/operations/backup/index.ts 
b/packages/taler-wallet-core/src/operations/backup/index.ts
index 68040695..9593325a 100644
--- a/packages/taler-wallet-core/src/operations/backup/index.ts
+++ b/packages/taler-wallet-core/src/operations/backup/index.ts
@@ -33,6 +33,7 @@ import {
   Codec,
   codecForAmountString,
   codecForBoolean,
+  codecForList,
   codecForNumber,
   codecForString,
   codecOptional,
@@ -41,6 +42,7 @@ import {
   getTimestampNow,
   j2s,
   Logger,
+  notEmpty,
   NotificationType,
   PreparePayResultType,
   RecoveryLoadRequest,
@@ -520,6 +522,19 @@ export async function processBackupForProvider(
   await guardOperationException(run, onOpErr);
 }
 
+
+export interface RunBackupCycleRequest {
+  /**
+   * List of providers to backup or empty for all known providers. 
+   */
+  providers?: Array<string>;
+}
+
+export const codecForRunBackupCycle = (): Codec<RunBackupCycleRequest> =>
+  buildCodecForObject<RunBackupCycleRequest>()
+    .property("providers", codecOptional(codecForList(codecForString())))
+    .build("RunBackupCycleRequest");
+
 /**
  * Do one backup cycle that consists of:
  * 1. Exporting a backup and try to upload it.
@@ -527,11 +542,15 @@ export async function processBackupForProvider(
  * 2. Download, verify and import backups from connected sync accounts.
  * 3. Upload the updated backup blob.
  */
-export async function runBackupCycle(ws: InternalWalletState): Promise<void> {
+export async function runBackupCycle(ws: InternalWalletState, req: 
RunBackupCycleRequest): Promise<void> {
   const providers = await ws.db
     .mktx((x) => ({ backupProviders: x.backupProviders }))
     .runReadOnly(async (tx) => {
-      return await tx.backupProviders.iter().toArray();
+      if (req.providers) {
+        const rs = await Promise.all(req.providers.map(id => 
tx.backupProviders.get(id)))
+        return rs.filter(notEmpty)
+      }
+      return await tx.backupProviders.iter(req.providers).toArray();
     });
   const backupJson = await exportBackup(ws);
   const backupConfig = await provideBackupState(ws);
diff --git a/packages/taler-wallet-core/src/wallet.ts 
b/packages/taler-wallet-core/src/wallet.ts
index ca9afc07..d46914b3 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -41,6 +41,7 @@ import {
 import {
   addBackupProvider,
   codecForAddBackupProviderRequest,
+  codecForRunBackupCycle,
   getBackupInfo,
   getBackupRecovery,
   loadBackupRecovery,
@@ -809,7 +810,8 @@ async function dispatchRequestInternal(
       return {};
     }
     case "runBackupCycle": {
-      await runBackupCycle(ws);
+      const req = codecForRunBackupCycle().decode(payload);
+      await runBackupCycle(ws, req);
       return {};
     }
     case "exportBackupRecovery": {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]