diff --git a/src/api.ml b/src/api.ml index 01e37c8b..e4d7e007 100644 --- a/src/api.ml +++ b/src/api.ml @@ -1,10 +1,10 @@ (* TODO + option: + - correct use opt_mem or Jsont.option number - number is "float", but we probably want int everywhere instead - numeric values capped at 2^53 -1 inclusive because json - time - - better types - - issues with "never" = uint64_max *) + *) open Crypto open Bin_signature @@ -12,6 +12,36 @@ let encode_exn jsont v = Jsont_bytesrw.encode_string jsont v |> Result.get_ok let encode jsont v = Jsont_bytesrw.encode_string jsont v let decode jsont v = Jsont_bytesrw.decode_string jsont v +module Account_operation = struct + type t = + | Withdraw + | Deposit + | Merge + | Balance + | Close + | Aggregate + | Transaction + | Refund + + let to_string t = + String.uppercase_ascii + @@ + match t with + | Withdraw -> "withdraw" + | Deposit -> "deposit" + | Merge -> "merge" + | Balance -> "balance" + | Close -> "close" + | Aggregate -> "aggregate" + | Transaction -> "transaction" + | Refund -> "refund" + + let jsont = + [ Withdraw; Deposit; Merge; Balance; Close; Aggregate; Transaction; Refund ] + |> List.map (fun t -> (to_string t, t)) + |> Jsont.enum ~kind:"account operation type" +end + module ErrorDetail = struct (* TODO GANA error codes https://git.gnunet.org/gana.git/tree/gnu-taler-error-codes/registry.rec *) @@ -26,7 +56,7 @@ module ErrorDetail = struct let enc_hint v = v.hint in Jsont.Object.map ~kind:"ErrorDetail" make |> Jsont.Object.mem "code" Jsont.int ~enc:enc_code - |> Jsont.Object.opt_mem "hint" Jsont.(string) ~enc:enc_hint + |> Jsont.Object.opt_mem "hint" Jsont.string ~enc:enc_hint |> Jsont.Object.finish end @@ -1000,7 +1030,8 @@ module RsaDenomGroup = struct |> finish end -(* TODO better jsont cases +(* TODO cases + better jsont cases handling factorize common fields (DenomCommon/DenomGroupCommon) "+age_restricted"/CS variants raise error not implemented if not RSA *) @@ -1018,3 +1049,28 @@ module DenomGroup = struct |> case_mem "cipher" Jsont.string ~enc:Fun.id ~enc_case cases |> finish end + +module AccountLimit = struct + type t = { + operation_type: Account_operation.t; + timeframe: RelativeTime.t; + threshold: Amount.t; + soft_limit: bool option; + } + + let jsont = + let make operation_type timeframe threshold soft_limit = + { operation_type; timeframe; threshold; soft_limit } + in + let operation_type v = v.operation_type in + let timeframe v = v.timeframe in + let threshold v = v.threshold in + let soft_limit v = v.soft_limit in + let open Jsont.Object in + map ~kind:"AccountLimit" make + |> mem "operation_type" Account_operation.jsont ~enc:operation_type + |> mem "timeframe" RelativeTime.jsont ~enc:timeframe + |> mem "threshold" Amount.jsont ~enc:threshold + |> opt_mem "soft_limit" Jsont.bool ~enc:soft_limit + |> finish +end