[Webfunds-commits] java/webfunds/sox TokenPayment.java
Ian Grigg
iang@cypherpunks.ai
Thu, 30 Nov 2000 09:43:43 -0400 (AST)
iang 00/11/30 09:43:43
Modified: webfunds/sox TokenPayment.java
Log:
made the total quantity code into a method, so others can call it
(issuer doesn't want to believe this number, prefers to recalculate).
Revision Changes Path
1.3 +20 -3 java/webfunds/sox/TokenPayment.java
Index: TokenPayment.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/TokenPayment.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TokenPayment.java 2000/11/09 13:13:50 1.2
+++ TokenPayment.java 2000/11/30 13:43:42 1.3
@@ -1,5 +1,5 @@
/*
- * $Id: TokenPayment.java,v 1.2 2000/11/09 13:13:50 iang Exp $
+ * $Id: TokenPayment.java,v 1.3 2000/11/30 13:43:42 iang Exp $
*
* Copyright (c) Systemics Inc 1995-2000 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -125,14 +125,27 @@
if (tokens.length > 0x00FF)
throw new Panic("tokens array too long (unsigned byte length)");
- qty = 0;
+ qty = calculateQuantity();
+ }
+
+ /**
+ * Count up the total Quantity that the tokens CLAIM to represent.
+ * @return a claimed total quantity
+ */
+ public long calculateQuantity()
+ {
+ long q = 0;
for (int i = 0; i < tokens.length; i++)
{
Token tok = tokens[i];
if (tok == null)
throw new Panic("null token in array at position " + i);
- qty += tokens[i].getQty();
+ long p = tokens[i].getQty();
+ if (p < 0) // Tokens use log form, must be positive
+ throw new Panic("token " + i + ": qty " + p + " < 0");
+ q += p;
}
+ return q;
}
/**
@@ -218,6 +231,10 @@
tokens = (Token[]) new RandomToken[number];
for (int i = 0; i < number; i++)
tokens[i] = new RandomToken(dis);
+
+ long q = calculateQuantity();
+ if (q != qty)
+ throw new SOXPacketException("Invalid qty " + qty + " != " + q);
}
/**