def do_transfer_from(self, project_id, t_from, t_to, amount): storage = StorageManager() if amount <= 0: return False available_key = concat(t_from, t_to) available_to_to_addr = storage.get_double(project_id, available_key) if available_to_to_addr < amount: print("Insufficient funds approved") return False from_balance = storage.get_double(project_id, t_from) if from_balance < amount: print("Insufficient tokens in from balance") return False to_balance = storage.get_double(project_id, t_to) new_from_balance = from_balance - amount new_to_balance = to_balance + amount storage.put_double(project_id, t_to, new_to_balance) storage.put_double(project_id, t_from, new_from_balance) print("transfer complete") new_allowance = available_to_to_addr - amount if new_allowance == 0: print("removing all balance") storage.delete_double(project_id, available_key) else: print("updating allowance to new allowance") storage.put_double(project_id, available_key, new_allowance) OnTransfer(project_id, t_from, t_to, amount) return True
def do_transfer(self, project_id, t_from, t_to, amount): storage = StorageManager() # Pointless if amount <= 0: return False # Validate address if CheckWitness(t_from): # Pointless if t_from == t_to: print("transfer to self!") return True from_val = storage.get_double(project_id, t_from) if from_val < amount: print("insufficient funds") return False if from_val == amount: storage.delete_double(project_id, t_from) else: difference = from_val - amount storage.put_double(project_id, t_from, difference) to_value = storage.get_double(project_id, t_to) to_total = to_value + amount storage.put_double(project_id, t_to, to_total) OnTransfer(project_id, t_from, t_to, amount) return True else: print("from address is not the tx sender") return False