Skip to content

Commit

Permalink
Update LedgerResponse and AccountResponse, remove outdated fields…
Browse files Browse the repository at this point in the history
…, and add missing fields. (#549)

* update outdated `LedgerResponse`

* update outdated `AccountResponse`

* update docs

* update docs link
  • Loading branch information
overcat authored Oct 21, 2023
1 parent d564e88 commit 19570b4
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 523 deletions.
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
21 changes: 19 additions & 2 deletions src/main/java/org/stellar/sdk/responses/AccountResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
/**
* Represents account response.
*
* @see <a href="https://developers.stellar.org/api/resources/accounts/" target="_blank">Account
* documentation</a>
* @see <a
* href="https://developers.stellar.org/docs/fundamentals-and-concepts/stellar-data-structures/accounts"
* target="_blank">Account documentation</a>
* @see org.stellar.sdk.requests.AccountsRequestBuilder
* @see org.stellar.sdk.Server#accounts()
*/
Expand Down Expand Up @@ -44,6 +45,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 +138,10 @@ public Integer getLastModifiedLedger() {
return lastModifiedLedger;
}

public String getLastModifiedTime() {
return lastModifiedTime;
}

public Thresholds getThresholds() {
return thresholds;
}
Expand Down Expand Up @@ -274,6 +282,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 +302,7 @@ public Balance(
@NonNull String sellingLiabilities,
Boolean isAuthorized,
Boolean isAuthorizedToMaintainLiabilities,
Boolean isClawbackEnabled,
Integer lastModifiedLedger,
String sponsor) {
this.assetType = assetType;
Expand All @@ -303,6 +315,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 +369,10 @@ public Boolean getAuthorizedToMaintainLiabilities() {
return isAuthorizedToMaintainLiabilities;
}

public Boolean getClawbackEnabled() {
return isClawbackEnabled;
}

public Integer getLastModifiedLedger() {
return lastModifiedLedger;
}
Expand Down
221 changes: 42 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,91 @@
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 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;

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

0 comments on commit 19570b4

Please sign in to comment.