Skip to content

Commit

Permalink
Merge pull request #646 from lightsail-network/p22-api-changes
Browse files Browse the repository at this point in the history
p22 api changes
  • Loading branch information
overcat authored Oct 14, 2024
2 parents e0220db + 49ec25e commit 314406f
Show file tree
Hide file tree
Showing 31 changed files with 55 additions and 81 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ continued engagement as we shape the future of this project together.
- chore: add some examples, you can find them in the `examples` directory.
- chore: bump dependencies.
- feat: add support for Soroban PRC's `getVersionInfo` API.
- refactor!: remove `amount` and `numAccounts` from `AssetResponse`.
- refactor!: remove `cost` from `SimulateTransactionResponse`, the correct resource costs can now be retrieved from the `transactionData`.
- refactor!: remove `pagingToken` from `GetEventsResponse.EventInfo`, use `GetEventsResponse.cursor` instead.
- feat: add `txHash` to `GetTransactionResponse` and `GetTransactionsResponse.Transaction`.

### Breaking changes
- refactor!: Refactored the handling of exceptions.
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/org/stellar/sdk/responses/AssetResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public class AssetResponse extends Response implements Pageable {
@SerializedName("contract_id")
String contractId;

@SerializedName("num_accounts")
Integer numAccounts;

@SerializedName("num_claimable_balances")
Integer numClaimableBalances;

Expand All @@ -38,9 +35,6 @@ public class AssetResponse extends Response implements Pageable {
@SerializedName("num_archived_contracts")
Integer numArchivedContracts;

@SerializedName("amount")
String amount;

@SerializedName("accounts")
AssetResponse.Accounts accounts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class SubmitTransactionAsyncResponse {
@SerializedName("tx_status")
TransactionStatus txStatus;

@SerializedName("errorResultXdr") // inconsistency
@SerializedName("error_result_xdr")
String errorResultXdr;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class GetEventsResponse {

Long latestLedger;

String cursor;

@Value
public static class EventInfo {
EventFilterType type;
Expand All @@ -32,8 +34,6 @@ public static class EventInfo {

String id;

String pagingToken;

/** The elements inside can be parsed as {@link org.stellar.sdk.xdr.SCVal} objects. */
List<String> topic;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
public class GetTransactionResponse {
GetTransactionStatus status;

String txHash;

Long latestLedger;

Long latestLedgerCloseTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class GetTransactionsResponse {
@Value
public static class Transaction {
TransactionStatus status;
String txHash;
Integer applicationOrder;
Boolean feeBump;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.stellar.sdk.responses.sorobanrpc;

import com.google.gson.annotations.SerializedName;
import java.math.BigInteger;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Value;
Expand Down Expand Up @@ -44,8 +42,6 @@ public class SimulateTransactionResponse {
// is supported per transaction.
List<SimulateHostFunctionResult> results;

SimulateTransactionCost cost;

RestorePreamble restorePreamble;

List<LedgerEntryChange> stateChanges;
Expand Down Expand Up @@ -102,15 +98,6 @@ public SCVal parseXdr() {
}
}

@Value
public static class SimulateTransactionCost {
@SerializedName("cpuInsns")
BigInteger cpuInstructions;

@SerializedName("memBytes")
BigInteger memoryBytes;
}

@Value
public static class RestorePreamble {
/** The field can be parsed as {@link org.stellar.sdk.xdr.SorobanTransactionData} object. */
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/stellar/sdk/ServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public void testSubmitTransactionAsyncTryAgainLater() throws IOException {
public void testSubmitTransactionAsyncError() throws IOException {
String resp =
"{\n"
+ " \"errorResultXdr\": \"AAAAAAAAAGT////7AAAAAA==\",\n"
+ " \"error_result_xdr\": \"AAAAAAAAAGT////7AAAAAA==\",\n"
+ " \"tx_status\": \"ERROR\",\n"
+ " \"hash\": \"2634d2cf5adcbd3487d1df042166eef53830115844fdde1588828667bf93ff42\"\n"
+ "}";
Expand Down
18 changes: 12 additions & 6 deletions src/test/java/org/stellar/sdk/SorobanServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.stellar.sdk.responses.sorobanrpc.GetLatestLedgerResponse;
import org.stellar.sdk.responses.sorobanrpc.GetLedgerEntriesResponse;
import org.stellar.sdk.responses.sorobanrpc.GetNetworkResponse;
import org.stellar.sdk.responses.sorobanrpc.GetTransactionResponse;
import org.stellar.sdk.responses.sorobanrpc.GetTransactionsResponse;
import org.stellar.sdk.responses.sorobanrpc.GetVersionInfoResponse;
import org.stellar.sdk.responses.sorobanrpc.SendTransactionResponse;
Expand Down Expand Up @@ -500,7 +501,10 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest)

HttpUrl baseUrl = mockWebServer.url("");
SorobanServer server = new SorobanServer(baseUrl.toString());
server.getTransaction(hash);
GetTransactionResponse tx = server.getTransaction(hash);
assertEquals(tx.getStatus(), GetTransactionResponse.GetTransactionStatus.SUCCESS);
assertEquals(
tx.getTxHash(), "8faa3e6bb29d9d8469bbcabdbfd800f3be1899f4736a3a2fa83cd58617c072fe");

server.close();
mockWebServer.close();
Expand Down Expand Up @@ -552,6 +556,9 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest)
assertEquals(
resp.getTransactions().get(0).getStatus(),
GetTransactionsResponse.TransactionStatus.FAILED);
assertEquals(
resp.getTransactions().get(0).getTxHash(),
"171359fff0edbf0a9d9d11014d0407486ff9f6a6e8f7673f97244acccb355b2d");
assertEquals(resp.getTransactions().get(0).getApplicationOrder().longValue(), 1L);
assertEquals(resp.getTransactions().get(0).getFeeBump(), false);
assertEquals(
Expand All @@ -569,6 +576,9 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest)
assertEquals(
resp.getTransactions().get(3).getStatus(),
GetTransactionsResponse.TransactionStatus.SUCCESS);
assertEquals(
resp.getTransactions().get(0).getTxHash(),
"171359fff0edbf0a9d9d11014d0407486ff9f6a6e8f7673f97244acccb355b2d");
assertEquals(resp.getTransactions().get(3).getApplicationOrder().longValue(), 4L);
assertEquals(resp.getTransactions().get(3).getFeeBump(), false);
assertEquals(
Expand Down Expand Up @@ -642,6 +652,7 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest)
SorobanServer server = new SorobanServer(baseUrl.toString());
GetEventsResponse resp = server.getEvents(getEventsRequest);
assertEquals(resp.getLatestLedger().longValue(), 187L);
assertEquals(resp.getCursor(), "0000000468151439360-0000000000");
assertEquals(resp.getEvents().size(), 2);
assertEquals(resp.getEvents().get(0).getType(), EventFilterType.CONTRACT);
assertEquals(resp.getEvents().get(0).getLedger().longValue(), 107L);
Expand All @@ -650,7 +661,6 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest)
resp.getEvents().get(0).getContractId(),
"CBQHNAXSI55GX2GN6D67GK7BHVPSLJUGZQEU7WJ5LKR5PNUCGLIMAO4K");
assertEquals(resp.getEvents().get(0).getId(), "0000000459561504768-0000000000");
assertEquals(resp.getEvents().get(0).getPagingToken(), "0000000459561504768-0000000000");
assertEquals(resp.getEvents().get(0).getTopic().size(), 2);
assertEquals(resp.getEvents().get(0).getTopic().get(0), "AAAADwAAAAdDT1VOVEVSAA==");
assertEquals(resp.getEvents().get(0).getTopic().get(1), "AAAADwAAAAlpbmNyZW1lbnQAAAA=");
Expand Down Expand Up @@ -826,8 +836,6 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest)
resp.getResults().get(0).getAuth().get(0),
"AAAAAAAAAAAAAAAB6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA");
assertEquals(resp.getResults().get(0).getXdr(), "AAAAAwAAABQ=");
assertEquals(resp.getCost().getCpuInstructions().longValue(), 1646885L);
assertEquals(resp.getCost().getMemoryBytes().longValue(), 1296481L);
assertEquals(resp.getStateChanges().size(), 1);
assertEquals(resp.getStateChanges().get(0).getType(), "created");
assertEquals(
Expand Down Expand Up @@ -902,8 +910,6 @@ public MockResponse dispatch(@NotNull RecordedRequest recordedRequest)
resp.getResults().get(0).getAuth().get(0),
"AAAAAAAAAAAAAAAB6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA");
assertEquals(resp.getResults().get(0).getXdr(), "AAAAAwAAABQ=");
assertEquals(resp.getCost().getCpuInstructions().longValue(), 1646885L);
assertEquals(resp.getCost().getMemoryBytes().longValue(), 1296481L);
server.close();
mockWebServer.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ public void testDeserialize() throws IOException {
"USDC_GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN_credit_alphanum4");
assertEquals(
assetResponse.getContractId(), "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75");
assertEquals(assetResponse.getNumAccounts().intValue(), 918786);
assertEquals(assetResponse.getNumClaimableBalances().intValue(), 415);
assertEquals(assetResponse.getNumLiquidityPools().intValue(), 384);
assertEquals(assetResponse.getNumContracts().intValue(), 24);
assertEquals(assetResponse.getNumArchivedContracts().intValue(), 1);
assertEquals(assetResponse.getAmount(), "196141192.6091517");
assertEquals(assetResponse.getAccounts().getAuthorized().intValue(), 918786);
assertEquals(assetResponse.getAccounts().getAuthorizedToMaintainLiabilities().intValue(), 0);
assertEquals(assetResponse.getAccounts().getUnauthorized().intValue(), 0);
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/org/stellar/sdk/responses/PagesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public void testAssets() throws IOException {
TypeToken<Page<AssetResponse>> type = new TypeToken<Page<AssetResponse>>() {};
Page<AssetResponse> page = GsonSingleton.getInstance().fromJson(json, type.getType());
assertEquals(3, page.getRecords().size());
assertEquals(25, page.getRecords().get(0).getNumAccounts().intValue());
assertEquals(1, page.getRecords().get(1).getNumAccounts().intValue());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ public void testDeserialize() throws IOException {
.fromJson(json, new TypeToken<SorobanRpcResponse<GetEventsResponse>>() {}.getType());
assertEquals(getEventsResponse.getResult().getLatestLedger().longValue(), 169L);
assertEquals(getEventsResponse.getResult().getEvents().size(), 3);
assertEquals(getEventsResponse.getResult().getCursor(), "0000000463856472064-0000000000");

GetEventsResponse.EventInfo eventInfo0 = getEventsResponse.getResult().getEvents().get(0);
assertEquals(eventInfo0.getType(), EventFilterType.CONTRACT);
assertEquals(eventInfo0.getLedger().intValue(), 108);
assertEquals(eventInfo0.getLedgerClosedAt(), "2023-07-23T14:47:01Z");
assertEquals(
eventInfo0.getContractId(), "CBQHNAXSI55GX2GN6D67GK7BHVPSLJUGZQEU7WJ5LKR5PNUCGLIMAO4K");
assertEquals(eventInfo0.getId(), "0000000463856472064-0000000000");
assertEquals(eventInfo0.getPagingToken(), "0000000463856472064-0000000000");
assertEquals(eventInfo0.getTopic().size(), 2);
assertEquals(eventInfo0.getTopic().get(0), "AAAADwAAAAdDT1VOVEVSAA==");
assertEquals(eventInfo0.getTopic().get(1), "AAAADwAAAAlpbmNyZW1lbnQAAAA=");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public void testDeserializeSuccess() throws IOException {
assertEquals(
getTransactionResponse.getResult().getStatus(),
GetTransactionResponse.GetTransactionStatus.SUCCESS);
assertEquals(
getTransactionResponse.getResult().getTxHash(),
"171359fff0edbf0a9d9d11014d0407486ff9f6a6e8f7673f97244acccb355b2d");
assertEquals(getTransactionResponse.getResult().getLatestLedger().longValue(), 79289L);
assertEquals(
getTransactionResponse.getResult().getLatestLedgerCloseTime().longValue(), 1690387240L);
Expand Down Expand Up @@ -66,6 +69,9 @@ public void testDeserializeFailed() throws IOException {
assertEquals(
getTransactionResponse.getResult().getStatus(),
GetTransactionResponse.GetTransactionStatus.FAILED);
assertEquals(
getTransactionResponse.getResult().getTxHash(),
"171359fff0edbf0a9d9d11014d0407486ff9f6a6e8f7673f97244acccb355b2d");
assertEquals(getTransactionResponse.getResult().getLatestLedger().longValue(), 79289L);
assertEquals(
getTransactionResponse.getResult().getLatestLedgerCloseTime().longValue(), 1690387240L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public void testDeserialize() throws IOException {
assertEquals(
getTransactionsResponse.getTransactions().get(0).getStatus(),
GetTransactionsResponse.TransactionStatus.FAILED);
assertEquals(
getTransactionsResponse.getTransactions().get(0).getTxHash(),
"171359fff0edbf0a9d9d11014d0407486ff9f6a6e8f7673f97244acccb355b2d");

assertEquals(
getTransactionsResponse.getTransactions().get(0).getApplicationOrder().longValue(), 1L);
assertEquals(getTransactionsResponse.getTransactions().get(0).getFeeBump(), false);
Expand All @@ -51,6 +55,9 @@ public void testDeserialize() throws IOException {
assertEquals(
getTransactionsResponse.getTransactions().get(3).getStatus(),
GetTransactionsResponse.TransactionStatus.SUCCESS);
assertEquals(
getTransactionsResponse.getTransactions().get(3).getTxHash(),
"8faa3e6bb29d9d8469bbcabdbfd800f3be1899f4736a3a2fa83cd58617c072fe");
assertEquals(
getTransactionsResponse.getTransactions().get(3).getApplicationOrder().longValue(), 4L);
assertEquals(getTransactionsResponse.getTransactions().get(3).getFeeBump(), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public void testDeserializeSuccess() throws IOException {
data.getResults().get(0).getAuth().get(0),
"AAAAAAAAAAAAAAAB6bfni71JNBarlvcR3WP2056a8vvFXQ0/CGfiBeDQA/wAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA");
assertEquals(data.getResults().get(0).getXdr(), "AAAAAwAAAAo=");
assertEquals(data.getCost().getCpuInstructions().longValue(), 1274180L);
assertEquals(data.getCost().getMemoryBytes().longValue(), 162857L);
assertEquals(data.getStateChanges().size(), 1);
assertEquals(data.getStateChanges().get(0).getType(), "created");
assertEquals(
Expand Down Expand Up @@ -85,8 +83,6 @@ public void testDeserializeFailed() throws IOException {
assertEquals(data.getTransactionData(), "");
assertNull(data.getEvents());
assertEquals(data.getMinResourceFee().longValue(), 0L);
assertEquals(data.getCost().getCpuInstructions().longValue(), 0L);
assertEquals(data.getCost().getMemoryBytes().longValue(), 0L);
assertEquals(data.getLatestLedger().longValue(), 898L);
assertNull(data.parseTransactionData());
assertNull(data.parseEvents());
Expand Down
2 changes: 0 additions & 2 deletions src/test/resources/responses/asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
"asset_issuer": "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
"paging_token": "USDC_GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN_credit_alphanum4",
"contract_id": "CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75",
"num_accounts": 918786,
"num_claimable_balances": 415,
"num_liquidity_pools": 384,
"num_contracts": 24,
"num_archived_contracts": 1,
"amount": "196141192.6091517",
"accounts": {
"authorized": 918786,
"authorized_to_maintain_liabilities": 0,
Expand Down
6 changes: 0 additions & 6 deletions src/test/resources/responses/pages/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
"asset_code": "0",
"asset_issuer": "GBBJZOYEGLOCW32Q4ZGWRWQ7UKIGMMIQXIRBBBOVJVFJTZW7CR2VQKAT",
"paging_token": "0_GBBJZOYEGLOCW32Q4ZGWRWQ7UKIGMMIQXIRBBBOVJVFJTZW7CR2VQKAT_credit_alphanum4",
"num_accounts": 25,
"num_claimable_balances": 0,
"num_liquidity_pools": 0,
"num_contracts": 0,
"num_archived_contracts": 0,
"amount": "988.9481303",
"accounts": {
"authorized": 25,
"authorized_to_maintain_liabilities": 0,
Expand Down Expand Up @@ -59,12 +57,10 @@
"asset_code": "0",
"asset_issuer": "GCKHHE33Q64N7NVM2AEWLWK4T55VPZBFQ5WNU7E3TNO6LTGM6JR3GJGG",
"paging_token": "0_GCKHHE33Q64N7NVM2AEWLWK4T55VPZBFQ5WNU7E3TNO6LTGM6JR3GJGG_credit_alphanum4",
"num_accounts": 1,
"num_claimable_balances": 0,
"num_liquidity_pools": 0,
"num_contracts": 0,
"num_archived_contracts": 0,
"amount": "0.0000001",
"accounts": {
"authorized": 1,
"authorized_to_maintain_liabilities": 0,
Expand Down Expand Up @@ -96,12 +92,10 @@
"asset_code": "0",
"asset_issuer": "GD3OJBRBHR77ZCRCK5I7LNKHMWN4RYLEAUJ3EROF4PYO6FZZOQBCDION",
"paging_token": "0_GD3OJBRBHR77ZCRCK5I7LNKHMWN4RYLEAUJ3EROF4PYO6FZZOQBCDION_credit_alphanum4",
"num_accounts": 1,
"num_claimable_balances": 0,
"num_liquidity_pools": 0,
"num_contracts": 0,
"num_archived_contracts": 0,
"amount": "0.0000001",
"accounts": {
"authorized": 1,
"authorized_to_maintain_liabilities": 0,
Expand Down
6 changes: 2 additions & 4 deletions src/test/resources/responses/sorobanrpc/get_events.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"ledgerClosedAt": "2023-07-23T14:47:01Z",
"contractId": "CBQHNAXSI55GX2GN6D67GK7BHVPSLJUGZQEU7WJ5LKR5PNUCGLIMAO4K",
"id": "0000000463856472064-0000000000",
"pagingToken": "0000000463856472064-0000000000",
"topic": [
"AAAADwAAAAdDT1VOVEVSAA==",
"AAAADwAAAAlpbmNyZW1lbnQAAAA="
Expand All @@ -24,7 +23,6 @@
"ledgerClosedAt": "2023-07-23T14:47:04Z",
"contractId": "CBQHNAXSI55GX2GN6D67GK7BHVPSLJUGZQEU7WJ5LKR5PNUCGLIMAO4K",
"id": "0000000476741373952-0000000000",
"pagingToken": "0000000476741373952-0000000000",
"topic": [
"AAAADwAAAAdDT1VOVEVSAA==",
"AAAADwAAAAlpbmNyZW1lbnQAAAA="
Expand All @@ -39,7 +37,6 @@
"ledgerClosedAt": "2023-07-23T14:47:07Z",
"contractId": "CBQHNAXSI55GX2GN6D67GK7BHVPSLJUGZQEU7WJ5LKR5PNUCGLIMAO4K",
"id": "0000000489626275840-0000000000",
"pagingToken": "0000000489626275840-0000000000",
"topic": [
"AAAADwAAAAdDT1VOVEVSAA==",
"AAAADwAAAAlpbmNyZW1lbnQAAAA="
Expand All @@ -49,6 +46,7 @@
"txHash": "db86e94aa98b7d38213c041ebbb727fbaabf0b7c435de594f36c2d51fc61926d"
}
],
"latestLedger": "169"
"latestLedger": "169",
"cursor": "0000000463856472064-0000000000"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"id": "198cb1a8-9104-4446-a269-88bf000c2721",
"result": {
"status": "FAILED",
"txHash": "171359fff0edbf0a9d9d11014d0407486ff9f6a6e8f7673f97244acccb355b2d",
"latestLedger": "79289",
"latestLedgerCloseTime": "1690387240",
"oldestLedger": "77850",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"id": "198cb1a8-9104-4446-a269-88bf000c2721",
"result": {
"status": "SUCCESS",
"txHash": "171359fff0edbf0a9d9d11014d0407486ff9f6a6e8f7673f97244acccb355b2d",
"latestLedger": "79289",
"latestLedgerCloseTime": "1690387240",
"oldestLedger": "77850",
Expand Down
Loading

0 comments on commit 314406f

Please sign in to comment.