Example #1
0
def assemble_order(rein, document):
    """
    Take one document and build the entire order based on it. The idea here is that one Job ID should
    allow us to query each available server for each document type that is associated with it, then
    filter out bogus shit by focusing on who's signed correct stuff. This kind of command can also
    look for attempted changes in foundational info like participants public keys and redeem scripts.
    If this works well, we can reduce how much data is required at each stage. Finally, we should
    be able to serialize a job from end to end so it can be easily reviewed by a mediator.
    """
    parsed = parse_document(document.contents)
    if 'Job ID' not in parsed:
        return 0
    job_id = parsed['Job ID']
    urls = Bucket.get_urls(rein)
    documents = []
    if job_id:
        for url in urls:
            # queries remote server for all docs associated with a job_id
            res = Document.get_documents_by_job_id(rein, url, job_id)
            if res:
                documents += res
        order_id = Order.get_order_id(rein, job_id)
        if not order_id:
            o = Order(job_id, testnet=rein.testnet)
            rein.session.add(o)
            rein.session.commit()

    for document in documents:
        doc_type = Document.get_document_type(document)
        if not doc_type:
            rein.log.info('doc_type not detected')
            continue
        doc_hash = Document.calc_hash(document)
        d = rein.session.query(Document).filter(
            Document.doc_hash == doc_hash).first()
        if d:
            d.set_order_id(order_id)
            rein.session.add(d)
        else:
            new_document = Document(rein,
                                    doc_type,
                                    document,
                                    order_id,
                                    'remote',
                                    source_key=None,
                                    sig_verified=True,
                                    testnet=rein.testnet)
            rein.session.add(new_document)
        rein.session.commit()

    return len(documents)
Example #2
0
def check_redeem_scripts(document):
    ret = parse_document(document)
    if u'Primary escrow redeem script' in ret.keys():
        pubkeys = [ret['Job creator public key'], ret['Worker public key'], ret['Mediator public key']]
        if not check_2_of_3(parse_script(ret[u'Primary escrow redeem script']), pubkeys):
            click.echo("2-of-3 check failed")
            return False

    if u'Mediator escrow redeem script' in ret.keys():
        pubkeys = [ret['Job creator public key'], ret['Worker public key']]
        if not check_mandatory_multisig(parse_script(ret[u'Mediator escrow redeem script']),
                                        ret['Mediator public key'], pubkeys):
            click.echo("2-of-3 check failed")
            return False
    return True
Example #3
0
def get_document_type(document):
    parsed = parse_document(document)
    titles = {'Rein User Enrollment':    'enrollment',
              'Rein Job':                'job_posting',
              'Rein Bid':                'bid',
              'Rein Offer':              'offer',
              'Rein Delivery':           'delivery',
              'Rein Accept Delivery':    'accept',
              'Rein Dispute Delivery':   'creatordispute',
              'Rein Dispute Offer':      'workerdispute',
              'Rein Dispute Resolution': 'resolution',
             }
    if 'Title' in parsed:
        return titles[parsed['Title']]
    return None
Example #4
0
 def get_document_type(document):
     parsed = parse_document(document)
     titles = {
         'Rein User Enrollment': 'enrollment',
         'Rein Job': 'job_posting',
         'Rein Bid': 'bid',
         'Rein Offer': 'offer',
         'Rein Delivery': 'delivery',
         'Rein Accept Delivery': 'accept',
         'Rein Dispute Delivery': 'creatordispute',
         'Rein Dispute Offer': 'workerdispute',
         'Rein Dispute Resolution': 'resolution',
     }
     if 'Title' in parsed:
         return titles[parsed['Title']]
     return None
Example #5
0
def assemble_order(rein, document):
    """
    Take one document and build the entire order based on it. The idea here is that one Job ID should
    allow us to query each available server for each document type that is associated with it, then
    filter out bogus shit by focusing on who's signed correct stuff. This kind of command can also
    look for attempted changes in foundational info like participants public keys and redeem scripts.
    If this works well, we can reduce how much data is required at each stage. Finally, we should
    be able to serialize a job from end to end so it can be easily reviewed by a mediator.
    """
    parsed = parse_document(document.contents)
    if 'Job ID' not in parsed:
        return 0
    job_id = parsed['Job ID']
    urls = get_urls(rein)
    documents = []
    if job_id:
        for url in urls:
            res = get_documents_by_job_id(rein, url, job_id)
            if res:
                documents += res
        order_id = Order.get_order_id(rein, job_id)
        if not order_id:
            o = Order(job_id, testnet=rein.testnet)
            rein.session.add(o)        
            rein.session.commit()

    for document in documents:
        doc_type = get_document_type(document)
        if not doc_type:
            rein.log.info('doc_type not detected')
            continue
        doc_hash = calc_hash(document)
        d = rein.session.query(Document).filter(Document.doc_hash == doc_hash).first()
        if d:
            d.set_order_id(order_id)
        else:
            new_document = Document(rein, doc_type, document, order_id, 'external', source_key=None, sig_verified=True, testnet=rein.testnet)
            rein.session.add(new_document)

        rein.session.commit()

    return len(documents)
Example #6
0
    def get_by_type(rein, doc_type):
        docs = rein.session.query(Document).filter(and_(Document.testnet == rein.testnet,
                                                        Document.source_url == 'remote')).all()

        # convert doc_type to nice title (bid -> "Rein Bid")
        target = ''
        for title in Document.titles:
            if Document.titles[title] == doc_type:
                target = title
        if not target:
            Exception('Non-existent doc_type requested')

        res = []
        for d in docs:
            parsed = parse_document(d.contents)
            if 'Title' in parsed:
                if parsed['Title'] == target:
                    parsed['id'] = d.id
                    res.append(parsed)
        return res
Example #7
0
def check_redeem_scripts(document):
    ret = parse_document(document)
    if u'Primary escrow redeem script' in ret.keys():
        pubkeys = [
            ret['Job creator public key'], ret['Worker public key'],
            ret['Mediator public key']
        ]
        if not check_2_of_3(parse_script(ret[u'Primary escrow redeem script']),
                            pubkeys):
            click.echo("2-of-3 check failed")
            return False

    if u'Mediator escrow redeem script' in ret.keys():
        pubkeys = [ret['Job creator public key'], ret['Worker public key']]
        if not check_mandatory_multisig(
                parse_script(ret[u'Mediator escrow redeem script']),
                ret['Mediator public key'], pubkeys):
            click.echo("2-of-3 check failed")
            return False
    return True
Example #8
0
 def get_document_type(document):
     parsed = parse_document(document)
     if 'Title' in parsed:
         return Document.titles[parsed['Title']]
     return None