123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* Copyright (c) 2019-2020 Nomadic Labs <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)(*
To add invoices, you can use a helper function like this one:
(** Invoice a contract at a given address with a given amount. Returns the
updated context and a balance update receipt (singleton list). The address
must be a valid base58 hash, otherwise this is no-op and returns an empty
receipts list.
Do not fail if something goes wrong.
*)
let invoice_contract ctxt ~address ~amount_mutez =
match Tez_repr.of_mutez amount_mutez with
| None ->
Lwt.return (ctxt, [])
| Some amount -> (
Contract_repr.of_b58check address
>>?= (fun recipient ->
Contract_storage.credit ctxt recipient amount
>|=? fun ctxt ->
( ctxt,
Receipt_repr.
[(Contract recipient, Credited amount, Protocol_migration)] ))
>|= function Ok res -> res | Error _ -> (ctxt, []) )
*)letprepare_first_blockctxt~typecheck~level~timestamp~fitness=Raw_context.prepare_first_block~level~timestamp~fitnessctxt>>=?fun(previous_protocol,ctxt)->matchprevious_protocolwith|Genesisparam->(* This is the genesis protocol: initialise the state *)Commitment_storage.initctxtparam.commitments>>=?functxt->Roll_storage.initctxt>>=?functxt->Seed_storage.initctxt>>=?functxt->Contract_storage.initctxt>>=?functxt->Bootstrap_storage.initctxt~typecheck?ramp_up_cycles:param.security_deposit_ramp_up_cycles?no_reward_cycles:param.no_reward_cyclesparam.bootstrap_accountsparam.bootstrap_contracts>>=?functxt->Roll_storage.init_first_cyclesctxt>>=?functxt->Vote_storage.initctxt~start_position:(Level_storage.currentctxt).level_position>>=?functxt->Storage.Block_priority.initctxt0>>=?functxt->Vote_storage.update_listingsctxt>>=?functxt->(* Must be called after other originations since it unsets the origination nonce.*)Liquidity_baking_migration.initctxt~typecheck>>=?fun(ctxt,operation_results)->Storage.Pending_migration.Operation_results.initctxtoperation_results|Florence_009->(* Only the starting position of the voting period is shifted by
one level into the future, so that voting periods are again
aligned with cycles. The period kind does not change, as a new
voting period has just started. *)Voting_period_storage.get_currentctxt>>=?funvoting_period->Storage.Vote.Current_period.updatectxt{voting_periodwithstart_position=Int32.succvoting_period.start_position;}>>=?functxt->Lazy_storage_diff.cleanup_edo_florence_dangling_lazy_storagectxt>>=functxt->(* Add balance updates receipts to be attached on the first block of this
protocol - see [[prepare]] function below. Any balance updates attached
in the migration should use the [[Receipt_repr.Migration]] constructor.
*)(* To add invoices, use something like that:
invoice_contract
ctxt
~address:"tz1..."
~amount_mutez:123_456L
>>= fun (ctxt, balance_updates) ->
Storage.Pending_migration_balance_updates.init ctxt balance_updates
*)(* Must be called after other originations since it unsets the origination nonce.*)Liquidity_baking_migration.initctxt~typecheck>>=?fun(ctxt,operation_results)->Storage.Pending_migration.Operation_results.initctxtoperation_resultsletpreparectxt~level~predecessor_timestamp~timestamp~fitness=Raw_context.prepare~level~predecessor_timestamp~timestamp~fitnessctxt>>=?functxt->Storage.Pending_migration.removectxt