aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-harness
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-07-22 12:59:53 +0200
committerFlorian Dold <florian@dold.me>2024-07-22 12:59:53 +0200
commit55052b7c0f41bfe98ed739aca4955bf72b64064c (patch)
treedd3caa527112474d17ce9f0b0fe25a3699972842 /packages/taler-harness
parenta8d3d46ae4926a40367e890730aa5a89f4571468 (diff)
harness: improve gen-coin-configv0.12.6-dev.1
Diffstat (limited to 'packages/taler-harness')
-rw-r--r--packages/taler-harness/src/index.ts95
1 files changed, 81 insertions, 14 deletions
diff --git a/packages/taler-harness/src/index.ts b/packages/taler-harness/src/index.ts
index 864b7530c..4a6fcc81f 100644
--- a/packages/taler-harness/src/index.ts
+++ b/packages/taler-harness/src/index.ts
@@ -19,6 +19,7 @@
*/
import {
AccessToken,
+ AmountJson,
AmountString,
Amounts,
BalancesResponse,
@@ -1158,6 +1159,23 @@ deploymentCli
process.exit(2);
});
+function computeFee(args: {
+ currency: string;
+ spec: string;
+ coinMin: AmountJson;
+ coinMax: AmountJson;
+}): string {
+ if (args.spec === "none") {
+ return `${args.currency}:0`;
+ }
+
+ if (args.spec === "const") {
+ return Amounts.stringify(args.coinMin);
+ }
+
+ throw Error(`unsupported fee spec (${args.spec})`);
+}
+
deploymentCli
.subcommand("coincfg", "gen-coin-config", {
help: "Generate a coin/denomination configuration for the exchange.",
@@ -1168,40 +1186,89 @@ deploymentCli
.requiredOption("maxAmount", ["--max-amount"], clk.STRING, {
help: "Largest denomination",
})
+ .maybeOption("feeWithdraw", ["--fee-deposit"], clk.STRING)
+ .maybeOption("feeDeposit", ["--fee-deposit"], clk.STRING)
+ .maybeOption("feeRefresh", ["--fee-refresh"], clk.STRING)
+ .maybeOption("feeRefund", ["--fee-refund"], clk.STRING)
+ .maybeOption("fees", ["--fees"], clk.STRING)
.flag("noFees", ["--no-fees"])
.action(async (args) => {
+ let feespecWithdraw;
+ let feespecDeposit;
+ let feespecRefund;
+ let feespecRefresh;
+
+ if (args.coincfg.noFees) {
+ feespecDeposit = "none";
+ feespecWithdraw = "none";
+ feespecRefund = "none";
+ feespecRefresh = "none";
+ } else if (args.coincfg.fees) {
+ feespecWithdraw = args.coincfg.fees;
+ feespecDeposit = args.coincfg.fees;
+ feespecRefund = args.coincfg.fees;
+ feespecRefresh = args.coincfg.fees;
+ } else {
+ // Default: Only deposit fees
+ feespecWithdraw = args.coincfg.feeWithdraw ?? "none";
+ feespecDeposit = args.coincfg.feeDeposit ?? "const";
+ feespecRefund = args.coincfg.feeRefund ?? "none";
+ feespecRefresh = args.coincfg.feeRefresh ?? "none";
+ }
+
let out = "";
const stamp = Math.floor(new Date().getTime() / 1000);
- const min = Amounts.parseOrThrow(args.coincfg.minAmount);
- const max = Amounts.parseOrThrow(args.coincfg.maxAmount);
- if (min.currency != max.currency) {
+ const coinMin = Amounts.parseOrThrow(args.coincfg.minAmount);
+ const coinMax = Amounts.parseOrThrow(args.coincfg.maxAmount);
+ if (coinMin.currency != coinMax.currency) {
console.error("currency mismatch");
process.exit(1);
}
- const currency = min.currency;
- let x = min;
+ const currency = coinMin.currency;
+ let x = coinMin;
let n = 1;
out += "# Coin configuration for the exchange.\n";
out += '# Should be placed in "/etc/taler/conf.d/exchange-coins.conf".\n';
out += "\n";
- while (Amounts.cmp(x, max) < 0) {
+ while (Amounts.cmp(x, coinMax) < 0) {
+ const feeWithdraw = computeFee({
+ currency,
+ coinMax,
+ coinMin,
+ spec: feespecWithdraw,
+ });
+ const feeDeposit = computeFee({
+ currency,
+ coinMax,
+ coinMin,
+ spec: feespecDeposit,
+ });
+ const feeRefresh = computeFee({
+ currency,
+ coinMax,
+ coinMin,
+ spec: feespecRefresh,
+ });
+ const feeRefund = computeFee({
+ currency,
+ coinMax,
+ coinMin,
+ spec: feespecRefund,
+ });
+
out += `[COIN-${currency}-n${n}-t${stamp}]\n`;
out += `VALUE = ${Amounts.stringify(x)}\n`;
out += `DURATION_WITHDRAW = 7 days\n`;
out += `DURATION_SPEND = 2 years\n`;
out += `DURATION_LEGAL = 6 years\n`;
- out += `FEE_WITHDRAW = ${currency}:0\n`;
- if (args.coincfg.noFees) {
- out += `FEE_DEPOSIT = ${currency}:0\n`;
- } else {
- out += `FEE_DEPOSIT = ${Amounts.stringify(min)}\n`;
- }
- out += `FEE_REFRESH = ${currency}:0\n`;
- out += `FEE_REFUND = ${currency}:0\n`;
+ out += `FEE_WITHDRAW = ${feeWithdraw}\n`;
+ out += `FEE_DEPOSIT = ${feeDeposit}\n`;
+ out += `FEE_REFRESH = ${feeRefresh}\n`;
+ out += `FEE_REFUND = ${feeRefund}\n`;
out += `RSA_KEYSIZE = 2048\n`;
out += `CIPHER = RSA\n`;
out += "\n";