-
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.
Add GetLedgerEntries and refactor calling SorobanServer with Closeabl…
…e interface
- Loading branch information
Showing
3 changed files
with
191 additions
and
144 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
examples/src/main/java/network/lightsail/GetLedgerEntries.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 network.lightsail; | ||
|
||
import static org.stellar.sdk.responses.sorobanrpc.GetLedgerEntriesResponse.*; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.stellar.sdk.KeyPair; | ||
import org.stellar.sdk.SorobanServer; | ||
import org.stellar.sdk.responses.sorobanrpc.GetLedgerEntriesResponse; | ||
import org.stellar.sdk.xdr.LedgerEntry; | ||
import org.stellar.sdk.xdr.LedgerEntryType; | ||
import org.stellar.sdk.xdr.LedgerKey; | ||
import org.stellar.sdk.xdr.LedgerKey.LedgerKeyAccount; | ||
|
||
public class GetLedgerEntries { | ||
public static void main(String[] args) throws IOException { | ||
String rpcServerUrl = "https://soroban-testnet.stellar.org:443"; | ||
GetLedgerEntriesResponse response; | ||
try (SorobanServer sorobanServer = new SorobanServer(rpcServerUrl)) { | ||
KeyPair keyPair = | ||
KeyPair.fromAccountId("GDJLBYYKMCXNVVNABOE66NYXQGIA5AC5D223Z2KF6ZEYK4UBCA7FKLTG"); | ||
|
||
// Create ledger keys | ||
List<LedgerKey> ledgerKeys = | ||
Collections.singletonList( | ||
LedgerKey.builder() | ||
.account(LedgerKeyAccount.builder().accountID(keyPair.getXdrAccountId()).build()) | ||
.discriminant(LedgerEntryType.ACCOUNT) | ||
.build()); | ||
|
||
// Get ledger entries | ||
response = sorobanServer.getLedgerEntries(ledgerKeys); | ||
} | ||
|
||
// Print ledger entries | ||
for (LedgerEntryResult result : response.getEntries()) { | ||
LedgerEntry.LedgerEntryData ledgerEntryData = | ||
LedgerEntry.LedgerEntryData.fromXdrBase64(result.getXdr()); | ||
System.out.println(ledgerEntryData); | ||
} | ||
} | ||
} |
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
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