Exemplo n.º 1
0
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')
Exemplo n.º 2
0
def clear_open_transactions():
    db = connect_to_db_blockchain()
    db.find_one_and_update({"_id": ObjectId("5cc8e412fb6fc00ed59ea3bb")},
                           {'$set': {
                               'open_transactions': []
                           }})
    return
Exemplo n.º 3
0
 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))
Exemplo n.º 4
0
    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')
Exemplo n.º 5
0
 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())
Exemplo n.º 6
0
def get_blockchain():
  db = connect_to_db_blockchain()
  blockchain = db.find_one({"_id": ObjectId("5cc8ec4efb6fc00ed59ea5fd")})
  return blockchain
Exemplo n.º 7
0
def get_nodes():
  db = connect_to_db_blockchain()
  nodes = db.find_one({"_id": ObjectId("5cc9c967e7179a596b194ca1")})
  nodes = nodes['nodes']
  return nodes
Exemplo n.º 8
0
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