diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-12-16 16:20:45 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-12-16 16:20:45 +0100 |
commit | 35a7b76a7d935dc2c749fd39ac80c6af1096b795 (patch) | |
tree | b7f0bb167d3c912a085e7b842e887d5c834208fb /src/operations | |
parent | fa4621e70c48500a372504eb8ae9b9481531c555 (diff) |
history WIP, DB naming
Diffstat (limited to 'src/operations')
-rw-r--r-- | src/operations/balance.ts | 8 | ||||
-rw-r--r-- | src/operations/exchanges.ts | 1 | ||||
-rw-r--r-- | src/operations/history.ts | 15 | ||||
-rw-r--r-- | src/operations/pay.ts | 12 | ||||
-rw-r--r-- | src/operations/pending.ts | 8 | ||||
-rw-r--r-- | src/operations/refresh.ts | 10 | ||||
-rw-r--r-- | src/operations/refund.ts | 4 | ||||
-rw-r--r-- | src/operations/reserves.ts | 34 | ||||
-rw-r--r-- | src/operations/tip.ts | 4 | ||||
-rw-r--r-- | src/operations/withdraw.ts | 8 |
10 files changed, 53 insertions, 51 deletions
diff --git a/src/operations/balance.ts b/src/operations/balance.ts index 15d8e52fa..d12fbaf7c 100644 --- a/src/operations/balance.ts +++ b/src/operations/balance.ts @@ -87,7 +87,7 @@ export async function getBalances( await tx.iter(Stores.refreshGroups).forEach(r => { // Don't count finished refreshes, since the refresh already resulted // in coins being added to the wallet. - if (r.finishedTimestamp) { + if (r.timestampFinished) { return; } for (let i = 0; i < r.oldCoinPubs.length; i++) { @@ -96,13 +96,13 @@ export async function getBalances( addTo( balanceStore, "pendingIncoming", - session.valueOutput, + session.amountRefreshOutput, session.exchangeBaseUrl, ); addTo( balanceStore, "pendingIncomingRefresh", - session.valueOutput, + session.amountRefreshOutput, session.exchangeBaseUrl, ); } @@ -128,7 +128,7 @@ export async function getBalances( }); await tx.iter(Stores.purchases).forEach(t => { - if (t.firstSuccessfulPayTimestamp) { + if (t.timestampFirstSuccessfulPay) { return; } for (const c of t.payReq.coins) { diff --git a/src/operations/exchanges.ts b/src/operations/exchanges.ts index fc1a50f00..871ee1138 100644 --- a/src/operations/exchanges.ts +++ b/src/operations/exchanges.ts @@ -431,6 +431,7 @@ async function updateExchangeFromUrlImpl( termsOfServiceAcceptedTimestamp: undefined, termsOfServiceLastEtag: undefined, termsOfServiceText: undefined, + updateDiff: undefined, }; await ws.db.put(Stores.exchanges, newExchangeRecord); } else { diff --git a/src/operations/history.ts b/src/operations/history.ts index 7e985d218..eec398f37 100644 --- a/src/operations/history.ts +++ b/src/operations/history.ts @@ -201,7 +201,7 @@ export async function getHistory( }); tx.iter(Stores.withdrawalSession).forEach(wsr => { - if (wsr.finishTimestamp) { + if (wsr.timestampFinish) { history.push({ type: HistoryEventType.Withdrawn, withdrawSessionId: wsr.withdrawSessionId, @@ -212,7 +212,8 @@ export async function getHistory( amountWithdrawnEffective: Amounts.toString(wsr.totalCoinValue), amountWithdrawnRaw: Amounts.toString(wsr.rawWithdrawalAmount), exchangeBaseUrl: wsr.exchangeBaseUrl, - timestamp: wsr.finishTimestamp, + timestamp: wsr.timestampFinish, + withdrawalSource: wsr.source, }); } }); @@ -239,7 +240,7 @@ export async function getHistory( }); await tx.iter(Stores.refreshGroups).forEachAsync(async (rg) => { - if (!rg.finishedTimestamp) { + if (!rg.timestampFinished) { return; } let numInputCoins = 0; @@ -252,8 +253,8 @@ export async function getHistory( numInputCoins++; if (session) { numRefreshedInputCoins++; - amountsRaw.push(session.valueWithFee); - amountsEffective.push(session.valueOutput); + amountsRaw.push(session.amountRefreshInput); + amountsEffective.push(session.amountRefreshOutput); numOutputCoins += session.newDenoms.length; } else { const c = await tx.get(Stores.coins, rg.oldCoinPubs[i]); @@ -274,7 +275,7 @@ export async function getHistory( type: HistoryEventType.Refreshed, refreshGroupId: rg.refreshGroupId, eventId: makeEventId(HistoryEventType.Refreshed, rg.refreshGroupId), - timestamp: rg.finishedTimestamp, + timestamp: rg.timestampFinished, refreshReason: rg.reason, amountRefreshedEffective: Amounts.toString(amountRefreshedEffective), amountRefreshedRaw: Amounts.toString(amountRefreshedRaw), @@ -305,7 +306,7 @@ export async function getHistory( eventId: makeEventId(HistoryEventType.ReserveBalanceUpdated, ru.reserveUpdateId), amountExpected: ru.amountExpected, amountReserveBalance: ru.amountReserveBalance, - timestamp: reserve.created, + timestamp: reserve.timestampCreated, newHistoryTransactions: ru.newHistoryTransactions, reserveShortInfo: { exchangeBaseUrl: reserve.exchangeBaseUrl, diff --git a/src/operations/pay.ts b/src/operations/pay.ts index 664524695..b0f1d4b62 100644 --- a/src/operations/pay.ts +++ b/src/operations/pay.ts @@ -345,8 +345,8 @@ async function recordConfirmPay( lastSessionId: sessionId, merchantSig: d.merchantSig, payReq, - acceptTimestamp: getTimestampNow(), - lastRefundStatusTimestamp: undefined, + timestampAccept: getTimestampNow(), + timestampLastRefundStatus: undefined, proposalId: proposal.proposalId, lastPayError: undefined, lastRefundStatusError: undefined, @@ -355,7 +355,7 @@ async function recordConfirmPay( refundStatusRequested: false, lastRefundApplyError: undefined, refundApplyRetryInfo: initRetryInfo(), - firstSuccessfulPayTimestamp: undefined, + timestampFirstSuccessfulPay: undefined, autoRefundDeadline: undefined, paymentSubmitPending: true, refundState: { @@ -421,7 +421,7 @@ export async function abortFailedPayment( if (!purchase) { throw Error("Purchase not found, unable to abort with refund"); } - if (purchase.firstSuccessfulPayTimestamp) { + if (purchase.timestampFirstSuccessfulPay) { throw Error("Purchase already finished, not aborting"); } if (purchase.abortDone) { @@ -725,8 +725,8 @@ export async function submitPay( // FIXME: properly display error throw Error("merchant payment signature invalid"); } - const isFirst = purchase.firstSuccessfulPayTimestamp === undefined; - purchase.firstSuccessfulPayTimestamp = now; + const isFirst = purchase.timestampFirstSuccessfulPay === undefined; + purchase.timestampFirstSuccessfulPay = now; purchase.paymentSubmitPending = false; purchase.lastPayError = undefined; purchase.payRetryInfo = initRetryInfo(false); diff --git a/src/operations/pending.ts b/src/operations/pending.ts index 252c9e98a..ffa23f101 100644 --- a/src/operations/pending.ts +++ b/src/operations/pending.ts @@ -158,7 +158,7 @@ async function gatherReservePending( type: PendingOperationType.Reserve, givesLifeness: false, stage: reserve.reserveStatus, - timestampCreated: reserve.created, + timestampCreated: reserve.timestampCreated, reserveType, reservePub: reserve.reservePub, retryInfo: reserve.retryInfo, @@ -180,7 +180,7 @@ async function gatherReservePending( type: PendingOperationType.Reserve, givesLifeness: true, stage: reserve.reserveStatus, - timestampCreated: reserve.created, + timestampCreated: reserve.timestampCreated, reserveType, reservePub: reserve.reservePub, retryInfo: reserve.retryInfo, @@ -208,7 +208,7 @@ async function gatherRefreshPending( onlyDue: boolean = false, ): Promise<void> { await tx.iter(Stores.refreshGroups).forEach(r => { - if (r.finishedTimestamp) { + if (r.timestampFinished) { return; } resp.nextRetryDelay = updateRetryDelay( @@ -235,7 +235,7 @@ async function gatherWithdrawalPending( onlyDue: boolean = false, ): Promise<void> { await tx.iter(Stores.withdrawalSession).forEach(wsr => { - if (wsr.finishTimestamp) { + if (wsr.timestampFinish) { return; } resp.nextRetryDelay = updateRetryDelay( diff --git a/src/operations/refresh.ts b/src/operations/refresh.ts index d9a080bd8..f602221af 100644 --- a/src/operations/refresh.ts +++ b/src/operations/refresh.ts @@ -168,7 +168,7 @@ async function refreshCreateSession( if (!c) { throw Error("coin not found, but marked for refresh"); } - const r = Amounts.sub(c.currentAmount, refreshSession.valueWithFee); + const r = Amounts.sub(c.currentAmount, refreshSession.amountRefreshInput); if (r.saturated) { console.log("can't refresh coin, no amount left"); return; @@ -224,7 +224,7 @@ async function refreshMelt( denom_pub_hash: coin.denomPubHash, denom_sig: coin.denomSig, rc: refreshSession.hash, - value_with_fee: refreshSession.valueWithFee, + value_with_fee: refreshSession.amountRefreshInput, }; logger.trace("melt request:", meltReq); const resp = await ws.http.postJson(reqUrl.href, meltReq); @@ -414,7 +414,7 @@ async function refreshReveal( } } if (allDone) { - rg.finishedTimestamp = getTimestampNow(); + rg.timestampFinished = getTimestampNow(); rg.retryInfo = initRetryInfo(false); } for (let coin of coins) { @@ -489,7 +489,7 @@ async function processRefreshGroupImpl( if (!refreshGroup) { return; } - if (refreshGroup.finishedTimestamp) { + if (refreshGroup.timestampFinished) { return; } const ps = refreshGroup.oldCoinPubs.map((x, i) => @@ -545,7 +545,7 @@ export async function createRefreshGroup( const refreshGroupId = encodeCrock(getRandomBytes(32)); const refreshGroup: RefreshGroupRecord = { - finishedTimestamp: undefined, + timestampFinished: undefined, finishedPerCoin: oldCoinPubs.map(x => false), lastError: undefined, lastErrorPerCoin: {}, diff --git a/src/operations/refund.ts b/src/operations/refund.ts index 589418571..b4139c991 100644 --- a/src/operations/refund.ts +++ b/src/operations/refund.ts @@ -194,14 +194,14 @@ export async function acceptRefundResponse( } if (queryDone) { - p.lastRefundStatusTimestamp = getTimestampNow(); + p.timestampLastRefundStatus = getTimestampNow(); p.lastRefundStatusError = undefined; p.refundStatusRetryInfo = initRetryInfo(); p.refundStatusRequested = false; console.log("refund query done"); } else { // No error, but we need to try again! - p.lastRefundStatusTimestamp = getTimestampNow(); + p.timestampLastRefundStatus = getTimestampNow(); p.refundStatusRetryInfo.retryCounter++; updateRetryInfoTimeout(p.refundStatusRetryInfo); p.lastRefundStatusError = undefined; diff --git a/src/operations/reserves.ts b/src/operations/reserves.ts index 56e9c25d6..7b0a6886e 100644 --- a/src/operations/reserves.ts +++ b/src/operations/reserves.ts @@ -77,13 +77,13 @@ export async function createReserve( const currency = req.amount.currency; const reserveRecord: ReserveRecord = { - created: now, - withdrawAllocatedAmount: Amounts.getZero(currency), - withdrawCompletedAmount: Amounts.getZero(currency), - withdrawRemainingAmount: Amounts.getZero(currency), + timestampCreated: now, + amountWithdrawAllocated: Amounts.getZero(currency), + amountWithdrawCompleted: Amounts.getZero(currency), + amountWithdrawRemaining: Amounts.getZero(currency), exchangeBaseUrl: canonExchange, hasPayback: false, - initiallyRequestedAmount: req.amount, + amountInitiallyRequested: req.amount, reservePriv: keypair.priv, reservePub: keypair.pub, senderWire: req.senderWire, @@ -414,20 +414,20 @@ async function updateReserve( // FIXME: check / compare history! if (!r.lastSuccessfulStatusQuery) { // FIXME: check if this matches initial expectations - r.withdrawRemainingAmount = balance; + r.amountWithdrawRemaining = balance; const reserveUpdate: ReserveUpdatedEventRecord = { reservePub: r.reservePub, timestamp: getTimestampNow(), amountReserveBalance: Amounts.toString(balance), - amountExpected: Amounts.toString(reserve.initiallyRequestedAmount), + amountExpected: Amounts.toString(reserve.amountInitiallyRequested), newHistoryTransactions, reserveUpdateId, }; await tx.put(Stores.reserveUpdatedEvents, reserveUpdate); } else { const expectedBalance = Amounts.sub( - r.withdrawAllocatedAmount, - r.withdrawCompletedAmount, + r.amountWithdrawAllocated, + r.amountWithdrawCompleted, ); const cmp = Amounts.cmp(balance, expectedBalance.amount); if (cmp == 0) { @@ -436,8 +436,8 @@ async function updateReserve( } if (cmp > 0) { const extra = Amounts.sub(balance, expectedBalance.amount).amount; - r.withdrawRemainingAmount = Amounts.add( - r.withdrawRemainingAmount, + r.amountWithdrawRemaining = Amounts.add( + r.amountWithdrawRemaining, extra, ).amount; } else { @@ -549,7 +549,7 @@ async function depleteReserve( } logger.trace(`depleting reserve ${reservePub}`); - const withdrawAmount = reserve.withdrawRemainingAmount; + const withdrawAmount = reserve.amountWithdrawRemaining; logger.trace(`getting denom list`); @@ -585,7 +585,7 @@ async function depleteReserve( reservePub: reserve.reservePub, }, rawWithdrawalAmount: withdrawAmount, - startTimestamp: getTimestampNow(), + timestampStart: getTimestampNow(), denoms: denomsForWithdraw.map(x => x.denomPub), withdrawn: denomsForWithdraw.map(x => false), planchets: denomsForWithdraw.map(x => undefined), @@ -603,7 +603,7 @@ async function depleteReserve( function mutateReserve(r: ReserveRecord): ReserveRecord { const remaining = Amounts.sub( - r.withdrawRemainingAmount, + r.amountWithdrawRemaining, totalWithdrawAmount, ); if (remaining.saturated) { @@ -611,15 +611,15 @@ async function depleteReserve( throw TransactionAbort; } const allocated = Amounts.add( - r.withdrawAllocatedAmount, + r.amountWithdrawAllocated, totalWithdrawAmount, ); if (allocated.saturated) { console.error("can't create planchets, saturated"); throw TransactionAbort; } - r.withdrawRemainingAmount = remaining.amount; - r.withdrawAllocatedAmount = allocated.amount; + r.amountWithdrawRemaining = remaining.amount; + r.amountWithdrawAllocated = allocated.amount; r.reserveStatus = ReserveRecordStatus.DORMANT; r.retryInfo = initRetryInfo(false); return r; diff --git a/src/operations/tip.ts b/src/operations/tip.ts index ba4b80974..df4b7990e 100644 --- a/src/operations/tip.ts +++ b/src/operations/tip.ts @@ -255,14 +255,14 @@ async function processTipImpl( type: "tip", tipId: tipRecord.tipId, }, - startTimestamp: getTimestampNow(), + timestampStart: getTimestampNow(), withdrawSessionId: withdrawalSessionId, rawWithdrawalAmount: tipRecord.amount, withdrawn: planchets.map((x) => false), totalCoinValue: Amounts.sum(planchets.map((p) => p.coinValue)).amount, lastErrorPerCoin: {}, retryInfo: initRetryInfo(), - finishTimestamp: undefined, + timestampFinish: undefined, lastError: undefined, }; diff --git a/src/operations/withdraw.ts b/src/operations/withdraw.ts index c7c91494c..6e7cdf512 100644 --- a/src/operations/withdraw.ts +++ b/src/operations/withdraw.ts @@ -280,7 +280,7 @@ async function processPlanchet( } } if (numDone === ws.denoms.length) { - ws.finishTimestamp = getTimestampNow(); + ws.timestampFinish = getTimestampNow(); ws.lastError = undefined; ws.retryInfo = initRetryInfo(false); withdrawSessionFinished = true; @@ -289,11 +289,11 @@ async function processPlanchet( if (!planchet.isFromTip) { const r = await tx.get(Stores.reserves, planchet.reservePub); if (r) { - r.withdrawCompletedAmount = Amounts.add( - r.withdrawCompletedAmount, + r.amountWithdrawCompleted = Amounts.add( + r.amountWithdrawCompleted, Amounts.add(denom.value, denom.feeWithdraw).amount, ).amount; - if (Amounts.cmp(r.withdrawCompletedAmount, r.withdrawAllocatedAmount) == 0) { + if (Amounts.cmp(r.amountWithdrawCompleted, r.amountWithdrawAllocated) == 0) { reserveDepleted = true; } await tx.put(Stores.reserves, r); |