Beispiel #1
0
    def post(self):
        args = parser.parse_args()
        profile = db.query(Profile).filter_by(id=args['profile_id']).first()
        miner = db.query(Profile).filter_by(id=args['miner_id']).first()
        previous = db.query(Block).order_by('-id').first()

        data = {
            "message": profile.message,
            "feedback": args["feedback"],
            "initiator": profile.email,
            "miner": miner.email,
            "reward": 30
        }

        nonce, hash, timestamp = Block.pow(data=json.dumps(data),
                                           previous_hash=previous.hash)

        block = Block(data=json.dumps(data),
                      hash=hash,
                      previous_hash=previous.hash,
                      nonce=nonce,
                      creation_date=timestamp)

        miner.thelmies += 30
        profile.thelmies -= 5

        # remove message from profile
        profile.message = ""

        db.add(block)
        db.commit()

        return jsonify(block)
Beispiel #2
0
    def generateFirst(self):

        data = '{"message": "TEX Event Genesis block"}'
        nonce, hash, timestamp = Block.pow(data=data, previous_hash="0")

        first = Block(data=data,
                      hash=hash,
                      previous_hash="0",
                      nonce=nonce,
                      creation_date=timestamp)
        # genesis = blockchain.genesis()
        db.add(first)
        db.commit()
Beispiel #3
0
    def genesis (self, first_block = None):

        data = "TEX Event Genesis block"
        nonce, hash, timestamp = Block.pow(data=data, previous_hash="0")

        return Block(data=data, hash=hash, previous_hash="0", nonce=nonce, creation_date=timestamp)