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

Update LedgerResponse and AccountResponse, remove outdated fields, and add missing fields. #549

Merged
merged 5 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ As this project is pre 1.0, breaking changes may happen for minor version bumps.

## Pending
* Make `StrKey` public, this allows users to conveniently encode and decode Stellar keys to/from strings. ([#548](https://github.com/stellar/java-stellar-sdk/pull/548))
* Update `LedgerResponse` and `AccountResponse`, remove outdated fields, and add missing fields. ([#549](https://github.com/stellar/java-stellar-sdk/pull/549))

## 0.41.1
* Add `org.stellar.sdk.spi.SdkProvider`, users can implement this interface to provide their own implementation of the SDK. We provide an [Android specific implementation](https://github.com/stellar/java-stellar-sdk-android-spi), if you are integrating this SDK into an Android project, be sure to check it out. ([#543](https://github.com/stellar/java-stellar-sdk/pull/543))
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/stellar/sdk/responses/AccountResponse.java
Copy link
Contributor

@sreuland sreuland Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for consideration, add reference to https://developers.stellar.org/docs/fundamentals-and-concepts/stellar-data-structures/accounts to the AccountResponse class docs, noticed you added similar link for LedgerResponse , that content looks great!

Also, do you feel it's worthwhile to refactor AccountResponse to use lombok also, noticed you included that refactoring on pr for LedgerResponse, understand if not, as it's not related to the change scope.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or consideration, add reference to https://developers.stellar.org/docs/fundamentals-and-concepts/stellar-data-structures/accounts to the AccountResponse class docs, noticed you added similar link for LedgerResponse , that content looks great!

Added.

Also, do you feel it's worthwhile to refactor AccountResponse to use lombok also, noticed you included that refactoring on pr for LedgerResponse, understand if not, as it's not related to the change scope.

I did not refactor AccountResponse using Lombok because it would cause breaking changes. I think I will have a separate PR later to use Lombok to rewrite all the code.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class AccountResponse extends Response implements org.stellar.sdk.Transac
@SerializedName("last_modified_ledger")
private Integer lastModifiedLedger;

@SerializedName("last_modified_time")
private String lastModifiedTime;

@SerializedName("thresholds")
private Thresholds thresholds;

Expand Down Expand Up @@ -134,6 +137,10 @@ public Integer getLastModifiedLedger() {
return lastModifiedLedger;
}

public String getLastModifiedTime() {
return lastModifiedTime;
}

public Thresholds getThresholds() {
return thresholds;
}
Expand Down Expand Up @@ -274,6 +281,9 @@ public static class Balance {
@SerializedName("is_authorized_to_maintain_liabilities")
private final Boolean isAuthorizedToMaintainLiabilities;

@SerializedName("is_clawback_enabled")
private final Boolean isClawbackEnabled;

@SerializedName("last_modified_ledger")
private final Integer lastModifiedLedger;

Expand All @@ -291,6 +301,7 @@ public Balance(
@NonNull String sellingLiabilities,
Boolean isAuthorized,
Boolean isAuthorizedToMaintainLiabilities,
Boolean isClawbackEnabled,
Integer lastModifiedLedger,
String sponsor) {
this.assetType = assetType;
Expand All @@ -303,6 +314,7 @@ public Balance(
this.sellingLiabilities = sellingLiabilities;
this.isAuthorized = isAuthorized;
this.isAuthorizedToMaintainLiabilities = isAuthorizedToMaintainLiabilities;
this.isClawbackEnabled = isClawbackEnabled;
this.lastModifiedLedger = lastModifiedLedger;
// sponsor is an optional field
this.sponsor = sponsor;
Expand Down Expand Up @@ -356,6 +368,10 @@ public Boolean getAuthorizedToMaintainLiabilities() {
return isAuthorizedToMaintainLiabilities;
}

public Boolean getClawbackEnabled() {
return isClawbackEnabled;
}

public Integer getLastModifiedLedger() {
return lastModifiedLedger;
}
Expand Down
223 changes: 44 additions & 179 deletions src/main/java/org/stellar/sdk/responses/LedgerResponse.java
Original file line number Diff line number Diff line change
@@ -1,228 +1,93 @@
package org.stellar.sdk.responses;

import com.google.gson.annotations.SerializedName;
import lombok.EqualsAndHashCode;
import lombok.Value;

/**
* Represents ledger response.
*
* @see <a href="https://developers.stellar.org/docs/glossary/ledger/" target="_blank">Ledger
* documentation</a>
* @see <a
* href="https://developers.stellar.org/docs/fundamentals-and-concepts/stellar-data-structures/ledgers"
* target="_blank">Ledger documentation</a>
* @see <a href="https://developers.stellar.org/api/horizon/resources/ledgers/object/"
* target="_blank">Horizon API</a>
* @see org.stellar.sdk.requests.LedgersRequestBuilder
* @see org.stellar.sdk.Server#ledgers()
*/
@Value
@EqualsAndHashCode(callSuper = false)
public class LedgerResponse extends Response implements Pageable {
@SerializedName("sequence")
private final Long sequence;

@SerializedName("hash")
private final String hash;
@SerializedName("id")
String id;

@SerializedName("paging_token")
private final String pagingToken;
String pagingToken;

@SerializedName("hash")
String hash;

@SerializedName("prev_hash")
private final String prevHash;
String prevHash;

@SerializedName("transaction_count")
private final Integer transactionCount;
@SerializedName("sequence")
Long sequence;

@SerializedName("successful_transaction_count")
private final Integer successfulTransactionCount;
Integer successfulTransactionCount;

@SerializedName("failed_transaction_count")
private final Integer failedTransactionCount;
Integer failedTransactionCount;

@SerializedName("operation_count")
private final Integer operationCount;
Integer operationCount;

@SerializedName("tx_set_operation_count")
Integer txSetOperationCount;

@SerializedName("closed_at")
private final String closedAt;
String closedAt;

@SerializedName("total_coins")
private final String totalCoins;
String totalCoins;

@SerializedName("fee_pool")
private final String feePool;

@SerializedName("base_fee")
private final Long baseFee;

@SerializedName("base_reserve")
private final String baseReserve;
String feePool;

@SerializedName("base_fee_in_stroops")
private final String baseFeeInStroops;
String baseFeeInStroops;

@SerializedName("base_reserve_in_stroops")
private final String baseReserveInStroops;
String baseReserveInStroops;

@SerializedName("max_tx_set_size")
private final Integer maxTxSetSize;
Integer maxTxSetSize;

@SerializedName("protocol_version")
private final Integer protocolVersion;
Integer protocolVersion;

@SerializedName("header_xdr")
private final String headerXdr;
String headerXdr;

@SerializedName("_links")
private final Links links;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome!


LedgerResponse(
Long sequence,
String hash,
String pagingToken,
String prevHash,
Integer transactionCount,
Integer successfulTransactionCount,
Integer failedTransactionCount,
Integer operationCount,
String closedAt,
String totalCoins,
String feePool,
Long baseFee,
String baseReserve,
String baseFeeInStroops,
String baseReserveInStroops,
Integer maxTxSetSize,
Integer protocolVersion,
String headerXdr,
Links links) {
this.sequence = sequence;
this.hash = hash;
this.pagingToken = pagingToken;
this.prevHash = prevHash;
this.transactionCount = transactionCount;
this.successfulTransactionCount = successfulTransactionCount;
this.failedTransactionCount = failedTransactionCount;
this.operationCount = operationCount;
this.closedAt = closedAt;
this.totalCoins = totalCoins;
this.feePool = feePool;
this.baseFee = baseFee;
this.baseFeeInStroops = baseFeeInStroops;
this.baseReserve = baseReserve;
this.baseReserveInStroops = baseReserveInStroops;
this.maxTxSetSize = maxTxSetSize;
this.protocolVersion = protocolVersion;
this.headerXdr = headerXdr;
this.links = links;
}

public Long getSequence() {
return sequence;
}

public String getHash() {
return hash;
}

public String getPagingToken() {
return pagingToken;
}

public String getPrevHash() {
return prevHash;
}

/**
* @deprecated Will be removed in Horizon 0.17.0
*/
public Integer getTransactionCount() {
return transactionCount;
}

public Integer getSuccessfulTransactionCount() {
return successfulTransactionCount;
}

public Integer getFailedTransactionCount() {
return failedTransactionCount;
}

public Integer getOperationCount() {
return operationCount;
}

public String getClosedAt() {
return closedAt;
}

public String getTotalCoins() {
return totalCoins;
}

public String getFeePool() {
return feePool;
}

public Long getBaseFee() {
return baseFee;
}

public String getBaseReserve() {
return baseReserve;
}

public String getBaseFeeInStroops() {
return baseFeeInStroops;
}

public String getBaseReserveInStroops() {
return baseReserveInStroops;
}

public Integer getMaxTxSetSize() {
return maxTxSetSize;
}

public Integer getProtocolVersion() {
return protocolVersion;
}

public String getHeaderXdr() {
return headerXdr;
}

public Links getLinks() {
return links;
}
Links links;

/** Links connected to ledger. */
@Value
public static class Links {
@SerializedName("effects")
private final Link effects;
@SerializedName("self")
Link self;

@SerializedName("transactions")
Link transactions;

@SerializedName("operations")
private final Link operations;
Link operations;

@SerializedName("self")
private final Link self;
@SerializedName("payments")
Link payments;

@SerializedName("transactions")
private final Link transactions;

Links(Link effects, Link operations, Link self, Link transactions) {
this.effects = effects;
this.operations = operations;
this.self = self;
this.transactions = transactions;
}

public Link getEffects() {
return effects;
}

public Link getOperations() {
return operations;
}

public Link getSelf() {
return self;
}

public Link getTransactions() {
return transactions;
}
@SerializedName("effects")
Link effects;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void testDeserializeBalanceAuth() {
assertEquals(account.getBalances()[0].getSellingLiabilities(), Optional.of("100.7654321"));
assertEquals(account.getBalances()[0].getAuthorized(), Boolean.FALSE);
assertEquals(account.getBalances()[0].getAuthorizedToMaintainLiabilities(), Boolean.TRUE);
assertEquals(account.getBalances()[0].getClawbackEnabled(), Boolean.TRUE);

assertEquals(account.getBalances()[1].getAssetType(), "native");
assertEquals(account.getBalances()[1].getAsset(), Optional.of(new AssetTypeNative()));
Expand All @@ -46,6 +47,8 @@ public void testDeserialize() {
account.getAccountId(), "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7");
assertEquals(account.getSequenceNumber(), Long.valueOf(2319149195853854L));
assertEquals(account.getSubentryCount(), Integer.valueOf(0));
assertEquals(account.getLastModifiedLedger(), Integer.valueOf(117663));
assertEquals(account.getLastModifiedTime(), "2020-09-28T17:56:04Z");
assertEquals(account.getSequenceUpdatedAtLedger().longValue(), 1234);
assertEquals(account.getSequenceUpdatedAtTime().longValue(), 4567);
assertEquals(
Expand Down Expand Up @@ -240,7 +243,8 @@ public void testDeserializeLiquidityPoolBalanc() {
+ " \"asset_code\": \"ABC\",\n"
+ " \"asset_issuer\": \"GCRA6COW27CY5MTKIA7POQ2326C5ABYCXODBN4TFF5VL4FMBRHOT3YHU\",\n"
+ " \"is_authorized\": false,\n"
+ " \"is_authorized_to_maintain_liabilities\": true\n"
+ " \"is_authorized_to_maintain_liabilities\": true,\n"
+ " \"is_clawback_enabled\": true\n"
+ " },"
+ " {\n"
+ " \"asset_type\": \"native\",\n"
Expand Down Expand Up @@ -301,6 +305,8 @@ public void testDeserializeLiquidityPoolBalanc() {
+ " \"subentry_count\": 0,\n"
+ " \"inflation_destination\": \"GAGRSA6QNQJN2OQYCBNQGMFLO4QLZFNEHIFXOMTQVSUTWVTWT66TOFSC\",\n"
+ " \"home_domain\": \"stellar.org\",\n"
+ " \"last_modified_ledger\": 117663,\n"
+ " \"last_modified_time\": \"2020-09-28T17:56:04Z\",\n"
+ " \"thresholds\": {\n"
+ " \"low_threshold\": 10,\n"
+ " \"med_threshold\": 20,\n"
Expand Down
Loading
Loading