-
Notifications
You must be signed in to change notification settings - Fork 159
Add CheckStellarAssetContract example #688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CheckStellarAssetContract example #688
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:
|
| LedgerEntryData entryData = | ||
| LedgerEntryData.fromXdrBase64(response.getEntries().get(0).getXdr()); | ||
| if (entryData.getContractData() == null) return null; | ||
| return entryData.getContractData().getContract().getContractId().toXdrBase64(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| + assetUSDC | |
| + assetUnknown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
| } | ||
| } | ||
|
|
||
| public static String getContractData(SorobanServer sorobanServer, Asset asset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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();
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
f67e537 to
cea7361
Compare
Description
Context