def get_balance(self, wallet_key: str) -> float: """ Retrieves the current scratch balance for the wallet :param wallet_key: The verifying address for the wallet :return: A float representing the current balance of the wallet """ return RS.float(self.r.hget(SCRATCH_KEY, wallet_key))
def get_swap_data(self, hash_lock: str) -> tuple: """ Returns the atomic swap data as a tuple :param hash_lock: The hash lock key for look up :return: A tuple containing (sender, recipient, amount, unix_expiration), or an empty tuple if the hash_lock does not exist in the hash table """ if self.r.hexists(SWAP_KEY, hash_lock): return RS.tuple_from_str(self.r.hget(SWAP_KEY, hash_lock)) else: print("Attempted to get hash_lock={} that doesnt exist in table") return ()
def set_swap_data(self, hash_lock: str, sender: str, recipient: str, amount: float, unix_expiration: str): """ Sets the atomic swap data in the hash table as a condensed tuple :param hash_lock: The hash lock for the swap :param sender: The verifying address for the sender's wallet :param recipient: The verifying address for the recipient's wallet :param amount: The amount for the swap :param unix_expiration: The unix expiration for the swap """ self.r.hset( SWAP_KEY, hash_lock, RS.str_from_tuple((sender, recipient, amount, unix_expiration)))
def get_balance(self, wallet_key: str) -> float: """ Retrieves the current balance for the wallet :param wallet_key: The verifying address for the wallet :return: A float representing the current balance of the wallet """ if self.r.hexists(BALANCE_KEY, wallet_key): return RS.float(self.r.hget(BALANCE_KEY, wallet_key)) else: # raise Exception('(get_balance) Balance could not be found for key: {}'.format(wallet_key)) # TODO ultra hack for testing, remove this log = get_logger("DB.BalanceDriver") log.info( "Could not find wallet {}, returning default 10000".format( wallet_key)) return 10000
def test_int_maker_fail(self): try: rs.int(b'abc') except: self.assertTrue(True)
def test_int_maker(self): self.assertEqual(rs.int(b'100'), 100)
def test_string_maker(self): self.assertEqual(rs.str(b'stuart'), 'stuart')