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; withdrawalDetails: WithdrawalDetails;
} }
export interface PeerInfoShort {
expiration: TalerProtocolTimestamp | undefined;
summary: string | undefined;
completed: boolean;
}
/** /**
* Credit because we were paid for a P2P invoice we created. * Credit because we were paid for a P2P invoice we created.
*/ */
export interface TransactionPeerPullCredit extends TransactionCommon { export interface TransactionPeerPullCredit extends TransactionCommon {
type: TransactionType.PeerPullCredit; type: TransactionType.PeerPullCredit;
info: PeerInfoShort;
/** /**
* Exchange used. * Exchange used.
*/ */
@ -220,6 +227,7 @@ export interface TransactionPeerPullCredit extends TransactionCommon {
export interface TransactionPeerPullDebit extends TransactionCommon { export interface TransactionPeerPullDebit extends TransactionCommon {
type: TransactionType.PeerPullDebit; type: TransactionType.PeerPullDebit;
info: PeerInfoShort;
/** /**
* Exchange used. * Exchange used.
*/ */
@ -236,6 +244,7 @@ export interface TransactionPeerPullDebit extends TransactionCommon {
export interface TransactionPeerPushDebit extends TransactionCommon { export interface TransactionPeerPushDebit extends TransactionCommon {
type: TransactionType.PeerPushDebit; type: TransactionType.PeerPushDebit;
info: PeerInfoShort;
/** /**
* Exchange used. * Exchange used.
*/ */
@ -263,6 +272,7 @@ export interface TransactionPeerPushDebit extends TransactionCommon {
export interface TransactionPeerPushCredit extends TransactionCommon { export interface TransactionPeerPushCredit extends TransactionCommon {
type: TransactionType.PeerPushCredit; type: TransactionType.PeerPushCredit;
info: PeerInfoShort;
/** /**
* Exchange used. * Exchange used.
*/ */

View File

@ -1180,9 +1180,9 @@ export const WALLET_BACKUP_STATE_KEY = "walletBackupState";
*/ */
export type ConfigRecord = export type ConfigRecord =
| { | {
key: typeof WALLET_BACKUP_STATE_KEY; key: typeof WALLET_BACKUP_STATE_KEY;
value: WalletBackupConfState; value: WalletBackupConfState;
} }
| { key: "currencyDefaultsApplied"; value: boolean }; | { key: "currencyDefaultsApplied"; value: boolean };
export interface WalletBackupConfState { export interface WalletBackupConfState {
@ -1243,6 +1243,7 @@ export interface WgInfoBankManual {
export interface WgInfoBankPeerPull { export interface WgInfoBankPeerPull {
withdrawalType: WithdrawalRecordType.PeerPullCredit; withdrawalType: WithdrawalRecordType.PeerPullCredit;
contractTerms: any;
/** /**
* Needed to quickly construct the taler:// URI for the counterparty * Needed to quickly construct the taler:// URI for the counterparty
* without a join. * without a join.
@ -1252,6 +1253,8 @@ export interface WgInfoBankPeerPull {
export interface WgInfoBankPeerPush { export interface WgInfoBankPeerPush {
withdrawalType: WithdrawalRecordType.PeerPushCredit; withdrawalType: WithdrawalRecordType.PeerPushCredit;
contractTerms: any;
} }
export interface WgInfoBankRecoup { export interface WgInfoBankRecoup {
@ -1445,17 +1448,17 @@ export enum BackupProviderStateTag {
export type BackupProviderState = export type BackupProviderState =
| { | {
tag: BackupProviderStateTag.Provisional; tag: BackupProviderStateTag.Provisional;
} }
| { | {
tag: BackupProviderStateTag.Ready; tag: BackupProviderStateTag.Ready;
nextBackupTimestamp: TalerProtocolTimestamp; nextBackupTimestamp: TalerProtocolTimestamp;
} }
| { | {
tag: BackupProviderStateTag.Retrying; tag: BackupProviderStateTag.Retrying;
retryInfo: RetryInfo; retryInfo: RetryInfo;
lastError?: TalerErrorDetail; lastError?: TalerErrorDetail;
}; };
export interface BackupProviderTerms { export interface BackupProviderTerms {
supportedProtocolVersion: string; supportedProtocolVersion: string;
@ -1630,6 +1633,7 @@ export interface PeerPushPaymentInitiationRecord {
amount: AmountString; amount: AmountString;
contractTerms: any;
/** /**
* Purse public key. Used as the primary key to look * Purse public key. Used as the primary key to look
* up this record. * up this record.

View File

@ -263,6 +263,7 @@ export async function initiatePeerToPeerPush(
await tx.peerPushPaymentInitiations.add({ await tx.peerPushPaymentInitiations.add({
amount: Amounts.stringify(instructedAmount), amount: Amounts.stringify(instructedAmount),
contractPriv: econtractResp.contractPriv, contractPriv: econtractResp.contractPriv,
contractTerms,
exchangeBaseUrl: sel.exchangeBaseUrl, exchangeBaseUrl: sel.exchangeBaseUrl,
mergePriv: mergePair.priv, mergePriv: mergePair.priv,
mergePub: mergePair.pub, mergePub: mergePair.pub,
@ -536,6 +537,7 @@ export async function acceptPeerPushPayment(
amount, amount,
wgInfo: { wgInfo: {
withdrawalType: WithdrawalRecordType.PeerPushCredit, withdrawalType: WithdrawalRecordType.PeerPushCredit,
contractTerms: peerInc.contractTerms,
}, },
exchangeBaseUrl: peerInc.exchangeBaseUrl, exchangeBaseUrl: peerInc.exchangeBaseUrl,
reserveStatus: ReserveRecordStatus.QueryingStatus, reserveStatus: ReserveRecordStatus.QueryingStatus,
@ -552,7 +554,7 @@ export async function acceptPeerPushPayment(
export async function acceptPeerPullPayment( export async function acceptPeerPullPayment(
ws: InternalWalletState, ws: InternalWalletState,
req: AcceptPeerPullPaymentRequest, req: AcceptPeerPullPaymentRequest,
) { ): Promise<void> {
const peerPullInc = await ws.db const peerPullInc = await ws.db
.mktx((x) => ({ peerPullPaymentIncoming: x.peerPullPaymentIncoming })) .mktx((x) => ({ peerPullPaymentIncoming: x.peerPullPaymentIncoming }))
.runReadOnly(async (tx) => { .runReadOnly(async (tx) => {
@ -808,6 +810,7 @@ export async function initiatePeerRequestForPay(
amount: Amounts.parseOrThrow(req.amount), amount: Amounts.parseOrThrow(req.amount),
wgInfo: { wgInfo: {
withdrawalType: WithdrawalRecordType.PeerPullCredit, withdrawalType: WithdrawalRecordType.PeerPullCredit,
contractTerms,
contractPriv: econtractResp.contractPriv, contractPriv: econtractResp.contractPriv,
}, },
exchangeBaseUrl: req.exchangeBaseUrl, exchangeBaseUrl: req.exchangeBaseUrl,

View File

@ -59,6 +59,8 @@ export enum TombstoneTag {
DeleteRefreshGroup = "delete-refresh-group", DeleteRefreshGroup = "delete-refresh-group",
DeleteDepositGroup = "delete-deposit-group", DeleteDepositGroup = "delete-deposit-group",
DeleteRefund = "delete-refund", DeleteRefund = "delete-refund",
DeletePeerPullDebit = "delete-peer-pull-debit",
DeletePeerPushDebit = "delete-peer-push-debit",
} }
/** /**
@ -144,6 +146,7 @@ export async function getTransactions(
.runReadOnly(async (tx) => { .runReadOnly(async (tx) => {
tx.peerPushPaymentInitiations.iter().forEachAsync(async (pi) => { tx.peerPushPaymentInitiations.iter().forEachAsync(async (pi) => {
const amount = Amounts.parseOrThrow(pi.amount); const amount = Amounts.parseOrThrow(pi.amount);
if (shouldSkipCurrency(transactionsRequest, amount.currency)) { if (shouldSkipCurrency(transactionsRequest, amount.currency)) {
return; return;
} }
@ -155,6 +158,11 @@ export async function getTransactions(
amountEffective: pi.amount, amountEffective: pi.amount,
amountRaw: pi.amount, amountRaw: pi.amount,
exchangeBaseUrl: pi.exchangeBaseUrl, exchangeBaseUrl: pi.exchangeBaseUrl,
info: {
expiration: pi.contractTerms.purse_expiration,
summary: pi.contractTerms.summary,
completed: Amounts.isZero(amount),
},
frozen: false, frozen: false,
pending: !pi.purseCreated, pending: !pi.purseCreated,
timestamp: pi.timestampCreated, timestamp: pi.timestampCreated,
@ -180,6 +188,7 @@ export async function getTransactions(
if (!pi.accepted) { if (!pi.accepted) {
return; return;
} }
transactions.push({ transactions.push({
type: TransactionType.PeerPullDebit, type: TransactionType.PeerPullDebit,
amountEffective: Amounts.stringify(amount), amountEffective: Amounts.stringify(amount),
@ -187,10 +196,15 @@ export async function getTransactions(
exchangeBaseUrl: pi.exchangeBaseUrl, exchangeBaseUrl: pi.exchangeBaseUrl,
frozen: false, frozen: false,
pending: false, pending: false,
info: {
expiration: pi.contractTerms.purse_expiration,
summary: pi.contractTerms.summary,
completed: pi.paid
},
timestamp: pi.timestampCreated, timestamp: pi.timestampCreated,
transactionId: makeEventId( transactionId: makeEventId(
TransactionType.PeerPullDebit, TransactionType.PeerPullDebit,
pi.pursePub, pi.peerPullPaymentIncomingId,
), ),
}); });
}); });
@ -217,6 +231,11 @@ export async function getTransactions(
exchangeBaseUrl: wsr.exchangeBaseUrl, exchangeBaseUrl: wsr.exchangeBaseUrl,
pending: !wsr.timestampFinish, pending: !wsr.timestampFinish,
timestamp: wsr.timestampStart, timestamp: wsr.timestampStart,
info: {
expiration: wsr.wgInfo.contractTerms.purse_expiration,
summary: wsr.wgInfo.contractTerms.summary,
completed: !!wsr.timestampFinish
},
talerUri: constructPayPullUri({ talerUri: constructPayPullUri({
exchangeBaseUrl: wsr.exchangeBaseUrl, exchangeBaseUrl: wsr.exchangeBaseUrl,
contractPriv: wsr.wgInfo.contractPriv, contractPriv: wsr.wgInfo.contractPriv,
@ -237,6 +256,11 @@ export async function getTransactions(
amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue), amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue),
amountRaw: Amounts.stringify(wsr.rawWithdrawalAmount), amountRaw: Amounts.stringify(wsr.rawWithdrawalAmount),
exchangeBaseUrl: wsr.exchangeBaseUrl, exchangeBaseUrl: wsr.exchangeBaseUrl,
info: {
expiration: wsr.wgInfo.contractTerms.purse_expiration,
summary: wsr.wgInfo.contractTerms.summary,
completed: !!wsr.timestampFinish,
},
pending: !wsr.timestampFinish, pending: !wsr.timestampFinish,
timestamp: wsr.timestampStart, timestamp: wsr.timestampStart,
transactionId: makeEventId( transactionId: makeEventId(
@ -567,9 +591,9 @@ export async function deleteTransaction(
ws: InternalWalletState, ws: InternalWalletState,
transactionId: string, transactionId: string,
): Promise<void> { ): Promise<void> {
const [type, ...rest] = transactionId.split(":"); const [typeStr, ...rest] = transactionId.split(":");
const type = typeStr as TransactionType;
if (type === TransactionType.Withdrawal) { if (type === TransactionType.Withdrawal || type === TransactionType.PeerPullCredit || type === TransactionType.PeerPushCredit) {
const withdrawalGroupId = rest[0]; const withdrawalGroupId = rest[0];
await ws.db await ws.db
.mktx((x) => ({ .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 { } else {
throw Error(`can't delete a '${type}' transaction`); const unknownTxType: never = type;
throw Error(`can't delete a '${unknownTxType}' transaction`);
} }
} }