text
stringlengths
12
786k
let upgrades_encoding = let open Data_encoding in def " user_activated . upgrades " ~ title " : User activated upgrades " ~ description : " User activated upgrades : at given level , switch to given protocol . " ( list ( obj2 ( req " level " int32 ) ( req " replacement_protocol "...
type protocol_overrides = ( Protocol_hash . t * Protocol_hash . t ) list
let protocol_overrides_encoding = let open Data_encoding in def " user_activated . protocol_overrides " ~ title " : User activated protocol overrides " ~ description : " User activated protocol overrides : activate a protocol instead of \ another . " @@ list ( obj2 ( req " replaced_protoco...
let ( ) = Data_encoding . Registration . register upgrades_encoding ; Data_encoding . Registration . register protocol_overrides_encoding
let test_metadata_consistency ~ migrate_from ~ migrate_to = Test . register ~ __FILE__ ~ title " : metadata consistency " ~ tags [ " : rpc " ; " metadata " ; " migration " ] @@ fun ( ) -> let node = Node . create [ ] in let * ( ) = Node . config_init node [ ] ...
let register ~ migrate_from ~ migrate_to = test_metadata_consistency ~ migrate_from ~ migrate_to
type t = { ua_family : string ; ua_major : string option ; ua_minor : string option ; ua_patch : string option ; os_family : string ; os_major : string option ; os_minor : string option ; os_patch : string option ; os_patch_minor : string option ; device_family : string ; device_brand ...
let uaparser = User_agent_parser . init ( )
let parse s = let parsed = User_agent_parser . parse uaparser s in let open User_agent_parser in let open User_agent_parser . UAParser in let open User_agent_parser . OSParser in let open User_agent_parser . DeviceParser in { ua_family = parsed . ua . family ; ua_major = parsed . ua . major ; ua_m...
let is_bot t = let is_google_bot ( ) = let regex = Str . regexp " Googlebot ( \\- Mobile \\|- Image \\|- Video \\|- News ) \\?\\| Feedfetcher - Google \\| Google - Test \\| Google - Site - Verification \\| Google \ Web \ Preview \\| AdsBot - Google ( \\- Mobile ) \\?\\| Mediapartners...
module Poly = struct [ %% versioned module Stable = struct module V2 = struct type ( ' u , ' s ) ' s t = Signed_command of ' u | Parties of ' s [ @@ deriving sexp , compare , equal , hash , yojson ] yojson let to_latest = Fn . id end module V1 = struct type ( ' u , ' s ) ' s ...
type ( ' u , ' s ) ' s t_ = ( ' u , ' s ) ' s Poly . Stable . Latest . t = | Signed_command of ' u | Parties of ' s
module Gen_make ( C : Signed_command_intf . Gen_intf ) Gen_intf = struct let to_signed_command f = Quickcheck . Generator . map f ~ f ( : fun c -> Signed_command c ) c open C . Gen let payment ? sign_type ~ key_gen ? nonce ~ max_amount ~ fee_range ( ) = to_signed_command ( payment ? sign_...
module Gen = Gen_make ( Signed_command ) Signed_command
module Valid = struct [ %% versioned module Stable = struct module V2 = struct type t = ( Signed_command . With_valid_signature . Stable . V2 . t , Parties . Valid . Stable . V1 . t ) Poly . Stable . V2 . t [ @@ deriving sexp , compare , equal , hash , yojson ] yojson let to_latest = Fn . ...
module Stable = struct module V2 = struct type t = ( Signed_command . Stable . V2 . t , Parties . Stable . V1 . t ) t Poly . Stable . V2 . t [ @@ deriving sexp , compare , equal , hash , yojson ] yojson let to_latest = Fn . id end end ] end
module Zero_one_or_two = struct [ %% versioned module Stable = struct module V1 = struct type ' a t = [ ` Zero | ` One of ' a | ` Two of ' a * ' a ] [ @@ deriving sexp , compare , equal , hash , yojson ] yojson end end ] end end
module Verifiable = struct [ %% versioned module Stable = struct module V2 = struct type t = ( Signed_command . Stable . V2 . t , Parties . Verifiable . Stable . V1 . t ) Poly . Stable . V2 . t [ @@ deriving sexp , compare , equal , hash , yojson ] yojson let to_latest = Fn . id end end ]...
let to_verifiable ( t : t ) t ~ ledger ~ get ~ location_of_account : Verifiable . t = let find_vk ( p : Party . t ) t = let ( ! ) x = Option . value_exn x in let id = Party . account_id p in Option . try_with ( fun ( ) -> let account : Account . t = ( ! get ledger ( ! locati...
let of_verifiable ( t : Verifiable . t ) t : t = match t with | Signed_command x -> Signed_command x | Parties p -> Parties ( Parties . of_verifiable p ) p
let fee : t -> Currency . Fee . t = function | Signed_command x -> Signed_command . fee x | Parties p -> Parties . fee p
let has_insufficient_fee t = Currency . Fee ( . fee t < minimum_fee ) minimum_fee
let accounts_accessed ( t : t ) t = match t with | Signed_command x -> Signed_command . accounts_accessed x | Parties ps -> Parties . accounts_accessed ps
let to_base58_check ( t : t ) t = match t with | Signed_command x -> Signed_command . to_base58_check x | Parties ps -> Parties . to_base58_check ps
let fee_payer ( t : t ) t = match t with | Signed_command x -> Signed_command . fee_payer x | Parties p -> Parties . fee_payer p
let nonce_exn ( t : t ) t = match t with | Signed_command x -> Signed_command . nonce x | Parties p -> Parties . nonce p
let check ( t : t ) t : Valid . t option = match t with | Signed_command x -> Option . map ( Signed_command . check x ) x ~ f ( : fun c -> Signed_command c ) c | Parties p -> Some ( Parties ( p :> Parties . Valid . t ) t ) t
let fee_token ( t : t ) t = match t with | Signed_command x -> Signed_command . fee_token x | Parties x -> Parties . fee_token x
let valid_until ( t : t ) t = match t with | Signed_command x -> Signed_command . valid_until x | Parties _ -> Mina_numbers . Global_slot . max_value
let forget_check ( t : Valid . t ) t : t = ( t :> t ) t
let to_valid_unsafe ( t : t ) t = ` If_this_is_used_it_should_have_a_comment_justifying_it ( match t with | Parties x -> Parties x | Signed_command x -> let ( ` If_this_is_used_it_should_have_a_comment_justifying_it x ) x = Signed_command . to_valid_unsafe x in Signed_command x )
let filter_by_participant ( commands : t list ) list public_key = List . filter commands ~ f ( : fun user_command -> Core_kernel . List . exists ( accounts_accessed user_command ) user_command ~ f : ( Fn . compose ( Signature_lib . Public_key . Compressed . equal public_key ) public_key...
let weight : Stable . Latest . t -> int = function | Signed_command signed_command -> Signed_command . payload signed_command |> Signed_command_payload . weight | Parties parties -> Parties . weight parties
let fee_per_wu ( user_command : Stable . Latest . t ) t : Currency . Fee_rate . t = Currency . Fee_rate . make_exn ( fee user_command ) user_command ( weight user_command ) user_command
module Query_first_seen = [ % graphql { | query query ( $ hashes : [ String ] ) !! { user_commands ( user_commandswhere : { hash : { _in : $ hashes } hashes } hashes ) { hash @ bsDecoder ( bsDecoderfn : " Transaction_hash . of_base58_check_exn ) " first_seen @ bsDecod...
module Query_participants = [ % graphql { | query query ( $ hashes : [ String ] ) !! { user_commands ( user_commandswhere : { hash : { _in : $ hashes } hashes } hashes ) { receiver { id value @ bsDecoder ( fn : " Public_key . Compressed . of_base58_check_exn ) " } ...
module Query = [ % graphql { | query query ( $ hash : String ) ! { user_commands ( user_commandswhere : { hash : { _eq : $ hash } hash } hash ) { fee @ bsDecoder ( fn : " Base_types . Fee . deserialize ) " hash @ bsDecoder ( bsDecoderfn : " Transaction_hash . of_...
module Insert = [ % graphql { | mutation insert ( $ user_commands : [ user_commands_insert_input ] ) !! { insert_user_commands ( insert_user_commandsobjects : $ user_commands , on_conflict : { constraint : user_commands_hash_key , update_columns : first_seen } first_seen ) { retur...
let parties_with_ledger ( ) = let open Quickcheck . Let_syntax in let open Signature_lib in let num_keypairs = ( Parties_generators . max_other_parties * 2 ) 2 + 2 in let keypairs = List . init num_keypairs ~ f ( : fun _ -> Keypair . create ( ) ) in let keymap = List . fold keypairs ...
let sequence_parties_with_ledger ? length ( ) = let open Quickcheck . Let_syntax in let % bind length = match length with | Some n -> return n | None -> Quickcheck . Generator . small_non_negative_int in let merge_ledger source_ledger target_ledger = Ledger . iteri source_ledger ~ f ( : fun _ndx ac...
let pk_to_public_key ~ context ( ` Pk pk ) pk = Public_key . Compressed . of_base58_check pk |> Result . map_error ~ f ( : fun _ -> Errors . create ~ context ` Public_key_format_not_valid )
let account_id ( ` Pk pk ) pk ( ` Token_id token_id ) token_id = { Account_identifier . address = pk ; sub_account = None ; metadata = Some ( Amount_of . Token_id . encode token_id ) token_id }
let token_id_of_account ( account : Account_identifier . t ) t = let module Decoder = Amount_of . Token_id . T ( Result ) Result in Decoder . decode account . metadata |> Result . map ~ f ( : Option . value ~ default : Amount_of . Token_id . default ) default |> Result . ok
module Op = struct type ' a t = { label : ' a ; related_to : ' a option } [ @@ deriving equal ] equal module T ( M : Monad . S2 ) S2 = struct let build ~ a_eq ~ plan ~ f = let open M . Let_syntax in let % map _ , rev_data = List . fold plan ~ init ( : M . return ( 0 , [ ...
module Kind = struct type t = [ ` Payment | ` Delegation ] [ @@ deriving yojson , equal , sexp , compare ] compare end
module Account_creation_fees_paid = struct type t = | By_no_one | By_fee_payer of Unsigned_extended . UInt64 . t | By_receiver of Unsigned_extended . UInt64 . t [ @@ deriving equal , to_yojson , sexp , compare ] compare end
module Failure_status = struct type t = [ ` Applied of Account_creation_fees_paid . t | ` Failed of string ] [ @@ deriving equal , to_yojson , sexp , compare ] compare end
type t = { kind : Kind . t ; fee_payer : [ ` Pk of string ] ; source : [ ` Pk of string ] ; receiver : [ ` Pk of string ] ; fee_token : [ ` Token_id of string ] ; token : [ ` Token_id of string ] ; fee : Unsigned_extended . UInt64 . t ; nonce : Unsigned_extended ...
module Partial = struct type t = { kind : Kind . t ; fee_payer : [ ` Pk of string ] ; source : [ ` Pk of string ] ; receiver : [ ` Pk of string ] ; fee_token : [ ` Token_id of string ] ; token : [ ` Token_id of string ] ; fee : Unsigned_extended . UInt64 . t ; am...
let forget ( t : t ) t : Partial . t = { kind = t . kind ; fee_payer = t . fee_payer ; source = t . source ; receiver = t . receiver ; fee_token = t . fee_token ; token = t . token ; fee = t . fee ; amount = t . amount ; valid_until = t . valid_until ; memo = t . memo }
let remember ~ nonce ~ hash t = { kind = t . kind ; fee_payer = t . fee_payer ; source = t . source ; receiver = t . receiver ; fee_token = t . fee_token ; token = t . token ; fee = t . fee ; amount = t . amount ; valid_until = t . valid_until ; memo = t . memo ; hash ; no...
let of_operations ? memo ? valid_until ( ops : Operation . t list ) list : ( Partial . t , Partial . Reason . t ) t Validation . t = let find_kind k ( ops : Operation . t list ) list = let name = Operation_types . name k in List . find ops ~ f ( : fun op -> String . equal op . Ope...
let to_operations ~ failure_status ( t : Partial . t ) t : Operation . t list = let plan : ' a Op . t list = ( if not Unsigned . UInt64 ( . equal t . fee zero ) zero then [ { Op . label = ` Fee_payment ; related_to = None } ] else [ ] ) @ ( match failure_status with | ...
let to_operations ' ( t : t ) t : Operation . t list = to_operations ~ failure_status : t . failure_status ( forget t ) t let start = { kind = ` Payment ; fee_payer = ` Pk " Alice " ; source = ` Pk " Alice " ; token = ` Token_id Amount_of . Token_id . default ; fee = U...
let non_default_token = ` Token_id ( Token_id . to_string ( Quickcheck . random_value Token_id . gen_non_default ) gen_non_default ) gen_non_default
let dummies = [ { kind = ` Payment ; fee_payer = ` Pk " Alice " ; source = ` Pk " Alice " ; token = ` Token_id Amount_of . Token_id . default ; fee_token = ` Token_id Amount_of . Token_id . default ; fee = Unsigned . UInt64 . of_int 2_000_000_000 ; receiver = ` Pk " Bob...
module Payload = struct module Common = struct [ %% versioned module Stable = struct module V2 = struct type t = ( Currency . Fee . Stable . V1 . t , Public_key . Compressed . Stable . V1 . t , Account_nonce . Stable . V1 . t option , Global_slot . Stable . V1 . t , Signed_command_memo . Stable . ...
module Sign_choice = struct [ %% versioned module Stable = struct module V1 = struct type t = | Signature of Signature . Stable . V1 . t | Hd_index of Unsigned_extended . UInt32 . Stable . V1 . t | Keypair of Keypair . Stable . V1 . t [ @@ deriving sexp , to_yojson ] to_yojson let to_latest = Fn . ...
module Stable = struct module V2 = struct type t = ( Payload . Stable . V2 . t , Public_key . Compressed . Stable . V1 . t , Sign_choice . Stable . V1 . t ) Signed_command . Poly . Stable . V1 . t [ @@ deriving sexp , to_yojson ] to_yojson let to_latest = Fn . id end end ] end
let fee_payer ( { payload ; _ } : t ) t = Payload . fee_payer payload
let create ? nonce ~ fee ~ fee_payer_pk ~ valid_until ~ memo ~ body ~ signer ~ sign_choice ( ) : t = let valid_until = Option . value valid_until ~ default : Global_slot . max_value in let payload = Payload . create ~ fee ~ fee_payer_pk ? nonce ~ valid_until ~ memo ~ body in { payload ; ...
let sign ~ signer ( ~ user_command_payload : Signed_command_payload . t ) t = function | Sign_choice . Signature signature -> Option . value_map ~ default ( : Deferred . return ( Error " Invalid_signature ) ) " ( Signed_command . create_with_signature_checked signature signer user_comm...
let inferred_nonce ~ get_current_nonce ( ~ fee_payer : Account_id . t ) t ~ nonce_map = let open Result . Let_syntax in let update_map = Map . set nonce_map ~ key : fee_payer in match Map . find nonce_map fee_payer with | Some ( min_nonce , nonce ) nonce -> let next_nonce = Account_nonce . suc...
let warn_if_unable_to_pay_account_creation_fee ~ get_account ( ~ constraint_constants : Genesis_constants . Constraint_constants . t ) t ~ logger user_command_payload = let receiver_pk = Signed_command_payload . receiver_pk user_command_payload in let token = Signed_command_payload . token user_command...
let to_user_command ( ? nonce_map = Account_id . Map . empty ) empty ~ get_current_nonce ~ get_account ~ constraint_constants ~ logger ( client_input : t ) t = Deferred . map ~ f : ( Result . map_error ~ f ( : fun str -> Error . createf " Error creating user command : % s Error : ...
let to_user_commands ( ? nonce_map = Account_id . Map . empty ) empty ~ get_current_nonce ~ get_account ~ constraint_constants ~ logger uc_inputs : Signed_command . t list Deferred . Or_error . t = let open Deferred . Or_error . Let_syntax in let % map user_commands , _ = Deferred . Or_error . L...
type t = { author_name : string option ; email : string option ; github_username : string option ; create_switch : bool option }
let of_dec ( dec : Dec_user_config . t ) t = { author_name = dec . author_name ; email = dec . email ; github_username = dec . github_username ; create_switch = dec . create_switch }
let path_of_opt value = value |> Option . map Result . ok |> Option . value ~ default : ( Config . spin_config_dir |> Result . map ( fun p -> Filename . concat p " default ) ) "
let read ? path ( ) = let decode_if_exists path = if Sys . file_exists path then Decoder . decode_sexps_file path Dec_user_config . decode |> Result . map of_dec |> Result . map Option . some |> Result . map_error ( Spin_error . of_decoder_error ~ file : path ) path else Ok None in Result . bin...
let save ? path ( t : t ) t = let open Result . Syntax in let + path = path_of_opt path in let ( ) = Sys . mkdir_p ( Filename . dirname path ) path in Encoder . encode_file path Dec_user_config . { author_name = t . author_name ; email = t . email ; github_username = t . github_usern...
let validate_strip s = match String . trim s with " " -> Error " Enter a value . " | s -> Ok s
let prompt ? default : d ( ) = let author_name = Inquire . input " Your name " ? default ( : Option . bind d ( fun d -> d . author_name ) author_name ) author_name ~ validate : validate_strip in let email = Inquire . input " Your email " ? default ( : Option . bind d ( fun d ...
let to_context t = let context = Hashtbl . create 256 in Option . iter ( fun v -> Hashtbl . add context " author_name " v |> ignore ) ignore t . author_name ; Option . iter ( fun v -> Hashtbl . add context " email " v |> ignore ) ignore t . email ; Option . iter ( fun v -> Hashtb...
module Search = struct module Query = Empty . Query module Request = struct type t = { search_term : string ; limited : int option } [ @@ deriving accessor ] let encoding = let to_tuple t = t . search_term , t . limited in let of_tuple v = let search_term , limited = v in { search_term ...
type links = | LINKS of ( ( int * int ) * int ) list | WHATEVER | SOME | TYPE of string * string
type cc_port = { port_links : links ; port_states : string list option ; }
type site = | Port of cc_port | Counter of int
type cc_site = { site_name : string ; site_type : site }
type cc_node = { node_type : string ; node_id : int option ; node_sites : cc_site array ; }
type connected_component = cc_node option array array
module LinkSetMap = SetMap . Make ( struct type t = ( int * int ) * int let print = Pp . pair ( Pp . pair Format . pp_print_int Format . pp_print_int ) Format . pp_print_int let compare ( x , y ) ( x ' , y ' ) = let c = Mods . int_pair_compare x x ' in if c = 0 then Mo...
let print_link ( dangling , free_id ) p f = function | WHATEVER -> Format . pp_print_string f " [ ] " # | SOME -> Format . pp_print_string f " [ _ ] " | TYPE ( si , ty ) -> Format . fprintf f " [ % s . % s ] " si ty | LINKS [ ] -> Format . pp_print_string f...
let print_port with_link node p id f = Format . fprintf f " % a % a " ( fun f -> function | None -> Format . pp_print_string f " { } " # | Some [ ] -> ( ) | Some l -> Format . fprintf f " { % a } " ( Pp . list Pp . space ( fun f i -> Format . fprintf f " % s...
let print_intf with_link node = Pp . array Pp . space ( fun id f si -> let ( ) = Format . fprintf f " % s " si . site_name in ( match si . site_type with | Port p -> print_port with_link node p id f | Counter i -> Format . fprintf f " { =% i } " i ) )
let print_agent with_id link node f = function | None -> Format . pp_print_string f " . " | Some ag -> Format . fprintf f " % a % s ( [ @< h >% a ] ) " @ ( Pp . option ~ with_space : false ( fun f i -> Format . fprintf f " x % i " : i ) ) ( if with_id then ag . n...
let print_cc f mix = let link = Some ( ref ( LinkSetMap . Map . empty ) , ref 0 ) in Pp . array ( fun f -> Format . fprintf f " \\@ " ) ( fun al -> Pp . array Pp . comma ( fun ar -> print_agent true link ( al , ar ) ) ) f mix
let get_color = let store = Hashtbl . create 10 in fun i -> try Hashtbl . find store i with Not_found -> let v = Format . sprintf " #% x % x % x " ( Random . int 255 ) ( Random . int 255 ) ( Random . int 255 ) in let ( ) = Hashtbl . add store i v in v
let print_dot_cc nb_cc f mix = Pp . array Pp . empty ( fun il -> Pp . array Pp . empty ( fun ir f -> function | None -> ( ) | Some ag -> Format . fprintf f " node % d_ % d_ % d [ label = " [ \@< h >% a ] " , @\ color = " \% s " , \ style = filled ] ; , " ...
let write_cc_port ob p = let ( ) = Bi_outbuf . add_char ob ' { ' in let ( ) = JsonUtil . write_field " port_links " ( fun ob -> function | WHATEVER -> Yojson . Basic . write_null ob ( ) | SOME -> Yojson . Basic . write_bool ob true | TYPE ( si , ty ) -> let ( ) =...
let write_site ob f = let ( ) = Bi_outbuf . add_char ob ' [ ' in let ( ) = match f . site_type with | Counter i -> let ( ) = Yojson . Basic . write_string ob " counter " in let ( ) = Bi_outbuf . add_char ob ' , ' in Yojson . Basic . write_int ob i | Port p -> let (...
let write_cc_site ob f = let ( ) = Bi_outbuf . add_char ob ' { ' in let ( ) = JsonUtil . write_field " site_name " Yojson . Basic . write_string ob f . site_name in let ( ) = JsonUtil . write_comma ob in let ( ) = JsonUtil . write_field " site_type " write_site ob f in B...
let links_of_yojson = function | ` Null -> WHATEVER | ` Bool b -> let ( ) = assert b in SOME | ` Assoc [ " site_name " , ` String si ; " agent_type " , ` String ty ] | ` Assoc [ " agent_type " , ` String ty ; " site_name " , ` String si ] -> TYPE ( si ,...
let read_cc_port p lb = let ( port_links , port_states ) = Yojson . Basic . read_fields ( fun ( s , i ) key p lb -> if key = " port_links " then ( links_of_yojson ( Yojson . Basic . read_json p lb ) , i ) else let ( ) = assert ( key = " port_states " ) in ( s , ...
let read_site p lb = let ( ) = Yojson . Basic . read_lbr p lb in let key = JsonUtil . read_between_spaces Yojson . Basic . read_string p lb in let ( ) = Yojson . Basic . read_comma p lb in let out = JsonUtil . read_between_spaces ( fun p lb -> if key = " counter " then Counter ( Y...
let read_cc_site p lb = let ( site_name , site_type ) = Yojson . Basic . read_fields ( fun ( n , s ) key p lb -> if key = " site_name " then ( Yojson . Basic . read_string p lb , s ) else let ( ) = assert ( key = " site_type " ) in ( n , read_site p lb ) ) ( "...
let write_cc_node ob x = JsonUtil . write_option ( fun ob f -> let ( ) = Bi_outbuf . add_char ob ' { ' in let ( ) = JsonUtil . write_field " node_type " Yojson . Basic . write_string ob f . node_type in let ( ) = JsonUtil . write_comma ob in let ( ) = match f . node_id ...
let read_cc_node p lb = JsonUtil . read_option ( fun p lb -> let ( node_id , node_type , node_sites ) = Yojson . Basic . read_fields ( fun ( id , n , s ) key p lb -> if key = " node_id " then ( Some ( Yojson . Basic . read_int p lb ) , n , s ) else if key = " node_t...
let write_connected_component ob f = JsonUtil . write_array ( JsonUtil . write_array write_cc_node ) ob f
let read_connected_component ob f = Yojson . Basic . read_array ( Yojson . Basic . read_array read_cc_node ) ob f