2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2017-11-14 03:36:14 +04:00
|
|
|
(* Copyright (c) 2014 - 2017. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
let string_of_errors exns =
|
|
|
|
Format.asprintf " @[<v>%a@]" pp_print_error exns
|
|
|
|
|
2017-11-07 20:38:11 +04:00
|
|
|
let handle_error (cctxt : #Client_commands.logger) = function
|
2016-09-08 21:13:10 +04:00
|
|
|
| Ok res -> Lwt.return res
|
|
|
|
| Error exns ->
|
|
|
|
pp_print_error Format.err_formatter exns ;
|
2017-11-07 20:38:11 +04:00
|
|
|
cctxt#error "%s" "cannot continue"
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-20 17:50:02 +04:00
|
|
|
let call_service0 cctxt s block =
|
|
|
|
Client_rpcs.call_service0 cctxt
|
|
|
|
(s Node_rpc_services.Blocks.proto_path) block
|
2016-12-03 16:05:02 +04:00
|
|
|
let call_service1 cctxt s block a1 =
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_rpcs.call_service1 cctxt
|
2016-09-08 21:13:10 +04:00
|
|
|
(s Node_rpc_services.Blocks.proto_path) block a1
|
2016-12-03 16:05:02 +04:00
|
|
|
let call_error_service1 cctxt s block a1 =
|
2017-04-05 01:35:41 +04:00
|
|
|
call_service1 cctxt s block a1 >>= function
|
2017-10-27 20:53:07 +04:00
|
|
|
| Ok (Error _ as err) -> Lwt.return (Environment.wrap_error err)
|
2017-04-05 01:35:41 +04:00
|
|
|
| Ok (Ok v) -> return v
|
|
|
|
| Error _ as err -> Lwt.return err
|
2016-12-03 16:05:02 +04:00
|
|
|
let call_service2 cctxt s block a1 a2 =
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_rpcs.call_service2 cctxt
|
2016-09-08 21:13:10 +04:00
|
|
|
(s Node_rpc_services.Blocks.proto_path) block a1 a2
|
2016-12-03 16:05:02 +04:00
|
|
|
let call_error_service2 cctxt s block a1 a2 =
|
2017-04-05 01:35:41 +04:00
|
|
|
call_service2 cctxt s block a1 a2 >>= function
|
2017-10-27 20:53:07 +04:00
|
|
|
| Ok (Error _ as err) -> Lwt.return (Environment.wrap_error err)
|
2017-04-05 01:35:41 +04:00
|
|
|
| Ok (Ok v) -> return v
|
|
|
|
| Error _ as err -> Lwt.return err
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-20 17:50:02 +04:00
|
|
|
type block = Node_rpc_services.Blocks.block
|
|
|
|
|
|
|
|
let header cctxt block =
|
|
|
|
call_error_service1 cctxt Services.header block ()
|
|
|
|
|
|
|
|
module Header = struct
|
|
|
|
let priority cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Header.priority block ()
|
|
|
|
let seed_nonce_hash cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Header.seed_nonce_hash block ()
|
|
|
|
end
|
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
module Constants = struct
|
2016-12-03 16:05:02 +04:00
|
|
|
let errors cctxt block =
|
|
|
|
call_service1 cctxt Services.Constants.errors block ()
|
|
|
|
let cycle_length cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Constants.cycle_length block ()
|
|
|
|
let voting_period_length cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Constants.voting_period_length block ()
|
|
|
|
let time_before_reward cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Constants.time_before_reward block ()
|
2017-02-24 21:32:30 +04:00
|
|
|
let slot_durations cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Constants.slot_durations block ()
|
2017-11-01 15:07:33 +04:00
|
|
|
let first_free_baking_slot cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Constants.first_free_baking_slot block ()
|
2016-12-03 16:05:02 +04:00
|
|
|
let max_signing_slot cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Constants.max_signing_slot block ()
|
|
|
|
let instructions_per_transaction cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Constants.instructions_per_transaction block ()
|
|
|
|
let stamp_threshold cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Constants.proof_of_work_threshold block ()
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
module Context = struct
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let level cctxt block =
|
2017-04-10 15:01:22 +04:00
|
|
|
call_error_service1 cctxt Services.Context.level block ()
|
2017-02-28 11:18:06 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let next_level cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Context.next_level block ()
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-04-14 22:24:11 +04:00
|
|
|
let voting_period_kind cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Context.voting_period_kind block ()
|
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
module Nonce = struct
|
|
|
|
|
|
|
|
type nonce_info = Services.Context.Nonce.nonce_info =
|
|
|
|
| Revealed of Nonce.t
|
|
|
|
| Missing of Nonce_hash.t
|
|
|
|
| Forgotten
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let get cctxt block level =
|
|
|
|
call_error_service2 cctxt Services.Context.Nonce.get block level ()
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let hash cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Context.Nonce.hash block ()
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
module Key = struct
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let get cctxt block pk_h =
|
|
|
|
call_error_service2 cctxt Services.Context.Key.get block pk_h ()
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let list cctxt block =
|
|
|
|
call_error_service1 cctxt Services.Context.Key.list block ()
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
module Contract = struct
|
2016-12-03 16:05:02 +04:00
|
|
|
let list cctxt b =
|
|
|
|
call_error_service1 cctxt Services.Context.Contract.list b ()
|
2016-09-08 21:13:10 +04:00
|
|
|
type info = Services.Context.Contract.info = {
|
|
|
|
manager: public_key_hash ;
|
|
|
|
balance: Tez.t ;
|
|
|
|
spendable: bool ;
|
|
|
|
delegate: bool * public_key_hash option ;
|
2017-03-09 22:17:13 +04:00
|
|
|
script: Script.t option ;
|
2016-09-08 21:13:10 +04:00
|
|
|
counter: int32 ;
|
|
|
|
}
|
2016-12-03 16:05:02 +04:00
|
|
|
let get cctxt b c =
|
|
|
|
call_error_service2 cctxt Services.Context.Contract.get b c ()
|
|
|
|
let balance cctxt b c =
|
|
|
|
call_error_service2 cctxt Services.Context.Contract.balance b c ()
|
|
|
|
let manager cctxt b c =
|
|
|
|
call_error_service2 cctxt Services.Context.Contract.manager b c ()
|
|
|
|
let delegate cctxt b c =
|
|
|
|
call_error_service2 cctxt Services.Context.Contract.delegate b c ()
|
|
|
|
let counter cctxt b c =
|
|
|
|
call_error_service2 cctxt Services.Context.Contract.counter b c ()
|
|
|
|
let spendable cctxt b c =
|
|
|
|
call_error_service2 cctxt Services.Context.Contract.spendable b c ()
|
|
|
|
let delegatable cctxt b c =
|
|
|
|
call_error_service2 cctxt Services.Context.Contract.delegatable b c ()
|
|
|
|
let script cctxt b c =
|
|
|
|
call_error_service2 cctxt Services.Context.Contract.script b c ()
|
2017-07-24 17:57:03 +04:00
|
|
|
let storage cctxt b c =
|
|
|
|
call_error_service2 cctxt Services.Context.Contract.storage b c ()
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
module Helpers = struct
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let minimal_time cctxt block ?prio () =
|
|
|
|
call_error_service1 cctxt Services.Helpers.minimal_timestamp block prio
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let typecheck_code cctxt =
|
|
|
|
call_error_service1 cctxt Services.Helpers.typecheck_code
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-02-16 22:01:35 +04:00
|
|
|
let apply_operation cctxt block pred_block hash forged_operation signature =
|
|
|
|
call_error_service1 cctxt Services.Helpers.apply_operation
|
|
|
|
block (pred_block, hash, forged_operation, signature)
|
|
|
|
|
2017-07-19 13:35:01 +04:00
|
|
|
let run_code cctxt block code (storage, input, amount) =
|
2016-12-03 16:05:02 +04:00
|
|
|
call_error_service1 cctxt Services.Helpers.run_code
|
2017-07-19 13:35:01 +04:00
|
|
|
block (code, storage, input, amount, None, None)
|
2016-11-15 18:58:18 +04:00
|
|
|
|
2017-07-19 13:35:01 +04:00
|
|
|
let trace_code cctxt block code (storage, input, amount) =
|
2016-12-03 16:05:02 +04:00
|
|
|
call_error_service1 cctxt Services.Helpers.trace_code
|
2017-07-19 13:35:01 +04:00
|
|
|
block (code, storage, input, amount, None, None)
|
2016-11-16 18:05:02 +04:00
|
|
|
|
2017-01-11 20:42:54 +04:00
|
|
|
let typecheck_data cctxt =
|
|
|
|
call_error_service1 cctxt Services.Helpers.typecheck_data
|
2016-09-12 16:06:23 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let hash_data cctxt =
|
|
|
|
call_error_service1 cctxt Services.Helpers.hash_data
|
2016-09-12 16:06:23 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let level cctxt block ?offset lvl =
|
|
|
|
call_error_service2 cctxt Services.Helpers.level block lvl offset
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let levels cctxt block cycle =
|
|
|
|
call_error_service2 cctxt Services.Helpers.levels block cycle ()
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Rights = struct
|
2017-11-01 15:07:33 +04:00
|
|
|
type baking_slot = Raw_level.t * int * Time.t
|
2017-03-14 19:32:01 +04:00
|
|
|
type endorsement_slot = Raw_level.t * int
|
2017-11-01 15:07:33 +04:00
|
|
|
let baking_rights_for_delegate cctxt
|
2016-09-08 21:13:10 +04:00
|
|
|
b c ?max_priority ?first_level ?last_level () =
|
2017-11-01 15:07:33 +04:00
|
|
|
call_error_service2 cctxt Services.Helpers.Rights.baking_rights_for_delegate
|
2017-11-13 19:34:00 +04:00
|
|
|
b c (max_priority, first_level, last_level)
|
2016-12-03 16:05:02 +04:00
|
|
|
let endorsement_rights_for_delegate cctxt
|
2016-09-08 21:13:10 +04:00
|
|
|
b c ?max_priority ?first_level ?last_level () =
|
2017-11-13 19:34:00 +04:00
|
|
|
call_error_service2 cctxt Services.Helpers.Rights.endorsement_rights_for_delegate
|
|
|
|
b c (max_priority, first_level, last_level)
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
module Forge = struct
|
|
|
|
|
|
|
|
module Manager = struct
|
2016-12-03 16:05:02 +04:00
|
|
|
let operations cctxt
|
2017-11-14 05:41:37 +04:00
|
|
|
block ~branch ~source ?sourcePubKey ~counter ~fee operations =
|
2016-09-08 21:13:10 +04:00
|
|
|
let ops =
|
|
|
|
Manager_operations { source ; public_key = sourcePubKey ;
|
|
|
|
counter ; operations ; fee } in
|
2016-12-03 16:05:02 +04:00
|
|
|
(call_error_service1 cctxt Services.Helpers.Forge.operations block
|
2017-11-14 05:41:37 +04:00
|
|
|
({ branch }, Sourced_operations ops))
|
2016-12-03 16:05:02 +04:00
|
|
|
let transaction cctxt
|
2017-11-14 05:41:37 +04:00
|
|
|
block ~branch ~source ?sourcePubKey ~counter
|
2016-09-08 21:13:10 +04:00
|
|
|
~amount ~destination ?parameters ~fee ()=
|
2017-11-14 05:41:37 +04:00
|
|
|
operations cctxt block ~branch ~source ?sourcePubKey ~counter ~fee
|
2016-09-08 21:13:10 +04:00
|
|
|
Tezos_context.[Transaction { amount ; parameters ; destination }]
|
2016-12-03 16:05:02 +04:00
|
|
|
let origination cctxt
|
2017-11-14 05:41:37 +04:00
|
|
|
block ~branch
|
2016-09-08 21:13:10 +04:00
|
|
|
~source ?sourcePubKey ~counter
|
|
|
|
~managerPubKey ~balance
|
|
|
|
?(spendable = true)
|
|
|
|
?(delegatable = true)
|
|
|
|
?delegatePubKey ?script ~fee () =
|
2017-11-14 05:41:37 +04:00
|
|
|
operations cctxt block ~branch ~source ?sourcePubKey ~counter ~fee
|
2016-09-08 21:13:10 +04:00
|
|
|
Tezos_context.[
|
|
|
|
Origination { manager = managerPubKey ;
|
|
|
|
delegate = delegatePubKey ;
|
|
|
|
script ;
|
|
|
|
spendable ;
|
|
|
|
delegatable ;
|
|
|
|
credit = balance }
|
|
|
|
]
|
2016-12-03 16:05:02 +04:00
|
|
|
let delegation cctxt
|
2017-11-14 05:41:37 +04:00
|
|
|
block ~branch ~source ?sourcePubKey ~counter ~fee delegate =
|
|
|
|
operations cctxt block ~branch ~source ?sourcePubKey ~counter ~fee
|
2016-09-08 21:13:10 +04:00
|
|
|
Tezos_context.[Delegation delegate]
|
|
|
|
end
|
|
|
|
module Delegate = struct
|
2016-12-03 16:05:02 +04:00
|
|
|
let operations cctxt
|
2017-11-14 05:41:37 +04:00
|
|
|
block ~branch ~source operations =
|
2016-09-08 21:13:10 +04:00
|
|
|
let ops = Delegate_operations { source ; operations } in
|
2016-12-03 16:05:02 +04:00
|
|
|
(call_error_service1 cctxt Services.Helpers.Forge.operations block
|
2017-11-14 05:41:37 +04:00
|
|
|
({ branch }, Sourced_operations ops))
|
2016-12-03 16:05:02 +04:00
|
|
|
let endorsement cctxt
|
2017-11-14 05:41:37 +04:00
|
|
|
b ~branch ~source ~block ~slot () =
|
|
|
|
operations cctxt b ~branch ~source
|
2016-09-08 21:13:10 +04:00
|
|
|
Tezos_context.[Endorsement { block ; slot }]
|
2017-04-12 20:53:23 +04:00
|
|
|
let proposals cctxt
|
2017-11-14 05:41:37 +04:00
|
|
|
b ~branch ~source ~period ~proposals () =
|
|
|
|
operations cctxt b ~branch ~source
|
2017-04-12 20:53:23 +04:00
|
|
|
Tezos_context.[Proposals { period ; proposals }]
|
|
|
|
let ballot cctxt
|
2017-11-14 05:41:37 +04:00
|
|
|
b ~branch ~source ~period ~proposal ~ballot () =
|
|
|
|
operations cctxt b ~branch ~source
|
2017-04-12 20:53:23 +04:00
|
|
|
Tezos_context.[Ballot { period ; proposal ; ballot }]
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
2017-02-27 21:24:26 +04:00
|
|
|
module Dictator = struct
|
|
|
|
let operation cctxt
|
2017-11-14 05:41:37 +04:00
|
|
|
block ~branch operation =
|
2017-02-27 21:24:26 +04:00
|
|
|
let op = Dictator_operation operation in
|
|
|
|
(call_error_service1 cctxt Services.Helpers.Forge.operations block
|
2017-11-14 05:41:37 +04:00
|
|
|
({ branch }, Sourced_operations op))
|
2017-02-27 21:24:26 +04:00
|
|
|
let activate cctxt
|
2017-11-14 05:41:37 +04:00
|
|
|
b ~branch hash =
|
|
|
|
operation cctxt b ~branch (Activate hash)
|
2017-02-27 21:24:26 +04:00
|
|
|
let activate_testnet cctxt
|
2017-11-14 05:41:37 +04:00
|
|
|
b ~branch hash =
|
|
|
|
operation cctxt b ~branch (Activate_testnet hash)
|
2017-02-27 21:24:26 +04:00
|
|
|
end
|
2016-09-08 21:13:10 +04:00
|
|
|
module Anonymous = struct
|
2017-11-14 05:41:37 +04:00
|
|
|
let operations cctxt block ~branch operations =
|
2016-12-03 16:05:02 +04:00
|
|
|
(call_error_service1 cctxt Services.Helpers.Forge.operations block
|
2017-11-14 05:41:37 +04:00
|
|
|
({ branch }, Anonymous_operations operations))
|
2016-12-03 16:05:02 +04:00
|
|
|
let seed_nonce_revelation cctxt
|
2017-11-14 05:41:37 +04:00
|
|
|
block ~branch ~level ~nonce () =
|
|
|
|
operations cctxt block ~branch [Seed_nonce_revelation { level ; nonce }]
|
2017-02-28 05:48:51 +04:00
|
|
|
let faucet cctxt
|
2017-11-14 05:41:37 +04:00
|
|
|
block ~branch ~id () =
|
2017-02-28 05:48:51 +04:00
|
|
|
let nonce = Sodium.Random.Bigbytes.generate 16 in
|
2017-11-14 05:41:37 +04:00
|
|
|
operations cctxt block ~branch [Faucet { id ; nonce }]
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
2017-04-27 03:01:05 +04:00
|
|
|
let empty_proof_of_work_nonce =
|
|
|
|
MBytes.of_string
|
|
|
|
(String.make Constants_repr.proof_of_work_nonce_size '\000')
|
|
|
|
let block_proto_header cctxt
|
|
|
|
block
|
|
|
|
~priority ~seed_nonce_hash
|
|
|
|
?(proof_of_work_nonce = empty_proof_of_work_nonce) () =
|
|
|
|
call_error_service1 cctxt Services.Helpers.Forge.block_proto_header
|
|
|
|
block (priority, seed_nonce_hash, proof_of_work_nonce)
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
module Parse = struct
|
2017-03-30 16:31:16 +04:00
|
|
|
let operations cctxt block ?check operations =
|
2017-03-21 20:23:06 +04:00
|
|
|
call_error_service1 cctxt
|
2017-03-30 16:31:16 +04:00
|
|
|
Services.Helpers.Parse.operations block (operations, check)
|
2017-03-22 20:21:52 +04:00
|
|
|
let block cctxt block shell proto =
|
|
|
|
call_error_service1 cctxt
|
|
|
|
Services.Helpers.Parse.block block
|
2017-04-20 17:21:10 +04:00
|
|
|
({ shell ; proto } : Block_header.raw)
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
(* type slot = *)
|
2017-11-13 19:34:00 +04:00
|
|
|
(* raw_level * int * timestamp option *)
|
|
|
|
(* let baking_possibilities *)
|
|
|
|
(* b c ?max_priority ?first_level ?last_level () = *)
|
|
|
|
(* call_error_service2 Services.Helpers.Context.Contract.baking_possibilities *)
|
|
|
|
(* b c (max_priority, first_level, last_level) *)
|
|
|
|
(* (\* let endorsement_possibilities b c ?max_priority ?first_level ?last_level () = *\) *)
|
|
|
|
(* call_error_service2 Services.Helpers.Context.Contract.endorsement_possibilities *)
|
|
|
|
(* b c (max_priority, first_level, last_level) *)
|