|
From: Pelle B. <pe...@us...> - 2004-03-31 23:23:03
|
Update of /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28687/src/java/org/neuclear/ledger Modified Files: Ledger.java LedgerController.java PostedHeldTransaction.java PostedTransaction.java Transaction.java TransactionExpiredException.java UnBalancedTransactionException.java UnPostedHeldTransaction.java UnPostedTransaction.java Added Files: ExceededHeldAmountException.java Log Message: Reworked the ID's of the transactions. The primary ID is now the request ID. Receipt ID's are optional and added using a separate set method. The various interactive passphrase agents now have shell methods for the new interactive approach. Index: PostedHeldTransaction.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/PostedHeldTransaction.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PostedHeldTransaction.java 25 Mar 2004 19:03:23 -0000 1.7 --- PostedHeldTransaction.java 31 Mar 2004 23:11:10 -0000 1.8 *************** *** 1,5 **** --- 1,7 ---- package org.neuclear.ledger; + import java.util.ArrayList; import java.util.Date; + import java.util.List; /** *************** *** 18,21 **** --- 20,44 ---- } + public List getAdjustedItems(final double amount) throws ExceededHeldAmountException, UnBalancedTransactionException { + final double origAmount = getAmount(); + if (amount > origAmount) + throw new ExceededHeldAmountException(this, amount); + final List ol = getItemList(); + + final List nl = new ArrayList(ol.size()); + + final double ratio = amount / origAmount; + double balance = 0; + for (int i = 0; i < ol.size(); i++) { + TransactionItem item = (TransactionItem) ol.get(i); + final double itemamount = item.getAmount() * ratio; + nl.add(new TransactionItem(item.getBook(), itemamount)); + balance += itemamount; + } + if (balance != 0) + throw new UnBalancedTransactionException(null, this, balance); + return nl; + } + final private Date expiryTime; Index: Ledger.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/Ledger.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Ledger.java 25 Mar 2004 16:44:22 -0000 1.14 --- Ledger.java 31 Mar 2004 23:11:10 -0000 1.15 *************** *** 4,7 **** --- 4,12 ---- * $Id$ * $Log$ + * Revision 1.15 2004/03/31 23:11:10 pelle + * Reworked the ID's of the transactions. The primary ID is now the request ID. + * Receipt ID's are optional and added using a separate set method. + * The various interactive passphrase agents now have shell methods for the new interactive approach. + * * Revision 1.14 2004/03/25 16:44:22 pelle * Added getTestBalance() and isBalanced() to Ledger to see if ledger is balanced. *************** *** 270,273 **** --- 275,280 ---- public abstract PostedHeldTransaction findHeldTransaction(String idstring) throws LowlevelLedgerException, UnknownTransactionException; + public abstract void setReceiptId(String id, String receipt) throws LowlevelLedgerException, UnknownTransactionException; + public abstract double getTestBalance() throws LowlevelLedgerException; *************** *** 276,281 **** } ! public final PostedTransaction transfer(String req, String id, String from, String to, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException { ! UnPostedTransaction tran = new UnPostedTransaction(req, id, comment); tran.addItem(from, -amount); tran.addItem(to, amount); --- 283,288 ---- } ! public final PostedTransaction transfer(String req, String from, String to, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException { ! UnPostedTransaction tran = new UnPostedTransaction(req, comment); tran.addItem(from, -amount); tran.addItem(to, amount); *************** *** 284,292 **** public final PostedTransaction transfer(String from, String to, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException { ! return transfer(CryptoTools.createRandomID(), CryptoTools.createRandomID(), from, to, amount, comment); } ! public final PostedTransaction verifiedTransfer(String req, String id, String from, String to, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException, InsufficientFundsException { ! UnPostedTransaction tran = new UnPostedTransaction(req, id, comment); tran.addItem(from, -amount); tran.addItem(to, amount); --- 291,299 ---- public final PostedTransaction transfer(String from, String to, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException { ! return transfer(CryptoTools.createRandomID(), from, to, amount, comment); } ! public final PostedTransaction verifiedTransfer(String req, String from, String to, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException, InsufficientFundsException { ! UnPostedTransaction tran = new UnPostedTransaction(req, comment); tran.addItem(from, -amount); tran.addItem(to, amount); *************** *** 295,303 **** public final PostedTransaction verifiedTransfer(String from, String to, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException, InsufficientFundsException { ! return verifiedTransfer(CryptoTools.createRandomID(), CryptoTools.createRandomID(), from, to, amount, comment); } ! public final PostedHeldTransaction hold(String req, String id, String from, String to, Date expiry, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException, InsufficientFundsException { ! UnPostedHeldTransaction tran = new UnPostedHeldTransaction(req, id, comment, expiry); tran.addItem(from, -amount); tran.addItem(to, amount); --- 302,310 ---- public final PostedTransaction verifiedTransfer(String from, String to, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException, InsufficientFundsException { ! return verifiedTransfer(CryptoTools.createRandomID(), from, to, amount, comment); } ! public final PostedHeldTransaction hold(String req, String from, String to, Date expiry, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException, InsufficientFundsException { ! UnPostedHeldTransaction tran = new UnPostedHeldTransaction(req, comment, expiry); tran.addItem(from, -amount); tran.addItem(to, amount); *************** *** 308,312 **** if (getAvailableBalance(from) - amount < 0) throw new InsufficientFundsException(this, from, amount); ! return hold(CryptoTools.createRandomID(), CryptoTools.createRandomID(), from, to, expiry, amount, comment); } --- 315,319 ---- if (getAvailableBalance(from) - amount < 0) throw new InsufficientFundsException(this, from, amount); ! return hold(CryptoTools.createRandomID(), from, to, expiry, amount, comment); } Index: LedgerController.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/LedgerController.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LedgerController.java 29 Mar 2004 23:43:29 -0000 1.1 --- LedgerController.java 31 Mar 2004 23:11:10 -0000 1.2 *************** *** 1,4 **** --- 1,6 ---- package org.neuclear.ledger; + import java.util.Date; + /* NeuClear Distributed Transaction Clearing Platform *************** *** 21,24 **** --- 23,31 ---- $Id$ $Log$ + Revision 1.2 2004/03/31 23:11:10 pelle + Reworked the ID's of the transactions. The primary ID is now the request ID. + Receipt ID's are optional and added using a separate set method. + The various interactive passphrase agents now have shell methods for the new interactive approach. + Revision 1.1 2004/03/29 23:43:29 pelle The servlets now work and display the ledger contents. *************** *** 31,43 **** * Time: 9:35:30 PM */ ! public class LedgerController { ! public Ledger add(String id){ ! return null; ! } ! public Ledger get(String id) { ! return null; ! } ! public boolean exists(String id){ ! return false; ! } } --- 38,162 ---- * Time: 9:35:30 PM */ ! public abstract class LedgerController { ! public abstract void createLedger(String id); ! ! public abstract boolean ledgerExists(String id); ! ! /** ! * The basic interface for creating Transactions in the database. ! * The implementing class takes this transacion information and stores it with an automatically generated uniqueid. ! * ! * @param trans Transaction to perform ! * @return The reference to the transaction ! */ ! public abstract PostedTransaction performTransaction(UnPostedTransaction trans) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException; ! ! /** ! * Similar to a transaction but guarantees that there wont be any negative balances left after the transaction. ! * ! * @param trans Transaction to perform ! * @return The reference to the transaction ! */ ! public abstract PostedTransaction performVerifiedTransfer(UnPostedTransaction trans) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException; ! ! /** ! * The basic interface for creating Transactions in the database. ! * The implementing class takes this transacion information and stores it with an automatically generated uniqueid. ! * This transaction guarantees to not leave a negative balance in any account. ! * ! * @param trans Transaction to perform ! */ ! public abstract PostedHeldTransaction performHeldTransfer(UnPostedHeldTransaction trans) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException; ! ! /** ! * Cancels a Held Transaction. ! * ! * @param hold ! * @throws org.neuclear.ledger.LowlevelLedgerException ! * ! * @throws org.neuclear.ledger.UnknownTransactionException ! * ! */ ! public abstract void performCancelHold(PostedHeldTransaction hold) throws LowlevelLedgerException, UnknownTransactionException; ! ! /** ! * Completes a held transaction. Which means: ! * cancelling the hold and performing the transfer with the given updated amount and comment. ! * ! * @param hold HeldTransaction to complete ! * @param amount The updatd amount. It must be <= than the amount of the hold ! * @param comment ! * @return ! * @throws InvalidTransactionException ! * @throws LowlevelLedgerException ! * @throws TransactionExpiredException ! */ ! public abstract PostedTransaction performCompleteHold(PostedHeldTransaction hold, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, TransactionExpiredException, UnknownTransactionException; ! ! /** ! * Searches for a Transaction based on its Transaction ID ! * ! * @param id A valid ID ! * @return The Transaction object ! */ ! public abstract Date getTransactionTime(String id) throws LowlevelLedgerException, UnknownTransactionException, InvalidTransactionException, UnknownBookException; ! ! /** ! * Calculate the true accounting balance at a given time. This does not take into account any held transactions, thus may not necessarily ! * show the Available balance.<p> ! * Example sql for implementors: <pre> ! * select c.credit - d.debit from ! * ( ! * select sum(amount) as credit ! * from ledger ! * where transactiondate <= sysdate and end_date is null and credit= 'neu://BOB' ! * ) c, ! * ( ! * select sum(amount) as debit ! * from ledger ! * where transactiondate <= sysdate and end_date is null and debit= 'neu://BOB' ! * ) d ! * <p/> ! * </pre> ! * ! * @return the balance as a double ! */ ! ! public abstract double getBalance(String book) throws LowlevelLedgerException; ! ! /** ! * Calculate the available balance at a given time. This DOES take into account any held transactions. ! * Example sql for implementors: <pre> ! * select c.credit - d.debit from ! * ( ! * select sum(amount) as credit ! * from ledger ! * where transactiondate <= sysdate and (end_date is null or end_date>= sysdate) and credit= 'neu://BOB' ! * ) c, ! * ( ! * select sum(amount) as debit ! * from ledger ! * where transactiondate <= sysdate and end_date is null and debit= 'neu://BOB' ! * ) d ! * <p/> ! * </pre> ! * ! * @return the balance as a double ! */ ! ! public abstract double getAvailableBalance(String book) throws LowlevelLedgerException; ! ! /** ! * Searches for a Held Transaction based on its Transaction ID ! * ! * @param idstring A valid ID ! * @return The Transaction object ! */ ! public abstract PostedHeldTransaction findHeldTransaction(String idstring) throws LowlevelLedgerException, UnknownTransactionException; ! ! public abstract double getTestBalance() throws LowlevelLedgerException; ! ! public abstract void close() throws LowlevelLedgerException; ! ! } Index: Transaction.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/Transaction.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Transaction.java 23 Mar 2004 22:01:43 -0000 1.6 --- Transaction.java 31 Mar 2004 23:11:10 -0000 1.7 *************** *** 4,7 **** --- 4,12 ---- * $Id$ * $Log$ + * Revision 1.7 2004/03/31 23:11:10 pelle + * Reworked the ID's of the transactions. The primary ID is now the request ID. + * Receipt ID's are optional and added using a separate set method. + * The various interactive passphrase agents now have shell methods for the new interactive approach. + * * Revision 1.6 2004/03/23 22:01:43 pelle * Bumped version numbers for commons and xmlsig througout. *************** *** 69,75 **** */ public abstract class Transaction implements Serializable { ! protected Transaction(final String req, final String id, final String comment, List items) throws InvalidTransactionException { this.comment = comment; - this.id = id; this.req = req; this.items = items; --- 74,79 ---- */ public abstract class Transaction implements Serializable { ! protected Transaction(final String req, final String comment, List items) { this.comment = comment; this.req = req; this.items = items; *************** *** 85,92 **** ! public String getId() { ! return id; ! } ! public String getRequestId() { return req; --- 89,97 ---- ! /** ! * The ID of the Request. ! * ! * @return ! */ public String getRequestId() { return req; *************** *** 97,103 **** } private final String comment; - private final String id; private final String req; protected final List items; --- 102,120 ---- } + public final double getAmount() { + + double amount = 0; + for (int i = 0; i < items.size(); i++) { + TransactionItem item = (TransactionItem) items.get(i); + if (item.getAmount() >= 0) { + amount += item.getAmount(); + } + } + return amount; + } + private final String comment; private final String req; + protected final List items; Index: UnBalancedTransactionException.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/UnBalancedTransactionException.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** UnBalancedTransactionException.java 25 Mar 2004 19:03:23 -0000 1.3 --- UnBalancedTransactionException.java 31 Mar 2004 23:11:10 -0000 1.4 *************** *** 9,20 **** */ public final class UnBalancedTransactionException extends InvalidTransactionException { ! public UnBalancedTransactionException(final Ledger ledger, final UnPostedTransaction tran) { ! super(ledger, "Transaction was Unbalanced by: " + tran.getBalance()); transaction = tran; } ! private final UnPostedTransaction transaction; ! public final UnPostedTransaction getTransaction() { return transaction; } --- 9,20 ---- */ public final class UnBalancedTransactionException extends InvalidTransactionException { ! public UnBalancedTransactionException(final Ledger ledger, final Transaction tran, final double amount) { ! super(ledger, "Transaction was Unbalanced by: " + amount); transaction = tran; } ! private final Transaction transaction; ! public final Transaction getTransaction() { return transaction; } --- NEW FILE: ExceededHeldAmountException.java --- package org.neuclear.ledger; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: ExceededHeldAmountException.java,v 1.1 2004/03/31 23:11:10 pelle Exp $ $Log: ExceededHeldAmountException.java,v $ Revision 1.1 2004/03/31 23:11:10 pelle Reworked the ID's of the transactions. The primary ID is now the request ID. Receipt ID's are optional and added using a separate set method. The various interactive passphrase agents now have shell methods for the new interactive approach. */ /** * User: pelleb * Date: Mar 31, 2004 * Time: 9:33:02 PM */ public class ExceededHeldAmountException extends InvalidTransactionException { public ExceededHeldAmountException(final PostedHeldTransaction tran, final double amount) { super(null, "Invalid Amount for Held Transaction: " + amount + " is higher than held amount: " + tran.getAmount()); } } Index: UnPostedTransaction.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/UnPostedTransaction.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** UnPostedTransaction.java 21 Mar 2004 00:48:36 -0000 1.8 --- UnPostedTransaction.java 31 Mar 2004 23:11:10 -0000 1.9 *************** *** 8,11 **** --- 8,16 ---- * $Id$ * $Log$ + * Revision 1.9 2004/03/31 23:11:10 pelle + * Reworked the ID's of the transactions. The primary ID is now the request ID. + * Receipt ID's are optional and added using a separate set method. + * The various interactive passphrase agents now have shell methods for the new interactive approach. + * * Revision 1.8 2004/03/21 00:48:36 pelle * The problem with Enveloped signatures has now been fixed. It was a problem in the way transforms work. I have bandaided it, but in the future if better support for transforms need to be made, we need to rethink it a bit. Perhaps using the new crypto channel's in neuclear-commons. *************** *** 83,88 **** * @param comment */ ! public UnPostedTransaction(final String req, final String id, final String comment) throws InvalidTransactionException { ! super(req, id, comment, new ArrayList(2)); balance = 0; --- 88,93 ---- * @param comment */ ! public UnPostedTransaction(final String req, final String comment) throws InvalidTransactionException { ! super(req, comment, new ArrayList(2)); balance = 0; Index: TransactionExpiredException.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/TransactionExpiredException.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TransactionExpiredException.java 21 Mar 2004 00:48:36 -0000 1.3 --- TransactionExpiredException.java 31 Mar 2004 23:11:10 -0000 1.4 *************** *** 21,25 **** public final String getSubMessage() { ! return "Transaction: " + transaction.getId() + " expired: " + transaction.getExpiryTime(); } } --- 21,25 ---- public final String getSubMessage() { ! return "Transaction: " + transaction.getRequestId() + " expired: " + transaction.getExpiryTime(); } } Index: PostedTransaction.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/PostedTransaction.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PostedTransaction.java 25 Mar 2004 19:03:23 -0000 1.8 --- PostedTransaction.java 31 Mar 2004 23:11:10 -0000 1.9 *************** *** 8,11 **** --- 8,16 ---- * $Id$ * $Log$ + * Revision 1.9 2004/03/31 23:11:10 pelle + * Reworked the ID's of the transactions. The primary ID is now the request ID. + * Receipt ID's are optional and added using a separate set method. + * The various interactive passphrase agents now have shell methods for the new interactive approach. + * * Revision 1.8 2004/03/25 19:03:23 pelle * PostedTransaction and friend now verify the unpostedtransaction is balanced. *************** *** 80,92 **** */ public PostedTransaction(final UnPostedTransaction orig, final Date time) throws InvalidTransactionException, UnBalancedTransactionException { ! super(orig.getRequestId(), orig.getId(), orig.getComment(), orig.getItemList()); if (!orig.isBalanced()) ! throw new UnBalancedTransactionException(null, orig); this.transactionTime = time; } ! public PostedTransaction(final PostedHeldTransaction orig, final Date time, final double amount, final String comment) throws InvalidTransactionException { ! super(orig.getRequestId(), orig.getId(), comment, orig.getItemList()); this.transactionTime = time; } --- 85,97 ---- */ public PostedTransaction(final UnPostedTransaction orig, final Date time) throws InvalidTransactionException, UnBalancedTransactionException { ! super(orig.getRequestId(), orig.getComment(), orig.getItemList()); if (!orig.isBalanced()) ! throw new UnBalancedTransactionException(null, orig, orig.getBalance()); this.transactionTime = time; } ! public PostedTransaction(final PostedHeldTransaction orig, final Date time, final double amount, final String comment) throws ExceededHeldAmountException, UnBalancedTransactionException { ! super(orig.getRequestId(), comment, orig.getAdjustedItems(amount)); this.transactionTime = time; } *************** *** 96,101 **** --- 101,120 ---- } + /** + * The ID of the Receipt generated after a Transaction has been posted + * + * @return + */ + public String getReceiptId() { + return receipt; + } + + public void setReceiptId(String receipt) { + this.receipt = receipt; + } + private final Date transactionTime; + private String receipt; } Index: UnPostedHeldTransaction.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/UnPostedHeldTransaction.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** UnPostedHeldTransaction.java 21 Mar 2004 00:48:36 -0000 1.5 --- UnPostedHeldTransaction.java 31 Mar 2004 23:11:10 -0000 1.6 *************** *** 8,11 **** --- 8,16 ---- * $Id$ * $Log$ + * Revision 1.6 2004/03/31 23:11:10 pelle + * Reworked the ID's of the transactions. The primary ID is now the request ID. + * Receipt ID's are optional and added using a separate set method. + * The various interactive passphrase agents now have shell methods for the new interactive approach. + * * Revision 1.5 2004/03/21 00:48:36 pelle * The problem with Enveloped signatures has now been fixed. It was a problem in the way transforms work. I have bandaided it, but in the future if better support for transforms need to be made, we need to rethink it a bit. Perhaps using the new crypto channel's in neuclear-commons. *************** *** 70,75 **** * @param expiryTime */ ! public UnPostedHeldTransaction(final String req, final String id, final String comment, final Date expiryTime) throws InvalidTransactionException { ! super(req, id, comment); this.expiryTime = expiryTime; } --- 75,80 ---- * @param expiryTime */ ! public UnPostedHeldTransaction(final String req, final String comment, final Date expiryTime) throws InvalidTransactionException { ! super(req, comment); this.expiryTime = expiryTime; } |