wallet-core: allow confirming peer-push-credit via txid
This commit is contained in:
parent
4f30506dca
commit
1f31ebc3cc
@ -2409,8 +2409,12 @@ export const codecForCheckPeerPullPaymentRequest =
|
|||||||
export interface ConfirmPeerPushCreditRequest {
|
export interface ConfirmPeerPushCreditRequest {
|
||||||
/**
|
/**
|
||||||
* Transparent identifier of the incoming peer push payment.
|
* Transparent identifier of the incoming peer push payment.
|
||||||
|
*
|
||||||
|
* @deprecated specify transactionId instead!
|
||||||
*/
|
*/
|
||||||
peerPushPaymentIncomingId: string;
|
peerPushPaymentIncomingId?: string;
|
||||||
|
|
||||||
|
transactionId?: string;
|
||||||
}
|
}
|
||||||
export interface AcceptPeerPushPaymentResponse {
|
export interface AcceptPeerPushPaymentResponse {
|
||||||
transactionId: TransactionIdStr;
|
transactionId: TransactionIdStr;
|
||||||
@ -2424,6 +2428,7 @@ export const codecForConfirmPeerPushPaymentRequest =
|
|||||||
(): Codec<ConfirmPeerPushCreditRequest> =>
|
(): Codec<ConfirmPeerPushCreditRequest> =>
|
||||||
buildCodecForObject<ConfirmPeerPushCreditRequest>()
|
buildCodecForObject<ConfirmPeerPushCreditRequest>()
|
||||||
.property("peerPushPaymentIncomingId", codecForString())
|
.property("peerPushPaymentIncomingId", codecForString())
|
||||||
|
.property("transactionId", codecForString())
|
||||||
.build("ConfirmPeerPushCreditRequest");
|
.build("ConfirmPeerPushCreditRequest");
|
||||||
|
|
||||||
export interface ConfirmPeerPullDebitRequest {
|
export interface ConfirmPeerPullDebitRequest {
|
||||||
|
@ -71,6 +71,7 @@ import {
|
|||||||
TransitionInfo,
|
TransitionInfo,
|
||||||
constructTransactionIdentifier,
|
constructTransactionIdentifier,
|
||||||
notifyTransition,
|
notifyTransition,
|
||||||
|
parseTransactionIdentifier,
|
||||||
stopLongpolling,
|
stopLongpolling,
|
||||||
} from "./transactions.js";
|
} from "./transactions.js";
|
||||||
import {
|
import {
|
||||||
@ -617,12 +618,27 @@ export async function confirmPeerPushCredit(
|
|||||||
req: ConfirmPeerPushCreditRequest,
|
req: ConfirmPeerPushCreditRequest,
|
||||||
): Promise<AcceptPeerPushPaymentResponse> {
|
): Promise<AcceptPeerPushPaymentResponse> {
|
||||||
let peerInc: PeerPushPaymentIncomingRecord | undefined;
|
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
|
await ws.db
|
||||||
.mktx((x) => [x.contractTerms, x.peerPushPaymentIncoming])
|
.mktx((x) => [x.contractTerms, x.peerPushPaymentIncoming])
|
||||||
.runReadWrite(async (tx) => {
|
.runReadWrite(async (tx) => {
|
||||||
peerInc = await tx.peerPushPaymentIncoming.get(
|
peerInc = await tx.peerPushPaymentIncoming.get(
|
||||||
req.peerPushPaymentIncomingId,
|
peerPushPaymentIncomingId,
|
||||||
);
|
);
|
||||||
if (!peerInc) {
|
if (!peerInc) {
|
||||||
return;
|
return;
|
||||||
@ -643,7 +659,7 @@ export async function confirmPeerPushCredit(
|
|||||||
|
|
||||||
const transactionId = constructTransactionIdentifier({
|
const transactionId = constructTransactionIdentifier({
|
||||||
tag: TransactionType.PeerPushCredit,
|
tag: TransactionType.PeerPushCredit,
|
||||||
peerPushPaymentIncomingId: req.peerPushPaymentIncomingId,
|
peerPushPaymentIncomingId,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user