wallet-core: allow confirming peer-push-credit via txid

This commit is contained in:
Florian Dold 2023-06-24 17:49:53 +02:00
parent 4f30506dca
commit 1f31ebc3cc
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 24 additions and 3 deletions

View File

@ -2409,8 +2409,12 @@ export const codecForCheckPeerPullPaymentRequest =
export interface ConfirmPeerPushCreditRequest {
/**
* Transparent identifier of the incoming peer push payment.
*
* @deprecated specify transactionId instead!
*/
peerPushPaymentIncomingId: string;
peerPushPaymentIncomingId?: string;
transactionId?: string;
}
export interface AcceptPeerPushPaymentResponse {
transactionId: TransactionIdStr;
@ -2424,6 +2428,7 @@ export const codecForConfirmPeerPushPaymentRequest =
(): Codec<ConfirmPeerPushCreditRequest> =>
buildCodecForObject<ConfirmPeerPushCreditRequest>()
.property("peerPushPaymentIncomingId", codecForString())
.property("transactionId", codecForString())
.build("ConfirmPeerPushCreditRequest");
export interface ConfirmPeerPullDebitRequest {

View File

@ -71,6 +71,7 @@ import {
TransitionInfo,
constructTransactionIdentifier,
notifyTransition,
parseTransactionIdentifier,
stopLongpolling,
} from "./transactions.js";
import {
@ -617,12 +618,27 @@ export async function confirmPeerPushCredit(
req: ConfirmPeerPushCreditRequest,
): Promise<AcceptPeerPushPaymentResponse> {
let peerInc: PeerPushPaymentIncomingRecord | undefined;
let peerPushPaymentIncomingId: string;
if (req.peerPushPaymentIncomingId) {
peerPushPaymentIncomingId = req.peerPushPaymentIncomingId;
} else if (req.transactionId) {
const parsedTx = parseTransactionIdentifier(req.transactionId);
if (!parsedTx) {
throw Error("invalid transaction ID");
}
if (parsedTx.tag !== TransactionType.PeerPushCredit) {
throw Error("invalid transaction ID type");
}
peerPushPaymentIncomingId = parsedTx.peerPushPaymentIncomingId;
} else {
throw Error("no transaction ID (or deprecated peerPushPaymentIncomingId) provided");
}
await ws.db
.mktx((x) => [x.contractTerms, x.peerPushPaymentIncoming])
.runReadWrite(async (tx) => {
peerInc = await tx.peerPushPaymentIncoming.get(
req.peerPushPaymentIncomingId,
peerPushPaymentIncomingId,
);
if (!peerInc) {
return;
@ -643,7 +659,7 @@ export async function confirmPeerPushCredit(
const transactionId = constructTransactionIdentifier({
tag: TransactionType.PeerPushCredit,
peerPushPaymentIncomingId: req.peerPushPaymentIncomingId,
peerPushPaymentIncomingId,
});
return {