-
Notifications
You must be signed in to change notification settings - Fork 32
✨ Introduce wallet exchange 🗃️ #7033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sanderegg
merged 28 commits into
ITISFoundation:master
from
matusdrobuliak66:changing-wallet-after-running-out-of-credits
Jan 21, 2025
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
8c81f52
daily work
matusdrobuliak66 d3d28fe
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 e18149e
openapi specs
matusdrobuliak66 53a31cb
improbemtns
matusdrobuliak66 bec976b
DB migration
matusdrobuliak66 9487856
fix test
matusdrobuliak66 634c8b9
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 ed94f26
Merge branch 'changing-wallet-after-running-out-of-credits' of github…
matusdrobuliak66 fe27eed
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 d7c6e36
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 32a63e9
improvements and tests
matusdrobuliak66 ec58d66
improvements and tests
matusdrobuliak66 00e6d21
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 c7f6bdb
fix tests
matusdrobuliak66 89bda75
adding unit tests
matusdrobuliak66 de3528a
adding test for open project
matusdrobuliak66 80ccea2
openapi specs
matusdrobuliak66 9b8685f
fix
matusdrobuliak66 61bbbf9
fix
matusdrobuliak66 4bec490
review @sanderegg
matusdrobuliak66 cb13f4c
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 2ce999a
review @sanderegg
matusdrobuliak66 537e44d
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 2e56581
fix
matusdrobuliak66 6eb8bc8
Merge branch 'changing-wallet-after-running-out-of-credits' of github…
matusdrobuliak66 b19a706
fix
matusdrobuliak66 cb1e18e
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 13f83ac
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...stgres_database/migration/versions/a3a58471b0f1_add_credit_transaction_classification_.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| """add credit transaction classification enums | ||
|
|
||
| Revision ID: a3a58471b0f1 | ||
| Revises: f19905923355 | ||
| Create Date: 2025-01-14 13:44:05.025647+00:00 | ||
|
|
||
| """ | ||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "a3a58471b0f1" | ||
| down_revision = "f19905923355" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.execute(sa.DDL("ALTER TYPE credittransactionstatus ADD VALUE 'IN_DEBT'")) | ||
| op.execute( | ||
| sa.DDL( | ||
| "ALTER TYPE credittransactionclassification ADD VALUE 'ADD_WALLET_EXCHANGE'" | ||
| ) | ||
| ) | ||
| op.execute( | ||
| sa.DDL( | ||
| "ALTER TYPE credittransactionclassification ADD VALUE 'DEDUCT_WALLET_EXCHANGE'" | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| pass | ||
| # ### end Alembic commands ### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...rary/src/servicelib/rabbitmq/rpc_interfaces/resource_usage_tracker/credit_transactions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import logging | ||
| from typing import Final | ||
|
|
||
| from models_library.api_schemas_resource_usage_tracker import ( | ||
| RESOURCE_USAGE_TRACKER_RPC_NAMESPACE, | ||
| ) | ||
| from models_library.api_schemas_resource_usage_tracker.credit_transactions import ( | ||
| CreditTransactionCreateBody, | ||
| WalletTotalCredits, | ||
| ) | ||
| from models_library.products import ProductName | ||
| from models_library.projects import ProjectID | ||
| from models_library.rabbitmq_basic_types import RPCMethodName | ||
| from models_library.resource_tracker import CreditTransactionStatus | ||
| from models_library.wallets import WalletID | ||
| from pydantic import NonNegativeInt, TypeAdapter | ||
|
|
||
| from ....logging_utils import log_decorator | ||
| from ....rabbitmq import RabbitMQRPCClient | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| _DEFAULT_TIMEOUT_S: Final[NonNegativeInt] = 20 | ||
|
|
||
| _RPC_METHOD_NAME_ADAPTER: TypeAdapter[RPCMethodName] = TypeAdapter(RPCMethodName) | ||
|
|
||
|
|
||
| @log_decorator(_logger, level=logging.DEBUG) | ||
| async def get_wallet_total_credits( | ||
| rabbitmq_rpc_client: RabbitMQRPCClient, | ||
| *, | ||
| product_name: ProductName, | ||
| wallet_id: WalletID, | ||
| ) -> WalletTotalCredits: | ||
| result = await rabbitmq_rpc_client.request( | ||
| RESOURCE_USAGE_TRACKER_RPC_NAMESPACE, | ||
| _RPC_METHOD_NAME_ADAPTER.validate_python("get_wallet_total_credits"), | ||
| product_name=product_name, | ||
| wallet_id=wallet_id, | ||
| timeout_s=_DEFAULT_TIMEOUT_S, | ||
| ) | ||
| assert isinstance(result, WalletTotalCredits) # nosec | ||
| return result | ||
|
|
||
|
|
||
| @log_decorator(_logger, level=logging.DEBUG) | ||
| async def get_project_wallet_total_credits( | ||
| rabbitmq_rpc_client: RabbitMQRPCClient, | ||
| *, | ||
| product_name: ProductName, | ||
| wallet_id: WalletID, | ||
| project_id: ProjectID, | ||
| transaction_status: CreditTransactionStatus | None = None, | ||
| ) -> WalletTotalCredits: | ||
| result = await rabbitmq_rpc_client.request( | ||
| RESOURCE_USAGE_TRACKER_RPC_NAMESPACE, | ||
| _RPC_METHOD_NAME_ADAPTER.validate_python("get_project_wallet_total_credits"), | ||
| product_name=product_name, | ||
| wallet_id=wallet_id, | ||
| project_id=project_id, | ||
| transaction_status=transaction_status, | ||
| timeout_s=_DEFAULT_TIMEOUT_S, | ||
| ) | ||
| assert isinstance(result, WalletTotalCredits) # nosec | ||
| return result | ||
|
|
||
|
|
||
| @log_decorator(_logger, level=logging.DEBUG) | ||
| async def pay_project_debt( | ||
| rabbitmq_rpc_client: RabbitMQRPCClient, | ||
| *, | ||
| project_id: ProjectID, | ||
| current_wallet_transaction: CreditTransactionCreateBody, | ||
| new_wallet_transaction: CreditTransactionCreateBody, | ||
| ) -> None: | ||
| await rabbitmq_rpc_client.request( | ||
| RESOURCE_USAGE_TRACKER_RPC_NAMESPACE, | ||
| _RPC_METHOD_NAME_ADAPTER.validate_python("pay_project_debt"), | ||
| project_id=project_id, | ||
| current_wallet_transaction=current_wallet_transaction, | ||
| new_wallet_transaction=new_wallet_transaction, | ||
| timeout_s=_DEFAULT_TIMEOUT_S, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.