-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for Soroban PRC's
getTransactions
API.
- Loading branch information
Showing
4 changed files
with
326 additions
and
2 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
27 changes: 27 additions & 0 deletions
27
src/main/java/org/stellar/sdk/requests/sorobanrpc/GetTransactionsRequest.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,27 @@ | ||
package org.stellar.sdk.requests.sorobanrpc; | ||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
import lombok.Value; | ||
|
||
/** | ||
* Request for JSON-RPC method getTransactions. | ||
* | ||
* @see <a href="https://developers.stellar.org/docs/data/rpc/api-reference/methods/getTransactions" | ||
* target="_blank">getEvents documentation</a> | ||
*/ | ||
@Value | ||
@Builder(toBuilder = true) | ||
public class GetTransactionsRequest { | ||
@NonNull Long startLedger; | ||
|
||
PaginationOptions pagination; | ||
|
||
@Value | ||
@Builder(toBuilder = true) | ||
public static class PaginationOptions { | ||
Long limit; | ||
|
||
String cursor; | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/main/java/org/stellar/sdk/responses/sorobanrpc/GetTransactionsResponse.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,96 @@ | ||
package org.stellar.sdk.responses.sorobanrpc; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.Value; | ||
import org.stellar.sdk.Util; | ||
import org.stellar.sdk.xdr.DiagnosticEvent; | ||
import org.stellar.sdk.xdr.TransactionEnvelope; | ||
import org.stellar.sdk.xdr.TransactionMeta; | ||
import org.stellar.sdk.xdr.TransactionResult; | ||
|
||
/** | ||
* Response for JSON-RPC method getTransactions. | ||
* | ||
* @see <a href="https://developers.stellar.org/docs/data/rpc/api-reference/methods/getTransactions" | ||
* target="_blank">getTransactions documentation</a> | ||
*/ | ||
@Value | ||
public class GetTransactionsResponse { | ||
List<Transaction> transactions; | ||
Long latestLedger; | ||
Long latestLedgerCloseTimestamp; | ||
Long oldestLedger; | ||
Long oldestLedgerCloseTimestamp; | ||
String cursor; | ||
|
||
@Value | ||
public static class Transaction { | ||
TransactionStatus status; | ||
Integer applicationOrder; | ||
Boolean feeBump; | ||
|
||
/** The field can be parsed as {@link org.stellar.sdk.xdr.TransactionEnvelope} object. */ | ||
String envelopeXdr; | ||
|
||
/** The field can be parsed as {@link org.stellar.sdk.xdr.TransactionResult} object. */ | ||
String resultXdr; | ||
|
||
/** The field can be parsed as {@link org.stellar.sdk.xdr.TransactionMeta} object. */ | ||
String resultMetaXdr; | ||
|
||
Long ledger; | ||
Long createdAt; | ||
List<String> diagnosticEventsXdr; | ||
|
||
/** | ||
* Parses the {@code envelopeXdr} field from a string to an {@link | ||
* org.stellar.sdk.xdr.TransactionEnvelope} object. | ||
* | ||
* @return the parsed {@link org.stellar.sdk.xdr.TransactionEnvelope} object | ||
*/ | ||
public TransactionEnvelope parseEnvelopeXdr() { | ||
return Util.parseXdr(envelopeXdr, TransactionEnvelope::fromXdrBase64); | ||
} | ||
|
||
/** | ||
* Parses the {@code resultXdr} field from a string to an {@link | ||
* org.stellar.sdk.xdr.TransactionResult} object. | ||
* | ||
* @return the parsed {@link org.stellar.sdk.xdr.TransactionResult} object | ||
*/ | ||
public TransactionResult parseResultXdr() { | ||
return Util.parseXdr(resultXdr, TransactionResult::fromXdrBase64); | ||
} | ||
|
||
/** | ||
* Parses the {@code resultMetaXdr} field from a string to an {@link | ||
* org.stellar.sdk.xdr.TransactionMeta} object. | ||
* | ||
* @return the parsed {@link org.stellar.sdk.xdr.TransactionMeta} object | ||
*/ | ||
public TransactionMeta parseResultMetaXdr() { | ||
return Util.parseXdr(resultMetaXdr, TransactionMeta::fromXdrBase64); | ||
} | ||
|
||
/** | ||
* Parses the {@code diagnosticEventsXdr} field from a list of strings to a list of {@link | ||
* org.stellar.sdk.xdr.DiagnosticEvent} objects. | ||
* | ||
* @return a list of parsed {@link org.stellar.sdk.xdr.DiagnosticEvent} objects | ||
*/ | ||
public List<DiagnosticEvent> parseDiagnosticEventsXdr() { | ||
if (diagnosticEventsXdr == null) { | ||
return null; | ||
} | ||
return diagnosticEventsXdr.stream() | ||
.map(xdr -> Util.parseXdr(xdr, DiagnosticEvent::fromXdrBase64)) | ||
.collect(Collectors.toList()); | ||
} | ||
} | ||
|
||
public enum TransactionStatus { | ||
SUCCESS, | ||
FAILED | ||
} | ||
} |
Oops, something went wrong.