Client: cosmetic or minor improvements

This commit is contained in:
Marco Stronati 2018-12-10 13:46:37 +01:00
parent f8d8c4d6e9
commit 8016f83903
8 changed files with 90 additions and 87 deletions

View File

@ -174,6 +174,11 @@ test:inject.sh:
script:
- dune build @src/bin_client/runtest_injection.sh
test:voting.sh:
<<: *test_definition
script:
- dune build @src/bin_client/runtest_voting.sh
test:proto:sandbox:
<<: *test_definition
script:

View File

@ -145,6 +145,7 @@
(locks /tcp-port/18731
/tcp-port/19731)
(deps sandbox.json
protocol_parameters.json
test_lib.inc.sh
(glob_files demo/*))
(action

View File

@ -21,7 +21,7 @@
"time_between_blocks" : [ "1", "0" ],
"blocks_per_cycle" : 128,
"blocks_per_roll_snapshot" : 32,
"blocks_per_voting_period" : 64,
"blocks_per_voting_period" : 256,
"preserved_cycles" : 1,
"proof_of_work_threshold": "-1"
}

View File

@ -66,7 +66,7 @@ cp -r demo $tempdir/proto3
echo '(* 3 *)' >> $tempdir/proto3/main.ml
$admin_client inject protocol $tempdir/proto3
proto_str=`$admin_client list protocols | head -3` # assuming new protocols listed first
proto_str=`$admin_client list protocols | grep "P" | head -3` # assuming new protocols listed first
echo New protocols: $proto_str
proto=($proto_str)

View File

@ -438,7 +438,7 @@ type vote_info = {
let ballot_list_encoding =
Data_encoding.(list (obj2
(req "pkh" Signature.Public_key_hash.encoding)
(req "balllot" Vote.ballot_encoding)))
(req "ballot" Vote.ballot_encoding)))
let vote_info_encoding =
let open Data_encoding in

View File

@ -396,12 +396,12 @@ let rec pp_contents_and_result_list :
From: %a@,\
Period: %a@,\
Protocol: %a@,\
Vote: %s@]"
Vote: %a@]"
Signature.Public_key_hash.pp source
Voting_period.pp period
Protocol_hash.pp proposal
(* FIXME We should use ballot_encoding? *)
(match ballot with Yay -> "YAY" | Pass -> "PASS" | Nay -> "NAY")
Data_encoding.Json.pp
(Data_encoding.Json.construct Vote.ballot_encoding ballot)
| Single_and_result (Manager_operation _ as op,
(Manager_operation_result _ as res))->
Format.fprintf ppf "%a"

View File

@ -645,49 +645,44 @@ let commands version () =
command ~group ~desc: "Submit protocol proposals."
no_options
(prefixes [ "submit" ; "proposals" ]
@@ prefix "for"
(prefixes [ "submit" ; "proposals" ; "for" ]
@@ ContractAlias.destination_param
~name: "src" ~desc: "name of the source contract"
@@ seq_of_param (param
@@ seq_of_param
(param
~name:"proposal"
~desc:"Proposal to be submitted"
(parameter
(fun _ x ->
match Protocol_hash.of_b58check_opt x with
| None -> Error_monad.failwith "Invalid proposal hash: '%s'" x
| Some hash -> return hash)))
)
(fun () (_name, source) proposals cctxt ->
| Some hash -> return hash))))
begin fun () (_name, source) proposals (cctxt : Proto_alpha.full) ->
Shell_services.Protocol.list cctxt >>=? fun known_protos ->
let check_proposals proposals =
let check_proposals proposals : unit tzresult Lwt.t =
let n = List.length proposals in
if n = 0 then generic_error "Empty proposal"
if n = 0 then cctxt#error "Empty proposal"
else if n > Constants.fixed.max_proposals_per_delegate then
generic_error "Too many proposals"
cctxt#error "Too many proposals"
else
(* Why we do not have Error_monad.iter ? *)
let rec iter f = function
| [] -> ok ()
| p::ps -> f p >>? fun () -> iter f ps
in
iter (fun p ->
if List.mem p known_protos then ok ()
else generic_error "Protocol %a is not injected in the node" Protocol_hash.pp p)
iter_s (fun p ->
if List.mem p known_protos then
cctxt#message "All proposals are valid" >>= fun () -> return_unit
else cctxt#error "Protocol %a is not known by the node"
Protocol_hash.pp p)
proposals
in
Lwt.return (check_proposals proposals) >>=? fun () ->
check_proposals proposals >>=? fun () ->
Client_proto_context.get_manager
cctxt ~chain:`Main ~block:cctxt#block
source >>=? fun (_src_name, src_pkh, _src_pk, src_sk) ->
submit_proposals cctxt ~chain:`Main ~block:cctxt#block ~src_sk src_pkh proposals >>=? fun _res ->
return_unit
);
end ;
command ~group ~desc: "Submit a ballot."
no_options
(prefixes [ "submit" ; "ballot" ]
@@ prefix "for"
(prefixes [ "submit" ; "ballot" ; "for" ]
@@ ContractAlias.destination_param
~name: "src" ~desc: "name of the source contract"
@@ param
@ -696,36 +691,38 @@ let commands version () =
(parameter
(fun _ x ->
match Protocol_hash.of_b58check_opt x with
| None -> Error_monad.failwith "Invalid proposal hash: '%s'" x
| None -> failwith "Invalid proposal hash: '%s'" x
| Some hash -> return hash))
@@ param
~name:"ballot"
~desc:"Ballot(yay/nay/pass)"
(parameter
(fun _ s ->
let fail () = Error_monad.failwith "Invalid ballot: '%s'" s in
let fail () = failwith "Invalid ballot: '%s'" s in
match Data_encoding.Json.from_string ("\"" ^ s ^ "\"") with
| Error _ -> fail ()
| Ok j ->
match Data_encoding.Json.destruct Vote.ballot_encoding j with
| exception _ -> fail ()
| b -> return b))
@@ stop
)
(fun () (_name, source) proposal ballot cctxt ->
@@ stop)
begin fun () (_name, source) proposal ballot (cctxt : Proto_alpha.full) ->
Client_proto_context.get_manager
cctxt ~chain:`Main ~block:cctxt#block
source >>=? fun (_src_name, src_pkh, _src_pk, src_sk) ->
submit_ballot cctxt ~chain:`Main ~block:cctxt#block ~src_sk src_pkh proposal ballot >>=? fun _res ->
submit_ballot cctxt ~chain:`Main ~block:cctxt#block ~src_sk src_pkh
proposal ballot >>=? fun _res ->
return_unit
);
end ;
command ~group ~desc: "Summarize the current voting information."
no_options
(fixed [ "show" ; "votes" ])
(fun () cctxt ->
begin fun () (cctxt : Proto_alpha.full) ->
get_vote_info ~chain:`Main ~block:cctxt#block cctxt >>=? fun vote_info ->
cctxt#message "%a" (Json_repr.pp_any ()) (Json_repr.(to_any (Data_encoding.Json.construct vote_info_encoding vote_info))) >>= fun () ->
cctxt#message "%a" Data_encoding.Json.pp
(Data_encoding.Json.construct vote_info_encoding vote_info) >>= fun () ->
return_unit
)
end ;
]