def OnCoinsChanged(self, added, changed, deleted): for coin in added: addr_hash = bytes(coin.Output.ScriptHash.Data) try: address = Address.get(ScriptHash=addr_hash) c = Coin( TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex, AssetId=bytes(coin.Output.AssetId.Data), Value=coin.Output.Value.value, ScriptHash=bytes(coin.Output.ScriptHash.Data), State=coin.State, Address=address ) c.save() except Exception as e: logger.error("[Path: %s ] Could not create coin: %s " % (self._path, e)) for coin in changed: try: c = Coin.get(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex) c.State = coin.State c.save() except Exception as e: logger.error("[Path: %s ] could not change coin %s %s (coin to change not found)" % (self._path, coin, e)) for coin in deleted: try: c = Coin.get(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex) c.delete_instance() except Exception as e: logger.error("[Path: %s] could not delete coin %s %s " % (self._path, coin, e))
def OnCoinsChanged(self, added, changed, deleted): for coin in added: addr_hash = bytes(coin.Output.ScriptHash.Data) try: address = Address.get(ScriptHash=addr_hash) c = Coin(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex, AssetId=bytes(coin.Output.AssetId.Data), Value=coin.Output.Value.value, ScriptHash=bytes(coin.Output.ScriptHash.Data), State=coin.State, Address=address) c.save() logger.debug("saved coin %s " % c) except Exception as e: logger.error("COULDN'T SAVE!!!! %s " % e) raise for coin in changed: for hold in self._holds: if hold.Reference == coin.Reference and coin.State & CoinState.Spent > 0: hold.IsComplete = True hold.save() try: c = Coin.get(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex) c.State = coin.State c.save() except Exception as e: logger.error( "Coulndn't change coin %s %s (coin to change not found)" % (coin, e)) raise for coin in deleted: for hold in self._holds: if hold.Reference == coin.Reference: hold.IsComplete = True hold.save() try: c = Coin.get(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex) c.delete_instance() except Exception as e: logger.error("could not delete coin %s %s " % (coin, e)) raise
def DeleteAddress(self, script_hash): success, coins_toremove = super(UserWallet, self).DeleteAddress(script_hash) for coin in coins_toremove: try: c = Coin.get(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex) c.delete_instance() except Exception as e: logger.error("Could not delete coin %s %s " % (coin, e)) todelete = bytes(script_hash.ToArray()) for c in Contract.select(): address = c.Address if address.ScriptHash == todelete: c.delete_instance() address.delete_instance() try: address = Address.get(ScriptHash=todelete) address.delete_instance() except Exception as e: pass return True, coins_toremove
def OnCoinsChanged(self, added, changed, deleted): for coin in added: addr_hash = bytes(coin.Output.ScriptHash.Data) try: address = Address.get(ScriptHash=addr_hash) c = Coin( TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex, AssetId=bytes(coin.Output.AssetId.Data), Value=coin.Output.Value.value, ScriptHash=bytes(coin.Output.ScriptHash.Data), State=coin.State, Address=address ) c.save() logger.debug("saved coin %s " % c) except Exception as e: logger.error("COULDN'T SAVE!!!! %s " % e) for coin in changed: for hold in self._holds: if hold.Reference == coin.Reference and coin.State & CoinState.Spent > 0: hold.IsComplete = True hold.save() try: c = Coin.get(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex) c.State = coin.State c.save() except Exception as e: logger.error("Coulndn't change coin %s %s (coin to change not found)" % (coin, e)) for coin in deleted: for hold in self._holds: if hold.Reference == coin.Reference: hold.IsComplete = True hold.save() try: c = Coin.get(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex) c.delete_instance() except Exception as e: logger.error("could not delete coin %s %s " % (coin, e))
def OnCoinsChanged(self, added, changed, deleted): if len(added) > 0 or len(changed) > 0 or len(deleted) > 0: pass for coin in added: addr_hash = bytes(coin.Output.ScriptHash.Data) address = Address.get(ScriptHash=addr_hash) try: c = Coin(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex, AssetId=bytes(coin.Output.AssetId.Data), Value=coin.Output.Value.value, ScriptHash=bytes(coin.Output.ScriptHash.Data), State=coin.State, Address=address) c.save() self.__log.debug("saved coin %s " % c) except Exception as e: print("COLUDNT SAVE!!!! %s " % e) for coin in changed: try: c = Coin.get(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex) c.State = coin.State c.save() except Exception as e: print("Coulndnt change coin %s %s" % (coin, e)) self.__log.debug("coin to change not found! %s %s " % (coin, e)) for coin in deleted: try: c = Coin.get(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex) c.delete_instance() except Exception as e: print("Couldnt delete coin %s %s " % (e, coin)) self.__log.debug("could not delete coin %s %s " % (coin, e))
def DeleteAddress(self, script_hash): success, coins_toremove = super(UserWallet, self).DeleteAddress(script_hash) for coin in coins_toremove: try: c = Coin.get(TxId=bytes(coin.Reference.PrevHash.Data), Index=coin.Reference.PrevIndex) c.delete_instance() print("deleted coin!!!") except Exception as e: print("Couldnt delete coin %s %s " % (e, coin)) self.__log.debug("could not delete coin %s %s " % (coin, e)) address = Address.get(ScriptHash=bytes(script_hash.ToArray())) address.delete_instance() return True, coins_toremove