コード例 #1
0
 def dispatch_request(self):
     config = app.config['yada_config']
     mongo = app.config['yada_mongo']
     address = request.args.get('address')
     bulletin_secret = request.args.get('bulletin_secret').replace(' ', "+")
     rid = TU.generate_rid(config, bulletin_secret)
     unspent_transactions = [
         x for x in BU.get_wallet_unspent_transactions(
             config, mongo, address)
     ]
     regular_txns = []
     txns_for_fastgraph = []
     for txn in unspent_transactions:
         if 'signatures' in txn and txn['signatures']:
             fastgraph = FastGraph.from_dict(config, mongo, txn)
             origin_fasttrack = fastgraph.get_origin_relationship(rid)
             if origin_fasttrack:
                 txns_for_fastgraph.append(txn)
         else:
             if 'rid' in txn and txn[
                     'rid'] == rid and 'dh_public_key' in txn and txn[
                         'dh_public_key']:
                 txns_for_fastgraph.append(txn)
             else:
                 regular_txns.append(txn)
     wallet = {
         'balance': BU.get_wallet_balance(config, mongo, address),
         'unspent_transactions': regular_txns,
         'txns_for_fastgraph': txns_for_fastgraph
     }
     return json.dumps(wallet, indent=4)
コード例 #2
0
ファイル: endpoints_old.py プロジェクト: EggPool/yadacoin
    def dispatch_request(self):
        config = app.config['yada_config']
        mongo = app.config['yada_mongo']
        my_bulletin_secret = config.get_bulletin_secret()
        their_bulletin_secret = request.json.get('bulletin_secret')
        rids = sorted([str(my_bulletin_secret), str(their_bulletin_secret)], key=str.lower)
        rid = hashlib.sha256(str(rids[0]) + str(rids[1])).digest().encode('hex')

        client = app.test_client()
        response = client.post('/post-fastgraph-transaction', data=request.json.get('txn'), headers=list(request.headers))
        fastgraph = FastGraph(**request.json.get('txn'))
        try:
            response.get_json()
        except:
            return 'error posting react', 400

        friend = BU().get_transactions(
            config,
            mongo,
            wif=config.wif,
            both=False,
            query={'txn.relationship.their_username': {'$exists': True}, 'txn.relationship.id': {'$in': signatures}},
            queryType="searchUsername"
        )
        if friend:
            username = [x for x in friend][0]['relationship']['their_username']
        else:
            username = ''

        res = mongo.site_db.fcmtokens.find({"rid": rid})
        for token in res:
            result = push_service.notify_single_device(
                registration_id=token['token'],
                message_title='%s commented on your post!' % username,
                message_body='Go see what they said!',
                extra_kwargs={'priority': 'high'}
            )

        comments = mongo.site_db.comments.find({
            'rid': {'$ne': rid},
            'txn_id': request.json.get('txn_id')
        })
        for comment in comments:
            res = mongo.site_db.fcmtokens.find({"rid": comment['rid']})
            for token in res:
                result = push_service.notify_single_device(
                    registration_id=token['token'],
                    message_title='%s commented on a post you commented on!' % username,
                    message_body='Go see what they said!',
                    extra_kwargs={'priority': 'high'}
                )
        return 'ok'
コード例 #3
0
ファイル: endpoints.py プロジェクト: BadPirateX/yadacoin
 def dispatch_request(self):
     # after the necessary signatures are gathered, the transaction is sent here.
     config = app.config['yada_config']
     mongo = app.config['yada_mongo']
     fastgraph = request.json
     fastgraph = FastGraph.from_dict(config, mongo, 0, fastgraph)
     try:
         fastgraph.verify()
     except:
         return 'did not verify', 400
     result = mongo.db.fastgraph_transactions.find_one(
         {'txn.hash': fastgraph.hash})
     if result:
         return 'duplicate transaction found', 400
     fastgraph.save()
     #fastgraph.broadcast()
     return fastgraph.to_json()
コード例 #4
0
ファイル: endpoints_old.py プロジェクト: EggPool/yadacoin
    def dispatch_request(self):
        config = app.config['yada_config']
        mongo = app.config['yada_mongo']
        address = request.args.get('address')
        bulletin_secret = request.args.get('bulletin_secret').replace(' ', "+")
        rid = TU.generate_rid(config, bulletin_secret)
        unspent_transactions = [x for x in BU().get_wallet_unspent_transactions(address)]
        spent_txn_ids = []
        for x in unspent_transactions:
            spent_txn_ids.extend([y['id'] for y in x['inputs']])

        unspent_fastgraph_transactions = [x for x in BU().get_wallet_unspent_fastgraph_transactions(address) if x['id'] not in spent_txn_ids]
        print('fastgraph uspent txn ids:')
        print([x['id'] for x in unspent_fastgraph_transactions])
        spent_fastgraph_ids = []
        for x in unspent_fastgraph_transactions:
            spent_fastgraph_ids.extend([y['id'] for y in x['inputs']])
        print('regular unspent txn ids:')
        print([x['id'] for x in unspent_transactions])
        regular_txns = []
        txns_for_fastgraph = []
        for txn in unspent_transactions:
            if 'signatures' in txn and txn['signatures']:
                fastgraph = FastGraph.from_dict(0, txn)
                origin_fasttrack = fastgraph.get_origin_relationship(rid)
                if origin_fasttrack:
                    txns_for_fastgraph.append(txn)
                else:
                    regular_txns.append(txn)
            else:
                if 'rid' in txn and txn['rid'] == rid and 'dh_public_key' in txn and txn['dh_public_key']:
                    txns_for_fastgraph.append(txn)
                else:
                    regular_txns.append(txn)
        #print(unspent_fastgraph_transactions)
        if unspent_fastgraph_transactions:
            txns_for_fastgraph.extend(unspent_fastgraph_transactions)
        print('final txn ids:')
        print([x['id'] for x in txns_for_fastgraph])
        wallet = {
            'balance': BU().get_wallet_balance(address),
            'unspent_transactions': regular_txns,
            'txns_for_fastgraph': txns_for_fastgraph
        }
        return json.dumps(wallet, indent=4)
コード例 #5
0
ファイル: endpoints_old.py プロジェクト: EggPool/yadacoin
 def dispatch_request(self):
     # after the necessary signatures are gathered, the transaction is sent here.
     config = app.config['yada_config']
     mongo = app.config['yada_mongo']
     fastgraph = request.json
     fastgraph = FastGraph.from_dict(0, fastgraph)
     try:
         fastgraph.verify()
     except Exception as e:
         raise
         return 'did not verify', 400
     result = mongo.db.fastgraph_transactions.find_one({
         'txn.hash': fastgraph.hash
     })
     if result:
         return 'duplicate transaction found', 400
     spent_check = mongo.db.fastgraph_transactions.find_one({
         'txn.inputs.id': {'$in': [x.id for x in fastgraph.inputs]}
     })
     if spent_check:
         return 'already spent input', 400
     fastgraph.save()
     #fastgraph.broadcast()
     return fastgraph.to_json()
コード例 #6
0
ファイル: endpoints_old.py プロジェクト: EggPool/yadacoin
    def dispatch_request(self):
        config = app.config['yada_config']
        mongo = app.config['yada_mongo']
        try:
            fg = FastGraph.from_dict(0, request.json.get('txn'), raw=True)
            fg.verify()
        except:
            raise
            return 'invalid transaction', 400
        res = mongo.db.signed_transactions.find_one({'hash': request.json.get('hash')})
        print(request.json)
        if res:
            return 'no', 400
        try:
            rid = TU.generate_rid(config, request.json.get('bulletin_secret'))
            my_entry_for_relationship = GU().get_transaction_by_rid(rid, config.wif, rid=True, my=True, public_key=config.public_key)
            their_entry_for_relationship = GU().get_transaction_by_rid(rid, rid=True, raw=True, theirs=True, public_key=config.public_key)
            verified = verify_signature(
                base64.b64decode(request.json.get('bulletin_secret')),
                my_entry_for_relationship['relationship']['their_username'].encode(),
                bytes.fromhex(their_entry_for_relationship['public_key'])
            )
            if not verified:
                return 'no', 400
            verified = verify_signature(
                base64.b64decode(request.json.get('id')),
                request.json.get('hash').encode('utf-8'),
                bytes.fromhex(their_entry_for_relationship['public_key'])
            )

            address = str(P2PKHBitcoinAddress.from_pubkey(bytes.fromhex(their_entry_for_relationship['public_key'])))
            found = False
            for x in BU().get_wallet_unspent_transactions(address, [request.json.get('input')]):
                if request.json.get('input') == x['id']:
                    found = True
            
            if not found:
                for x in BU().get_wallet_unspent_fastgraph_transactions(address):
                    if request.json.get('input') == x['id']:
                        found = True

            if found:
                signature = mongo.db.signed_transactions.find_one({'input': request.json.get('input')})
                if signature:
                    already_spent = mongo.db.fastgraph_transactions.find_one({'txn.inputs.id': request.json.get('input')})
                    if already_spent:
                        return 'already spent!', 400
                    return 'already signed!', 400
            else:
                return 'no transactions with this input found', 400

            if verified:
                transaction_signature = TU.generate_signature_with_private_key(config.private_key, request.json.get('hash'))
                signature = {
                    'signature': transaction_signature,
                    'hash': request.json.get('hash'),
                    'bulletin_secret': request.json.get('bulletin_secret'),
                    'input': request.json.get('input'),
                    'id': request.json.get('id'),
                    'txn': request.json.get('txn')
                }
                mongo.db.signed_transactions.insert(signature)
                if '_id' in signature:
                    del signature['_id']
                return json.dumps(signature)
            else:
                return 'no', 400
        except Exception as e:
            raise
            return json.dumps({
                'status': 'error',
                'msg': e
            }), 400