diff --git a/src/app/cli/src/init/client.ml b/src/app/cli/src/init/client.ml index 3ff3454f4bf..f3538203fdf 100644 --- a/src/app/cli/src/init/client.ml +++ b/src/app/cli/src/init/client.ml @@ -67,20 +67,21 @@ let get_balance_graphql = ~f:(fun graphql_endpoint (public_key, token) -> let%map response = Graphql_client.query_exn - (Graphql_queries.Get_tracked_account.make - ~public_key:(Graphql_lib.Encoders.public_key public_key) - ~token:(Graphql_lib.Encoders.token token) - () ) + Graphql_queries.Get_tracked_account.( + make @@ makeVariables + ~public_key:(Graphql_lib.Encoders.public_key public_key) + ~token:(Graphql_lib.Encoders.token token) + ()) graphql_endpoint in - match response#account with + match response.account with | Some account -> if Token_id.(equal default) token then printf "Balance: %s mina\n" - (Currency.Balance.to_formatted_string account#balance#total) + (Currency.Balance.to_formatted_string account.balance.total) else printf "Balance: %s tokens\n" - (Currency.Balance.to_formatted_string account#balance#total) + (Currency.Balance.to_formatted_string account.balance.total) | None -> printf "There are no funds in this account\n" ) ) @@ -96,14 +97,14 @@ let get_tokens_graphql = ~f:(fun graphql_endpoint public_key -> let%map response = Graphql_client.query_exn - (Graphql_queries.Get_all_accounts.make + Graphql_queries.Get_all_accounts.(make @@ makeVariables ~public_key:(Graphql_lib.Encoders.public_key public_key) - () ) + ()) graphql_endpoint in printf "Accounts are held for token IDs:\n" ; - Array.iter response#accounts ~f:(fun account -> - printf "%s " (Token_id.to_string account#token) ) ) ) + Array.iter response.accounts ~f:(fun account -> + printf "%s " (Token_id.to_string account.token) ) ) ) let get_time_offset_graphql = Command.async @@ -114,10 +115,10 @@ let get_time_offset_graphql = ~f:(fun graphql_endpoint () -> let%map response = Graphql_client.query_exn - (Graphql_queries.Time_offset.make ()) + Graphql_queries.Time_offset.(make @@ makeVariables ()) graphql_endpoint in - let time_offset = response#timeOffset in + let time_offset = response.timeOffset in printf "Current time offset:\n\ %i\n\n\ @@ -534,7 +535,7 @@ let send_payment_graphql = -> let%map response = Graphql_client.query_exn - (Graphql_queries.Send_payment.make + Graphql_queries.Send_payment.(make @@ makeVariables ~receiver:(Encoders.public_key receiver) ~sender:(Encoders.public_key sender) ~amount:(Encoders.amount amount) ~fee:(Encoders.fee fee) @@ -544,7 +545,7 @@ let send_payment_graphql = graphql_endpoint in printf "Dispatched payment with ID %s\n" - (response#sendPayment#payment |> unwrap_user_command)#id ) ) + response.sendPayment.payment.id)) let delegate_stake_graphql = let open Command.Param in @@ -564,7 +565,7 @@ let delegate_stake_graphql = -> let%map response = Graphql_client.query_exn - (Graphql_queries.Send_delegation.make + Graphql_queries.Send_delegation.(make @@ makeVariables ~receiver:(Encoders.public_key receiver) ~sender:(Encoders.public_key sender) ~fee:(Encoders.fee fee) @@ -573,7 +574,7 @@ let delegate_stake_graphql = graphql_endpoint in printf "Dispatched stake delegation with ID %s\n" - (response#sendDelegation#delegation |> unwrap_user_command)#id ) ) + response.sendDelegation.delegation.id ) ) let create_new_token_graphql = let open Command.Param in @@ -594,7 +595,7 @@ let create_new_token_graphql = let receiver = Option.value ~default:sender receiver in let%map response = Graphql_client.query_exn - (Graphql_queries.Send_create_token.make + Graphql_queries.Send_create_token.(make @@ makeVariables ~sender:(Encoders.public_key sender) ~receiver:(Encoders.public_key receiver) ~fee:(Encoders.fee fee) @@ -603,7 +604,7 @@ let create_new_token_graphql = graphql_endpoint in printf "Dispatched create new token command with TRANSACTION_ID %s\n" - response#createToken#createNewToken#id ) ) + response.createToken.createNewToken.id ) ) let create_new_account_graphql = let open Command.Param in @@ -650,11 +651,11 @@ let create_new_account_graphql = let%map token_owner = Graphql_client.( query_exn - (Graphql_queries.Get_token_owner.make + Graphql_queries.Get_token_owner.(make @@ makeVariables ~token:(Encoders.token token) () )) graphql_endpoint in - match token_owner#tokenOwner with + match token_owner.tokenOwner with | Some token_owner -> Graphql_lib.Decoders.public_key token_owner | None -> @@ -664,7 +665,7 @@ let create_new_account_graphql = in let%map response = Graphql_client.query_exn - (Graphql_queries.Send_create_token_account.make + Graphql_queries.Send_create_token_account.(make @@ makeVariables ~sender:(Encoders.public_key sender) ~receiver:(Encoders.public_key receiver) ~tokenOwner:(Encoders.public_key token_owner) @@ -675,7 +676,7 @@ let create_new_account_graphql = in printf "Dispatched create new token account command with TRANSACTION_ID %s\n" - response#createTokenAccount#createNewTokenAccount#id ) ) + response.createTokenAccount.createNewTokenAccount.id ) ) let mint_tokens_graphql = let open Command.Param in @@ -708,7 +709,7 @@ let mint_tokens_graphql = -> let%map response = Graphql_client.query_exn - (Graphql_queries.Send_mint_tokens.make + Graphql_queries.Send_mint_tokens.(make @@ makeVariables ~sender:(Encoders.public_key sender) ?receiver:(Option.map ~f:Encoders.public_key receiver) ~token:(Encoders.token token) ~amount:(Encoders.amount amount) @@ -718,7 +719,7 @@ let mint_tokens_graphql = graphql_endpoint in printf "Dispatched mint token command with TRANSACTION_ID %s\n" - response#mintTokens#mintTokens#id ) ) + response.mintTokens.mintTokens.id ) ) let cancel_transaction_graphql = let txn_id_flag = @@ -748,7 +749,7 @@ let cancel_transaction_graphql = (Currency.Fee.to_formatted_string cancel_fee) ; let cancel_query = let open Graphql_lib.Encoders in - Graphql_queries.Send_payment.make + Graphql_queries.Send_payment.(make @@ makeVariables ~sender:(public_key cancel_sender_pk) ~receiver:(public_key receiver_pk) ~fee:(fee cancel_fee) ~amount:(amount Currency.Amount.zero) @@ -756,13 +757,13 @@ let cancel_transaction_graphql = (uint32 (Mina_numbers.Account_nonce.to_uint32 (Signed_command.nonce user_command) ) ) - () + ()) in let%map cancel_response = Graphql_client.query_exn cancel_query graphql_endpoint in printf "šŸ›‘ Cancelled transaction! Cancel ID: %s\n" - (cancel_response#sendPayment#payment |> unwrap_user_command)#id ) ) + cancel_response.sendPayment.payment.id ) ) let send_rosetta_transactions_graphql = Command.async @@ -781,15 +782,12 @@ let send_rosetta_transactions_graphql = in let%map response = Graphql_client.query_exn - (Graphql_queries.Send_rosetta_transaction.make + Graphql_queries.Send_rosetta_transaction.(make @@ makeVariables ~transaction:transaction_json () ) graphql_endpoint in - let (`UserCommand user_command) = - response#sendRosettaTransaction#userCommand - in printf "Dispatched command with TRANSACTION_ID %s\n" - user_command#id ; + response.sendRosettaTransaction.userCommand.id ; `Repeat () with Yojson.End_of_input -> return (`Finished ()) ) ) with @@ -815,10 +813,10 @@ module Export_logs = struct ~f:(fun graphql_endpoint basename -> let%map response = Graphql_client.query_exn - (Graphql_queries.Export_logs.make ?basename ()) + Graphql_queries.Export_logs.(make @@ makeVariables ?basename ()) graphql_endpoint in - pp_export_result response#exportLogs#exportLogs#tarfile ) ) + pp_export_result response.exportLogs.exportLogs.tarfile ) ) let export_locally = let run ~tarfile ~conf_dir = @@ -1131,7 +1129,7 @@ let snark_pool_list = ~f:(fun graphql_endpoint () -> Deferred.map (Graphql_client.query_exn - (Graphql_queries.Snark_pool.make ()) + Graphql_queries.Snark_pool.(make @@ makeVariables ()) graphql_endpoint ) ~f:(fun response -> let lst = @@ -1140,11 +1138,11 @@ let snark_pool_list = (Array.map ~f:(fun w -> { Cli_lib.Graphql_types.Completed_works.Work.work_ids = - Array.to_list w#work_ids - ; fee = Currency.Fee.of_uint64 w#fee - ; prover = w#prover + Array.to_list w.work_ids + ; fee = Currency.Fee.of_uint64 w.fee + ; prover = w.prover } ) - response#snarkPool ) ) + response.snarkPool ) ) in print_string (Yojson.Safe.to_string lst) ) ) ) @@ -1161,20 +1159,12 @@ let pooled_user_commands = Yojson.Safe.to_basic @@ [%to_yojson: Public_key.Compressed.t option] maybe_public_key in - let graphql = - Graphql_queries.Pooled_user_commands.make ~public_key () + let module Q = Graphql_queries.Pooled_user_commands in + let graphql = Q.( make @@ makeVariables ~public_key ()) in let%map response = Graphql_client.query_exn graphql graphql_endpoint in - let json_response : Yojson.Safe.t = - `List - ( List.map - ~f: - (Fn.compose Graphql_client.Signed_command.to_yojson - (Fn.compose Graphql_client.Signed_command.of_obj - unwrap_user_command ) ) - @@ Array.to_list response#pooledUserCommands ) - in - print_string (Yojson.Safe.to_string json_response) ) ) + let json_response = Q.serialize response |> Q.toJson in + print_string (Yojson.Basic.to_string json_response) ) ) let to_signed_fee_exn sign magnitude = let sgn = match sign with `PLUS -> Sgn.Pos | `MINUS -> Neg in @@ -1191,30 +1181,30 @@ let pending_snark_work = ~f:(fun graphql_endpoint () -> Deferred.map (Graphql_client.query_exn - (Graphql_queries.Pending_snark_work.make ()) + Graphql_queries.Pending_snark_work.(make @@ makeVariables ()) graphql_endpoint ) ~f:(fun response -> let lst = [%to_yojson: Cli_lib.Graphql_types.Pending_snark_work.t] (Array.map ~f:(fun bundle -> - Array.map bundle#workBundle ~f:(fun w -> - let f = w#fee_excess in + Array.map bundle.workBundle ~f:(fun w -> + let f = w.fee_excess in let hash_of_string = Mina_base.Frozen_ledger_hash.of_base58_check_exn in { Cli_lib.Graphql_types.Pending_snark_work.Work - .work_id = w#work_id + .work_id = w.work_id ; fee_excess = - to_signed_fee_exn f#sign f#fee_magnitude + to_signed_fee_exn f.sign f.fee_magnitude ; supply_increase = - Currency.Amount.of_uint64 w#supply_increase + Currency.Amount.of_uint64 w.supply_increase ; source_ledger_hash = - hash_of_string w#source_ledger_hash + hash_of_string w.source_ledger_hash ; target_ledger_hash = - hash_of_string w#target_ledger_hash + hash_of_string w.target_ledger_hash } ) ) - response#pendingSnarkWork ) + response.pendingSnarkWork ) in print_string (Yojson.Safe.to_string lst) ) ) ) @@ -1271,7 +1261,7 @@ let set_coinbase_receiver_graphql = in let%map result = Graphql_client.query_exn - (Graphql_queries.Set_coinbase_receiver.make + Graphql_queries.Set_coinbase_receiver.(make @@ makeVariables ~public_key: (Option.value_map ~f:Encoders.public_key public_key_opt ~default:`Null ) @@ -1280,8 +1270,8 @@ let set_coinbase_receiver_graphql = in printf "Was sending coinbases to the %a\nNow sending coinbases to the %a\n" - print_pk_opt result#setCoinbaseReceiver#lastCoinbaseReceiver - print_pk_opt result#setCoinbaseReceiver#currentCoinbaseReceiver ) ) + print_pk_opt result.setCoinbaseReceiver.lastCoinbaseReceiver + print_pk_opt result.setCoinbaseReceiver.currentCoinbaseReceiver ) ) let set_snark_worker = let open Command.Param in @@ -1297,10 +1287,10 @@ let set_snark_worker = (Cli_lib.Background_daemon.graphql_init public_key_flag ~f:(fun graphql_endpoint optional_public_key -> let graphql = - Graphql_queries.Set_snark_worker.make + Graphql_queries.Set_snark_worker.(make @@ makeVariables ~public_key: Graphql_lib.Encoders.(optional optional_public_key ~f:public_key) - () + ()) in Deferred.map (Graphql_client.query_exn graphql graphql_endpoint) ~f:(fun response -> @@ -1312,7 +1302,7 @@ let set_snark_worker = | None -> printf "Will stop doing snark work\n" ) ; printf "Previous snark worker public key : %s\n" - (Option.value_map response#setSnarkWorker#lastSnarkWorker + (Option.value_map response.setSnarkWorker.lastSnarkWorker ~default:"None" ~f:Public_key.Compressed.to_base58_check ) ) ) ) @@ -1322,16 +1312,16 @@ let set_snark_work_fee = Command.Param.(anon @@ ("fee" %: Cli_lib.Arg_type.txn_fee)) ~f:(fun graphql_endpoint fee -> let graphql = - Graphql_queries.Set_snark_work_fee.make + Graphql_queries.Set_snark_work_fee.(make @@ makeVariables ~fee:(Graphql_lib.Encoders.uint64 @@ Currency.Fee.to_uint64 fee) - () + ()) in Deferred.map (Graphql_client.query_exn graphql graphql_endpoint) ~f:(fun response -> printf !"Updated snark work fee: %i\nOld snark work fee: %i\n" (Currency.Fee.to_int fee) - (Unsigned.UInt64.to_int response#setSnarkWorkFee#lastFee) ) ) + (Unsigned.UInt64.to_int response.setSnarkWorkFee.lastFee) ) ) let import_key = Command.async @@ -1365,14 +1355,14 @@ let import_key = password in let graphql = - Graphql_queries.Import_account.make ~path:privkey_path - ~password:(Bytes.to_string password) () + Graphql_queries.Import_account.(make @@ makeVariables ~path:privkey_path + ~password:(Bytes.to_string password) ()) in match%map Graphql_client.query graphql graphql_endpoint with | Ok res -> - let res = res#importAccount in - if res#already_imported then Ok (`Already_imported res#public_key) - else Ok (`Imported res#public_key) + let res = res.importAccount in + if res.already_imported then Ok (`Already_imported res.public_key) + else Ok (`Imported res.public_key) | Error (`Failed_request _ as err) -> Error err | Error (`Graphql_error _ as err) -> @@ -1561,11 +1551,11 @@ let list_accounts = let do_graphql graphql_endpoint = match%map Graphql_client.query - (Graphql_queries.Get_tracked_accounts.make ()) + Graphql_queries.Get_tracked_accounts.(make @@ makeVariables ()) graphql_endpoint with | Ok response -> ( - match response#trackedAccounts with + match response.trackedAccounts with | [||] -> printf "šŸ˜¢ You have no tracked accounts!\n\ @@ -1574,14 +1564,14 @@ let list_accounts = | accounts -> Array.iteri accounts ~f:(fun i w -> printf - "Account #%d:\n\ + "Account .%d:\n\ \ Public key: %s\n\ \ Balance: %s\n\ \ Locked: %b\n" (i + 1) - (Public_key.Compressed.to_base58_check w#public_key) - (Currency.Balance.to_formatted_string w#balance#total) - (Option.value ~default:true w#locked) ) ; + (Public_key.Compressed.to_base58_check w.public_key) + (Currency.Balance.to_formatted_string w.balance.total) + (Option.value ~default:true w.locked) ) ; Ok () ) | Error (`Failed_request _ as err) -> Error err @@ -1602,7 +1592,7 @@ let list_accounts = You can make a new one using `mina accounts create`\n" | accounts -> List.iteri accounts ~f:(fun i public_key -> - printf "Account #%d:\n Public key: %s\n" (i + 1) + printf "Account .%d:\n Public key: %s\n" (i + 1) (Public_key.Compressed.to_base58_check public_key) ) in match access_method with @@ -1640,13 +1630,13 @@ let create_account = in let%map response = Graphql_client.query_exn - (Graphql_queries.Create_account.make + Graphql_queries.Create_account.(make @@ makeVariables ~password:(Bytes.to_string password) () ) graphql_endpoint in let pk_string = Public_key.Compressed.to_base58_check - response#createAccount#public_key + response.createAccount.public_key in printf "\nšŸ˜„ Added new account!\nPublic key: %s\n" pk_string ) ) @@ -1657,14 +1647,14 @@ let create_hd_account = let%map response = Graphql_client.( query_exn - (Graphql_queries.Create_hd_account.make + Graphql_queries.Create_hd_account.(make @@ makeVariables ~hd_index:(Graphql_lib.Encoders.uint32 hd_index) () )) graphql_endpoint in let pk_string = Public_key.Compressed.to_base58_check - response#createHDAccount#public_key + response.createHDAccount.public_key in printf "\nšŸ˜„ created HD account with HD-index %s!\nPublic key: %s\n" (Mina_numbers.Hd_index.to_string hd_index) @@ -1689,7 +1679,7 @@ let unlock_account = | Ok password_bytes -> let%map response = Graphql_client.query_exn - (Graphql_queries.Unlock_account.make + Graphql_queries.Unlock_account.(make @@ makeVariables ~public_key:(Graphql_lib.Encoders.public_key pk_str) ~password:(Bytes.to_string password_bytes) () ) @@ -1697,7 +1687,7 @@ let unlock_account = in let pk_string = Public_key.Compressed.to_base58_check - response#unlockAccount#public_key + response.unlockAccount.public_key in printf "\nšŸ”“ Unlocked account!\nPublic key: %s\n" pk_string | Error e -> @@ -1717,13 +1707,13 @@ let lock_account = ~f:(fun graphql_endpoint pk -> let%map response = Graphql_client.query_exn - (Graphql_queries.Lock_account.make + Graphql_queries.Lock_account.(make @@ makeVariables ~public_key:(Graphql_lib.Encoders.public_key pk) () ) graphql_endpoint in let pk_string = - Public_key.Compressed.to_base58_check response#lockAccount#public_key + Public_key.Compressed.to_base58_check response.lockAccount.public_key in printf "šŸ”’ Locked account!\nPublic key: %s\n" pk_string ) ) @@ -1820,15 +1810,15 @@ let get_peers_graphql = ~f:(fun graphql_endpoint () -> let%map response = Graphql_client.query_exn - (Graphql_queries.Get_peers.make ()) + Graphql_queries.Get_peers.(make @@ makeVariables ()) graphql_endpoint in - Array.iter response#getPeers ~f:(fun peer -> + Array.iter response.getPeers ~f:(fun peer -> printf "%s\n" (Network_peer.Peer.to_multiaddr_string - { host = Unix.Inet_addr.of_string peer#host - ; libp2p_port = peer#libp2pPort - ; peer_id = peer#peerId + { host = Unix.Inet_addr.of_string peer.host + ; libp2p_port = peer.libp2pPort + ; peer_id = peer.peerId } ) ) ) ) let add_peers_graphql = @@ -1858,14 +1848,11 @@ let add_peers_graphql = |> Mina_net2.Multiaddr.to_peer |> Option.map ~f:Network_peer.Peer.to_display with - | Some peer -> - object - method host = peer.host - - method libp2p_port = peer.libp2p_port - - method peer_id = peer.peer_id - end + | Some peer -> { + Graphql_queries.Add_peers.host = peer.host; + libp2p_port = peer.libp2p_port; + peer_id = peer.peer_id + } | None -> eprintf "Could not parse %s as a peer address. It should use the \ @@ -1876,16 +1863,16 @@ let add_peers_graphql = let seed = Option.value ~default:true seed in let%map response = Graphql_client.query_exn - (Graphql_queries.Add_peers.make ~peers ~seed ()) + Graphql_queries.Add_peers.(make @@ makeVariables ~peers ~seed ()) graphql_endpoint in printf "Requested to add peers:\n" ; - Array.iter response#addPeers ~f:(fun peer -> + Array.iter response.addPeers ~f:(fun peer -> printf "%s\n" (Network_peer.Peer.to_multiaddr_string - { host = Unix.Inet_addr.of_string peer#host - ; libp2p_port = peer#libp2pPort - ; peer_id = peer#peerId + { host = Unix.Inet_addr.of_string peer.host + ; libp2p_port = peer.libp2pPort + ; peer_id = peer.peerId } ) ) ) ) let compile_time_constants = @@ -2020,11 +2007,11 @@ let next_available_token_cmd = ~f:(fun graphql_endpoint () -> let%map response = Graphql_client.query_exn - (Graphql_queries.Next_available_token.make ()) + Graphql_queries.Next_available_token.(make @@ makeVariables ()) graphql_endpoint in printf "Next available token ID: %s\n" - (Token_id.to_string response#nextAvailableToken) ) ) + (Token_id.to_string response.nextAvailableToken) ) ) let object_lifetime_statistics = let open Daemon_rpcs in @@ -2109,7 +2096,7 @@ let archive_blocks = (* Don't catch this error: [query_exn] already handles printing etc. *) - Graphql_client.query (graphql_make ~block ()) graphql_endpoint + Graphql_client.query (graphql_make block) graphql_endpoint |> Deferred.Result.map_error ~f:(function | `Failed_request e -> Error.create "Unable to connect to Mina daemon" () @@ -2143,14 +2130,20 @@ let archive_blocks = let add_to_failure_file = output_file_line failure_file in let send_precomputed_block = make_send_block - ~graphql_make:Graphql_queries.Archive_precomputed_block.make + ~graphql_make:(fun block -> + Graphql_queries.Archive_precomputed_block.( + make @@ makeVariables ~block () + )) ~archive_dispatch: Mina_lib.Archive_client.dispatch_precomputed_block ~block_to_yojson:Mina_block.Precomputed.to_yojson in let send_extensional_block = make_send_block - ~graphql_make:Graphql_queries.Archive_extensional_block.make + ~graphql_make:(fun block -> + Graphql_queries.Archive_extensional_block.( + make @@ makeVariables ~block () + )) ~archive_dispatch: Mina_lib.Archive_client.dispatch_extensional_block ~block_to_yojson:Archive_lib.Extensional.Block.to_yojson @@ -2298,12 +2291,12 @@ let runtime_config = ~f:(fun graphql_endpoint () -> match%bind Graphql_client.query - (Graphql_queries.Runtime_config.make ()) + Graphql_queries.Runtime_config.(make @@ makeVariables ()) graphql_endpoint with | Ok runtime_config -> Format.printf "%s@." - (Yojson.Basic.pretty_to_string runtime_config#runtimeConfig) ; + (Yojson.Basic.pretty_to_string runtime_config.runtimeConfig) ; return () | Error err -> Format.eprintf @@ -2321,11 +2314,11 @@ let thread_graph = ~f:(fun graphql_endpoint () -> match%bind Graphql_client.query - (Graphql_queries.Thread_graph.make ()) + Graphql_queries.Thread_graph.(make @@ makeVariables ()) graphql_endpoint with | Ok graph -> - print_endline graph#threadGraph ; + print_endline graph.threadGraph ; return () | Error e -> Format.eprintf diff --git a/src/app/cli/src/init/dune b/src/app/cli/src/init/dune index 0b71fad25e4..6ae22521d7e 100644 --- a/src/app/cli/src/init/dune +++ b/src/app/cli/src/init/dune @@ -21,6 +21,7 @@ uri core_kernel core + base async cohttp graphql_parser @@ -94,4 +95,15 @@ ) (instrumentation (backend bisect_ppx)) (preprocessor_deps ../../../../config.mlh ../../../../../graphql_schema.json) - (preprocess (pps graphql_ppx ppx_deriving_yojson ppx_coda ppx_version ppx_let))) + (preprocess (pps ppx_deriving_yojson ppx_coda ppx_version + ; ppx_jane except ppx_optcomp + ppx_base ppx_assert ppx_bench ppx_bin_prot ppx_custom_printf + ppx_fields_conv ppx_fixed_literal ppx_here ppx_inline_test ppx_let + ppx_module_timer ppx_optional ppx_pipebang ppx_sexp_message + ppx_sexp_value ppx_string ppx_typerep_conv ppx_variants_conv + ; GraphQL with config + graphql_ppx -- + -extend-query Graphql_lib.Serializing.ExtendQuery + -extend-mutation Graphql_lib.Serializing.ExtendQuery + -future-added-value false + ))) diff --git a/src/app/cli/src/init/graphql_client.ml b/src/app/cli/src/init/graphql_client.ml index d95e4656c11..f58e81e5731 100644 --- a/src/app/cli/src/init/graphql_client.ml +++ b/src/app/cli/src/init/graphql_client.ml @@ -1,7 +1,5 @@ open Core open Async -open Signature_lib -open Mina_base module Client = Graphql_lib.Client.Make (struct let preprocess_variables_string = Fn.id @@ -40,28 +38,3 @@ let query query_obj (uri : Uri.t Cli_lib.Flag.Types.with_name) = Client.query query_obj uri.value let query_exn query_obj port = run_exn ~f:Client.query query_obj port - -module Signed_command = struct - type t = - { id : string - ; isDelegation : bool - ; nonce : int - ; from : Public_key.Compressed.t - ; to_ : Public_key.Compressed.t - ; amount : Currency.Amount.t - ; fee : Currency.Fee.t - ; memo : Signed_command_memo.t - } - [@@deriving yojson] - - let of_obj x = - { id = x#id - ; isDelegation = x#isDelegation - ; nonce = x#nonce - ; from = x#from - ; to_ = x#to_ - ; amount = x#amount - ; fee = x#fee - ; memo = x#memo - } -end diff --git a/src/app/cli/src/init/graphql_queries.ml b/src/app/cli/src/init/graphql_queries.ml index 8588b86f0a5..460c6a37fb7 100644 --- a/src/app/cli/src/init/graphql_queries.ml +++ b/src/app/cli/src/init/graphql_queries.ml @@ -1,17 +1,17 @@ (* exclude from bisect_ppx to avoid type error on GraphQL modules *) [@@@coverage exclude_file] -module Decoders = Graphql_lib.Decoders +module Serializing = Graphql_lib.Serializing module Get_tracked_accounts = [%graphql {| query { trackedAccounts { - public_key: publicKey @bsDecoder(fn: "Decoders.public_key") + public_key: publicKey @ppxCustom(module: "Serializing.Public_key") locked balance { - total @bsDecoder(fn: "Decoders.balance") + total @ppxCustom(module: "Serializing.Balance") } } } @@ -20,10 +20,10 @@ query { module Get_tracked_account = [%graphql {| -query ($public_key: PublicKey, $token: UInt64) { +query ($public_key: PublicKey!, $token: UInt64) { account(publicKey: $public_key, token: $token) { balance { - total @bsDecoder(fn: "Decoders.balance") + total @ppxCustom(module: "Serializing.Balance") } } } @@ -32,9 +32,9 @@ query ($public_key: PublicKey, $token: UInt64) { module Get_all_accounts = [%graphql {| -query ($public_key: PublicKey) { +query ($public_key: PublicKey!) { accounts(publicKey: $public_key) { - token @bsDecoder(fn: "Decoders.token") + token @ppxCustom(module: "Serializing.Token") } } |}] @@ -42,9 +42,9 @@ query ($public_key: PublicKey) { module Create_account = [%graphql {| -mutation ($password: String) { +mutation ($password: String!) { createAccount(input: {password: $password}) { - public_key: publicKey @bsDecoder(fn: "Decoders.public_key") + public_key: publicKey @ppxCustom(module: "Serializing.Public_key") } } |}] @@ -52,9 +52,9 @@ mutation ($password: String) { module Create_hd_account = [%graphql {| -mutation ($hd_index: UInt32) { +mutation ($hd_index: UInt32!) { createHDAccount(input: {index: $hd_index}) { - public_key: publicKey @bsDecoder(fn: "Decoders.public_key") + public_key: publicKey @ppxCustom(module: "Serializing.Public_key") } } |}] @@ -62,9 +62,9 @@ mutation ($hd_index: UInt32) { module Unlock_account = [%graphql {| -mutation ($password: String, $public_key: PublicKey) { +mutation ($password: String!, $public_key: PublicKey!) { unlockAccount(input: {password: $password, publicKey: $public_key }) { - public_key: publicKey @bsDecoder(fn: "Decoders.public_key") + public_key: publicKey @ppxCustom(module: "Serializing.Public_key") } } |}] @@ -72,9 +72,9 @@ mutation ($password: String, $public_key: PublicKey) { module Lock_account = [%graphql {| -mutation ($public_key: PublicKey) { +mutation ($public_key: PublicKey!) { lockAccount(input: {publicKey: $public_key }) { - public_key: publicKey @bsDecoder(fn: "Decoders.public_key") + public_key: publicKey @ppxCustom(module: "Serializing.Public_key") } } |}] @@ -90,8 +90,8 @@ module Snark_pool = {| query snarkPool { snarkPool { - fee @bsDecoder(fn: "Decoders.uint64") - prover @bsDecoder(fn: "Decoders.public_key") + fee @ppxCustom(module: "Serializing.UInt64") + prover @ppxCustom(module: "Serializing.Public_key") work_ids: workIds } } @@ -107,9 +107,9 @@ query pendingSnarkWork { target_ledger_hash: targetLedgerHash fee_excess: feeExcess { sign - fee_magnitude: feeMagnitude @bsDecoder(fn: "Decoders.uint64") + fee_magnitude: feeMagnitude @ppxCustom(module: "Serializing.UInt64") } - supply_increase: supplyIncrease @bsDecoder(fn: "Decoders.uint64") + supply_increase: supplyIncrease @ppxCustom(module: "Serializing.UInt64") work_id: workId } } @@ -121,8 +121,8 @@ module Set_coinbase_receiver = {| mutation ($public_key: PublicKey) { setCoinbaseReceiver(input : {publicKey: $public_key}) { - lastCoinbaseReceiver @bsDecoder(fn: "Decoders.optional_public_key") - currentCoinbaseReceiver @bsDecoder(fn: "Decoders.optional_public_key") + lastCoinbaseReceiver @ppxCustom(module: "Serializing.Public_key") + currentCoinbaseReceiver @ppxCustom(module: "Serializing.Public_key") } } |}] @@ -132,7 +132,7 @@ module Set_snark_worker = {| mutation ($public_key: PublicKey) { setSnarkWorker (input : {publicKey: $public_key}) { - lastSnarkWorker @bsDecoder(fn: "Decoders.optional_public_key") + lastSnarkWorker @ppxCustom(module: "Serializing.Public_key") } } |}] @@ -142,7 +142,7 @@ module Set_snark_work_fee = {| mutation ($fee: UInt64!) { setSnarkWorkFee(input: {fee: $fee}) { - lastFee @bsDecoder(fn: "Decoders.uint64") + lastFee @ppxCustom(module: "Serializing.UInt64") } } |}] @@ -260,7 +260,7 @@ query tokenOwner($token: TokenId!) { module Get_inferred_nonce = [%graphql {| -query nonce($public_key: PublicKey) { +query nonce($public_key: PublicKey!) { account(publicKey: $public_key) { inferredNonce } @@ -275,11 +275,11 @@ query user_commands($public_key: PublicKey) { id isDelegation nonce - from @bsDecoder(fn: "Decoders.public_key") - to_: to @bsDecoder(fn: "Decoders.public_key") - amount @bsDecoder(fn: "Decoders.amount") - fee @bsDecoder(fn: "Decoders.fee") - memo @bsDecoder(fn: "Mina_base.Signed_command_memo.of_base58_check_exn") + from @ppxCustom(module: "Serializing.Public_key") + to_: to @ppxCustom(module: "Serializing.Public_key") + amount @ppxCustom(module: "Serializing.Amount") + fee @ppxCustom(module: "Serializing.Fee") + memo @ppxCustom(module: "Serializing.Memo") } } |}] @@ -288,7 +288,7 @@ module Next_available_token = [%graphql {| query next_available_token { - nextAvailableToken @bsDecoder(fn: "Decoders.token") + nextAvailableToken @ppxCustom(module: "Serializing.Token") } |}] @@ -359,7 +359,7 @@ module Import_account = {| mutation ($path: String!, $password: String!) { importAccount (path: $path, password: $password) { - public_key: publicKey @bsDecoder(fn: "Decoders.public_key") + public_key: publicKey @ppxCustom(module: "Serializing.Public_key") already_imported: alreadyImported success } diff --git a/src/lib/graphql_lib/serializing.ml b/src/lib/graphql_lib/serializing.ml new file mode 100644 index 00000000000..78b0a75d627 --- /dev/null +++ b/src/lib/graphql_lib/serializing.ml @@ -0,0 +1,129 @@ +(* serializing.ml -- regroup encoders and decoders in + modules for use with ppxCustom *) + +open Base + +let unimplemented op name _ = + let error = Printf.sprintf "JSON %s not implemented for %s!" op name in + failwith error + +let unimplemented_serializer (type t) s (x : t) = unimplemented "encoding" s x +(*let unimplemented_parser= unimplemented "decoding"*) + +module type GraphQLQuery = sig + module Raw : sig + type t + + type t_variables + end + + type t + + type t_variables + + val query : string + + val parse : Raw.t -> t + + val serialize : t -> Raw.t + + val unsafe_fromJson : Yojson.Basic.t -> Raw.t + + val toJson : Raw.t -> Yojson.Basic.t + + val serializeVariables : t_variables -> Raw.t_variables + + val variablesToJson : Raw.t_variables -> Yojson.Basic.t +end + +module ExtendQuery (Q : GraphQLQuery) = struct + let make variables = + object + method variables = Q.serializeVariables variables |> Q.variablesToJson + + method query = Q.query + + method parse x = Q.unsafe_fromJson x |> Q.parse + end +end + +module type S = sig + type t + + type conv + + val parse : conv -> t + + val serialize : t -> conv +end + +module type S_JSON = S with type conv := Yojson.Basic.t + +module type S_STRING = S with type conv := string + +module Optional (F : S_JSON) : S_JSON with type t = F.t option = struct + type t = F.t option + + let parse = Decoders.optional ~f:F.parse + + let serialize = Encoders.optional ~f:F.serialize +end + +module UInt64 : S_JSON with type t = Unsigned.UInt64.t = struct + type t = Unsigned.UInt64.t + + let parse = Decoders.uint64 + + let serialize = Encoders.uint64 +end + +module Public_key : S_JSON with type t = Signature_lib.Public_key.Compressed.t = +struct + type t = Signature_lib.Public_key.Compressed.t + + let parse = Decoders.public_key + + let serialize = unimplemented_serializer "public_key" +end + +module Optional_public_key = Optional (Public_key) + +module Balance : S_JSON with type t = Currency.Balance.t = struct + type t = Currency.Balance.t + + let parse = Decoders.balance + + let serialize = unimplemented_serializer "balance" +end + +module Token : S_JSON with type t = Mina_base.Token_id.t = struct + type t = Mina_base.Token_id.t + + let parse = Decoders.token + + let serialize = Encoders.token +end + +module Amount : S_JSON with type t = Currency.Amount.t = struct + type t = Currency.Amount.t + + let parse = Decoders.amount + + let serialize = Encoders.amount +end + +module Fee : S_JSON with type t = Currency.Fee.t = struct + type t = Currency.Fee.t + + let parse = Decoders.fee + + let serialize = Encoders.fee +end + +module Memo : S_STRING with type t = Mina_base.Signed_command_memo.t = struct + type t = Mina_base.Signed_command_memo.t + + let parse = Mina_base.Signed_command_memo.of_base58_check_exn + + let serialize = Mina_base.Signed_command_memo.to_base58_check +end