Exemple #1
0
def return_length():
	try:
		with open("pitcoin.bc", 'rb') as file:
			PITCOIN = miner.importBlockChainFromFile(file)
			file.close()
	except IOError:
		return("<h1>There is no blockchain yet</h1>")	
	return ('<h1>The length is <font color="red">' + str(PITCOIN.height) + '</font> blocks</h1>')
Exemple #2
0
def return_last_block():
	try:
		with open("pitcoin.bc", 'rb') as file:
			PITCOIN = miner.importBlockChainFromFile(file)
			file.close()
	except IOError:
		return("<h1>There is no blockchain yet</h1>")
	return (str(PITCOIN.chain[-1]))
Exemple #3
0
def return_nodes():
	try:
		with open("pitcoin.bc", 'rb') as file:
			PITCOIN = miner.importBlockChainFromFile(file)
			file.close()
	except IOError:
		return("<h1>There is no blockchain yet</h1>")	
	return (json.dumps(PITCOIN.nodes))
Exemple #4
0
def  get_balance():
	add = request.args.get('address')
	try:
		with open("pitcoin.bc", 'rb') as file:
			PITCOIN = miner.importBlockChainFromFile(file)
			file.close()
	except IOError:
		return("<h1>There is no blockchain yet</h1>")
	return('<h1>Your balance is<font color="red"> ' + str(PITCOIN.GetBalance(add)) + ' </font>pitcoins</h1>' + '\nAnd you are the God'if add == '0' * 34 else '')
Exemple #5
0
def return_block_by_index():
	hi = int(request.args.get('height'))
	try:
		with open("pitcoin.bc", 'rb') as file:
			PITCOIN = miner.importBlockChainFromFile(file)
			file.close()
	except IOError:
		return("<h1>There is no blockchain yet</h1>")
	if len(PITCOIN.chain) > hi:
		return (str(PITCOIN.chain[hi]))
	return("<h1>Nice try</h1>")