def return_funds_to_faucet( *src_addrs: clusterlib.AddressRecord, cluster_obj: clusterlib.ClusterLib, faucet_addr: str, amount: int = -1, tx_name: Optional[str] = None, destination_dir: FileType = ".", ) -> None: """Send `amount` from all `src_addrs` to `faucet_addr`. The amount of "-1" means all available funds. """ tx_name = tx_name or helpers.get_timestamped_rand_str() tx_name = f"{tx_name}_return_funds" with helpers.FileLockIfXdist(f"{helpers.get_basetemp()}/{faucet_addr}.lock"): try: logging.disable(logging.ERROR) for src in src_addrs: fund_dst = [clusterlib.TxOut(address=faucet_addr, amount=amount)] fund_tx_files = clusterlib.TxFiles(signing_key_files=[src.skey_file]) # try to return funds; don't mind if there's not enough funds for fees etc. try: cluster_obj.send_funds( src_address=src.address, destinations=fund_dst, tx_name=tx_name, tx_files=fund_tx_files, destination_dir=destination_dir, ) except Exception: pass finally: logging.disable(logging.NOTSET)
def update_params( cluster_obj: clusterlib.ClusterLib, src_addr_record: clusterlib.AddressRecord, update_proposals: List[UpdateProposal], ) -> None: """Update params using update proposal.""" _cli_args = [(u.arg, str(u.value)) for u in update_proposals] cli_args = list(itertools.chain.from_iterable(_cli_args)) with helpers.FileLockIfXdist(f"{helpers.get_basetemp()}/update_params.lock"): LOGGER.info("Waiting for new epoch to submit proposal.") cluster_obj.wait_for_new_epoch() cluster_obj.submit_update_proposal( cli_args=cli_args, src_address=src_addr_record.address, src_skey_file=src_addr_record.skey_file, tx_name=helpers.get_timestamped_rand_str(), ) LOGGER.info(f"Update Proposal submitted ({cli_args})") cluster_obj.wait_for_new_epoch() protocol_params = cluster_obj.get_protocol_params() for u in update_proposals: # TODO: handle nested dictionaries if not u.name: continue updated_value = protocol_params[u.name] if str(updated_value) != str(u.value): raise AssertionError( f"Cluster update proposal failed! Param value for {u.name}: {updated_value}.\n" f"Expected: {u.value}\n" f"Tip: {cluster_obj.get_tip()}" )
def update_params_build( cluster_obj: clusterlib.ClusterLib, src_addr_record: clusterlib.AddressRecord, update_proposals: List[UpdateProposal], ) -> None: """Update params using update proposal. Uses `cardano-cli transaction build` command for building the transactions. """ if not update_proposals: return _cli_args = [(u.arg, str(u.value)) for u in update_proposals] cli_args = list(itertools.chain.from_iterable(_cli_args)) temp_template = helpers.get_timestamped_rand_str() # assumption is update proposals are submitted near beginning of epoch epoch = cluster_obj.get_epoch() out_file = cluster_obj.gen_update_proposal( cli_args=cli_args, epoch=epoch, tx_name=temp_template, ) tx_files = clusterlib.TxFiles( proposal_files=[out_file], signing_key_files=[ *cluster_obj.genesis_keys.delegate_skeys, Path(src_addr_record.skey_file), ], ) tx_output = cluster_obj.build_tx( src_address=src_addr_record.address, tx_name=f"{temp_template}_submit_proposal", tx_files=tx_files, fee_buffer=2000_000, ) tx_signed = cluster_obj.sign_tx( tx_body_file=tx_output.out_file, signing_key_files=tx_files.signing_key_files, tx_name=f"{temp_template}_submit_proposal", ) cluster_obj.submit_tx(tx_file=tx_signed, txins=tx_output.txins) LOGGER.info(f"Update Proposal submitted ({cli_args})")
def update_params( cluster_obj: clusterlib.ClusterLib, src_addr_record: clusterlib.AddressRecord, update_proposals: List[UpdateProposal], ) -> None: """Update params using update proposal.""" if not update_proposals: return _cli_args = [(u.arg, str(u.value)) for u in update_proposals] cli_args = list(itertools.chain.from_iterable(_cli_args)) cluster_obj.submit_update_proposal( cli_args=cli_args, src_address=src_addr_record.address, src_skey_file=src_addr_record.skey_file, tx_name=helpers.get_timestamped_rand_str(), ) LOGGER.info(f"Update Proposal submitted ({cli_args})")
def return_funds_to_faucet( *src_addrs: clusterlib.AddressRecord, cluster_obj: clusterlib.ClusterLib, faucet_addr: str, amount: Union[int, List[int]] = -1, tx_name: Optional[str] = None, destination_dir: FileType = ".", ) -> None: """Send `amount` from all `src_addrs` to `faucet_addr`. The amount of "-1" means all available funds. """ tx_name = tx_name or helpers.get_timestamped_rand_str() tx_name = f"{tx_name}_return_funds" if isinstance(amount, int): amount = [amount] * len(src_addrs) with locking.FileLockIfXdist( f"{temptools.get_basetemp()}/{faucet_addr}.lock"): try: logging.disable(logging.ERROR) for addr, amount_rec in zip(src_addrs, amount): fund_dst = [ clusterlib.TxOut(address=faucet_addr, amount=amount_rec) ] fund_tx_files = clusterlib.TxFiles( signing_key_files=[addr.skey_file]) # try to return funds; don't mind if there's not enough funds for fees etc. with contextlib.suppress(Exception): cluster_obj.send_funds( src_address=addr.address, destinations=fund_dst, tx_name=tx_name, tx_files=fund_tx_files, destination_dir=destination_dir, ) finally: logging.disable(logging.NOTSET)
cluster_obj: clusterlib.ClusterLib, amount: int = 2_000_000, tx_name: Optional[str] = None, destination_dir: FileType = ".", ) -> None: """Send `amount` from genesis addr to all `dst_addrs`.""" fund_dst = [ clusterlib.TxOut(address=d, amount=amount) for d in dst_addrs if cluster_obj.get_address_balance(d) < amount ] if not fund_dst: return with helpers.FileLockIfXdist(f"{helpers.get_basetemp()}/{cluster_obj.genesis_utxo_addr}.lock"): tx_name = tx_name or helpers.get_timestamped_rand_str() tx_name = f"{tx_name}_genesis_funding" fund_tx_files = clusterlib.TxFiles( signing_key_files=[ *cluster_obj.genesis_keys.delegate_skeys, cluster_obj.genesis_keys.genesis_utxo_skey, ] ) cluster_obj.send_funds( src_address=cluster_obj.genesis_utxo_addr, destinations=fund_dst, tx_name=tx_name, tx_files=fund_tx_files, destination_dir=destination_dir, )