def search_account(): search = request.args.get('search', '') search_filter = int(request.args.get('search_filter', 0)) res = [] for tmp in rpc.db_lookup_accounts(ACCOUNT_PREFIX + search, 10): if tmp[0].startswith(ACCOUNT_PREFIX): tmp[0] = tmp[0][len(ACCOUNT_PREFIX):] #print tmp[0], search if tmp[0].startswith(search): add_account = True # Only with no-credit and no black-listed if search_filter == 1: p = rpc.db_get_account_balances( tmp[1], [DESCUBIERTO_ID]) no_credit = p[0]['amount'] == 0 no_black = tmp[1] not in rpc.db_get_accounts( [PROPUESTA_PAR_ID])[0]['blacklisted_accounts'] add_account = no_credit and no_black # Only with credit if search_filter == 2: p = rpc.db_get_account_balances( tmp[1], [DESCUBIERTO_ID]) has_credit = p[0]['amount'] > 0 #no_black = tmp[1] not in rpc.db_get_accounts([PROPUESTA_PAR_ID])[0]['blacklisted_accounts'] add_account = has_credit if add_account: res.append(tmp) return jsonify(res)
def find_account(): key = request.json.get('key') account_ids = set(rpc.db_get_key_references([key])[0]) return jsonify([ real_name(a['name']) for a in rpc.db_get_accounts(list(account_ids)) ])
def endorse_create(): valid_assets = [AVAL_1000, AVAL_10000, AVAL_30000] _from = request.json.get('from') endorse_type = request.json.get('endorse_type') from_id = cache.get_account_id(ACCOUNT_PREFIX + _from) if endorse_type not in valid_assets: return jsonify({'error': 'invalid_endorsement'}) p = rpc.db_get_account_balances(from_id, [endorse_type]) if p[0]['amount'] == 0: return jsonify({'error': 'no_endorsement_available'}) if from_id not in rpc.db_get_accounts([PROPUESTA_PAR_ID ])[0]['blacklisted_accounts']: return jsonify({'error': 'no_endore_state'}) p = rpc.db_get_account_balances(from_id, [DESCUBIERTO_ID]) if p[0]['amount'] > 0: return jsonify({'error': 'already_have_credit'}) asset, asset_core = rpc.db_get_assets([endorse_type, CORE_ASSET]) memo = {'message': '~ae'.encode('hex')} endorse_transfer_op = transfer(from_id, PROPUESTA_PAR_ID, asset, 1, memo, None, CORE_ASSET)[0] print "************************************************" print json.dumps(endorse_transfer_op, indent=2) print "*********************" # fees = rpc.db_get_required_fees([endorse_transfer_op], CORE_ASSET) print "toma => ", endorse_transfer_op[1]['fee']['amount'] print "************************************************" tx = build_tx_and_broadcast( account_whitelist( PROPUESTA_PAR_ID, from_id, 0 #remove from black list ) + transfer( PROPUESTA_PAR_ID, from_id, asset_core, amount_value(endorse_transfer_op[1]['fee']['amount'], asset_core)) + [endorse_transfer_op] + account_whitelist( PROPUESTA_PAR_ID, from_id, 2 #add to black list ), None) to_sign = bts2helper_tx_digest(json.dumps(tx), CHAIN_ID) signature = bts2helper_sign_compact(to_sign, REGISTER_PRIVKEY) tx['signatures'] = [signature] return jsonify({'tx': tx})
def get_account(account_id): key = '?account_%s' % account_id account = mc.get(key) if not account: account = rpc.db_get_accounts([account_id])[0] mc.set(key, account, 120) return account
def endorse_create(): valid_assets = [AVAL_1000, AVAL_10000, AVAL_30000] _from = request.json.get('from') _to = request.json.get('to') endorse_type = request.json.get('endorse_type') from_id = cache.get_account_id(ACCOUNT_PREFIX + _from) to_id = cache.get_account_id(ACCOUNT_PREFIX + _to) if endorse_type not in valid_assets: return jsonify({'error':'invalid_endorsement'}) if to_id in rpc.db_get_accounts([PROPUESTA_PAR_ID])[0]['blacklisted_accounts']: return jsonify({'error':'already_endorsed'}) p = rpc.db_get_account_balances(from_id, [endorse_type]) if p[0]['amount'] == 0: return jsonify({'error':'no_endorsement_available'}) p = rpc.db_get_account_balances(to_id, [DESCUBIERTO_ID]) if p[0]['amount'] > 0: return jsonify({'error':'already_have_credit'}) asset = rpc.db_get_assets([endorse_type])[0] memo = { 'message' : '~ieu'.encode('hex') } tx = build_tx_and_broadcast( transfer( from_id, to_id, asset, 1, memo, None, MONEDAPAR_ID ) + account_whitelist( PROPUESTA_PAR_ID, to_id, 2 #insert into black list ) , None) to_sign = bts2helper_tx_digest(json.dumps(tx), CHAIN_ID) signature = bts2helper_sign_compact(to_sign, REGISTER_PRIVKEY) tx['signatures'] = [signature] return jsonify( {'tx':tx} )
def user_transfer_authorizations(t): to = t.memo[8:].decode('hex') to_id = cache.get_account_id(unicode(ACCOUNT_PREFIX + to)) from_name = real_name(t.from_name) endorse_type = t.amount_asset if to_id in rpc.db_get_accounts([PROPUESTA_PAR_ID ])[0]['blacklisted_accounts']: raise Exception('unable_to_receive') asset = rpc.db_get_assets([endorse_type])[0] memo = {'message': '~et:{0}'.format(from_name).encode('hex')} tx = build_tx_and_broadcast( transfer(PROPUESTA_PAR_ID, to_id, asset, t.amount, memo), None) to_sign = bts2helper_tx_digest(json.dumps(tx), CHAIN_ID) signature = bts2helper_sign_compact(to_sign, REGISTER_PRIVKEY) tx['signatures'] = [signature] print tx p = rpc.network_broadcast_transaction(tx) return to_sign
def user_authorize_user(t): to = t.memo[8:].decode('hex') to_id = cache.get_account_id(unicode(ACCOUNT_PREFIX + to)) from_name = real_name(t.from_name) endorse_type = t.amount_asset if endorse_type not in valid_assets: raise Exception('invalid_endorsement') p = rpc.db_get_account_balances(to_id, [DESCUBIERTO_ID]) if p[0]['amount'] > 0: raise Exception('already_have_credit') if to_id in rpc.db_get_accounts([PROPUESTA_PAR_ID ])[0]['blacklisted_accounts']: raise Exception('already_endorsed') asset = rpc.db_get_assets([endorse_type])[0] memo = {'message': '~eb:{0}'.format(from_name).encode('hex')} tx = build_tx_and_broadcast( transfer(PROPUESTA_PAR_ID, to_id, asset, 1, memo) + account_whitelist( PROPUESTA_PAR_ID, to_id, 2 #insert into black list ), None) to_sign = bts2helper_tx_digest(json.dumps(tx), CHAIN_ID) signature = bts2helper_sign_compact(to_sign, REGISTER_PRIVKEY) tx['signatures'] = [signature] print tx p = rpc.network_broadcast_transaction(tx) return to_sign