def legacy_sign_blockchain_transaction_v1(network: str, transaction: Dict[str, Any]) -> Dict[str, str]: if network in ["BTC_MAINNET", "BTC_TESTNET3"]: # Check if legacy bitcoin network client = interchain_dao.get_interchain_client("bitcoin", network) else: # Must be a legacy ethereum network client = interchain_dao.get_interchain_client("ethereum", network) return {"signed": client.sign_transaction(transaction)}
def test_get_interchain_client_gets_from_storage(self, mock_btc, mock_eth, mock_storage): interchain_dao.get_interchain_client("bitcoin", "banana") interchain_dao.get_interchain_client("ethereum", "banana") mock_btc.assert_called_once_with("thing") mock_eth.assert_called_once_with("thing") mock_storage.assert_has_calls([ call("INTERCHAINS/bitcoin/banana"), call("INTERCHAINS/ethereum/banana") ])
def update_binance_interchain_v1(name: str, user_data: Dict[str, Any]) -> Dict[str, Any]: # Get current client current_client = cast( bnb.BinanceNetwork, interchain_dao.get_interchain_client("binance", name)) # Merge user data with existing data client_data = { "version": "1", "name": name, "testnet": user_data["testnet"] if isinstance(user_data.get("testnet"), bool) else current_client.testnet, "private_key": user_data["private_key"] if isinstance(user_data.get("private_key"), str) else current_client.get_private_key(), "node_url": user_data["node_url"] if isinstance(user_data.get("node_url"), str) else current_client.node_url, "rpc_port": user_data["rpc_port"] if isinstance(user_data.get("rpc_port"), int) else current_client.rpc_port, "api_port": user_data["api_port"] if isinstance(user_data.get("api_port"), int) else current_client.api_port, } # Create and save updated client return create_binance_interchain_v1(client_data, conflict_check=False)
def update_ethereum_interchain_v1(name: str, user_data: Dict[str, Any]) -> Dict[str, Any]: # Get current client current_client = cast( eth.EthereumNetwork, interchain_dao.get_interchain_client("ethereum", name)) # Merge user data with existing data client_data = { "version": "1", "name": name, "private_key": user_data["private_key"] if isinstance(user_data.get("private_key"), str) else current_client.get_private_key(), "rpc_address": user_data["rpc_address"] if isinstance( user_data.get("rpc_address"), str) else current_client.rpc_address, "chain_id": user_data["chain_id"] if isinstance(user_data.get("chain_id"), int) else current_client.chain_id, } # Create and save updated client return create_ethereum_interchain_v1(client_data, conflict_check=False)
def update_bitcoin_interchain_v1(name: str, user_data: Dict[str, Any]) -> Dict[str, Any]: # Get current client current_client = cast( btc.BitcoinNetwork, interchain_dao.get_interchain_client("bitcoin", name)) # Merge user data with existing data client_data = { "version": "1", "name": name, "testnet": user_data["testnet"] if isinstance(user_data.get("testnet"), bool) else current_client.testnet, "private_key": user_data["private_key"] if isinstance(user_data.get("private_key"), str) else current_client.get_private_key(), "rpc_address": user_data["rpc_address"] if isinstance( user_data.get("rpc_address"), str) else current_client.rpc_address, "rpc_authorization": user_data["rpc_authorization"] if isinstance( user_data.get("rpc_authorization"), str) else current_client.authorization, "utxo_scan": user_data["utxo_scan"] if isinstance(user_data.get("utxo_scan"), bool) else False, } # Create and save updated client return create_bitcoin_interchain_v1(client_data, conflict_check=False)
def sign_interchain_transaction_v1(blockchain: str, name: str, transaction: Dict[str, Any]) -> Dict[str, str]: client = interchain_dao.get_interchain_client(blockchain, name) # Delete the user provided version field before passing it to sign transaction try: del transaction["version"] except KeyError: # If the key doesn't exist, that is fine pass return {"signed": client.sign_transaction(transaction)}
def legacy_get_blockchain_addresses_v1() -> Dict[str, str]: return { "eth_mainnet": interchain_dao.get_interchain_client("ethereum", "ETH_MAINNET").address, "eth_ropsten": interchain_dao.get_interchain_client("ethereum", "ETH_ROPSTEN").address, "etc_mainnet": interchain_dao.get_interchain_client("ethereum", "ETC_MAINNET").address, "btc_mainnet": interchain_dao.get_interchain_client("bitcoin", "BTC_MAINNET").address, "btc_testnet3": interchain_dao.get_interchain_client("bitcoin", "BTC_TESTNET3").address, }
def publish_interchain_transaction_v1( blockchain: str, name: str, signed_transaction: str) -> Dict[str, str]: client = interchain_dao.get_interchain_client(blockchain, name) try: return {"transaction": client.publish_transaction(signed_transaction)} except Exception as e: # Try to surface a usable error for the user if there is a failure raise exceptions.InterchainPublishError(str(e))
def get_interchain_v1(blockchain: str, name: str) -> Dict[str, Any]: return _get_output_dto_v1(interchain_dao.get_interchain_client(blockchain, name))