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

Ian Grigg iang@cypherpunks.ai
Wed, 11 Apr 2001 15:37:35 -0400 (AST)


iang        01/04/11 15:37:34

  Modified:    webfunds/sox/value StateReceiptStore.java
  Log:
  get pending from wrong store, of course couldn't find data
  also tidied up diags

Revision  Changes    Path
1.2       +38 -9     java/webfunds/sox/value/StateReceiptStore.java

Index: StateReceiptStore.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/value/StateReceiptStore.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StateReceiptStore.java	2001/03/26 03:29:53	1.1
+++ StateReceiptStore.java	2001/04/11 19:37:34	1.2
@@ -1,5 +1,5 @@
 /*
- * $Id: StateReceiptStore.java,v 1.1 2001/03/26 03:29:53 iang Exp $
+ * $Id: StateReceiptStore.java,v 1.2 2001/04/11 19:37:34 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -14,9 +14,11 @@
 import java.io.PrintWriter;
 import java.io.ByteArrayOutputStream;
 
-import webfunds.utils.Hex;
+import webfunds.util.Hex;
+import webfunds.util.Panic;
+import webfunds.util.Support;
+
 import webfunds.utils.Debug;
-import webfunds.utils.Panic;
 
 import webfunds.sox.Receipt;
 import webfunds.sox.AccountId;
@@ -39,18 +41,25 @@
     extends Debug
 {
 
+    static final String TAB = Store.TAB,
+                        fix = "sRecS= ",
+                        NL  = TAB + fix;
+
     Store store;
     static final String RECEIPTS_NAME = "Receipts";
     static final String PENDING = "Pending";
 
     public StateReceiptStore(Store store, PrintWriter bug)
     {
-        debug(bug);
+        super();
+        debug(bug, TAB + fix);
         init(store);
     }
 
     public StateReceiptStore(Store store)
     {
+        super();
+        debug(new PrintWriter(System.err, true), fix);
         init(store);
     }
 
@@ -146,7 +155,7 @@
         addReceipt(sub, receipt);
 
         //
-        // Remove the pending.
+        //  Remove the pending.
         //
         String pid = receipt.getPaymentId();
         removePending(pid, acct, item);
@@ -213,7 +222,7 @@
 
 
     /**
-     *  Get a receipts for (acct / item / pid).
+     *  Get a receipt for (acct / item / pid).
      *
      *  XXX: stored indexed with xid not pid, needs to search
      *
@@ -231,6 +240,9 @@
                 continue ;
 
             byte[] data = (byte[])sub.get(key);
+            if (data == null || data.length == 0)
+                throw new Panic("no data for key " + key);
+
             Receipt r;
             try {
                 r = new Receipt(data);
@@ -251,7 +263,10 @@
             if (PENDING.equals(key))
                 continue ;
 
-            byte[] data = (byte[])sub.get(key);
+            byte[] data = (byte[])pen.get(key);
+            if (data == null || data.length == 0)
+                throw new Panic("no data for key " + key);
+
             PendingReceipt p;
             try {
                 p = new PendingReceipt(data);
@@ -330,6 +345,8 @@
         throws StoreException
     {
         Store pen = getPen(acct, pending.item);
+// logmsg("XXX- got Store for " + acct.fp());
+// logmsg("XXX- " + store);
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         try {
@@ -337,7 +354,19 @@
         } catch (IOException ex) {
             throw new StoreException("dud pending: " + ex);
         }
-        pen.put(pending.transid, baos.toByteArray());
+
+        String key = pending.transid;
+        byte[] buf = baos.toByteArray();
+        if (buf == null || buf.length == 0)
+            throw new StoreException("nothing in buf for pending " + pending);
+// logmsg("XXX- key " + key + " "  + buf.length + " as Pending:" + NL + pending);
+
+        pen.put(key, buf);
+
+        byte[] checkBuf = (byte[])pen.get(key);
+        if (!Support.equals(checkBuf, buf))
+            throw new StoreException("could not recover pending " + pending
+                                     + "\n\n" + Hex.printable(checkBuf));
 
         if (store.checkErrors())
         {
@@ -355,7 +384,7 @@
     {
         Store pen = getPen(acct, item);
 
-//System.err.println("REMOVE: " + id + " ( " + acct + " / " + item + " )");
+// logmsg("XXX- REMOVE: " + id + " ( " + acct.fp() + " / " + item.fp() + " )");
         pen.remove(id);
         if (store.checkErrors())
         {