2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2016. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
open Client_proto_args
|
|
|
|
open Client_proto_contracts
|
|
|
|
open Client_proto_programs
|
|
|
|
open Client_keys
|
2017-04-05 01:35:41 +04:00
|
|
|
open Client_commands
|
2016-11-14 18:55:24 +04:00
|
|
|
module Ed25519 = Environment.Ed25519
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let check_contract cctxt neu =
|
2017-04-05 03:02:10 +04:00
|
|
|
RawContractAlias.mem cctxt neu >>=? function
|
2016-09-08 21:13:10 +04:00
|
|
|
| true ->
|
2017-04-05 03:02:10 +04:00
|
|
|
failwith "contract '%s' already exists" neu
|
2016-09-08 21:13:10 +04:00
|
|
|
| false ->
|
2017-04-05 03:02:10 +04:00
|
|
|
return ()
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let get_delegate_pkh cctxt = function
|
2017-04-05 03:02:10 +04:00
|
|
|
| None ->
|
|
|
|
return None
|
2016-09-08 21:13:10 +04:00
|
|
|
| Some delegate ->
|
2017-04-05 03:02:10 +04:00
|
|
|
Public_key_hash.find_opt cctxt delegate
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let get_timestamp cctxt block =
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.Blocks.timestamp cctxt.rpc_config block >>=? fun v ->
|
|
|
|
cctxt.message "%s" (Time.to_notation v) >>= fun () ->
|
|
|
|
return ()
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let list_contracts cctxt block =
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_proto_rpcs.Context.Contract.list cctxt.rpc_config block >>=? fun contracts ->
|
2017-03-15 04:20:25 +04:00
|
|
|
map_s (fun h ->
|
|
|
|
begin match Contract.is_default h with
|
|
|
|
| Some m -> begin
|
2017-04-05 03:02:10 +04:00
|
|
|
Public_key_hash.rev_find cctxt m >>=? function
|
|
|
|
| None -> return ""
|
|
|
|
| Some nm -> return nm
|
2017-03-15 04:20:25 +04:00
|
|
|
end
|
|
|
|
| None -> begin
|
2017-04-05 03:02:10 +04:00
|
|
|
RawContractAlias.rev_find cctxt h >>=? function
|
|
|
|
| None -> return ""
|
|
|
|
| Some nm -> return nm
|
2017-03-15 04:20:25 +04:00
|
|
|
end
|
2017-04-05 03:02:10 +04:00
|
|
|
end >>=? fun alias ->
|
2017-03-15 04:20:25 +04:00
|
|
|
return (alias, h, Contract.is_default h))
|
|
|
|
contracts
|
|
|
|
|
|
|
|
let list_contract_labels cctxt block =
|
2017-04-05 03:02:10 +04:00
|
|
|
Client_proto_rpcs.Context.Contract.list
|
|
|
|
cctxt.rpc_config block >>=? fun contracts ->
|
2017-03-15 04:20:25 +04:00
|
|
|
map_s (fun h ->
|
2016-09-08 21:13:10 +04:00
|
|
|
begin match Contract.is_default h with
|
|
|
|
| Some m -> begin
|
2017-04-05 03:02:10 +04:00
|
|
|
Public_key_hash.rev_find cctxt m >>=? function
|
|
|
|
| None -> return ""
|
2016-09-08 21:13:10 +04:00
|
|
|
| Some nm ->
|
2017-04-05 03:02:10 +04:00
|
|
|
RawContractAlias.find_opt cctxt nm >>=? function
|
|
|
|
| None -> return (" (known as " ^ nm ^ ")")
|
|
|
|
| Some _ -> return (" (known as key:" ^ nm ^ ")")
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
| None -> begin
|
2017-04-05 03:02:10 +04:00
|
|
|
RawContractAlias.rev_find cctxt h >>=? function
|
|
|
|
| None -> return ""
|
|
|
|
| Some nm -> return (" (known as " ^ nm ^ ")")
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
2017-04-05 03:02:10 +04:00
|
|
|
end >>=? fun nm ->
|
2016-09-08 21:13:10 +04:00
|
|
|
let kind = match Contract.is_default h with
|
|
|
|
| Some _ -> " (default)"
|
|
|
|
| None -> "" in
|
2017-03-15 04:20:25 +04:00
|
|
|
let h_b58 = Contract.to_b58check h in
|
|
|
|
return (nm, h_b58, kind))
|
2016-09-08 21:13:10 +04:00
|
|
|
contracts
|
|
|
|
|
2017-03-15 04:20:25 +04:00
|
|
|
let get_balance cctxt block contract =
|
|
|
|
Client_proto_rpcs.Context.Contract.balance cctxt block contract
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let transfer cctxt
|
|
|
|
block ?force
|
2016-09-08 21:13:10 +04:00
|
|
|
~source ~src_pk ~src_sk ~destination ?arg ~amount ~fee () =
|
|
|
|
let open Cli_entries in
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.Blocks.net cctxt.rpc_config block >>=? fun net ->
|
2016-09-08 21:13:10 +04:00
|
|
|
begin match arg with
|
|
|
|
| Some arg ->
|
2017-04-05 12:22:41 +04:00
|
|
|
Client_proto_programs.parse_data arg >>=? fun arg ->
|
|
|
|
return (Some arg)
|
|
|
|
| None -> return None
|
|
|
|
end >>=? fun parameters ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_proto_rpcs.Context.Contract.counter cctxt.rpc_config block source >>=? fun pcounter ->
|
2016-09-08 21:13:10 +04:00
|
|
|
let counter = Int32.succ pcounter in
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.message "Acquired the source's sequence counter (%ld -> %ld)."
|
2016-11-22 17:23:40 +04:00
|
|
|
pcounter counter >>= fun () ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_proto_rpcs.Helpers.Forge.Manager.transaction cctxt.rpc_config block
|
2016-09-08 21:13:10 +04:00
|
|
|
~net ~source ~sourcePubKey:src_pk ~counter ~amount
|
|
|
|
~destination ?parameters ~fee () >>=? fun bytes ->
|
2017-02-16 22:01:35 +04:00
|
|
|
cctxt.Client_commands.message "Forged the raw origination frame." >>= fun () ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.Blocks.predecessor cctxt.rpc_config block >>=? fun predecessor ->
|
2017-02-16 22:01:35 +04:00
|
|
|
let signature = Ed25519.sign src_sk bytes in
|
|
|
|
let signed_bytes = MBytes.concat bytes signature in
|
|
|
|
let oph = Operation_hash.hash_bytes [ signed_bytes ] in
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_proto_rpcs.Helpers.apply_operation cctxt.rpc_config block
|
2017-02-16 22:01:35 +04:00
|
|
|
predecessor oph bytes (Some signature) >>=? fun contracts ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.inject_operation cctxt.rpc_config ?force signed_bytes >>=? fun injected_oph ->
|
2017-02-16 22:01:35 +04:00
|
|
|
assert (Operation_hash.equal oph injected_oph) ;
|
|
|
|
cctxt.message "Operation successfully injected in the node." >>= fun () ->
|
|
|
|
cctxt.message "Operation hash is '%a'." Operation_hash.pp oph >>= fun () ->
|
|
|
|
return contracts
|
|
|
|
|
2017-02-28 05:48:51 +04:00
|
|
|
let originate cctxt ?force ~block ?signature bytes =
|
2017-02-16 22:01:35 +04:00
|
|
|
cctxt.Client_commands.message "Forged the raw origination frame." >>= fun () ->
|
2017-02-28 05:48:51 +04:00
|
|
|
let signed_bytes =
|
|
|
|
match signature with
|
|
|
|
| None -> bytes
|
|
|
|
| Some signature -> MBytes.concat bytes signature in
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.Blocks.predecessor cctxt.rpc_config block >>=? fun predecessor ->
|
2017-02-16 22:01:35 +04:00
|
|
|
let oph = Operation_hash.hash_bytes [ signed_bytes ] in
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_proto_rpcs.Helpers.apply_operation cctxt.rpc_config block
|
2017-02-28 05:48:51 +04:00
|
|
|
predecessor oph bytes signature >>=? function
|
2017-02-16 22:01:35 +04:00
|
|
|
| [ contract ] ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.inject_operation cctxt.rpc_config ?force signed_bytes >>=? fun injected_oph ->
|
2017-02-16 22:01:35 +04:00
|
|
|
assert (Operation_hash.equal oph injected_oph) ;
|
|
|
|
cctxt.message "Operation successfully injected in the node." >>= fun () ->
|
|
|
|
cctxt.message "Operation hash is '%a'." Operation_hash.pp oph >>= fun () ->
|
|
|
|
return contract
|
|
|
|
| contracts ->
|
|
|
|
cctxt.error "The origination introduced %d contracts instead of one." (List.length contracts)
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let originate_account cctxt
|
|
|
|
block ?force
|
2016-09-08 21:13:10 +04:00
|
|
|
~source ~src_pk ~src_sk ~manager_pkh ?delegatable ?spendable ?delegate ~balance ~fee () =
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.Blocks.net cctxt.rpc_config block >>=? fun net ->
|
|
|
|
Client_proto_rpcs.Context.Contract.counter cctxt.rpc_config block source >>=? fun pcounter ->
|
2016-09-08 21:13:10 +04:00
|
|
|
let counter = Int32.succ pcounter in
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.message "Acquired the source's sequence counter (%ld -> %ld)."
|
2016-11-22 17:23:40 +04:00
|
|
|
pcounter counter >>= fun () ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_proto_rpcs.Helpers.Forge.Manager.origination cctxt.rpc_config block
|
2016-09-08 21:13:10 +04:00
|
|
|
~net ~source ~sourcePubKey:src_pk ~managerPubKey:manager_pkh
|
|
|
|
~counter ~balance ?spendable
|
2017-02-16 22:01:35 +04:00
|
|
|
?delegatable ?delegatePubKey:delegate ~fee () >>=? fun bytes ->
|
2017-02-28 05:48:51 +04:00
|
|
|
let signature = Ed25519.sign src_sk bytes in
|
|
|
|
originate cctxt ?force ~block ~signature bytes
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let originate_contract cctxt
|
2016-09-08 21:13:10 +04:00
|
|
|
block ?force
|
|
|
|
~source ~src_pk ~src_sk ~manager_pkh ~balance ?delegatable ?delegatePubKey
|
|
|
|
~(code:Script.code) ~init ~fee () =
|
2017-04-05 12:22:41 +04:00
|
|
|
Client_proto_programs.parse_data init >>=? fun storage ->
|
2017-03-09 22:17:13 +04:00
|
|
|
let storage = Script.{ storage ; storage_type = code.storage_type } in
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_proto_rpcs.Context.Contract.counter cctxt.rpc_config block source >>=? fun pcounter ->
|
2016-09-08 21:13:10 +04:00
|
|
|
let counter = Int32.succ pcounter in
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.message "Acquired the source's sequence counter (%ld -> %ld)."
|
2016-11-22 17:23:40 +04:00
|
|
|
pcounter counter >>= fun () ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.Blocks.net cctxt.rpc_config block >>=? fun net ->
|
|
|
|
Client_proto_rpcs.Helpers.Forge.Manager.origination cctxt.rpc_config block
|
2016-09-08 21:13:10 +04:00
|
|
|
~net ~source ~sourcePubKey:src_pk ~managerPubKey:manager_pkh
|
|
|
|
~counter ~balance ~spendable:!spendable
|
|
|
|
?delegatable ?delegatePubKey
|
2017-03-09 22:17:13 +04:00
|
|
|
~script:{ code ; storage } ~fee () >>=? fun bytes ->
|
2017-02-28 05:48:51 +04:00
|
|
|
let signature = Ed25519.sign src_sk bytes in
|
|
|
|
originate cctxt ?force ~block ~signature bytes
|
|
|
|
|
|
|
|
let faucet cctxt block ?force ~manager_pkh () =
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.Blocks.net cctxt.rpc_config block >>=? fun net ->
|
|
|
|
Client_proto_rpcs.Helpers.Forge.Anonymous.faucet cctxt.rpc_config block
|
2017-02-28 05:48:51 +04:00
|
|
|
~net ~id:manager_pkh () >>=? fun bytes ->
|
|
|
|
originate cctxt ?force ~block bytes
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-03-21 18:19:35 +04:00
|
|
|
let delegate_contract cctxt
|
|
|
|
block ?force
|
|
|
|
~source ?src_pk ~manager_sk
|
|
|
|
~fee delegate_opt =
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.Blocks.net cctxt.rpc_config block >>=? fun net ->
|
|
|
|
Client_proto_rpcs.Context.Contract.counter cctxt.rpc_config block source
|
2017-03-21 18:19:35 +04:00
|
|
|
>>=? fun pcounter ->
|
|
|
|
let counter = Int32.succ pcounter in
|
|
|
|
cctxt.message "Acquired the source's sequence counter (%ld -> %ld)."
|
|
|
|
pcounter counter >>= fun () ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_proto_rpcs.Helpers.Forge.Manager.delegation cctxt.rpc_config block
|
2017-03-21 18:19:35 +04:00
|
|
|
~net ~source ?sourcePubKey:src_pk ~counter ~fee delegate_opt
|
|
|
|
>>=? fun bytes ->
|
|
|
|
cctxt.Client_commands.message "Forged the raw origination frame." >>= fun () ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.Blocks.predecessor cctxt.rpc_config block >>=? fun predecessor ->
|
2017-03-21 18:19:35 +04:00
|
|
|
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
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_proto_rpcs.Helpers.apply_operation cctxt.rpc_config block
|
2017-03-21 18:19:35 +04:00
|
|
|
predecessor oph bytes (Some signature) >>=? function
|
|
|
|
| [] ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.inject_operation cctxt.rpc_config ?force signed_bytes >>=? fun injected_oph ->
|
2017-03-21 18:19:35 +04:00
|
|
|
assert (Operation_hash.equal oph injected_oph) ;
|
|
|
|
cctxt.message "Operation successfully injected in the node." >>= fun () ->
|
|
|
|
cctxt.message "Operation hash is '%a'." Operation_hash.pp oph >>= fun () ->
|
|
|
|
return ()
|
|
|
|
| contracts ->
|
|
|
|
cctxt.error "The origination introduced %d contracts instead of one." (List.length contracts)
|
|
|
|
|
2017-02-27 21:24:26 +04:00
|
|
|
let dictate cctxt block command seckey =
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.Blocks.net cctxt.rpc_config block >>=? fun net ->
|
2017-02-27 21:24:26 +04:00
|
|
|
Client_proto_rpcs.Helpers.Forge.Dictator.operation
|
2017-04-05 01:35:41 +04:00
|
|
|
cctxt.rpc_config block ~net command >>=? fun bytes ->
|
2017-02-27 21:24:26 +04:00
|
|
|
let signature = Ed25519.sign seckey bytes in
|
|
|
|
let signed_bytes = MBytes.concat bytes signature in
|
|
|
|
let oph = Operation_hash.hash_bytes [ signed_bytes ] in
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.inject_operation cctxt.rpc_config signed_bytes >>=? fun injected_oph ->
|
2017-02-27 21:24:26 +04:00
|
|
|
assert (Operation_hash.equal oph injected_oph) ;
|
|
|
|
cctxt.message "Operation successfully injected in the node." >>= fun () ->
|
|
|
|
cctxt.message "Operation hash is '%a'." Operation_hash.pp oph >>= fun () ->
|
|
|
|
return ()
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let group =
|
|
|
|
{ Cli_entries.name = "context" ;
|
|
|
|
title = "Block contextual commands (see option -block)" }
|
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
let commands () =
|
|
|
|
let open Cli_entries in
|
2017-03-15 04:17:20 +04:00
|
|
|
let open Client_commands in
|
2017-04-05 03:02:10 +04:00
|
|
|
[
|
|
|
|
|
|
|
|
command ~group ~desc: "access the timestamp of the block"
|
2016-09-08 21:13:10 +04:00
|
|
|
(fixed [ "get" ; "timestamp" ])
|
2017-03-15 04:17:20 +04:00
|
|
|
(fun cctxt -> get_timestamp cctxt cctxt.config.block) ;
|
2017-04-05 03:02:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "lists all non empty contracts of the block"
|
2016-09-08 21:13:10 +04:00
|
|
|
(fixed [ "list" ; "contracts" ])
|
2016-12-03 16:05:02 +04:00
|
|
|
(fun cctxt ->
|
2017-04-05 01:35:41 +04:00
|
|
|
list_contract_labels cctxt cctxt.config.block >>=? fun contracts ->
|
2017-04-05 03:02:10 +04:00
|
|
|
Lwt_list.iter_s
|
|
|
|
(fun (alias, hash, kind) -> cctxt.message "%s%s%s" hash kind alias)
|
2017-04-05 01:35:41 +04:00
|
|
|
contracts >>= fun () ->
|
|
|
|
return ()) ;
|
2017-04-05 03:02:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "get the balance of a contract"
|
2016-09-08 21:13:10 +04:00
|
|
|
(prefixes [ "get" ; "balance" ]
|
2016-11-22 17:23:40 +04:00
|
|
|
@@ ContractAlias.destination_param ~name:"src" ~desc:"source contract"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ stop)
|
2016-12-03 16:05:02 +04:00
|
|
|
(fun (_, contract) cctxt ->
|
2017-04-05 01:35:41 +04:00
|
|
|
get_balance cctxt.rpc_config cctxt.config.block contract >>=? fun amount ->
|
|
|
|
cctxt.answer "%a %s" Tez.pp amount tez_sym >>= fun () ->
|
|
|
|
return ()) ;
|
2017-04-05 03:02:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "get the manager of a block"
|
2016-09-08 21:13:10 +04:00
|
|
|
(prefixes [ "get" ; "manager" ]
|
2016-11-22 17:23:40 +04:00
|
|
|
@@ ContractAlias.destination_param ~name:"src" ~desc:"source contract"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ stop)
|
2016-12-03 16:05:02 +04:00
|
|
|
(fun (_, contract) cctxt ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_proto_rpcs.Context.Contract.manager cctxt.rpc_config cctxt.config.block contract >>=? fun manager ->
|
2017-04-05 03:02:10 +04:00
|
|
|
Public_key_hash.rev_find cctxt manager >>=? fun mn ->
|
|
|
|
Public_key_hash.to_source cctxt manager >>=? fun m ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.message "%s (%s)" m
|
2017-04-05 01:35:41 +04:00
|
|
|
(match mn with None -> "unknown" | Some n -> "known as " ^ n) >>= fun () ->
|
|
|
|
return ());
|
2017-04-05 03:02:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "open a new account"
|
2016-09-08 21:13:10 +04:00
|
|
|
~args: ([ fee_arg ; delegate_arg ; force_arg ]
|
|
|
|
@ delegatable_args @ spendable_args)
|
|
|
|
(prefixes [ "originate" ; "account" ]
|
|
|
|
@@ RawContractAlias.fresh_alias_param
|
2016-11-22 17:23:40 +04:00
|
|
|
~name: "new" ~desc: "name of the new contract"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ prefix "for"
|
|
|
|
@@ Public_key_hash.alias_param
|
2016-11-22 17:23:40 +04:00
|
|
|
~name: "mgr" ~desc: "manager of the new contract"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ prefix "transfering"
|
|
|
|
@@ tez_param
|
2016-11-22 17:23:40 +04:00
|
|
|
~name: "qty" ~desc: "amount taken from source"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ prefix "from"
|
|
|
|
@@ ContractAlias.alias_param
|
2016-11-22 17:23:40 +04:00
|
|
|
~name:"src" ~desc: "name of the source contract"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ stop)
|
2016-12-03 16:05:02 +04:00
|
|
|
(fun neu (_, manager) balance (_, source) cctxt ->
|
2017-04-05 03:02:10 +04:00
|
|
|
check_contract cctxt neu >>=? fun () ->
|
|
|
|
get_delegate_pkh cctxt !delegate >>=? fun delegate ->
|
2017-04-05 01:35:41 +04:00
|
|
|
(Client_proto_contracts.get_manager cctxt.rpc_config cctxt.config.block source >>=? fun src_pkh ->
|
2017-03-15 04:17:20 +04:00
|
|
|
Client_keys.get_key cctxt src_pkh
|
|
|
|
>>=? fun (src_name, src_pk, src_sk) ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.message "Got the source's manager keys (%s)." src_name >>= fun () ->
|
2017-03-15 04:17:20 +04:00
|
|
|
originate_account cctxt cctxt.config.block ~force:!force
|
2016-12-03 16:05:02 +04:00
|
|
|
~source ~src_pk ~src_sk ~manager_pkh:manager ~balance ~fee:!fee
|
|
|
|
~delegatable:!delegatable ~spendable:!spendable ?delegate:delegate
|
2017-04-05 01:35:41 +04:00
|
|
|
()) >>=? fun contract ->
|
2017-04-05 03:02:10 +04:00
|
|
|
RawContractAlias.add cctxt neu contract) ;
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "open a new scripted account"
|
2016-09-08 21:13:10 +04:00
|
|
|
~args: ([ fee_arg ; delegate_arg ; force_arg ] @
|
|
|
|
delegatable_args @ spendable_args @ [ init_arg ])
|
|
|
|
(prefixes [ "originate" ; "contract" ]
|
|
|
|
@@ RawContractAlias.fresh_alias_param
|
2016-11-22 17:23:40 +04:00
|
|
|
~name: "new" ~desc: "name of the new contract"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ prefix "for"
|
|
|
|
@@ Public_key_hash.alias_param
|
2016-11-22 17:23:40 +04:00
|
|
|
~name: "mgr" ~desc: "manager of the new contract"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ prefix "transfering"
|
|
|
|
@@ tez_param
|
2016-11-22 17:23:40 +04:00
|
|
|
~name: "qty" ~desc: "amount taken from source"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ prefix "from"
|
|
|
|
@@ ContractAlias.alias_param
|
2016-11-22 17:23:40 +04:00
|
|
|
~name:"src" ~desc: "name of the source contract"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ prefix "running"
|
|
|
|
@@ Program.source_param
|
2016-11-22 17:23:40 +04:00
|
|
|
~name:"prg" ~desc: "script of the account\n\
|
2017-01-11 19:15:38 +04:00
|
|
|
combine with -init if the storage type is not unit"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ stop)
|
2016-12-03 16:05:02 +04:00
|
|
|
(fun neu (_, manager) balance (_, source) code cctxt ->
|
2017-04-05 03:02:10 +04:00
|
|
|
check_contract cctxt neu >>=? fun () ->
|
|
|
|
get_delegate_pkh cctxt !delegate >>=? fun delegate ->
|
2017-04-05 01:35:41 +04:00
|
|
|
(Client_proto_contracts.get_manager cctxt.rpc_config cctxt.config.block source >>=? fun src_pkh ->
|
2017-03-15 04:17:20 +04:00
|
|
|
Client_keys.get_key cctxt src_pkh
|
|
|
|
>>=? fun (src_name, src_pk, src_sk) ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.message "Got the source's manager keys (%s)." src_name >>= fun () ->
|
2017-03-15 04:17:20 +04:00
|
|
|
originate_contract cctxt cctxt.config.block ~force:!force
|
2016-12-03 16:05:02 +04:00
|
|
|
~source ~src_pk ~src_sk ~manager_pkh:manager ~balance ~fee:!fee
|
|
|
|
~delegatable:!delegatable ?delegatePubKey:delegate ~code ~init:!init
|
2017-04-05 01:35:41 +04:00
|
|
|
()) >>=? fun contract ->
|
2017-04-05 03:02:10 +04:00
|
|
|
RawContractAlias.add cctxt neu contract) ;
|
|
|
|
|
2017-02-28 05:48:51 +04:00
|
|
|
command ~group ~desc: "open a new (free) account"
|
|
|
|
~args: ([ fee_arg ; delegate_arg ; force_arg ]
|
|
|
|
@ delegatable_args @ spendable_args)
|
|
|
|
(prefixes [ "originate" ; "free" ; "account" ]
|
|
|
|
@@ RawContractAlias.fresh_alias_param
|
|
|
|
~name: "new" ~desc: "name of the new contract"
|
|
|
|
@@ prefix "for"
|
|
|
|
@@ Public_key_hash.alias_param
|
|
|
|
~name: "mgr" ~desc: "manager of the new contract"
|
|
|
|
@@ stop)
|
|
|
|
(fun neu (_, manager) cctxt ->
|
2017-04-05 03:02:10 +04:00
|
|
|
check_contract cctxt neu >>=? fun () ->
|
2017-04-05 01:35:41 +04:00
|
|
|
faucet cctxt cctxt.config.block ~force:!force ~manager_pkh:manager () >>=? fun contract ->
|
2017-04-05 03:02:10 +04:00
|
|
|
RawContractAlias.add cctxt neu contract) ;
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "transfer tokens"
|
2016-09-08 21:13:10 +04:00
|
|
|
~args: [ fee_arg ; arg_arg ; force_arg ]
|
|
|
|
(prefixes [ "transfer" ]
|
|
|
|
@@ tez_param
|
2016-11-22 17:23:40 +04:00
|
|
|
~name: "qty" ~desc: "amount taken from source"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ prefix "from"
|
|
|
|
@@ ContractAlias.alias_param
|
2016-11-22 17:23:40 +04:00
|
|
|
~name: "src" ~desc: "name of the source contract"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ prefix "to"
|
|
|
|
@@ ContractAlias.destination_param
|
2016-11-22 17:23:40 +04:00
|
|
|
~name: "dst" ~desc: "name/literal of the destination contract"
|
2016-09-08 21:13:10 +04:00
|
|
|
@@ stop)
|
2016-12-03 16:05:02 +04:00
|
|
|
(fun amount (_, source) (_, destination) cctxt ->
|
2017-04-05 01:35:41 +04:00
|
|
|
(Client_proto_contracts.get_manager cctxt.rpc_config cctxt.config.block source >>=? fun src_pkh ->
|
2017-03-15 04:17:20 +04:00
|
|
|
Client_keys.get_key cctxt src_pkh
|
|
|
|
>>=? fun (src_name, src_pk, src_sk) ->
|
2017-02-16 22:01:35 +04:00
|
|
|
cctxt.message "Got the source's manager keys (%s)." src_name >>= fun () ->
|
2017-03-15 04:17:20 +04:00
|
|
|
(transfer cctxt cctxt.config.block ~force:!force
|
2017-02-16 22:01:35 +04:00
|
|
|
~source ~src_pk ~src_sk ~destination ?arg:!arg ~amount ~fee:!fee ()) >>=? fun contracts ->
|
|
|
|
Lwt_list.iter_s
|
|
|
|
(fun c -> cctxt.message "New contract %a originated from a smart contract."
|
|
|
|
Contract.pp c)
|
2017-04-05 01:35:41 +04:00
|
|
|
contracts >>= fun () ->
|
|
|
|
return ())) ;
|
2017-04-05 03:02:10 +04:00
|
|
|
|
2017-02-27 21:24:26 +04:00
|
|
|
command ~desc: "Activate a protocol" begin
|
|
|
|
prefixes [ "activate" ; "protocol" ] @@
|
2017-04-05 12:22:41 +04:00
|
|
|
Protocol_hash.param ~name:"version" ~desc:"Protocol version (b58check)" @@
|
2017-02-27 21:24:26 +04:00
|
|
|
prefixes [ "with" ; "key" ] @@
|
2017-04-05 12:22:41 +04:00
|
|
|
Environment.Ed25519.Secret_key.param
|
|
|
|
~name:"password" ~desc:"Dictator's key" @@
|
2017-02-27 21:24:26 +04:00
|
|
|
stop
|
|
|
|
end
|
|
|
|
(fun hash seckey cctxt ->
|
2017-04-05 01:35:41 +04:00
|
|
|
dictate cctxt cctxt.config.block (Activate hash) seckey) ;
|
2017-04-05 03:02:10 +04:00
|
|
|
|
2017-02-27 21:24:26 +04:00
|
|
|
command ~desc: "Fork a test protocol" begin
|
|
|
|
prefixes [ "fork" ; "test" ; "protocol" ] @@
|
2017-04-05 12:22:41 +04:00
|
|
|
Protocol_hash.param ~name:"version" ~desc:"Protocol version (b58check)" @@
|
2017-02-27 21:24:26 +04:00
|
|
|
prefixes [ "with" ; "key" ] @@
|
2017-04-05 12:22:41 +04:00
|
|
|
Environment.Ed25519.Secret_key.param
|
|
|
|
~name:"password" ~desc:"Dictator's key" @@
|
|
|
|
stop
|
2017-02-27 21:24:26 +04:00
|
|
|
end
|
|
|
|
(fun hash seckey cctxt ->
|
2017-04-05 01:35:41 +04:00
|
|
|
dictate cctxt cctxt.config.block (Activate_testnet hash) seckey) ;
|
2017-04-05 12:22:41 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
]
|