wallet-core: handle 'never' timestamp in purse status
This commit is contained in:
parent
4e3e17edd1
commit
5bbf41ce1c
@ -110,6 +110,10 @@ export namespace TalerProtocolTimestamp {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isNever(t: TalerProtocolTimestamp): boolean {
|
||||||
|
return t.t_s === "never";
|
||||||
|
}
|
||||||
|
|
||||||
export function fromSeconds(s: number): TalerProtocolTimestamp {
|
export function fromSeconds(s: number): TalerProtocolTimestamp {
|
||||||
return {
|
return {
|
||||||
t_s: s,
|
t_s: s,
|
||||||
|
@ -29,6 +29,7 @@ import {
|
|||||||
NotificationType,
|
NotificationType,
|
||||||
TalerErrorCode,
|
TalerErrorCode,
|
||||||
TalerPreciseTimestamp,
|
TalerPreciseTimestamp,
|
||||||
|
TalerProtocolTimestamp,
|
||||||
TalerUriAction,
|
TalerUriAction,
|
||||||
TransactionAction,
|
TransactionAction,
|
||||||
TransactionMajorState,
|
TransactionMajorState,
|
||||||
@ -64,12 +65,11 @@ import { PendingTaskType } from "../pending-types.js";
|
|||||||
import { assertUnreachable } from "../util/assertUnreachable.js";
|
import { assertUnreachable } from "../util/assertUnreachable.js";
|
||||||
import { checkDbInvariant } from "../util/invariants.js";
|
import { checkDbInvariant } from "../util/invariants.js";
|
||||||
import {
|
import {
|
||||||
|
LongpollResult,
|
||||||
OperationAttemptResult,
|
OperationAttemptResult,
|
||||||
OperationAttemptResultType,
|
OperationAttemptResultType,
|
||||||
constructTaskIdentifier,
|
constructTaskIdentifier,
|
||||||
LongpollResult,
|
|
||||||
runLongpollAsync,
|
runLongpollAsync,
|
||||||
runTaskWithErrorReporting,
|
|
||||||
} from "./common.js";
|
} from "./common.js";
|
||||||
import {
|
import {
|
||||||
codecForExchangePurseStatus,
|
codecForExchangePurseStatus,
|
||||||
@ -84,7 +84,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
getExchangeWithdrawalInfo,
|
getExchangeWithdrawalInfo,
|
||||||
internalCreateWithdrawalGroup,
|
internalCreateWithdrawalGroup,
|
||||||
processWithdrawalGroup,
|
|
||||||
} from "./withdraw.js";
|
} from "./withdraw.js";
|
||||||
|
|
||||||
const logger = new Logger("pay-peer-pull-credit.ts");
|
const logger = new Logger("pay-peer-pull-credit.ts");
|
||||||
@ -121,7 +120,9 @@ async function queryPurseForPeerPullCredit(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.response.deposit_timestamp) {
|
const depositTimestamp = result.response.deposit_timestamp;
|
||||||
|
|
||||||
|
if (!depositTimestamp || TalerProtocolTimestamp.isNever(depositTimestamp)) {
|
||||||
logger.info("purse not ready yet (no deposit)");
|
logger.info("purse not ready yet (no deposit)");
|
||||||
return { ready: false };
|
return { ready: false };
|
||||||
}
|
}
|
||||||
@ -314,9 +315,7 @@ async function handlePeerPullCreditWithdrawing(
|
|||||||
const transitionInfo = await ws.db
|
const transitionInfo = await ws.db
|
||||||
.mktx((x) => [x.peerPullPaymentInitiations, x.withdrawalGroups])
|
.mktx((x) => [x.peerPullPaymentInitiations, x.withdrawalGroups])
|
||||||
.runReadWrite(async (tx) => {
|
.runReadWrite(async (tx) => {
|
||||||
const ppi = await tx.peerPullPaymentInitiations.get(
|
const ppi = await tx.peerPullPaymentInitiations.get(pullIni.pursePub);
|
||||||
pullIni.pursePub,
|
|
||||||
);
|
|
||||||
if (!ppi) {
|
if (!ppi) {
|
||||||
finished = true;
|
finished = true;
|
||||||
return;
|
return;
|
||||||
@ -653,7 +652,7 @@ export async function checkPeerPullPaymentInitiation(
|
|||||||
let numCoins = 0;
|
let numCoins = 0;
|
||||||
for (let i = 0; i < wi.selectedDenoms.selectedDenoms.length; i++) {
|
for (let i = 0; i < wi.selectedDenoms.selectedDenoms.length; i++) {
|
||||||
numCoins += wi.selectedDenoms.selectedDenoms[i].count;
|
numCoins += wi.selectedDenoms.selectedDenoms[i].count;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
exchangeBaseUrl: exchangeUrl,
|
exchangeBaseUrl: exchangeUrl,
|
||||||
|
@ -29,6 +29,7 @@ import {
|
|||||||
TalerError,
|
TalerError,
|
||||||
TalerErrorCode,
|
TalerErrorCode,
|
||||||
TalerPreciseTimestamp,
|
TalerPreciseTimestamp,
|
||||||
|
TalerProtocolTimestamp,
|
||||||
TalerProtocolViolationError,
|
TalerProtocolViolationError,
|
||||||
TalerUriAction,
|
TalerUriAction,
|
||||||
TransactionAction,
|
TransactionAction,
|
||||||
@ -479,8 +480,11 @@ async function processPeerPushDebitReady(
|
|||||||
resp,
|
resp,
|
||||||
codecForExchangePurseStatus(),
|
codecForExchangePurseStatus(),
|
||||||
);
|
);
|
||||||
|
const mergeTimestamp = purseStatus.merge_timestamp;
|
||||||
logger.info(`got purse status ${purseStatus}`);
|
logger.info(`got purse status ${purseStatus}`);
|
||||||
if (purseStatus.merge_timestamp) {
|
if (!mergeTimestamp || TalerProtocolTimestamp.isNever(mergeTimestamp)) {
|
||||||
|
return { ready: false };
|
||||||
|
} else {
|
||||||
await transitionPeerPushDebitTransaction(
|
await transitionPeerPushDebitTransaction(
|
||||||
ws,
|
ws,
|
||||||
peerPushInitiation.pursePub,
|
peerPushInitiation.pursePub,
|
||||||
@ -505,10 +509,12 @@ async function processPeerPushDebitReady(
|
|||||||
return {
|
return {
|
||||||
ready: true,
|
ready: true,
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
logger.warn(`unexpected HTTP status for purse: ${resp.status}`);
|
||||||
|
return {
|
||||||
|
ready: false,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
ready: false,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
logger.trace(
|
logger.trace(
|
||||||
"returning early from peer-push-debit for long-polling in background",
|
"returning early from peer-push-debit for long-polling in background",
|
||||||
|
Loading…
Reference in New Issue
Block a user