def payment_info(): """ Retrieve and store the selected set of relays's bitcoin addresses with a new bitcoin keypair """ outputs = {} options = util.Opt(dict(request.args.items())) relays = util.determine_relays(options) for relay in relays['results']: # If this address already has an output, add the share if relay.bitcoin_address in outputs: outputs[relay.bitcoin_address] += relay.donation_share else: outputs[relay.bitcoin_address] = relay.donation_share if outputs: ''' Retrieve last id and provide it when creating next privkey from seed. NOTE: Possible race condition? Two people may get the same address? ''' last_address = ForwardAddress.query.order_by( ForwardAddress.id.desc()).first() previous_id = last_address.id if last_address else 0 donation_request = ForwardAddress(outputs=outputs, previous_n=previous_id) db.session.add(donation_request) db.session.commit() app.logger.info( 'Forwarding adddress {} paying to {} relays created.'.format( donation_request.address, len(outputs))) return Response(json.dumps({ 'status': 'success', 'data': { 'message': 'A new bitcoin address forwarding to the {} selected relays has been created' .format(len(outputs)), 'bitcoin_address': donation_request.address, 'num_unique_addresses': len(outputs) } }), mimetype='application/json'), 201 else: return Response(json.dumps({ 'status': 'We could not find any relays which meet your criteria' }), mimetype='application/json'), 400
def payment_info(): """ Retrieve and store the selected set of relays's bitcoin addresses with a new bitcoin keypair """ outputs = {} options = util.Opt(dict(request.args.items())) relays = util.determine_relays(options) for relay in relays['results']: # If this address already has an output, add the share if relay.bitcoin_address in outputs: outputs[relay.bitcoin_address] += relay.donation_share else: outputs[relay.bitcoin_address] = relay.donation_share if outputs: ''' Retrieve last id and provide it when creating next privkey from seed. NOTE: Possible race condition? Two people may get the same address? ''' last_address = ForwardAddress.query.order_by(ForwardAddress.id.desc()).first() previous_id = last_address.id if last_address else 0 donation_request = ForwardAddress(outputs=outputs, previous_n=previous_id) db.session.add(donation_request) db.session.commit() app.logger.info('Forwarding adddress {} paying to {} relays created.'.format(donation_request.address, len(outputs))) return Response(json.dumps({ 'status': 'success', 'data': { 'message': 'A new bitcoin address forwarding to the {} selected relays has been created'.format(len(outputs)), 'bitcoin_address': donation_request.address, 'num_unique_addresses': len(outputs) }}), mimetype='application/json'), 201 else: return Response(json.dumps({'status': 'We could not find any relays which meet your criteria'}), mimetype='application/json'), 400
def json_result(): options = util.Opt(dict(request.args.items())) relays = util.determine_relays(options) return Response(json.dumps(relays, cls=util.ResultEncoder), mimetype='application/json')