123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)(** 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.
*)letinvoice_contractctxt~address~amount_mutez=matchTez_repr.of_mutezamount_mutezwith|None->Lwt.return(ctxt,[])|Someamount->(Contract_repr.of_b58checkaddress>>?=(funrecipient->Contract_storage.creditctxtrecipientamount>|=?functxt->(ctxt,Receipt_repr.[(Contractrecipient,Creditedamount,Protocol_migration)]))>|=functionOkres->res|Error_->(ctxt,[]))(* This is the genesis protocol: initialise the state *)letprepare_first_blockctxt~typecheck~level~timestamp~fitness=Raw_context.prepare_first_block~level~timestamp~fitnessctxt>>=?fun(previous_protocol,ctxt)->matchprevious_protocolwith|Genesisparam->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|Edo_008->(* 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.
*)invoice_contractctxt~address:"tz1abmz7jiCV2GH2u81LRrGgAFFgvQgiDiaf"~amount_mutez:100_000_000L>>=fun(ctxt,balance_updates)->Storage.Pending_migration_balance_updates.initctxtbalance_updatesletpreparectxt~level~predecessor_timestamp~timestamp~fitness=Raw_context.prepare~level~predecessor_timestamp~timestamp~fitnessctxt>>=?functxt->Storage.Pending_migration_balance_updates.findctxt>>=?function|Somebalance_updates->Storage.Pending_migration_balance_updates.removectxt>>=functxt->(* When applying balance updates in a migration, we must attach receipts.
The balance updates returned from here will be applied in the first
block of the new protocol. *)return(ctxt,balance_updates)|None->return(ctxt,[])