-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for calling Soroban RPC server. (#492)
- Loading branch information
Showing
34 changed files
with
3,169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/org/stellar/sdk/AccountNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.stellar.sdk; | ||
|
||
import lombok.Getter; | ||
|
||
/** Exception thrown when trying to load an account that doesn't exist on the Stellar network. */ | ||
@Getter | ||
public class AccountNotFoundException extends Exception { | ||
// The account that was not found. | ||
private final String accountId; | ||
|
||
public AccountNotFoundException(String accountId) { | ||
super("Account not found, accountId: " + accountId); | ||
this.accountId = accountId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/org/stellar/sdk/PrepareTransactionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.stellar.sdk; | ||
|
||
import lombok.Getter; | ||
import org.stellar.sdk.responses.sorobanrpc.SimulateTransactionResponse; | ||
|
||
/** Exception thrown when preparing a transaction failed. */ | ||
@Getter | ||
public class PrepareTransactionException extends Exception { | ||
// The response returned by the Soroban-RPC instance when simulating the transaction. | ||
private final SimulateTransactionResponse simulateTransactionResponse; | ||
|
||
public PrepareTransactionException( | ||
String message, SimulateTransactionResponse simulateTransactionResponse) { | ||
super(message); | ||
this.simulateTransactionResponse = simulateTransactionResponse; | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/org/stellar/sdk/requests/sorobanrpc/EventFilterType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.stellar.sdk.requests.sorobanrpc; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
/** Represents the type of event. */ | ||
public enum EventFilterType { | ||
@SerializedName("system") | ||
SYSTEM, | ||
@SerializedName("contract") | ||
CONTRACT, | ||
@SerializedName("diagnostic") | ||
DIAGNOSTIC | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/org/stellar/sdk/requests/sorobanrpc/GetEventsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.stellar.sdk.requests.sorobanrpc; | ||
|
||
import java.util.Collection; | ||
import lombok.Builder; | ||
import lombok.NonNull; | ||
import lombok.Singular; | ||
import lombok.Value; | ||
|
||
/** | ||
* Request for JSON-RPC method getEvents. | ||
* | ||
* @see <a href="https://soroban.stellar.org/api/methods/getEvents#parameters" | ||
* target="_blank">getEvents documentation</a> | ||
*/ | ||
@Value | ||
@Builder(toBuilder = true) | ||
public class GetEventsRequest { | ||
@NonNull String startLedger; | ||
|
||
@Singular("filter") | ||
Collection<EventFilter> filters; | ||
|
||
PaginationOptions pagination; | ||
|
||
@Value | ||
@Builder(toBuilder = true) | ||
public static class PaginationOptions { | ||
Long limit; | ||
|
||
String cursor; | ||
} | ||
|
||
@Builder(toBuilder = true) | ||
@Value | ||
public static class EventFilter { | ||
EventFilterType type; | ||
|
||
Collection<String> contractIds; | ||
|
||
@Singular("topic") | ||
Collection<Collection<String>> topics; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/stellar/sdk/requests/sorobanrpc/GetLedgerEntriesRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.stellar.sdk.requests.sorobanrpc; | ||
|
||
import java.util.Collection; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Value; | ||
|
||
/** | ||
* Request for JSON-RPC method getLedgerEntries. | ||
* | ||
* @see <a href="https://soroban.stellar.org/api/methods/getLedgerEntries#parameters" | ||
* target="_blank">getLedgerEntries documentation</a> | ||
*/ | ||
@AllArgsConstructor | ||
@Value | ||
public class GetLedgerEntriesRequest { | ||
Collection<String> keys; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/stellar/sdk/requests/sorobanrpc/GetTransactionRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.stellar.sdk.requests.sorobanrpc; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Value; | ||
|
||
/** | ||
* Request for JSON-RPC method getTransaction. | ||
* | ||
* @see <a href="https://soroban.stellar.org/api/methods/getTransaction#parameters" | ||
* target="_blank">getTransaction documentation</a> | ||
*/ | ||
@Value | ||
@AllArgsConstructor | ||
public class GetTransactionRequest { | ||
String hash; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/stellar/sdk/requests/sorobanrpc/SendTransactionRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.stellar.sdk.requests.sorobanrpc; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Value; | ||
|
||
/** | ||
* Request for JSON-RPC method sendTransaction. | ||
* | ||
* @see <a href="https://soroban.stellar.org/api/methods/sendTransaction#parameters" | ||
* target="_blank">sendTransaction documentation</a> | ||
*/ | ||
@AllArgsConstructor | ||
@Value | ||
public class SendTransactionRequest { | ||
String transaction; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/stellar/sdk/requests/sorobanrpc/SimulateTransactionRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.stellar.sdk.requests.sorobanrpc; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Value; | ||
|
||
/** | ||
* Request for JSON-RPC method simulateTransaction. | ||
* | ||
* @see <a href="https://soroban.stellar.org/api/methods/simulateTransaction#parameters" | ||
* target="_blank">simulateTransaction documentation</a> | ||
*/ | ||
@AllArgsConstructor | ||
@Value | ||
public class SimulateTransactionRequest { | ||
String transaction; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/stellar/sdk/requests/sorobanrpc/SorobanRpcErrorResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.stellar.sdk.requests.sorobanrpc; | ||
|
||
import lombok.Getter; | ||
|
||
/** | ||
* Throws when Soroban-RPC instance responds with error. | ||
* | ||
* @see <a href="https://www.jsonrpc.org/specification#error_object" target="_blank">JSON-RPC 2.0 | ||
* Specification - Error object<a> | ||
*/ | ||
@Getter | ||
public class SorobanRpcErrorResponse extends Exception { | ||
private final Integer code; | ||
|
||
private final String message; | ||
|
||
private final String data; | ||
|
||
public SorobanRpcErrorResponse(Integer code, String message, String data) { | ||
super(message); | ||
this.code = code; | ||
this.message = message; | ||
this.data = data; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/stellar/sdk/requests/sorobanrpc/SorobanRpcRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.stellar.sdk.requests.sorobanrpc; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Value; | ||
|
||
/** | ||
* Represent the request sent to Soroban-RPC. | ||
* | ||
* @see <a href="https://www.jsonrpc.org/specification#request_object" target="_blank">JSON-RPC 2.0 | ||
* Specification - Request object<a> | ||
*/ | ||
@RequiredArgsConstructor | ||
@Value | ||
public class SorobanRpcRequest<T> { | ||
@SerializedName("jsonrpc") | ||
String jsonRpc = "2.0"; | ||
|
||
String id; | ||
|
||
String method; | ||
|
||
T params; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/org/stellar/sdk/responses/sorobanrpc/GetEventsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.stellar.sdk.responses.sorobanrpc; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Value; | ||
import org.stellar.sdk.requests.sorobanrpc.EventFilterType; | ||
|
||
/** | ||
* Response for JSON-RPC method getEvents. | ||
* | ||
* @see <a href="https://soroban.stellar.org/api/methods/getEvents#returns" | ||
* target="_blank">getEvents documentation</a> | ||
*/ | ||
@AllArgsConstructor | ||
@Value | ||
public class GetEventsResponse { | ||
ImmutableList<EventInfo> events; | ||
|
||
Long latestLedger; | ||
|
||
@AllArgsConstructor | ||
@Value | ||
public static class EventInfo { | ||
EventFilterType type; | ||
|
||
Integer ledger; | ||
|
||
String ledgerClosedAt; | ||
|
||
String contractId; | ||
|
||
String id; | ||
|
||
String pagingToken; | ||
|
||
ImmutableList<String> topic; | ||
|
||
EventInfoValue value; | ||
|
||
Boolean inSuccessfulContractCall; | ||
} | ||
|
||
@AllArgsConstructor | ||
@Value | ||
public static class EventInfoValue { | ||
String xdr; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/org/stellar/sdk/responses/sorobanrpc/GetHealthResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.stellar.sdk.responses.sorobanrpc; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Value; | ||
|
||
/** | ||
* Response for JSON-RPC method getHealth. | ||
* | ||
* @see <a href="https://soroban.stellar.org/api/methods/getHealth#returns" | ||
* target="_blank">getHealth documentation</a> | ||
*/ | ||
@AllArgsConstructor | ||
@Value | ||
public class GetHealthResponse { | ||
String status; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLatestLedgerResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.stellar.sdk.responses.sorobanrpc; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Value; | ||
|
||
/** | ||
* Response for JSON-RPC method getLatestLedger. | ||
* | ||
* @see <a href="https://soroban.stellar.org/api/methods/getLatestLedger#returns" | ||
* target="_blank">getLatestLedger documentation</a> | ||
*/ | ||
@AllArgsConstructor | ||
@Value | ||
public class GetLatestLedgerResponse { | ||
String id; | ||
|
||
Integer protocolVersion; | ||
|
||
Integer sequence; | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/org/stellar/sdk/responses/sorobanrpc/GetLedgerEntriesResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.stellar.sdk.responses.sorobanrpc; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.gson.annotations.SerializedName; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Value; | ||
|
||
/** | ||
* Response for JSON-RPC method getLedgerEntries. | ||
* | ||
* @see <a href="https://soroban.stellar.org/api/methods/getLedgerEntries#returns" | ||
* target="_blank">getLedgerEntries documentation</a> | ||
*/ | ||
@AllArgsConstructor | ||
@Value | ||
public class GetLedgerEntriesResponse { | ||
ImmutableList<LedgerEntryResult> entries; | ||
|
||
Long latestLedger; | ||
|
||
@AllArgsConstructor | ||
@Value | ||
public static class LedgerEntryResult { | ||
String key; | ||
|
||
String xdr; | ||
|
||
@SerializedName("lastModifiedLedgerSeq") | ||
Long lastModifiedLedger; | ||
} | ||
} |
Oops, something went wrong.