def execute(self, arguments): wallet = PromptData.Wallet if len(arguments) != 1: print("Please specify the required parameter") return False hash_string = arguments[0] try: script_hash = UInt160.ParseString(hash_string) except Exception: # because UInt160 throws a generic exception. Should be fixed in the future print("Invalid script hash") return False # try to find token and collect some data try: token = ModelNEP5Token.get(ContractHash=script_hash) except peewee.DoesNotExist: print(f"Could not find a token with script_hash {arguments[0]}") return False success = wallet.DeleteNEP5Token(script_hash) if success: print( f"Token {token.Symbol} with script_hash {arguments[0]} deleted" ) else: # probably unreachable to due token check earlier. Better safe than sorrow print(f"Could not find a token with script_hash {arguments[0]}") return success
def DeleteNEP5Token(self, token): success = super(UserWallet, self).DeleteNEP5Token(token) try: db_token = NEP5Token.get(ContractHash=token.ScriptHash.ToBytes()) db_token.delete_instance() except Exception as e: pass return success
def DeleteNEP5Token(self, script_hash): token = super(UserWallet, self).DeleteNEP5Token(script_hash) try: db_token = NEP5Token.get(ContractHash=token.ScriptHash.ToBytes()) db_token.delete_instance() except Exception as e: return False return True
def AddNEP5Token(self, token): super(UserWallet, self).AddNEP5Token(token) try: db_token = NEP5Token.get(ContractHash=token.ScriptHash.ToBytes()) db_token.delete_instance() except Exception as e: pass db_token = NEP5Token.create(ContractHash=token.ScriptHash.ToBytes(), Name=token.name, Symbol=token.symbol, Decimals=token.decimals) db_token.save() return True
def AddNEP5Token(self, token): super(UserWallet, self).AddNEP5Token(token) try: db_token = NEP5Token.get(ContractHash=token.ScriptHash.ToBytes()) db_token.delete_instance() except Exception as e: pass db_token = NEP5Token.create( ContractHash=token.ScriptHash.ToBytes(), Name=token.name, Symbol=token.symbol, Decimals=token.decimals ) db_token.save() return True