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

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


iang        00/11/30 09:42:01

  Modified:    webfunds/sox Receipt.java
  Log:
  finished off the self-test and got it working, required moving the
  initialisation of the version number around (cannot be done statically
  as static code is run after super())

Revision  Changes    Path
1.42      +62 -28    java/webfunds/sox/Receipt.java

Index: Receipt.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Receipt.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- Receipt.java	2000/11/09 13:13:50	1.41
+++ Receipt.java	2000/11/30 13:42:00	1.42
@@ -1,5 +1,5 @@
 /*
- * $Id: Receipt.java,v 1.41 2000/11/09 13:13:50 iang Exp $
+ * $Id: Receipt.java,v 1.42 2000/11/30 13:42:00 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -18,7 +18,7 @@
  * data received from the issuer.
  */
 public class Receipt
-    extends Encodable // implements Serializable
+    extends Encodable
 {
     /**
      *  The version of the encoded receipt.
@@ -34,11 +34,14 @@
                             RECEIPT_PROTO        = 3,   // includes ProtoPay
                             RECEIPT_not_used_yet = 4;   // use me next...
      
-    protected int version = RECEIPT_LOCAL_VERS;  // change this if an old packet
+    protected int version;
        
     public int getVersion()         { return version; }
 
 
+    /**
+     *  SOX format for these hashes is the PGP format with leading byte.
+     */
     protected static final int MD_SHA1 = 2;
 
     protected DepositRequest depositRequest;
@@ -243,11 +246,6 @@
                 DepositRequest req )
         throws SOXPacketException
     {
-//        try
-//        {
-//            debug = new PrintWriter(System.err);
-//        }
-//        catch (Exception ex) { ex = null; }
 
         this.item = item;
         this.qty = qty;
@@ -257,8 +255,9 @@
         this.did = did;
         this.tgt = tgt;
         this.src = src;
-        this.depositRequest = req;
 
+        this.version = RECEIPT_LOCAL_VERS;
+
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         try {
             req.encode(baos);
@@ -266,11 +265,7 @@
             throw new SOXPacketException("DepositRequest IOEx: " + ex);
         }
         this.depositRequestData = baos.toByteArray();
-
-        // logmsg("Receipt source = " + src);
-        // logmsg("DepositRequest source = " + depositRequest.getSource());
-        // logmsg("Receipt target = " + tgt);
-        // logmsg("DepositRequest target = " + depositRequest.getTarget());
+        this.depositRequest = req;
 
         if (!isValid())
             throw new SOXPacketException("dud Receipt");
@@ -317,10 +312,7 @@
     public Receipt(byte[] receiptData)
         throws SOXPacketException
     {
-//        PrintWriter temp = debug;
-//        debug = null;
         decode(receiptData);
-//        debug = temp;
     }
 
     /**
@@ -424,13 +416,14 @@
         InputStream d2 = (InputStream) new ByteArrayInputStream(bbbb);
         dis = new DataInputStream(d2);
 
-        int v = dis.readUnsignedByte();
-        if ( !(RECEIPT_LOCAL_VERS <= v && v <= RECEIPT_PROTO) )
+        version = dis.readUnsignedByte();
+        if ( !(RECEIPT_LOCAL_VERS <= version && version <= RECEIPT_PROTO) )
             throw new SOXPacketException(
                  "Invalid version number {" +
-                 RECEIPT_LOCAL_VERS + "-" + RECEIPT_PROTO + "} != " + v);
+                 RECEIPT_LOCAL_VERS + "-" + RECEIPT_PROTO + "} != " + version);
 
-        if (v >= RECEIPT_PROTO)
+        flags = 0;
+        if (version >= RECEIPT_PROTO)
             flags = dis.readLong();
 
         //
@@ -463,6 +456,8 @@
         depositRequestData = readByteArray(dis);
         depositRequest = new DepositRequest(depositRequestData);
 
+        exPaymentData = null;
+        exPayment = null;
         if (version >= RECEIPT_PROTO && isWithdrawalReceipt())
         {
             exPaymentData = readByteArray(dis);
@@ -590,21 +585,60 @@
 
     public boolean equals(Object object)
     {
-        Receipt other = null;
-
-        if (object instanceof Receipt)
-            other = (Receipt)object;
-        else
+        if ( !(object instanceof Receipt) )
             return false;
-        logmsg("Comparing receipts");
+
+        Receipt other = (Receipt)object;
+
+//System.err.println("2");
         if (!(xid.equals(other.getTransactionId())))
         {
             logmsg("Receipts are not the same.. " + xid + " != " +
                    other.getTransactionId());
             return false;
         }
+
+//System.err.println("2");
+        if (version != other.version)
+            return false;
+
+//System.err.println("2");
+        if (!(pid.equals(other.getPaymentId())))
+        {
+            logmsg("Receipts are not the same.. " + pid + " != " +
+                   other.getPaymentId());
+            return false;
+        }
+//System.err.println("2");
+        if (!(did.equals(other.getDepositId())))
+        {
+            logmsg("Receipts are not the same.. " + did + " != " +
+                   other.getDepositId());
+            return false;
+        }
+
+//System.err.println("1: " + flags + " " + other.flags);
+        if (flags != other.flags)
+            return false;
+        if (qty != other.qty)
+            return false;
+        if (timestamp != other.timestamp)
+            return false;
+
+        if (!(item.equals(other.item)))
+            return false;
+        if (!(tgt.equals(other.tgt)))
+            return false;
+        if (!(src.equals(other.src)))
+            return false;
+
+        if (!Utils.byteEquals(depositRequestData, other.depositRequestData))
+            return false;
+        if (!Utils.byteEquals(exPaymentData, other.exPaymentData))
+            return false;
+        if (!Utils.byteEquals(sig, other.sig))
+            return false;
 
-        logmsg("Receipts are the same");
         return true;
     }