directly withdraw after creating planchet

This commit is contained in:
Florian Dold 2020-05-11 21:05:00 +05:30
parent d7ee78669d
commit 277a513a8f
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B

View File

@ -189,7 +189,7 @@ async function processPlanchet(
if (!withdrawalGroup) { if (!withdrawalGroup) {
return; return;
} }
const planchet = await ws.db.getIndexed(Stores.planchets.byGroupAndIndex, [ let planchet = await ws.db.getIndexed(Stores.planchets.byGroupAndIndex, [
withdrawalGroupId, withdrawalGroupId,
coinIdx, coinIdx,
]); ]);
@ -247,12 +247,15 @@ async function processPlanchet(
coinIdx, coinIdx,
]); ]);
if (p) { if (p) {
planchet = p;
return; return;
} }
await tx.put(Stores.planchets, newPlanchet); await tx.put(Stores.planchets, newPlanchet);
planchet = newPlanchet;
}); });
console.log("processPlanchet: planchet not found"); }
return; if (!planchet) {
throw Error("invariant violated");
} }
if (planchet.withdrawalDone) { if (planchet.withdrawalDone) {
console.log("processPlanchet: planchet already withdrawn"); console.log("processPlanchet: planchet already withdrawn");
@ -332,6 +335,8 @@ async function processPlanchet(
let withdrawalGroupFinished = false; let withdrawalGroupFinished = false;
const planchetCoinPub = planchet.coinPub;
const success = await ws.db.runWithWriteTransaction( const success = await ws.db.runWithWriteTransaction(
[Stores.coins, Stores.withdrawalGroups, Stores.reserves, Stores.planchets], [Stores.coins, Stores.withdrawalGroups, Stores.reserves, Stores.planchets],
async (tx) => { async (tx) => {
@ -339,7 +344,7 @@ async function processPlanchet(
if (!ws) { if (!ws) {
return false; return false;
} }
const p = await tx.get(Stores.planchets, planchet.coinPub); const p = await tx.get(Stores.planchets, planchetCoinPub);
if (!p) { if (!p) {
return false; return false;
} }