[Webfunds-commits] java/webfunds/sox ValueAccount.java

Ian Grigg iang@cypherpunks.ai
Thu, 30 Nov 2000 09:45:54 -0400 (AST)


iang        00/11/30 09:45:53

  Modified:    webfunds/sox ValueAccount.java
  Log:
  added withdraw method, untested as yet

Revision  Changes    Path
1.22      +50 -12    java/webfunds/sox/ValueAccount.java

Index: ValueAccount.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/ValueAccount.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- ValueAccount.java	2000/11/09 13:13:50	1.21
+++ ValueAccount.java	2000/11/30 13:45:53	1.22
@@ -1,5 +1,5 @@
 /*
- * $Id: ValueAccount.java,v 1.21 2000/11/09 13:13:50 iang Exp $
+ * $Id: ValueAccount.java,v 1.22 2000/11/30 13:45:53 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -93,16 +93,54 @@
         //
         acct.sign(req);   // this method requires Acct to know about requests
 
-//        byte[] reqData = req.encode();
-//        byte[] sig;
-//        try {
-//            sig = acct.sign(reqData);
-//        } catch (java.security.KeyException kex) {
-//            kex.printStackTrace(System.err);
-//            throw new SOXKeyException("KeyException: " + kex);
-//        }
-//
-//        req.setSignature(sig);
+        return doDepositGetMail(req, false, myDID);
+    }
+
+    /**
+     *  Withdraw a payment, paying with another payment.
+     *  This is similar to Deposit, but involves two payments.
+     *  The first pays for the second, which latter comes back signed.
+     *
+     *  @param payment that pays for proto withdrawal
+     *  @param proto is the tokens for signing
+     *  @param desc is a binary description
+     *  @param did is a suggested idempotent Id to use, ignore if invalid
+     *
+     *  @throws SOXArgsException if item in payment is invalid
+     *  @throws SOXLaterException if there is no ability to talk to the server
+     *  @throws SOXSubAccountException if something goes wrong with access
+     *  @throws SOXKeyException if something goes wrong with signing
+     */
+    public MailItem[] withdraw(AbstractPayment payment, AbstractPayment proto,
+                               String desc, String did)
+          throws SOXSubAccountException, SOXLaterException, SOXKeyException,
+                 SOXArgsException, SOXDepositException
+    {
+        checkFrozen("withdraw");
+        checkNet();
+        if (isNew())          // also see retry code in doDepositGetMail()
+            register();
+
+        ItemId payId = payment.getItem();
+        if (!payId.equals(itemId))
+        {
+            String s = "subAccount item is " + itemId + " not " + payId;
+            throw new SOXArgsException(s);
+        }
+
+        boolean myDID = false;        // user DID being dud is a user error
+        if (did == null || (did.length() == 0))
+        {
+            did = "D" + System.currentTimeMillis();
+            myDID = true;             // but my DID should be SubAccount error
+        }
+        String num = "" + reqNo++;
+        DepositRequest req = new DepositRequest(num, acct.getId(),
+                                                payment, proto,
+                                                did, desc.getBytes());
+
+        // hmm, sig is necessary?
+        //acct.sign(req);   // this method requires Acct to know about requests
 
         return doDepositGetMail(req, false, myDID);
     }
@@ -522,7 +560,7 @@
 
     /**
      *  Create a proto token payment.
-     *  A little different to normal payments, as there are
+     *  A little different to normal payments - as there are
      *  no special needs like signing, so this call is not needed.
      *
      * @param tokens the individual tokens or coins that need withdrawing