17
17
package io .proximax .sdk .infrastructure ;
18
18
19
19
import static io .proximax .sdk .utils .GsonUtils .stream ;
20
- import static io .proximax .sdk .utils .dto .UInt64Utils .toBigInt ;
21
20
22
- import java .util .HashMap ;
23
21
import java .util .List ;
24
- import java .util .Map ;
25
22
import java .util .Optional ;
26
23
import java .util .stream .Collectors ;
27
24
36
33
import io .proximax .sdk .gen .model .AccountPropertiesInfoDTO ;
37
34
import io .proximax .sdk .gen .model .MultisigAccountGraphInfoDTO ;
38
35
import io .proximax .sdk .gen .model .MultisigAccountInfoDTO ;
39
- import io .proximax .sdk .gen .model .MultisigDTO ;
40
36
import io .proximax .sdk .model .account .AccountInfo ;
41
37
import io .proximax .sdk .model .account .Address ;
42
38
import io .proximax .sdk .model .account .MultisigAccountGraphInfo ;
43
39
import io .proximax .sdk .model .account .MultisigAccountInfo ;
44
40
import io .proximax .sdk .model .account .PublicAccount ;
45
41
import io .proximax .sdk .model .account .props .AccountProperties ;
46
- import io .proximax .sdk .model .blockchain .NetworkType ;
47
- import io .proximax .sdk .model .mosaic .Mosaic ;
48
- import io .proximax .sdk .model .mosaic .MosaicId ;
49
42
import io .proximax .sdk .model .transaction .AggregateTransaction ;
50
43
import io .proximax .sdk .model .transaction .Transaction ;
51
- import io .proximax .sdk .utils .dto .AccountDTOUtils ;
52
44
import io .reactivex .Observable ;
53
- import io .reactivex .functions .Function ;
54
45
55
46
/**
56
47
* Account http repository.
@@ -61,25 +52,15 @@ public class AccountHttp extends Http implements AccountRepository {
61
52
62
53
private static final String ROUTE = "/account/" ;
63
54
private static final String PROPERTIES_SUFFIX = "/properties" ;
64
-
55
+
65
56
public AccountHttp (BlockchainApi api ) {
66
57
super (api );
67
58
}
68
59
69
60
@ Override
70
61
public Observable <AccountInfo > getAccountInfo (Address address ) {
71
- return this .client .get (ROUTE + address .plain ())
72
- .map (Http ::mapStringOrError )
73
- .map (str -> objectMapper .readValue (str , AccountInfoDTO .class ))
74
- .map (AccountInfoDTO ::getAccount )
75
- .map (accountDTO -> new AccountInfo (
76
- Address .createFromRawAddress (AccountDTOUtils .getAddressEncoded (accountDTO )),
77
- toBigInt (accountDTO .getAddressHeight ()), accountDTO .getPublicKey (),
78
- toBigInt (accountDTO .getPublicKeyHeight ()),
79
- accountDTO .getMosaics ().stream ()
80
- .map (mosaicDTO -> new Mosaic (new MosaicId (toBigInt (mosaicDTO .getId ())),
81
- toBigInt (mosaicDTO .getAmount ())))
82
- .collect (Collectors .toList ())));
62
+ return this .client .get (ROUTE + address .plain ()).map (Http ::mapStringOrError )
63
+ .map (str -> objectMapper .readValue (str , AccountInfoDTO .class )).map (AccountInfo ::fromDto );
83
64
}
84
65
85
66
@ Override
@@ -92,58 +73,32 @@ public Observable<List<AccountInfo>> getAccountsInfo(List<Address> addresses) {
92
73
requestBody .add ("addresses" , arr );
93
74
return this .client .post (ROUTE , requestBody ).map (Http ::mapStringOrError )
94
75
.map (str -> objectMapper .<List <AccountInfoDTO >>readValue (str , new TypeReference <List <AccountInfoDTO >>() {
95
- })).flatMapIterable (item -> item ).map (AccountInfoDTO ::getAccount ).map (
96
- accountDTO -> new AccountInfo (
97
- Address .createFromRawAddress (AccountDTOUtils .getAddressEncoded (accountDTO )),
98
- toBigInt (accountDTO .getAddressHeight ()), accountDTO .getPublicKey (),
99
- toBigInt (accountDTO .getPublicKeyHeight ()),
100
- accountDTO .getMosaics ().stream ()
101
- .map (mosaicDTO -> new Mosaic (new MosaicId (toBigInt (mosaicDTO .getId ())),
102
- toBigInt (mosaicDTO .getAmount ())))
103
- .collect (Collectors .toList ())))
104
- .toList ().toObservable ();
76
+ })).flatMapIterable (item -> item ).map (AccountInfo ::fromDto ).toList ().toObservable ();
105
77
}
106
78
107
79
@ Override
108
80
public Observable <MultisigAccountInfo > getMultisigAccountInfo (Address address ) {
109
81
return this .client .get (ROUTE + address .plain () + "/multisig" ).map (Http ::mapStringOrError )
110
82
.map (str -> objectMapper .readValue (str , MultisigAccountInfoDTO .class ))
111
- .map (MultisigAccountInfoDTO :: getMultisig ). map ( transfromMultisigAccountInfoDTO ( api .getNetworkType ()));
83
+ .map (dto -> MultisigAccountInfo . fromDto ( dto , api .getNetworkType ()));
112
84
}
113
85
114
86
@ Override
115
87
public Observable <MultisigAccountGraphInfo > getMultisigAccountGraphInfo (Address address ) {
116
- final NetworkType networkType = api .getNetworkType ();
117
88
return this .client .get (ROUTE + address .plain () + "/multisig/graph" ).map (Http ::mapStringOrError )
118
89
.map (str -> objectMapper .<List <MultisigAccountGraphInfoDTO >>readValue (str ,
119
90
new TypeReference <List <MultisigAccountGraphInfoDTO >>() {
120
91
}))
121
- .map (multisigAccountGraphInfoDTOList -> {
122
- Map <Integer , List <MultisigAccountInfo >> multisigAccountInfoMap = new HashMap <>();
123
- multisigAccountGraphInfoDTOList .forEach (item -> multisigAccountInfoMap .put (item .getLevel (),
124
- item .getMultisigEntries ().stream ().map (MultisigAccountInfoDTO ::getMultisig )
125
- .map (item2 -> new MultisigAccountInfo (new PublicAccount (item2 .getAccount (), networkType ),
126
- item2 .getMinApproval (), item2 .getMinRemoval (),
127
- item2 .getCosignatories ().stream ()
128
- .map (cosigner -> new PublicAccount (cosigner , networkType ))
129
- .collect (Collectors .toList ()),
130
- item2 .getMultisigAccounts ().stream ()
131
- .map (multisigAccount -> new PublicAccount (multisigAccount , networkType ))
132
- .collect (Collectors .toList ())))
133
- .collect (Collectors .toList ())));
134
- return new MultisigAccountGraphInfo (multisigAccountInfoMap );
135
- });
92
+ .map (dto -> MultisigAccountGraphInfo .fromDto (dto , api .getNetworkType ()));
136
93
}
137
94
138
95
@ Override
139
96
public Observable <AccountProperties > getAccountProperties (Address address ) {
140
- return this .client .get (ROUTE + address .plain () + PROPERTIES_SUFFIX )
141
- .map (Http ::mapStringOrError )
97
+ return this .client .get (ROUTE + address .plain () + PROPERTIES_SUFFIX ).map (Http ::mapStringOrError )
142
98
.map (str -> objectMapper .readValue (str , AccountPropertiesInfoDTO .class ))
143
- .map (AccountPropertiesInfoDTO ::getAccountProperties )
144
- .map (AccountProperties ::fromDto );
99
+ .map (AccountPropertiesInfoDTO ::getAccountProperties ).map (AccountProperties ::fromDto );
145
100
}
146
-
101
+
147
102
@ Override
148
103
public Observable <List <AccountProperties >> getAccountProperties (List <Address > addresses ) {
149
104
// prepare JSON array with addresses
@@ -153,16 +108,15 @@ public Observable<List<AccountProperties>> getAccountProperties(List<Address> ad
153
108
JsonObject requestBody = new JsonObject ();
154
109
requestBody .add ("addresses" , arr );
155
110
// post to the API
156
- return this .client .post (ROUTE + PROPERTIES_SUFFIX , requestBody )
157
- .map (Http ::mapStringOrError )
158
- .map (str -> objectMapper .<List <AccountPropertiesInfoDTO >>readValue (str , new TypeReference <List <AccountPropertiesInfoDTO >>() {}))
159
- .flatMapIterable (item -> item )
160
- .map (AccountPropertiesInfoDTO ::getAccountProperties )
161
- .map (AccountProperties ::fromDto )
162
- .toList ().toObservable ();
163
-
111
+ return this .client .post (ROUTE + PROPERTIES_SUFFIX , requestBody ).map (Http ::mapStringOrError )
112
+ .map (str -> objectMapper .<List <AccountPropertiesInfoDTO >>readValue (str ,
113
+ new TypeReference <List <AccountPropertiesInfoDTO >>() {
114
+ }))
115
+ .flatMapIterable (item -> item ).map (AccountPropertiesInfoDTO ::getAccountProperties )
116
+ .map (AccountProperties ::fromDto ).toList ().toObservable ();
117
+
164
118
}
165
-
119
+
166
120
@ Override
167
121
public Observable <List <Transaction >> transactions (PublicAccount publicAccount ) {
168
122
return this .transactions (publicAccount , Optional .empty ());
@@ -249,20 +203,4 @@ private Observable<List<Transaction>> findTransactions(PublicAccount publicAccou
249
203
.collect (Collectors .toList ()))
250
204
.flatMapIterable (item -> item ).map (new TransactionMapping ()).toList ().toObservable ();
251
205
}
252
-
253
- /**
254
- * return function that transforms MultisigDTO to MultisigAccountInfo
255
- *
256
- * @param networkType
257
- * @return
258
- */
259
- private Function <MultisigDTO , MultisigAccountInfo > transfromMultisigAccountInfoDTO (NetworkType networkType ) {
260
- return multisig -> new MultisigAccountInfo (new PublicAccount (multisig .getAccount (), networkType ),
261
- multisig .getMinApproval (), multisig .getMinRemoval (),
262
- multisig .getCosignatories ().stream ().map (cosigner -> new PublicAccount (cosigner , networkType ))
263
- .collect (Collectors .toList ()),
264
- multisig .getMultisigAccounts ().stream ()
265
- .map (multisigAccount -> new PublicAccount (multisigAccount , networkType ))
266
- .collect (Collectors .toList ()));
267
- }
268
206
}
0 commit comments