示例#1
0
文件: requests.py 项目: pataca/pataca
def get_receive_address(request, data):
	account_name = data['account']

	response = {}

	with createsession(engine) as session:
		try:
			account = session.query(Account).filter_by(name=account_name).one()
		except NoResultFound:
			return error(request, 'Invalid account.')
		except MultipleResultsFound:
			return error(request, 'Account error.')

		generate_new = False

		try:
			accountwallet = session.query(AccountWallet).filter_by(account=account_name).first()
		except NoResultFound:
			generate_new = True

		if generate_new:
			currency = account.currency
			address = get_new_wallet(currency, account_name)

			accountwallet = AccountWallet(account_name, address)
			session.add(accountwallet)
			session.commit()

		response['account'] = accountwallet.account
		response['address'] = accountwallet.address
示例#2
0
文件: requests.py 项目: pataca/pataca
def set_currency_wallet(request, data, user):
	currency_name = data['currency']
	identifier = data['identifier']
	password = data['password']
	defaultrate = Decimal(data['defaultrate'])

	with createsession(engine) as session:
		try:
			currency = session.query(Currency).filter_by(name=currency_name).one()
		except:
			return error(request, 'Currency error')

		try:
			currencywallet = session.query(CurrencyWallet).filter_by(currency=currency).one()
		except MultipleResultsFound:
			for currencywallet_item in currencywallet:
				session.delete(currencywallet_item)

			currencywallet = CurrencyWallet(currency=currency, identifier=identifier, password=password, defaultrate=defaultrate)
		except NoResultFound:
			currencywallet = CurrencyWallet(currency=currency, identifier=identifier, password=password, defaultrate=defaultrate)

		session.add(currencywallet)
		session.commit()

	return success()
示例#3
0
	def process(self, request, urilist):
		ops = self._opdict

		# check URI
		if len(urilist) > 0 and urilist[0] in ops:
			
			if isinstance(ops[urilist[0]], Dispatcher):
				return ops[urilist[0]].process(request, urilist[1:])

			data = json.loads(request.content.getvalue())
			return ops[urilist[0]] (request, data)

		# check op
		try:
			data = json.loads(request.content.getvalue())
		except ValueError:
			data = {}

		if 'op' in data and data['op'] in ops:
			return ops[data['op']] (request, data)
		
		if len(urilist) == 0 and '' in ops:
			return ops[''] (request, data)

		return error(request, 'Request not found.', http_code=404)
示例#4
0
文件: requests.py 项目: pataca/pataca
def get_currency_wallet(request, data, user):
	currency_name = data['currency']

	with createsession(engine) as session:
		try:
			currency = session.query(Currency).filter_by(name=currency_name).one()
		except:
			return error(request, 'Currency error')

		try:
			currencywallet = session.query(CurrencyWallet).filter_by(currency=currency).one()
		except:
			return error(request, 'Currency wallet error.')

		return jsonresponse({
				"identifier": currencywallet.identifier,
				"password": currencywallet.password,
				"defaultrate": currencywallet.defaultrate,
			})
示例#5
0
文件: requests.py 项目: pataca/pataca
def get_currency_rate(request, data, user):
	currency_name = data['currency']

	response = {}

	with createsession(engine) as session:
		try:
			currency = session.query(Currency).filter_by(name=currency_name).one()
		except:
			return error(request, 'Currency error')

		try:
			currencywallet = session.query(CurrencyWallet).filter_by(currency=currency).one()
		except:
			return error(request, 'Currency wallet error.')

		response['currency'] = currency_name
		response['rate'] = currencywallet.get_rate(session)

	return jsonresponse(response)
示例#6
0
文件: requests.py 项目: pataca/pataca
def send(request, data, user):
	orig = data['orig']
	dest = data['dest']
	amount = Decimal(data['amount'])
	description = data['description'] if 'description' in data else ''

	if amount < 0.0:
		return error(request, 'Amount must be greater than zero.')

	with createsession(engine) as session:
		try:
			acc_orig = session.query(Account).filter_by(name=orig).one()
		except NoResultFound:
			return error(request, 'Invalid origin account.')
		except MultipleResultsFound:
			return error(request, 'Account error.', http_code=500)

		# check ownership
		if not acc_orig.is_owner(user, session):
			return error(request, 'Not authorized.')

		# check amount
		if acc_orig.getbalance() < amount:
			return error(request, 'Not enough balance.')

		# get transit account
		transit_acc_name = ACCOUNT_PREFIX + orig.currency.name + '_' + orig
		try:
			transit_acc = session.query(Account).filter_by(name=transit_acc_name).one()
		except NoResultFound:
			transit_acc = Account(name=transit_acc_name, acc_class=account_class, currency=acc_orig.currency)
			session.add(transit_acc)
		except MultipleResultsFound:
			return error(request, 'Account error.')

		# check federation
		try:
			destinfo = resolve_federation(dest)
		except Exception, e:
			return error(request, e.message)

		if isinstance(destinfo, str):
			return error(request, 'Local account.')

		# send to transit account
		movement = acc_orig.transfer_funds(user, transit_acc, amount, description, session)

		# put on the queue
		MovementQueue.put('new', movement=movement, orig=orig, dest=dest, user=user, session=session)

		session.commit()
示例#7
0
文件: utils.py 项目: pataca/pataca
		def verify(request, data, *args, **kwargs):


			not_present = []

			for field in fields:
				if field not in data:
					not_present.append(field)

			if len(not_present) > 0:
				return error(request, 'Fields not present: ' + ', '.join(not_present))

			return func(request, data, *args, **kwargs)
示例#8
0
文件: telnetProxy.py 项目: AKJ/sage
	def enableRemote(self, option):
		"""Hands Negotiation Requests from server"""
		if option == GMCP:
			if self.allow_gmcp:
				# Technically this will make us send IAC DO GMCP twice
				# but we have to do Core.Hello after we enable it
				self._do(GMCP)
				self.gmcp_hello()
				self.gmcp = True
			return self.allow_gmcp
		elif option == EOR:
			return self.allow_eor
		elif option == ATCP:
			return self.allow_atcp
		elif option == COMPRESS2:
			return self.allow_mccp2
		elif option == COMPRESS:
			return self.allow_mccp
		elif option == ECHO:
			return self.allow_echo
		else:
			core.error("Unhandled negotiation request: %s" % ord(option))
示例#9
0
文件: telnetProxy.py 项目: AKJ/sage
	def dataReceived(self, data):
		appDataBuffer = []

		for b in data:
			if self.state == 'data':
				if b == IAC:
					self.state = 'escaped'
				elif b == '\r':
					self.state = 'newline'
				else:
					appDataBuffer.append(b)
			elif self.state == 'escaped':
				if b == IAC:
					appDataBuffer.append(b)
					self.state = 'data'
				elif b == SB:
					self.state = 'subnegotiation'
					self.commands = []
				elif b == GA:
					self.state = 'data'
					if appDataBuffer:
						self.applicationDataReceived(''.join(appDataBuffer) + IAC + GA)
						del appDataBuffer[:]
				elif b in (NOP, DM, BRK, IP, AO, AYT, EC, EL):
					self.state = 'data'
					if appDataBuffer:
						self.applicationDataReceived(''.join(appDataBuffer))
						del appDataBuffer[:]
					self.commandReceived(b, None)
				elif b in (WILL, WONT, DO, DONT):
					self.state = 'command'
					self.command = b
				else:
					self.state = 'data'
					appDataBuffer.append(b)
					core.error("Unexpected signal: %s" % ord(b))
			elif self.state == 'command':
				self.state = 'data'
				command = self.command
				del self.command
				if appDataBuffer:
					self.applicationDataReceived(''.join(appDataBuffer))
					del appDataBuffer[:]
				self.commandReceived(command, b)
			elif self.state == 'newline':
				self.state = 'data'
				if b == '\n':
					appDataBuffer.append('\n')
				elif b == '\0':
					appDataBuffer.append('\r')
				elif b == IAC:
					# IAC isn't really allowed after \r, according to the
					# RFC, but handling it this way is less surprising than
					# delivering the IAC to the app as application data.
					# The purpose of the restriction is to allow terminals
					# to unambiguously interpret the behavior of the CR
					# after reading only one more byte.  CR LF is supposed
					# to mean one thing (cursor to next line, first column),
					# CR NUL another (cursor to first column).  Absent the
					# NUL, it still makes sense to interpret this as CR and
					# then apply all the usual interpretation to the IAC.
					appDataBuffer.append('\r')
					self.state = 'escaped'
				else:
					appDataBuffer.append('\r' + b)
			elif self.state == 'subnegotiation':
				if b == IAC:
					self.state = 'subnegotiation-escaped'
				else:
					self.commands.append(b)
			elif self.state == 'subnegotiation-escaped':
				if b == SE:
					self.state = 'data'
					commands = self.commands
					del self.commands
					# Hang on to the buffer a little longer to prevent prompt lines from getting split up
					#if appDataBuffer:
						#self.applicationDataReceived(''.join(appDataBuffer))
						#del appDataBuffer[:]
					self.negotiate(commands)
				else:
					self.state = 'subnegotiation'
					self.commands.append(b)
			else:
				core.error("Invalid telnet state")

		if appDataBuffer:
			self.applicationDataReceived(''.join(appDataBuffer))