Skip to content

Commit fdb2789

Browse files
committed
Take care of PR comments
1 parent 42399ad commit fdb2789

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

examples/src/main/java/network/lightsail/CheckStellarAssetContract.java

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
import org.stellar.sdk.xdr.LedgerKey.LedgerKeyContractData;
1313

1414
/**
15-
* This example shows how to check the existence of the SAC (Stellar Asset Contract) of a class asset.
15+
* This example shows how to check the existence of the SAC (Stellar Asset Contract) of a class
16+
* asset.
1617
*/
1718
public class CheckStellarAssetContract {
1819
public static void main(String[] args) throws IOException {
1920
String rpcServerUrl = "https://soroban-testnet.stellar.org:443";
21+
Network network = Network.TESTNET;
2022
Asset assetNative = Asset.createNativeAsset();
2123
Asset assetUSDC =
2224
Asset.createNonNativeAsset(
@@ -26,28 +28,18 @@ public static void main(String[] args) throws IOException {
2628
"UNKN", "GDQOE23CFSUMSVQK4Y5JHPPYK73VYCNHZHA7ENKCV37P6SUEO6XQBKPP");
2729

2830
try (SorobanServer sorobanServer = new SorobanServer(rpcServerUrl)) {
29-
System.out.println(
30-
"The SAC ID of the asset ["
31-
+ assetNative
32-
+ "] is "
33-
+ getContractData(sorobanServer, assetNative));
34-
System.out.println(
35-
"The SAC ID of the asset ["
36-
+ assetUSDC
37-
+ "] is "
38-
+ getContractData(sorobanServer, assetNative));
39-
System.out.println(
40-
"The SAC ID of the asset ["
41-
+ assetUSDC
42-
+ "] is unknown ("
43-
+ getContractData(sorobanServer, assetUnknown)
44-
+ ")");
31+
for (Asset asset : List.of(assetNative, assetUSDC, assetUnknown)) {
32+
String contractId = asset.getContractId(network);
33+
System.out.printf(
34+
"The contract id for %s is %s, it is %s\n",
35+
asset,
36+
contractId,
37+
isContractDeployed(sorobanServer, contractId) ? "deployed" : "not deployed");
38+
}
4539
}
4640
}
4741

48-
public static String getContractData(SorobanServer sorobanServer, Asset asset)
49-
throws IOException {
50-
String contractId = asset.getContractId(Network.TESTNET);
42+
public static boolean isContractDeployed(SorobanServer sorobanServer, String contractId) {
5143
List<LedgerKey> ledgerKeys =
5244
List.of(
5345
LedgerKey.builder()
@@ -60,13 +52,6 @@ public static String getContractData(SorobanServer sorobanServer, Asset asset)
6052
.build())
6153
.build());
6254
GetLedgerEntriesResponse response = sorobanServer.getLedgerEntries(ledgerKeys);
63-
if (response.getEntries() != null && !response.getEntries().isEmpty()) {
64-
LedgerEntryData entryData =
65-
LedgerEntryData.fromXdrBase64(response.getEntries().get(0).getXdr());
66-
if (entryData.getContractData() == null) return null;
67-
return entryData.getContractData().getContract().getContractId().toXdrBase64();
68-
} else {
69-
return null;
70-
}
55+
return response.getEntries() != null && !response.getEntries().isEmpty();
7156
}
7257
}

src/test/java/org/stellar/sdk/operations/InvokeHostFunctionOperationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ public void testNotEqualsSource() {
292292
}
293293

294294
@Test
295-
public void testUploadContractWasmOperationBuilder() {
295+
public void testInstallContractWasmOperationBuilder() {
296296
byte[] wasm = new byte[] {0x00, 0x01, 0x02, 0x03, 0x34, 0x45, 0x66, 0x46};
297297
InvokeHostFunctionOperation operation =
298-
InvokeHostFunctionOperation.uploadContractWasmOperationBuilder(wasm).build();
298+
InvokeHostFunctionOperation.installContractWasmOperationBuilder(wasm).build();
299299
HostFunction expectedFunction =
300300
HostFunction.builder()
301301
.discriminant(HostFunctionType.HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM)

0 commit comments

Comments
 (0)