diff --git a/.env b/.env index 61045cce..8871486d 100644 --- a/.env +++ b/.env @@ -2,6 +2,6 @@ # You SHOULD specify point releases here so that build time and run time Erlang/OTPs # are the same. See: https://github.com/erlware/relx/pull/902 SERVICE_NAME=fistful-server -OTP_VERSION=24.3 -REBAR_VERSION=3.18 +OTP_VERSION=27.1.2 +REBAR_VERSION=3.24 THRIFT_VERSION=0.14.2.3 diff --git a/apps/ff_core/src/ff_indef.erl b/apps/ff_core/src/ff_indef.erl index e184355c..1c50cfbd 100644 --- a/apps/ff_core/src/ff_indef.erl +++ b/apps/ff_core/src/ff_indef.erl @@ -65,20 +65,20 @@ expmin(#{expected_min := V}) -> expmax(#{expected_max := V}) -> V. -account(Delta, Indef = #{expected_min := ExpMin, expected_max := ExpMax}) -> +account(Delta, #{expected_min := ExpMin, expected_max := ExpMax} = Indef) -> Indef#{ expected_min := erlang:min(ExpMin + Delta, ExpMin), expected_max := erlang:max(ExpMax + Delta, ExpMax) }. -confirm(Delta, Indef = #{current := Current, expected_min := ExpMin, expected_max := ExpMax}) -> +confirm(Delta, #{current := Current, expected_min := ExpMin, expected_max := ExpMax} = Indef) -> Indef#{ current := Current + Delta, expected_min := erlang:max(ExpMin + Delta, ExpMin), expected_max := erlang:min(ExpMax + Delta, ExpMax) }. -reject(Delta, Indef = #{expected_min := ExpMin, expected_max := ExpMax}) -> +reject(Delta, #{expected_min := ExpMin, expected_max := ExpMax} = Indef) -> Indef#{ expected_min := erlang:max(ExpMin - Delta, ExpMin), expected_max := erlang:min(ExpMax - Delta, ExpMax) diff --git a/apps/ff_core/src/ff_maybe.erl b/apps/ff_core/src/ff_maybe.erl index 90441448..7d5e364c 100644 --- a/apps/ff_core/src/ff_maybe.erl +++ b/apps/ff_core/src/ff_maybe.erl @@ -4,10 +4,10 @@ -module(ff_maybe). --type maybe(T) :: +-type 'maybe'(T) :: undefined | T. --export_type([maybe/1]). +-export_type(['maybe'/1]). -export([from_result/1]). -export([to_list/1]). @@ -18,13 +18,13 @@ %% --spec from_result({ok, T} | {error, _}) -> maybe(T). +-spec from_result({ok, T} | {error, _}) -> 'maybe'(T). from_result({ok, T}) -> T; from_result({error, _}) -> undefined. --spec to_list(maybe(T)) -> [T]. +-spec to_list('maybe'(T)) -> [T]. to_list(undefined) -> []; to_list(T) -> @@ -40,7 +40,7 @@ apply(Fun, Arg, _Default) when Arg =/= undefined -> apply(_Fun, undefined, Default) -> Default. --spec get_defined([maybe(T)]) -> T. +-spec get_defined(['maybe'(T)]) -> T. get_defined([]) -> erlang:error(badarg); get_defined([Value | _Tail]) when Value =/= undefined -> @@ -48,6 +48,6 @@ get_defined([Value | _Tail]) when Value =/= undefined -> get_defined([undefined | Tail]) -> get_defined(Tail). --spec get_defined(maybe(T), maybe(T)) -> T. +-spec get_defined('maybe'(T), 'maybe'(T)) -> T. get_defined(V1, V2) -> get_defined([V1, V2]). diff --git a/apps/ff_core/src/ff_range.erl b/apps/ff_core/src/ff_range.erl index 31133047..760c26ee 100644 --- a/apps/ff_core/src/ff_range.erl +++ b/apps/ff_core/src/ff_range.erl @@ -3,10 +3,10 @@ -module(ff_range). --type range(T) :: {maybe(bound(T)), maybe(bound(T))}. +-type range(T) :: {'maybe'(bound(T)), 'maybe'(bound(T))}. -type bound(T) :: {exclusive | inclusive, ord(T)}. --type maybe(T) :: infinity | T. +-type 'maybe'(T) :: infinity | T. % totally ordered -type ord(T) :: T. diff --git a/apps/ff_cth/src/ct_domain.erl b/apps/ff_cth/src/ct_domain.erl index aa28dd57..f1180bbd 100644 --- a/apps/ff_cth/src/ct_domain.erl +++ b/apps/ff_cth/src/ct_domain.erl @@ -288,7 +288,7 @@ term_set_hierarchy(Ref) -> term_set_hierarchy(Ref, TermSets) -> term_set_hierarchy(Ref, undefined, TermSets). --spec term_set_hierarchy(Ref, ff_maybe:maybe(Ref), [?DTP('TimedTermSet')]) -> object() when +-spec term_set_hierarchy(Ref, ff_maybe:'maybe'(Ref), [?DTP('TimedTermSet')]) -> object() when Ref :: ?DTP('TermSetHierarchyRef'). term_set_hierarchy(Ref, ParentRef, TermSets) -> {term_set_hierarchy, #domain_TermSetHierarchyObject{ diff --git a/apps/ff_cth/src/ct_sup.erl b/apps/ff_cth/src/ct_sup.erl index 0e45763f..e0f0684c 100644 --- a/apps/ff_cth/src/ct_sup.erl +++ b/apps/ff_cth/src/ct_sup.erl @@ -13,9 +13,9 @@ -spec start() -> pid(). start() -> - {ok, PID} = supervisor:start_link(?MODULE, []), - true = unlink(PID), - PID. + {ok, Pid} = supervisor:start_link(?MODULE, []), + true = unlink(Pid), + Pid. -spec stop(pid()) -> ok. stop(Pid) -> diff --git a/apps/ff_server/src/ff_codec.erl b/apps/ff_server/src/ff_codec.erl index 3455a444..47997dc2 100644 --- a/apps/ff_server/src/ff_codec.erl +++ b/apps/ff_server/src/ff_codec.erl @@ -3,7 +3,6 @@ -include_lib("fistful_proto/include/fistful_fistful_base_thrift.hrl"). -include_lib("fistful_proto/include/fistful_repairer_thrift.hrl"). -include_lib("fistful_proto/include/fistful_account_thrift.hrl"). --include_lib("fistful_proto/include/fistful_msgp_thrift.hrl"). -include_lib("fistful_proto/include/fistful_fistful_thrift.hrl"). -include_lib("fistful_proto/include/fistful_evsink_thrift.hrl"). @@ -79,10 +78,10 @@ marshal(withdrawal_method, #{id := {bank_card, #{payment_system := PaymentSystem }}; marshal( transaction_info, - TransactionInfo = #{ + #{ id := TransactionID, extra := Extra - } + } = TransactionInfo ) -> Timestamp = maps:get(timestamp, TransactionInfo, undefined), AddInfo = maps:get(additional_info, TransactionInfo, undefined), @@ -92,7 +91,7 @@ marshal( extra = Extra, additional_info = marshal(additional_transaction_info, AddInfo) }; -marshal(additional_transaction_info, AddInfo = #{}) -> +marshal(additional_transaction_info, #{} = AddInfo) -> #'fistful_base_AdditionalTransactionInfo'{ rrn = marshal(string, maps:get(rrn, AddInfo, undefined)), approval_code = marshal(string, maps:get(approval_code, AddInfo, undefined)), @@ -152,7 +151,7 @@ marshal(resource_descriptor, {bank_card, BinDataID}) -> {bank_card, #'fistful_base_ResourceDescriptorBankCard'{ bin_data_id = marshal(msgpack, BinDataID) }}; -marshal(bank_card, BankCard = #{token := Token}) -> +marshal(bank_card, #{token := Token} = BankCard) -> Bin = maps:get(bin, BankCard, undefined), PaymentSystem = ff_resource:payment_system(BankCard), MaskedPan = ff_resource:masked_pan(BankCard), @@ -178,13 +177,13 @@ marshal(bank_card_auth_data, {session, #{session_id := ID}}) -> {session_data, #'fistful_base_SessionAuthData'{ id = marshal(string, ID) }}; -marshal(crypto_wallet, CryptoWallet = #{id := ID, currency := Currency}) -> +marshal(crypto_wallet, #{id := ID, currency := Currency} = CryptoWallet) -> #'fistful_base_CryptoWallet'{ id = marshal(string, ID), currency = marshal(crypto_currency, Currency), tag = maybe_marshal(string, maps:get(tag, CryptoWallet, undefined)) }; -marshal(digital_wallet, Wallet = #{id := ID, payment_service := PaymentService}) -> +marshal(digital_wallet, #{id := ID, payment_service := PaymentService} = Wallet) -> #'fistful_base_DigitalWallet'{ id = marshal(string, ID), token = maybe_marshal(string, maps:get(token, Wallet, undefined)), @@ -192,7 +191,7 @@ marshal(digital_wallet, Wallet = #{id := ID, payment_service := PaymentService}) account_name = maybe_marshal(string, maps:get(account_name, Wallet, undefined)), account_identity_number = maybe_marshal(string, maps:get(account_identity_number, Wallet, undefined)) }; -marshal(generic_resource, Generic = #{provider := PaymentService}) -> +marshal(generic_resource, #{provider := PaymentService} = Generic) -> #'fistful_base_ResourceGenericData'{ provider = marshal(payment_service, PaymentService), data = maybe_marshal(content, maps:get(data, Generic, undefined)) diff --git a/apps/ff_server/src/ff_deposit_adjustment_codec.erl b/apps/ff_server/src/ff_deposit_adjustment_codec.erl index 9a572213..228e85fa 100644 --- a/apps/ff_server/src/ff_deposit_adjustment_codec.erl +++ b/apps/ff_server/src/ff_deposit_adjustment_codec.erl @@ -54,10 +54,10 @@ marshal(changes_plan, Plan) -> new_status = maybe_marshal(status_change_plan, maps:get(new_status, Plan, undefined)) }; marshal(cash_flow_change_plan, Plan) -> - OldCashFLow = ff_cash_flow_codec:marshal(final_cash_flow, maps:get(old_cash_flow_inverted, Plan)), + OldCashFlow = ff_cash_flow_codec:marshal(final_cash_flow, maps:get(old_cash_flow_inverted, Plan)), NewCashFlow = ff_cash_flow_codec:marshal(final_cash_flow, maps:get(new_cash_flow, Plan)), #deposit_adj_CashFlowChangePlan{ - old_cash_flow_inverted = OldCashFLow, + old_cash_flow_inverted = OldCashFlow, new_cash_flow = NewCashFlow }; marshal(status_change_plan, Plan) -> diff --git a/apps/ff_server/src/ff_deposit_machinery_schema.erl b/apps/ff_server/src/ff_deposit_machinery_schema.erl index 77b97a83..36d0f754 100644 --- a/apps/ff_server/src/ff_deposit_machinery_schema.erl +++ b/apps/ff_server/src/ff_deposit_machinery_schema.erl @@ -3,9 +3,6 @@ %% Storage schema behaviour -behaviour(machinery_mg_schema). --include_lib("fistful_proto/include/fistful_deposit_thrift.hrl"). --include_lib("mg_proto/include/mg_proto_state_processing_thrift.hrl"). - -export([get_version/1]). -export([marshal/3]). -export([unmarshal/3]). @@ -92,9 +89,9 @@ unmarshal_event(undefined = Version, EncodedChange, Context0) -> {{ev, Timestamp, maybe_migrate(Change, Context1)}, Context1}. -spec maybe_migrate(any(), context()) -> ff_deposit:event(). -maybe_migrate(Ev = {status_changed, {failed, #{code := _}}}, _MigrateParams) -> +maybe_migrate({status_changed, {failed, #{code := _}}} = Ev, _MigrateParams) -> Ev; -maybe_migrate(Ev = {limit_check, {wallet_receiver, _Details}}, _MigrateParams) -> +maybe_migrate({limit_check, {wallet_receiver, _Details}} = Ev, _MigrateParams) -> Ev; maybe_migrate({p_transfer, PEvent}, _MigrateParams) -> {p_transfer, ff_postings_transfer:maybe_migrate(PEvent, deposit)}; diff --git a/apps/ff_server/src/ff_deposit_revert_adjustment_codec.erl b/apps/ff_server/src/ff_deposit_revert_adjustment_codec.erl index 9a6d8819..445e5f59 100644 --- a/apps/ff_server/src/ff_deposit_revert_adjustment_codec.erl +++ b/apps/ff_server/src/ff_deposit_revert_adjustment_codec.erl @@ -54,10 +54,10 @@ marshal(changes_plan, Plan) -> new_status = maybe_marshal(status_change_plan, maps:get(new_status, Plan, undefined)) }; marshal(cash_flow_change_plan, Plan) -> - OldCashFLow = ff_cash_flow_codec:marshal(final_cash_flow, maps:get(old_cash_flow_inverted, Plan)), + OldCashFlow = ff_cash_flow_codec:marshal(final_cash_flow, maps:get(old_cash_flow_inverted, Plan)), NewCashFlow = ff_cash_flow_codec:marshal(final_cash_flow, maps:get(new_cash_flow, Plan)), #deposit_revert_adj_CashFlowChangePlan{ - old_cash_flow_inverted = OldCashFLow, + old_cash_flow_inverted = OldCashFlow, new_cash_flow = NewCashFlow }; marshal(status_change_plan, Plan) -> diff --git a/apps/ff_server/src/ff_destination_codec.erl b/apps/ff_server/src/ff_destination_codec.erl index 118e3a31..e99c7a63 100644 --- a/apps/ff_server/src/ff_destination_codec.erl +++ b/apps/ff_server/src/ff_destination_codec.erl @@ -73,10 +73,10 @@ marshal(change, {status_changed, StatusChange}) -> {status, marshal(status_change, StatusChange)}; marshal( create_change, - Destination = #{ + #{ name := Name, resource := Resource - } + } = Destination ) -> #destination_Destination{ name = Name, diff --git a/apps/ff_server/src/ff_identity_machinery_schema.erl b/apps/ff_server/src/ff_identity_machinery_schema.erl index bf5cb2e1..ed0727c5 100644 --- a/apps/ff_server/src/ff_identity_machinery_schema.erl +++ b/apps/ff_server/src/ff_identity_machinery_schema.erl @@ -4,7 +4,6 @@ -behaviour(machinery_mg_schema). -include_lib("fistful_proto/include/fistful_identity_thrift.hrl"). --include_lib("mg_proto/include/mg_proto_state_processing_thrift.hrl"). -export([get_version/1]). -export([marshal/3]). @@ -118,7 +117,7 @@ maybe_migrate_thrift_change(Change, _MigrateContext) -> Change. -spec maybe_migrate_change(legacy_change(), context()) -> ff_identity:event(). -maybe_migrate_change(Event = {created, #{version := 2, name := _}}, _MigrateContext) -> +maybe_migrate_change({created, #{version := 2, name := _}} = Event, _MigrateContext) -> Event; maybe_migrate_change({created, Identity = #{version := 2, id := ID}}, MigrateContext) -> Context = fetch_entity_context(ID, MigrateContext), diff --git a/apps/ff_server/src/ff_server.erl b/apps/ff_server/src/ff_server.erl index dd4df2f0..45cb4959 100644 --- a/apps/ff_server/src/ff_server.erl +++ b/apps/ff_server/src/ff_server.erl @@ -127,7 +127,7 @@ init([]) -> -spec enable_health_logging(erl_health:check()) -> erl_health:check(). enable_health_logging(Check) -> EvHandler = {erl_health_event_handler, []}, - maps:map(fun(_, V = {_, _, _}) -> #{runner => V, event_handler => EvHandler} end, Check). + maps:map(fun(_, {_, _, _} = V) -> #{runner => V, event_handler => EvHandler} end, Check). -spec get_prometheus_routes() -> [{iodata(), module(), _Opts :: any()}]. get_prometheus_routes() -> diff --git a/apps/ff_server/src/ff_source_codec.erl b/apps/ff_server/src/ff_source_codec.erl index 5856efb4..fc3eda42 100644 --- a/apps/ff_server/src/ff_source_codec.erl +++ b/apps/ff_server/src/ff_source_codec.erl @@ -70,10 +70,10 @@ marshal(change, {status_changed, Status}) -> {status, #source_StatusChange{status = marshal(status, Status)}}; marshal( source, - Source = #{ + #{ name := Name, resource := Resource - } + } = Source ) -> #source_Source{ id = marshal(id, ff_source:id(Source)), diff --git a/apps/ff_server/src/ff_w2w_transfer_adjustment_codec.erl b/apps/ff_server/src/ff_w2w_transfer_adjustment_codec.erl index 9efbf562..f183f719 100644 --- a/apps/ff_server/src/ff_w2w_transfer_adjustment_codec.erl +++ b/apps/ff_server/src/ff_w2w_transfer_adjustment_codec.erl @@ -54,10 +54,10 @@ marshal(changes_plan, Plan) -> new_status = maybe_marshal(status_change_plan, maps:get(new_status, Plan, undefined)) }; marshal(cash_flow_change_plan, Plan) -> - OldCashFLow = ff_cash_flow_codec:marshal(final_cash_flow, maps:get(old_cash_flow_inverted, Plan)), + OldCashFlow = ff_cash_flow_codec:marshal(final_cash_flow, maps:get(old_cash_flow_inverted, Plan)), NewCashFlow = ff_cash_flow_codec:marshal(final_cash_flow, maps:get(new_cash_flow, Plan)), #w2w_adj_CashFlowChangePlan{ - old_cash_flow_inverted = OldCashFLow, + old_cash_flow_inverted = OldCashFlow, new_cash_flow = NewCashFlow }; marshal(status_change_plan, Plan) -> diff --git a/apps/ff_server/src/ff_wallet_machinery_schema.erl b/apps/ff_server/src/ff_wallet_machinery_schema.erl index f80a3b89..57b113a5 100644 --- a/apps/ff_server/src/ff_wallet_machinery_schema.erl +++ b/apps/ff_server/src/ff_wallet_machinery_schema.erl @@ -3,9 +3,6 @@ %% Storage schema behaviour -behaviour(machinery_mg_schema). --include_lib("fistful_proto/include/fistful_wallet_thrift.hrl"). --include_lib("mg_proto/include/mg_proto_state_processing_thrift.hrl"). - -export([get_version/1]). -export([marshal/3]). -export([unmarshal/3]). @@ -90,7 +87,7 @@ unmarshal_event(undefined = Version, EncodedChange, Context0) -> {{ev, Timestamp, maybe_migrate(Change, Context1)}, Context1}. -spec maybe_migrate(any(), context()) -> ff_wallet:event(). -maybe_migrate(Event = {created, #{version := 2}}, _MigrateContext) -> +maybe_migrate({created, #{version := 2}} = Event, _MigrateContext) -> Event; maybe_migrate({created, Wallet = #{version := 1}}, MigrateContext) -> Context = diff --git a/apps/ff_server/src/ff_withdrawal_adjustment_codec.erl b/apps/ff_server/src/ff_withdrawal_adjustment_codec.erl index 433dfd84..3a037e69 100644 --- a/apps/ff_server/src/ff_withdrawal_adjustment_codec.erl +++ b/apps/ff_server/src/ff_withdrawal_adjustment_codec.erl @@ -55,10 +55,10 @@ marshal(changes_plan, Plan) -> new_domain_revision = maybe_marshal(domain_revision_change_plan, maps:get(new_domain_revision, Plan, undefined)) }; marshal(cash_flow_change_plan, Plan) -> - OldCashFLow = ff_cash_flow_codec:marshal(final_cash_flow, maps:get(old_cash_flow_inverted, Plan)), + OldCashFlow = ff_cash_flow_codec:marshal(final_cash_flow, maps:get(old_cash_flow_inverted, Plan)), NewCashFlow = ff_cash_flow_codec:marshal(final_cash_flow, maps:get(new_cash_flow, Plan)), #wthd_adj_CashFlowChangePlan{ - old_cash_flow_inverted = OldCashFLow, + old_cash_flow_inverted = OldCashFlow, new_cash_flow = NewCashFlow }; marshal(status_change_plan, Plan) -> diff --git a/apps/ff_server/src/ff_withdrawal_codec.erl b/apps/ff_server/src/ff_withdrawal_codec.erl index b5b3c1a8..e4a369eb 100644 --- a/apps/ff_server/src/ff_withdrawal_codec.erl +++ b/apps/ff_server/src/ff_withdrawal_codec.erl @@ -259,7 +259,7 @@ unmarshal(validation_result, {personal, Validation}) -> }}; unmarshal(validation_status, V) when V =:= valid; V =:= invalid -> V; -unmarshal(withdrawal, Withdrawal = #wthd_Withdrawal{}) -> +unmarshal(withdrawal, #wthd_Withdrawal{} = Withdrawal) -> ff_withdrawal:gen(#{ id => unmarshal(id, Withdrawal#wthd_Withdrawal.id), body => unmarshal(cash, Withdrawal#wthd_Withdrawal.body), diff --git a/apps/ff_server/src/ff_withdrawal_machinery_schema.erl b/apps/ff_server/src/ff_withdrawal_machinery_schema.erl index 7e83c275..5342edbe 100644 --- a/apps/ff_server/src/ff_withdrawal_machinery_schema.erl +++ b/apps/ff_server/src/ff_withdrawal_machinery_schema.erl @@ -3,8 +3,6 @@ %% Storage schema behaviour -behaviour(machinery_mg_schema). --include_lib("mg_proto/include/mg_proto_state_processing_thrift.hrl"). - -export([get_version/1]). -export([marshal/3]). -export([unmarshal/3]). @@ -96,7 +94,7 @@ unmarshal_event(undefined = Version, EncodedChange, Context) -> ), {{ev, Timestamp, maybe_migrate(Change, Context1)}, Context1}. -maybe_migrate(Ev = {created, #{version := 4}}, _MigrateParams) -> +maybe_migrate({created, #{version := 4}} = Ev, _MigrateParams) -> Ev; maybe_migrate({route_changed, Route}, _MigrateParams) -> {route_changed, maybe_migrate_route(Route)}; diff --git a/apps/ff_server/src/ff_withdrawal_session_codec.erl b/apps/ff_server/src/ff_withdrawal_session_codec.erl index 53994f69..82134af1 100644 --- a/apps/ff_server/src/ff_withdrawal_session_codec.erl +++ b/apps/ff_server/src/ff_withdrawal_session_codec.erl @@ -3,7 +3,6 @@ -behaviour(ff_codec). -include_lib("fistful_proto/include/fistful_wthd_session_thrift.hrl"). --include_lib("fistful_proto/include/fistful_fistful_base_thrift.hrl"). -export([marshal_state/3]). @@ -67,11 +66,11 @@ marshal(session_finished_status, {failed, Failure}) -> {failed, #wthd_session_SessionFinishedFailed{failure = marshal(failure, Failure)}}; marshal( withdrawal, - Params = #{ + #{ id := WithdrawalID, resource := Resource, cash := Cash - } + } = Params ) -> SenderIdentity = maps:get(sender, Params, undefined), ReceiverIdentity = maps:get(receiver, Params, undefined), @@ -86,7 +85,7 @@ marshal( session_id = maybe_marshal(id, SessionID), quote = maybe_marshal(quote, Quote) }; -marshal(identity, Identity = #{id := ID}) -> +marshal(identity, #{id := ID} = Identity) -> #wthd_session_Identity{ identity_id = marshal(id, ID), effective_challenge = maybe_marshal(challenge, maps:get(effective_challenge, Identity, undefined)) diff --git a/apps/ff_server/src/ff_withdrawal_session_machinery_schema.erl b/apps/ff_server/src/ff_withdrawal_session_machinery_schema.erl index 6c9fb931..4481106e 100644 --- a/apps/ff_server/src/ff_withdrawal_session_machinery_schema.erl +++ b/apps/ff_server/src/ff_withdrawal_session_machinery_schema.erl @@ -3,9 +3,6 @@ %% Storage schema behaviour -behaviour(machinery_mg_schema). --include_lib("fistful_proto/include/fistful_wthd_session_thrift.hrl"). --include_lib("mg_proto/include/mg_proto_state_processing_thrift.hrl"). - -export([get_version/1]). -export([marshal/3]). -export([unmarshal/3]). @@ -98,7 +95,7 @@ unmarshal_aux_state(undefined = Version, EncodedAuxState, Context0) -> {maybe_migrate_aux_state(AuxState, Context0), Context1}. -spec maybe_migrate(any(), context()) -> ff_withdrawal_session:event(). -maybe_migrate(Event = {created, #{version := 5}}, _Context) -> +maybe_migrate({created, #{version := 5}} = Event, _Context) -> Event; maybe_migrate( {created, diff --git a/apps/ff_server/src/ff_woody_event_handler.erl b/apps/ff_server/src/ff_woody_event_handler.erl index ea33d3f7..2cc120af 100644 --- a/apps/ff_server/src/ff_woody_event_handler.erl +++ b/apps/ff_server/src/ff_woody_event_handler.erl @@ -5,9 +5,9 @@ %% woody_event_handler behaviour callbacks -export([handle_event/4]). --spec handle_event(Event, RpcId, Meta, Opts) -> ok when +-spec handle_event(Event, RpcID, Meta, Opts) -> ok when Event :: woody_event_handler:event(), - RpcId :: woody:rpc_id() | undefined, + RpcID :: woody:rpc_id() | undefined, Meta :: woody_event_handler:event_meta(), Opts :: woody:options(). handle_event(Event, RpcID, RawMeta, Opts) -> diff --git a/apps/ff_transfer/src/ff_adapter_withdrawal_codec.erl b/apps/ff_transfer/src/ff_adapter_withdrawal_codec.erl index 854fe15c..9e8c5c62 100644 --- a/apps/ff_transfer/src/ff_adapter_withdrawal_codec.erl +++ b/apps/ff_transfer/src/ff_adapter_withdrawal_codec.erl @@ -3,7 +3,6 @@ -include_lib("damsel/include/dmsl_wthd_domain_thrift.hrl"). -include_lib("damsel/include/dmsl_wthd_provider_thrift.hrl"). -include_lib("damsel/include/dmsl_domain_thrift.hrl"). --include_lib("damsel/include/dmsl_base_thrift.hrl"). -include_lib("damsel/include/dmsl_msgpack_thrift.hrl"). -export([marshal/2]). @@ -242,7 +241,7 @@ marshal( account_name = maps:get(account_name, Wallet, undefined), account_identity_number = maps:get(account_identity_number, Wallet, undefined) }}; -marshal(resource, Resource = {generic, _}) -> +marshal(resource, {generic, _} = Resource) -> ff_dmsl_codec:marshal(payment_tool, Resource); marshal( withdrawal, diff --git a/apps/ff_transfer/src/ff_deposit.erl b/apps/ff_transfer/src/ff_deposit.erl index baf234eb..4605b83b 100644 --- a/apps/ff_transfer/src/ff_deposit.erl +++ b/apps/ff_transfer/src/ff_deposit.erl @@ -462,7 +462,7 @@ apply_event_({revert, _Ev} = Event, T) -> apply_event_({adjustment, _Ev} = Event, T) -> apply_adjustment_event(Event, T). -apply_negative_body(T = #{body := {Amount, Currency}}) when Amount < 0 -> +apply_negative_body(#{body := {Amount, Currency}} = T) when Amount < 0 -> T#{body => {-1 * Amount, Currency}, is_negative => true}; apply_negative_body(T) -> T. diff --git a/apps/ff_transfer/src/ff_deposit_revert.erl b/apps/ff_transfer/src/ff_deposit_revert.erl index 5293ae45..bcfa0575 100644 --- a/apps/ff_transfer/src/ff_deposit_revert.erl +++ b/apps/ff_transfer/src/ff_deposit_revert.erl @@ -337,14 +337,14 @@ apply_event_({p_transfer, Ev}, T) -> apply_event_({adjustment, _Ev} = Event, T) -> apply_adjustment_event(Event, T). -apply_negative_body(T = #{body := {Amount, Currency}}) when Amount < 0 -> +apply_negative_body(#{body := {Amount, Currency}} = T) when Amount < 0 -> T#{body => {-1 * Amount, Currency}, is_negative => true}; apply_negative_body(T) -> T. -spec maybe_migrate(event() | legacy_event()) -> event(). % Actual events -maybe_migrate(Ev = {limit_check, {wallet_receiver, _Details}}) -> +maybe_migrate({limit_check, {wallet_receiver, _Details}} = Ev) -> Ev; maybe_migrate({adjustment, _Payload} = Event) -> ff_adjustment_utils:maybe_migrate(Event); diff --git a/apps/ff_transfer/src/ff_destination.erl b/apps/ff_transfer/src/ff_destination.erl index deb46e4b..c28523ec 100644 --- a/apps/ff_transfer/src/ff_destination.erl +++ b/apps/ff_transfer/src/ff_destination.erl @@ -231,18 +231,18 @@ authorize(#{status := unauthorized}) -> authorize(#{status := authorized}) -> {ok, []}. --spec apply_event(event(), ff_maybe:maybe(destination_state())) -> destination_state(). +-spec apply_event(event(), ff_maybe:'maybe'(destination_state())) -> destination_state(). apply_event({created, Destination}, undefined) -> Destination; apply_event({status_changed, S}, Destination) -> Destination#{status => S}; -apply_event({account, Ev}, Destination = #{account := Account}) -> +apply_event({account, Ev}, #{account := Account} = Destination) -> Destination#{account => ff_account:apply_event(Ev, Account)}; apply_event({account, Ev}, Destination) -> apply_event({account, Ev}, Destination#{account => undefined}). -spec maybe_migrate(event() | legacy_event(), ff_machine:migrate_params()) -> event(). -maybe_migrate(Event = {created, #{version := ?ACTUAL_FORMAT_VERSION}}, _MigrateParams) -> +maybe_migrate({created, #{version := ?ACTUAL_FORMAT_VERSION}} = Event, _MigrateParams) -> Event; maybe_migrate({created, Destination = #{version := 4}}, MigrateParams) -> maybe_migrate( diff --git a/apps/ff_transfer/src/ff_destination_machine.erl b/apps/ff_transfer/src/ff_destination_machine.erl index 87189bc9..d2f46999 100644 --- a/apps/ff_transfer/src/ff_destination_machine.erl +++ b/apps/ff_transfer/src/ff_destination_machine.erl @@ -121,12 +121,10 @@ process_timeout(Machine, _, _Opts) -> process_timeout(authorize, St) -> D0 = destination(St), - case ff_destination:authorize(D0) of - {ok, Events} -> - #{ - events => ff_machine:emit_events(Events) - } - end. + {ok, Events} = ff_destination:authorize(D0), + #{ + events => ff_machine:emit_events(Events) + }. deduce_activity(#{status := unauthorized}) -> authorize; diff --git a/apps/ff_transfer/src/ff_limiter.erl b/apps/ff_transfer/src/ff_limiter.erl index 1704405b..21d9dc08 100644 --- a/apps/ff_transfer/src/ff_limiter.erl +++ b/apps/ff_transfer/src/ff_limiter.erl @@ -55,7 +55,7 @@ check_limits(TurnoverLimits, Withdrawal, Route, Iter) -> {error, {overflow, ErrorList}} end. -make_operation_segments(Withdrawal, _Route = #{terminal_id := TerminalID, provider_id := ProviderID}, Iter) -> +make_operation_segments(Withdrawal, #{terminal_id := TerminalID, provider_id := ProviderID} = _Route, Iter) -> [ genlib:to_binary(ProviderID), genlib:to_binary(TerminalID), @@ -93,7 +93,7 @@ get_batch_limit_values(_Context, [], _OperationIdSegments) -> get_batch_limit_values(Context, TurnoverLimits, OperationIdSegments) -> {LimitRequest, TurnoverLimitsMap} = prepare_limit_request(TurnoverLimits, OperationIdSegments), lists:map( - fun(Limit = #limiter_Limit{id = LimitID}) -> + fun(#limiter_Limit{id = LimitID} = Limit) -> #domain_TurnoverLimit{upper_boundary = UpperBoundary} = maps:get(LimitID, TurnoverLimitsMap), #{ id => LimitID, @@ -177,8 +177,8 @@ split_turnover_limits_by_available_limiter_api(TurnoverLimits) -> prepare_limit_request(TurnoverLimits, IdSegments) -> {TurnoverLimitsIdList, LimitChanges} = lists:unzip( lists:map( - fun(TurnoverLimit = #domain_TurnoverLimit{id = Id, domain_revision = DomainRevision}) -> - {{Id, TurnoverLimit}, #limiter_LimitChange{id = Id, version = DomainRevision}} + fun(#domain_TurnoverLimit{id = ID, domain_revision = DomainRevision} = TurnoverLimit) -> + {{ID, TurnoverLimit}, #limiter_LimitChange{id = ID, version = DomainRevision}} end, TurnoverLimits ) diff --git a/apps/ff_transfer/src/ff_source.erl b/apps/ff_transfer/src/ff_source.erl index 677d6e5f..c969bf85 100644 --- a/apps/ff_transfer/src/ff_source.erl +++ b/apps/ff_transfer/src/ff_source.erl @@ -205,18 +205,18 @@ authorize(#{status := unauthorized}) -> authorize(#{status := authorized}) -> {ok, []}. --spec apply_event(event(), ff_maybe:maybe(source_state())) -> source_state(). +-spec apply_event(event(), ff_maybe:'maybe'(source_state())) -> source_state(). apply_event({created, Source}, undefined) -> Source; apply_event({status_changed, S}, Source) -> Source#{status => S}; -apply_event({account, Ev}, Source = #{account := Account}) -> +apply_event({account, Ev}, #{account := Account} = Source) -> Source#{account => ff_account:apply_event(Ev, Account)}; apply_event({account, Ev}, Source) -> apply_event({account, Ev}, Source#{account => undefined}). -spec maybe_migrate(event() | legacy_event(), ff_machine:migrate_params()) -> event(). -maybe_migrate(Event = {created, #{version := ?ACTUAL_FORMAT_VERSION}}, _MigrateParams) -> +maybe_migrate({created, #{version := ?ACTUAL_FORMAT_VERSION}} = Event, _MigrateParams) -> Event; maybe_migrate({created, Source = #{version := 3}}, MigrateParams) -> maybe_migrate( diff --git a/apps/ff_transfer/src/ff_source_machine.erl b/apps/ff_transfer/src/ff_source_machine.erl index 3ed824cd..3fee6d63 100644 --- a/apps/ff_transfer/src/ff_source_machine.erl +++ b/apps/ff_transfer/src/ff_source_machine.erl @@ -121,12 +121,10 @@ process_timeout(Machine, _, _Opts) -> process_timeout(authorize, St) -> D0 = source(St), - case ff_source:authorize(D0) of - {ok, Events} -> - #{ - events => ff_machine:emit_events(Events) - } - end. + {ok, Events} = ff_source:authorize(D0), + #{ + events => ff_machine:emit_events(Events) + }. deduce_activity(#{status := unauthorized}) -> authorize; diff --git a/apps/ff_transfer/src/ff_withdrawal.erl b/apps/ff_transfer/src/ff_withdrawal.erl index 572ccece..b72391f5 100644 --- a/apps/ff_transfer/src/ff_withdrawal.erl +++ b/apps/ff_transfer/src/ff_withdrawal.erl @@ -1256,7 +1256,7 @@ construct_payment_tool({bank_card, #{bank_card := ResourceBankCard}}) -> }}; construct_payment_tool({crypto_wallet, #{crypto_wallet := #{currency := Currency}}}) -> {crypto_currency, ff_dmsl_codec:marshal(crypto_currency, Currency)}; -construct_payment_tool(Resource = {generic, _}) -> +construct_payment_tool({generic, _} = Resource) -> ff_dmsl_codec:marshal(payment_tool, Resource); construct_payment_tool( {digital_wallet, #{ @@ -1279,7 +1279,7 @@ construct_payment_tool( -spec get_quote(quote_params()) -> {ok, quote()} | {error, create_error() | {route, ff_withdrawal_routing:route_not_found()}}. -get_quote(Params = #{destination_id := DestinationID, body := Body, wallet_id := WalletID}) -> +get_quote(#{destination_id := DestinationID, body := Body, wallet_id := WalletID} = Params) -> do(fun() -> Destination = unwrap(destination, get_destination(DestinationID)), Wallet = unwrap(wallet, get_wallet(WalletID)), @@ -1696,7 +1696,7 @@ validate_change_same_domain_revision(DomainRevision, DomainRevision) -> | {error, {unavailable_status, status()}}. validate_current_status(succeeded) -> {ok, valid}; -validate_current_status(Status = {failed, _Failure}) -> +validate_current_status({failed, _Failure} = Status) -> {error, {unavailable_status, Status}}; validate_current_status(Status) -> {error, {unavailable_status, Status}}. @@ -1915,17 +1915,14 @@ update_adjusment_index(Updater, Value, Withdrawal) -> -spec build_failure(fail_type(), withdrawal_state()) -> failure(). build_failure(limit_check, Withdrawal) -> - {failed, Details} = limit_check_status(Withdrawal), - case Details of - {wallet_sender, _WalletLimitDetails} -> - #{ - code => <<"account_limit_exceeded">>, - reason => genlib:format(Details), - sub => #{ - code => <<"amount">> - } - } - end; + {failed, {wallet_sender, _WalletLimitDetails} = Details} = limit_check_status(Withdrawal), + #{ + code => <<"account_limit_exceeded">>, + reason => genlib:format(Details), + sub => #{ + code => <<"amount">> + } + }; build_failure({route_not_found, []}, _Withdrawal) -> #{ code => <<"no_route_found">> @@ -1962,13 +1959,13 @@ get_quote_field(terminal_id, #{route := Route}) -> %% --spec apply_event(event() | legacy_event(), ff_maybe:maybe(withdrawal_state())) -> withdrawal_state(). +-spec apply_event(event() | legacy_event(), ff_maybe:'maybe'(withdrawal_state())) -> withdrawal_state(). apply_event(Ev, T0) -> T1 = apply_event_(Ev, T0), T2 = save_adjustable_info(Ev, T1), T2. --spec apply_event_(event(), ff_maybe:maybe(withdrawal_state())) -> withdrawal_state(). +-spec apply_event_(event(), ff_maybe:'maybe'(withdrawal_state())) -> withdrawal_state(). apply_event_({created, T}, undefined) -> make_state(T); apply_event_({status_changed, Status}, T) -> diff --git a/apps/ff_transfer/src/ff_withdrawal_callback.erl b/apps/ff_transfer/src/ff_withdrawal_callback.erl index 48e443f5..41cea46b 100644 --- a/apps/ff_transfer/src/ff_withdrawal_callback.erl +++ b/apps/ff_transfer/src/ff_withdrawal_callback.erl @@ -103,13 +103,11 @@ create(#{tag := Tag}) -> -spec process_response(response(), callback()) -> process_result(). process_response(Response, Callback) -> - case status(Callback) of - pending -> - [ - {finished, Response}, - {status_changed, succeeded} - ] - end. + pending = status(Callback), + [ + {finished, Response}, + {status_changed, succeeded} + ]. %% Utils diff --git a/apps/ff_transfer/src/ff_withdrawal_route_attempt_utils.erl b/apps/ff_transfer/src/ff_withdrawal_route_attempt_utils.erl index b47af8e8..20f1121b 100644 --- a/apps/ff_transfer/src/ff_withdrawal_route_attempt_utils.erl +++ b/apps/ff_transfer/src/ff_withdrawal_route_attempt_utils.erl @@ -143,7 +143,7 @@ update_current_session(Session, Attempts) -> update_current(Updated, Attempts). -spec update_current_p_transfer(p_transfer(), attempts()) -> attempts(). -update_current_p_transfer(PTransfer, Attempts = #{index := Index}) -> +update_current_p_transfer(PTransfer, #{index := Index} = Attempts) -> Attempt = current(Attempts), Updated = Attempt#{ p_transfer => PTransfer diff --git a/apps/ff_transfer/src/ff_withdrawal_routing.erl b/apps/ff_transfer/src/ff_withdrawal_routing.erl index a8f48f33..16dfa3b1 100644 --- a/apps/ff_transfer/src/ff_withdrawal_routing.erl +++ b/apps/ff_transfer/src/ff_withdrawal_routing.erl @@ -88,7 +88,7 @@ gather_routes(PartyVarset, Context) -> -spec gather_routes(party_varset(), routing_context(), [terminal_id()]) -> routing_state(). -gather_routes(PartyVarset, Context = #{identity := Identity, domain_revision := DomainRevision}, ExcludeRoutes) -> +gather_routes(PartyVarset, #{identity := Identity, domain_revision := DomainRevision} = Context, ExcludeRoutes) -> {ok, PaymentInstitutionID} = ff_party:get_identity_payment_institution_id(Identity), {ok, PaymentInstitution} = ff_payment_institution:get(PaymentInstitutionID, PartyVarset, DomainRevision), {Routes, RejectContext} = ff_routing_rule:gather_routes( @@ -230,7 +230,7 @@ process_routes_with(Func, Routes, PartyVarset, RoutingContext) -> routing_state(). validate_routes_with(Func, #{routes := Routes, reject_context := RejectContext}, PartyVarset, RoutingContext) -> lists:foldl( - fun(Route, State = #{routes := ValidRoutes0, reject_context := RejectContext0}) -> + fun(Route, #{routes := ValidRoutes0, reject_context := RejectContext0} = State) -> ProviderRef = maps:get(provider_ref, Route), TerminalRef = maps:get(terminal_ref, Route), case get_route_terms_and_process(Func, ProviderRef, TerminalRef, PartyVarset, RoutingContext) of @@ -249,7 +249,7 @@ validate_routes_with(Func, #{routes := Routes, reject_context := RejectContext}, ). get_route_terms_and_process( - Func, ProviderRef, TerminalRef, PartyVarset, RoutingContext = #{domain_revision := DomainRevision} + Func, ProviderRef, TerminalRef, PartyVarset, #{domain_revision := DomainRevision} = RoutingContext ) -> case ff_party:compute_provider_terminal_terms(ProviderRef, TerminalRef, PartyVarset, DomainRevision) of {ok, #domain_ProvisionTermSet{ @@ -265,7 +265,7 @@ get_route_terms_and_process( exclude_routes(#{routes := Routes, reject_context := RejectContext}, ExcludeRoutes) -> lists:foldl( - fun(Route, State = #{routes := ValidRoutes0, reject_context := RejectContext0}) -> + fun(Route, #{routes := ValidRoutes0, reject_context := RejectContext0} = State) -> ProviderRef = maps:get(provider_ref, Route), TerminalRef = maps:get(terminal_ref, Route), case not lists:member(ff_routing_rule:terminal_id(Route), ExcludeRoutes) of diff --git a/apps/ff_transfer/src/ff_withdrawal_session.erl b/apps/ff_transfer/src/ff_withdrawal_session.erl index e472619f..9a7c7459 100644 --- a/apps/ff_transfer/src/ff_withdrawal_session.erl +++ b/apps/ff_transfer/src/ff_withdrawal_session.erl @@ -4,8 +4,6 @@ -module(ff_withdrawal_session). --include_lib("damsel/include/dmsl_domain_thrift.hrl"). - %% Accessors -export([id/1]). @@ -176,7 +174,7 @@ result(_) -> undefined. -spec transaction_info(session_state()) -> transaction_info() | undefined. -transaction_info(Session = #{}) -> +transaction_info(#{} = Session) -> maps:get(transaction_info, Session, undefined). %% @@ -243,7 +241,7 @@ assert_transaction_info(NewTrxInfo, _TrxInfo) -> erlang:error({transaction_info_is_different, NewTrxInfo}). -spec set_session_result(session_result(), session_state()) -> process_result(). -set_session_result(Result, Session = #{status := active}) -> +set_session_result(Result, #{status := active} = Session) -> process_adapter_intent({finish, Result}, Session). -spec process_callback(callback_params(), session_state()) -> diff --git a/apps/ff_transfer/test/ff_ct_barrier.erl b/apps/ff_transfer/test/ff_ct_barrier.erl index 63f5049e..3294114b 100644 --- a/apps/ff_transfer/test/ff_ct_barrier.erl +++ b/apps/ff_transfer/test/ff_ct_barrier.erl @@ -43,10 +43,10 @@ init(_Args) -> -spec handle_call(enter | release, caller(), st()) -> {noreply, st()} | {reply, ok, st()}. -handle_call(enter, From = {ClientPid, _}, St = #{blocked := Blocked}) -> +handle_call(enter, {ClientPid, _} = From, #{blocked := Blocked} = St) -> false = lists:any(fun({Pid, _}) -> Pid == ClientPid end, Blocked), {noreply, St#{blocked => [From | Blocked]}}; -handle_call(release, _From, St = #{blocked := Blocked}) -> +handle_call(release, _From, #{blocked := Blocked} = St) -> ok = lists:foreach(fun(Caller) -> gen_server:reply(Caller, ok) end, Blocked), {reply, ok, St#{blocked => []}}; handle_call(Call, _From, _St) -> diff --git a/apps/ff_transfer/test/ff_ct_machine.erl b/apps/ff_transfer/test/ff_ct_machine.erl index 74d456fd..f40d5c63 100644 --- a/apps/ff_transfer/test/ff_ct_machine.erl +++ b/apps/ff_transfer/test/ff_ct_machine.erl @@ -25,11 +25,11 @@ unload_per_suite() -> -type hook() :: fun((machinery:machine(_, _), module(), _Args) -> _). -spec set_hook(timeout, hook()) -> ok. -set_hook(On = timeout, Fun) when is_function(Fun, 3) -> +set_hook(timeout = On, Fun) when is_function(Fun, 3) -> persistent_term:put({?MODULE, hook, On}, Fun). -spec clear_hook(timeout) -> ok. -clear_hook(On = timeout) -> +clear_hook(timeout = On) -> _ = persistent_term:erase({?MODULE, hook, On}), ok. diff --git a/apps/ff_transfer/test/ff_limiter_helper.erl b/apps/ff_transfer/test/ff_limiter_helper.erl index 9b2a5463..cb85bef9 100644 --- a/apps/ff_transfer/test/ff_limiter_helper.erl +++ b/apps/ff_transfer/test/ff_limiter_helper.erl @@ -36,7 +36,7 @@ get_limit_amount(LimitID, Version, Withdrawal, Config) -> Amount. -spec get_limit(id(), dmt_client:vsn(), withdrawal(), config()) -> limit(). -get_limit(LimitId, Version, Withdrawal, Config) -> +get_limit(LimitID, Version, Withdrawal, Config) -> MarshaledWithdrawal = maybe_marshal_withdrawal(Withdrawal), Context = #limiter_LimitContext{ withdrawal_processing = #context_withdrawal_Context{ @@ -44,7 +44,7 @@ get_limit(LimitId, Version, Withdrawal, Config) -> withdrawal = #context_withdrawal_Withdrawal{withdrawal = MarshaledWithdrawal} } }, - maybe_uninitialized_limit(ff_ct_limiter_client:get(LimitId, Version, Context, ct_helper:get_woody_ctx(Config))). + maybe_uninitialized_limit(ff_ct_limiter_client:get(LimitID, Version, Context, ct_helper:get_woody_ctx(Config))). -spec maybe_uninitialized_limit({ok, _} | {exception, _}) -> _Limit. maybe_uninitialized_limit({ok, Limit}) -> @@ -57,7 +57,7 @@ maybe_uninitialized_limit({exception, _}) -> description = undefined }. -maybe_marshal_withdrawal(Withdrawal = #wthd_domain_Withdrawal{}) -> +maybe_marshal_withdrawal(#wthd_domain_Withdrawal{} = Withdrawal) -> Withdrawal; maybe_marshal_withdrawal(Withdrawal) -> ff_limiter:marshal_withdrawal(Withdrawal). diff --git a/apps/fistful/src/ff_account.erl b/apps/fistful/src/ff_account.erl index 358b1475..af15a31a 100644 --- a/apps/fistful/src/ff_account.erl +++ b/apps/fistful/src/ff_account.erl @@ -142,6 +142,6 @@ get_identity(Account) -> %% State --spec apply_event(event(), ff_maybe:maybe(account())) -> account(). +-spec apply_event(event(), ff_maybe:'maybe'(account())) -> account(). apply_event({created, Account}, undefined) -> Account. diff --git a/apps/fistful/src/ff_dmsl_codec.erl b/apps/fistful/src/ff_dmsl_codec.erl index 7ffad52c..458e1780 100644 --- a/apps/fistful/src/ff_dmsl_codec.erl +++ b/apps/fistful/src/ff_dmsl_codec.erl @@ -224,20 +224,20 @@ maybe_unmarshal(Type, V) -> unmarshal(Type, V). -spec marshal(ff_dmsl_codec:type_name(), ff_dmsl_codec:decoded_value()) -> ff_dmsl_codec:encoded_value(). -marshal(transaction_info, V = #{id := ID}) -> +marshal(transaction_info, #{id := ID} = V) -> #domain_TransactionInfo{ id = marshal(string, ID), timestamp = maybe_marshal(string, maps:get(timestamp, V, undefined)), extra = maps:get(extra, V, #{}) % TODO additional info }; -marshal(failure, V = #{code := Code}) -> +marshal(failure, #{code := Code} = V) -> #domain_Failure{ code = marshal(string, Code), reason = maybe_marshal(string, maps:get(reason, V, undefined)), sub = maybe_marshal(sub_failure, maps:get(sub, V, undefined)) }; -marshal(sub_failure, V = #{code := Code}) -> +marshal(sub_failure, #{code := Code} = V) -> #domain_SubFailure{ code = marshal(string, Code), sub = maybe_marshal(sub_failure, maps:get(sub, V, undefined)) @@ -280,7 +280,7 @@ marshal(payment_method, {crypto_currency, CryptoCurrencyRef}) -> {crypto_currency, marshal(crypto_currency, CryptoCurrencyRef)}; marshal(payment_method, {bank_card, #{payment_system := PaymentSystem}}) -> {bank_card, #domain_BankCardPaymentMethod{payment_system = marshal(payment_system, PaymentSystem)}}; -marshal(payment_resource_payer, Payer = #{resource := Resource}) -> +marshal(payment_resource_payer, #{resource := Resource} = Payer) -> ClientInfo = maps:get(client_info, Payer, undefined), ContactInfo = maps:get(contact_info, Payer, undefined), #domain_PaymentResourcePayer{ diff --git a/apps/fistful/src/ff_identity.erl b/apps/fistful/src/ff_identity.erl index 0f4d654e..baa75ca1 100644 --- a/apps/fistful/src/ff_identity.erl +++ b/apps/fistful/src/ff_identity.erl @@ -186,7 +186,7 @@ set_blocking(Identity) -> -spec create(params()) -> {ok, [event()]} | {error, create_error()}. -create(Params = #{id := ID, name := Name, party := Party, provider := ProviderID}) -> +create(#{id := ID, name := Name, party := Party, provider := ProviderID} = Params) -> do(fun() -> Provider = unwrap(check_identity_creation(#{party => Party, provider => ProviderID})), Contract = unwrap( @@ -257,7 +257,7 @@ get_terms(Identity, Params) -> %% --spec apply_event(event(), ff_maybe:maybe(identity_state())) -> identity_state(). +-spec apply_event(event(), ff_maybe:'maybe'(identity_state())) -> identity_state(). apply_event({created, Identity}, undefined) -> Identity; apply_event({level_changed, _L}, Identity) -> diff --git a/apps/fistful/src/ff_identity_machine.erl b/apps/fistful/src/ff_identity_machine.erl index 28ec04b5..9d7aa7b0 100644 --- a/apps/fistful/src/ff_identity_machine.erl +++ b/apps/fistful/src/ff_identity_machine.erl @@ -66,7 +66,7 @@ | {error, ff_identity:create_error() | exists}. -create(Params = #{id := ID}, Ctx) -> +create(#{id := ID} = Params, Ctx) -> do(fun() -> Events = unwrap(ff_identity:create(Params)), unwrap(machinery:start(?NS, ID, {Events, Ctx}, backend())) diff --git a/apps/fistful/src/ff_limit.erl b/apps/fistful/src/ff_limit.erl index 6d747bc5..171aa07a 100644 --- a/apps/fistful/src/ff_limit.erl +++ b/apps/fistful/src/ff_limit.erl @@ -264,19 +264,19 @@ head(#{head := Head}) -> lookup_trx(TrxID, #{trxs := Trxs}) -> maps:find(TrxID, Trxs). -record_trx(Trx, St = #{head := Head, trxs := Trxs}) -> +record_trx(Trx, #{head := Head, trxs := Trxs} = St) -> St#{ head := ff_indef:account(get_trx_dv(Trx), Head), trxs := maps:put(get_trx_id(Trx), Trx, Trxs) }. -confirm_trx(Trx, St = #{head := Head, trxs := Trxs}) -> +confirm_trx(Trx, #{head := Head, trxs := Trxs} = St) -> St#{ head := ff_indef:confirm(get_trx_dv(Trx), Head), trxs := maps:remove(get_trx_id(Trx), Trxs) }. -reject_trx(Trx, St = #{head := Head, trxs := Trxs}) -> +reject_trx(Trx, #{head := Head, trxs := Trxs} = St) -> St#{ head := ff_indef:reject(get_trx_dv(Trx), Head), trxs := maps:remove(get_trx_id(Trx), Trxs) diff --git a/apps/fistful/src/ff_machine.erl b/apps/fistful/src/ff_machine.erl index ab148b6c..d00eb282 100644 --- a/apps/fistful/src/ff_machine.erl +++ b/apps/fistful/src/ff_machine.erl @@ -179,13 +179,13 @@ merge_event(Mod, {_ID, _Ts, TsEvent}, St0) -> Model1 = Mod:apply_event(Ev, maps:get(model, St1, undefined)), St1#{model => Model1}. -merge_timestamped_event({ev, Ts, Body}, St = #{times := {Created, _Updated}}) -> +merge_timestamped_event({ev, Ts, Body}, #{times := {Created, _Updated}} = St) -> {Body, St#{times => {Created, Ts}}}; -merge_timestamped_event({ev, Ts, Body}, St = #{}) -> +merge_timestamped_event({ev, Ts, Body}, #{} = St) -> {Body, St#{times => {Ts, Ts}}}. -spec migrate_machine(module(), machine()) -> machine(). -migrate_machine(Mod, Machine = #{history := History}) -> +migrate_machine(Mod, #{history := History} = Machine) -> MigrateParams = #{ ctx => maps:get(ctx, maps:get(aux_state, Machine, #{}), undefined), id => maps:get(id, Machine, undefined) diff --git a/apps/fistful/src/ff_machine_tag.erl b/apps/fistful/src/ff_machine_tag.erl index 2884e3cf..f773e7fc 100644 --- a/apps/fistful/src/ff_machine_tag.erl +++ b/apps/fistful/src/ff_machine_tag.erl @@ -27,10 +27,8 @@ create_binding(NS, Tag, EntityID) -> create_binding_(NS, Tag, EntityID, Context) -> WoodyContext = ff_context:get_woody_context(ff_context:load()), - case bender_client:gen_constant(tag_to_external_id(NS, Tag), EntityID, WoodyContext, Context) of - {ok, EntityID} -> - ok - end. + {ok, EntityID} = bender_client:gen_constant(tag_to_external_id(NS, Tag), EntityID, WoodyContext, Context), + ok. tag_to_external_id(NS, Tag) -> BinNS = atom_to_binary(NS, utf8), diff --git a/apps/fistful/src/ff_postings_transfer.erl b/apps/fistful/src/ff_postings_transfer.erl index 40086c46..d911a68b 100644 --- a/apps/fistful/src/ff_postings_transfer.erl +++ b/apps/fistful/src/ff_postings_transfer.erl @@ -124,7 +124,7 @@ validate_identities([A0 | Accounts]) -> -spec prepare(transfer()) -> {ok, [event()]} | {error, {status, committed | cancelled}}. -prepare(Transfer = #{status := created}) -> +prepare(#{status := created} = Transfer) -> ID = id(Transfer), CashFlow = final_cash_flow(Transfer), do(fun() -> @@ -145,7 +145,7 @@ prepare(#{status := Status}) -> -spec commit(transfer()) -> {ok, [event()]} | {error, {status, created | cancelled}}. -commit(Transfer = #{status := prepared}) -> +commit(#{status := prepared} = Transfer) -> ID = id(Transfer), CashFlow = final_cash_flow(Transfer), do(fun() -> @@ -162,7 +162,7 @@ commit(#{status := Status}) -> -spec cancel(transfer()) -> {ok, [event()]} | {error, {status, created | committed}}. -cancel(Transfer = #{status := prepared}) -> +cancel(#{status := prepared} = Transfer) -> ID = id(Transfer), CashFlow = final_cash_flow(Transfer), do(fun() -> @@ -176,7 +176,7 @@ cancel(#{status := Status}) -> %% --spec apply_event(event(), ff_maybe:maybe(transfer())) -> transfer(). +-spec apply_event(event(), ff_maybe:'maybe'(transfer())) -> transfer(). apply_event({created, Transfer}, undefined) -> Transfer; apply_event({status_changed, S}, Transfer) -> @@ -287,7 +287,7 @@ maybe_migrate_account({destination, DestinationID}) -> maybe_migrate_account(Account) when is_map(Account) -> Account. -maybe_migrate_final_account(Account = #{type := _Type}, _, _) -> +maybe_migrate_final_account(#{type := _Type} = Account, _, _) -> Account; maybe_migrate_final_account(Account, receiver, withdrawal) -> Account#{type => {wallet, receiver_destination}}; diff --git a/apps/fistful/src/ff_resource.erl b/apps/fistful/src/ff_resource.erl index 6b285e95..65c29b8e 100644 --- a/apps/fistful/src/ff_resource.erl +++ b/apps/fistful/src/ff_resource.erl @@ -1,7 +1,5 @@ -module(ff_resource). --include_lib("damsel/include/dmsl_domain_thrift.hrl"). - -type resource() :: {bank_card, resource_bank_card()} | {crypto_wallet, resource_crypto_wallet()} @@ -194,53 +192,53 @@ token(#{token := Token}) -> Token. --spec bin(bank_card()) -> ff_maybe:maybe(bin()). +-spec bin(bank_card()) -> ff_maybe:'maybe'(bin()). bin(BankCard) -> maps:get(bin, BankCard, undefined). --spec bin_data_id(bank_card()) -> ff_maybe:maybe(bin_data_id()). +-spec bin_data_id(bank_card()) -> ff_maybe:'maybe'(bin_data_id()). bin_data_id(BankCard) -> maps:get(bin_data_id, BankCard, undefined). --spec masked_pan(bank_card()) -> ff_maybe:maybe(masked_pan()). +-spec masked_pan(bank_card()) -> ff_maybe:'maybe'(masked_pan()). masked_pan(BankCard) -> maps:get(masked_pan, BankCard, undefined). --spec payment_system(bank_card()) -> ff_maybe:maybe(payment_system()). +-spec payment_system(bank_card()) -> ff_maybe:'maybe'(payment_system()). payment_system(BankCard) -> maps:get(payment_system, BankCard, undefined). --spec issuer_country(bank_card()) -> ff_maybe:maybe(issuer_country()). +-spec issuer_country(bank_card()) -> ff_maybe:'maybe'(issuer_country()). issuer_country(BankCard) -> maps:get(issuer_country, BankCard, undefined). --spec category(bank_card()) -> ff_maybe:maybe(category()). +-spec category(bank_card()) -> ff_maybe:'maybe'(category()). category(BankCard) -> maps:get(category, BankCard, undefined). --spec bank_name(bank_card()) -> ff_maybe:maybe(bank_name()). +-spec bank_name(bank_card()) -> ff_maybe:'maybe'(bank_name()). bank_name(BankCard) -> maps:get(bank_name, BankCard, undefined). --spec exp_date(bank_card()) -> ff_maybe:maybe(exp_date()). +-spec exp_date(bank_card()) -> ff_maybe:'maybe'(exp_date()). exp_date(BankCard) -> maps:get(exp_date, BankCard, undefined). --spec card_type(bank_card()) -> ff_maybe:maybe(card_type()). +-spec card_type(bank_card()) -> ff_maybe:'maybe'(card_type()). card_type(BankCard) -> maps:get(card_type, BankCard, undefined). --spec cardholder_name(bank_card()) -> ff_maybe:maybe(cardholder_name()). +-spec cardholder_name(bank_card()) -> ff_maybe:'maybe'(cardholder_name()). cardholder_name(BankCard) -> maps:get(cardholder_name, BankCard, undefined). --spec resource_descriptor(ff_maybe:maybe(resource())) -> ff_maybe:maybe(resource_descriptor()). +-spec resource_descriptor(ff_maybe:'maybe'(resource())) -> ff_maybe:'maybe'(resource_descriptor()). resource_descriptor({bank_card, #{bank_card := #{bin_data_id := ID}}}) -> {bank_card, ID}; resource_descriptor(_) -> undefined. --spec method(resource()) -> ff_maybe:maybe(method()). +-spec method(resource()) -> ff_maybe:'maybe'(method()). method({bank_card, #{bank_card := #{payment_system := PaymentSystem}}}) -> {bank_card, #{payment_system => PaymentSystem}}; method({digital_wallet, #{digital_wallet := #{payment_service := PaymentService}}}) -> @@ -252,7 +250,7 @@ method({generic, #{generic := #{provider := PaymentService}}}) -> method(_) -> undefined. --spec get_bin_data(binary(), ff_maybe:maybe(resource_descriptor())) -> +-spec get_bin_data(binary(), ff_maybe:'maybe'(resource_descriptor())) -> {ok, bin_data()} | {error, bin_data_error()}. get_bin_data(Token, undefined) -> diff --git a/apps/fistful/src/ff_wallet.erl b/apps/fistful/src/ff_wallet.erl index 0c183dd3..4ab1f352 100644 --- a/apps/fistful/src/ff_wallet.erl +++ b/apps/fistful/src/ff_wallet.erl @@ -146,7 +146,7 @@ metadata(Wallet) -> -spec create(params()) -> {ok, [event()]} | {error, create_error()}. -create(Params = #{id := ID, name := Name}) -> +create(#{id := ID, name := Name} = Params) -> do(fun() -> {Identity, Currency} = unwrap(check_creation(maps:with([identity, currency], Params))), Wallet = genlib_map:compact(#{ diff --git a/apps/fistful/src/ff_wallet_machine.erl b/apps/fistful/src/ff_wallet_machine.erl index 26fb639d..eee6a629 100644 --- a/apps/fistful/src/ff_wallet_machine.erl +++ b/apps/fistful/src/ff_wallet_machine.erl @@ -65,7 +65,7 @@ ctx(St) -> %% -spec create(params(), ctx()) -> ok | {error, exists | ff_wallet:create_error()}. -create(Params = #{id := ID}, Ctx) -> +create(#{id := ID} = Params, Ctx) -> do(fun() -> Events = unwrap(ff_wallet:create(Params)), unwrap(machinery:start(?NS, ID, {Events, Ctx}, backend())) diff --git a/apps/fistful/src/ff_woody_client.erl b/apps/fistful/src/ff_woody_client.erl index 310eff11..9ca7b554 100644 --- a/apps/fistful/src/ff_woody_client.erl +++ b/apps/fistful/src/ff_woody_client.erl @@ -41,7 +41,7 @@ }. -spec new(woody:url() | opts()) -> client(). -new(Opts = #{url := _}) -> +new(#{url := _} = Opts) -> EventHandlerOpts = genlib_app:env(ff_server, scoper_event_handler_options, #{}), maps:merge( #{ diff --git a/apps/fistful/src/fistful.erl b/apps/fistful/src/fistful.erl index 9e53c056..a92dcc3c 100644 --- a/apps/fistful/src/fistful.erl +++ b/apps/fistful/src/fistful.erl @@ -70,7 +70,7 @@ notify(NS, ID, Range, Args, Backend) -> -type handler_opts() :: _. -spec init(args(_), machine(E, A), options(), handler_opts()) -> result(E, A). -init(Args, Machine, Options = #{handler := Handler}, MachineryOptions) -> +init(Args, Machine, #{handler := Handler} = Options, MachineryOptions) -> _ = scope(Machine, #{activity => init}, fun() -> ok = ff_context:save(create_context(Options, MachineryOptions)), try @@ -81,7 +81,7 @@ init(Args, Machine, Options = #{handler := Handler}, MachineryOptions) -> end). -spec process_timeout(machine(E, A), options(), handler_opts()) -> result(E, A). -process_timeout(Machine, Options = #{handler := Handler}, MachineryOptions) -> +process_timeout(Machine, #{handler := Handler} = Options, MachineryOptions) -> _ = scope(Machine, #{activity => timeout}, fun() -> ok = ff_context:save(create_context(Options, MachineryOptions)), try @@ -92,7 +92,7 @@ process_timeout(Machine, Options = #{handler := Handler}, MachineryOptions) -> end). -spec process_call(args(_), machine(E, A), options(), handler_opts()) -> {response(_), result(E, A)}. -process_call(Args, Machine, Options = #{handler := Handler}, MachineryOptions) -> +process_call(Args, Machine, #{handler := Handler} = Options, MachineryOptions) -> _ = scope(Machine, #{activity => call}, fun() -> ok = ff_context:save(create_context(Options, MachineryOptions)), try @@ -104,7 +104,7 @@ process_call(Args, Machine, Options = #{handler := Handler}, MachineryOptions) - -spec process_repair(args(_), machine(E, A), options(), handler_opts()) -> {ok, {response(_), result(E, A)}} | {error, machinery:error(_)}. -process_repair(Args, Machine, Options = #{handler := Handler}, MachineryOptions) -> +process_repair(Args, Machine, #{handler := Handler} = Options, MachineryOptions) -> _ = scope(Machine, #{activity => repair}, fun() -> ok = ff_context:save(create_context(Options, MachineryOptions)), try @@ -115,7 +115,7 @@ process_repair(Args, Machine, Options = #{handler := Handler}, MachineryOptions) end). -spec process_notification(args(_), machine(E, A), options(), handler_opts()) -> result(E, A). -process_notification(Args, Machine, Options = #{handler := Handler}, MachineryOptions) -> +process_notification(Args, Machine, #{handler := Handler} = Options, MachineryOptions) -> _ = scope(Machine, #{activity => notification}, fun() -> ok = ff_context:save(create_context(Options, MachineryOptions)), try diff --git a/apps/fistful/src/hg_cash_range.erl b/apps/fistful/src/hg_cash_range.erl index 25caf1e8..9ff0c5ea 100644 --- a/apps/fistful/src/hg_cash_range.erl +++ b/apps/fistful/src/hg_cash_range.erl @@ -10,7 +10,7 @@ -type cash() :: dmsl_domain_thrift:'Cash'(). -spec is_inside(cash(), cash_range()) -> within | {exceeds, lower | upper}. -is_inside(Cash, CashRange = #domain_CashRange{lower = Lower, upper = Upper}) -> +is_inside(Cash, #domain_CashRange{lower = Lower, upper = Upper} = CashRange) -> case { compare_cash(fun erlang:'>'/2, Cash, Lower), diff --git a/apps/machinery_extra/src/machinery_gensrv_backend.erl b/apps/machinery_extra/src/machinery_gensrv_backend.erl index 823b8675..7bd87f32 100644 --- a/apps/machinery_extra/src/machinery_gensrv_backend.erl +++ b/apps/machinery_extra/src/machinery_gensrv_backend.erl @@ -56,7 +56,7 @@ %% API -spec new(backend_opts()) -> backend(). -new(Opts = #{name := _}) -> +new(#{name := _} = Opts) -> {?MODULE, Opts}. -spec child_spec(logic_handler(_), backend_opts()) -> supervisor:child_spec(). @@ -171,7 +171,7 @@ construct_machine(NS, ID) -> -spec handle_call({call, range(), args(_)}, {pid(), reference()}, st(E, Aux, Args)) -> {reply, response(_), st(E, Aux, Args), timeout()} | {stop, normal, st(E, Aux, Args)}. -handle_call({call, Range, Args}, _From, St0 = #{machine := #{namespace := NS, id := ID}}) -> +handle_call({call, Range, Args}, _From, #{machine := #{namespace := NS, id := ID}} = St0) -> St1 = apply_range(Range, St0), _ = logger:debug("[machinery/gensrv][server][~s:~s] dispatching call: ~p with state: ~p", [NS, ID, Args, St1]), {Response, Result} = dispatch_call(Args, St0), @@ -183,7 +183,7 @@ handle_call({call, Range, Args}, _From, St0 = #{machine := #{namespace := NS, id _ = logger:debug("[machinery/gensrv][server][~s:~s] responded: ~p, removed", [NS, ID, Response]), {stop, normal, Response, St0} end; -handle_call({get, Range}, _From, St = #{machine := M}) -> +handle_call({get, Range}, _From, #{machine := M} = St) -> {reply, apply_range(Range, M), St, compute_timeout(St)}; handle_call(Call, _From, _St) -> error({badcall, Call}). @@ -195,7 +195,7 @@ handle_cast(Cast, _St) -> -spec handle_info(timeout, st(E, Aux, Args)) -> {noreply, st(E, Aux, Args), timeout()} | {stop, normal, st(E, Aux, Args)}. -handle_info(timeout, St0 = #{machine := #{namespace := NS, id := ID}}) -> +handle_info(timeout, #{machine := #{namespace := NS, id := ID}} = St0) -> _ = logger:debug("[machinery/gensrv][server][~s:~s] dispatching timeout with state: ~p", [NS, ID, St0]), Result = dispatch_signal(timeout, St0), case apply_result(Result, St0) of @@ -219,22 +219,22 @@ code_change(_OldVsn, St, _Extra) -> %% -apply_range(Range, St = #{machine := M}) -> +apply_range(Range, #{machine := M} = St) -> St#{machine := apply_range(Range, M)}; -apply_range(Range, M = #{history := H}) -> +apply_range(Range, #{history := H} = M) -> M#{history := select_range(Range, H)}. -apply_result(R = #{action := As}, St) -> +apply_result(#{action := As} = R, St) -> apply_result( maps:remove(action, R), apply_actions(As, St) ); -apply_result(R = #{events := Es}, St = #{machine := M}) -> +apply_result(#{events := Es} = R, #{machine := M} = St) -> apply_result( maps:remove(events, R), St#{machine := apply_events(Es, M)} ); -apply_result(R = #{aux_state := Aux}, St = #{machine := M}) -> +apply_result(#{aux_state := Aux} = R, #{machine := M} = St) -> apply_result( maps:remove(aux_state, R), St#{machine := apply_auxst(Aux, M)} @@ -256,7 +256,7 @@ apply_action(continue, St) -> apply_action(remove, _St) -> removed. -apply_events(Es, M = #{history := Hs}) -> +apply_events(Es, #{history := Hs} = M) -> Ts = machinery_time:now(), Hl = length(Hs), M#{ @@ -267,7 +267,7 @@ apply_events(Es, M = #{history := Hs}) -> ] }. -apply_auxst(Aux, M = #{}) -> +apply_auxst(Aux, #{} = M) -> M#{aux_state := Aux}. compute_deadline({timeout, V}) -> diff --git a/elvis.config b/elvis.config index 703d17a9..30ad5f7a 100644 --- a/elvis.config +++ b/elvis.config @@ -28,7 +28,11 @@ ff_withdrawal_machinery_schema, ff_withdrawal_session_machinery_schema ] - }} + }}, + %% TODO Review modules for compliance with rules + {elvis_style, export_used_types, disable}, + {elvis_style, no_throw, disable}, + {elvis_style, no_import, disable} ] }, #{ @@ -54,7 +58,10 @@ {elvis_style, state_record_and_type, disable}, % Tests are usually more comprehensible when a bit more verbose. {elvis_style, dont_repeat_yourself, #{min_complexity => 50}}, - {elvis_style, god_modules, disable} + {elvis_style, god_modules, disable}, + {elvis_style, export_used_types, disable}, + {elvis_style, no_import, disable}, + {elvis_style, no_block_expressions, disable} ] }, #{ @@ -76,7 +83,8 @@ {elvis_text_style, no_tabs}, {elvis_text_style, no_trailing_whitespace}, %% Temporarily disabled till regex pattern is available - {elvis_project, no_deps_master_rebar, disable} + {elvis_project, no_deps_master_rebar, disable}, + {elvis_project, no_branch_deps, disable} ] }, #{ diff --git a/rebar.config b/rebar.config index 1bbcd15e..b5c74cde 100644 --- a/rebar.config +++ b/rebar.config @@ -61,7 +61,6 @@ % mandatory unmatched_returns, error_handling, - race_conditions, unknown ]}, {plt_apps, all_deps} @@ -122,9 +121,9 @@ ]}. {project_plugins, [ - {rebar3_lint, "1.0.1"}, - {covertool, "2.0.4"}, - {erlfmt, "1.0.0"} + {rebar3_lint, "3.2.6"}, + {covertool, "2.0.7"}, + {erlfmt, "1.5.0"} ]}. {erlfmt, [