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)
This commit is contained in:
Sebastian 2022-09-01 08:41:22 -03:00
parent e759684fd0
commit 94eeab8ad0
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
4 changed files with 98 additions and 18 deletions

View File

@ -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.
*/

View File

@ -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.

View File

@ -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,

View File

@ -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`);
}
}