Client: cosmetic or minor improvements
This commit is contained in:
parent
f8d8c4d6e9
commit
8016f83903
@ -174,6 +174,11 @@ test:inject.sh:
|
|||||||
script:
|
script:
|
||||||
- dune build @src/bin_client/runtest_injection.sh
|
- 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:proto:sandbox:
|
||||||
<<: *test_definition
|
<<: *test_definition
|
||||||
script:
|
script:
|
||||||
|
@ -145,6 +145,7 @@
|
|||||||
(locks /tcp-port/18731
|
(locks /tcp-port/18731
|
||||||
/tcp-port/19731)
|
/tcp-port/19731)
|
||||||
(deps sandbox.json
|
(deps sandbox.json
|
||||||
|
protocol_parameters.json
|
||||||
test_lib.inc.sh
|
test_lib.inc.sh
|
||||||
(glob_files demo/*))
|
(glob_files demo/*))
|
||||||
(action
|
(action
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
"time_between_blocks" : [ "1", "0" ],
|
"time_between_blocks" : [ "1", "0" ],
|
||||||
"blocks_per_cycle" : 128,
|
"blocks_per_cycle" : 128,
|
||||||
"blocks_per_roll_snapshot" : 32,
|
"blocks_per_roll_snapshot" : 32,
|
||||||
"blocks_per_voting_period" : 64,
|
"blocks_per_voting_period" : 256,
|
||||||
"preserved_cycles" : 1,
|
"preserved_cycles" : 1,
|
||||||
"proof_of_work_threshold": "-1"
|
"proof_of_work_threshold": "-1"
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ cp -r demo $tempdir/proto3
|
|||||||
echo '(* 3 *)' >> $tempdir/proto3/main.ml
|
echo '(* 3 *)' >> $tempdir/proto3/main.ml
|
||||||
$admin_client inject protocol $tempdir/proto3
|
$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
|
echo New protocols: $proto_str
|
||||||
proto=($proto_str)
|
proto=($proto_str)
|
||||||
|
|
||||||
|
@ -438,7 +438,7 @@ type vote_info = {
|
|||||||
let ballot_list_encoding =
|
let ballot_list_encoding =
|
||||||
Data_encoding.(list (obj2
|
Data_encoding.(list (obj2
|
||||||
(req "pkh" Signature.Public_key_hash.encoding)
|
(req "pkh" Signature.Public_key_hash.encoding)
|
||||||
(req "balllot" Vote.ballot_encoding)))
|
(req "ballot" Vote.ballot_encoding)))
|
||||||
|
|
||||||
let vote_info_encoding =
|
let vote_info_encoding =
|
||||||
let open Data_encoding in
|
let open Data_encoding in
|
||||||
|
@ -396,12 +396,12 @@ let rec pp_contents_and_result_list :
|
|||||||
From: %a@,\
|
From: %a@,\
|
||||||
Period: %a@,\
|
Period: %a@,\
|
||||||
Protocol: %a@,\
|
Protocol: %a@,\
|
||||||
Vote: %s@]"
|
Vote: %a@]"
|
||||||
Signature.Public_key_hash.pp source
|
Signature.Public_key_hash.pp source
|
||||||
Voting_period.pp period
|
Voting_period.pp period
|
||||||
Protocol_hash.pp proposal
|
Protocol_hash.pp proposal
|
||||||
(* FIXME We should use ballot_encoding? *)
|
Data_encoding.Json.pp
|
||||||
(match ballot with Yay -> "YAY" | Pass -> "PASS" | Nay -> "NAY")
|
(Data_encoding.Json.construct Vote.ballot_encoding ballot)
|
||||||
| Single_and_result (Manager_operation _ as op,
|
| Single_and_result (Manager_operation _ as op,
|
||||||
(Manager_operation_result _ as res))->
|
(Manager_operation_result _ as res))->
|
||||||
Format.fprintf ppf "%a"
|
Format.fprintf ppf "%a"
|
||||||
|
@ -645,49 +645,44 @@ let commands version () =
|
|||||||
|
|
||||||
command ~group ~desc: "Submit protocol proposals."
|
command ~group ~desc: "Submit protocol proposals."
|
||||||
no_options
|
no_options
|
||||||
(prefixes [ "submit" ; "proposals" ]
|
(prefixes [ "submit" ; "proposals" ; "for" ]
|
||||||
@@ prefix "for"
|
|
||||||
@@ ContractAlias.destination_param
|
@@ ContractAlias.destination_param
|
||||||
~name: "src" ~desc: "name of the source contract"
|
~name: "src" ~desc: "name of the source contract"
|
||||||
@@ seq_of_param (param
|
@@ seq_of_param
|
||||||
|
(param
|
||||||
~name:"proposal"
|
~name:"proposal"
|
||||||
~desc:"Proposal to be submitted"
|
~desc:"Proposal to be submitted"
|
||||||
(parameter
|
(parameter
|
||||||
(fun _ x ->
|
(fun _ x ->
|
||||||
match Protocol_hash.of_b58check_opt x with
|
match Protocol_hash.of_b58check_opt x with
|
||||||
| None -> Error_monad.failwith "Invalid proposal hash: '%s'" x
|
| None -> Error_monad.failwith "Invalid proposal hash: '%s'" x
|
||||||
| Some hash -> return hash)))
|
| Some hash -> return hash))))
|
||||||
)
|
begin fun () (_name, source) proposals (cctxt : Proto_alpha.full) ->
|
||||||
(fun () (_name, source) proposals cctxt ->
|
|
||||||
Shell_services.Protocol.list cctxt >>=? fun known_protos ->
|
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
|
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
|
else if n > Constants.fixed.max_proposals_per_delegate then
|
||||||
generic_error "Too many proposals"
|
cctxt#error "Too many proposals"
|
||||||
else
|
else
|
||||||
(* Why we do not have Error_monad.iter ? *)
|
iter_s (fun p ->
|
||||||
let rec iter f = function
|
if List.mem p known_protos then
|
||||||
| [] -> ok ()
|
cctxt#message "All proposals are valid" >>= fun () -> return_unit
|
||||||
| p::ps -> f p >>? fun () -> iter f ps
|
else cctxt#error "Protocol %a is not known by the node"
|
||||||
in
|
Protocol_hash.pp p)
|
||||||
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)
|
|
||||||
proposals
|
proposals
|
||||||
in
|
in
|
||||||
Lwt.return (check_proposals proposals) >>=? fun () ->
|
check_proposals proposals >>=? fun () ->
|
||||||
Client_proto_context.get_manager
|
Client_proto_context.get_manager
|
||||||
cctxt ~chain:`Main ~block:cctxt#block
|
cctxt ~chain:`Main ~block:cctxt#block
|
||||||
source >>=? fun (_src_name, src_pkh, _src_pk, src_sk) ->
|
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 ->
|
submit_proposals cctxt ~chain:`Main ~block:cctxt#block ~src_sk src_pkh proposals >>=? fun _res ->
|
||||||
return_unit
|
return_unit
|
||||||
);
|
end ;
|
||||||
|
|
||||||
command ~group ~desc: "Submit a ballot."
|
command ~group ~desc: "Submit a ballot."
|
||||||
no_options
|
no_options
|
||||||
(prefixes [ "submit" ; "ballot" ]
|
(prefixes [ "submit" ; "ballot" ; "for" ]
|
||||||
@@ prefix "for"
|
|
||||||
@@ ContractAlias.destination_param
|
@@ ContractAlias.destination_param
|
||||||
~name: "src" ~desc: "name of the source contract"
|
~name: "src" ~desc: "name of the source contract"
|
||||||
@@ param
|
@@ param
|
||||||
@ -696,36 +691,38 @@ let commands version () =
|
|||||||
(parameter
|
(parameter
|
||||||
(fun _ x ->
|
(fun _ x ->
|
||||||
match Protocol_hash.of_b58check_opt x with
|
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))
|
| Some hash -> return hash))
|
||||||
@@ param
|
@@ param
|
||||||
~name:"ballot"
|
~name:"ballot"
|
||||||
~desc:"Ballot(yay/nay/pass)"
|
~desc:"Ballot(yay/nay/pass)"
|
||||||
(parameter
|
(parameter
|
||||||
(fun _ s ->
|
(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
|
match Data_encoding.Json.from_string ("\"" ^ s ^ "\"") with
|
||||||
| Error _ -> fail ()
|
| Error _ -> fail ()
|
||||||
| Ok j ->
|
| Ok j ->
|
||||||
match Data_encoding.Json.destruct Vote.ballot_encoding j with
|
match Data_encoding.Json.destruct Vote.ballot_encoding j with
|
||||||
| exception _ -> fail ()
|
| exception _ -> fail ()
|
||||||
| b -> return b))
|
| b -> return b))
|
||||||
@@ stop
|
@@ stop)
|
||||||
)
|
begin fun () (_name, source) proposal ballot (cctxt : Proto_alpha.full) ->
|
||||||
(fun () (_name, source) proposal ballot cctxt ->
|
|
||||||
Client_proto_context.get_manager
|
Client_proto_context.get_manager
|
||||||
cctxt ~chain:`Main ~block:cctxt#block
|
cctxt ~chain:`Main ~block:cctxt#block
|
||||||
source >>=? fun (_src_name, src_pkh, _src_pk, src_sk) ->
|
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
|
return_unit
|
||||||
);
|
end ;
|
||||||
|
|
||||||
command ~group ~desc: "Summarize the current voting information."
|
command ~group ~desc: "Summarize the current voting information."
|
||||||
no_options
|
no_options
|
||||||
(fixed [ "show" ; "votes" ])
|
(fixed [ "show" ; "votes" ])
|
||||||
(fun () cctxt ->
|
begin fun () (cctxt : Proto_alpha.full) ->
|
||||||
get_vote_info ~chain:`Main ~block:cctxt#block cctxt >>=? fun vote_info ->
|
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
|
return_unit
|
||||||
)
|
end ;
|
||||||
|
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user