def get_last_block(): db = connect_to_db_blockchain() last_block = db.find_one({"_id": ObjectId("5cc8ec4efb6fc00ed59ea5fd")}, {"block":{'$slice': -1}}) return last_block['block'][0] # get_my_tx('markgagnon', 'root')
def clear_open_transactions(): db = connect_to_db_blockchain() db.find_one_and_update({"_id": ObjectId("5cc8e412fb6fc00ed59ea3bb")}, {'$set': { 'open_transactions': [] }}) return
def add_node(self, node): db = connect_to_db_blockchain() db.find_one_and_update({"_id": ObjectId("5cc9c967e7179a596b194ca1")}, {'$addToSet': { 'nodes': node }}) print('Node {} added'.format(node))
def remove_node(self, node, node_password): db = connect_to_db_accounts() account = db.find_one({"username": node}) if account != '': db_password = account['password'] if password_compare(node_password, db_password): db = connect_to_db_blockchain() db.find_one_and_update( {"_id": ObjectId("5cc9c967e7179a596b194ca1")}, {'$pull': { 'nodes': node }}) message = { "message": 'Node {} removed'.format(node), "code": 201 } else: message = {"message": 'Wrong password', "code": 401} return message # Nodes().remove_node('markgagnon', 'root')
def __init__(self): self.db = connect_to_db_blockchain() self.blockchain = self.db.find_one( {"_id": ObjectId("5cc8ec4efb6fc00ed59ea5fd")}) if len(self.blockchain['block']) == 0: self.add_block(self.genesis_block())
def get_blockchain(): db = connect_to_db_blockchain() blockchain = db.find_one({"_id": ObjectId("5cc8ec4efb6fc00ed59ea5fd")}) return blockchain
def get_nodes(): db = connect_to_db_blockchain() nodes = db.find_one({"_id": ObjectId("5cc9c967e7179a596b194ca1")}) nodes = nodes['nodes'] return nodes
def get_transactions(): db = connect_to_db_blockchain() open_transactions = db.find_one({"_id": ObjectId("5cc8e412fb6fc00ed59ea3bb")}) open_transactions = open_transactions['open_transactions'] return open_transactions