Skip to content

Commit

Permalink
Merge pull request #120 from proximax-storage/feature/111-118-renaming
Browse files Browse the repository at this point in the history
Rename TransactionType/Version to EntityType/Version + code improvements
  • Loading branch information
tonowie authored Sep 5, 2019
2 parents 4035778 + b39b0cf commit 47942da
Show file tree
Hide file tree
Showing 86 changed files with 549 additions and 448 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## 0.5.0 MaxFee calculation and transaction builders

See [milestone](https://github.com/proximax-storage/java-xpx-chain-sdk/milestone/5?closed=1) for fixed issues
* introduced fee calculation strategies
* introduced transaction builders as primary API to create transaction instances
* unified constructors and moved logic to transaction builders
* version field changes (breaks server backward compatibility)
* support for blockchain configuration and upgrade transactions/endpoints
* update of dependency versions

## 0.4.0 Dragon release support

See [milestone](https://github.com/proximax-storage/java-xpx-chain-sdk/milestone/4?closed=1) for fixed issues
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<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>

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![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)
[![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)
[![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)
[![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)

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

## Use the library ##

Current version of the library is <b>0.4.0</b>
Current version of the library is <b>0.5.0</b>

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:

Expand Down
18 changes: 11 additions & 7 deletions src/e2e/java/io/proximax/sdk/E2EAccountTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
import io.proximax.sdk.model.mosaic.NetworkCurrencyMosaic;
import io.proximax.sdk.model.namespace.NamespaceId;
import io.proximax.sdk.model.namespace.NamespaceInfo;
import io.proximax.sdk.model.transaction.EntityType;
import io.proximax.sdk.model.transaction.ModifyAccountPropertyTransaction;
import io.proximax.sdk.model.transaction.Transaction;
import io.proximax.sdk.model.transaction.TransactionType;
import io.proximax.sdk.model.transaction.UInt64Id;
import io.proximax.sdk.utils.dto.UInt64Utils;

Expand Down Expand Up @@ -126,9 +126,9 @@ void addAllowMosaicProperty() {
void addAllowEntityTypeProperty() {
Account acct = new Account(new KeyPair(), getNetworkType());
signup(acct.getAddress());
TransactionType allowedTransType = TransactionType.ACCOUNT_PROPERTIES_ENTITY_TYPE;
EntityType allowedTransType = EntityType.ACCOUNT_PROPERTIES_ENTITY_TYPE;
logger.info("going to allow {} by {}", allowedTransType, acct.getPublicAccount());
ModifyAccountPropertyTransaction<TransactionType> trans = transact.accountPropEntityType()
ModifyAccountPropertyTransaction<EntityType> trans = transact.accountPropEntityType()
.propertyType(AccountPropertyType.ALLOW_TRANSACTION)
.modifications(Arrays.asList(AccountPropertyModification.add(allowedTransType))).build();
// announce the transaction
Expand Down Expand Up @@ -213,15 +213,15 @@ private void testAccountPropertiesOnSimpleAccount(AccountProperties aps, UInt64I
* @param aps account properties
* @param blockedAddress address that is blocked
*/
private void testAccountPropertiesOnSimpleAccount(AccountProperties aps, TransactionType allowedTransactionType) {
private void testAccountPropertiesOnSimpleAccount(AccountProperties aps, EntityType allowedTransactionType) {
boolean gotMatch = false;
for (AccountProperty ap : aps.getProperties()) {
if (ap.getPropertyType().equals(AccountPropertyType.ALLOW_TRANSACTION)) {
for (Object value : ap.getValues()) {
try {
if (value instanceof Long && isValidTransactionTypeCode(((Long) value).intValue())) {
assertEquals(TransactionType.ACCOUNT_PROPERTIES_ENTITY_TYPE,
TransactionType.rawValueOf(((Long) value).intValue()));
assertEquals(EntityType.ACCOUNT_PROPERTIES_ENTITY_TYPE,
EntityType.rawValueOf(((Long) value).intValue()));
gotMatch = true;
}
} catch (RuntimeException e) {
Expand All @@ -236,7 +236,7 @@ private void testAccountPropertiesOnSimpleAccount(AccountProperties aps, Transac

private static boolean isValidTransactionTypeCode(int code) {
try {
TransactionType.rawValueOf(code);
EntityType.rawValueOf(code);
return true;
} catch (RuntimeException e) {
return false;
Expand Down Expand Up @@ -293,8 +293,12 @@ void transactionsWithPagination() throws ExecutionException, InterruptedExceptio
void incomingTransactions() throws ExecutionException, InterruptedException {
List<Transaction> transactions = accountHttp.incomingTransactions(simpleAccount.getPublicAccount()).toFuture()
.get();
List<Transaction> transactionsByAddr = accountHttp.incomingTransactions(simpleAccount.getPublicAccount().getAddress()).toFuture()
.get();

assertEquals(1, transactions.size());
assertEquals(1, transactionsByAddr.size());
assertEquals(transactions.get(0).getSignature(), transactionsByAddr.get(0).getSignature());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import io.proximax.sdk.TransactionRepository;
import io.proximax.sdk.model.transaction.Transaction;
import io.proximax.sdk.model.transaction.TransactionStatus;
import io.proximax.sdk.model.transaction.TransactionType;
import io.proximax.sdk.model.transaction.EntityType;
import io.reactivex.observers.TestObserver;
import io.reactivex.schedulers.Schedulers;

Expand All @@ -59,7 +59,7 @@ public void getTransaction() throws ExecutionException, InterruptedException {
.toFuture()
.get();

assertEquals(TransactionType.TRANSFER.getValue(), transaction.getType().getValue());
assertEquals(EntityType.TRANSFER.getValue(), transaction.getType().getValue());
assertEquals(TRANSACTION_HASH, transaction.getTransactionInfo().get().getHash().get());
}

Expand All @@ -70,7 +70,7 @@ public void getTransactions() throws ExecutionException, InterruptedException {
.toFuture()
.get();

assertEquals(TransactionType.TRANSFER.getValue(), transaction.get(0).getType().getValue());
assertEquals(EntityType.TRANSFER.getValue(), transaction.get(0).getType().getValue());
assertEquals(TRANSACTION_HASH, transaction.get(0).getTransactionInfo().get().getHash().get());
}

Expand Down
20 changes: 20 additions & 0 deletions src/main/java/io/proximax/sdk/AccountRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ public interface AccountRepository {
*/
Observable<List<Transaction>> incomingTransactions(PublicAccount publicAccount, QueryParams queryParams);

/**
* Gets an list of transactions for which an account is the recipient of a transaction.
* A transaction is said to be incoming with respect to an account if the account is the recipient of a transaction.
*
* @param address the address
* @return Observable of {@link Transaction} list
*/
Observable<List<Transaction>> incomingTransactions(Address address);

/**
* Gets an list of transactions for which an account is the recipient of a transaction.
* A transaction is said to be incoming with respect to an account if the account is the recipient of a transaction.
* With pagination.
*
* @param address the address
* @param queryParams QueryParams
* @return Observable of {@link Transaction} list
*/
Observable<List<Transaction>> incomingTransactions(Address address, QueryParams queryParams);

/**
* Gets an list of transactions for which an account is the sender a transaction.
* A transaction is said to be outgoing with respect to an account if the account is the sender of a transaction.
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/proximax/sdk/BlockchainApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ private NetworkType queryForNetworkType() {
public TransactionBuilderFactory transact() {
TransactionBuilderFactory fac = new TransactionBuilderFactory();
fac.setNetworkType(getNetworkType());
fac.setFeeCalculationStrategy(DEFAULT_FEE_CALCULATION_STRATEGY);
return fac;
}
}
34 changes: 22 additions & 12 deletions src/main/java/io/proximax/sdk/infrastructure/AccountHttp.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private List<AccountPropertiesInfoDTO> toAccountProperties(String json) {
public Observable<List<AccountInfo>> getAccountsInfo(List<Address> addresses) {
// prepare JSON array with addresses
JsonArray arr = new JsonArray(addresses.size());
addresses.stream().map(Address::plain).forEachOrdered(addr -> arr.add(addr));
addresses.stream().map(Address::plain).forEachOrdered(arr::add);

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

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

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

@Override
public Observable<List<Transaction>> incomingTransactions(PublicAccount publicAccount) {
return this.incomingTransactions(publicAccount, Optional.empty());
return this.incomingTransactions(publicAccount.getPublicKey(), Optional.empty());
}

@Override
public Observable<List<Transaction>> incomingTransactions(PublicAccount publicAccount, QueryParams queryParams) {
return this.incomingTransactions(publicAccount, Optional.of(queryParams));
return this.incomingTransactions(publicAccount.getPublicKey(), Optional.of(queryParams));
}

private Observable<List<Transaction>> incomingTransactions(PublicAccount publicAccount,
@Override
public Observable<List<Transaction>> incomingTransactions(Address address) {
return this.incomingTransactions(address.plain(), Optional.empty());
}

@Override
public Observable<List<Transaction>> incomingTransactions(Address address, QueryParams queryParams) {
return this.incomingTransactions(address.plain(), Optional.of(queryParams));
}

private Observable<List<Transaction>> incomingTransactions(String accountKey,
Optional<QueryParams> queryParams) {
return this.findTransactions(publicAccount, queryParams, "/transactions/incoming");
return this.findTransactions(accountKey, queryParams, "/transactions/incoming");
}

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

private Observable<List<Transaction>> outgoingTransactions(PublicAccount publicAccount,
Optional<QueryParams> queryParams) {
return this.findTransactions(publicAccount, queryParams, "/transactions/outgoing");
return this.findTransactions(publicAccount.getPublicKey(), queryParams, "/transactions/outgoing");
}

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

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

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

private Observable<List<Transaction>> unconfirmedTransactions(PublicAccount publicAccount,
Optional<QueryParams> queryParams) {
return this.findTransactions(publicAccount, queryParams, "/transactions/unconfirmed");
return this.findTransactions(publicAccount.getPublicKey(), queryParams, "/transactions/unconfirmed");
}

private Observable<List<Transaction>> findTransactions(PublicAccount publicAccount,
private Observable<List<Transaction>> findTransactions(String accountKey,
Optional<QueryParams> queryParams, String path) {
return this.client
.get(ROUTE
+ publicAccount.getPublicKey() + path + (queryParams.isPresent() ? queryParams.get().toUrl() : ""))
+ accountKey + path + (queryParams.isPresent() ? queryParams.get().toUrl() : ""))
.map(Http::mapStringOrError)
.map(str -> stream(new Gson().fromJson(str, JsonArray.class)).map(s -> (JsonObject) s)
.collect(Collectors.toList()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Observable<Contract> getContract(Address address) {
public Observable<List<Contract>> getContracts(Address... addresses) {
// prepare JSON array with addresses
JsonArray arr = new JsonArray(addresses.length);
Arrays.stream(addresses).map(Address::plain).forEachOrdered(addr -> arr.add(addr));
Arrays.stream(addresses).map(Address::plain).forEachOrdered(arr::add);

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

JsonObject requestBody = new JsonObject();
requestBody.add("publicKeys", arr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ private List<MosaicInfoDTO> toMosaicInfoList(String json) {
}

private List<MosaicNamesDTO> toMosaicNamesList(String json) {
System.out.println(json);
return gson.fromJson(json, MOSAIC_NAMES_LIST_TYPE);
}
}
Loading

0 comments on commit 47942da

Please sign in to comment.