Skip to content

Commit ad8e2d0

Browse files
authored
TD-407: Add route and wallet scopes (#43)
1 parent e28ecaa commit ad8e2d0

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

apps/ff_transfer/src/ff_limiter.erl

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
-include_lib("damsel/include/dmsl_base_thrift.hrl").
44
-include_lib("damsel/include/dmsl_domain_thrift.hrl").
55
-include_lib("damsel/include/dmsl_wthd_domain_thrift.hrl").
6+
-include_lib("limiter_proto/include/limproto_base_thrift.hrl").
67
-include_lib("limiter_proto/include/limproto_limiter_thrift.hrl").
78
-include_lib("limiter_proto/include/limproto_context_withdrawal_thrift.hrl").
89

@@ -21,7 +22,7 @@
2122
-type clock() :: limproto_limiter_thrift:'Clock'().
2223

2324
-export([get_turnover_limits/1]).
24-
-export([check_limits/2]).
25+
-export([check_limits/3]).
2526
-export([marshal_withdrawal/1]).
2627

2728
-export([hold_withdrawal_limits/3]).
@@ -36,11 +37,11 @@ get_turnover_limits({value, Limits}) ->
3637
get_turnover_limits(Ambiguous) ->
3738
error({misconfiguration, {'Could not reduce selector to a value', Ambiguous}}).
3839

39-
-spec check_limits([turnover_limit()], withdrawal()) ->
40+
-spec check_limits([turnover_limit()], route(), withdrawal()) ->
4041
{ok, [limit()]}
4142
| {error, {overflow, [{limit_id(), limit_amount(), turnover_limit_upper_boundary()}]}}.
42-
check_limits(TurnoverLimits, Withdrawal) ->
43-
Context = gen_limit_context(Withdrawal),
43+
check_limits(TurnoverLimits, Route, Withdrawal) ->
44+
Context = gen_limit_context(Route, Withdrawal),
4445
case lists:foldl(fun(Limit, Acc) -> check_limits_(Limit, Acc, Context) end, {[], []}, TurnoverLimits) of
4546
{Limits, ErrorList} when length(ErrorList) =:= 0 ->
4647
{ok, Limits};
@@ -67,21 +68,21 @@ check_limits_(T, {Limits, Errors}, Context) ->
6768
hold_withdrawal_limits(TurnoverLimits, Route, Withdrawal) ->
6869
IDs = [T#domain_TurnoverLimit.id || T <- TurnoverLimits],
6970
LimitChanges = gen_limit_changes(IDs, Route, Withdrawal),
70-
Context = gen_limit_context(Withdrawal),
71+
Context = gen_limit_context(Route, Withdrawal),
7172
hold(LimitChanges, get_latest_clock(), Context).
7273

7374
-spec commit_withdrawal_limits([turnover_limit()], route(), withdrawal()) -> ok.
7475
commit_withdrawal_limits(TurnoverLimits, Route, Withdrawal) ->
7576
IDs = [T#domain_TurnoverLimit.id || T <- TurnoverLimits],
7677
LimitChanges = gen_limit_changes(IDs, Route, Withdrawal),
77-
Context = gen_limit_context(Withdrawal),
78+
Context = gen_limit_context(Route, Withdrawal),
7879
commit(LimitChanges, get_latest_clock(), Context).
7980

8081
-spec rollback_withdrawal_limits([turnover_limit()], route(), withdrawal()) -> ok.
8182
rollback_withdrawal_limits(TurnoverLimits, Route, Withdrawal) ->
8283
IDs = [T#domain_TurnoverLimit.id || T <- TurnoverLimits],
8384
LimitChanges = gen_limit_changes(IDs, Route, Withdrawal),
84-
Context = gen_limit_context(Withdrawal),
85+
Context = gen_limit_context(Route, Withdrawal),
8586
rollback(LimitChanges, get_latest_clock(), Context).
8687

8788
-spec hold([limit_change()], clock(), context()) -> ok.
@@ -111,12 +112,20 @@ rollback(LimitChanges, Clock, Context) ->
111112
LimitChanges
112113
).
113114

114-
gen_limit_context(Withdrawal) ->
115+
gen_limit_context(#{provider_id := ProviderID, terminal_id := TerminalID}, Withdrawal) ->
116+
#{wallet_id := WalletID} = ff_withdrawal:params(Withdrawal),
115117
MarshaledWithdrawal = marshal_withdrawal(Withdrawal),
116118
#limiter_LimitContext{
117119
withdrawal_processing = #context_withdrawal_Context{
118120
op = {withdrawal, #context_withdrawal_OperationWithdrawal{}},
119-
withdrawal = #context_withdrawal_Withdrawal{withdrawal = MarshaledWithdrawal}
121+
withdrawal = #context_withdrawal_Withdrawal{
122+
withdrawal = MarshaledWithdrawal,
123+
route = #base_Route{
124+
provider = #domain_ProviderRef{id = ProviderID},
125+
terminal = #domain_TerminalRef{id = TerminalID}
126+
},
127+
wallet_id = WalletID
128+
}
120129
}
121130
}.
122131

apps/ff_transfer/src/ff_withdrawal_routing.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ validate_turnover_limits(undefined, _VS, _Route, _RoutingContext) ->
356356
{ok, valid};
357357
validate_turnover_limits({value, TurnoverLimits}, _VS, Route, #{withdrawal := Withdrawal}) ->
358358
ok = ff_limiter:hold_withdrawal_limits(TurnoverLimits, Route, Withdrawal),
359-
case ff_limiter:check_limits(TurnoverLimits, Withdrawal) of
359+
case ff_limiter:check_limits(TurnoverLimits, Route, Withdrawal) of
360360
{ok, _} ->
361361
{ok, valid};
362362
{error, Error} ->

rebar.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
{<<"jsx">>,{pkg,<<"jsx">>,<<"3.1.0">>},1},
5151
{<<"limiter_proto">>,
5252
{git,"https://github.com/valitydev/limiter-proto.git",
53-
{ref,"61581846b4d41de3a9e561c79f558e74450ab950"}},
53+
{ref,"31de59b17ad20e426b158ace6097e35330926bea"}},
5454
0},
5555
{<<"machinery">>,
5656
{git,"https://github.com/valitydev/machinery-erlang.git",

0 commit comments

Comments
 (0)