Skip to content

Commit

Permalink
Merge branch 'develop' into rosetta/db-connection-pooling
Browse files Browse the repository at this point in the history
  • Loading branch information
bkase authored Aug 31, 2020
2 parents 1030bcb + 10b9db8 commit bbbc6cc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
53 changes: 40 additions & 13 deletions src/app/cli/src/init/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,52 @@ let get_balance_graphql =
~doc:"KEY Public key for which you want to check the balance"
(required Cli_lib.Arg_type.public_key_compressed)
in
let token_flag =
flag "token" ~doc:"TOKEN_ID The token ID for the account"
(optional_with_default Token_id.default Cli_lib.Arg_type.token_id)
in
Command.async ~summary:"Get balance associated with a public key"
(Cli_lib.Background_daemon.graphql_init pk_flag
~f:(fun graphql_endpoint public_key ->
(Cli_lib.Background_daemon.graphql_init (Args.zip2 pk_flag token_flag)
~f:(fun graphql_endpoint (public_key, token) ->
let%map response =
Graphql_client.query_exn
(Graphql_queries.Get_tracked_account.make
~public_key:(Graphql_client.Encoders.public_key public_key)
~token:(Graphql_client.Encoders.token token)
())
graphql_endpoint
in
match response#account with
| Some account ->
printf "Balance: %s coda\n"
(Currency.Balance.to_formatted_string (account#balance)#total)
if Token_id.(equal default) token then
printf "Balance: %s coda\n"
(Currency.Balance.to_formatted_string (account#balance)#total)
else
printf "Balance: %s tokens\n"
(Currency.Balance.to_formatted_string (account#balance)#total)
| None ->
printf "There are no funds in this account\n" ))

let get_tokens_graphql =
let open Command.Param in
let pk_flag =
flag "public-key" ~doc:"KEY Public key for which you want to find accounts"
(required Cli_lib.Arg_type.public_key_compressed)
in
Command.async ~summary:"Get all token IDs that a public key has accounts for"
(Cli_lib.Background_daemon.graphql_init pk_flag
~f:(fun graphql_endpoint public_key ->
let%map response =
Graphql_client.query_exn
(Graphql_queries.Get_all_accounts.make
~public_key:(Graphql_client.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) ) ))

let print_trust_status status json =
if json then
printf "%s\n"
Expand Down Expand Up @@ -234,9 +263,8 @@ let generate_receipt =
(required public_key_compressed)
in
let token_flag =
(*flag "token" ~doc:"TOKEN_ID The token ID for the account"
(optional_with_default Token_id.default Cli_lib.Arg_type.token_id)*)
Command.Param.return Token_id.default
flag "token" ~doc:"TOKEN_ID The token ID for the account"
(optional_with_default Token_id.default Cli_lib.Arg_type.token_id)
in
Command.async ~summary:"Generate a receipt for a sent payment"
(Cli_lib.Background_daemon.rpc_init
Expand Down Expand Up @@ -281,9 +309,8 @@ let verify_receipt =
(required public_key_compressed)
in
let token_flag =
(*flag "token" ~doc:"TOKEN_ID The token ID for the account"
(optional_with_default Token_id.default Cli_lib.Arg_type.token_id)*)
Command.Param.return Token_id.default
flag "token" ~doc:"TOKEN_ID The token ID for the account"
(optional_with_default Token_id.default Cli_lib.Arg_type.token_id)
in
Command.async ~summary:"Verify a receipt of a sent payment"
(Cli_lib.Background_daemon.rpc_init
Expand Down Expand Up @@ -349,9 +376,8 @@ let get_nonce_cmd =
(required Cli_lib.Arg_type.public_key_compressed)
in
let token_flag =
(*flag "token" ~doc:"TOKEN_ID The token ID for the account"
(optional_with_default Token_id.default Cli_lib.Arg_type.token_id)*)
Command.Param.return Token_id.default
flag "token" ~doc:"TOKEN_ID The token ID for the account"
(optional_with_default Token_id.default Cli_lib.Arg_type.token_id)
in
let flags = Args.zip2 address_flag token_flag in
Command.async ~summary:"Get the current nonce for an account"
Expand Down Expand Up @@ -1569,6 +1595,7 @@ let client =
Command.group ~summary:"Lightweight client commands"
~preserve_subcommand_order:()
[ ("get-balance", get_balance_graphql)
; ("get-tokens", get_tokens_graphql)
; ("send-payment", send_payment_graphql)
; ("delegate-stake", delegate_stake_graphql)
; ("create-token", create_new_token_graphql)
Expand Down
15 changes: 12 additions & 3 deletions src/app/cli/src/init/graphql_queries.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,25 @@ query {
module Get_tracked_account =
[%graphql
{|
query ($public_key: PublicKey) {
account(publicKey: $public_key) {
public_key: publicKey @bsDecoder(fn: "Decoders.public_key")
query ($public_key: PublicKey, $token: UInt64) {
account(publicKey: $public_key, token: $token) {
balance {
total @bsDecoder(fn: "Decoders.balance")
}
}
}
|}]

module Get_all_accounts =
[%graphql
{|
query ($public_key: PublicKey) {
accounts(publicKey: $public_key) {
token @bsDecoder(fn: "Decoders.token")
}
}
|}]

module Create_account =
[%graphql
{|
Expand Down
6 changes: 2 additions & 4 deletions src/app/rosetta/test-agent/signer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ let sign ~(keys : Keys.t) ~unsigned_transaction_string =
let signature =
Schnorr.sign keys.keypair.private_key
unsigned_transaction.random_oracle_input
|> Signature.Raw.encode
in
let signature' =
User_command.sign_payload keys.keypair.private_key user_command_payload
|> Signature.Raw.encode
in
[%test_eq: string] signature signature' ;
signature
[%test_eq: Signature.t] signature signature' ;
signature |> Signature.Raw.encode

0 comments on commit bbbc6cc

Please sign in to comment.