TD-262: Move from shumpune to accounter (#15)

* TD-262: Move from shumpune to accounter

* Fix spec

* Add test

* Fix
This commit is contained in:
ndiezel0 2022-04-08 01:32:50 +03:00 committed by GitHub
parent 76058e0aa8
commit f757b7905b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 52 deletions

View File

@ -10,7 +10,6 @@
stdlib,
genlib,
pm_proto,
shumpune_proto,
cowboy,
woody,
scoper, % should be before any scoper event handler usage

View File

@ -1,10 +1,3 @@
%%% Accounting
%%%
%%% TODO
%%% - Brittle posting id assignment, it should be a level upper, maybe even in
%%% `pm_cashflow`.
%%% - Stuff cash flow details in the posting description fields.
-module(pm_accounting).
-export([get_account/1]).
@ -12,17 +5,12 @@
-export([create_account/1]).
-include_lib("damsel/include/dmsl_payment_processing_thrift.hrl").
-include_lib("shumpune_proto/include/shumpune_shumpune_thrift.hrl").
-include_lib("damsel/include/dmsl_accounter_thrift.hrl").
-type amount() :: dmsl_domain_thrift:'Amount'().
-type currency_code() :: dmsl_domain_thrift:'CurrencySymbolicCode'().
-type account_id() :: dmsl_accounter_thrift:'AccountID'().
-type batch_id() :: dmsl_accounter_thrift:'BatchID'().
-type final_cash_flow() :: dmsl_domain_thrift:'FinalCashFlow'().
-type batch() :: {batch_id(), final_cash_flow()}.
-type clock() :: shumpune_shumpune_thrift:'Clock'().
-export_type([batch/0]).
-type thrift_account() :: dmsl_accounter_thrift:'Account'().
-type account() :: #{
account_id => account_id(),
@ -38,25 +26,13 @@
-spec get_account(account_id()) -> account().
get_account(AccountID) ->
case call_accounter('GetAccountByID', {AccountID}) of
{ok, Result} ->
construct_account(AccountID, Result);
{exception, #shumpune_AccountNotFound{}} ->
pm_woody_wrapper:raise(#payproc_AccountNotFound{})
end.
Account = do_get_account(AccountID),
construct_account(Account).
-spec get_balance(account_id()) -> balance().
get_balance(AccountID) ->
get_balance(AccountID, {latest, #shumpune_LatestClock{}}).
-spec get_balance(account_id(), clock()) -> balance().
get_balance(AccountID, Clock) ->
case call_accounter('GetBalanceByID', {AccountID, Clock}) of
{ok, Result} ->
construct_balance(AccountID, Result);
{exception, #shumpune_AccountNotFound{}} ->
pm_woody_wrapper:raise(#payproc_AccountNotFound{})
end.
Account = do_get_account(AccountID),
construct_balance(Account).
-spec create_account(currency_code()) -> account_id().
create_account(CurrencyCode) ->
@ -65,24 +41,31 @@ create_account(CurrencyCode) ->
-spec create_account(currency_code(), binary() | undefined) -> account_id().
create_account(CurrencyCode, Description) ->
case call_accounter('CreateAccount', {construct_prototype(CurrencyCode, Description)}) of
{ok, Result} ->
Result
end.
-spec do_get_account(account_id()) -> thrift_account().
do_get_account(AccountID) ->
case call_accounter('GetAccountByID', {AccountID}) of
{ok, Result} ->
Result;
{exception, Exception} ->
% FIXME
error({accounting, Exception})
{exception, #accounter_AccountNotFound{}} ->
pm_woody_wrapper:raise(#payproc_AccountNotFound{})
end.
construct_prototype(CurrencyCode, Description) ->
#shumpune_AccountPrototype{
#accounter_AccountPrototype{
currency_sym_code = CurrencyCode,
description = Description
description = Description,
creation_time = pm_datetime:format_now()
}.
%%
construct_account(
AccountID,
#shumpune_Account{
#accounter_Account{
id = AccountID,
currency_sym_code = CurrencyCode
}
) ->
@ -92,8 +75,8 @@ construct_account(
}.
construct_balance(
AccountID,
#shumpune_Balance{
#accounter_Account{
id = AccountID,
own_amount = OwnAmount,
min_available_amount = MinAvailableAmount,
max_available_amount = MaxAvailableAmount

View File

@ -93,7 +93,7 @@ start_app(party_management = AppName) ->
}
}},
{services, #{
accounter => <<"http://shumway:8022/shumpune">>,
accounter => <<"http://shumway:8022/accounter">>,
automaton => <<"http://machinegun:8022/v1/automaton">>,
party_management => #{
url => <<"http://party-management:8022/v1/processing/partymgmt">>,

View File

@ -69,6 +69,7 @@
-export([shop_account_set_retrieval/1]).
-export([shop_account_retrieval/1]).
-export([get_account_state_not_found/1]).
-export([contract_not_found/1]).
-export([contract_creation/1]).
@ -242,7 +243,8 @@ groups() ->
contract_creation,
shop_creation,
shop_account_set_retrieval,
shop_account_retrieval
shop_account_retrieval,
get_account_state_not_found
]},
{claim_management, [sequence], [
party_creation,
@ -474,6 +476,7 @@ end_per_testcase(_Name, _C) ->
-spec shop_already_active(config()) -> _ | no_return().
-spec shop_account_set_retrieval(config()) -> _ | no_return().
-spec shop_account_retrieval(config()) -> _ | no_return().
-spec get_account_state_not_found(config()) -> _ | no_return().
-spec contract_not_found(config()) -> _ | no_return().
-spec contract_creation(config()) -> _ | no_return().
@ -1559,6 +1562,11 @@ shop_account_retrieval(C) ->
{shop_account_set_retrieval, #domain_ShopAccount{guarantee = AccountID}} = ?config(saved_config, C),
#payproc_AccountState{account_id = AccountID} = pm_client_party:get_account_state(AccountID, Client).
get_account_state_not_found(C) ->
Client = cfg(client, C),
{exception, #payproc_AccountNotFound{}} =
(catch pm_client_party:get_account_state(420, Client)).
%%
contractor_creation(C) ->

View File

@ -21,7 +21,7 @@ get_service(claim_committer) ->
get_service(party_management) ->
{dmsl_payment_processing_thrift, 'PartyManagement'};
get_service(accounter) ->
{shumpune_shumpune_thrift, 'Accounter'};
{dmsl_accounter_thrift, 'Accounter'};
get_service(automaton) ->
{mg_proto_state_processing_thrift, 'Automaton'};
get_service(processor) ->

View File

@ -51,7 +51,7 @@ services:
retries: 20
shumway:
image: docker.io/rbkmoney/shumway:44eb989065b27be619acd16b12ebdb2288b46c36
image: docker.io/rbkmoney/shumway:d5b74714437b1a1b11689a38297fd2a6c08e0db2
restart: unless-stopped
depends_on:
- shumway-db

View File

@ -37,7 +37,7 @@
}},
{services, #{
automaton => "http://machinegun:8022/v1/automaton",
accounter => "http://shumway:8022/shumpune"
accounter => "http://shumway:8022/accounter"
}},
{cache_options, #{ %% see `pm_party_cache:cache_options/0`
memory => 209715200, % 200Mb, cache memory quota in bytes

View File

@ -33,8 +33,6 @@
{damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "master"}}},
{payproc_errors, {git, "https://github.com/valitydev/payproc-errors-erlang.git", {branch, "master"}}},
{mg_proto, {git, "https://github.com/valitydev/machinegun-proto.git", {branch, "master"}}},
{shumpune_proto,
{git, "https://github.com/valitydev/shumaich-proto.git", {ref, "a0aed3bdce6aafdb832bbcde45e6278222b08c0b"}}},
{dmt_client, {git, "https://github.com/valitydev/dmt_client.git", {branch, "master"}}},
{scoper, {git, "https://github.com/valitydev/scoper.git", {branch, "master"}}},
{erl_health, {git, "https://github.com/valitydev/erlang-health.git", {branch, "master"}}}

View File

@ -9,7 +9,7 @@
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.11.0">>},2},
{<<"damsel">>,
{git,"https://github.com/valitydev/damsel.git",
{ref,"8016313ab8c27a237a33927a0ee22dd58524e86c"}},
{ref,"3efe7dffaae0f40a77dead166a52f8c9108f2d8d"}},
0},
{<<"dmt_client">>,
{git,"https://github.com/valitydev/dmt_client.git",
@ -47,10 +47,6 @@
{git,"https://github.com/valitydev/scoper.git",
{ref,"7f3183df279bc8181efe58dafd9cae164f495e6f"}},
0},
{<<"shumpune_proto">>,
{git,"https://github.com/valitydev/shumaich-proto.git",
{ref,"a0aed3bdce6aafdb832bbcde45e6278222b08c0b"}},
0},
{<<"snowflake">>,
{git,"https://github.com/valitydev/snowflake.git",
{ref,"de159486ef40cec67074afe71882bdc7f7deab72"}},