Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#307: change offer ids to be represented in requests and response as long data type #386

Merged
merged 4 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
As this project is pre 1.0, breaking changes may happen for minor version bumps. A breaking change will get clearly notified in this log.

## Unreleased

### Changes
sreuland marked this conversation as resolved.
Show resolved Hide resolved
* Fix missing Liquidity Pool ID in AccountResponse Balance ([#379](https://github.com/stellar/java-stellar-sdk/pull/379)).
* Fix null pointer when calling ChangeTrustOperationResponse.getAsset() for LiquidityPool trust line ([#378](https://github.com/stellar/java-stellar-sdk/pull/378)).
### Breaking changes
sreuland marked this conversation as resolved.
Show resolved Hide resolved
* Changed offer ids to be represented in requests and response models as long data type. ([#386](https://github.com/stellar/java-stellar-sdk/pull/386)).
* `TradesRequestBuilder.offerId()`
* `TradeResponse.getOfferId()`
* `TradeResponse.getBaseOfferId()`
* `TradeResponse.getCounterOfferId()`
* `RevokeSponsorshipOperationResponse.getOfferId()`

## 0.29.0

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/stellar/sdk/requests/TradesRequestBuilder.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.stellar.sdk.requests;

import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand All @@ -12,6 +11,8 @@
import org.stellar.sdk.responses.Page;
import org.stellar.sdk.responses.TradeResponse;

import java.io.IOException;

import static com.google.common.base.Preconditions.checkNotNull;

/**
Expand Down Expand Up @@ -77,7 +78,7 @@ public TradesRequestBuilder forLiquidityPool(String liquidityPoolID) {
/**
* Returns all trades that of a specific type.
*
* @param trade type
* @param tradeType type
* @return current {@link TradesRequestBuilder} instance
* @see <a href="https://developers.stellar.org/api/resources/trades/list/">List All Trades</a>
*/
Expand All @@ -103,8 +104,11 @@ public Page<TradeResponse> execute() throws IOException, TooManyRequestsExceptio
return this.execute(this.httpClient, this.buildUri());
}

public TradesRequestBuilder offerId(String offerId) {
uriBuilder.setQueryParameter("offer_id", offerId);
public TradesRequestBuilder offerId(Long offerId) {
if (offerId == null) {
return this;
sreuland marked this conversation as resolved.
Show resolved Hide resolved
}
uriBuilder.setQueryParameter("offer_id", offerId.toString());
return this;
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/stellar/sdk/responses/TradeResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class TradeResponse extends Response implements Pageable {
private final String ledgerCloseTime;

@SerializedName("offer_id")
private final String offerId;
private final Long offerId;

@SerializedName("base_is_seller")
protected final boolean baseIsSeller;
Expand All @@ -31,7 +31,7 @@ public class TradeResponse extends Response implements Pageable {
@SerializedName("base_liquidity_pool_id")
protected LiquidityPoolID baseLiquidityPoolID;
@SerializedName("base_offer_id")
private String baseOfferId;
private Long baseOfferId;
@SerializedName("base_amount")
protected final String baseAmount;
@SerializedName("base_asset_type")
Expand All @@ -46,7 +46,7 @@ public class TradeResponse extends Response implements Pageable {
@SerializedName("counter_liquidity_pool_id")
protected LiquidityPoolID counterLiquidityPoolID;
@SerializedName("counter_offer_id")
private String counterOfferId;
private Long counterOfferId;
@SerializedName("counter_amount")
protected final String counterAmount;
@SerializedName("counter_asset_type")
Expand All @@ -62,7 +62,7 @@ public class TradeResponse extends Response implements Pageable {
@SerializedName("_links")
private TradeResponse.Links links;

public TradeResponse(String id, String pagingToken, String ledgerCloseTime, String offerId, boolean baseIsSeller, String baseAccount, LiquidityPoolID baseLiquidityPoolID, String baseOfferId, String baseAmount, String baseAssetType, String baseAssetCode, String baseAssetIssuer, String counterAccount, LiquidityPoolID counterLiquidityPoolID, String counterOfferId, String counterAmount, String counterAssetType, String counterAssetCode, String counterAssetIssuer, TradePrice price) {
public TradeResponse(String id, String pagingToken, String ledgerCloseTime, Long offerId, boolean baseIsSeller, String baseAccount, LiquidityPoolID baseLiquidityPoolID, Long baseOfferId, String baseAmount, String baseAssetType, String baseAssetCode, String baseAssetIssuer, String counterAccount, LiquidityPoolID counterLiquidityPoolID, Long counterOfferId, String counterAmount, String counterAssetType, String counterAssetCode, String counterAssetIssuer, TradePrice price) {
this.id = id;
this.pagingToken = pagingToken;
this.ledgerCloseTime = ledgerCloseTime;
Expand Down Expand Up @@ -97,15 +97,15 @@ public String getLedgerCloseTime() {
return ledgerCloseTime;
}

public String getOfferId() {
public Long getOfferId() {
return offerId;
}

public boolean isBaseSeller() {
return baseIsSeller;
}

public Optional<String> getBaseOfferId() {
public Optional<Long> getBaseOfferId() {
return Optional.fromNullable(baseOfferId);
}

Expand Down Expand Up @@ -145,7 +145,7 @@ public Optional<LiquidityPoolID> getCounterLiquidityPoolID() {
return Optional.fromNullable(counterLiquidityPoolID);
}

public Optional<String> getCounterOfferId() {
public Optional<Long> getCounterOfferId() {
return Optional.fromNullable(counterOfferId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class RevokeSponsorshipOperationResponse extends OperationResponse {
private final String dataName;

@SerializedName("offer_id")
private final String offerId;
private final Long offerId;

@SerializedName("trustline_account_id")
private final String trustlineAccountId;
Expand All @@ -37,7 +37,7 @@ public class RevokeSponsorshipOperationResponse extends OperationResponse {
private final String signerKey;


public RevokeSponsorshipOperationResponse(String accountId, String claimableBalanceId, String dataAccountId, String dataName, String offerId, String trustlineAccountId, String trustlineAsset, String signerAccountId, String signerKey) {
public RevokeSponsorshipOperationResponse(String accountId, String claimableBalanceId, String dataAccountId, String dataName, Long offerId, String trustlineAccountId, String trustlineAsset, String signerAccountId, String signerKey) {
this.accountId = accountId;
this.claimableBalanceId = claimableBalanceId;
this.dataAccountId = dataAccountId;
Expand Down Expand Up @@ -65,7 +65,7 @@ public Optional<String> getDataName() {
return Optional.fromNullable(dataName);
}

public Optional<String> getOfferId() {
public Optional<Long> getOfferId() {
return Optional.fromNullable(offerId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public void testTrades() {
.baseAsset(Asset.createNonNativeAsset("EUR", "GAUPA4HERNBDPVO4IUA3MJXBCRRK5W54EVXTDK6IIUTGDQRB6D5W242W"))
.counterAsset(Asset.createNonNativeAsset("USD", "GDRRHSJMHXDTQBT4JTCILNGF5AS54FEMTXL7KOLMF6TFTHRK6SSUSUZZ"))
.cursor("13537736921089")
.offerId(123L)
.limit(200)
.order(RequestBuilder.Order.ASC)
.buildUri();
Expand All @@ -30,6 +31,7 @@ public void testTrades() {
"counter_asset_code=USD&" +
"counter_asset_issuer=GDRRHSJMHXDTQBT4JTCILNGF5AS54FEMTXL7KOLMF6TFTHRK6SSUSUZZ&" +
"cursor=13537736921089&" +
"offer_id=123&" +
"limit=200&" +
"order=asc", uri.toString());
}
Expand Down Expand Up @@ -58,4 +60,15 @@ public void testForLiquidityPool() {
.buildUri();
assertEquals("https://horizon-testnet.stellar.org/liquidity_pools/67260c4c1807b262ff851b0a3fe141194936bb0215b2f77447f1df11998eabb9/trades", uri.toString());
}

@Test
public void testForNullOfferId() {
Server server = new Server("https://horizon-testnet.stellar.org");
HttpUrl uri = server.trades()
.cursor("13537736921089")
.offerId(null)
.limit(200)
.buildUri();
assertEquals("https://horizon-testnet.stellar.org/trades?cursor=13537736921089&limit=200", uri.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.stellar.sdk.responses.operations.PaymentOperationResponse;
import org.stellar.sdk.responses.operations.RevokeSponsorshipOperationResponse;

import static java.lang.Long.valueOf;

public class OperationsPageDeserializerTest extends TestCase {
@Test
public void testDeserialize() {
Expand Down Expand Up @@ -50,7 +52,7 @@ public void testDeserializeWithTransactions() {

TransactionResponse transaction = createAccountOperation.getTransaction().get();
assertEquals(transaction.getHash(), "749e4f8933221b9942ef38a02856803f379789ec8d971f1f60535db70135673e");
assertEquals(transaction.getLedger(), Long.valueOf(193));
assertEquals(transaction.getLedger(), valueOf(193));
assertEquals(transaction.getMemo(), Memo.none());
}

Expand All @@ -67,7 +69,7 @@ public void testDeserializeRevokeSponsorship() {
assertFalse(revokeOp.getSignerKey().isPresent());
assertFalse(revokeOp.getTrustlineAccountId().isPresent());
assertFalse(revokeOp.getTrustlineAsset().isPresent());
assertEquals(revokeOp.getOfferId().get(), "8822470");
assertEquals(revokeOp.getOfferId().get(), valueOf(8822470));
assertEquals(revokeOp.getSourceAccount(), "GB6QDNU47MYBR4NDTRP7M3FW27DAFOEADN5KDQI2DAVWW6YVKKG4QJS7");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.stellar.sdk.Asset;
import org.stellar.sdk.AssetTypeNative;

import static java.lang.Long.valueOf;

public class TradesPageDeserializerTest extends TestCase {
@Test
public void testDeserialize() {
Expand All @@ -19,13 +21,13 @@ public void testDeserialize() {
assertEquals(tradesPage.getRecords().get(0).getId(), "3697472920621057-0");
assertEquals(tradesPage.getRecords().get(0).getPagingToken(), "3697472920621057-0");
assertEquals(tradesPage.getRecords().get(0).getLedgerCloseTime(), "2015-11-18T03:47:47Z");
assertEquals(tradesPage.getRecords().get(0).getOfferId(), "9");
assertEquals(tradesPage.getRecords().get(0).getBaseOfferId(), Optional.of("10"));
assertEquals(tradesPage.getRecords().get(0).getCounterOfferId(), Optional.of("11"));
assertEquals(tradesPage.getRecords().get(0).getOfferId(), valueOf(9));
assertEquals(tradesPage.getRecords().get(0).getBaseOfferId(), Optional.of(valueOf(10)));
assertEquals(tradesPage.getRecords().get(0).getCounterOfferId(), Optional.of(valueOf(11)));
assertEquals(tradesPage.getRecords().get(0).getBaseAsset(), new AssetTypeNative());
assertEquals(tradesPage.getRecords().get(0).getCounterAsset(), Asset.createNonNativeAsset("JPY", "GBVAOIACNSB7OVUXJYC5UE2D4YK2F7A24T7EE5YOMN4CE6GCHUTOUQXM"));
assertEquals(tradesPage.getRecords().get(0).getPrice().getNumerator(), Long.valueOf(267));
assertEquals(tradesPage.getRecords().get(0).getPrice().getDenominator(), Long.valueOf(1000));
assertEquals(tradesPage.getRecords().get(0).getPrice().getNumerator(), valueOf(267));
assertEquals(tradesPage.getRecords().get(0).getPrice().getDenominator(), valueOf(1000));

assertEquals(tradesPage.getRecords().get(1).getBaseAccount(), Optional.of("GAVH5JM5OKXGMQDS7YPRJ4MQCPXJUGH26LYQPQJ4SOMOJ4SXY472ZM7G"));
}
Expand Down