From 8d059b1be7ff2969f876f178d8c794782c1d4dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC?= Date: Mon, 10 Feb 2020 14:23:17 +0300 Subject: [PATCH] FF-157: Refactor create functions (#176) * refactored wip * updated proto # Conflicts: # apps/ff_server/src/ff_identity_codec.erl # apps/ff_server/src/ff_wallet_codec.erl # apps/wapi/src/wapi_identity_backend.erl # apps/wapi/src/wapi_wallet_backend.erl # apps/wapi/test/wapi_thrift_SUITE.erl # rebar.lock * fixed * updated proto # Conflicts: # apps/wapi/src/wapi_identity_backend.erl # rebar.lock * refactored * fixed * fixed --- apps/ff_cth/src/ct_payment_system.erl | 3 +- apps/ff_server/src/ff_codec.erl | 11 +++++- apps/ff_server/src/ff_destination_codec.erl | 1 + apps/ff_server/src/ff_destination_handler.erl | 2 +- apps/ff_server/src/ff_identity_codec.erl | 37 +++++++++++------- apps/ff_server/src/ff_identity_handler.erl | 8 ++-- .../ff_server/src/ff_server_admin_handler.erl | 3 +- apps/ff_server/src/ff_wallet_handler.erl | 3 +- .../test/ff_destination_handler_SUITE.erl | 3 +- apps/ff_server/test/ff_eventsink_SUITE.erl | 21 +++++----- .../test/ff_identity_handler_SUITE.erl | 12 +++--- .../test/ff_wallet_handler_SUITE.erl | 3 +- .../test/ff_withdrawal_handler_SUITE.erl | 2 +- .../ff_withdrawal_session_repair_SUITE.erl | 14 +++---- apps/ff_transfer/src/ff_destination.erl | 8 ++-- .../ff_transfer/src/ff_instrument_machine.erl | 13 +++++-- apps/ff_transfer/src/ff_source.erl | 8 ++-- apps/ff_transfer/test/ff_deposit_SUITE.erl | 10 ++--- .../test/ff_deposit_adjustment_SUITE.erl | 10 ++--- .../test/ff_deposit_revert_SUITE.erl | 10 ++--- .../ff_deposit_revert_adjustment_SUITE.erl | 10 ++--- apps/ff_transfer/test/ff_transfer_SUITE.erl | 17 ++++---- apps/ff_transfer/test/ff_withdrawal_SUITE.erl | 14 +++---- .../test/ff_withdrawal_adjustment_SUITE.erl | 10 ++--- apps/fistful/src/ff_identity.erl | 39 ++++++++++++------- apps/fistful/src/ff_identity_machine.erl | 7 ++-- apps/fistful/src/ff_wallet_machine.erl | 7 ++-- apps/fistful/test/ff_identity_SUITE.erl | 8 ++-- apps/fistful/test/ff_wallet_SUITE.erl | 18 ++++----- apps/p2p/test/p2p_quote_SUITE.erl | 3 +- apps/p2p/test/p2p_tests_utils.erl | 3 +- .../test/p2p_transfer_adjustment_SUITE.erl | 3 +- apps/wapi/src/wapi_wallet_ff_backend.erl | 11 +++--- rebar.lock | 2 +- 34 files changed, 175 insertions(+), 159 deletions(-) diff --git a/apps/ff_cth/src/ct_payment_system.erl b/apps/ff_cth/src/ct_payment_system.erl index c476285..20be15e 100644 --- a/apps/ff_cth/src/ct_payment_system.erl +++ b/apps/ff_cth/src/ct_payment_system.erl @@ -177,8 +177,7 @@ create_identity(PartyID, ProviderID, ClassID) -> create_identity(ID, PartyID, ProviderID, ClassID) -> ok = ff_identity_machine:create( - ID, - #{party => PartyID, provider => ProviderID, class => ClassID}, + #{id => ID, party => PartyID, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. diff --git a/apps/ff_server/src/ff_codec.erl b/apps/ff_server/src/ff_codec.erl index 5b05ad9..afd2ec1 100644 --- a/apps/ff_server/src/ff_codec.erl +++ b/apps/ff_server/src/ff_codec.erl @@ -57,8 +57,10 @@ marshal(id, V) -> marshal(event_id, V) -> marshal(integer, V); -marshal(blocked, V) -> - marshal(bool, V); +marshal(blocking, blocked) -> + blocked; +marshal(blocking, unblocked) -> + unblocked; marshal(transaction_info, TransactionInfo = #{ id := TransactionID, @@ -214,6 +216,11 @@ unmarshal(id, V) -> unmarshal(event_id, V) -> unmarshal(integer, V); +unmarshal(blocking, blocked) -> + blocked; +unmarshal(blocking, unblocked) -> + unblocked; + unmarshal(transaction_info, #'TransactionInfo'{ id = TransactionID, timestamp = Timestamp, diff --git a/apps/ff_server/src/ff_destination_codec.erl b/apps/ff_server/src/ff_destination_codec.erl index 91bdab2..78ef34b 100644 --- a/apps/ff_server/src/ff_destination_codec.erl +++ b/apps/ff_server/src/ff_destination_codec.erl @@ -19,6 +19,7 @@ unmarshal_destination_params(Params) -> genlib_map:compact(#{ + id => unmarshal(id, Params#dst_DestinationParams.id), identity => unmarshal(id, Params#dst_DestinationParams.identity), name => unmarshal(string, Params#dst_DestinationParams.name), currency => unmarshal(string, Params#dst_DestinationParams.currency), diff --git a/apps/ff_server/src/ff_destination_handler.erl b/apps/ff_server/src/ff_destination_handler.erl index 7a8e77c..adb676e 100644 --- a/apps/ff_server/src/ff_destination_handler.erl +++ b/apps/ff_server/src/ff_destination_handler.erl @@ -24,7 +24,7 @@ handle_function(Func, Args, Opts) -> handle_function_('Create', [Params], Opts) -> ID = Params#dst_DestinationParams.id, Ctx = Params#dst_DestinationParams.context, - case ff_destination:create(ID, + case ff_destination:create( ff_destination_codec:unmarshal_destination_params(Params), ff_destination_codec:unmarshal(ctx, Ctx)) of diff --git a/apps/ff_server/src/ff_identity_codec.erl b/apps/ff_server/src/ff_identity_codec.erl index 48a3df2..67e87a7 100644 --- a/apps/ff_server/src/ff_identity_codec.erl +++ b/apps/ff_server/src/ff_identity_codec.erl @@ -24,12 +24,14 @@ ff_identity_machine:params(). unmarshal_identity_params(#idnt_IdentityParams{ + id = ID, party = PartyID, provider = ProviderID, cls = ClassID, external_id = ExternalID }) -> genlib_map:compact(#{ + id => unmarshal(id, ID), party => unmarshal(id, PartyID), provider => unmarshal(id, ProviderID), class => unmarshal(id, ClassID), @@ -105,7 +107,8 @@ marshal_identity(Identity) -> cls = marshal(id, ff_identity:class(Identity)), contract = maybe_marshal(id, ff_identity:contract(Identity)), level = maybe_marshal(id, ff_identity:level(Identity)), - blocked = maybe_marshal(bool, ff_identity:blocked(Identity)), + blocking = maybe_marshal(blocking, ff_identity:blocking(Identity)), + created_at = maybe_marshal(created_at, ff_identity:created_at(Identity)), external_id = maybe_marshal(id, ff_identity:external_id(Identity)), effective_challenge = EffectiveChallengeID }. @@ -119,20 +122,22 @@ unmarshal_identity(#idnt_Identity{ cls = ClassID, contract = ContractID, level = LevelID, - blocked = Blocked, + blocking = Blocking, external_id = ExternalID, + created_at = CreatedAt, effective_challenge = EffectiveChallengeID }) -> genlib_map:compact(#{ - id => unmarshal(id, ID), - party => unmarshal(id, PartyID), - provider => unmarshal(id, ProviderID), - class => unmarshal(id, ClassID), - contract => unmarshal(id, ContractID), - level => maybe_unmarshal(id, LevelID), - blocked => maybe_unmarshal(bool, Blocked), - external_id => maybe_unmarshal(id, ExternalID), - effective => maybe_unmarshal(id, EffectiveChallengeID) + id => unmarshal(id, ID), + party => unmarshal(id, PartyID), + provider => unmarshal(id, ProviderID), + class => unmarshal(id, ClassID), + contract => unmarshal(id, ContractID), + level => maybe_unmarshal(id, LevelID), + blocking => maybe_unmarshal(blocking, Blocking), + external_id => maybe_unmarshal(id, ExternalID), + created_at => maybe_unmarshal(created_at, CreatedAt), + effective => maybe_unmarshal(id, EffectiveChallengeID) }). -spec marshal(ff_codec:type_name(), ff_codec:decoded_value()) -> ff_codec:encoded_value(). @@ -203,6 +208,9 @@ marshal(resolution, denied) -> marshal(ctx, Ctx) -> maybe_marshal(context, Ctx); +marshal(created_at, TimeMS) -> + marshal(string, ff_time:to_rfc3339(TimeMS)); + marshal(T, V) -> ff_codec:marshal(T, V). @@ -276,6 +284,9 @@ unmarshal(effective_challenge, undefined) -> unmarshal(effective_challenge, EffectiveChallengeID) -> {ok, unmarshal(id, EffectiveChallengeID)}; +unmarshal(created_at, Timestamp) -> + unmarshal(integer, ff_time:from_rfc3339(Timestamp)); + unmarshal(ctx, Ctx) -> maybe_unmarshal(context, Ctx); @@ -303,7 +314,7 @@ maybe_unmarshal(Type, Value) -> -spec identity_test() -> _. identity_test() -> - Blocked = true, + Blocking = blocked, IdentityIn = #{ id => genlib:unique(), party => genlib:unique(), @@ -311,7 +322,7 @@ identity_test() -> class => genlib:unique(), contract => genlib:unique(), level => genlib:unique(), - blocked => Blocked, + blocking => Blocking, external_id => genlib:unique(), effective => genlib:unique() }, diff --git a/apps/ff_server/src/ff_identity_handler.erl b/apps/ff_server/src/ff_identity_handler.erl index 589d0e2..a0aaa77 100644 --- a/apps/ff_server/src/ff_identity_handler.erl +++ b/apps/ff_server/src/ff_identity_handler.erl @@ -23,10 +23,10 @@ handle_function(Func, Args, Opts) -> %% Internals %% -handle_function_('Create', [IdentityID, IdentityParams], Opts) -> - Params = ff_identity_codec:unmarshal_identity_params(IdentityParams), +handle_function_('Create', [IdentityParams], Opts) -> + Params = #{id := IdentityID} = ff_identity_codec:unmarshal_identity_params(IdentityParams), Context = ff_identity_codec:unmarshal(ctx, IdentityParams#idnt_IdentityParams.context), - case ff_identity_machine:create(IdentityID, Params, Context) of + case ff_identity_machine:create(Params, Context) of ok -> handle_function_('Get', [IdentityID], Opts); {error, {provider, notfound}} -> @@ -41,7 +41,7 @@ handle_function_('Create', [IdentityID, IdentityParams], Opts) -> handle_function_('Get', [ID], _Opts) -> case ff_identity_machine:get(ID) of {ok, Machine} -> - Identity = ff_identity:set_blocked(ff_identity_machine:identity(Machine)), + Identity = ff_identity:set_blocking(ff_identity_machine:identity(Machine)), Ctx = ff_identity_codec:marshal(ctx, ff_identity_machine:ctx(Machine)), Response = ff_identity_codec:marshal_identity(Identity), {ok, Response#idnt_Identity{context = Ctx}}; diff --git a/apps/ff_server/src/ff_server_admin_handler.erl b/apps/ff_server/src/ff_server_admin_handler.erl index 717df7e..c688712 100644 --- a/apps/ff_server/src/ff_server_admin_handler.erl +++ b/apps/ff_server/src/ff_server_admin_handler.erl @@ -25,7 +25,8 @@ handle_function(Func, Args, Opts) -> handle_function_('CreateSource', [Params], Opts) -> SourceID = Params#ff_admin_SourceParams.id, - case ff_source:create(SourceID, #{ + case ff_source:create(#{ + id => SourceID, identity => Params#ff_admin_SourceParams.identity_id, name => Params#ff_admin_SourceParams.name, currency => ff_codec:unmarshal(currency_ref, Params#ff_admin_SourceParams.currency), diff --git a/apps/ff_server/src/ff_wallet_handler.erl b/apps/ff_server/src/ff_wallet_handler.erl index a12ee5e..a7c1792 100644 --- a/apps/ff_server/src/ff_wallet_handler.erl +++ b/apps/ff_server/src/ff_wallet_handler.erl @@ -23,7 +23,7 @@ handle_function(Func, Args, Opts) -> %% handle_function_('Create', [Params], Opts) -> WalletID = Params#wlt_WalletParams.id, - case ff_wallet_machine:create(WalletID, + case ff_wallet_machine:create( decode(wallet_params, Params), decode(context, Params#wlt_WalletParams.context)) of @@ -73,6 +73,7 @@ encode(currency, CurrencyId) -> decode(wallet_params, Params) -> AccountParams = Params#wlt_WalletParams.account_params, #{ + id => Params#wlt_WalletParams.id, name => Params#wlt_WalletParams.name, identity => AccountParams#account_AccountParams.identity_id, currency => AccountParams#account_AccountParams.symbolic_code, diff --git a/apps/ff_server/test/ff_destination_handler_SUITE.erl b/apps/ff_server/test/ff_destination_handler_SUITE.erl index 506c3cc..215ba34 100644 --- a/apps/ff_server/test/ff_destination_handler_SUITE.erl +++ b/apps/ff_server/test/ff_destination_handler_SUITE.erl @@ -169,8 +169,7 @@ create_person_identity(Party, C) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. diff --git a/apps/ff_server/test/ff_eventsink_SUITE.erl b/apps/ff_server/test/ff_eventsink_SUITE.erl index 99a32b0..66c5a18 100644 --- a/apps/ff_server/test/ff_eventsink_SUITE.erl +++ b/apps/ff_server/test/ff_eventsink_SUITE.erl @@ -96,8 +96,8 @@ get_identity_events_ok(C) -> LastEvent = ct_eventsink:last_id(Sink), ok = ff_identity_machine:create( - ID, #{ + id => ID, party => Party, provider => <<"good-one">>, class => <<"person">> @@ -138,8 +138,8 @@ get_create_wallet_events_ok(C) -> LastEvent = ct_eventsink:last_id(Sink), ok = ff_wallet_machine:create( - ID, #{ + id => ID, identity => IdentityID, name => <<"EVENTS TEST">>, currency => <<"RUB">> @@ -337,8 +337,7 @@ create_person_identity(Party, C) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. @@ -346,8 +345,7 @@ create_identity(Party, ProviderID, ClassID, _C) -> create_wallet(IdentityID, Name, Currency, _C) -> ID = genlib:unique(), ok = ff_wallet_machine:create( - ID, - #{identity => IdentityID, name => Name, currency => Currency}, + #{id => ID, identity => IdentityID, name => Name, currency => Currency}, ff_entity_context:new() ), ID. @@ -356,17 +354,16 @@ create_instrument(Type, IdentityID, Name, Currency, Resource, C) -> ID = genlib:unique(), ok = create_instrument( Type, - ID, - #{identity => IdentityID, name => Name, currency => Currency, resource => Resource}, + #{id => ID, identity => IdentityID, name => Name, currency => Currency, resource => Resource}, ff_entity_context:new(), C ), ID. -create_instrument(destination, ID, Params, Ctx, _C) -> - ff_destination:create(ID, Params, Ctx); -create_instrument(source, ID, Params, Ctx, _C) -> - ff_source:create(ID, Params, Ctx). +create_instrument(destination, Params, Ctx, _C) -> + ff_destination:create(Params, Ctx); +create_instrument(source, Params, Ctx, _C) -> + ff_source:create(Params, Ctx). generate_id() -> genlib:to_binary(genlib_time:ticks()). diff --git a/apps/ff_server/test/ff_identity_handler_SUITE.erl b/apps/ff_server/test/ff_identity_handler_SUITE.erl index 6f44f20..262f2f4 100644 --- a/apps/ff_server/test/ff_identity_handler_SUITE.erl +++ b/apps/ff_server/test/ff_identity_handler_SUITE.erl @@ -83,12 +83,12 @@ create_identity_ok(_C) -> IID = Identity#idnt_Identity.id, {ok, Identity_} = call_api('Get', [IID]), - ProvID = Identity_#idnt_Identity.provider, - IID = Identity_#idnt_Identity.id, + ProvID = Identity_#idnt_Identity.provider, + IID = Identity_#idnt_Identity.id, PartyID = Identity_#idnt_Identity.party, ClassID = Identity_#idnt_Identity.cls, - false = Identity_#idnt_Identity.blocked, - Ctx = ff_entity_context_codec:unmarshal(Identity_#idnt_Identity.context), + blocked = Identity_#idnt_Identity.blocking, + Ctx = ff_entity_context_codec:unmarshal(Identity_#idnt_Identity.context), ok. run_challenge_ok(C) -> @@ -212,15 +212,15 @@ get_challenges_ok(C) -> %% INTERNAL %%---------- create_identity(EID, PartyID, ProvID, ClassID, Ctx) -> - IID = genlib:unique(), Params = #idnt_IdentityParams{ + id = genlib:unique(), party = PartyID, provider = ProvID, cls = ClassID, external_id = EID, context = Ctx }, - {ok, IdentityState} = call_api('Create', [IID, Params]), + {ok, IdentityState} = call_api('Create', [Params]), IdentityState. gen_challenge_param(ClgClassID, ChallengeID, C) -> diff --git a/apps/ff_server/test/ff_wallet_handler_SUITE.erl b/apps/ff_server/test/ff_wallet_handler_SUITE.erl index ed98d58..f6e40d4 100644 --- a/apps/ff_server/test/ff_wallet_handler_SUITE.erl +++ b/apps/ff_server/test/ff_wallet_handler_SUITE.erl @@ -169,8 +169,7 @@ create_person_identity(Party, C) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. diff --git a/apps/ff_server/test/ff_withdrawal_handler_SUITE.erl b/apps/ff_server/test/ff_withdrawal_handler_SUITE.erl index 065bf35..24ca19b 100644 --- a/apps/ff_server/test/ff_withdrawal_handler_SUITE.erl +++ b/apps/ff_server/test/ff_withdrawal_handler_SUITE.erl @@ -306,8 +306,8 @@ create_identity() -> IdentityID = genlib:unique(), Party = create_party(), ok = ff_identity_machine:create( - IdentityID, #{ + id => IdentityID, party => Party, provider => <<"good-one">>, class => <<"person">> diff --git a/apps/ff_server/test/ff_withdrawal_session_repair_SUITE.erl b/apps/ff_server/test/ff_withdrawal_session_repair_SUITE.erl index 32675e8..ee8736e 100644 --- a/apps/ff_server/test/ff_withdrawal_session_repair_SUITE.erl +++ b/apps/ff_server/test/ff_withdrawal_session_repair_SUITE.erl @@ -133,8 +133,7 @@ create_identity(Party, C) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. @@ -155,17 +154,16 @@ create_instrument(Type, IdentityID, Name, Currency, Resource, C) -> ID = genlib:unique(), ok = create_instrument( Type, - ID, - #{identity => IdentityID, name => Name, currency => Currency, resource => Resource}, + #{id => ID, identity => IdentityID, name => Name, currency => Currency, resource => Resource}, ff_entity_context:new(), C ), ID. -create_instrument(destination, ID, Params, Ctx, _C) -> - ff_destination:create(ID, Params, Ctx); -create_instrument(source, ID, Params, Ctx, _C) -> - ff_source:create(ID, Params, Ctx). +create_instrument(destination, Params, Ctx, _C) -> + ff_destination:create(Params, Ctx); +create_instrument(source, Params, Ctx, _C) -> + ff_source:create(Params, Ctx). create_failed_session(IdentityID, DestinationID, _C) -> ID = genlib:unique(), diff --git a/apps/ff_transfer/src/ff_destination.erl b/apps/ff_transfer/src/ff_destination.erl index 5a2c411..bd68357 100644 --- a/apps/ff_transfer/src/ff_destination.erl +++ b/apps/ff_transfer/src/ff_destination.erl @@ -100,7 +100,7 @@ %% API --export([create/3]). +-export([create/2]). -export([get_machine/1]). -export([get/1]). -export([ctx/1]). @@ -181,15 +181,15 @@ unwrap_resource_id(#{<<"bank_card">> := ID}) -> -define(NS, 'ff/destination_v2'). --spec create(id(), params(), ctx()) -> +-spec create(params(), ctx()) -> ok | {error, _InstrumentCreateError | exists }. -create(ID, Params, Ctx) -> - ff_instrument_machine:create(?NS, ID, Params, Ctx). +create(Params, Ctx) -> + ff_instrument_machine:create(?NS, Params, Ctx). -spec get_machine(id()) -> {ok, machine()} | diff --git a/apps/ff_transfer/src/ff_instrument_machine.erl b/apps/ff_transfer/src/ff_instrument_machine.erl index 5f98e3a..55b8db9 100644 --- a/apps/ff_transfer/src/ff_instrument_machine.erl +++ b/apps/ff_transfer/src/ff_instrument_machine.erl @@ -19,7 +19,7 @@ -export_type([events/1]). -export_type([params/1]). --export([create/4]). +-export([create/3]). -export([get/2]). -export([events/3]). @@ -43,6 +43,7 @@ %% -type params(T) :: #{ + id := id(), identity := ff_identity:id(), name := binary(), currency := ff_currency:id(), @@ -50,14 +51,20 @@ external_id => id() }. --spec create(ns(), id(), params(_), ctx()) -> +-spec create(ns(), params(_), ctx()) -> ok | {error, _InstrumentCreateError | exists }. -create(NS, ID, Params = #{identity := IdentityID, name := Name, currency := CurrencyID, resource := Resource}, Ctx) -> +create(NS, Params = #{ + id := ID, + identity := IdentityID, + name := Name, + currency := CurrencyID, + resource := Resource +}, Ctx) -> do(fun () -> Events = unwrap(ff_instrument:create( ID, diff --git a/apps/ff_transfer/src/ff_source.erl b/apps/ff_transfer/src/ff_source.erl index 47d589b..8bc8641 100644 --- a/apps/ff_transfer/src/ff_source.erl +++ b/apps/ff_transfer/src/ff_source.erl @@ -46,7 +46,7 @@ %% API --export([create/3]). +-export([create/2]). -export([get_machine/1]). -export([get/1]). -export([is_accessible/1]). @@ -78,15 +78,15 @@ external_id(T) -> ff_instrument:external_id(T). -define(NS, 'ff/source_v1'). --spec create(id(), params(), ctx()) -> +-spec create(params(), ctx()) -> ok | {error, _InstrumentCreateError | exists }. -create(ID, Params, Ctx) -> - ff_instrument_machine:create(?NS, ID, Params, Ctx). +create(Params, Ctx) -> + ff_instrument_machine:create(?NS, Params, Ctx). -spec get_machine(id()) -> {ok, machine()} | diff --git a/apps/ff_transfer/test/ff_deposit_SUITE.erl b/apps/ff_transfer/test/ff_deposit_SUITE.erl index d826875..5540a6b 100644 --- a/apps/ff_transfer/test/ff_deposit_SUITE.erl +++ b/apps/ff_transfer/test/ff_deposit_SUITE.erl @@ -292,8 +292,7 @@ create_person_identity(Party, C, ProviderID) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. @@ -301,8 +300,7 @@ create_identity(Party, ProviderID, ClassID, _C) -> create_wallet(IdentityID, Name, Currency, _C) -> ID = genlib:unique(), ok = ff_wallet_machine:create( - ID, - #{identity => IdentityID, name => Name, currency => Currency}, + #{id => ID, identity => IdentityID, name => Name, currency => Currency}, ff_entity_context:new() ), ID. @@ -339,8 +337,8 @@ generate_id() -> create_source(IID, _C) -> ID = generate_id(), SrcResource = #{type => internal, details => <<"Infinite source of cash">>}, - Params = #{identity => IID, name => <<"XSource">>, currency => <<"RUB">>, resource => SrcResource}, - ok = ff_source:create(ID, Params, ff_entity_context:new()), + Params = #{id => ID, identity => IID, name => <<"XSource">>, currency => <<"RUB">>, resource => SrcResource}, + ok = ff_source:create(Params, ff_entity_context:new()), authorized = ct_helper:await( authorized, fun () -> diff --git a/apps/ff_transfer/test/ff_deposit_adjustment_SUITE.erl b/apps/ff_transfer/test/ff_deposit_adjustment_SUITE.erl index faaba1e..e7ee282 100644 --- a/apps/ff_transfer/test/ff_deposit_adjustment_SUITE.erl +++ b/apps/ff_transfer/test/ff_deposit_adjustment_SUITE.erl @@ -388,8 +388,7 @@ create_person_identity(Party, C, ProviderID) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. @@ -397,8 +396,7 @@ create_identity(Party, ProviderID, ClassID, _C) -> create_wallet(IdentityID, Name, Currency, _C) -> ID = genlib:unique(), ok = ff_wallet_machine:create( - ID, - #{identity => IdentityID, name => Name, currency => Currency}, + #{id => ID, identity => IdentityID, name => Name, currency => Currency}, ff_entity_context:new() ), ID. @@ -441,8 +439,8 @@ generate_id() -> create_source(IID, _C) -> ID = generate_id(), SrcResource = #{type => internal, details => <<"Infinite source of cash">>}, - Params = #{identity => IID, name => <<"XSource">>, currency => <<"RUB">>, resource => SrcResource}, - ok = ff_source:create(ID, Params, ff_entity_context:new()), + Params = #{id => ID, identity => IID, name => <<"XSource">>, currency => <<"RUB">>, resource => SrcResource}, + ok = ff_source:create(Params, ff_entity_context:new()), authorized = ct_helper:await( authorized, fun () -> diff --git a/apps/ff_transfer/test/ff_deposit_revert_SUITE.erl b/apps/ff_transfer/test/ff_deposit_revert_SUITE.erl index 0a64663..a89f92b 100644 --- a/apps/ff_transfer/test/ff_deposit_revert_SUITE.erl +++ b/apps/ff_transfer/test/ff_deposit_revert_SUITE.erl @@ -393,8 +393,7 @@ create_person_identity(Party, C, ProviderID) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. @@ -402,8 +401,7 @@ create_identity(Party, ProviderID, ClassID, _C) -> create_wallet(IdentityID, Name, Currency, _C) -> ID = genlib:unique(), ok = ff_wallet_machine:create( - ID, - #{identity => IdentityID, name => Name, currency => Currency}, + #{id => ID, identity => IdentityID, name => Name, currency => Currency}, ff_entity_context:new() ), ID. @@ -450,8 +448,8 @@ generate_id() -> create_source(IID, _C) -> ID = generate_id(), SrcResource = #{type => internal, details => <<"Infinite source of cash">>}, - Params = #{identity => IID, name => <<"XSource">>, currency => <<"RUB">>, resource => SrcResource}, - ok = ff_source:create(ID, Params, ff_entity_context:new()), + Params = #{id => ID, identity => IID, name => <<"XSource">>, currency => <<"RUB">>, resource => SrcResource}, + ok = ff_source:create(Params, ff_entity_context:new()), authorized = ct_helper:await( authorized, fun () -> diff --git a/apps/ff_transfer/test/ff_deposit_revert_adjustment_SUITE.erl b/apps/ff_transfer/test/ff_deposit_revert_adjustment_SUITE.erl index 4056492..d8df4a2 100644 --- a/apps/ff_transfer/test/ff_deposit_revert_adjustment_SUITE.erl +++ b/apps/ff_transfer/test/ff_deposit_revert_adjustment_SUITE.erl @@ -443,8 +443,7 @@ create_person_identity(Party, C, ProviderID) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. @@ -452,8 +451,7 @@ create_identity(Party, ProviderID, ClassID, _C) -> create_wallet(IdentityID, Name, Currency, _C) -> ID = genlib:unique(), ok = ff_wallet_machine:create( - ID, - #{identity => IdentityID, name => Name, currency => Currency}, + #{id => ID, identity => IdentityID, name => Name, currency => Currency}, ff_entity_context:new() ), ID. @@ -500,8 +498,8 @@ generate_id() -> create_source(IID, _C) -> ID = generate_id(), SrcResource = #{type => internal, details => <<"Infinite source of cash">>}, - Params = #{identity => IID, name => <<"XSource">>, currency => <<"RUB">>, resource => SrcResource}, - ok = ff_source:create(ID, Params, ff_entity_context:new()), + Params = #{id => ID, identity => IID, name => <<"XSource">>, currency => <<"RUB">>, resource => SrcResource}, + ok = ff_source:create(Params, ff_entity_context:new()), authorized = ct_helper:await( authorized, fun () -> diff --git a/apps/ff_transfer/test/ff_transfer_SUITE.erl b/apps/ff_transfer/test/ff_transfer_SUITE.erl index 36824e3..10c676c 100644 --- a/apps/ff_transfer/test/ff_transfer_SUITE.erl +++ b/apps/ff_transfer/test/ff_transfer_SUITE.erl @@ -352,8 +352,7 @@ create_person_identity(Party, C, ProviderID) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. @@ -361,8 +360,7 @@ create_identity(Party, ProviderID, ClassID, _C) -> create_wallet(IdentityID, Name, Currency, _C) -> ID = genlib:unique(), ok = ff_wallet_machine:create( - ID, - #{identity => IdentityID, name => Name, currency => Currency}, + #{id => ID, identity => IdentityID, name => Name, currency => Currency}, ff_entity_context:new() ), ID. @@ -404,17 +402,16 @@ create_instrument(Type, IdentityID, Name, Currency, Resource, C) -> ID = genlib:unique(), ok = create_instrument( Type, - ID, - #{identity => IdentityID, name => Name, currency => Currency, resource => Resource}, + #{id => ID, identity => IdentityID, name => Name, currency => Currency, resource => Resource}, ff_entity_context:new(), C ), ID. -create_instrument(destination, ID, Params, Ctx, _C) -> - ff_destination:create(ID, Params, Ctx); -create_instrument(source, ID, Params, Ctx, _C) -> - ff_source:create(ID, Params, Ctx). +create_instrument(destination, Params, Ctx, _C) -> + ff_destination:create(Params, Ctx); +create_instrument(source, Params, Ctx, _C) -> + ff_source:create(Params, Ctx). generate_id() -> genlib:to_binary(genlib_time:ticks()). diff --git a/apps/ff_transfer/test/ff_withdrawal_SUITE.erl b/apps/ff_transfer/test/ff_withdrawal_SUITE.erl index a7354f7..4039fd0 100644 --- a/apps/ff_transfer/test/ff_withdrawal_SUITE.erl +++ b/apps/ff_transfer/test/ff_withdrawal_SUITE.erl @@ -573,8 +573,7 @@ create_person_identity(Party, C, ProviderID) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. @@ -582,8 +581,7 @@ create_identity(Party, ProviderID, ClassID, _C) -> create_wallet(IdentityID, Name, Currency, _C) -> ID = genlib:unique(), ok = ff_wallet_machine:create( - ID, - #{identity => IdentityID, name => Name, currency => Currency}, + #{id => ID, identity => IdentityID, name => Name, currency => Currency}, ff_entity_context:new() ), ID. @@ -626,8 +624,8 @@ create_destination(IID, Currency, Token, C) -> StoreSource#{token => Token} end, Resource = {bank_card, NewStoreResource}, - Params = #{identity => IID, name => <<"XDesination">>, currency => Currency, resource => Resource}, - ok = ff_destination:create(ID, Params, ff_entity_context:new()), + Params = #{id => ID, identity => IID, name => <<"XDesination">>, currency => Currency, resource => Resource}, + ok = ff_destination:create(Params, ff_entity_context:new()), authorized = ct_helper:await( authorized, fun () -> @@ -643,8 +641,8 @@ create_crypto_destination(IID, _C) -> id => <<"a30e277c07400c9940628828949efd48">>, currency => {litecoin, #{}} }}, - Params = #{identity => IID, name => <<"CryptoDestination">>, currency => <<"RUB">>, resource => Resource}, - ok = ff_destination:create(ID, Params, ff_entity_context:new()), + Params = #{id => ID, identity => IID, name => <<"CryptoDestination">>, currency => <<"RUB">>, resource => Resource}, + ok = ff_destination:create(Params, ff_entity_context:new()), authorized = ct_helper:await( authorized, fun () -> diff --git a/apps/ff_transfer/test/ff_withdrawal_adjustment_SUITE.erl b/apps/ff_transfer/test/ff_withdrawal_adjustment_SUITE.erl index 89fe66e..7975e7f 100644 --- a/apps/ff_transfer/test/ff_withdrawal_adjustment_SUITE.erl +++ b/apps/ff_transfer/test/ff_withdrawal_adjustment_SUITE.erl @@ -390,8 +390,7 @@ create_person_identity(Party, C, ProviderID) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. @@ -399,8 +398,7 @@ create_identity(Party, ProviderID, ClassID, _C) -> create_wallet(IdentityID, Name, Currency, _C) -> ID = genlib:unique(), ok = ff_wallet_machine:create( - ID, - #{identity => IdentityID, name => Name, currency => Currency}, + #{id => ID, identity => IdentityID, name => Name, currency => Currency}, ff_entity_context:new() ), ID. @@ -443,8 +441,8 @@ generate_id() -> create_destination(IID, C) -> ID = generate_id(), Resource = {bank_card, ct_cardstore:bank_card(<<"4150399999000900">>, {12, 2025}, C)}, - Params = #{identity => IID, name => <<"XDesination">>, currency => <<"RUB">>, resource => Resource}, - ok = ff_destination:create(ID, Params, ff_entity_context:new()), + Params = #{id => ID, identity => IID, name => <<"XDesination">>, currency => <<"RUB">>, resource => Resource}, + ok = ff_destination:create(Params, ff_entity_context:new()), authorized = ct_helper:await( authorized, fun () -> diff --git a/apps/fistful/src/ff_identity.erl b/apps/fistful/src/ff_identity.erl index 84f05a2..842d61b 100644 --- a/apps/fistful/src/ff_identity.erl +++ b/apps/fistful/src/ff_identity.erl @@ -24,7 +24,7 @@ -type challenge_class() :: ff_identity_challenge:challenge_class(). -type challenge_class_id() :: ff_identity_class:challenge_class_id(). -type challenge_id() :: id(). --type blocked() :: boolean(). +-type blocking() :: unblocked | blocked. -type level() :: ff_identity_class:level(). -type level_id() :: ff_identity_class:level_id(). @@ -38,7 +38,8 @@ challenges => #{challenge_id() => challenge()}, effective => challenge_id(), external_id => id(), - blocked => blocked() + blocking => blocking(), + created_at => ff_time:timestamp_ms() }. -type challenge() :: @@ -81,10 +82,11 @@ -export([challenge/2]). -export([effective_challenge/1]). -export([external_id/1]). --export([blocked/1]). +-export([blocking/1]). +-export([created_at/1]). -export([is_accessible/1]). --export([set_blocked/1]). +-export([set_blocking/1]). -export([create/5]). @@ -109,7 +111,7 @@ party_id(). -spec contract(identity()) -> contract_id(). --spec blocked(identity()) -> +-spec blocking(identity()) -> boolean() | undefined. -spec level(identity()) -> level_id() | undefined. @@ -121,6 +123,8 @@ ff_map:result(challenge()). -spec external_id(identity()) -> external_id(). +-spec created_at(identity()) -> + ff_time:timestamp_ms() | undefined. id(#{id := V}) -> V. @@ -137,8 +141,8 @@ party(#{party := V}) -> contract(#{contract := V}) -> V. -blocked(Identity) -> - maps:get(blocked, Identity, undefined). +blocking(Identity) -> + maps:get(blocking, Identity, undefined). level(Identity) -> maps:get(level, Identity, undefined). @@ -155,6 +159,9 @@ challenge(ChallengeID, Identity) -> external_id(Identity) -> maps:get(external_id, Identity, undefined). +created_at(Identity) -> + maps:get(created_at, Identity, undefined). + -spec is_accessible(identity()) -> {ok, accessible} | {error, ff_party:inaccessibility()}. @@ -163,12 +170,16 @@ is_accessible(Identity) -> ff_party:is_accessible(party(Identity)). --spec set_blocked(identity()) -> identity(). - -set_blocked(Identity) -> - Blocked = {ok, accessible} =/= is_accessible(Identity), - maps:put(blocked, Blocked, Identity). +-spec set_blocking(identity()) -> identity(). +set_blocking(Identity) -> + Blocking = case {ok, accessible} =/= is_accessible(Identity) of + true -> + unblocked; + false -> + blocked + end, + maps:put(blocking, Blocking, Identity). %% Constructor @@ -193,7 +204,9 @@ create(ID, Party, ProviderID, ClassID, ExternalID) -> party => Party, provider => ProviderID, class => ClassID, - contract => Contract + contract => Contract, + %% TODO need migration for events + created_at => ff_time:now() })}, {level_changed, LevelID diff --git a/apps/fistful/src/ff_identity_machine.erl b/apps/fistful/src/ff_identity_machine.erl index b00fed1..a9adf22 100644 --- a/apps/fistful/src/ff_identity_machine.erl +++ b/apps/fistful/src/ff_identity_machine.erl @@ -35,7 +35,7 @@ -export_type([challenge_params/0]). -export_type([params/0]). --export([create/3]). +-export([create/2]). -export([get/1]). -export([events/2]). @@ -61,20 +61,21 @@ -define(NS, 'ff/identity'). -type params() :: #{ + id := id(), party := ff_party:id(), provider := ff_provider:id(), class := ff_identity:class_id(), external_id => id() }. --spec create(id(), params(), ctx()) -> +-spec create(params(), ctx()) -> ok | {error, ff_identity:create_error() | exists }. -create(ID, Params = #{party := Party, provider := ProviderID, class := IdentityClassID}, Ctx) -> +create(Params = #{id := ID, party := Party, provider := ProviderID, class := IdentityClassID}, Ctx) -> do(fun () -> Events = unwrap(ff_identity:create( ID, diff --git a/apps/fistful/src/ff_wallet_machine.erl b/apps/fistful/src/ff_wallet_machine.erl index d4c014f..93cd43e 100644 --- a/apps/fistful/src/ff_wallet_machine.erl +++ b/apps/fistful/src/ff_wallet_machine.erl @@ -17,7 +17,7 @@ -export_type([id/0]). --export([create/3]). +-export([create/2]). -export([get/1]). -export([events/2]). @@ -56,16 +56,17 @@ ctx(St) -> %% -type params() :: #{ + id := id(), identity := ff_identity_machine:id(), name := binary(), currency := ff_currency:id(), external_id => id() }. --spec create(id(), params(), ctx()) -> +-spec create(params(), ctx()) -> ok | {error, exists | ff_wallet:create_error() }. -create(ID, Params = #{identity := IdentityID, name := Name, currency := CurrencyID}, Ctx) -> +create(Params = #{id := ID, identity := IdentityID, name := Name, currency := CurrencyID}, Ctx) -> do(fun () -> Events = unwrap(ff_wallet:create( ID, diff --git a/apps/fistful/test/ff_identity_SUITE.erl b/apps/fistful/test/ff_identity_SUITE.erl index f94f508..debbde3 100644 --- a/apps/fistful/test/ff_identity_SUITE.erl +++ b/apps/fistful/test/ff_identity_SUITE.erl @@ -72,8 +72,8 @@ get_missing_fails(_C) -> create_missing_fails(_C) -> ID = genlib:unique(), {error, {provider, notfound}} = ff_identity_machine:create( - ID, #{ + id => ID, party => <<"party">>, provider => <<"who">>, class => <<"person">> @@ -81,8 +81,8 @@ create_missing_fails(_C) -> ff_entity_context:new() ), {error, {identity_class, notfound}} = ff_identity_machine:create( - ID, #{ + id => ID, party => <<"party">>, provider => <<"good-one">>, class => <<"nosrep">> @@ -94,8 +94,8 @@ create_ok(C) -> ID = genlib:unique(), Party = create_party(C), ok = ff_identity_machine:create( - ID, #{ + id => ID, party => Party, provider => <<"good-one">>, class => <<"person">> @@ -111,8 +111,8 @@ identify_ok(C) -> ID = genlib:unique(), Party = create_party(C), ok = ff_identity_machine:create( - ID, #{ + id => ID, party => Party, provider => <<"good-one">>, class => <<"person">> diff --git a/apps/fistful/test/ff_wallet_SUITE.erl b/apps/fistful/test/ff_wallet_SUITE.erl index 3404809..5ef2379 100644 --- a/apps/fistful/test/ff_wallet_SUITE.erl +++ b/apps/fistful/test/ff_wallet_SUITE.erl @@ -88,7 +88,7 @@ create_ok(C) -> Party = create_party(C), IdentityID = create_identity(Party, C), WalletParams = construct_wallet_params(IdentityID), - CreateResult = ff_wallet_machine:create(ID, WalletParams, ff_entity_context:new()), + CreateResult = ff_wallet_machine:create(WalletParams#{id => ID}, ff_entity_context:new()), Wallet = ff_wallet_machine:wallet(unwrap(ff_wallet_machine:get(ID))), Accessibility = unwrap(ff_wallet:is_accessible(Wallet)), Account = ff_wallet:account(Wallet), @@ -103,15 +103,15 @@ create_error_id_exists(C) -> Party = create_party(C), IdentityID = create_identity(Party, C), WalletParams = construct_wallet_params(IdentityID), - CreateResult0 = ff_wallet_machine:create(ID, WalletParams, ff_entity_context:new()), - CreateResult1 = ff_wallet_machine:create(ID, WalletParams, ff_entity_context:new()), + CreateResult0 = ff_wallet_machine:create(WalletParams#{id => ID}, ff_entity_context:new()), + CreateResult1 = ff_wallet_machine:create(WalletParams#{id => ID}, ff_entity_context:new()), ?assertMatch(ok, CreateResult0), ?assertMatch({error, exists}, CreateResult1). create_error_identity_not_found(_C) -> ID = genlib:unique(), WalletParams = construct_wallet_params(genlib:unique()), - CreateResult = ff_wallet_machine:create(ID, WalletParams, ff_entity_context:new()), + CreateResult = ff_wallet_machine:create(WalletParams#{id => ID}, ff_entity_context:new()), ?assertMatch({error, {identity, notfound}}, CreateResult). create_error_currency_not_found(C) -> @@ -119,7 +119,7 @@ create_error_currency_not_found(C) -> Party = create_party(C), IdentityID = create_identity(Party, C), WalletParams = construct_wallet_params(IdentityID, <<"EOS">>), - CreateResult = ff_wallet_machine:create(ID, WalletParams, ff_entity_context:new()), + CreateResult = ff_wallet_machine:create(WalletParams#{id => ID}, ff_entity_context:new()), ?assertMatch({error, {currency, notfound}}, CreateResult). create_error_party_blocked(C) -> @@ -128,7 +128,7 @@ create_error_party_blocked(C) -> IdentityID = create_identity(Party, C), ok = block_party(Party, C), WalletParams = construct_wallet_params(IdentityID), - CreateResult = ff_wallet_machine:create(ID, WalletParams, ff_entity_context:new()), + CreateResult = ff_wallet_machine:create(WalletParams#{id => ID}, ff_entity_context:new()), ?assertMatch({error, {party, {inaccessible, blocked}}}, CreateResult). create_error_party_suspended(C) -> @@ -137,7 +137,7 @@ create_error_party_suspended(C) -> IdentityID = create_identity(Party, C), ok = suspend_party(Party, C), WalletParams = construct_wallet_params(IdentityID), - CreateResult = ff_wallet_machine:create(ID, WalletParams, ff_entity_context:new()), + CreateResult = ff_wallet_machine:create(WalletParams#{id => ID}, ff_entity_context:new()), ?assertMatch({error, {party, {inaccessible, suspended}}}, CreateResult). create_error_terms_not_allowed_currency(C) -> @@ -145,7 +145,7 @@ create_error_terms_not_allowed_currency(C) -> Party = create_party(C), IdentityID = create_identity(Party, C), WalletParams = construct_wallet_params(IdentityID, <<"EUR">>), - CreateResult = ff_wallet_machine:create(ID, WalletParams, ff_entity_context:new()), + CreateResult = ff_wallet_machine:create(WalletParams#{id => ID}, ff_entity_context:new()), ExpectedError = {terms, {terms_violation, {not_allowed_currency, {<<"EUR">>, [ #domain_CurrencyRef{symbolic_code = <<"RUB">>}, #domain_CurrencyRef{symbolic_code = <<"USD">>} @@ -167,8 +167,8 @@ create_identity(Party, C) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, #{ + id => ID, party => Party, provider => ProviderID, class => ClassID diff --git a/apps/p2p/test/p2p_quote_SUITE.erl b/apps/p2p/test/p2p_quote_SUITE.erl index 54373d9..73f79d1 100644 --- a/apps/p2p/test/p2p_quote_SUITE.erl +++ b/apps/p2p/test/p2p_quote_SUITE.erl @@ -123,8 +123,7 @@ create_person_identity(Party, C, ProviderID) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. diff --git a/apps/p2p/test/p2p_tests_utils.erl b/apps/p2p/test/p2p_tests_utils.erl index ed72d40..3694d28 100644 --- a/apps/p2p/test/p2p_tests_utils.erl +++ b/apps/p2p/test/p2p_tests_utils.erl @@ -71,8 +71,7 @@ create_person_identity(Party, C, ProviderID) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. diff --git a/apps/p2p/test/p2p_transfer_adjustment_SUITE.erl b/apps/p2p/test/p2p_transfer_adjustment_SUITE.erl index bc8b3cc..089d8c0 100644 --- a/apps/p2p/test/p2p_transfer_adjustment_SUITE.erl +++ b/apps/p2p/test/p2p_transfer_adjustment_SUITE.erl @@ -377,8 +377,7 @@ create_person_identity(Party, C, ProviderID) -> create_identity(Party, ProviderID, ClassID, _C) -> ID = genlib:unique(), ok = ff_identity_machine:create( - ID, - #{party => Party, provider => ProviderID, class => ClassID}, + #{id => ID, party => Party, provider => ProviderID, class => ClassID}, ff_entity_context:new() ), ID. diff --git a/apps/wapi/src/wapi_wallet_ff_backend.erl b/apps/wapi/src/wapi_wallet_ff_backend.erl index bff2b18..9488e11 100644 --- a/apps/wapi/src/wapi_wallet_ff_backend.erl +++ b/apps/wapi/src/wapi_wallet_ff_backend.erl @@ -146,10 +146,10 @@ get_identity(IdentityId, Context) -> {external_id_conflict, id(), external_id()} ). create_identity(Params, Context) -> + IdentityParams = from_swag(identity_params, Params), CreateIdentity = fun(ID, EntityCtx) -> ff_identity_machine:create( - ID, - maps:merge(from_swag(identity_params, Params), #{party => wapi_handler_utils:get_owner(Context)}), + maps:merge(IdentityParams#{id => ID}, #{party => wapi_handler_utils:get_owner(Context)}), add_meta_to_ctx([<<"name">>], Params, EntityCtx) ) end, @@ -278,11 +278,11 @@ get_wallet_by_external_id(ExternalID, #{woody_context := WoodyContext} = Context ff_wallet:create_error() ). create_wallet(Params = #{<<"identity">> := IdenityId}, Context) -> + WalletParams = from_swag(wallet_params, Params), CreateFun = fun(ID, EntityCtx) -> _ = check_resource(identity, IdenityId, Context), ff_wallet_machine:create( - ID, - from_swag(wallet_params, Params), + WalletParams#{id => ID}, add_meta_to_ctx([], Params, EntityCtx) ) end, @@ -355,8 +355,7 @@ create_destination(Params = #{<<"identity">> := IdenityId}, Context) -> DestinationParams = from_swag(destination_params, Params), Resource = unwrap(construct_resource(maps:get(resource, DestinationParams))), ff_destination:create( - ID, - DestinationParams#{resource => Resource}, + DestinationParams#{id => ID, resource => Resource}, add_meta_to_ctx([], Params, EntityCtx) ) end, diff --git a/rebar.lock b/rebar.lock index df43fd8..cdb397d 100644 --- a/rebar.lock +++ b/rebar.lock @@ -59,7 +59,7 @@ 0}, {<<"fistful_proto">>, {git,"git@github.com:rbkmoney/fistful-proto.git", - {ref,"6f874c11828dfd248dd9c9447db02dd4eee72783"}}, + {ref,"2baaac00772ab167e31bec6ce975bd6e1d586250"}}, 0}, {<<"fistful_reporter_proto">>, {git,"git@github.com:rbkmoney/fistful-reporter-proto.git",