From 028cfe5ca33ea9a7abb846158319f64f9e44fc5e Mon Sep 17 00:00:00 2001 From: nicksavers Date: Sat, 20 Sep 2014 10:48:53 +0200 Subject: [PATCH] Fix ContractCallDialog error --- ethereumj-core/src/main/java/org/ethereum/util/Utils.java | 6 +++++- .../src/main/java/org/ethereum/gui/ContractCallDialog.java | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/util/Utils.java b/ethereumj-core/src/main/java/org/ethereum/util/Utils.java index 8defc6b4..13a5d80e 100644 --- a/ethereumj-core/src/main/java/org/ethereum/util/Utils.java +++ b/ethereumj-core/src/main/java/org/ethereum/util/Utils.java @@ -62,6 +62,10 @@ public class Utils { } return result.toString() + "ยท(" + "10^" + pow + ")"; } + + public static boolean isValidAddress(byte[] addr) { + return addr != null && addr.length == 20; + } /** * @param addr length should be 20 @@ -69,7 +73,7 @@ public class Utils { */ public static String getAddressShortString(byte[] addr) { - if (addr == null || addr.length != 20) throw new Error("not an address"); + if (!isValidAddress(addr)) throw new Error("not an address"); String addrShort = Hex.toHexString(addr, 0, 3); diff --git a/ethereumj-studio/src/main/java/org/ethereum/gui/ContractCallDialog.java b/ethereumj-studio/src/main/java/org/ethereum/gui/ContractCallDialog.java index fcb5aab6..cd13c004 100644 --- a/ethereumj-studio/src/main/java/org/ethereum/gui/ContractCallDialog.java +++ b/ethereumj-studio/src/main/java/org/ethereum/gui/ContractCallDialog.java @@ -305,6 +305,11 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog { private void playContractCall() { byte[] contractAddress = Hex.decode(contractAddrInput.getText()); + if (!Utils.isValidAddress(contractAddress)) { + alertStatusMsg("Not a valid contract address"); + return; + } + ContractDetails contractDetails = UIEthereumManager.ethereum.getRepository().getContractDetails(contractAddress); if (contractDetails == null) { alertStatusMsg("No contract for that address");