(* this module defines caqti encoding/decodings *) open Caqti_type open Crypto open Api let amount : Amount.t t = let open Amount in custom ~encode:(fun amount -> Ok (amount.value, amount.fraction)) ~decode:(fun (value, fraction) -> Amount.make ~sign:None ~currency:Config.currency ~value ~fraction) (t2 int64 int32) (* we want to use int64 timestamps, not postgresql built-in timestamp type *) let ptime : unit t = Caqti_type.unit let time = Timestamp.caqti let time_span = Time.TimeRelative.caqti let age_mask : int t = Caqti_type.int let rsa_pub = RsaPublicKey.caqti let eddsa_pub = EddsaPublicKey.caqti let eddsa_sig = EddsaSignature.caqti (* todo: enum type for wire_method? *) let wire_method = Caqti_type.string let payto_uri = Caqti_type.string let b32 = B32.caqti include struct (* alias for hash *) open Hash let fullpayto_hash = FullPaytoHash.caqti let nomalizaedpayto_hash = NormalizedPaytoHash.caqti let denom_hash = DenominationHash.caqti let privatecontract_hash = PrivateContractHash.caqti let extensionspolicy_hash = ExtensionsPolicyHash.caqti let merchantwire_hash = MerchantWireHash.caqti let agecommitment_hash = AgeCommitmentHash.caqti let blindedcoin_hash = BlindedCoinHash.caqti let coinpub_hash = CoinPubHash.caqti let outputcommitment_hash = OutputCommitmentHash.caqti let planchets_hash = HashPlanchetsP.caqti end let signkey = let master_sig = Signatures.ExchangeSigningKeyValidity.caqti in custom ~encode:(fun Signkey.{ pub; stamp_start; stamp_expire; stamp_end; master_sig } -> Ok (pub, stamp_start, stamp_expire, stamp_end, master_sig)) ~decode:(fun (pub, stamp_start, stamp_expire, stamp_end, master_sig) -> Ok { pub; stamp_start; stamp_expire; stamp_end; master_sig }) (t5 eddsa_pub time time time master_sig) let denom = let master_sig = Signatures.DenominationKeyValidity.caqti in custom ~encode:(fun Denomination. { pub; value; stamp_start; stamp_expire_withdraw; stamp_expire_deposit; stamp_expire_legal; fee_withdraw; fee_deposit; fee_refresh; fee_refund; age_mask; h_pub; master_sig; } -> Ok ( pub, value, stamp_start, stamp_expire_withdraw, stamp_expire_deposit, stamp_expire_legal, fee_withdraw, fee_deposit, fee_refresh, fee_refund, age_mask, (h_pub, master_sig) )) ~decode:(fun ( pub, value, stamp_start, stamp_expire_withdraw, stamp_expire_deposit, stamp_expire_legal, fee_withdraw, fee_deposit, fee_refresh, fee_refund, age_mask, (h_pub, master_sig) ) -> Ok { pub; value; stamp_start; stamp_expire_withdraw; stamp_expire_deposit; stamp_expire_legal; fee_withdraw; fee_deposit; fee_refresh; fee_refund; age_mask; h_pub; master_sig; }) (t12 rsa_pub amount time time time time amount amount amount amount int (t2 denom_hash master_sig)) let account_restrictions = custom ~encode:(fun l -> Api.encode (Jsont.list AccountRestriction.jsont) l) ~decode:(fun s -> Api.decode (Jsont.list AccountRestriction.jsont) s) string let global_fee = let master_sig = Signatures.GlobalFees.caqti in custom ~encode:(fun GlobalFees. { start_date; end_date; history_fee; account_fee; purse_fee; history_expiration; purse_account_limit; purse_timeout; master_sig; } -> Ok ( start_date, end_date, history_fee, account_fee, purse_fee, history_expiration, purse_account_limit, purse_timeout, master_sig )) ~decode:(fun ( start_date, end_date, history_fee, account_fee, purse_fee, history_expiration, purse_account_limit, purse_timeout, master_sig ) -> Ok { start_date; end_date; history_fee; account_fee; purse_fee; history_expiration; purse_account_limit; purse_timeout; master_sig; }) Caqti_type.( t9 time time amount amount amount time_span int32 time_span master_sig) let aggregate_transfer_fee = let master_sig = Signatures.MasterWireFee.caqti in Caqti_type.custom ~encode:(fun AggregateTransferFee. { wire_fee; closing_fee; start_date; end_date; sig_ } -> Ok (wire_fee, closing_fee, start_date, end_date, sig_)) ~decode:(fun (wire_fee, closing_fee, start_date, end_date, sig_) -> Ok AggregateTransferFee. { wire_fee; closing_fee; start_date; end_date; sig_ }) Caqti_type.(t5 amount amount time time master_sig) let exchange_wire_account = let master_sig = Signatures.MasterWireDetails.caqti in Caqti_type.custom ~encode:(fun ExchangeWireAccount. { payto_uri; conversion_url; debit_restrictions; credit_restrictions; master_sig; bank_label; priority; } -> Ok ( payto_uri, conversion_url, debit_restrictions, credit_restrictions, master_sig, bank_label, priority )) ~decode:(fun ( payto_uri, conversion_url, debit_restrictions, credit_restrictions, master_sig, bank_label, priority ) -> Ok { payto_uri; conversion_url; debit_restrictions; credit_restrictions; master_sig; bank_label; priority; }) Caqti_type.( t7 payto_uri (option string) account_restrictions account_restrictions master_sig (option string) (option int)) let drain_profit_message = let master_sig = Signatures.MasterDrainProfit.caqti in Caqti_type.custom ~encode:(fun DrainProfitsMessage. { wtid; debit_account_section; credit_payto_uri; date; amount; master_sig; } -> Ok (wtid, debit_account_section, credit_payto_uri, date, amount, master_sig)) ~decode:(fun (wtid, debit_account_section, credit_payto_uri, date, amount, master_sig) -> Ok { wtid; debit_account_section; credit_payto_uri; date; amount; master_sig; }) Caqti_type.(t6 b32 string string time amount master_sig) let aml_officer_setup = let master_sig = Signatures.MasterAmlOfficerStatus.caqti in Caqti_type.custom ~encode:(fun AmlOfficerSetup. { officer_pub; master_sig; officer_name; is_active; read_only; change_date; } -> Ok ( officer_pub, master_sig, officer_name, is_active, read_only, change_date )) ~decode:(fun ( officer_pub, master_sig, officer_name, is_active, read_only, change_date ) -> Ok { officer_pub; master_sig; officer_name; is_active; read_only; change_date; }) Caqti_type.(t6 eddsa_pub master_sig string bool bool time) let exchange_partner_setup = let master_sig = Signatures.PartnerConfiguration.caqti in Caqti_type.custom ~encode:(fun ExchangePartnerSetupRequest. { partner_pub; start_date; end_date; wad_frequency; wad_fee; master_sig; partner_base_url; } -> Ok ( partner_pub, start_date, end_date, wad_frequency, wad_fee, master_sig, partner_base_url )) ~decode:(fun ( partner_pub, start_date, end_date, wad_frequency, wad_fee, master_sig, partner_base_url ) -> Ok { partner_base_url; partner_pub; wad_frequency; master_sig; start_date; end_date; wad_fee; }) Caqti_type.(t7 eddsa_pub time time time_span amount master_sig string) let auditor = let open Auditor in Caqti_type.custom ~encode:(fun { auditor_pub; auditor_url; auditor_name; last_change; is_active } -> Ok (auditor_pub, auditor_url, auditor_name, last_change, is_active)) ~decode:(fun (auditor_pub, auditor_url, auditor_name, last_change, is_active) -> Ok { auditor_pub; auditor_url; auditor_name; last_change; is_active }) Caqti_type.(t5 eddsa_pub string string time bool)