better relative time
This commit is contained in:
parent
0e46ea162a
commit
262aeaec66
8 changed files with 115 additions and 89 deletions
55
src/api.ml
55
src/api.ml
|
|
@ -85,36 +85,6 @@ end = struct
|
|||
let jsont = B32.jsont
|
||||
end
|
||||
|
||||
module RelativeTime = struct
|
||||
type t =
|
||||
| Microseconds of float
|
||||
| Forever
|
||||
|
||||
let number_or_forever_jsont =
|
||||
let forever =
|
||||
let dec s =
|
||||
match s with
|
||||
| "forever" -> Forever
|
||||
| _ -> Jsont.Error.msg Jsont.Meta.none "unexpected string value"
|
||||
in
|
||||
let enc = function Forever -> "forever" | _ -> assert false in
|
||||
Jsont.map ~dec ~enc Jsont.string
|
||||
in
|
||||
let number =
|
||||
let dec n = Microseconds n in
|
||||
let enc = function Microseconds n -> n | _ -> assert false in
|
||||
Jsont.map ~dec ~enc Jsont.number
|
||||
in
|
||||
let enc = function Forever -> forever | Microseconds _ -> number in
|
||||
Jsont.any ~dec_string:forever ~dec_number:number ~enc ()
|
||||
|
||||
let jsont =
|
||||
let make t_s = t_s in
|
||||
Jsont.Object.map ~kind:"RelativeTime" make
|
||||
|> Jsont.Object.mem "t_s" number_or_forever_jsont ~enc:Fun.id
|
||||
|> Jsont.Object.finish
|
||||
end
|
||||
|
||||
(* TODO error response
|
||||
- use GANA error codes
|
||||
https://git.gnunet.org/gana.git/tree/gnu-taler-error-codes/registry.rec *)
|
||||
|
|
@ -613,9 +583,9 @@ module GlobalFees = struct
|
|||
history_fee: Amount.t;
|
||||
account_fee: Amount.t;
|
||||
purse_fee: Amount.t;
|
||||
history_expiration: RelativeTime.t;
|
||||
history_expiration: Timestamp.Span.t;
|
||||
purse_account_limit: int32;
|
||||
purse_timeout: RelativeTime.t;
|
||||
purse_timeout: Timestamp.Span.t;
|
||||
master_sig: GlobalFees.t;
|
||||
}
|
||||
|
||||
|
|
@ -649,9 +619,9 @@ module GlobalFees = struct
|
|||
|> mem "history_fee" Amount.jsont ~enc:history_fee
|
||||
|> mem "account_fee" Amount.jsont ~enc:account_fee
|
||||
|> mem "purse_fee" Amount.jsont ~enc:purse_fee
|
||||
|> mem "history_expiration" RelativeTime.jsont ~enc:history_expiration
|
||||
|> mem "history_expiration" Timestamp.Span.jsont ~enc:history_expiration
|
||||
|> mem "purse_account_limit" Jsont.int32 ~enc:purse_account_limit
|
||||
|> mem "purse_timeout" RelativeTime.jsont ~enc:purse_timeout
|
||||
|> mem "purse_timeout" Timestamp.Span.jsont ~enc:purse_timeout
|
||||
|> mem "master_sig" GlobalFees.jsont ~enc:master_sig
|
||||
|> finish
|
||||
end
|
||||
|
|
@ -797,7 +767,7 @@ module ExchangePartnerSetupRequest = struct
|
|||
type t = {
|
||||
partner_base_url: string;
|
||||
partner_pub: EddsaPublicKey.t;
|
||||
wad_frequency: RelativeTime.t;
|
||||
wad_frequency: Timestamp.Span.t;
|
||||
master_sig: PartnerConfiguration.t;
|
||||
start_date: Timestamp.t;
|
||||
end_date: Timestamp.t;
|
||||
|
|
@ -827,7 +797,7 @@ module ExchangePartnerSetupRequest = struct
|
|||
map ~kind:"ExchangePartnerSetupRequest" make
|
||||
|> mem "partner_base_url" Jsont.string ~enc:partner_base_url
|
||||
|> mem "partner_pub" EddsaPublicKey.jsont ~enc:partner_pub
|
||||
|> mem "wad_frequency" RelativeTime.jsont ~enc:wad_frequency
|
||||
|> mem "wad_frequency" Timestamp.Span.jsont ~enc:wad_frequency
|
||||
|> mem "master_sig" PartnerConfiguration.jsont ~enc:master_sig
|
||||
|> mem "start_date" Timestamp.jsont ~enc:start_date
|
||||
|> mem "end_date" Timestamp.jsont ~enc:end_date
|
||||
|
|
@ -842,7 +812,7 @@ module ExchangePartnerListEntry = struct
|
|||
partner_base_url: string;
|
||||
partner_master_pub: EddsaPublicKey.t;
|
||||
wad_fee: Amount.t;
|
||||
wad_frequency: RelativeTime.t;
|
||||
wad_frequency: Timestamp.Span.t;
|
||||
start_date: Timestamp.t;
|
||||
end_date: Timestamp.t;
|
||||
master_sig: WadPartnerSignature.t;
|
||||
|
|
@ -872,7 +842,7 @@ module ExchangePartnerListEntry = struct
|
|||
|> mem "partner_base_url" Jsont.string ~enc:partner_base_url
|
||||
|> mem "partner_master_pub" EddsaPublicKey.jsont ~enc:partner_master_pub
|
||||
|> mem "wad_fee" Amount.jsont ~enc:wad_fee
|
||||
|> mem "wad_frequency" RelativeTime.jsont ~enc:wad_frequency
|
||||
|> mem "wad_frequency" Timestamp.Span.jsont ~enc:wad_frequency
|
||||
|> mem "start_date" Timestamp.jsont ~enc:start_date
|
||||
|> mem "end_date" Timestamp.jsont ~enc:end_date
|
||||
|> mem "master_sig" WadPartnerSignature.jsont ~enc:master_sig
|
||||
|
|
@ -1091,7 +1061,7 @@ end
|
|||
module AccountLimit = struct
|
||||
type t = {
|
||||
operation_type: Account_operation.t;
|
||||
timeframe: RelativeTime.t;
|
||||
timeframe: Timestamp.Span.t;
|
||||
threshold: Amount.t;
|
||||
soft_limit: bool option;
|
||||
}
|
||||
|
|
@ -1106,7 +1076,7 @@ module AccountLimit = struct
|
|||
let soft_limit v = v.soft_limit in
|
||||
map ~kind:"AccountLimit" make
|
||||
|> mem "operation_type" Account_operation.jsont ~enc:operation_type
|
||||
|> mem "timeframe" RelativeTime.jsont ~enc:timeframe
|
||||
|> mem "timeframe" Timestamp.Span.jsont ~enc:timeframe
|
||||
|> mem "threshold" Amount.jsont ~enc:threshold
|
||||
|> opt_mem "soft_limit" Jsont.bool ~enc:soft_limit
|
||||
|> finish
|
||||
|
|
@ -1254,7 +1224,7 @@ module ExchangeKeysResponse = struct
|
|||
kyc_enabled: bool;
|
||||
disable_direct_deposit: bool;
|
||||
master_public_key: EddsaPublicKey.t;
|
||||
reserve_closing_delay: RelativeTime.t;
|
||||
reserve_closing_delay: Timestamp.Span.t;
|
||||
wallet_balance_limit_without_kyc: Amount.t list option;
|
||||
hard_limits: AccountLimit.t list;
|
||||
zero_limits: ZeroLimitedOperation.t list;
|
||||
|
|
@ -1381,7 +1351,8 @@ module ExchangeKeysResponse = struct
|
|||
|> mem "kyc_enabled" Jsont.bool ~enc:kyc_enabled
|
||||
|> mem "disable_direct_deposit" Jsont.bool ~enc:disable_direct_deposit
|
||||
|> mem "master_public_key" EddsaPublicKey.jsont ~enc:master_public_key
|
||||
|> mem "reserve_closing_delay" RelativeTime.jsont ~enc:reserve_closing_delay
|
||||
|> mem "reserve_closing_delay" Timestamp.Span.jsont
|
||||
~enc:reserve_closing_delay
|
||||
|> opt_mem "wallet_balance_limit_without_kyc" (Jsont.list Amount.jsont)
|
||||
~enc:wallet_balance_limit_without_kyc
|
||||
|> mem "hard_limits" (Jsont.list AccountLimit.jsont) ~enc:hard_limits
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue