コード例 #1
0
ファイル: app.py プロジェクト: lucasfelhberg/uclcoin
def get_reset_blockchain():
    BlockChain.clear()
    return jsonify({'message': 'Blockchain reseted successfuly'}), 200
コード例 #2
0
#!/usr/bin/env python
# pylint: disable=C0103,C0111

import os
import re

from flask import Flask, jsonify, request
from uclcoin import Block, BlockChain, BlockchainException, KeyPair, Transaction

from pymongo import MongoClient

uclcoindb = MongoClient().uclcoin
blockchain = BlockChain(mongodb=uclcoindb)

app = Flask(__name__)


@app.route('/balance/<address>', methods=['GET'])
def get_balance(address):
    if not re.match(r'[\da-f]{66}$', address):
        return jsonify({'message': 'Invalid address'}), 400

    balance = blockchain.get_balance(address)
    return jsonify({'balance': balance}), 200


@app.route('/pending_transactions', methods=['GET'])
def pending_transactions():
    pending_txns = [dict(t) for t in blockchain.pending_transactions]
    return jsonify({'transactions': pending_txns}), 200
コード例 #3
0
from uclcoin import (Block, BlockChain, BlockchainException, KeyPair,
                     Transaction)
from pymongo import MongoClient
from flask import Flask, jsonify, request

import requests
import grequests
import json
import re
import os
import numpy as np
from hashlib import sha256

server = MongoClient('mongodb+srv://bbk:[email protected]/test?retryWrites=true&w=majority')
uclcoindb = server.uclcoin
blockchain = BlockChain(mongodb=uclcoindb)
domain = 'https://uclcriptocoin2.herokuapp.com' #Insert your domain
consecutives_invalids_blocks = 0

app = Flask(__name__)

@app.route('/consensus', methods=['GET'])
def get_consensus():
    local_consensus = consensus()
    if local_consensus:
        return jsonify({'message': f'Consensus updated'}), 201
    return jsonify({'message': f'Consensus already updated'}), 400


# endpoint to return the node's copy of the chain.
# Our application will be using this endpoint to query