tipping transaction list entry, integration test and DB simplifications

This commit is contained in:
Florian Dold 2020-09-08 19:54:23 +05:30
parent b9e43e652e
commit 043a5f89fe
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
6 changed files with 50 additions and 50 deletions

View File

@ -109,4 +109,13 @@ runTest(async (t: GlobalTestState) => {
console.log(bal); console.log(bal);
t.assertAmountEquals(bal.balances[0].available, "TESTKUDOS:4.85"); t.assertAmountEquals(bal.balances[0].available, "TESTKUDOS:4.85");
const txns = await wallet.getTransactions();
console.log("Transactions:", JSON.stringify(txns, undefined, 2));
t.assertDeepEqual(txns.transactions[0].type, "tip");
t.assertDeepEqual(txns.transactions[0].pending, false);
t.assertAmountEquals(txns.transactions[0].amountEffective, "TESTKUDOS:4.85");
t.assertAmountEquals(txns.transactions[0].amountRaw, "TESTKUDOS:5.0");
}); });

View File

@ -351,7 +351,7 @@ async function gatherTipPending(
onlyDue = false, onlyDue = false,
): Promise<void> { ): Promise<void> {
await tx.iter(Stores.tips).forEach((tip) => { await tx.iter(Stores.tips).forEach((tip) => {
if (tip.pickedUp) { if (tip.pickedUpTimestamp) {
return; return;
} }
resp.nextRetryDelay = updateRetryDelay( resp.nextRetryDelay = updateRetryDelay(

View File

@ -25,11 +25,8 @@ import {
import * as Amounts from "../util/amounts"; import * as Amounts from "../util/amounts";
import { import {
Stores, Stores,
PlanchetRecord,
WithdrawalGroupRecord,
initRetryInfo, initRetryInfo,
updateRetryInfoTimeout, updateRetryInfoTimeout,
WithdrawalSourceType,
TipPlanchet, TipPlanchet,
CoinRecord, CoinRecord,
CoinSourceType, CoinSourceType,
@ -38,7 +35,6 @@ import {
import { import {
getExchangeWithdrawalInfo, getExchangeWithdrawalInfo,
selectWithdrawalDenoms, selectWithdrawalDenoms,
processWithdrawGroup,
denomSelectionInfoToState, denomSelectionInfoToState,
} from "./withdraw"; } from "./withdraw";
import { updateExchangeFromUrl } from "./exchanges"; import { updateExchangeFromUrl } from "./exchanges";
@ -102,15 +98,11 @@ export async function prepareTip(
tipRecord = { tipRecord = {
walletTipId: walletTipId, walletTipId: walletTipId,
acceptedTimestamp: undefined, acceptedTimestamp: undefined,
rejectedTimestamp: undefined,
tipAmountRaw: amount, tipAmountRaw: amount,
deadline: tipPickupStatus.expiration, tipExpiration: tipPickupStatus.expiration,
exchangeUrl: tipPickupStatus.exchange_url, exchangeBaseUrl: tipPickupStatus.exchange_url,
merchantBaseUrl: res.merchantBaseUrl, merchantBaseUrl: res.merchantBaseUrl,
nextUrl: undefined,
pickedUp: false,
planchets: undefined, planchets: undefined,
response: undefined,
createdTimestamp: getTimestampNow(), createdTimestamp: getTimestampNow(),
merchantTipId: res.merchantTipId, merchantTipId: res.merchantTipId,
tipAmountEffective: Amounts.sub(amount, Amounts.add( tipAmountEffective: Amounts.sub(amount, Amounts.add(
@ -120,6 +112,7 @@ export async function prepareTip(
retryInfo: initRetryInfo(), retryInfo: initRetryInfo(),
lastError: undefined, lastError: undefined,
denomsSel: denomSelectionInfoToState(selectedDenoms), denomsSel: denomSelectionInfoToState(selectedDenoms),
pickedUpTimestamp: undefined,
}; };
await ws.db.put(Stores.tips, tipRecord); await ws.db.put(Stores.tips, tipRecord);
} }
@ -197,7 +190,7 @@ async function processTipImpl(
return; return;
} }
if (tipRecord.pickedUp) { if (tipRecord.pickedUpTimestamp) {
logger.warn("tip already picked up"); logger.warn("tip already picked up");
return; return;
} }
@ -302,7 +295,7 @@ async function processTipImpl(
denomPub: planchet.denomPub, denomPub: planchet.denomPub,
denomPubHash: planchet.denomPubHash, denomPubHash: planchet.denomPubHash,
denomSig: denomSig, denomSig: denomSig,
exchangeBaseUrl: tipRecord.exchangeUrl, exchangeBaseUrl: tipRecord.exchangeBaseUrl,
status: CoinStatus.Fresh, status: CoinStatus.Fresh,
suspended: false, suspended: false,
}); });
@ -315,10 +308,11 @@ async function processTipImpl(
if (!tr) { if (!tr) {
return; return;
} }
if (tr.pickedUp) { if (tr.pickedUpTimestamp) {
return; return;
} }
tr.pickedUp = true; tr.pickedUpTimestamp = getTimestampNow();
tr.lastError = undefined;
tr.retryInfo = initRetryInfo(false); tr.retryInfo = initRetryInfo(false);
await tx.put(Stores.tips, tr); await tx.put(Stores.tips, tr);
for (const cr of newCoinRecords) { for (const cr of newCoinRecords) {

View File

@ -38,6 +38,7 @@ import {
OrderShortInfo, OrderShortInfo,
} from "../types/transactions"; } from "../types/transactions";
import { getFundingPaytoUris } from "./reserves"; import { getFundingPaytoUris } from "./reserves";
import { TipResponse } from "../types/talerTypes";
/** /**
* Create an event ID from the type and the primary key for the event. * Create an event ID from the type and the primary key for the event.
@ -308,6 +309,29 @@ export async function getTransactions(
}); });
}); });
}); });
tx.iter(Stores.tips).forEachAsync(async (tipRecord) => {
if (
shouldSkipCurrency(
transactionsRequest,
tipRecord.tipAmountRaw.currency,
)
) {
return;
}
if (!tipRecord.acceptedTimestamp) {
return;
}
transactions.push({
type: TransactionType.Tip,
amountEffective: Amounts.stringify(tipRecord.tipAmountEffective),
amountRaw: Amounts.stringify(tipRecord.tipAmountRaw),
pending: !tipRecord.pickedUpTimestamp,
timestamp: tipRecord.acceptedTimestamp,
transactionId: makeEventId(TransactionType.Tip, tipRecord.walletTipId),
error: tipRecord.lastError,
});
});
}, },
); );

View File

@ -950,16 +950,6 @@ export interface TipRecord {
*/ */
acceptedTimestamp: Timestamp | undefined; acceptedTimestamp: Timestamp | undefined;
/**
* Has the user rejected the tip?
*/
rejectedTimestamp: Timestamp | undefined;
/**
* Have we picked up the tip record from the merchant already?
*/
pickedUp: boolean;
/** /**
* The tipped amount. * The tipped amount.
*/ */
@ -970,12 +960,12 @@ export interface TipRecord {
/** /**
* Timestamp, the tip can't be picked up anymore after this deadline. * Timestamp, the tip can't be picked up anymore after this deadline.
*/ */
deadline: Timestamp; tipExpiration: Timestamp;
/** /**
* The exchange that will sign our coins, chosen by the merchant. * The exchange that will sign our coins, chosen by the merchant.
*/ */
exchangeUrl: string; exchangeBaseUrl: string;
/** /**
* Base URL of the merchant that is giving us the tip. * Base URL of the merchant that is giving us the tip.
@ -990,12 +980,6 @@ export interface TipRecord {
denomsSel: DenomSelectionState; denomsSel: DenomSelectionState;
/**
* Response if the merchant responded,
* undefined otherwise.
*/
response?: TipResponse[];
/** /**
* Tip ID chosen by the wallet. * Tip ID chosen by the wallet.
*/ */
@ -1006,13 +990,14 @@ export interface TipRecord {
*/ */
merchantTipId: string; merchantTipId: string;
/**
* URL to go to once the tip has been accepted.
*/
nextUrl?: string;
createdTimestamp: Timestamp; createdTimestamp: Timestamp;
/**
* Timestamp for when the wallet finished picking up the tip
* from the merchant.
*/
pickedUpTimestamp: Timestamp | undefined;
/** /**
* Retry info, even present when the operation isn't active to allow indexing * Retry info, even present when the operation isn't active to allow indexing
* on the next retry timestamp. * on the next retry timestamp.

View File

@ -278,18 +278,6 @@ interface TransactionRefund extends TransactionCommon {
interface TransactionTip extends TransactionCommon { interface TransactionTip extends TransactionCommon {
type: TransactionType.Tip; type: TransactionType.Tip;
// true if the user still needs to accept/decline this tip
waiting: boolean;
// true if the user has accepted this top, false otherwise
accepted: boolean;
// Exchange that the tip will be (or was) withdrawn from
exchangeBaseUrl: string;
// More information about the merchant that sent the tip
merchant: any;
// Raw amount of the tip, without extra fees that apply // Raw amount of the tip, without extra fees that apply
amountRaw: AmountString; amountRaw: AmountString;