Skip to content

Commit 47942da

Browse files
authored
Merge pull request #120 from proximax-storage/feature/111-118-renaming
Rename TransactionType/Version to EntityType/Version + code improvements
2 parents 4035778 + b39b0cf commit 47942da

File tree

86 files changed

+549
-448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+549
-448
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# CHANGELOG
22

3+
## 0.5.0 MaxFee calculation and transaction builders
4+
5+
See [milestone](https://github.com/proximax-storage/java-xpx-chain-sdk/milestone/5?closed=1) for fixed issues
6+
* introduced fee calculation strategies
7+
* introduced transaction builders as primary API to create transaction instances
8+
* unified constructors and moved logic to transaction builders
9+
* version field changes (breaks server backward compatibility)
10+
* support for blockchain configuration and upgrade transactions/endpoints
11+
* update of dependency versions
12+
313
## 0.4.0 Dragon release support
414

515
See [milestone](https://github.com/proximax-storage/java-xpx-chain-sdk/milestone/4?closed=1) for fixed issues

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<p align="center"><a href="https://github.com/proximax-storage" target="_blank"><img width="150" src="https://github.com/proximax-storage/java-xpx-chain-sdk/raw/master/docs/images/logo.jpg" alt="ProximaX Sirius Blockchain Java SDK"></a></p>
22

33
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4-
[![star this repo](http://githubbadges.com/star.svg?user=proximax-storage&repo=java-xpx-chain-sdk&style=flat)](https://github.com/proximax-storage/java-xpx-chain-sdk)
5-
[![fork this repo](http://githubbadges.com/fork.svg?user=proximax-storage&repo=java-xpx-chain-sdk&style=flat)](https://github.com/proximax-storage/java-xpx-chain-sdk/fork)
64
[![Coverage Status](https://coveralls.io/repos/github/proximax-storage/java-xpx-chain-sdk/badge.svg?branch=master)](https://coveralls.io/github/proximax-storage/java-xpx-chain-sdk?branch=master)
75
[![Build Status](https://travis-ci.com/proximax-storage/java-xpx-chain-sdk.svg?branch=master)](https://travis-ci.com/proximax-storage/java-xpx-chain-sdk)
86

@@ -14,7 +12,7 @@ The ProximaX Sirius Chain Java SDK is a Java library for interacting with the Si
1412

1513
## Use the library ##
1614

17-
Current version of the library is <b>0.4.0</b>
15+
Current version of the library is <b>0.5.0</b>
1816

1917
This library requires use of Java8. Library is published to [Maven Central](https://search.maven.org/). To include library and its dependencies, add following to your build script:
2018

src/e2e/java/io/proximax/sdk/E2EAccountTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
import io.proximax.sdk.model.mosaic.NetworkCurrencyMosaic;
4747
import io.proximax.sdk.model.namespace.NamespaceId;
4848
import io.proximax.sdk.model.namespace.NamespaceInfo;
49+
import io.proximax.sdk.model.transaction.EntityType;
4950
import io.proximax.sdk.model.transaction.ModifyAccountPropertyTransaction;
5051
import io.proximax.sdk.model.transaction.Transaction;
51-
import io.proximax.sdk.model.transaction.TransactionType;
5252
import io.proximax.sdk.model.transaction.UInt64Id;
5353
import io.proximax.sdk.utils.dto.UInt64Utils;
5454

@@ -126,9 +126,9 @@ void addAllowMosaicProperty() {
126126
void addAllowEntityTypeProperty() {
127127
Account acct = new Account(new KeyPair(), getNetworkType());
128128
signup(acct.getAddress());
129-
TransactionType allowedTransType = TransactionType.ACCOUNT_PROPERTIES_ENTITY_TYPE;
129+
EntityType allowedTransType = EntityType.ACCOUNT_PROPERTIES_ENTITY_TYPE;
130130
logger.info("going to allow {} by {}", allowedTransType, acct.getPublicAccount());
131-
ModifyAccountPropertyTransaction<TransactionType> trans = transact.accountPropEntityType()
131+
ModifyAccountPropertyTransaction<EntityType> trans = transact.accountPropEntityType()
132132
.propertyType(AccountPropertyType.ALLOW_TRANSACTION)
133133
.modifications(Arrays.asList(AccountPropertyModification.add(allowedTransType))).build();
134134
// announce the transaction
@@ -213,15 +213,15 @@ private void testAccountPropertiesOnSimpleAccount(AccountProperties aps, UInt64I
213213
* @param aps account properties
214214
* @param blockedAddress address that is blocked
215215
*/
216-
private void testAccountPropertiesOnSimpleAccount(AccountProperties aps, TransactionType allowedTransactionType) {
216+
private void testAccountPropertiesOnSimpleAccount(AccountProperties aps, EntityType allowedTransactionType) {
217217
boolean gotMatch = false;
218218
for (AccountProperty ap : aps.getProperties()) {
219219
if (ap.getPropertyType().equals(AccountPropertyType.ALLOW_TRANSACTION)) {
220220
for (Object value : ap.getValues()) {
221221
try {
222222
if (value instanceof Long && isValidTransactionTypeCode(((Long) value).intValue())) {
223-
assertEquals(TransactionType.ACCOUNT_PROPERTIES_ENTITY_TYPE,
224-
TransactionType.rawValueOf(((Long) value).intValue()));
223+
assertEquals(EntityType.ACCOUNT_PROPERTIES_ENTITY_TYPE,
224+
EntityType.rawValueOf(((Long) value).intValue()));
225225
gotMatch = true;
226226
}
227227
} catch (RuntimeException e) {
@@ -236,7 +236,7 @@ private void testAccountPropertiesOnSimpleAccount(AccountProperties aps, Transac
236236

237237
private static boolean isValidTransactionTypeCode(int code) {
238238
try {
239-
TransactionType.rawValueOf(code);
239+
EntityType.rawValueOf(code);
240240
return true;
241241
} catch (RuntimeException e) {
242242
return false;
@@ -293,8 +293,12 @@ void transactionsWithPagination() throws ExecutionException, InterruptedExceptio
293293
void incomingTransactions() throws ExecutionException, InterruptedException {
294294
List<Transaction> transactions = accountHttp.incomingTransactions(simpleAccount.getPublicAccount()).toFuture()
295295
.get();
296+
List<Transaction> transactionsByAddr = accountHttp.incomingTransactions(simpleAccount.getPublicAccount().getAddress()).toFuture()
297+
.get();
296298

297299
assertEquals(1, transactions.size());
300+
assertEquals(1, transactionsByAddr.size());
301+
assertEquals(transactions.get(0).getSignature(), transactionsByAddr.get(0).getSignature());
298302
}
299303

300304
@Test

src/e2e/java/io/proximax/sdk/infrastructure/TransactionHttpTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import io.proximax.sdk.TransactionRepository;
3737
import io.proximax.sdk.model.transaction.Transaction;
3838
import io.proximax.sdk.model.transaction.TransactionStatus;
39-
import io.proximax.sdk.model.transaction.TransactionType;
39+
import io.proximax.sdk.model.transaction.EntityType;
4040
import io.reactivex.observers.TestObserver;
4141
import io.reactivex.schedulers.Schedulers;
4242

@@ -59,7 +59,7 @@ public void getTransaction() throws ExecutionException, InterruptedException {
5959
.toFuture()
6060
.get();
6161

62-
assertEquals(TransactionType.TRANSFER.getValue(), transaction.getType().getValue());
62+
assertEquals(EntityType.TRANSFER.getValue(), transaction.getType().getValue());
6363
assertEquals(TRANSACTION_HASH, transaction.getTransactionInfo().get().getHash().get());
6464
}
6565

@@ -70,7 +70,7 @@ public void getTransactions() throws ExecutionException, InterruptedException {
7070
.toFuture()
7171
.get();
7272

73-
assertEquals(TransactionType.TRANSFER.getValue(), transaction.get(0).getType().getValue());
73+
assertEquals(EntityType.TRANSFER.getValue(), transaction.get(0).getType().getValue());
7474
assertEquals(TRANSACTION_HASH, transaction.get(0).getTransactionInfo().get().getHash().get());
7575
}
7676

src/main/java/io/proximax/sdk/AccountRepository.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,26 @@ public interface AccountRepository {
121121
*/
122122
Observable<List<Transaction>> incomingTransactions(PublicAccount publicAccount, QueryParams queryParams);
123123

124+
/**
125+
* Gets an list of transactions for which an account is the recipient of a transaction.
126+
* A transaction is said to be incoming with respect to an account if the account is the recipient of a transaction.
127+
*
128+
* @param address the address
129+
* @return Observable of {@link Transaction} list
130+
*/
131+
Observable<List<Transaction>> incomingTransactions(Address address);
132+
133+
/**
134+
* Gets an list of transactions for which an account is the recipient of a transaction.
135+
* A transaction is said to be incoming with respect to an account if the account is the recipient of a transaction.
136+
* With pagination.
137+
*
138+
* @param address the address
139+
* @param queryParams QueryParams
140+
* @return Observable of {@link Transaction} list
141+
*/
142+
Observable<List<Transaction>> incomingTransactions(Address address, QueryParams queryParams);
143+
124144
/**
125145
* Gets an list of transactions for which an account is the sender a transaction.
126146
* A transaction is said to be outgoing with respect to an account if the account is the sender of a transaction.

src/main/java/io/proximax/sdk/BlockchainApi.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ private NetworkType queryForNetworkType() {
227227
public TransactionBuilderFactory transact() {
228228
TransactionBuilderFactory fac = new TransactionBuilderFactory();
229229
fac.setNetworkType(getNetworkType());
230+
fac.setFeeCalculationStrategy(DEFAULT_FEE_CALCULATION_STRATEGY);
230231
return fac;
231232
}
232233
}

src/main/java/io/proximax/sdk/infrastructure/AccountHttp.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private List<AccountPropertiesInfoDTO> toAccountProperties(String json) {
8585
public Observable<List<AccountInfo>> getAccountsInfo(List<Address> addresses) {
8686
// prepare JSON array with addresses
8787
JsonArray arr = new JsonArray(addresses.size());
88-
addresses.stream().map(Address::plain).forEachOrdered(addr -> arr.add(addr));
88+
addresses.stream().map(Address::plain).forEachOrdered(arr::add);
8989

9090
JsonObject requestBody = new JsonObject();
9191
requestBody.add("addresses", arr);
@@ -123,7 +123,7 @@ public Observable<AccountProperties> getAccountProperties(Address address) {
123123
public Observable<List<AccountProperties>> getAccountProperties(List<Address> addresses) {
124124
// prepare JSON array with addresses
125125
JsonArray arr = new JsonArray(addresses.size());
126-
addresses.stream().map(Address::plain).forEachOrdered(addr -> arr.add(addr));
126+
addresses.stream().map(Address::plain).forEachOrdered(arr::add);
127127

128128
JsonObject requestBody = new JsonObject();
129129
requestBody.add("addresses", arr);
@@ -146,22 +146,32 @@ public Observable<List<Transaction>> transactions(PublicAccount publicAccount, Q
146146
}
147147

148148
private Observable<List<Transaction>> transactions(PublicAccount publicAccount, Optional<QueryParams> queryParams) {
149-
return this.findTransactions(publicAccount, queryParams, "/transactions");
149+
return this.findTransactions(publicAccount.getPublicKey(), queryParams, "/transactions");
150150
}
151151

152152
@Override
153153
public Observable<List<Transaction>> incomingTransactions(PublicAccount publicAccount) {
154-
return this.incomingTransactions(publicAccount, Optional.empty());
154+
return this.incomingTransactions(publicAccount.getPublicKey(), Optional.empty());
155155
}
156156

157157
@Override
158158
public Observable<List<Transaction>> incomingTransactions(PublicAccount publicAccount, QueryParams queryParams) {
159-
return this.incomingTransactions(publicAccount, Optional.of(queryParams));
159+
return this.incomingTransactions(publicAccount.getPublicKey(), Optional.of(queryParams));
160160
}
161161

162-
private Observable<List<Transaction>> incomingTransactions(PublicAccount publicAccount,
162+
@Override
163+
public Observable<List<Transaction>> incomingTransactions(Address address) {
164+
return this.incomingTransactions(address.plain(), Optional.empty());
165+
}
166+
167+
@Override
168+
public Observable<List<Transaction>> incomingTransactions(Address address, QueryParams queryParams) {
169+
return this.incomingTransactions(address.plain(), Optional.of(queryParams));
170+
}
171+
172+
private Observable<List<Transaction>> incomingTransactions(String accountKey,
163173
Optional<QueryParams> queryParams) {
164-
return this.findTransactions(publicAccount, queryParams, "/transactions/incoming");
174+
return this.findTransactions(accountKey, queryParams, "/transactions/incoming");
165175
}
166176

167177
@Override
@@ -176,7 +186,7 @@ public Observable<List<Transaction>> outgoingTransactions(PublicAccount publicAc
176186

177187
private Observable<List<Transaction>> outgoingTransactions(PublicAccount publicAccount,
178188
Optional<QueryParams> queryParams) {
179-
return this.findTransactions(publicAccount, queryParams, "/transactions/outgoing");
189+
return this.findTransactions(publicAccount.getPublicKey(), queryParams, "/transactions/outgoing");
180190
}
181191

182192
@Override
@@ -192,7 +202,7 @@ public Observable<List<AggregateTransaction>> aggregateBondedTransactions(Public
192202

193203
private Observable<List<AggregateTransaction>> aggregateBondedTransactions(PublicAccount publicAccount,
194204
Optional<QueryParams> queryParams) {
195-
return this.findTransactions(publicAccount, queryParams, "/transactions/partial").flatMapIterable(item -> item)
205+
return this.findTransactions(publicAccount.getPublicKey(), queryParams, "/transactions/partial").flatMapIterable(item -> item)
196206
.map(item -> (AggregateTransaction) item).toList().toObservable();
197207
}
198208

@@ -208,14 +218,14 @@ public Observable<List<Transaction>> unconfirmedTransactions(PublicAccount publi
208218

209219
private Observable<List<Transaction>> unconfirmedTransactions(PublicAccount publicAccount,
210220
Optional<QueryParams> queryParams) {
211-
return this.findTransactions(publicAccount, queryParams, "/transactions/unconfirmed");
221+
return this.findTransactions(publicAccount.getPublicKey(), queryParams, "/transactions/unconfirmed");
212222
}
213223

214-
private Observable<List<Transaction>> findTransactions(PublicAccount publicAccount,
224+
private Observable<List<Transaction>> findTransactions(String accountKey,
215225
Optional<QueryParams> queryParams, String path) {
216226
return this.client
217227
.get(ROUTE
218-
+ publicAccount.getPublicKey() + path + (queryParams.isPresent() ? queryParams.get().toUrl() : ""))
228+
+ accountKey + path + (queryParams.isPresent() ? queryParams.get().toUrl() : ""))
219229
.map(Http::mapStringOrError)
220230
.map(str -> stream(new Gson().fromJson(str, JsonArray.class)).map(s -> (JsonObject) s)
221231
.collect(Collectors.toList()))

src/main/java/io/proximax/sdk/infrastructure/ContractHttp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public Observable<Contract> getContract(Address address) {
4949
public Observable<List<Contract>> getContracts(Address... addresses) {
5050
// prepare JSON array with addresses
5151
JsonArray arr = new JsonArray(addresses.length);
52-
Arrays.stream(addresses).map(Address::plain).forEachOrdered(addr -> arr.add(addr));
52+
Arrays.stream(addresses).map(Address::plain).forEachOrdered(arr::add);
5353

5454
JsonObject requestBody = new JsonObject();
5555
requestBody.add("addresses", arr);
@@ -76,7 +76,7 @@ public Observable<Contract> getContract(PublicKey publicKey) {
7676
public Observable<List<Contract>> getContracts(PublicKey... publicKeys) {
7777
// prepare JSON array with public keys
7878
JsonArray arr = new JsonArray(publicKeys.length);
79-
Arrays.stream(publicKeys).map(PublicKey::getHexString).forEachOrdered(pubKey -> arr.add(pubKey));
79+
Arrays.stream(publicKeys).map(PublicKey::getHexString).forEachOrdered(arr::add);
8080

8181
JsonObject requestBody = new JsonObject();
8282
requestBody.add("publicKeys", arr);

src/main/java/io/proximax/sdk/infrastructure/MosaicHttp.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ private List<MosaicInfoDTO> toMosaicInfoList(String json) {
8989
}
9090

9191
private List<MosaicNamesDTO> toMosaicNamesList(String json) {
92-
System.out.println(json);
9392
return gson.fromJson(json, MOSAIC_NAMES_LIST_TYPE);
9493
}
9594
}

0 commit comments

Comments
 (0)