Skip to content

Commit

Permalink
Debugger impl fix
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 committed Sep 1, 2021
1 parent 84cb845 commit 9e1103f
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<text value="-"/>
</properties>
</component>
<grid id="3bb50" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="3bb50" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand All @@ -107,14 +107,6 @@
</constraints>
<properties/>
</component>
<component id="182b1" class="javax.swing.JButton" binding="accountsChooserBtn">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="..."/>
</properties>
</component>
</children>
</grid>
<component id="a284e" class="javax.swing.JLabel">
Expand All @@ -125,14 +117,6 @@
<text value="Accounts"/>
</properties>
</component>
<component id="109e4" class="javax.swing.JButton" binding="accountAddBtn">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="+"/>
</properties>
</component>
<component id="df384" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
Expand Down Expand Up @@ -198,6 +182,14 @@
<text value="-"/>
</properties>
</component>
<component id="182b1" class="javax.swing.JButton" binding="accountsChooserBtn">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="..."/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.bloxbean.algodea.idea.nodeint.exception.InvalidInputParamException;
import com.bloxbean.algodea.idea.nodeint.model.ApplArg;
import com.bloxbean.algodea.idea.nodeint.model.ArgType;
import com.bloxbean.algodea.idea.nodeint.model.Lease;
import com.bloxbean.algodea.idea.nodeint.model.Note;
import com.bloxbean.algodea.idea.nodeint.util.ArgTypeToByteConverter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
Expand All @@ -17,6 +15,7 @@
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -30,7 +29,6 @@ public class AppTxnDetailsEntryForm {
private JTextField accountsTf;
private JList accountsList;
private JList argList;
private JButton accountAddBtn;
private JButton argAddBtn;
private JPanel mainPanel;
private JComboBox<ArgType> argTypeCB;
Expand All @@ -56,15 +54,21 @@ public AppTxnDetailsEntryForm() {

public void initializeData(Project project) {
this.project = project;
argAddBtn.addActionListener(e -> {

Action argAddAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
ArgType argType = (ArgType)argTypeCB.getSelectedItem();

if(argType != null) {
ApplArg applArg = new ApplArg(argType, argTf.getText());
argListModel.addElement(applArg);
argTf.setText("");
}
});
}
};
argTf.addActionListener(argAddAction);
argAddBtn.addActionListener(argAddAction);

argDelBtn.addActionListener(e -> {
Object selectedValue = argList.getSelectedValue();
Expand All @@ -75,17 +79,21 @@ public void initializeData(Project project) {

accountsChooserBtn.addActionListener(e -> {
AlgoAccount algoAccount = AccountChooser.getSelectedAccount(project, true);
if(algoAccount != null) {
accountsTf.setText(algoAccount.getAddress());
}
((DefaultListModel) accountsList.getModel()).addElement(StringUtil.trim(algoAccount.getAddress()));
});

accountAddBtn.addActionListener( e -> {
Action addAccountAction = new AbstractAction()
{
@Override
public void actionPerformed(ActionEvent e)
{
if(!StringUtil.isEmpty(accountsTf.getText())) {
((DefaultListModel) accountsList.getModel()).addElement(StringUtil.trim(accountsTf.getText()));
accountsTf.setText("");
}
});
}
};
accountsTf.addActionListener(addAccountAction);

accountsDelBtn.addActionListener(e -> {
Object selectedValue = accountsList.getSelectedValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.ValidationInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -22,15 +24,20 @@ public class DryRunContextEntryDialog extends DialogWrapper {
private boolean enableGeneralContextInfo;
private boolean enableSourceInfo;

protected Action fetchDefaultAction;
private Project project;

public DryRunContextEntryDialog(@Nullable Project project,
java.util.List<Long> appIds, java.util.List<Address> accounts, List<Long> foreignApps, boolean isStatefulContract, boolean enableGeneralContextInfo, boolean enableSourceInfo) {
super(project, true);
init();
setTitle("Dry Run Context");

this.fetchDefaultAction = new FetchDefaultAction("Fetch Defaults");
this.project = project;
this.enableSourceInfo = enableSourceInfo;
this.enableGeneralContextInfo = enableGeneralContextInfo;

init();
setTitle("Dry Run Context");

if(enableGeneralContextInfo) {
dryRunContextForm.initializeData(project, appIds);
} else {
Expand Down Expand Up @@ -124,4 +131,28 @@ private void createUIComponents() {
dryRunSourceInputForm = new DryRunSourceContextForm();
dryRunContextForm = new DryRunContextForm();
}

@Override
protected @NotNull Action[] createLeftSideActions() {

if(enableGeneralContextInfo) {
return new Action[]{
fetchDefaultAction
};
} else {
return super.createLeftSideActions();
}
}

class FetchDefaultAction extends DialogWrapperAction {

public FetchDefaultAction(String label) {
super(label);
}

@Override
protected void doAction(ActionEvent e) {
dryRunContextForm.updateNetworkDefaults(project);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.bloxbean.algodea.idea.dryrun.ui;

import com.algorand.algosdk.crypto.Address;
import com.algorand.algosdk.v2.client.model.TransactionParametersResponse;
import com.bloxbean.algodea.idea.account.model.AlgoAccount;
import com.bloxbean.algodea.idea.account.service.AccountChooser;
import com.bloxbean.algodea.idea.nodeint.exception.DeploymentTargetNotConfigured;
import com.bloxbean.algodea.idea.nodeint.model.DryRunContext;
import com.bloxbean.algodea.idea.nodeint.service.LogListenerAdapter;
import com.bloxbean.algodea.idea.nodeint.service.NetworkService;
import com.bloxbean.algodea.idea.toolwindow.AlgoConsole;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.ValidationInfo;
Expand Down Expand Up @@ -32,6 +39,7 @@ public class DryRunContextForm {
private JScrollPane scrollPane;

private DefaultListModel<String> listModel;
private AlgoConsole console;

public DryRunContextForm() {

Expand All @@ -46,6 +54,7 @@ public void initializeData(Project project, List<Long> appIds) {
appIdsTf.setText(String.valueOf(mergedAppIds));
}

console = AlgoConsole.getConsole(project);
attachListeners(project);
}

Expand All @@ -67,6 +76,41 @@ private void attachListeners(Project project) {

listModel.remove(index);
});

}

public void updateNetworkDefaults(Project project) {
ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
//Get network info
try {
NetworkService networkService = new NetworkService(project, new LogListenerAdapter(console));
TransactionParametersResponse transactionParametersResponse = networkService.getNetworkInfo();

Integer latestTimestamp = null;
try {
String timeStampStr = networkService.getBlockTimeStamp(transactionParametersResponse.lastRound);
latestTimestamp = Integer.parseInt(timeStampStr);
} catch (Exception e) {}

roundTf.setText(String.valueOf(transactionParametersResponse.lastRound));
protocolVersionTf.setText(transactionParametersResponse.consensusVersion);
if(latestTimestamp != null) {
latestTimestampTf.setText(String.valueOf(latestTimestamp));
}

} catch (DeploymentTargetNotConfigured deploymentTargetNotConfigured) {
Messages.showWarningDialog(deploymentTargetNotConfigured.getMessage(), "Error");
console.showErrorMessage(deploymentTargetNotConfigured.getMessage(), deploymentTargetNotConfigured);
} catch (Exception exception) {
console.showErrorMessage(exception.getMessage(), exception);
}

progressIndicator.setFraction(1.0);
}
} , "Connecting to Algorand Node to fetch network info...", true, project);
}

protected @Nullable ValidationInfo doValidate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ public void setSource(DryRunContext.Source source) {
return new ValidationInfo("Please provide a valid transaction index. Error: " + e.getMessage(), srcTxnIndexTf);
}

if(isStatefulContract) {
String srcFile = sourceFileTf.getText();
if(StringUtil.isEmpty(srcFile)) {
return new ValidationInfo("Please select a valid source file", sourceFileTf);
}
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package com.bloxbean.algodea.idea.nodeint.service;

import com.algorand.algosdk.v2.client.common.Response;
import com.algorand.algosdk.v2.client.model.BlockResponse;
import com.algorand.algosdk.v2.client.model.TransactionParametersResponse;
import com.bloxbean.algodea.idea.common.Tuple;
import com.bloxbean.algodea.idea.configuration.model.NodeInfo;
import com.bloxbean.algodea.idea.nodeint.exception.DeploymentTargetNotConfigured;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

public class NetworkService extends AlgoBaseService {

public NetworkService(Project project, LogListener logListener) throws DeploymentTargetNotConfigured {
super(project, logListener);
}

public NetworkService(@NotNull NodeInfo nodeInfo, LogListener logListener) {
super(nodeInfo, logListener);
}
Expand All @@ -22,4 +28,20 @@ public TransactionParametersResponse getNetworkInfo() throws Exception {

return transactionParametersResponse.body();
}

public String getBlockTimeStamp(Long round) throws Exception {
Response<BlockResponse> blockResponse = client.GetBlock(round).execute(getHeaders()._1(), getHeaders()._2());

if(!blockResponse.isSuccessful()) {
printErrorMessage("Unable to get block for round : " + round, blockResponse);
return null;
}

Object value = blockResponse.body().block.get("ts");
if(value == null)
return null;
else {
return String.valueOf(value);
}
}
}

0 comments on commit 9e1103f

Please sign in to comment.