public class SorobanServer
extends java.lang.Object
implements java.io.Closeable
Modifier and Type | Class and Description |
---|---|
static class |
SorobanServer.Durability
Represents the "durability keyspace" that this ledger key belongs to, check
getContractData(java.lang.String, org.stellar.sdk.xdr.SCVal, org.stellar.sdk.SorobanServer.Durability) for more details. |
static interface |
SorobanServer.SleepStrategy
Strategy for sleeping between retries in a retry loop.
|
Constructor and Description |
---|
SorobanServer(java.lang.String serverURI)
Creates a new SorobanServer instance.
|
SorobanServer(java.lang.String serverURI,
okhttp3.OkHttpClient httpClient)
Creates a new SorobanServer instance.
|
Modifier and Type | Method and Description |
---|---|
static Transaction |
assembleTransaction(Transaction transaction,
SimulateTransactionResponse simulateTransactionResponse) |
void |
close() |
TransactionBuilderAccount |
getAccount(java.lang.String address)
Fetch a minimal set of current info about a Stellar account.
|
java.util.Optional<GetLedgerEntriesResponse.LedgerEntryResult> |
getContractData(java.lang.String contractId,
SCVal key,
SorobanServer.Durability durability)
Reads the current value of contract data ledger entries directly.
|
GetEventsResponse |
getEvents(GetEventsRequest getEventsRequest)
Fetches all events that match the given
GetEventsRequest . |
GetFeeStatsResponse |
getFeeStats()
Get statistics for charged inclusion fees.
|
GetHealthResponse |
getHealth()
General node health check.
|
GetLatestLedgerResponse |
getLatestLedger()
Fetches the latest ledger meta info from network which Soroban-RPC is connected to.
|
GetLedgerEntriesResponse |
getLedgerEntries(java.util.Collection<LedgerKey> keys)
Reads the current value of ledger entries directly.
|
GetLedgersResponse |
getLedgers(GetLedgersRequest getLedgersRequest)
Gets a detailed list of ledgers starting from the user specified starting point that you can
paginate as long as the pages fall within the history retention of their corresponding RPC
provider.
|
GetNetworkResponse |
getNetwork()
Fetches metadata about the network which Soroban-RPC is connected to.
|
GetSACBalanceResponse |
getSACBalance(java.lang.String contractId,
Asset asset,
Network network)
Fetches the balance of a specific asset for a contract.
|
GetTransactionResponse |
getTransaction(java.lang.String hash)
Fetch the details of a submitted transaction.
|
GetTransactionsResponse |
getTransactions(GetTransactionsRequest getTransactionsRequest)
Gets a detailed list of transactions starting from the user specified starting point that you
can paginate as long as the pages fall within the history retention of their corresponding RPC
provider.
|
GetVersionInfoResponse |
getVersionInfo()
Fetches version information about the RPC and Captive core.
|
GetTransactionResponse |
pollTransaction(java.lang.String hash)
An alias for
pollTransaction(String, int, SleepStrategy) with default parameters,
which maxAttempts is set to 30, and the sleep strategy is set to a default strategy
that sleeps for 1 second between attempts. |
GetTransactionResponse |
pollTransaction(java.lang.String hash,
int maxAttempts,
SorobanServer.SleepStrategy sleepStrategy)
Polls the transaction status until it is completed or the maximum number of attempts is
reached.
|
Transaction |
prepareTransaction(Transaction transaction)
Submit a trial contract invocation, first run a simulation of the contract invocation as
defined on the incoming transaction, and apply the results to a new copy of the transaction
which is then returned.
|
Transaction |
prepareTransaction(Transaction transaction,
SimulateTransactionResponse simulateTransactionResponse)
Prepare the transaction using the simulateTransaction obtained by the user in advance, apply
the simulateTransaction results to a new copy of the transaction which is then returned.
|
SendTransactionResponse |
sendTransaction(Transaction transaction)
Submit a real transaction to the Stellar network.
|
SimulateTransactionResponse |
simulateTransaction(Transaction transaction)
An alias for
simulateTransaction(Transaction,
SimulateTransactionRequest.ResourceConfig, SimulateTransactionRequest.AuthMode) with no
resource leeway, and no auth mode set. |
SimulateTransactionResponse |
simulateTransaction(Transaction transaction,
SimulateTransactionRequest.ResourceConfig resourceConfig,
SimulateTransactionRequest.AuthMode authMode)
Submit a trial contract invocation to get back return values, expected ledger footprint,
expected authorizations, and expected costs.
|
public SorobanServer(java.lang.String serverURI)
serverURI
- The URI of the Soroban-RPC instance to connect to.public SorobanServer(java.lang.String serverURI, okhttp3.OkHttpClient httpClient)
serverURI
- The URI of the Soroban-RPC instance to connect to.httpClient
- The OkHttpClient
instance to use for requests.public TransactionBuilderAccount getAccount(java.lang.String address)
TransactionBuilder
.address
- The address of the account to load, muxed accounts are supported.Account
object containing the sequence number and current state of the
account.NetworkException
- All the exceptions below are subclasses of
NetworkErrorAccountNotFoundException
- If the account does not exist on the network. You may need to
fund it first.SorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public GetHealthResponse getHealth()
GetHealthResponse
object containing the health check result.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public GetFeeStatsResponse getFeeStats()
GetFeeStatsResponse
object containing the fee stats.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public java.util.Optional<GetLedgerEntriesResponse.LedgerEntryResult> getContractData(java.lang.String contractId, SCVal key, SorobanServer.Durability durability)
contractId
- The contract ID containing the data to load. Encoded as Stellar Contract
Address. e.g. "CCJZ5DGASBWQXR5MPFCJXMBI333XE5U3FSJTNQU7RIKE3P5GN2K2WYD5"key
- The key of the contract data to load.durability
- The "durability keyspace" that this ledger key belongs to, which is either
SorobanServer.Durability.TEMPORARY
or SorobanServer.Durability.PERSISTENT
.GetLedgerEntriesResponse.LedgerEntryResult
object containing the ledger entry
result.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public GetLedgerEntriesResponse getLedgerEntries(java.util.Collection<LedgerKey> keys)
Allows you to directly inspect the current state of contracts, contract's code, or any other ledger entries.
keys
- The key of the contract data to load, at least one key must be provided.GetLedgerEntriesResponse
object containing the current values.java.lang.IllegalArgumentException
- If the keys collection is empty or invalid.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public GetTransactionResponse getTransaction(java.lang.String hash)
When submitting a transaction, client should poll this to tell when the transaction has completed.
hash
- The hash of the transaction to check. Encoded as a hex string.GetTransactionResponse
object containing the transaction status, result, and
other details.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public GetTransactionResponse pollTransaction(java.lang.String hash) throws java.lang.InterruptedException
pollTransaction(String, int, SleepStrategy)
with default parameters,
which maxAttempts
is set to 30, and the sleep strategy is set to a default strategy
that sleeps for 1 second between attempts.hash
- The hash of the transaction to poll for.GetTransactionResponse
object after a "found" response, (which may be success
or failure) or the last response obtained after polling the maximum number of specified
attempts.java.lang.InterruptedException
- If the thread is interrupted while sleeping between attempts.public GetTransactionResponse pollTransaction(java.lang.String hash, int maxAttempts, SorobanServer.SleepStrategy sleepStrategy) throws java.lang.InterruptedException
After submitting a transaction, clients can use this to poll for transaction completion and return a definitive state of success or failure.
hash
- The hash of the transaction to poll for.maxAttempts
- The number of attempts to make before returning the last-seen status.sleepStrategy
- A strategy to determine the sleep duration between attempts. It should
take the current attempt number and return the sleep duration in milliseconds.GetTransactionResponse
object after a "found" response, (which may be success
or failure) or the last response obtained after polling the maximum number of specified
attempts.java.lang.IllegalArgumentException
- If maxAttempts is less than or equal to 0.java.lang.InterruptedException
- If the thread is interrupted while sleeping between attempts.public GetTransactionsResponse getTransactions(GetTransactionsRequest getTransactionsRequest)
getTransactionsRequest
- The GetTransactionsRequest
to use for the request.GetTransactionsResponse
object containing the transactions that match the
request.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public GetLedgersResponse getLedgers(GetLedgersRequest getLedgersRequest)
getLedgersRequest
- The GetLedgersRequest
to use for the request.GetLedgersResponse
object containing the ledgers that match the request.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public GetEventsResponse getEvents(GetEventsRequest getEventsRequest)
GetEventsRequest
.getEventsRequest
- The GetEventsRequest
to use for the request.GetEventsResponse
object containing the events that match the request.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public GetVersionInfoResponse getVersionInfo()
GetVersionInfoResponse
object containing the version information.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public GetNetworkResponse getNetwork()
GetNetworkResponse
object containing the network metadata.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public GetLatestLedgerResponse getLatestLedger()
GetLatestLedgerResponse
object containing the latest ledger meta info.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public SimulateTransactionResponse simulateTransaction(Transaction transaction, @Nullable SimulateTransactionRequest.ResourceConfig resourceConfig, @Nullable SimulateTransactionRequest.AuthMode authMode)
transaction
- The transaction to simulate. It should include exactly one operation, which
must be one of InvokeHostFunctionOperation
, ExtendFootprintTTLOperation
, or RestoreFootprintOperation
. Any provided footprint will be
ignored.resourceConfig
- Additional resource include in the simulation.authMode
- Explicitly allows users to opt-in to non-root authorization in recording mode.SimulateTransactionResponse
object containing the cost, footprint,
result/auth requirements (if applicable), and error of the transaction.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public SimulateTransactionResponse simulateTransaction(Transaction transaction)
simulateTransaction(Transaction,
SimulateTransactionRequest.ResourceConfig, SimulateTransactionRequest.AuthMode)
with no
resource leeway, and no auth mode set.public Transaction prepareTransaction(Transaction transaction)
The returned transaction will also have an updated fee that is the sum of fee set on incoming transaction with the contract resource fees estimated from simulation. It is advisable to check the fee on returned transaction and validate or take appropriate measures for interaction with user to confirm it is acceptable.
You can call the simulateTransaction(org.stellar.sdk.Transaction, org.stellar.sdk.requests.sorobanrpc.SimulateTransactionRequest.ResourceConfig, org.stellar.sdk.requests.sorobanrpc.SimulateTransactionRequest.AuthMode)
method directly first if you want
to inspect estimated fees for a given transaction in detail first, if that is of importance.
transaction
- The transaction to prepare. It should include exactly one operation, which
must be one of InvokeHostFunctionOperation
, ExtendFootprintTTLOperation
, or RestoreFootprintOperation
. Any provided footprint will be
ignored. You can use Transaction.isSorobanTransaction()
to check if a transaction
is a Soroban transaction. Any provided footprint will be overwritten. However, if your
operation has existing auth entries, they will be preferred over ALL auth entries from the
simulation. In other words, if you include auth entries, you don't care about the auth
returned from the simulation. Other fields (footprint, etc.) will be filled as normal.Transaction
, with the expected authorizations (in the
case of invocation) and ledger footprint added. The transaction fee will also automatically
be padded with the contract's minimum resource fees discovered from the simulation.PrepareTransactionException
- If preparing the transaction fails.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public Transaction prepareTransaction(Transaction transaction, SimulateTransactionResponse simulateTransactionResponse)
The returned transaction will also have an updated fee that is the sum of fee set on incoming transaction with the contract resource fees estimated from simulation. It is advisable to check the fee on returned transaction and validate or take appropriate measures for interaction with user to confirm it is acceptable.
transaction
- The transaction to prepare. It should include exactly one operation, which
must be one of InvokeHostFunctionOperation
, ExtendFootprintTTLOperation
, or RestoreFootprintOperation
. Any provided footprint will be
ignored. You can use Transaction.isSorobanTransaction()
to check if a transaction
is a Soroban transaction. Any provided footprint will be overwritten. However, if your
operation has existing auth entries, they will be preferred over ALL auth entries from the
simulation. In other words, if you include auth entries, you don't care about the auth
returned from the simulation. Other fields (footprint, etc.) will be filled as normal.simulateTransactionResponse
- The SimulateTransactionResponse
to use for preparing
the transaction.Transaction
, with the expected authorizations (in the
case of invocation) and ledger footprint added. The transaction fee will also automatically
be padded with the contract's minimum resource fees discovered from the simulation.PrepareTransactionException
- If preparing the transaction fails.public SendTransactionResponse sendTransaction(Transaction transaction)
getTransaction(java.lang.String)
to learn about transaction's status.transaction
- The transaction to submit.SendTransactionResponse
object containing some details about the transaction
that was submitted.NetworkException
- All the exceptions below are subclasses of
NetworkErrorSorobanRpcException
- If the Soroban-RPC instance returns an error response.RequestTimeoutException
- If the request timed out.ConnectionErrorException
- When the request cannot be executed due to cancellation or
connectivity problems, etc.public GetSACBalanceResponse getSACBalance(java.lang.String contractId, Asset asset, Network network)
contractId
- The contract ID containing the asset balance. Encoded as Stellar Contract
Address. e.g. CAB...asset
- The asset to check the balance for. This should be a valid asset object.network
- The network to use for the asset.GetSACBalanceResponse
which will contain the balance entry details if and
only if the request returned a valid balance ledger entry. If it doesn't, the balanceEntry
field will not exist.public static Transaction assembleTransaction(Transaction transaction, SimulateTransactionResponse simulateTransactionResponse)
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException