~~~
This commit is contained in:
parent
099cd80670
commit
b507d540ad
43 changed files with 5647 additions and 1808 deletions
377
src/pg_type.ml
Normal file
377
src/pg_type.ml
Normal file
|
|
@ -0,0 +1,377 @@
|
|||
(* this module defines caqti encoding/decodings *)
|
||||
open Crypto
|
||||
open Bin_type
|
||||
open Api
|
||||
open Caqti_type
|
||||
|
||||
(* TODO
|
||||
check that we use Caqti_type.octets for binary data *)
|
||||
|
||||
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 : Ptime.t option t = Timestamp.caqti
|
||||
let time = Timestamp.caqti
|
||||
let time_span = Timestamp.Span.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 *)
|
||||
|
||||
let fullpayto_hash = FullPaytoHash.caqti
|
||||
let nomalizaedpayto_hash = NormalizedPaytoHash.caqti
|
||||
let denomination_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_data =
|
||||
let master_sig = Bin_sig.ExchangeSigningKeyValidity.caqti in
|
||||
let revoked_sig = option Bin_sig.MasterSigningKeyRevocation.caqti in
|
||||
custom
|
||||
~encode:(fun
|
||||
Signkey_data.
|
||||
{ pub; stamp_start; stamp_expire; stamp_end; master_sig; revoked_sig }
|
||||
->
|
||||
match master_sig with
|
||||
| None -> Error "signkey_data master_sig is none"
|
||||
| Some master_sig ->
|
||||
Ok (pub, stamp_start, stamp_expire, stamp_end, master_sig, revoked_sig))
|
||||
~decode:(fun
|
||||
(pub, stamp_start, stamp_expire, stamp_end, master_sig, revoked_sig) ->
|
||||
Ok
|
||||
{
|
||||
pub;
|
||||
stamp_start;
|
||||
stamp_expire;
|
||||
stamp_end;
|
||||
master_sig= Some master_sig;
|
||||
revoked_sig;
|
||||
})
|
||||
(t6 eddsa_pub time time time master_sig revoked_sig)
|
||||
|
||||
let denom_data =
|
||||
let master_sig = Bin_sig.DenominationKeyValidity.caqti in
|
||||
let revoked_sig = option Bin_sig.MasterDenominationKeyRevocation.caqti in
|
||||
custom
|
||||
~encode:(fun
|
||||
Denom_data.
|
||||
{
|
||||
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;
|
||||
revoked_sig;
|
||||
}
|
||||
->
|
||||
match master_sig with
|
||||
| None -> Error "denom_data master_sig is none"
|
||||
| Some 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, revoked_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, revoked_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= Some master_sig;
|
||||
revoked_sig;
|
||||
})
|
||||
(t12 rsa_pub amount time time time time amount amount amount amount int
|
||||
(t3 denomination_hash master_sig revoked_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 = Bin_sig.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 = Bin_sig.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 = Bin_sig.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 = Bin_sig.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 = Bin_sig.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 = Bin_sig.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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue