Skip to content

Commit

Permalink
Refactor and add support for Yaci DevKit
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 committed Nov 15, 2024
1 parent 170b37b commit 2bb13ee
Show file tree
Hide file tree
Showing 39 changed files with 1,310 additions and 195 deletions.
36 changes: 10 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 +37,39 @@ repositories {
}

compileJava {
sourceCompatibility = '17'
targetCompatibility = '17'
sourceCompatibility = '21'
targetCompatibility = '21'
}

//compileKotlin {
// kotlinOptions.jvmTarget = "1.8"
//}
//compileTestKotlin {
// kotlinOptions.jvmTarget = "1.8"
//}

dependencies {
intellijPlatform {
intellijIdeaCommunity("2023.3.6")
intellijIdeaCommunity("2024.2")
plugin("com.redhat.devtools.lsp4ij:0.5.0")
pluginVerifier()
zipSigner()
instrumentationTools()
}

implementation fileTree(include: ['*.jar'], dir: 'lib')
implementation('com.bloxbean.cardano:cardano-client-lib:0.4.3') {
implementation('com.bloxbean.cardano:cardano-client-lib:0.6.2') {
exclude group: 'org.slf4j', module: 'slf4j-api'
}
implementation('com.bloxbean.cardano:cardano-client-backend-blockfrost:0.4.3') {
implementation('com.bloxbean.cardano:cardano-client-backend-blockfrost:0.6.2') {
exclude group: 'org.slf4j', module: 'slf4j-api'
exclude group: 'com.bloxbean.cardano', module: 'cardano-client-lib'
}
implementation('com.bloxbean.cardano:cardano-client-backend-koios:0.4.3') {
implementation('com.bloxbean.cardano:cardano-client-backend-koios:0.6.2') {
exclude group: 'org.slf4j', module: 'slf4j-api'
exclude group: 'com.bloxbean.cardano', module: 'cardano-client-lib'
}
implementation('com.moandjiezana.toml:toml4j:0.7.2')
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10")

compileOnly 'org.projectlombok:lombok:1.18.20'
implementation 'org.json:json:20240303'

compileOnly 'org.projectlombok:lombok:1.18.34'

annotationProcessor 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.34'
testImplementation group: 'junit', name: 'junit', version: '4.12'
}

Expand Down Expand Up @@ -103,17 +98,6 @@ grammarKit {
}
}

//intellij {
// version = '2023.2'
//// version = "232-EAP-SNAPSHOT"
//// type = "IU"
//// version = "2024.1.4"
//// type = "IU"
// type = 'IC'
// plugins = ['java']
//
// updateSinceUntilBuild = false
//}
patchPluginXml {
changeNotes = changeLogAsHtml()
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import com.bloxbean.intelliada.idea.core.util.Networks;
import com.bloxbean.intelliada.idea.nodeint.CardanoNodeConfigurationHelper;
import com.bloxbean.intelliada.idea.nodeint.exception.TargetNodeNotConfigured;
import com.bloxbean.intelliada.idea.nodeint.service.CardanoServiceFactory;
import com.bloxbean.intelliada.idea.nodeint.service.api.CardanoAccountService;
import com.bloxbean.intelliada.idea.nodeint.service.api.LogListenerAdapter;
import com.bloxbean.intelliada.idea.nodeint.service.impl.AccountServiceImpl;
import com.bloxbean.intelliada.idea.toolwindow.CardanoConsole;
import com.bloxbean.intelliada.idea.util.IdeaUtil;
import com.intellij.icons.AllIcons;
Expand Down Expand Up @@ -400,7 +400,7 @@ public void run() {

CardanoAccountService cardanoAccountService = null;
try {
cardanoAccountService = new AccountServiceImpl(project, new LogListenerAdapter(console));
cardanoAccountService = CardanoServiceFactory.getAccountService(project, new LogListenerAdapter(console));
} catch (TargetNodeNotConfigured targetNodeNotConfigured) {
console.showErrorMessage(targetNodeNotConfigured.getMessage());
IdeaUtil.showNotification(project, "Node Configuration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.bloxbean.intelliada.idea.account.model.CardanoAccount;
import com.bloxbean.intelliada.idea.account.service.AccountService;
import com.bloxbean.intelliada.idea.nodeint.service.CardanoServiceFactory;
import com.bloxbean.intelliada.idea.nodeint.service.api.CardanoAccountService;
import com.bloxbean.intelliada.idea.nodeint.service.api.LogListenerAdapter;
import com.bloxbean.intelliada.idea.nodeint.service.api.model.AssetBalance;
import com.bloxbean.intelliada.idea.nodeint.service.impl.AccountServiceImpl;
import com.bloxbean.intelliada.idea.toolwindow.CardanoConsole;
import com.bloxbean.intelliada.idea.utxos.service.UtxoChooser;
import com.intellij.openapi.application.ApplicationManager;
Expand Down Expand Up @@ -118,7 +118,7 @@ public void run() {
return;

try {
CardanoAccountService accountService = new AccountServiceImpl(project, new LogListenerAdapter(console));
CardanoAccountService accountService = CardanoServiceFactory.getAccountService(project, new LogListenerAdapter(console));
List<AssetBalance> assetBalanceList = accountService.getBalance(address);
assetComboBoxModel.addAll(assetBalanceList);
if (assetBalanceList.size() > 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.bloxbean.intelliada.idea.account.ui.details;

import com.bloxbean.intelliada.idea.account.model.CardanoAccount;
import com.bloxbean.intelliada.idea.configuration.model.RemoteNode;
import com.bloxbean.intelliada.idea.core.util.NodeType;
import com.bloxbean.intelliada.idea.nodeint.CardanoNodeConfigurationHelper;
import com.bloxbean.intelliada.idea.toolwindow.CardanoConsole;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
Expand Down Expand Up @@ -43,7 +46,17 @@ public boolean getAccountInfoUpdated() {

private void createUIComponents() {
// TODO: place custom component creation code here

if (project != null) {
RemoteNode remoteNode = CardanoNodeConfigurationHelper.getTargetRemoteNode(project);
if (remoteNode != null) {
if (remoteNode.getNodeType() == NodeType.YaciDevKit) {
transactionUI = new AccountTransactionsUI(project, false);
return; //we don't support this yet
}
}
}
//Need to initialize here because as non-null project required for JsonEditorTextField
transactionUI = new AccountTransactionsUI(project);
transactionUI = new AccountTransactionsUI(project, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import com.bloxbean.cardano.client.backend.model.metadata.MetadataJSONContent;
import com.bloxbean.intelliada.idea.account.model.CardanoAccount;
import com.bloxbean.intelliada.idea.common.ui.JsonEditorTextField;
import com.bloxbean.intelliada.idea.nodeint.service.CardanoServiceFactory;
import com.bloxbean.intelliada.idea.nodeint.service.api.CardanoAccountService;
import com.bloxbean.intelliada.idea.nodeint.service.api.LogListenerAdapter;
import com.bloxbean.intelliada.idea.nodeint.service.api.TransactionInfoService;
import com.bloxbean.intelliada.idea.nodeint.service.impl.AccountServiceImpl;
import com.bloxbean.intelliada.idea.nodeint.service.impl.TransactionInfoServiceImpl;
import com.bloxbean.intelliada.idea.toolwindow.CardanoConsole;
import com.bloxbean.intelliada.idea.util.JsonUtil;
Expand Down Expand Up @@ -39,8 +39,11 @@ public class AccountTransactionsUI {
private CardanoAccount account;
private DefaultListModel<String> txnListModel;

public AccountTransactionsUI(Project project) {
private boolean supported;

public AccountTransactionsUI(Project project, boolean supported) {
this.project = project;
this.supported = supported;
}

public void initialize(CardanoAccount account, CardanoConsole console) {
Expand All @@ -50,6 +53,14 @@ public void initialize(CardanoAccount account, CardanoConsole console) {

attachListeners();
getRecentTransactions();

if(!supported) {
transactionContentTf.setText("Transaction details are not supported for the selected node type");
metadataEditorTf.setText("Transaction metadata are not supported for the selected node type");

transactionContentTf.setEnabled(false);
metadataEditorTf.setEnabled(false);
}
}

private void attachListeners() {
Expand Down Expand Up @@ -100,7 +111,7 @@ public void run() {
return;

try {
CardanoAccountService accountService = new AccountServiceImpl(project, new LogListenerAdapter(console));
CardanoAccountService accountService = CardanoServiceFactory.getAccountService(project, new LogListenerAdapter(console));
List<String> txnList = accountService.getRecentTransactions(address, 100, 1, OrderEnum.desc);
txnListModel.addAll(txnList);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,47 @@
import com.bloxbean.intelliada.idea.aiken.common.AikenIcons;
import com.bloxbean.intelliada.idea.aiken.module.AikenModuleType;
import com.bloxbean.intelliada.idea.aiken.module.pkg.AikenTomlService;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

public class AikenActionGroup extends DefaultActionGroup {
@Override
public void update(AnActionEvent event) {
public void update(@NotNull AnActionEvent event) {
Project project = event.getProject();
if (project == null) {
event.getPresentation().setVisible(false);
return;
}

DataContext dataContext = event.getDataContext();
final Module module = LangDataKeys.MODULE.getData(dataContext);

final ModuleType moduleType = module == null ? null : ModuleType.get(module);
boolean isAikenModule = moduleType instanceof AikenModuleType;
// Wrap logic in ReadAction.nonBlocking or ReadAction.compute to move off EDT
boolean isAikenModule = ReadAction.compute(() -> {
final Module module = LangDataKeys.MODULE.getData(dataContext);
if (module == null) return false;

//Try to check if aiken.toml file available.
//For non-Aiken modules
if(!isAikenModule) {
AikenTomlService aikenTomlService = AikenTomlService.getInstance(project);
if (aikenTomlService != null)
isAikenModule = aikenTomlService.isAikenProject();
}
final ModuleType moduleType = ModuleType.get(module);
return moduleType instanceof AikenModuleType;
});

if(isAikenModule) {
event.getPresentation().setVisible(true);
event.getPresentation().setIcon(AikenIcons.AIKEN_ICON);
} else {
event.getPresentation().setVisible(false);
event.getPresentation().setIcon(AikenIcons.AIKEN_ICON);
// For non-Aiken modules, check if aiken.toml is available in background
if (!isAikenModule) {
isAikenModule = ReadAction.nonBlocking(() -> {
AikenTomlService aikenTomlService = AikenTomlService.getInstance(project);
return aikenTomlService != null && aikenTomlService.isAikenProject();
}).executeSynchronously();
}

event.getPresentation().setVisible(isAikenModule);
event.getPresentation().setIcon(AikenIcons.AIKEN_ICON);
}

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.icons.AllIcons;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileDocumentManager;
Expand Down Expand Up @@ -163,4 +160,10 @@ public void run(@NotNull ProgressIndicator indicator) {

ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task));
}

@NotNull
@Override
public ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.icons.AllIcons;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.FileDocumentManager;
Expand Down Expand Up @@ -159,4 +156,10 @@ public void run(@NotNull ProgressIndicator indicator) {

ProgressManager.getInstance().runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task));
}

@NotNull
@Override
public ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bloxbean.intelliada.idea.folding;
package com.bloxbean.intelliada.idea.aiken.folding;

import com.bloxbean.intelliada.idea.aiken.lang.psi.*;
import com.intellij.lang.ASTNode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bloxbean.intelliada.idea.folding;
package com.bloxbean.intelliada.idea.aiken.folding;

import com.bloxbean.intelliada.idea.aiken.lang.psi.AikenTypes;
import com.intellij.lang.BracePair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void moduleCreated(@NotNull Module module) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
ProjectGeneratorUtil.createNewContract(module.getProject(), srcRoot, AikenContractTemplates.AK_HELLOWORLD_TEMPLATE, module.getName() + ".ak");
ProjectGeneratorUtil.createNewContract(module.getProject(), srcRoot, AikenContractTemplates.AK_HELLOWORLD_TEMPLATE, module.getName().toLowerCase() + ".ak");

build(module);
}
Expand Down Expand Up @@ -189,10 +189,10 @@ public void run(@NotNull ProgressIndicator indicator) {
public void setupRootModel(@NotNull ModifiableRootModel rootModel) throws ConfigurationException {
rootModel.inheritSdk();

String moduleName = rootModel.getModule().getName();
String moduleName = rootModel.getModule().getName().toLowerCase();

String ownerInputFieldVal= ownerInputField.getValue();
String owner = ownerInputFieldVal != null? ownerInputFieldVal.trim(): System.getProperty("user.name");
String owner = ownerInputFieldVal != null? ownerInputFieldVal.trim().toLowerCase(): System.getProperty("user.name").toLowerCase();

Project project = rootModel.getProject();
String basePath = project.getBasePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

//This is just for UI
public enum CardanoNodeType {
Blockfrost, Koios
LocalYaciDevKit, YaciDevKit, Blockfrost, Koios
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class RemoteNode {
private Map<String, String> headers;
private int timeout;

//local node properties
private String home;
private String version;

public RemoteNode() {

}
Expand Down Expand Up @@ -108,6 +112,22 @@ public void setTimeout(int timeout) {
this.timeout = timeout;
}

public String getHome() {
return home;
}

public void setHome(String home) {
this.home = home;
}

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public void updateValues(RemoteNode node) { //Update everything except id
if (node == null) return;

Expand All @@ -120,6 +140,8 @@ public void updateValues(RemoteNode node) { //Update everything except id
this.setProtocolMagic(node.getProtocolMagic());
this.setHeaders(node.getHeaders());
this.setTimeout(node.getTimeout());
this.setHome(node.getHome());
this.setVersion(node.getVersion());
}

@Override
Expand Down
Loading

0 comments on commit 2bb13ee

Please sign in to comment.