diff --git a/src/api.ml b/src/api.ml index ede981d6..96c11e50 100644 --- a/src/api.ml +++ b/src/api.ml @@ -1086,3 +1086,48 @@ module ZeroLimitedOperation = struct |> mem "operation_type" Account_operation.jsont ~enc:operation_type |> finish end + +module RegexAccountRestriction = struct + type t = { + payto_regex: string; + human_hint: string; + (* Map from IETF BCP 47 language tags to localized human hints. *) + human_hint_i18n: string option; + } + + let jsont = + let make payto_regex human_hint human_hint_i18n = + { payto_regex; human_hint; human_hint_i18n } + in + let payto_regex v = v.payto_regex in + let human_hint v = v.human_hint in + let human_hint_i18n v = v.human_hint_i18n in + let open Jsont.Object in + map ~kind:"RegexAccountRestriction" make + |> mem "payto_regex" Jsont.string ~enc:payto_regex + |> mem "human_hint" Jsont.string ~enc:human_hint + |> opt_mem "human_hint_i18n" Jsont.string ~enc:human_hint_i18n + |> finish +end + +module AccountRestriction = struct + type t = + | Deny + | Regex of RegexAccountRestriction.t + + let of_regex v = Regex v + let of_deny () = Deny + + let jsont = + let open Jsont.Object in + let regex = Case.map "regex" RegexAccountRestriction.jsont ~dec:of_regex in + let deny = Case.map "deny" Jsont.ignore ~dec:of_deny in + let enc_case = function + | Regex v -> Case.value regex v + | Deny -> Case.value deny () + in + let cases = Case.[ make regex; make deny ] in + map ~kind:"AccountRestriction" Fun.id + |> case_mem "type" Jsont.string ~enc:Fun.id ~enc_case cases + |> finish +end