-
Notifications
You must be signed in to change notification settings - Fork 0
Implements GetWalletAccount operation bypassing fistful service #minor
#39
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
574400e
Implements `GetWalletAccount` operation bypassing fistful service
nanodirijabl d07c4fb
Adds `GetWallet` operation
nanodirijabl b2479f9
Reverts auth context for wallets to use backend module
nanodirijabl 6e8416c
Retires `createdAt` field for wallet object; bumps deps
nanodirijabl fc3588b
Upgrades deps with PM compat
nanodirijabl 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| -module(wapi_wallet_backend). | ||
|
|
||
| -type handler_context() :: wapi_handler_utils:handler_context(). | ||
| -type response_data() :: wapi_handler_utils:response_data(). | ||
| -type id() :: binary(). | ||
|
|
||
| -export([get/2]). | ||
| -export([get_account/2]). | ||
|
|
||
| -include_lib("damsel/include/dmsl_domain_thrift.hrl"). | ||
| -include_lib("damsel/include/dmsl_payproc_thrift.hrl"). | ||
|
|
||
| -spec get(id(), handler_context()) -> {ok, response_data(), id()} | {error, {wallet, notfound}}. | ||
| get(WalletID, _HandlerContext) -> | ||
| case get_wallet_config(WalletID) of | ||
| {ok, WalletConfig} -> | ||
| {ok, unmarshal(wallet, {WalletID, WalletConfig}), WalletConfig#domain_WalletConfig.party_id}; | ||
| {error, notfound} -> | ||
| {error, {wallet, notfound}} | ||
| end. | ||
|
|
||
| -spec get_account(id(), handler_context()) -> {ok, response_data()} | {error, {wallet, notfound}}. | ||
| get_account(WalletID, HandlerContext) -> | ||
| DomainRevision = wapi_domain_backend:head(), | ||
| case get_wallet_config(WalletID) of | ||
| {ok, #domain_WalletConfig{party_id = PartyID, account = #domain_WalletAccount{settlement = AccountID}}} -> | ||
| Request = {party_management, 'GetAccountState', {PartyID, AccountID, DomainRevision}}, | ||
| case wapi_handler_utils:service_call(Request, HandlerContext) of | ||
| {ok, AccountBalanceThrift} -> | ||
| {ok, unmarshal(account_state, AccountBalanceThrift)}; | ||
| {exception, #payproc_PartyNotFound{}} -> | ||
| {error, {wallet, notfound}}; | ||
| {exception, #payproc_AccountNotFound{}} -> | ||
| {error, {wallet, notfound}} | ||
| end; | ||
| {error, notfound} -> | ||
| {error, {wallet, notfound}} | ||
| end. | ||
|
|
||
| %% Internal | ||
|
|
||
| get_wallet_config(WalletID) -> | ||
| ObjectRef = {wallet_config, #domain_WalletConfigRef{id = WalletID}}, | ||
| wapi_domain_backend:get_object(ObjectRef). | ||
|
|
||
| %% Marshaling | ||
|
|
||
| unmarshal( | ||
| wallet, | ||
| {WalletID, #domain_WalletConfig{ | ||
| name = Name, | ||
| block = Blocking, | ||
| account = #domain_WalletAccount{currency = #domain_CurrencyRef{symbolic_code = Currency}}, | ||
| party_id = PartyID | ||
| }} | ||
| ) -> | ||
| genlib_map:compact(#{ | ||
| <<"id">> => unmarshal(id, WalletID), | ||
| <<"name">> => unmarshal(string, Name), | ||
| <<"isBlocked">> => unmarshal(blocking, Blocking), | ||
| <<"party">> => PartyID, | ||
| <<"currency">> => Currency | ||
| }); | ||
| unmarshal(blocking, {unblocked, _}) -> | ||
| false; | ||
| unmarshal(blocking, {blocked, _}) -> | ||
| true; | ||
| unmarshal(account_state, #payproc_AccountState{ | ||
| own_amount = OwnAmount, | ||
| available_amount = AvailableAmount, | ||
| currency = #domain_Currency{symbolic_code = CurrencyCode} | ||
| }) -> | ||
| #{ | ||
| <<"own">> => #{ | ||
| <<"amount">> => OwnAmount, | ||
| <<"currency">> => CurrencyCode | ||
| }, | ||
| <<"available">> => #{ | ||
| <<"amount">> => AvailableAmount, | ||
| <<"currency">> => CurrencyCode | ||
| } | ||
| }; | ||
| unmarshal(T, V) -> | ||
| wapi_codec:unmarshal(T, V). |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
надо бы еще глянуть что контекст для кошелька норм собирается - там же почти тоже самое - нужно вычитать кошелек и ео отмаршалить в баунсер контекст - не помню как я это сделал и делал ли