[Webfunds-commits] java/webfunds/ricardian Contract.java

Ian Grigg iang@cypherpunks.ai
Fri, 6 Apr 2001 18:36:42 -0400 (AST)


iang        01/04/06 18:36:42

  Modified:    webfunds/ricardian Contract.java
  Log:
  1. Moved over to webfunds.util.IniFileReader and FormattedFileException.
  2. All units of account/contracts utilities are now in Units, not Support.
  3. Made getServerCert() public as it is needed to build Server objects
     (to be done in webfunds.sox.server & webfunds.sox.value in new code).

Revision  Changes    Path
1.53      +28 -42    java/webfunds/ricardian/Contract.java

Index: Contract.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/ricardian/Contract.java,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- Contract.java	2001/03/18 23:23:12	1.52
+++ Contract.java	2001/04/06 22:36:41	1.53
@@ -1,4 +1,4 @@
-/* $Id: Contract.java,v 1.52 2001/03/18 23:23:12 iang Exp $
+/* $Id: Contract.java,v 1.53 2001/04/06 22:36:41 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -39,9 +39,12 @@
 
 import webfunds.util.Armoury;
 
+import webfunds.util.IniFileReader;
+import webfunds.util.FormattedFileException;
+import webfunds.util.Hex;
+import webfunds.util.Panic;
+
 import webfunds.utils.Debug;
-import webfunds.utils.Hex;
-import webfunds.utils.Panic;
 
 import webfunds.sox.Crypto;
 import webfunds.sox.ItemId;
@@ -141,11 +144,15 @@
          *  be illegal in the contract itself, so there should be no
          *  conflict?
          */
-        fields = new IniFileReader(localData);
-        fields.addByteArray(contractData);
+        try {
+            fields = new IniFileReader(localData);
+            fields.addByteArray(contractData);
+            // overrides contract if set by appl ??
+            myFile = new IniFileReader(yData);
+        } catch (FormattedFileException ex) {
+            throw new ContractException("FFEx: " + ex);
+        }
 
-        // overrides contract if set by appl ??
-        myFile = new IniFileReader(yData);
 
         //
         // Decide the sort of canonical hash from the local file.
@@ -203,10 +210,10 @@
         if (s != null && s.length() > 0)
         {
 // System.err.println("got new power: " + s);
-            int p = Support.powerInt(s);
+            int p = Units.powerInt(s);
 // System.err.println("set new power: " + p);
             setPower(p);
-            this.factor = Support.power2factorDouble(p);
+            this.factor = Units.power2factorDouble(p);
             return ;
         }
 
@@ -236,7 +243,7 @@
            return decimalFormatPattern;
 
         int power = getPower();
-        decimalFormatPattern = Support.power2DecimalFormatPattern(power);
+        decimalFormatPattern = Units.power2DecimalFormatPattern(power);
         return decimalFormatPattern ;
     }
 
@@ -325,7 +332,7 @@
         Base64Coder b64 = new Base64Coder();
         String s = b64.encode(hash);
         byte b[]  = b64.decode(s);
-        if (!Support.equals(b, hash))
+        if (!webfunds.util.Support.equals(b, hash))
             throw new RuntimeException("Base64 failed: " +
                       name + " ==> " + fileName + " ==> " + Hex.data2hex(b));
         s = s.replace('/', '_').trim();
@@ -786,7 +793,13 @@
     public static int getType(byte[] contractData)
         throws ContractException
     {
-        IniFileReader ini = new IniFileReader(contractData);
+        IniFileReader ini;
+        try {
+            ini = new IniFileReader(contractData);
+        } catch (FormattedFileException ex) {
+            throw new ContractException("FFEx: " + ex);
+        }
+
         String type = ini.getSectionItemValue("issue", "type");
         if(CURRENCY_WORD.equalsIgnoreCase(type))
             return CURRENCY_TYPE;
@@ -944,7 +957,7 @@
      *  The verification capability of this cert should authenticate
      *  the server that is used (as indicated in the local file).
      */
-    protected Certificate getServerCert()
+    public Certificate getServerCert()
         throws ContractException
     {
         // this is what we should do:
@@ -956,13 +969,11 @@
 
         // deprecate this with the DigiGold.asc V1.3 contract
         String text = getField(SECT_KEYS, fieldName);
-//logmsg("ok, got " + text + " from " + fieldName);
         if (text == null || text.length() == 0)
         {
             fieldName = "servercertifiation";    // missing _, speeling mistake
             text = getField(SECT_KEYS, fieldName);
         }
-//logmsg("now got " + text + " from " + FS2);
         if (text == null || text.length() == 0)
             throw new ContractException(ContractException.KEY_SERVER,
                       "cert <" + FIELD_OPERATOR + "> is not present");
@@ -1016,7 +1027,7 @@
     {
         if (text == null || text.length() == 0)
             throw new ContractException(errno,
-                      "cert <" + name + "> is not present");
+                      "cert for <" + name + "> is empty");
 
         // twice?  Should be multiple times?  Once?
         int end = text.indexOf("- ");
@@ -1588,7 +1599,7 @@
             newIni = new IniFileReader(contract.localData);
             newIni.addByteArray(contractData);
             fields = newIni;
-        } catch (ContractException ex) {
+        } catch (FormattedFileException ex) {
             ex.printStackTrace(err());
             logmsg("cannot re-read contract? " + ex);
             throw new IOException("internal contract data is bad? " + ex);
@@ -1679,31 +1690,6 @@
         }
 
     }
-
-
-
-
-
-
-//// was public
-//    protected URL[] getSOXFileLocation()
-//    {
-//        URL[] retval = new URL[0];
-//        String[] strings = new String[0];
-//
-//        strings = getArray("local_server_file_url");
-//        retval = new URL[strings.length];
-//        for(int i = 0; i < retval.length; i++)
-//        {
-//            try {
-//                retval[i] = new URL(strings[i]);
-//            } catch(MalformedURLException mfex) {
-//                logmsg(mfex);
-//            }
-//        }
-//
-//        return retval;
-//    }