Exemplo n.º 1
0
    def check_script(vouts):
        """
        Looks into the vouts list of a transaction and returns the op_return if one exists
        :param vouts: lists of outputs of a transaction
        :return: string representation of the op_return
        """

        for vout in [v for v in vouts[::-1] if v['hex'].startswith('6a')]:
            verb = BlockchainSpider.decode_op_return(vout['hex'])
            action = Spoolverb.from_verb(verb).action
            if action in Spoolverb.supported_actions:
                return verb
        raise Exception("Invalid ascribe transaction")
Exemplo n.º 2
0
    def check_script(vouts):
        """
        Looks into the vouts list of a transaction and returns the op_return if one exists
        :param vouts: lists of outputs of a transaction
        :return: string representation of the op_return
        """

        for vout in [v for v in vouts[::-1] if v['hex'].startswith('6a')]:
            verb = BlockchainSpider.decode_op_return(vout['hex'])
            action = Spoolverb.from_verb(verb).action
            if action in Spoolverb.supported_actions:
                return verb
        raise Exception("Invalid ascribe transaction")
Exemplo n.º 3
0
    def history(self, hash):
        """
        Retrieve the ownership tree of all editions of a piece given the hash.

        Args:
            hash (str): Hash of the file to check. Can be created with the
                :class:`File` class

        Returns:
            ownsership tree of all editions of a piece

        .. note:: For now we only support searching the blockchain by
            the piece hash.

        """
        txs = self._t.get(hash, max_transactions=10000)['transactions']
        tree = defaultdict(list)
        number_editions = 0

        for tx in txs:
            _tx = self._t.get(tx['txid'])
            txid = _tx['txid']
            verb_str = BlockchainSpider.check_script(_tx['vouts'])
            verb = Spoolverb.from_verb(verb_str)
            from_address, to_address, piece_address = BlockchainSpider._get_addresses(_tx)
            timestamp_utc = _tx['time']
            action = verb.action

            edition_number = 0
            if action != 'EDITIONS':
                edition_number = verb.edition_number
            else:
                number_editions = verb.num_editions

            tree[edition_number].append({'txid': txid,
                                         'verb': verb_str,
                                         'from_address': from_address,
                                         'to_address': to_address,
                                         'piece_address': piece_address,
                                         'timestamp_utc': timestamp_utc,
                                         'action': action,
                                         'number_editions': number_editions,
                                         'edition_number': edition_number})

        # lets update the records with the number of editions of the piece since we do not know
        # this information before the EDITIONS transaction
        for edition, chain in tree.iteritems():
            [d.update({'number_editions': number_editions}) for d in chain]
        return dict(tree)
Exemplo n.º 4
0
    def history(self, hash):
        """
        Retrieve the ownership tree of all editions of a piece given the hash

        :param hash: Hash of the file to check. Can be created with the File class
        :return: ownsership tree of all editions of a piece
        """

        # For now we only support searching the blockchain by the piece hash
        txs = self._t.get(hash, max_transactions=10000)['transactions']
        tree = defaultdict(list)
        number_editions = 0

        for tx in txs:
            _tx = self._t.get(tx['txid'])
            txid = _tx['txid']
            verb_str = BlockchainSpider.check_script(_tx['vouts'])
            verb = Spoolverb.from_verb(verb_str)
            from_address, to_address, piece_address = BlockchainSpider._get_addresses(
                _tx)
            timestamp_utc = _tx['time']
            action = verb.action

            edition_number = 0
            if action != 'EDITIONS':
                edition_number = verb.edition_number
            else:
                number_editions = verb.num_editions

            tree[edition_number].append({
                'txid': txid,
                'verb': verb_str,
                'from_address': from_address,
                'to_address': to_address,
                'piece_address': piece_address,
                'timestamp_utc': timestamp_utc,
                'action': action,
                'number_editions': number_editions,
                'edition_number': edition_number
            })

        # lets update the records with the number of editions of the piece since we do not know
        # this information before the EDITIONS transaction
        for edition, chain in tree.iteritems():
            [d.update({'number_editions': number_editions}) for d in chain]
        return dict(tree)