Exemplo n.º 1
0
 def _address_from_vout(self, txid, vout):
     script = vout.scriptPubKey
     if len(script) >= 38 and script[:6] == bitcoin.core.WITNESS_COINBASE_SCRIPTPUBKEY_MAGIC:
         return
     try:
         script = CScript(vout.scriptPubKey)
         if script.is_unspendable():
             self.log.warn("Unspendable %s" % vout.scriptPubKey)
             if vout.scriptPubKey[2:4] == b'\xfe\xab':
                 m = vout.scriptPubKey[4:].decode('utf-8')
                 Message.create(message=m)
             return
         return str(TX_CBitcoinAddress.from_scriptPubKey(script))
     except:
         self.log.warn('scriptPubKey invalid txid=%s scriptPubKey=%s value=%s' % (txid, b2lx(vout.scriptPubKey), vout.nValue))
Exemplo n.º 2
0
    def parse_vout(self, tx, txid, tx_data, vout, idx, batch=None, blockHeight=None):
        script = vout.scriptPubKey
        if len(script) >= 38 and script[:6] == bitcoin.core.WITNESS_COINBASE_SCRIPTPUBKEY_MAGIC:
            return
        try:
            script = CScript(vout.scriptPubKey)
            if script.is_unspendable():
                self.log.warn("Unspendable %s" % vout.scriptPubKey)
                if vout.scriptPubKey[2:4] == b'\xfe\xab':
                    m = vout.scriptPubKey[4:].decode('utf-8')
                    Message.create(message=m)
                return
            address = str(TX_CBitcoinAddress.from_scriptPubKey(script))
        except:
            self.log.warn('scriptPubKey invalid txid=%s scriptPubKey=%s value=%s' % (txid, b2lx(vout.scriptPubKey), vout.nValue))
            return
        value = vout.nValue
        self.pututxo(txid, idx, address, value, wb=batch, scriptPubKey=vout.scriptPubKey.hex(), blockHeight=blockHeight)
        tx_data["vout"].append({"address": address, "value": value, "vout": idx})
        if address in tx_data["addresses_out"]:
            tx_data["addresses_out"][address] += value
        else:
            tx_data["addresses_out"][address] = value
        tx_data["output_value"] += value

        # Update address tracking only when non-mempool (batch is not none)
        if batch:
            self.log.debug("Updating address %s with value %s" % (address, value))
            if address in self.address_changes:
                self.address_changes[address]['balance'] += value
                self.address_changes[address]['received'] += value
            else:
                self.address_changes[address] = {
                    'balance': value,
                    'received': value,
                    'sent': 0,
                }