Skip to content

Commit

Permalink
improve naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe7s committed Aug 10, 2024
1 parent eb54281 commit 5365d9a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package software.sava.anchor.programs;

import software.sava.anchor.AnchorIDL;
import software.sava.anchor.AnchorSourceGenerator;
import software.sava.anchor.AnchorUtil;
import software.sava.anchor.OnChainIDL;
import software.sava.rpc.json.http.SolanaNetwork;
Expand All @@ -20,32 +21,32 @@

import static software.sava.core.accounts.PublicKey.fromBase58Encoded;

public record AnchorSourceGenerator(SolanaRpcClient rpcClient, int tabLength) {
public record Entrypoint(SolanaRpcClient rpcClient, int tabLength) {

private static String formatPackage(final String basePackage, final String moduleName) {
return String.format("%s.%s.anchor", basePackage, moduleName);
}

public software.sava.anchor.AnchorSourceGenerator createGenerator(final String moduleName,
final String programAddress,
final Path sourceDirectory,
final String basePackageName) {
public AnchorSourceGenerator createGenerator(final String moduleName,
final String programAddress,
final Path sourceDirectory,
final String basePackageName) {
final var idlAddress = AnchorUtil.createIdlAddress(fromBase58Encoded(programAddress));
final var idlAccountInfo = rpcClient.getAccountInfo(idlAddress, OnChainIDL.FACTORY).join();
final var idl = AnchorIDL.parseIDL(JsonIterator.parse(idlAccountInfo.data().json()));
return new software.sava.anchor.AnchorSourceGenerator(
return new AnchorSourceGenerator(
sourceDirectory,
formatPackage(basePackageName, moduleName),
tabLength,
idl
);
}

public software.sava.anchor.AnchorSourceGenerator createGenerator(final String moduleName,
final URI url,
final Path sourceDirectory,
final String basePackageName) {
return software.sava.anchor.AnchorSourceGenerator.createGenerator(
public AnchorSourceGenerator createGenerator(final String moduleName,
final URI url,
final Path sourceDirectory,
final String basePackageName) {
return AnchorSourceGenerator.createGenerator(
rpcClient.httpClient(),
url,
sourceDirectory,
Expand All @@ -55,7 +56,7 @@ public software.sava.anchor.AnchorSourceGenerator createGenerator(final String m
}

public static void main(final String[] args) {
final var clas = AnchorSourceGenerator.class;
final var clas = Entrypoint.class;
final var moduleName = clas.getModule().getName();
final int tabLength = Integer.parseInt(System.getProperty(moduleName + ".tabLength", "2"));
final var sourceDirectory = Path.of(System.getProperty(moduleName + ".sourceDirectory", "anchor-programs/src/main/java")).toAbsolutePath();
Expand All @@ -76,7 +77,7 @@ public static void main(final String[] args) {
rpcEndpoint == null || rpcEndpoint.isBlank() ? SolanaNetwork.MAIN_NET.getEndpoint() : URI.create(rpcEndpoint),
httpClient
);
final var anchorGenerator = new AnchorSourceGenerator(rpcClient, tabLength);
final var anchorGenerator = new Entrypoint(rpcClient, tabLength);
final var futures = programs.entrySet().stream()
.map(entry -> anchorGenerator.createGenerator(entry.getKey(), entry.getValue(), sourceDirectory, basePackageName))
.map(generator -> CompletableFuture.runAsync(generator, executor))
Expand Down
4 changes: 2 additions & 2 deletions programs/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
requires software.sava.solana_programs;
requires software.sava.anchor_src_gen;

// exports software.sava.anchor.programs.drift.anchor;
// exports software.sava.anchor.programs.drift.anchor.types;
exports software.sava.anchor.programs.drift.anchor;
exports software.sava.anchor.programs.drift.anchor.types;

exports software.sava.anchor.programs.marinade;
exports software.sava.anchor.programs.marinade.anchor;
Expand Down
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ readonly moduleName="software.sava.anchor_generator"
readonly package="software.sava.anchor.programs"
projectDirectory="$(pwd)/generator"
readonly projectDirectory
readonly mainClass="$package.AnchorSourceGenerator"
readonly mainClass="$package.Entrypoint"

javaArgs=(
'-XX:+UseZGC'
Expand Down

0 comments on commit 5365d9a

Please sign in to comment.