fix bug in withdrawal operation state machine, allow manual reserve update from CLI

This commit is contained in:
Florian Dold 2020-03-16 17:18:46 +05:30
parent 1744b1a800
commit 9e2be07cfc
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
3 changed files with 25 additions and 3 deletions

View File

@ -374,6 +374,18 @@ advancedCli
}); });
}); });
advancedCli
.subcommand("updateReserve", "update-reserve", {
help: "Update reserve status.",
})
.requiredArgument("reservePub", clk.STRING)
.action(async args => {
await withWallet(args, async wallet => {
const r = await wallet.updateReserve(args.updateReserve.reservePub);
console.log("updated reserve:", JSON.stringify(r, undefined, 2));
});
});
const testCli = walletCli.subcommand("testingArgs", "testing", { const testCli = walletCli.subcommand("testingArgs", "testing", {
help: "Subcommands for testing GNU Taler deployments.", help: "Subcommands for testing GNU Taler deployments.",
}); });

View File

@ -228,7 +228,7 @@ export async function forceQueryReserve(
await tx.put(Stores.reserves, reserve); await tx.put(Stores.reserves, reserve);
}); });
await processReserve(ws, reservePub); await processReserve(ws, reservePub, true);
} }
/** /**
@ -490,6 +490,7 @@ async function updateReserve(
reserveUpdateId, reserveUpdateId,
}; };
await tx.put(Stores.reserveUpdatedEvents, reserveUpdate); await tx.put(Stores.reserveUpdatedEvents, reserveUpdate);
r.reserveStatus = ReserveRecordStatus.WITHDRAWING;
} else { } else {
const expectedBalance = Amounts.sub( const expectedBalance = Amounts.sub(
r.amountWithdrawAllocated, r.amountWithdrawAllocated,
@ -497,7 +498,8 @@ async function updateReserve(
); );
const cmp = Amounts.cmp(balance, expectedBalance.amount); const cmp = Amounts.cmp(balance, expectedBalance.amount);
if (cmp == 0) { if (cmp == 0) {
// Nothing changed. // Nothing changed, go back to sleep!
r.reserveStatus = ReserveRecordStatus.DORMANT;
return; return;
} }
if (cmp > 0) { if (cmp > 0) {
@ -506,8 +508,10 @@ async function updateReserve(
r.amountWithdrawRemaining, r.amountWithdrawRemaining,
extra, extra,
).amount; ).amount;
r.reserveStatus = ReserveRecordStatus.WITHDRAWING;
} else { } else {
// We're missing some money. // We're missing some money.
r.reserveStatus = ReserveRecordStatus.DORMANT;
} }
const reserveUpdate: ReserveUpdatedEventRecord = { const reserveUpdate: ReserveUpdatedEventRecord = {
reservePub: r.reservePub, reservePub: r.reservePub,
@ -520,12 +524,12 @@ async function updateReserve(
await tx.put(Stores.reserveUpdatedEvents, reserveUpdate); await tx.put(Stores.reserveUpdatedEvents, reserveUpdate);
} }
r.lastSuccessfulStatusQuery = getTimestampNow(); r.lastSuccessfulStatusQuery = getTimestampNow();
r.reserveStatus = ReserveRecordStatus.WITHDRAWING;
r.retryInfo = initRetryInfo(); r.retryInfo = initRetryInfo();
r.reserveTransactions = reserveInfo.history; r.reserveTransactions = reserveInfo.history;
await tx.put(Stores.reserves, r); await tx.put(Stores.reserves, r);
}, },
); );
console.log("updated reserve");
ws.notify({ type: NotificationType.ReserveUpdated }); ws.notify({ type: NotificationType.ReserveUpdated });
} }

View File

@ -85,6 +85,7 @@ import {
import { import {
processReserve, processReserve,
createTalerWithdrawReserve, createTalerWithdrawReserve,
forceQueryReserve,
} from "./operations/reserves"; } from "./operations/reserves";
import { InternalWalletState } from "./operations/state"; import { InternalWalletState } from "./operations/state";
@ -714,6 +715,11 @@ export class Wallet {
} }
} }
async updateReserve(reservePub: string): Promise<ReserveRecord | undefined> {
await forceQueryReserve(this.ws, reservePub);
return await this.ws.db.get(Stores.reserves, reservePub);
}
async refuseProposal(proposalId: string): Promise<void> { async refuseProposal(proposalId: string): Promise<void> {
return refuseProposal(this.ws, proposalId); return refuseProposal(this.ws, proposalId);
} }