def job_prompt(rein, jobs): """ Prompt user for jobs they can bid on. Filters out jobs they created or are mediator for. """ key = pubkey(rein.user.dkey) valid_jobs = [] for j in jobs: if j['Job creator public key'] != key and j[ 'Mediator public key'] != key: valid_jobs.append(j) i = 0 for j in valid_jobs: click.echo('%s - %s - %s - %s' % (str(i), j["Job creator"], j['Job name'], shorten(j['Description']))) i += 1 choice = get_choice(jobs, 'job') if choice == 'q': return False job = jobs[choice] click.echo( 'You have chosen a Job posted by %s.\n\nFull description: %s\n\nPlease pay attention ' 'to each requirement and provide a time frame to complete the job. (Ctrl-c to abort)\n' % (job['Job creator'], job['Description'])) return job
def enroll(rein): Base.metadata.create_all(rein.engine) user = rein.user mediator_extras = '' if user.will_mediate: mediator_extras = "\nMediator public key: %s\nMediator fee: %s%%" % \ (pubkey(user.dkey), user.mediator_fee) enrollment = "Rein User Enrollment\nUser: %s\nContact: %s\nMaster signing address: %s" \ "\nDelegate signing address: %s\nWilling to mediate: %s%s" % \ (user.name, user.contact, user.maddr, user.daddr, user.will_mediate, mediator_extras) if rein.testnet: enrollment += '\nTestnet: True' f = open(rein.enroll_filename, 'w') f.write(enrollment) f.close() click.echo("%s\n" % enrollment) done = False while not done: filename = click.prompt(hilight("File containing signed statement", True, True), type=str, default=rein.sig_enroll_filename) if os.path.isfile(filename): done = True else: click.echo("File not found. Please check the file name and location and try again.") f = open(filename, 'r') signed = f.read() res = validate_enrollment(signed) if res: User.set_enrolled(rein, user) # insert signed document into documents table as type 'enrollment' document = Document(rein, 'enrollment', signed, sig_verified=True, testnet=rein.testnet) rein.session.add(document) rein.session.commit() return res
def bid_prompt(rein, bids): """ Prompts user to choose a bid on one of their jobs. This means they should be the job creator and not the worker or mediator. """ i = 0 valid_bids = [] key = pubkey(rein.user.dkey) for b in bids: if 'Description' not in b or b['Job creator public key'] != key: continue click.echo('%s - %s - %s - %s - %s BitCoin' % (str(i), b['Job name'], b["Worker"], shorten(b['Description']), b['Bid amount (BTC)'])) valid_bids.append(b) i += 1 if len(valid_bids) == 0: click.echo('No bids available.') return None choice = get_choice(valid_bids, 'bid') if choice == 'q': click.echo('None chosen.') return False bid = valid_bids[choice] click.echo('You have chosen %s\'s bid.\n\nFull description: %s\nBid amount (BTC): %s\n\nPlease review carefully before accepting. (Ctrl-c to abort)' % (bid['Worker'], bid['Description'], bid['Bid amount (BTC)'])) return bid
def bid_prompt(rein, bids): """ Prompts user to choose a bid on one of their jobs. This means they should be the job creator and not the worker or mediator. """ i = 0 valid_bids = [] key = pubkey(rein.user.dkey) for b in bids: if 'Description' not in b or b['Worker public key'] == key or b[ 'Mediator public key'] == key: continue click.echo('%s - %s - %s - %s - %s BitCoin' % (str(i), b['Job name'], b["Worker"], shorten(b['Description']), b['Bid amount (BTC)'])) valid_bids.append(b) i += 1 if len(valid_bids) == 0: return None choice = get_choice(valid_bids, 'bid') if choice == 'q': return False bid = valid_bids[choice] click.echo( 'You have chosen %s\'s bid.\n\nFull description: %s\nBid amount (BTC): %s\n\nPlease review carefully before accepting. (Ctrl-c to abort)' % (bid['Worker'], bid['Description'], bid['Bid amount (BTC)'])) return bid
def job_prompt(rein, jobs): """ Prompt user for jobs they can bid on. Filters out jobs they created or are mediator for. """ key = pubkey(rein.user.dkey) valid_jobs = [] for j in jobs: if j['Job creator public key'] != key and j['Mediator public key'] != key: valid_jobs.append(j) if len(valid_jobs) == 0: click.echo('None found.') return None i = 0 for j in valid_jobs: click.echo('%s - %s - %s - %s' % (str(i), j["Job creator"], j['Job name'], shorten(j['Description']))) i += 1 choice = get_choice(valid_jobs, 'job') if choice == 'q': return False job = valid_jobs[choice] click.echo('You have chosen a Job posted by %s.\n\nFull description: %s\n\nPlease pay attention ' 'to each requirement and provide a time frame to complete the job. (Ctrl-c to abort)\n' % (job['Job creator'], job['Description'])) return job
def build_enrollment_from_dict(data): mediator_extras = '' if data['will_mediate']: mediator_extras = "\nMediator public key: %s\nMediator fee: %s%%" % \ (pubkey(data['dkey']), data['mediator_fee']) enrollment = "Rein User Enrollment\nUser: %s\nContact: %s\nMaster signing address: %s" \ "\nDelegate signing address: %s\nWilling to mediate: %s%s" % \ (data['name'], data['contact'], data['maddr'], data['daddr'], data['will_mediate'], mediator_extras) if data['testnet']: enrollment += '\nTestnet: True' return enrollment
def build_enrollment(rein): user = rein.user mediator_extras = '' if user.will_mediate: mediator_extras = "\nMediator public key: %s\nMediator fee: %s%%" % \ (pubkey(user.dkey), user.mediator_fee) enrollment = "Rein User Enrollment\nUser: %s\nContact: %s\nMaster signing address: %s" \ "\nDelegate signing address: %s\nWilling to mediate: %s%s" % \ (user.name, user.contact, user.maddr, user.daddr, user.will_mediate, mediator_extras) if rein.testnet: enrollment += '\nTestnet: True' return enrollment
def mediator_prompt(rein, eligible_mediators): mediators = unique(eligible_mediators, 'Mediator public key') key = pubkey(rein.user.dkey) i = 0 for m in mediators: if m["Mediator public key"] == key: mediators.remove(m) continue click.echo('%s - %s - Fee: %s - Public key: %s' % (str(i), m['User'], m['Mediator fee'], m['Mediator public key'])) i += 1 if len(mediators) == 0: click.echo("None found.") return None choice = get_choice(mediators, 'mediator') if choice == 'q': return False return mediators[choice]
def enroll(rein): Base.metadata.create_all(rein.engine) user = rein.user mediator_extras = '' if user.will_mediate: mediator_extras = "\nMediator public key: %s\nMediator fee: %s%%" % \ (pubkey(user.dkey), user.mediator_fee) enrollment = "Rein User Enrollment\nUser: %s\nContact: %s\nMaster signing address: %s" \ "\nDelegate signing address: %s\nWilling to mediate: %s%s" % \ (user.name, user.contact, user.maddr, user.daddr, user.will_mediate, mediator_extras) if rein.testnet: enrollment += '\nTestnet: True' f = open(rein.enroll_filename, 'w') f.write(enrollment) f.close() click.echo("%s\n" % enrollment) done = False while not done: filename = click.prompt(hilight("File containing signed statement", True, True), type=str, default=rein.sig_enroll_filename) if os.path.isfile(filename): done = True else: click.echo( "File not found. Please check the file name and location and try again." ) f = open(filename, 'r') signed = f.read() res = validate_enrollment(signed) if res: User.set_enrolled(rein, user) # insert signed document into documents table as type 'enrollment' document = Document(rein, 'enrollment', signed, sig_verified=True, testnet=rein.testnet) rein.session.add(document) rein.session.commit() return res