+ coin config
This commit is contained in:
parent
6a2871492f
commit
51007ff612
2 changed files with 88 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue