Skip to content

Commit

Permalink
Issue lightsail-network#261: Horizon v1.0.0 compatibility - convertin…
Browse files Browse the repository at this point in the history
…g Int64 to String

* Attribute offer_id in manage buy offer and manage sell offer operations.
* Attribute offer_id in Trade effect.
* Attribute id in Offer resource.
* Attribute timestamp and trade_count in Trade Aggregation resource.
  • Loading branch information
Joe committed Mar 6, 2020
1 parent f9c2ad0 commit b04eb98
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 61 deletions.
22 changes: 11 additions & 11 deletions src/main/java/org/stellar/sdk/ManageBuyOfferOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class ManageBuyOfferOperation extends Operation {
private final Asset buying;
private final String amount;
private final String price;
private final long offerId;
private final String offerId;

private ManageBuyOfferOperation(Asset selling, Asset buying, String amount, String price, long offerId) {
private ManageBuyOfferOperation(Asset selling, Asset buying, String amount, String price, String offerId) {
this.selling = checkNotNull(selling, "selling cannot be null");
this.buying = checkNotNull(buying, "buying cannot be null");
this.amount = checkNotNull(amount, "amount cannot be null");
Expand Down Expand Up @@ -59,7 +59,7 @@ public String getPrice() {
/**
* The ID of the offer.
*/
public long getOfferId() {
public String getOfferId() {
return offerId;
}

Expand All @@ -73,8 +73,8 @@ org.stellar.sdk.xdr.Operation.OperationBody toOperationBody() {
op.setBuyAmount(amount);
Price price = Price.fromString(this.price);
op.setPrice(price.toXdr());
Int64 offerId = new Int64();
offerId.setInt64(Long.valueOf(this.offerId));
String64 offerId = new String64();
offerId.setString64(new XdrString(this.offerId));
op.setOfferID(offerId);

org.stellar.sdk.xdr.Operation.OperationBody body = new org.stellar.sdk.xdr.Operation.OperationBody();
Expand All @@ -86,7 +86,7 @@ org.stellar.sdk.xdr.Operation.OperationBody toOperationBody() {

/**
* Builds ManageBuyOffer operation. If you want to update existing offer use
* {@link org.stellar.sdk.ManageBuyOfferOperation.Builder#setOfferId(long)}.
* {@link org.stellar.sdk.ManageBuyOfferOperation.Builder#setOfferId(String)}.
*
* @see ManageBuyOfferOperation
*/
Expand All @@ -96,7 +96,7 @@ public static class Builder {
private final Asset buying;
private final String amount;
private final String price;
private long offerId = 0;
private String offerId = "0";

private String mSourceAccount;

Expand All @@ -108,14 +108,14 @@ public static class Builder {
Builder(ManageBuyOfferOp op) {
selling = Asset.fromXdr(op.getSelling());
buying = Asset.fromXdr(op.getBuying());
amount = Operation.fromXdrAmount(op.getBuyAmount().getInt64().longValue());
amount = Operation.fromXdrAmount(op.getBuyAmount().getInt64());
price = Price.fromXdr(op.getPrice()).toString();
offerId = op.getOfferID().getInt64().longValue();
offerId = op.getOfferID().getString64().toString();
}

/**
* Creates a new ManageBuyOffer builder. If you want to update existing offer use
* {@link org.stellar.sdk.ManageBuyOfferOperation.Builder#setOfferId(long)}.
* {@link org.stellar.sdk.ManageBuyOfferOperation.Builder#setOfferId(String)}.
*
* @param selling The asset being sold in this operation
* @param buying The asset being bought in this operation
Expand All @@ -135,7 +135,7 @@ public Builder(Asset selling, Asset buying, String amount, String price) {
*
* @param offerId
*/
public Builder setOfferId(long offerId) {
public Builder setOfferId(String offerId) {
this.offerId = offerId;
return this;
}
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/org/stellar/sdk/ManageSellOfferOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class ManageSellOfferOperation extends Operation {
private final Asset buying;
private final String amount;
private final String price;
private final long offerId;
private final String offerId;

private ManageSellOfferOperation(Asset selling, Asset buying, String amount, String price, long offerId) {
private ManageSellOfferOperation(Asset selling, Asset buying, String amount, String price, String offerId) {
this.selling = checkNotNull(selling, "selling cannot be null");
this.buying = checkNotNull(buying, "buying cannot be null");
this.amount = checkNotNull(amount, "amount cannot be null");
Expand Down Expand Up @@ -58,7 +58,7 @@ public String getPrice() {
/**
* The ID of the offer.
*/
public long getOfferId() {
public String getOfferId() {
return offerId;
}

Expand All @@ -72,8 +72,8 @@ org.stellar.sdk.xdr.Operation.OperationBody toOperationBody() {
op.setAmount(amount);
Price price = Price.fromString(this.price);
op.setPrice(price.toXdr());
Int64 offerId = new Int64();
offerId.setInt64(Long.valueOf(this.offerId));
String64 offerId = new String64();
offerId.setString64(new XdrString(this.offerId));
op.setOfferID(offerId);

org.stellar.sdk.xdr.Operation.OperationBody body = new org.stellar.sdk.xdr.Operation.OperationBody();
Expand All @@ -85,7 +85,7 @@ org.stellar.sdk.xdr.Operation.OperationBody toOperationBody() {

/**
* Builds ManageSellOffer operation. If you want to update existing offer use
* {@link org.stellar.sdk.ManageSellOfferOperation.Builder#setOfferId(long)}.
* {@link org.stellar.sdk.ManageSellOfferOperation.Builder#setOfferId(String)}.
* @see ManageSellOfferOperation
*/
public static class Builder {
Expand All @@ -94,7 +94,7 @@ public static class Builder {
private final Asset buying;
private final String amount;
private final String price;
private long offerId = 0;
private String offerId = "0";

private String mSourceAccount;

Expand All @@ -105,14 +105,14 @@ public static class Builder {
Builder(ManageSellOfferOp op) {
selling = Asset.fromXdr(op.getSelling());
buying = Asset.fromXdr(op.getBuying());
amount = Operation.fromXdrAmount(op.getAmount().getInt64().longValue());
amount = Operation.fromXdrAmount(op.getAmount().getInt64());
price = Price.fromXdr(op.getPrice()).toString();
offerId = op.getOfferID().getInt64().longValue();
offerId = op.getOfferID().getString64().toString();
}

/**
* Creates a new ManageSellOffer builder. If you want to update existing offer use
* {@link org.stellar.sdk.ManageSellOfferOperation.Builder#setOfferId(long)}.
* {@link org.stellar.sdk.ManageSellOfferOperation.Builder#setOfferId(String)}.
* @param selling The asset being sold in this operation
* @param buying The asset being bought in this operation
* @param amount Amount of selling being sold.
Expand All @@ -130,7 +130,7 @@ public Builder(Asset selling, Asset buying, String amount, String price) {
* Sets offer ID. <code>0</code> creates a new offer. Set to existing offer ID to change it.
* @param offerId
*/
public Builder setOfferId(long offerId) {
public Builder setOfferId(String offerId) {
this.offerId = offerId;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public SSEStream<OfferResponse> stream(final EventListener<OfferResponse> listen
* @throws IOException
*/
public Page<OfferResponse> execute() throws IOException, TooManyRequestsException {
return this.execute(this.httpClient, this.buildUri());
return execute(this.httpClient, this.buildUri());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ public static Page<TradeAggregationResponse> execute(OkHttpClient httpClient, Ht
}

public Page<TradeAggregationResponse> execute() throws IOException, TooManyRequestsException {
return this.execute(this.httpClient, this.buildUri());
return execute(this.httpClient, this.buildUri());
}
}
6 changes: 3 additions & 3 deletions src/main/java/org/stellar/sdk/responses/OfferResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
public class OfferResponse extends Response implements Pageable {
@SerializedName("id")
private final Long id;
private final String id;
@SerializedName("paging_token")
private final String pagingToken;
@SerializedName("seller")
Expand All @@ -32,7 +32,7 @@ public class OfferResponse extends Response implements Pageable {
@SerializedName("_links")
private final Links links;

public OfferResponse(Long id, String pagingToken, String seller, Asset selling, Asset buying, String amount, String price, Integer lastModifiedLedger, String lastModifiedTime, Links links) {
public OfferResponse(String id, String pagingToken, String seller, Asset selling, Asset buying, String amount, String price, Integer lastModifiedLedger, String lastModifiedTime, Links links) {
this.id = id;
this.pagingToken = pagingToken;
this.seller = seller;
Expand All @@ -45,7 +45,7 @@ public OfferResponse(Long id, String pagingToken, String seller, Asset selling,
this.links = links;
}

public Long getId() {
public String getId() {
return id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

public class TradeAggregationResponse extends Response {
@SerializedName("timestamp")
private final long timestamp;
private final String timestamp;
@SerializedName("trade_count")
private final int tradeCount;
private final String tradeCount;
@SerializedName("base_volume")
private final String baseVolume;
@SerializedName("counter_volume")
Expand All @@ -24,7 +24,7 @@ public class TradeAggregationResponse extends Response {
@SerializedName("close")
private final String close;

public TradeAggregationResponse(long timestamp, int tradeCount, String baseVolume, String counterVolume, String avg, String high, String low, String open, String close) {
public TradeAggregationResponse(String timestamp, String tradeCount, String baseVolume, String counterVolume, String avg, String high, String low, String open, String close) {
this.timestamp = timestamp;
this.tradeCount = tradeCount;
this.baseVolume = baseVolume;
Expand All @@ -36,15 +36,15 @@ public TradeAggregationResponse(long timestamp, int tradeCount, String baseVolum
this.close = close;
}

public long getTimestamp() {
public String getTimestamp() {
return timestamp;
}

public Date getDate() {
return new Date(Long.valueOf(this.timestamp));
return new Date(Long.parseLong(this.timestamp));
}

public int getTradeCount() {
public String getTradeCount() {
return tradeCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TradeEffectResponse extends EffectResponse {
@SerializedName("seller")
protected final String seller;
@SerializedName("offer_id")
protected final Long offerId;
protected final String offerId;

@SerializedName("sold_amount")
protected final String soldAmount;
Expand All @@ -35,7 +35,16 @@ public class TradeEffectResponse extends EffectResponse {
@SerializedName("bought_asset_issuer")
protected final String boughtAssetIssuer;

TradeEffectResponse(String seller, Long offerId, String soldAmount, String soldAssetType, String soldAssetCode, String soldAssetIssuer, String boughtAmount, String boughtAssetType, String boughtAssetCode, String boughtAssetIssuer) {
TradeEffectResponse(String seller,
String offerId,
String soldAmount,
String soldAssetType,
String soldAssetCode,
String soldAssetIssuer,
String boughtAmount,
String boughtAssetType,
String boughtAssetCode,
String boughtAssetIssuer) {
this.seller = seller;
this.offerId = offerId;
this.soldAmount = soldAmount;
Expand All @@ -52,7 +61,7 @@ public String getSeller() {
return seller;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
public class ManageBuyOfferOperationResponse extends OperationResponse {
@SerializedName("offer_id")
protected final Integer offerId;
protected final String offerId;
@SerializedName("amount")
protected final String amount;
// Price is not implemented yet in horizon
Expand All @@ -34,7 +34,15 @@ public class ManageBuyOfferOperationResponse extends OperationResponse {
@SerializedName("selling_asset_issuer")
protected final String sellingAssetIssuer;

ManageBuyOfferOperationResponse(Integer offerId, String amount, String price, String buyingAssetType, String buyingAssetCode, String buyingAssetIssuer, String sellingAssetType, String sellingAssetCode, String sellingAssetIssuer) {
ManageBuyOfferOperationResponse(String offerId,
String amount,
String price,
String buyingAssetType,
String buyingAssetCode,
String buyingAssetIssuer,
String sellingAssetType,
String sellingAssetCode,
String sellingAssetIssuer) {
this.offerId = offerId;
this.amount = amount;
this.price = price;
Expand All @@ -46,7 +54,7 @@ public class ManageBuyOfferOperationResponse extends OperationResponse {
this.sellingAssetIssuer = sellingAssetIssuer;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
public class ManageSellOfferOperationResponse extends OperationResponse {
@SerializedName("offer_id")
protected final Integer offerId;
protected final String offerId;
@SerializedName("amount")
protected final String amount;
// Price is not implemented yet in horizon
Expand All @@ -35,7 +35,15 @@ public class ManageSellOfferOperationResponse extends OperationResponse {
@SerializedName("selling_asset_issuer")
protected final String sellingAssetIssuer;

ManageSellOfferOperationResponse(Integer offerId, String amount, String price, String buyingAssetType, String buyingAssetCode, String buyingAssetIssuer, String sellingAssetType, String sellingAssetCode, String sellingAssetIssuer) {
ManageSellOfferOperationResponse(String offerId,
String amount,
String price,
String buyingAssetType,
String buyingAssetCode,
String buyingAssetIssuer,
String sellingAssetType,
String sellingAssetCode,
String sellingAssetIssuer) {
this.offerId = offerId;
this.amount = amount;
this.price = price;
Expand All @@ -47,7 +55,7 @@ public class ManageSellOfferOperationResponse extends OperationResponse {
this.sellingAssetIssuer = sellingAssetIssuer;
}

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

Expand Down
18 changes: 11 additions & 7 deletions src/main/java/org/stellar/sdk/xdr/ManageBuyOfferOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ public Price getPrice() {
public void setPrice(Price value) {
this.price = value;
}
private Int64 offerID;
public Int64 getOfferID() {
private String64 offerID;
public String64 getOfferID() {
return this.offerID;
}
public void setOfferID(Int64 value) {
public void setOfferID(String64 value) {
this.offerID = value;
}
public static void encode(XdrDataOutputStream stream, ManageBuyOfferOp encodedManageBuyOfferOp) throws IOException{
Asset.encode(stream, encodedManageBuyOfferOp.selling);
Asset.encode(stream, encodedManageBuyOfferOp.buying);
Int64.encode(stream, encodedManageBuyOfferOp.buyAmount);
Price.encode(stream, encodedManageBuyOfferOp.price);
Int64.encode(stream, encodedManageBuyOfferOp.offerID);
String64.encode(stream, encodedManageBuyOfferOp.offerID);
}
public void encode(XdrDataOutputStream stream) throws IOException {
encode(stream, this);
Expand All @@ -76,7 +76,7 @@ public static ManageBuyOfferOp decode(XdrDataInputStream stream) throws IOExcept
decodedManageBuyOfferOp.buying = Asset.decode(stream);
decodedManageBuyOfferOp.buyAmount = Int64.decode(stream);
decodedManageBuyOfferOp.price = Price.decode(stream);
decodedManageBuyOfferOp.offerID = Int64.decode(stream);
decodedManageBuyOfferOp.offerID = String64.decode(stream);
return decodedManageBuyOfferOp;
}
@Override
Expand All @@ -85,11 +85,15 @@ public int hashCode() {
}
@Override
public boolean equals(Object object) {
if (object == null || !(object instanceof ManageBuyOfferOp)) {
if (!(object instanceof ManageBuyOfferOp)) {
return false;
}

ManageBuyOfferOp other = (ManageBuyOfferOp) object;
return Objects.equal(this.selling, other.selling) && Objects.equal(this.buying, other.buying) && Objects.equal(this.buyAmount, other.buyAmount) && Objects.equal(this.price, other.price) && Objects.equal(this.offerID, other.offerID);
return Objects.equal(this.selling, other.selling)
&& Objects.equal(this.buying, other.buying)
&& Objects.equal(this.buyAmount, other.buyAmount)
&& Objects.equal(this.price, other.price)
&& Objects.equal(this.offerID, other.offerID);
}
}
Loading

0 comments on commit b04eb98

Please sign in to comment.