def close( auction_address, keystore: str, jsonrpc: str, gas: int, gas_price: int, nonce: int, auto_nonce: bool, ): web3 = connect_to_json_rpc(jsonrpc) private_key = retrieve_private_key(keystore) contracts = get_deployed_auction_contracts(web3, auction_address) nonce = get_nonce(web3=web3, nonce=nonce, auto_nonce=auto_nonce, private_key=private_key) transaction_options = build_transaction_options(gas=gas, gas_price=gas_price, nonce=nonce) auction_close = contracts.auction.functions.closeAuction() send_function_call_transaction( auction_close, web3=web3, transaction_options=transaction_options, private_key=private_key, )
def deploy_unw_eth( *, web3: Web3, transaction_options: Dict = None, private_key: bytes = None, exchange_address=None, ): if transaction_options is None: transaction_options = {} unw_eth = deploy( "UnwEth", web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) if exchange_address is not None: if exchange_address is not None: function_call = unw_eth.functions.addAuthorizedAddress(exchange_address) send_function_call_transaction( function_call, web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) return unw_eth
def deploy_network( web3, name, symbol, decimals, expiration_time, fee_divisor=0, default_interest_rate=0, custom_interests=True, prevent_mediator_interests=False, exchange_address=None, currency_network_contract_name=None, transaction_options: Dict = None, private_key=None, authorized_addresses=None, ): if transaction_options is None: transaction_options = {} if authorized_addresses is None: authorized_addresses = [] # CurrencyNetwork is the standard contract to deploy, If we're running # tests or trying to export data for testing the python implementation of # private functions, we may want deploy the TestCurrencyNetwork contract # instead. if currency_network_contract_name is None: currency_network_contract_name = "CurrencyNetwork" currency_network = deploy( currency_network_contract_name, web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) if exchange_address is not None: authorized_addresses.append(exchange_address) init_function_call = currency_network.functions.init( name, symbol, decimals, fee_divisor, default_interest_rate, custom_interests, prevent_mediator_interests, expiration_time, authorized_addresses, ) send_function_call_transaction( init_function_call, web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) return currency_network
def initialize_auction_contracts( *, web3, transaction_options=None, contracts: DeployedAuctionContracts, release_timestamp, private_key=None, ) -> None: if transaction_options is None: transaction_options = {} deposit_init = contracts.locker.functions.init(release_timestamp, contracts.slasher.address, contracts.auction.address) send_function_call_transaction( deposit_init, web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) slasher_init = contracts.slasher.functions.init(contracts.locker.address) send_function_call_transaction( slasher_init, web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options)
def test_send_contract_call_set_nonce(test_contract, web3, account_keys): function_call = test_contract.functions.set(200) nonce = 1 # right nonce should be 0 # This should just test, that the nonce is set # Apparently eth_tester raises a validation error if the nonce to high with pytest.raises(eth_utils.ValidationError): send_function_call_transaction( function_call, transaction_options={"nonce": nonce}, web3=web3, private_key=account_keys[2], )
def deploy_identity( web3, owner_address, chain_id=None, transaction_options: Dict = None ): if transaction_options is None: transaction_options = {} identity = deploy("Identity", web3=web3, transaction_options=transaction_options) increase_transaction_options_nonce(transaction_options) if chain_id is None: chain_id = get_chain_id(web3) function_call = identity.functions.init(owner_address, chain_id) send_function_call_transaction( function_call, web3=web3, transaction_options=transaction_options ) increase_transaction_options_nonce(transaction_options) return identity
def report_malicious_validator( web3, transaction_options, private_key, validator_set_contract_address, unsigned_block_header_one, signature_one, unsigned_block_header_two, signature_two, ): validator_set_contract = web3.eth.contract( abi=SIMPLE_REPORT_MALICIOUS_ABI, address=validator_set_contract_address) report_validator_call = validator_set_contract.functions.reportMaliciousValidator( unsigned_block_header_one, signature_one, unsigned_block_header_two, signature_two, ) transaction_receipt = send_function_call_transaction( report_validator_call, web3=web3, transaction_options=transaction_options, private_key=private_key, ) return encode_hex(transaction_receipt.transactionHash)
def test_send_contract_call(test_contract, web3): function_call = test_contract.functions.set(200) receipt = send_function_call_transaction(function_call, web3=web3) assert receipt["status"] assert test_contract.functions.state().call() == 200
def test_send_contract_call_from_private_key(test_contract, web3, account_keys): function_call = test_contract.functions.set(200) receipt = send_function_call_transaction( function_call, web3=web3, private_key=account_keys[2] ) assert receipt["status"] assert test_contract.functions.state().call() == 200
def whitelist_addresses( auction_contract: Contract, whitelist: Sequence[str], *, batch_size, web3, transaction_options=None, private_key=None, ) -> int: """Add all not yet whitelisted addresses in `whitelist` to the whitelisted addresses in the auction contract. Returns the number of new whitelisted addresses""" if transaction_options is None: transaction_options = {} # only whitelist addresses that are not whitelisted yet filtered_whitelist = missing_whitelisted_addresses(auction_contract, whitelist) assert batch_size > 0 chunks = [ filtered_whitelist[i:i + batch_size] for i in range(0, len(filtered_whitelist), batch_size) ] for chunk in chunks: assert len(chunk) <= batch_size add_to_whitelist_call = auction_contract.functions.addToWhitelist( chunk) send_function_call_transaction( add_to_whitelist_call, web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) return len(filtered_whitelist)
def initialize_validator_set_contract( *, web3, transaction_options=None, validator_set_contract, validators, validator_proxy_address, private_key=None ) -> None: if transaction_options is None: transaction_options = {} validator_init = validator_set_contract.functions.init( validators, validator_proxy_address ) send_function_call_transaction( validator_init, web3=web3, transaction_options=transaction_options, private_key=private_key, )
def deploy_proxied_identity( web3, factory_address, implementation_address, signature, *, transaction_options: Dict = None, private_key: bytes = None, ): if transaction_options is None: transaction_options = {} owner = recover_proxy_deployment_signature_owner(web3, factory_address, implementation_address, signature) interface = get_pinned_proxy_interface() initcode = build_initcode( contract_abi=interface["abi"], contract_bytecode=interface["bytecode"], constructor_args=[owner], ) factory_interface = get_contract_interface("IdentityProxyFactory") factory = web3.eth.contract(address=factory_address, abi=factory_interface["abi"]) function_call = factory.functions.deployProxy(initcode, implementation_address, signature) receipt = send_function_call_transaction( function_call, web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) deployment_event = factory.events.ProxyDeployment().processReceipt(receipt) proxy_address = deployment_event[0]["args"]["proxyAddress"] computed_proxy_address = build_create2_address(factory_address, initcode) assert ( computed_proxy_address == proxy_address ), "The computed proxy address does not match the deployed address found via events" identity_interface = get_contract_interface("Identity") proxied_identity = web3.eth.contract(address=proxy_address, abi=identity_interface["abi"]) return proxied_identity
def test_send_contract_call_with_transaction_options(test_contract, web3, account_keys): function_call = test_contract.functions.set(200) transaction_options = {"gas": 199999, "gasPrice": 99} receipt = send_function_call_transaction( function_call, web3=web3, transaction_options=transaction_options, private_key=account_keys[2], ) transaction = web3.eth.getTransaction(receipt.transactionHash) for key, value in transaction_options.items(): assert transaction[key] == value
def initialize_auction_contracts( *, web3, transaction_options=None, contracts: DeployedAuctionContracts, release_timestamp, token_address=None, private_key=None, ) -> None: if transaction_options is None: transaction_options = {} if contracts.slasher is None: raise RuntimeError("Slasher contract not set") if not contracts.locker.functions.initialized().call(): init_args: Tuple = ( release_timestamp, contracts.slasher.address, contracts.auction.address, ) if token_address is not None: init_args += (token_address, ) deposit_init = contracts.locker.functions.init(*init_args) send_function_call_transaction( deposit_init, web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) else: if (contracts.locker.functions.depositorsProxy().call() != contracts.auction.address): raise ValueError( "Locker is already initialized but address of auction in locker and given auction contract do not match" ) if contracts.locker.functions.slasher().call( ) != contracts.slasher.address: raise ValueError( "Locker is already initialized but address of slasher in locker and given slasher contract do not match" ) if not contracts.slasher.functions.initialized().call(): slasher_init = contracts.slasher.functions.init( contracts.locker.address) send_function_call_transaction( slasher_init, web3=web3, transaction_options=transaction_options, private_key=private_key, ) increase_transaction_options_nonce(transaction_options) else: if (contracts.slasher.functions.depositContract().call() != contracts.locker.address): raise ValueError( "Slasher is already initialized but address of locker in slasher and given locker contract do not match" ) if contracts.auction.functions.depositLocker().call( ) != contracts.locker.address: raise ValueError( "Address of deposit locker in auction contract does not match with address of locker" )