gnunet-svn
[Top][All Lists]
Advanced

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

[taler-wallet-core] 01/02: more information about p2p:


From: gnunet
Subject: [taler-wallet-core] 01/02: more information about p2p:
Date: Thu, 01 Sep 2022 13:42:57 +0200

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

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

commit 94eeab8ad011d26e447b691a2deaccb91dee1fb7
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Thu Sep 1 08:41:22 2022 -0300

    more information about p2p:
    
     - added the contract terms on WgInfoBankPeerPush and WgInfoBankPeerPull, 
so we can show summary and expiration in the ui
     - added info: PeerInfoShort on Transaction* type
     - definition of completed p2p tx:
       - push debit: Amounts.cmp(sentAmount, pickedUpAmount) === 0. is this 
transfer already picked up? (not working)
       - pull debit: pi.paid, is this invoice already paid?
       - pull credit: wsr.timestampFinish, has someone already paid my invoice?
       - push credit: wsr.timestampFinish, have I already picked up this?
     - changed the txId of peer pull debit to have the incomingId instead of 
pursePub (allow deletion)
---
 packages/taler-util/src/transactionsTypes.ts       | 10 +++
 packages/taler-wallet-core/src/db.ts               | 28 +++++----
 .../src/operations/peer-to-peer.ts                 |  5 +-
 .../src/operations/transactions.ts                 | 73 ++++++++++++++++++++--
 4 files changed, 98 insertions(+), 18 deletions(-)

diff --git a/packages/taler-util/src/transactionsTypes.ts 
b/packages/taler-util/src/transactionsTypes.ts
index 79c62cbc..e4b1faf2 100644
--- a/packages/taler-util/src/transactionsTypes.ts
+++ b/packages/taler-util/src/transactionsTypes.ts
@@ -187,12 +187,19 @@ export interface TransactionWithdrawal extends 
TransactionCommon {
   withdrawalDetails: WithdrawalDetails;
 }
 
+export interface PeerInfoShort {
+  expiration: TalerProtocolTimestamp | undefined;
+  summary: string | undefined;
+  completed: boolean;
+}
+
 /**
  * Credit because we were paid for a P2P invoice we created.
  */
 export interface TransactionPeerPullCredit extends TransactionCommon {
   type: TransactionType.PeerPullCredit;
 
+  info: PeerInfoShort;
   /**
    * Exchange used.
    */
@@ -220,6 +227,7 @@ export interface TransactionPeerPullCredit extends 
TransactionCommon {
 export interface TransactionPeerPullDebit extends TransactionCommon {
   type: TransactionType.PeerPullDebit;
 
+  info: PeerInfoShort;
   /**
    * Exchange used.
    */
@@ -236,6 +244,7 @@ export interface TransactionPeerPullDebit extends 
TransactionCommon {
 export interface TransactionPeerPushDebit extends TransactionCommon {
   type: TransactionType.PeerPushDebit;
 
+  info: PeerInfoShort;
   /**
    * Exchange used.
    */
@@ -263,6 +272,7 @@ export interface TransactionPeerPushDebit extends 
TransactionCommon {
 export interface TransactionPeerPushCredit extends TransactionCommon {
   type: TransactionType.PeerPushCredit;
 
+  info: PeerInfoShort;
   /**
    * Exchange used.
    */
diff --git a/packages/taler-wallet-core/src/db.ts 
b/packages/taler-wallet-core/src/db.ts
index 3f97be04..903dfa47 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 88bfecd3..27525808 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 8eff945c..11f47d8a 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`);
   }
 }

-- 
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]