def test_get_set_stored_gas_price(self): """Checks default stored gas price and set method.""" # checks default assert Settings.get_stored_gas_price() == 4 # checks set Settings.set_stored_gas_price(42) assert Settings.get_stored_gas_price() == 42
def test_get_set_is_persistent_keystore(self): """Checks default persist value and set method.""" # checks default assert Settings.is_persistent_keystore() is False # checks set Settings.set_is_persistent_keystore(True) assert Settings.is_persistent_keystore() is True
def test_get_set_stored_network(self): """Checks default stored network and set method.""" # checks default assert Settings.get_stored_network() == ChainID.MAINNET # checks set Settings.set_stored_network(ChainID.ROPSTEN) assert Settings.get_stored_network() == ChainID.ROPSTEN
def load_settings(self): """Load json store settings to UI properties.""" self.is_stored_mainnet = Settings.is_stored_mainnet() self.is_stored_testnet = Settings.is_stored_testnet() self.stored_gas_price = Settings.get_stored_gas_price() is_persistent_keystore = (Settings.is_persistent_keystore() and check_write_permission()) self.set_persist_keystore_switch_state(is_persistent_keystore)
def sync_keystore_to_non_persistent(cls): """Copies keystore from persistent to non persistent storage.""" # TODO: handle dir doesn't exist source_dir = os.path.join(Settings.get_persistent_keystore_path(), KEYSTORE_DIR_SUFFIX) destination_dir = os.path.join( Settings.get_non_persistent_keystore_path(), KEYSTORE_DIR_SUFFIX) cls.sync_to_directory(source_dir, destination_dir)
def store_is_persistent_keystore(self): """ Saves the persistency option to the store. Note that to save `True` we also check if we have write permissions. """ persist_keystore = self.is_ui_persistent_keystore() persist_keystore = persist_keystore and check_write_permission() persistency_toggled = (Settings.is_persistent_keystore() != persist_keystore) if persistency_toggled: self.sync_keystore(persist_keystore) Settings.set_is_persistent_keystore(persist_keystore)
def test_get_android_keystore_prefix(self): """ The keystore prefix should be the same as user_data_dir by default. But it can also be persisted to the sdcard. """ assert Settings.is_persistent_keystore() is False prefix = Settings._get_android_keystore_prefix() assert prefix == self.app.user_data_dir with mock.patch.object(Settings, 'is_persistent_keystore', return_value=True): prefix = Settings._get_android_keystore_prefix() assert prefix == '/sdcard/etheroll'
def pyetheroll(self): """ Gets or creates the Etheroll object. Also recreates the object if the chain_id changed. """ chain_id = Settings.get_stored_network() return Etheroll.get_or_create(chain_id)
def pyetheroll(self): """ Gets or creates the Etheroll object. Also recreates the object if the chain_id changed. """ chain_id = Settings.get_stored_network() api_key = get_etherscan_api_key(API_KEY_PATH) return Etheroll.get_or_create(api_key, chain_id)
def send(self, address, amount_eth): """Retrieves fields to complete the `transaction()` call.""" gas_price_gwei = Settings.get_stored_gas_price() account = self.current_account if account is None: self.on_account_none() return wallet_path = account.path password = self.get_account_password( account, lambda: self.send(address, amount_eth)) if password is not None: self.transaction(address, amount_eth, wallet_path, password, gas_price_gwei)
def roll(self): """ Retrieves bet parameters from user input and sends it as a signed transaction to the smart contract. """ roll_screen = self.roll_screen roll_input = roll_screen.get_roll_input() bet_size_eth = roll_input['bet_size'] chances = roll_input['chances'] gas_price_gwei = Settings.get_stored_gas_price() account = self.current_account if account is None: self.on_account_none() return wallet_path = account.path password = self.get_account_password(account, self.roll) if password is not None: self.player_roll_dice(bet_size_eth, chances, wallet_path, password, gas_price_gwei) # restarts roll polling service to reset the roll activity period self.start_services()
def account_utils(self): """Gets or creates the AccountUtils object so it loads lazily.""" from etherollapp.ethereum_utils import AccountUtils keystore_dir = Settings.get_keystore_path() return AccountUtils.get_or_create(keystore_dir)
def store_network(self): """Saves selected network to the store.""" network = self.get_ui_network() Settings.set_stored_network(network)
def store_gas_price(self): """Saves gas price value to the store.""" gas_price = self.get_ui_gas_price() Settings.set_stored_gas_price(gas_price)
def test_is_stored_testnet(self): Settings.set_stored_network(ChainID.MAINNET) assert Settings.is_stored_testnet() is False Settings.set_stored_network(ChainID.ROPSTEN) assert Settings.is_stored_testnet() is True
def account_utils(self): """ Gets or creates the AccountUtils object so it loads lazily. """ keystore_dir = Settings.get_keystore_path() return AccountUtils.get_or_create(keystore_dir)
def load_keystore_path(self, dt=None): """Updates keystore path displayed in the UI.""" self.keystore_path = Settings.get_keystore_path()