[Webfunds-commits] java/webfunds/client/sox/gui PaymentFrame.java

Ian Grigg iang@cypherpunks.ai
Thu, 12 Apr 2001 15:02:51 -0400 (AST)


iang        01/04/12 15:02:50

  Modified:    webfunds/sox AccountId.java
               webfunds/sox/value PendingReceipt.java
               webfunds/client AccountInfo.java SimplePaymentFrame.java
               webfunds/client/sox SOXWallet.java
               webfunds/client/sox/gui PaymentFrame.java
  Log:
  1. cleaned up the openName from open()
  2. acced OPEN to AccountInfo to mimic the AccountId convention.
  3. added some extra names getRealName, getFullName() to AccountInfo.
  3. modified the Payment dialogs to use less AccountIds
  4. fixed SOXWallet to do a kludged sanity check on the AccountId
     that results from the user's c&p'd data.
  (Doesn't yet handle the actual resultant payment with faulty AccountId.)

Revision  Changes    Path
1.25      +25 -19    java/webfunds/sox/AccountId.java

Index: AccountId.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/AccountId.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- AccountId.java	2001/03/23 15:06:03	1.24
+++ AccountId.java	2001/04/12 19:02:48	1.25
@@ -1,4 +1,4 @@
-/* $Id: AccountId.java,v 1.24 2001/03/23 15:06:03 iang Exp $
+/* $Id: AccountId.java,v 1.25 2001/04/12 19:02:48 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -14,7 +14,7 @@
  * This class represents an Account identifier,
  * which is the standard way of referring to an account.
  *
- * @version $Revision: 1.24 $
+ * @version $Revision: 1.25 $
  */
 public class AccountId extends Id
 {
@@ -47,35 +47,29 @@
 
     public static final AccountId OPEN = new AccountId();   // empty is open
 
-    public boolean equals(Object object)
-    {
-        if(!(object instanceof AccountId))
-            return false;
-
-        return super.eq((Id)object) ;
-    }
-
-
 
-////// Self-Test //////////////////////////////////
+////// Names //////////////////////////////////
 
-    private static String open = null;
+    private static String openName = null;
     /**
      *  @return the string to display if the account is not set.
      */
-    public static String open()
+    public static String openName()
     {
         // if a different string is desired, like CASH, set this
         // at the start of the program.
-        if (open == null)
-            open =  "<OPEN>";
-        return open;
+        if (openName == null)
+            openName =  "<OPEN>";
+        return openName;
     }
 
+    /** XXX: deprecate this name, too general. */
+    public static String open()    { return openName(); }
+
     public String toString()
     {
         if (isOpen())
-            return open();
+            return openName();
 
         return super.toString();
     }
@@ -83,9 +77,21 @@
     public String fp()
     {
         if (isOpen())
-            return open();
+            return openName();
 
         return super.fp();
+    }
+
+
+
+////// Self-Test //////////////////////////////////
+
+    public boolean equals(Object object)
+    {
+        if(!(object instanceof AccountId))
+            return false;
+
+        return super.eq((Id)object) ;
     }
 
     /**



1.17      +2 -2      java/webfunds/sox/value/PendingReceipt.java

Index: PendingReceipt.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/value/PendingReceipt.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- PendingReceipt.java	2001/04/11 19:38:09	1.16
+++ PendingReceipt.java	2001/04/12 19:02:48	1.17
@@ -1,5 +1,5 @@
 /*
- * $Id: PendingReceipt.java,v 1.16 2001/04/11 19:38:09 iang Exp $
+ * $Id: PendingReceipt.java,v 1.17 2001/04/12 19:02:48 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -179,7 +179,7 @@
         public String toString()
         {
             if (id == null || id.length == 0)
-        	    return AccountId.open();
+        	return AccountId.openName();
             return getAccountId().toString();
         }
     



1.26      +75 -10    java/webfunds/client/AccountInfo.java

Index: AccountInfo.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/AccountInfo.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- AccountInfo.java	2001/03/27 01:40:46	1.25
+++ AccountInfo.java	2001/04/12 19:02:49	1.26
@@ -1,5 +1,5 @@
 /*
- * $Id: AccountInfo.java,v 1.25 2001/03/27 01:40:46 iang Exp $
+ * $Id: AccountInfo.java,v 1.26 2001/04/12 19:02:49 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -8,10 +8,13 @@
 
 import java.io.*;
 
+import webfunds.util.Hex;
+
 import webfunds.sox.Utils;
 import webfunds.sox.Encodable;
 import webfunds.sox.AccountId;
 
+
 public class AccountInfo
 {
 
@@ -72,10 +75,29 @@
 
 
 
+    private static String openName = null;
+    /**
+     *  @return the string to display if the account is not set.
+     */
+    public static String openName()
+    {
+        // if a different string is desired, like CASH, set this
+        // at the start of the program.
+        if (openName == null)
+            openName =  "<OPEN>";
+        return openName;
+    }
+
+    public static final AccountInfo OPEN = new AccountInfo();
+
+
+
 ////// Construction ///////////////////////////////////
 
     /**
      *  Use this constructor for an OPEN (empty) info.
+     *  This should not be used unless constucting something special,
+     *  use AccountInfo.OPEN instead.
      */
     public AccountInfo()
     {
@@ -85,6 +107,11 @@
     }
 
 
+    /**
+     *  Use this constructor for an OPEN (empty) info.
+     *  This should not be used unless constucting something special,
+     *  use AccountInfo.OPEN instead.
+     */
     public AccountInfo(AccountId id, String name, WalletInterface wi)
     {
         setByteArray(id.getByteArray());
@@ -93,6 +120,7 @@
     }
 
 
+    // XXX: Hold on, WebFunds client doesn't know about AccountIds!?!
     /**
      * @deprecated we don't want to pass byte[] around, use AccountIds instead.
      */
@@ -144,20 +172,57 @@
 
 
 
-////// Self-test ///////////////////////////////////
+////// Names ///////////////////////////////////
 
+    /**
+     * @return the most convenient human name, being the string name.
+     */
     public String toString()
     {
         if (name != null)
-            return name ; // + " (" + webfunds.utils.Hex.data2hex(id) + ")";
-        if (id == null || id.length == 0)
-    	    return AccountId.open();
-    	String retval = webfunds.utils.Hex.data2hex(id);
-    	if (retval.length() > 10)
-            retval = retval.substring(0, 9);
-        return retval;
+            return name ;
+        else
+            return fp() ;
     }
 
+    /**
+     * @return the full human name if set, with the full id.
+     */
+    public String getFullName()
+    {
+        if (name != null)
+            return name + " (" + getRealName() + ")";
+        else
+            return getRealName();
+    }
+
+    /**
+     * @return the full id, or the OPEN indicator.
+     */
+    public String getRealName()
+    {
+        if (isOpen())
+            return openName();
+        else
+            return Hex.data2hex(id);
+    }
+
+    /**
+     * @return the a short form of the id, good for debugs.
+     */
+    public String fp()
+    {
+        if (isOpen())
+            return openName();
+
+        String s = Hex.data2hex(id);
+    	if (s.length() > 10)
+            s = s.substring(0, 9);
+        return s;
+    }
+
+////// Self-test ///////////////////////////////////
+
     public boolean equals(Object obj)
     {
         AccountInfo info = null;
@@ -208,7 +273,7 @@
         byte[] r = webfunds.sox.Utils.exampleData(1);
         byte[] b = webfunds.sox.Utils.exampleData((r[0] & 0x1F) + 4);
         byte[] n = webfunds.sox.Utils.exampleData((r[0] & 0x60) >> 5);
-        String name = webfunds.utils.Hex.data2hex(n);
+        String name = Hex.data2hex(n);
         AccountInfo info = new AccountInfo(b, name, null);
         return info ;
     }



1.55      +37 -30    java/webfunds/client/SimplePaymentFrame.java

Index: SimplePaymentFrame.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/SimplePaymentFrame.java,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- SimplePaymentFrame.java	2001/03/23 15:06:01	1.54
+++ SimplePaymentFrame.java	2001/04/12 19:02:49	1.55
@@ -1,5 +1,5 @@
 /*
- * $Id: SimplePaymentFrame.java,v 1.54 2001/03/23 15:06:01 iang Exp $
+ * $Id: SimplePaymentFrame.java,v 1.55 2001/04/12 19:02:49 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -18,9 +18,13 @@
 import webfunds.client.plugins.ModeNotSupportedException;
 import webfunds.client.plugins.Plugin;
 import webfunds.ricardian.Contract;
-import webfunds.sox.*;
+
+// these should be removed, client should not depend on SOX
+import webfunds.sox.ItemId;
+import webfunds.sox.Id;
+
 import webfunds.utils.ClipboardHelper;
-import webfunds.utils.Hex;
+import webfunds.util.Hex;
 
 
 public class SimplePaymentFrame
@@ -36,7 +40,7 @@
 
     JFrame  frame;
     TextField amount;
-    TextField target;
+    TextField target1;
     JTextField validFrom;
     JTextField validTill;
     TextArea   paymentArea;
@@ -44,7 +48,7 @@
     WalletInterface wallet;
     AccountInfo source;
     JTextArea description;
-    JComboBox combo;
+    JComboBox target2;
     ItemId contractid;
 
 
@@ -84,8 +88,8 @@
         dcbm.setSelectedItem(emptyInfo);
 
         amount      = new TextField(15);
-        target      = new TextField(15);
-        combo       = new JComboBox(dcbm);
+        target1     = new TextField(15);
+        target2       = new JComboBox(dcbm);
         validFrom   = new JTextField(15);
         validTill   = new JTextField(15);
         paymentArea = new TextArea(20, 55);
@@ -94,7 +98,7 @@
         JPanel pane = (JPanel)frame.getContentPane();
             
         JLabel amountlbl        = new JLabel("Amount:");
-        JLabel targetlbl        = new JLabel("Target:");
+        JLabel target1lbl       = new JLabel("Target:");
         JLabel target2lbl       = new JLabel("Target:");
         JLabel validFromlbl     = new JLabel("Valid from:");
         JLabel validTilllbl     = new JLabel("Valid till:");
@@ -123,14 +127,14 @@
         close.setMnemonic('c');
     
         amountlbl.setLabelFor(amount);
-        targetlbl.setLabelFor(target);
-        target2lbl.setLabelFor(combo);
+        target1lbl.setLabelFor(target1);
+        target2lbl.setLabelFor(target2);
         validFromlbl.setLabelFor(validFrom);
         validTilllbl.setLabelFor(validTill);
         desclbl.setLabelFor(description);
     
         amountlbl.setDisplayedMnemonic('a');
-        targetlbl.setDisplayedMnemonic('t');
+        target1lbl.setDisplayedMnemonic('t');
         target2lbl.setDisplayedMnemonic('r');
         validFromlbl.setDisplayedMnemonic('v');
         validTilllbl.setDisplayedMnemonic('l');
@@ -154,7 +158,7 @@
             
         c.gridy = y++;
         c.insets = new Insets(3, 3, 3, 3);
-        textpanel.add(targetlbl, c);
+        textpanel.add(target1lbl, c);
             
         c.gridy = y++;
         textpanel.add(target2lbl, c);
@@ -181,10 +185,10 @@
     
         c.gridy = y++;
         c.insets = new Insets(3, 3, 3, 3);
-        textpanel.add(target, c);
+        textpanel.add(target1, c);
             
         c.gridy = y++;
-        textpanel.add(combo, c);
+        textpanel.add(target2, c);
 
         c.gridy = y++;
         textpanel.add(validFrom, c);
@@ -284,20 +288,24 @@
 
         long longamount = contract.getUnitsOfContract(dub);
 
-        // who to
-        AccountInfo tgt = (AccountInfo)combo.getSelectedItem(); //default OPEN
-        String tgtName = target.getText();
+        //
+        //  Get the Target.  The text box overrides the combo.
+        //  The combo is set to return OPEN by default.
+        //
+        AccountInfo target = (AccountInfo)target2.getSelectedItem();
+        String targetName = target1.getText();
 
-        if (!"".equals(tgtName))
+        //
+        //  XXX: this was all wrong, it was using SOX Ids, and this is the
+        //  WebFunds client side, which knows nix about SOX.
+        //  Rewritten to strip out AccountIds.
+        //
+        if (targetName != null && targetName.length() > 0)
         {
-            byte[] bytes = Id.getBytesFromIdString(tgtName);
+            byte[] bytes = Id.getBytesFromIdString(targetName);
 
-            tgt = new AccountInfo(bytes, null, null);
+            target = new AccountInfo(bytes, null, null);
         }
-        else if (tgt.isOpen())             // what does tgt return ?
-            tgtName = AccountId.open();
-        else
-            tgtName = tgt.getName() + " ("+Hex.data2hex(tgt.getByteArray())+")";
 
         // expiry date and earliest date
         Date validFrom = new Date(0);
@@ -305,7 +313,7 @@
         Date validTill = new Date(System.currentTimeMillis() + future);
 
         // the payment itself
-        byte[] payment = wallet.makePayment(contractid, source, tgt,
+        byte[] payment = wallet.makePayment(contractid, source, target,
                             longamount, description.getText().getBytes(),
                             validFrom, validTill);
 
@@ -330,9 +338,8 @@
 
             String msg = NEWLINE +
                 "This is a payment for " + tla + amount + nam + NEWLINE +
-                "from " + source.getName() +
-                " (" + Hex.data2hex(source.getByteArray()) + ")" + NEWLINE +
-                "to   " + tgtName + NEWLINE +
+                "from " + source.getFullName() + NEWLINE +
+                "to   " + target.getFullName() + NEWLINE +
                 new String(payment);
 
             paymentArea.append(ClipboardHelper.toClipboardableText(msg));
@@ -346,14 +353,14 @@
 
         else if ("Direct Transfer".equals(command))
         {
-            if (tgt == null || tgt.isOpen())
+            if (target == null || target.isOpen())
             {
                 String e = "You have to specify a target";
                 pm.getUInterface(this).errorMessage(e);
                 return ;  //XXX: oops, we just leaked our payment
             }
 
-            wallet.makeDeposit(payment, tgt, "Deposit".getBytes());
+            wallet.makeDeposit(payment, target, "Deposit".getBytes());
         }
     }
 }



1.152     +44 -2     java/webfunds/client/sox/SOXWallet.java

Index: SOXWallet.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/sox/SOXWallet.java,v
retrieving revision 1.151
retrieving revision 1.152
diff -u -r1.151 -r1.152
--- SOXWallet.java	2001/04/12 05:09:50	1.151
+++ SOXWallet.java	2001/04/12 19:02:49	1.152
@@ -1,4 +1,4 @@
-/* $Id: SOXWallet.java,v 1.151 2001/04/12 05:09:50 iang Exp $
+/* $Id: SOXWallet.java,v 1.152 2001/04/12 19:02:49 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All Rights Reserved.
@@ -80,7 +80,7 @@
  *
  *  Check the above search strings for separation so far.
  *
- * @version $Revision: 1.151 $
+ * @version $Revision: 1.152 $
  */
 public class SOXWallet
     extends Debug
@@ -514,6 +514,25 @@
     }
 
     /**
+     *  Kludge test to stop a target that is duff from
+     *  being accepted.
+     */
+    protected boolean isLegalTarget(AccountId accountid)
+    {
+        if (accountid == null)
+            return false;
+
+        if (accountid.isOpen())
+            return true;
+
+        byte[] buf = accountid.getByteArray();
+        if (buf.length != 20)
+            return false;
+
+        return true;
+    }
+
+    /**
      *  WebFunds Wallet Interface
      */
     public AccountInfo[] getAccounts()
@@ -816,6 +835,29 @@
                        "                   \"" + descString + "\"\n" +
                        "\n" +
                        "and it may bounce when deposited!\n\n\n" +
+                       "Are you sure you want to make this payment?";
+            if (!ask(q))
+                return null ;
+        }
+
+        if (!isLegalTarget(tgt))
+        {
+
+            /*
+             *  Need to get the display amount into unit of account.
+             */
+            Contract contract = contracts.getContract(contractid);
+            String am = "" + amount;
+            String name = contractid.toString();
+            if (contract != null)
+            {
+                am = contract.getPrintableAmount(amount);
+                name = contract.getName();
+            }
+            String descString = Hex.printable(desc);
+
+            String q = "The target " + tgt + " is not a SOX target account." +
+                       "\n\n" +
                        "Are you sure you want to make this payment?";
             if (!ask(q))
                 return null ;



1.10      +24 -22    java/webfunds/client/sox/gui/PaymentFrame.java

Index: PaymentFrame.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/sox/gui/PaymentFrame.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- PaymentFrame.java	2001/03/23 15:06:03	1.9
+++ PaymentFrame.java	2001/04/12 19:02:50	1.10
@@ -1,5 +1,5 @@
 /*
- * $Id: PaymentFrame.java,v 1.9 2001/03/23 15:06:03 iang Exp $
+ * $Id: PaymentFrame.java,v 1.10 2001/04/12 19:02:50 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -100,9 +100,8 @@
             AccountInfo[] accounts = pm.getAddressbook(this).getAccounts();
             DefaultComboBoxModel acList;
             acList = new DefaultComboBoxModel(accounts);
-            AccountInfo emptyInfo = new AccountInfo();
-            acList.insertElementAt(emptyInfo, 0);
-            acList.setSelectedItem(emptyInfo);
+            acList.insertElementAt(AccountInfo.OPEN, 0);
+            acList.setSelectedItem(AccountInfo.OPEN);
 
             DefaultComboBoxModel typeList;
             typeList = new DefaultComboBoxModel(types);
@@ -339,33 +338,39 @@
 
         //
         //  Get the target.  Text box of KHID overrides address book list.
-        //  Default is to Open.
+        //  Default is to OPEN.
         //
         AccountInfo target = (AccountInfo)target2.getSelectedItem();
         byte[] rawTgtName = target.getByteArray();
-        String tgtName = target1.getText();
+        String targetName = target1.getText();
 
-        if (!"".equals(tgtName))             // text box is (also?) set, use it
+        //
+        //  Get the text box if there.
+        //
+        if (targetName != null && targetName.length() > 0)
         {
-            byte[] bytes = Id.getBytesFromIdString(tgtName);
+            byte[] bytes = Id.getBytesFromIdString(targetName);
 
             target = new AccountInfo(bytes, null, null);
         }
-        else if (target.isOpen())             // what does target return ?
-            tgtName = AccountId.open();
-        else
-            tgtName = target.getName() + " (" + Hex.data2hex(rawTgtName) + ")";
 
+        //
+        //  Build an AccountId for the "special" methods.
+        //
+        AccountId tgt;
+        if (!target.isOpen())               // target probably OPEN
+        {
+            tgt = new AccountId();
+            tgt.setByteArray(rawTgtName);
+        }
+        else
+            tgt = AccountId.OPEN;
+         
         // expiry date and earliest date
         Date validFrom = new Date(0);
         long future = 5 * 24 * 60 * 60 * 1000;
         Date validTill = new Date(System.currentTimeMillis() + future);
 
-        AccountId tgt = new AccountId();
-        if (target != null)               // target probably OPEN
-            tgt.setByteArray(rawTgtName);
-         
-
         //
         //  Extract the payment from the wallet.  What sort?
         //
@@ -471,13 +476,10 @@
 
             String msg = "\nThis is a " + typeString +
                          " payment for " + tla + amount + nam +
-                         "\nfrom " + source.getName() +
-                             " (" + Hex.data2hex(source.getByteArray()) + ")" +
-                         "\nto   " + tgtName +
+                         "\nfrom " + source.getFullName() +
+                         "\nto   " + target.getFullName() +
                          "\nCut and Paste the following lines into an email:" +
                          "\n";
-
-                         // " from wallet " + wallet.getShortName() +
 
             paybox.append(msg);;
             paybox.append(new String(pay));