Add CheckStellarAssetContract example#688
Merged
overcat merged 4 commits intoMay 23, 2025
Merged
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #688 +/- ##
=========================================
Coverage 80.18% 80.18%
Complexity 1227 1227
=========================================
Files 213 213
Lines 4820 4820
Branches 412 412
=========================================
Hits 3865 3865
Misses 703 703
Partials 252 252 🚀 New features to boost your workflow:
|
overcat
requested changes
May 21, 2025
| LedgerEntryData entryData = | ||
| LedgerEntryData.fromXdrBase64(response.getEntries().get(0).getXdr()); | ||
| if (entryData.getContractData() == null) return null; | ||
| return entryData.getContractData().getContract().getContractId().toXdrBase64(); |
Member
There was a problem hiding this comment.
The return here is a base64 character; returning the C... address would be better.
| + getContractData(sorobanServer, assetNative)); | ||
| System.out.println( | ||
| "The SAC ID of the asset [" | ||
| + assetUSDC |
Member
There was a problem hiding this comment.
Suggested change
| + assetUSDC | |
| + assetUnknown |
| } | ||
| } | ||
|
|
||
| public static String getContractData(SorobanServer sorobanServer, Asset asset) |
Member
There was a problem hiding this comment.
Would it be better to change this to boolean isContractDeployed(SorobanServer sorobanServer, String contractId)?
public class CheckStellarAssetContract {
public static void main(String[] args) throws IOException {
String rpcServerUrl = "https://soroban-testnet.stellar.org:443";
Network network = Network.TESTNET;
Asset assetNative = Asset.createNativeAsset();
Asset assetUSDC =
Asset.createNonNativeAsset(
"USDC", "GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP");
Asset assetUnknown =
Asset.createNonNativeAsset(
"UNKN", "GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP");
try (SorobanServer sorobanServer = new SorobanServer(rpcServerUrl)) {
for (Asset asset : List.of(assetNative, assetUSDC, assetUnknown)) {
String contractId = asset.getContractId(network);
System.out.printf(
"The contract id for %s is %s, it is %s\n",
asset,
contractId,
isContractDeployed(sorobanServer, contractId) ? "deployed" : "not deployed");
}
}
}
public static boolean isContractDeployed(SorobanServer sorobanServer, String contractId) {
List<LedgerKey> ledgerKeys =
List.of(
LedgerKey.builder()
.discriminant(LedgerEntryType.CONTRACT_DATA)
.contractData(
LedgerKeyContractData.builder()
.contract(new Address(contractId).toSCAddress())
.key(Scv.toLedgerKeyContractInstance())
.durability(ContractDataDurability.PERSISTENT)
.build())
.build());
GetLedgerEntriesResponse response = sorobanServer.getLedgerEntries(ledgerKeys);
return response.getEntries() != null && !response.getEntries().isEmpty();
}
}f67e537 to
cea7361
Compare
overcat
approved these changes
May 23, 2025
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Context