Example #1
0
    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))
Example #2
0
    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
Example #3
0
    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))
Example #4
0
    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))