From a318c7ef5a3c47482eef6839d803a930724c1671 Mon Sep 17 00:00:00 2001 From: swrup Date: Thu, 20 Nov 2025 20:25:06 +0100 Subject: [PATCH] --- default.config | 26 ++++++++++++++++ include/parse_config.ml | 67 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 88 insertions(+), 5 deletions(-) diff --git a/default.config b/default.config index 1699fcb9..b1b00e13 100644 --- a/default.config +++ b/default.config @@ -50,3 +50,29 @@ legal_reserve_expiration_time = "1 year" aggregator_shift = "1 year" max_aml_program_runtime = "1 year" default_purse_limit = 9999 + +[coin_kudo_1] +value= EUR:0.01 +duration_withdraw= "1 year" +duration_spend= "1 year" +duration_legal= "1 year" +fee_withdraw= EUR:0.00 +fee_deposit= EUR:0.00 +fee_refresh= EUR:0.00 +fee_refund= EUR:0.00 +cipher= RSA +rsa_keysize= 2048 +age_restricted= NO + +[coin_kudo_2] +value= EUR:0.02 +duration_withdraw= "1 year" +duration_spend= "1 year" +duration_legal= "1 year" +fee_withdraw= EUR:0.00 +fee_deposit= EUR:0.00 +fee_refresh= EUR:0.00 +fee_refund= EUR:0.00 +cipher= RSA +rsa_keysize= 2048 +age_restricted= NO diff --git a/include/parse_config.ml b/include/parse_config.ml index a53c79da..40a99e99 100644 --- a/include/parse_config.ml +++ b/include/parse_config.ml @@ -368,11 +368,8 @@ module Config = struct } let currency_sections = - List.filter_map - (fun v -> - match String.starts_with ~prefix:"currency-" v.header with - | false -> None - | true -> Some v) + List.filter + (fun v -> String.starts_with ~prefix:"currency-" v.header) config let parse_currency section = @@ -409,4 +406,64 @@ module Config = struct () *) end + + module Coin = struct + type t = { + section_name: string; + value: Amount.t; + duration_withdraw: Ptime.Span.t; + duration_spend: Ptime.Span.t; + duration_legal: Ptime.Span.t; + fee_withdraw: Amount.t; + fee_deposit: Amount.t; + fee_refresh: Amount.t; + fee_refund: Amount.t; + cipher: [ (* `CS |*) `RSA ]; + rsa_keysize: int; (* : int option (only if `RSA) *) + age_restricted: [ (*`YES|*) `NO ]; + } + + let coin_sections = + List.filter + (fun v -> + (* note: here its a '_' not '-' *) + String.starts_with ~prefix:"coin_" v.header) + config + + let parse_coin section = + let get field = get config ~section:section.header ~field in + let section_name = + String.sub section.header 5 (String.length section.header - 5) + in + { + section_name; + value= get "value" |> amount; + duration_withdraw= get "duration_withdraw" |> duration; + duration_spend= get "duration_spend" |> duration; + duration_legal= get "duration_legal" |> duration; + fee_withdraw= get "fee_withdraw" |> amount; + fee_deposit= get "fee_deposit" |> amount; + fee_refresh= get "fee_refresh" |> amount; + fee_refund= get "fee_refund" |> amount; + cipher= (get "cipher" |> const_value "RSA" |> fun _s -> `RSA); + rsa_keysize= get "rsa_keysize" |> int; + age_restricted= + ( get "age_restricted" |> yes_no |> function + | `NO -> `NO + | `YES -> fail_with "`age_restricted = YES` is not supported" ); + } + + let all_coins = List.map parse_coin coin_sections + + let get_coin name = + match List.find_opt (fun v -> v.section_name = name) all_coins with + | None -> + fail_with + (Fmt.str "section `[coin_%s]` not found, coin `%s` is not defined" + name name) + | Some v -> v + + let kudo_1 = get_coin "kudo_1" + let kudo_2 = get_coin "kudo_2" + end end