[Webfunds-commits] java/webfunds/sox/value ValueManager.java

Ian Grigg iang@cypherpunks.ai
Thu, 12 Apr 2001 00:52:59 -0400 (AST)


iang        01/04/12 00:52:58

  Modified:    webfunds/sox/value ValueManager.java
  Log:
  Tightened up definition of exceptions, DepositEx is now expected,
  PaymentEx means the AP is junk.  Still not clear how to handle the
  marginal cases.

Revision  Changes    Path
1.6       +58 -10    java/webfunds/sox/value/ValueManager.java

Index: ValueManager.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/value/ValueManager.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ValueManager.java	2001/04/10 20:14:20	1.5
+++ ValueManager.java	2001/04/12 04:52:57	1.6
@@ -1,4 +1,4 @@
-/* $Id: ValueManager.java,v 1.5 2001/04/10 20:14:20 iang Exp $
+/* $Id: ValueManager.java,v 1.6 2001/04/12 04:52:57 iang Exp $
  *
  * Copyright (c) Systemics Inc. 1995-2000 on behalf of
  * The WebFunds Development Team.  All Rights Reserved.
@@ -24,12 +24,12 @@
 
 import webfunds.store.Store;
 import webfunds.store.StoreException;
-import webfunds.store.SepFileStore;
 
 import webfunds.sox.Account;
 import webfunds.sox.AccountId;
 import webfunds.sox.ArmouredPayment;
 import webfunds.sox.Crypto;
+import webfunds.sox.Errors;
 import webfunds.sox.ServerFinder;
 import webfunds.sox.ItemId;
 import webfunds.sox.MailId;
@@ -60,7 +60,7 @@
  *
  *  (Was the SOXWallet -- attempt to separate and make simple!)
  *
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
  */
 public class ValueManager
     extends Debug
@@ -470,7 +470,6 @@
                                        "Payment no good: " + ex);
         }
 
-logmsg("Payment Created::::: " + payment);
         savePaymentAsPending(src, payment);
 
         return payment ;
@@ -814,13 +813,21 @@
      *  @param desc description
      *  @param idempotentId is suggested id for deposit, ignored if null/empty
      *
+     *  @throw DepositException if the payment turns out to be invalid for
+     *         some reason that is understood and expected at the user level
+     *  @throw PaymentException if the payment is faulty for technical reasons,
+     *         the payment target is junk (entered as field in dialog?),
+     *         other payment paramaters were faulty (treat with suspicion).
      *  @throw AccountException if the target account does not exist, or
-     *                          does not include the item as a subaccount
+     *         does not include the item as a subaccount, or
+     *         some other unexpected problem is detected (possible bug).
      */
     public Receipt deposit(AbstractPayment pay, AccountId accountid, 
                              byte[] desc, String idempotentId)
-        throws DepositException, AccountException
+        throws DepositException, PaymentException, AccountException
     {
+
+        // throws AccountException if unknown item
         ValueAccount val = getKnownValueAccount(accountid, pay.getItem());
 
         String choice = val.getAccount().getName();
@@ -835,13 +842,39 @@
         try {
             mails = val.deposit(pay, new String(desc), idempotentId);
 
-        } catch (SOXDepositException ex) {      // webfunds.sox.Errors
+        } catch (SOXDepositException ex) {      // routine payment errors
             throw new DepositException(ex.getNumber(), ex.getMessage());
         } catch (SOXLaterException ex) {
             throw new DepositException(ex.getNumber(), ex.getMessage());
-        } catch (SOXSubAccountException ex) {   // negative
+        } catch (SOXSubAccountException ex) {   // abnormalities
+            int err = ex.getNumber();
+            String error = ex.getMessage();
+
+            /*
+             *  Anything that is to do with the payment is not
+             *  our problem, caller supplied junk, and should
+             *  have checked more carefully.
+             *  For example,  a junk target is probably a coding
+             *  in the original payment dialog.
+             *  What it means here is that there is no need to
+             *  print a stacktrace at this level, but caller
+             *  should treat this payment with suspicion.
+             */
+            if (
+                  (err == Errors.ERROR_NOT_A_PAYMENT)                     ||
+                  (err == Errors.ERROR_PAYMENT_NOT_SIGNED)                ||
+                  (err == Errors.ERROR_NOT_AN_ITEM)                       ||
+                  (err == Errors.ERROR_NOT_A_QUANTITY)                    ||
+                  ((err==Errors.ERROR_NOT_TARGET_KHID) && !pay.isOpen())  ||
+                  (err == Errors.ERROR_ILLEGAL_PID)                       ||
+                  (err == Errors.ERROR_NOT_PROTO)                         ||
+                  (err == Errors.ERROR_NOT_TOKEN)                         ||
+                  false
+               )
+                  throw new PaymentException(err, ex.getMessage());
+
             ex.printStackTrace();
-            throw new DepositException(ex.getNumber(), ex.getMessage());
+            throw new AccountException(ex.getNumber(), ex.getMessage());
 
         } catch (SOXArgsException ex) {
             ex.printStackTrace();
@@ -869,7 +902,7 @@
         String s = checkReceipt(mails[0], pss, ptt, item, qty);
         if (s != null)
             /// hmmm this is really a SubAccount failure, should never happen
-            throw new DepositException(SOXSubAccountException.NO_RECEIPT);
+            throw new AccountException(SOXSubAccountException.NO_RECEIPT);
 
         internalUpdate(val, mails);
 
@@ -967,6 +1000,7 @@
      *  Cancel a Payment (pid) within a SubAccount.
      *  And call the update.  For high-level user programs.
      *
+     *  On return, the pid is cancelled for the named subaccount.
      */
     public void cancel(AccountId accountid, ItemId item, String pid)
         throws CancelException, AccountException
@@ -1182,6 +1216,17 @@
         // } catch (SOXLaterException ex) {
         //     return try_again_later;
         // } catch (SOXSubAccountException e) {
+        } catch (SOXDepositException ex) {
+            int err = ex.getNumber();
+            if (err == Errors.ERROR_CANCELLED)
+                logmsg(pid + " cancelled already!");
+            else
+            {
+                logmsg("cancel " + pid + " failed: " + ex);
+                ex.printStackTrace(err());
+            }
+            throw new CancelException(err, ex.getMessage());
+
         } catch (SOXException ex) {
             ex.printStackTrace(err());
             throw new CancelException(CancelException.INTERNAL,
@@ -1397,10 +1442,10 @@
             acct.newSub(sub);
         } catch (SOXSubAccountException ex) {
             ex.printStackTrace();
-            throw new AccountException("EX?: " + ex);
+            throw new AccountException("SubEx: " + ex);
         } catch (SOXAccountException ex) {
             ex.printStackTrace();
-            throw new AccountException("EX?: " + ex);
+            throw new AccountException("AcEx: " + ex);
         }
 
         storeAccount(acct);
@@ -1533,7 +1578,10 @@
             mails = sub.update(confirms);
 
             if (mails == null || (mails.length == 0))
+            {
+                logmsg("for(;;;) update cycle complete");
                 return ;
+            }
             logmsg("for(;" + i + "<4; ++) on " + mails.length + " mails");
 
             //