-implement getTransaction for p2p credit txns

This commit is contained in:
Florian Dold 2023-02-20 03:36:46 +01:00
parent b718885907
commit bd9904f6a0
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -136,10 +136,7 @@ export async function getTransactionById(
req: TransactionByIdRequest,
): Promise<Transaction> {
const { type, args: rest } = parseId("txn", req.transactionId);
if (
type === TransactionType.Withdrawal ||
type === TransactionType.PeerPullCredit
) {
if (type === TransactionType.Withdrawal) {
const withdrawalGroupId = rest[0];
return await ws.db
.mktx((x) => [
@ -341,11 +338,77 @@ export async function getTransactionById(
return buildTransactionForPushPaymentDebit(debit, ct.contractTermsRaw);
});
} else if (type === TransactionType.PeerPushCredit) {
// FIXME: Implement!
throw Error("getTransaction not yet implemented for PeerPushCredit");
} else if (type === TransactionType.PeerPushCredit) {
// FIXME: Implement!
throw Error("getTransaction not yet implemented for PeerPullCredit");
const peerPushPaymentIncomingId = rest[0];
return await ws.db
.mktx((x) => [
x.peerPushPaymentIncoming,
x.contractTerms,
x.withdrawalGroups,
x.operationRetries,
])
.runReadWrite(async (tx) => {
const pushInc = await tx.peerPushPaymentIncoming.get(
peerPushPaymentIncomingId,
);
if (!pushInc) throw Error("not found");
const ct = await tx.contractTerms.get(pushInc.contractTermsHash);
checkDbInvariant(!!ct);
let wg: WithdrawalGroupRecord | undefined = undefined;
let wgOrt: OperationRetryRecord | undefined = undefined;
if (pushInc.withdrawalGroupId) {
wg = await tx.withdrawalGroups.get(pushInc.withdrawalGroupId);
if (wg) {
const withdrawalOpId = RetryTags.forWithdrawal(wg);
wgOrt = await tx.operationRetries.get(withdrawalOpId);
}
}
const pushIncOpId = RetryTags.forPeerPushCredit(pushInc);
let pushIncOrt = await tx.operationRetries.get(pushIncOpId);
return buildTransactionForPeerPushCredit(
pushInc,
pushIncOrt,
ct.contractTermsRaw,
wg,
wgOrt,
);
});
} else if (type === TransactionType.PeerPullCredit) {
const pursePub = rest[0];
return await ws.db
.mktx((x) => [
x.peerPullPaymentInitiations,
x.contractTerms,
x.withdrawalGroups,
x.operationRetries,
])
.runReadWrite(async (tx) => {
const pushInc = await tx.peerPullPaymentInitiations.get(pursePub);
if (!pushInc) throw Error("not found");
const ct = await tx.contractTerms.get(pushInc.contractTermsHash);
checkDbInvariant(!!ct);
let wg: WithdrawalGroupRecord | undefined = undefined;
let wgOrt: OperationRetryRecord | undefined = undefined;
if (pushInc.withdrawalGroupId) {
wg = await tx.withdrawalGroups.get(pushInc.withdrawalGroupId);
if (wg) {
const withdrawalOpId = RetryTags.forWithdrawal(wg);
wgOrt = await tx.operationRetries.get(withdrawalOpId);
}
}
const pushIncOpId = RetryTags.forPeerPullPaymentInitiation(pushInc);
let pushIncOrt = await tx.operationRetries.get(pushIncOpId);
return buildTransactionForPeerPullCredit(
pushInc,
pushIncOrt,
ct.contractTermsRaw,
wg,
wgOrt,
);
});
} else {
const unknownTxType: never = type;
throw Error(`can't retrieve a '${unknownTxType}' transaction`);