Add: tezos-client set delegate ...
This commit is contained in:
parent
3b3428ddad
commit
81b720fee0
@ -26,11 +26,11 @@ wait_for_the_node_to_be_bootstraped() {
|
||||
## Account #################################################################
|
||||
|
||||
may_create_identity() {
|
||||
if ! $client get balance "my_identity" >/dev/null 2>&1 ; then
|
||||
if ! $client get balance for "my_identity" >/dev/null 2>&1 ; then
|
||||
echo "Generating new manager key (known as 'my_identity')..."
|
||||
$client gen keys "my_identity"
|
||||
fi
|
||||
if ! $client get balance "my_account" >/dev/null 2>&1 ; then
|
||||
if ! $client get balance for "my_account" >/dev/null 2>&1 ; then
|
||||
echo "Creating new account for 'my_identity' (known as 'my_account')..."
|
||||
$client forget contract "my_account" >/dev/null 2>&1 || true
|
||||
$client originate free account "my_account" for "my_identity"
|
||||
|
@ -117,21 +117,13 @@ let delegate_contract rpc_config
|
||||
Client_proto_rpcs.Helpers.Forge.Manager.delegation rpc_config block
|
||||
~net ~source ?sourcePubKey:src_pk ~counter ~fee delegate_opt
|
||||
>>=? fun bytes ->
|
||||
Client_node_rpcs.Blocks.predecessor rpc_config block >>=? fun predecessor ->
|
||||
let signature = Environment.Ed25519.sign manager_sk bytes in
|
||||
let signed_bytes = MBytes.concat bytes signature in
|
||||
let oph = Operation_hash.hash_bytes [ signed_bytes ] in
|
||||
Client_proto_rpcs.Helpers.apply_operation rpc_config block
|
||||
predecessor oph bytes (Some signature) >>=? function
|
||||
| [] ->
|
||||
Client_node_rpcs.inject_operation
|
||||
rpc_config ?force signed_bytes >>=? fun injected_oph ->
|
||||
assert (Operation_hash.equal oph injected_oph) ;
|
||||
return oph
|
||||
| contracts ->
|
||||
failwith
|
||||
"The origination introduced %d contracts instead of one."
|
||||
(List.length contracts)
|
||||
Client_node_rpcs.inject_operation
|
||||
rpc_config ?force signed_bytes >>=? fun injected_oph ->
|
||||
assert (Operation_hash.equal oph injected_oph) ;
|
||||
return oph
|
||||
|
||||
let dictate rpc_config block command seckey =
|
||||
Client_node_rpcs.Blocks.net rpc_config block >>=? fun net ->
|
||||
@ -214,6 +206,18 @@ let group =
|
||||
{ Cli_entries.name = "context" ;
|
||||
title = "Block contextual commands (see option -block)" }
|
||||
|
||||
let dictate rpc_config block command seckey =
|
||||
Client_node_rpcs.Blocks.net rpc_config block >>=? fun net ->
|
||||
Client_proto_rpcs.Helpers.Forge.Dictator.operation
|
||||
rpc_config block ~net command >>=? fun bytes ->
|
||||
let signature = Ed25519.sign seckey bytes in
|
||||
let signed_bytes = MBytes.concat bytes signature in
|
||||
let oph = Operation_hash.hash_bytes [ signed_bytes ] in
|
||||
Client_node_rpcs.inject_operation
|
||||
rpc_config signed_bytes >>=? fun injected_oph ->
|
||||
assert (Operation_hash.equal oph injected_oph) ;
|
||||
return oph
|
||||
|
||||
let commands () =
|
||||
let open Cli_entries in
|
||||
let open Client_commands in
|
||||
@ -239,7 +243,7 @@ let commands () =
|
||||
end ;
|
||||
|
||||
command ~group ~desc: "get the balance of a contract" begin
|
||||
prefixes [ "get" ; "balance" ]
|
||||
prefixes [ "get" ; "balance" ; "for" ]
|
||||
@@ ContractAlias.destination_param ~name:"src" ~desc:"source contract"
|
||||
@@ stop
|
||||
end begin fun (_, contract) cctxt ->
|
||||
@ -248,12 +252,12 @@ let commands () =
|
||||
return ()
|
||||
end ;
|
||||
|
||||
command ~group ~desc: "get the manager of a block" begin
|
||||
prefixes [ "get" ; "manager" ]
|
||||
command ~group ~desc: "get the manager of a contract" begin
|
||||
prefixes [ "get" ; "manager" ; "for" ]
|
||||
@@ ContractAlias.destination_param ~name:"src" ~desc:"source contract"
|
||||
@@ stop
|
||||
end begin fun (_, contract) cctxt ->
|
||||
Client_proto_rpcs.Context.Contract.manager
|
||||
Client_proto_contracts.get_manager
|
||||
cctxt.rpc_config cctxt.config.block contract >>=? fun manager ->
|
||||
Public_key_hash.rev_find cctxt manager >>=? fun mn ->
|
||||
Public_key_hash.to_source cctxt manager >>=? fun m ->
|
||||
@ -262,6 +266,38 @@ let commands () =
|
||||
return ()
|
||||
end ;
|
||||
|
||||
command ~group ~desc: "get the delegate of a contract" begin
|
||||
prefixes [ "get" ; "delegate" ; "for" ]
|
||||
@@ ContractAlias.destination_param ~name:"src" ~desc:"source contract"
|
||||
@@ stop
|
||||
end begin fun (_, contract) cctxt ->
|
||||
Client_proto_contracts.get_delegate
|
||||
cctxt.rpc_config cctxt.config.block contract >>=? fun delegate ->
|
||||
Public_key_hash.rev_find cctxt delegate >>=? fun mn ->
|
||||
Public_key_hash.to_source cctxt delegate >>=? fun m ->
|
||||
cctxt.message "%s (%s)" m
|
||||
(match mn with None -> "unknown" | Some n -> "known as " ^ n) >>= fun () ->
|
||||
return ()
|
||||
end ;
|
||||
|
||||
command ~group ~desc: "set the delegate of a contract"
|
||||
~args: ([ fee_arg ; force_arg ]) begin
|
||||
prefixes [ "set" ; "delegate" ; "for" ]
|
||||
@@ ContractAlias.destination_param ~name:"src" ~desc:"source contract"
|
||||
@@ prefix "to"
|
||||
@@ Public_key_hash.alias_param
|
||||
~name: "mgr" ~desc: "new delegate of the contract"
|
||||
@@ stop
|
||||
end begin fun (_, contract) (_, delegate) cctxt ->
|
||||
get_manager cctxt contract >>=? fun (_src_name, _src_pkh, src_pk, src_sk) ->
|
||||
delegate_contract
|
||||
cctxt.rpc_config cctxt.config.block ~source:contract
|
||||
~src_pk ~manager_sk:src_sk ~fee:!fee (Some delegate)
|
||||
>>=? fun oph ->
|
||||
message_injection cctxt ~force:!force oph >>= fun () ->
|
||||
return ()
|
||||
end ;
|
||||
|
||||
command ~group ~desc: "open a new account"
|
||||
~args: ([ fee_arg ; delegate_arg ; force_arg ]
|
||||
@ delegatable_args @ spendable_args) begin
|
||||
|
@ -361,15 +361,15 @@ let mining_rights_for_delegate
|
||||
ctxt contract (max_priority, min_level, max_level) =
|
||||
let max_priority = default_max_mining_priority ctxt max_priority in
|
||||
let current_level = Level.current ctxt in
|
||||
let max_level =
|
||||
match max_level with
|
||||
| None ->
|
||||
Level.last_level_in_cycle ctxt @@
|
||||
Cycle.succ current_level.cycle
|
||||
| Some l -> Level.from_raw ctxt l in
|
||||
let min_level = match min_level with
|
||||
| None -> current_level
|
||||
| Some l -> Level.from_raw ctxt l in
|
||||
let max_level =
|
||||
match max_level with
|
||||
| Some max_level -> Level.from_raw ctxt max_level
|
||||
| None ->
|
||||
Level.last_level_in_cycle ctxt @@
|
||||
current_level.cycle in
|
||||
let rec loop level =
|
||||
if Level.(>) level max_level
|
||||
then return []
|
||||
@ -427,15 +427,13 @@ let endorsement_rights_for_delegate
|
||||
ctxt contract (max_priority, min_level, max_level) =
|
||||
let current_level = Level.current ctxt in
|
||||
let max_priority = default_max_endorsement_priority ctxt max_priority in
|
||||
let max_level =
|
||||
match max_level with
|
||||
| None ->
|
||||
Level.last_level_in_cycle ctxt @@
|
||||
Cycle.succ (Cycle.succ current_level.cycle)
|
||||
| Some l -> Level.from_raw ctxt l in
|
||||
let min_level = match min_level with
|
||||
| None -> Level.succ ctxt current_level
|
||||
| Some l -> Level.from_raw ctxt l in
|
||||
let max_level =
|
||||
match max_level with
|
||||
| None -> min_level
|
||||
| Some l -> Level.from_raw ctxt l in
|
||||
let rec loop level =
|
||||
if Level.(>) level max_level
|
||||
then return []
|
||||
|
@ -68,13 +68,13 @@ assert() {
|
||||
fi
|
||||
}
|
||||
|
||||
${CLIENT} get balance ${KEY1} | assert "1,000.00 ꜩ"
|
||||
${CLIENT} get balance ${KEY2} | assert "2,000.00 ꜩ"
|
||||
${CLIENT} get balance for ${KEY1} | assert "1,000.00 ꜩ"
|
||||
${CLIENT} get balance for ${KEY2} | assert "2,000.00 ꜩ"
|
||||
|
||||
${CLIENT} transfer 1000 from ${KEY2} to ${KEY1}
|
||||
|
||||
${CLIENT} get balance ${KEY1} | assert "2,000.00 ꜩ"
|
||||
${CLIENT} get balance ${KEY2} | assert "999.95 ꜩ"
|
||||
${CLIENT} get balance for ${KEY1} | assert "2,000.00 ꜩ"
|
||||
${CLIENT} get balance for ${KEY2} | assert "999.95 ꜩ"
|
||||
|
||||
# Should fail
|
||||
# ${CLIENT} transfer 999.95 from ${KEY2} to ${KEY1}
|
||||
@ -95,6 +95,11 @@ ${CLIENT} transfer 10 from bootstrap1 to hardlimit -arg "Unit"
|
||||
${CLIENT} transfer 10 from bootstrap1 to hardlimit -arg "Unit"
|
||||
# ${CLIENT} transfer 10 from bootstrap1 to hardlimit -arg "unit" # should fail
|
||||
|
||||
${CLIENT} originate free account free_account for ${KEY1}
|
||||
${CLIENT} get delegate for free_account
|
||||
${CLIENT} set delegate for free_account to ${KEY2}
|
||||
${CLIENT} get delegate for free_account
|
||||
|
||||
echo
|
||||
echo End of test
|
||||
echo
|
||||
|
Loading…
Reference in New Issue
Block a user