def add_inventory_account_with_initial_funds_to_db(amount): inventory_user = User( username=INVENTORY_ACCOUNT_NAME, registration_status=RegistrationStatus.Approved, selected_fiat_currency=FiatCurrency.USD, selected_language="en", password_salt="123", password_hash="deadbeef", ) inventory_user.account = Account(name=INVENTORY_ACCOUNT_NAME) tx = Transaction( created_timestamp=datetime.now(), amount=amount, currency=CURRENCY, type=TransactionType.EXTERNAL, status=TransactionStatus.COMPLETED, sequence=0, blockchain_version=0, source_address=DD_ADDRESS, destination_address=VASP_ADDRESS, destination_id=inventory_user.id, ) inventory_user.account.received_transactions.append(tx) db_session.add(inventory_user) db_session.commit()
def add_outgoing_user_transaction_to_db(amount, account_name, receiver_address, sender_sub_address, sequence, user, version): user_account_id = Account.query.filter_by(name=account_name).first().id tx = Transaction( amount=amount, source_address=VASP_ADDRESS, destination_address=receiver_address, ) if version is not None: tx.blockchain_version = version if sequence is not None: tx.sequence = sequence tx.created_timestamp = datetime.now() tx.type = TransactionType.EXTERNAL tx.currency = CURRENCY tx.status = TransactionStatus.COMPLETED tx.source_id = user.id tx.source_subaddress = sender_sub_address user.account.sent_transactions.append(tx) db_session.add( SubAddress(address=sender_sub_address, account_id=user_account_id)) db_session.commit()
def setup_fake_data() -> None: clear_db() fake_users = [ User( username="******", registration_status=RegistrationStatus.Registered, selected_fiat_currency=FiatCurrency.USD, selected_language="en", password_salt="123", password_hash="deadbeef", is_admin=True, first_name="First1", last_name="Last1", account=Account(), ), User( username="******", registration_status=RegistrationStatus.Registered, selected_fiat_currency=FiatCurrency.USD, selected_language="en", password_salt="123", password_hash="deadbeef", is_admin=False, first_name="First2", last_name="Last2", account=Account(), ), User( username="******", registration_status=RegistrationStatus.Registered, selected_fiat_currency=FiatCurrency.USD, selected_language="en", password_salt="123", password_hash="deadbeef", is_admin=False, first_name="First3", last_name="Last3", account=Account(), ), ] for user in fake_users: db_session.add(user) try: db_session.commit() except Exception as e: db_session.rollback() db_session.flush()
def add_user_in_db(account_name): user = User( username=account_name, registration_status=RegistrationStatus.Approved, selected_fiat_currency=FiatCurrency.USD, selected_language="en", password_salt="123", password_hash="deadbeef", ) user.account = Account(name=account_name) db_session.add(user) db_session.commit() return user
def add_inventory_account_to_db(): inventory_user = User( username=INVENTORY_ACCOUNT_NAME, registration_status=RegistrationStatus.Approved, selected_fiat_currency=FiatCurrency.USD, selected_language="en", password_salt="123", password_hash="deadbeef", ) inventory_user.account = Account(name=INVENTORY_ACCOUNT_NAME) db_session.add(inventory_user) db_session.commit() return inventory_user
def add_inventory_account_with_initial_funds_to_db(amount): inventory_user = add_inventory_account_to_db() tx = Transaction( created_timestamp=datetime.now(), amount=amount, currency=CURRENCY, type=TransactionType.EXTERNAL, status=TransactionStatus.COMPLETED, sequence=0, blockchain_version=0, source_address=DD_ADDRESS, destination_address=VASP_ADDRESS, destination_id=inventory_user.id, ) inventory_user.account.received_transactions.append(tx) db_session.add(inventory_user) db_session.commit()