wallet-core: report correct amountEffective in peer-pull-credit even before withdrawal is active

This commit is contained in:
Florian Dold 2023-02-23 16:07:14 +01:00
parent dd9e4555ba
commit 582b6ae5f4
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
5 changed files with 25 additions and 2 deletions

View File

@ -151,7 +151,7 @@ class NodeThreadCryptoWorker implements CryptoWorker {
this.onmessage(v); this.onmessage(v);
} }
}); });
this.nodeWorker.unref(); //this.nodeWorker.unref();
} }
/** /**

View File

@ -1795,6 +1795,8 @@ export interface PeerPullPaymentInitiationRecord {
*/ */
amount: AmountString; amount: AmountString;
estimatedAmountEffective: AmountString;
/** /**
* Purse public key. Used as the primary key to look * Purse public key. Used as the primary key to look
* up this record. * up this record.
@ -2606,6 +2608,18 @@ export const walletDbFixups: FixupDescription[] = [
}); });
}, },
}, },
{
name: "PeerPullPaymentInitiationRecord_estimatedAmountEffective_add",
async fn(tx): Promise<void> {
await tx.peerPullPaymentInitiations.iter().forEachAsync(async (pi) => {
if (pi.estimatedAmountEffective) {
return;
}
pi.estimatedAmountEffective = pi.amount;
await tx.peerPullPaymentInitiations.put(pi);
});
},
},
{ {
name: "PeerPushPaymentInitiationRecord_ALL_removeLegacyTx", name: "PeerPushPaymentInitiationRecord_ALL_removeLegacyTx",
async fn(tx): Promise<void> { async fn(tx): Promise<void> {

View File

@ -260,6 +260,7 @@ async function validateWireInfo(
throw Error("exchange acct signature invalid"); throw Error("exchange acct signature invalid");
} }
} }
logger.trace("account validation done");
const feesForType: WireFeeMap = {}; const feesForType: WireFeeMap = {};
for (const wireMethod of Object.keys(wireInfo.fees)) { for (const wireMethod of Object.keys(wireInfo.fees)) {
const feeList: WireFee[] = []; const feeList: WireFee[] = [];

View File

@ -1655,6 +1655,13 @@ export async function initiatePeerPullPayment(
const mergeReserveRowId = mergeReserveInfo.rowId; const mergeReserveRowId = mergeReserveInfo.rowId;
checkDbInvariant(!!mergeReserveRowId); checkDbInvariant(!!mergeReserveRowId);
const wi = await getExchangeWithdrawalInfo(
ws,
exchangeBaseUrl,
Amounts.parseOrThrow(req.partialContractTerms.amount),
undefined,
);
await ws.db await ws.db
.mktx((x) => [x.peerPullPaymentInitiations, x.contractTerms]) .mktx((x) => [x.peerPullPaymentInitiations, x.contractTerms])
.runReadWrite(async (tx) => { .runReadWrite(async (tx) => {
@ -1673,6 +1680,7 @@ export async function initiatePeerPullPayment(
contractPriv: contractKeyPair.priv, contractPriv: contractKeyPair.priv,
contractPub: contractKeyPair.pub, contractPub: contractKeyPair.pub,
withdrawalGroupId, withdrawalGroupId,
estimatedAmountEffective: wi.withdrawalAmountEffective,
}); });
await tx.contractTerms.put({ await tx.contractTerms.put({
contractTermsRaw: contractTerms, contractTermsRaw: contractTerms,

View File

@ -542,7 +542,7 @@ function buildTransactionForPeerPullCredit(
return { return {
type: TransactionType.PeerPullCredit, type: TransactionType.PeerPullCredit,
amountEffective: Amounts.stringify(peerContractTerms.amount), amountEffective: Amounts.stringify(pullCredit.amount),
amountRaw: Amounts.stringify(peerContractTerms.amount), amountRaw: Amounts.stringify(peerContractTerms.amount),
exchangeBaseUrl: pullCredit.exchangeBaseUrl, exchangeBaseUrl: pullCredit.exchangeBaseUrl,
extendedStatus: ExtendedStatus.Pending, extendedStatus: ExtendedStatus.Pending,