def blockchain(): """ return all blockchain data """ local_chain = sync.sync_local() json_blocks = local_chain.block_list_to_dict() return jsonify(json_blocks)
def transaction(txid): local_chain = sync.sync_local() block = local_chain.find_block_by_txid(txid) if block: return jsonify(block.to_dict()), 200 else: return jsonify(message='Block not found'), 404
def mine_for_block(chain=None, rounds=STANDARD_ROUNDS, start_nonce=0): if not chain: chain = sync.sync_local() # gather last node prev_block = chain.most_recent_block() return mine_from_prev_block(prev_block, rounds=rounds, start_nonce=start_nonce)
def mine_for_block(chain=None, rounds=STANDARD_ROUNDS, start_nonce=0, timestamp=None): if not chain: chain = sync.sync_local() prev_block = chain.most_recent_block() return mine_from_prev_block(prev_block, rounds=rounds, start_nonce=start_nonce, timestamp=timestamp)
def blockchain(): ''' Shoots back the blockchain, which in our case, is a json list of hashes with the block information which is: index timestamp data hash prev_hash ''' local_chain = sync.sync_local() json_blocks = json.dumps(local_chain.block_list_dict()) return json_blocks
def blockchain(): ''' Shoots back the blockchain, which in our case, is a json list of hashes with the block information which is: index timestamp data hash prev_hash ''' local_chain = sync.sync_local() # update if they've changed # Convert our blocks into dictionaries # so we can send them as json objects later json_blocks = json.dumps(local_chain.block_list_dict()) return json_blocks
def mine_for_block(chain=None, rounds=STANDARD_ROUNDS, start_nonce=0, timestamp=None): ''' try and get the next block in the chain ''' if not chain: chain = sync.sync_local() prev_block = chain.most_recent_block() print(prev_block) return mine_from_prev_block(prev_block, rounds=rounds, start_nonce=start_nonce, timestamp=timestamp)
def blockchain(): ''' Shoots back the blockchain, which in our case, is a json list of hashes with the block information which is: index timestamp data hash prev_hash ''' local_chain = sync.sync_local() #update if they've changed # Convert our blocks into dictionaries # so we can send them as json objects later json_blocks = json.dumps(local_chain.block_list_dict()) return json_blocks
def blockchain(): ''' Shoots back the blockchain, which in our case, is a json list of hashes with the block information which is: index timestamp data hash prev_hash ''' local_chain = sync.sync_local() # update if they've changed print(local_chain.links) # Convert our blocks into dictionaries # so we can send them as json objects later index = json.loads(request.args.get('i', '0')) json_blocks = json.dumps(local_chain.block_list_dict()[index:]) return json_blocks
def new(): data = request.get_json() # check required field required = ['author', 'title', 'doc_hash', 's3_url'] if not all(k in data for k in required): return jsonify({'result': 'Missing values'}), 400 # TODO # check doc_hash # if doc_hash already in blockchain database # return Document was exist and txid # push transaction to mongodb local_chain = sync.sync_local() if not local_chain.find_block_by_data_attr(key='doc_hash', value=data['doc_hash']): txid = mongo_conn.new_pending_transaction(data) return jsonify({'message': 'New transaction was submitted'\ ' to blockchain database', ' transaction_id': txid}), 201 else: return jsonify({'message': 'This document is already on blockchain'}), 403
def mine_for_block(sched, mongo_conn): print "Starting mining listener" if mongo_conn.check_free_job(): print "Node is mining other transaction" return False try: pending_tx = mongo_conn.query_a_pending_transaction() if pending_tx: # add to pending mongo_conn.add_mining_tx(pending_tx['txid']) print "Start minging transaction id %s " % pending_tx['txid'] blockchain = sync.sync_local() sched.add_job(proof_of_work, args=[blockchain, pending_tx], id='mining') sched.add_listener(mine_block_listener, EVENT_JOB_EXECUTED) else: print "No pending transaction" except Exception as e: ## query pending transaction fail or not have any pending transaction # if minging error, remove mining job mongo_conn.remove_mining_tx(txid=pending_tx) raise Exception(e)
def blockchain(): local_chain = sync.sync_local() json_blocks = json.dumps(local_chain.block_list_dict()) return json_blocks
def mine_for_block(chain=None, rounds=STANDARD_ROUNDS, start_nonce=0, timestamp=None): if not chain: chain = sync.sync_local() #gather last node prev_block = chain.most_recent_block() return mine_from_prev_block(prev_block, rounds=rounds, start_nonce=start_nonce, timestamp=timestamp)