|
From: Pelle B. <pe...@us...> - 2004-03-22 19:49:31
|
Update of /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9416/src/java/org/neuclear/ledger Modified Files: Ledger.java Added Files: InsufficientFundsException.java Log Message: Added a verified transfer to neuclear-ledger. Added InsufficientFundsException to be thrown if transfer isnt verified. HeldTransfers also are now verified. --- NEW FILE: InsufficientFundsException.java --- package org.neuclear.ledger; /** * Created by IntelliJ IDEA. * User: pelleb * Date: Mar 22, 2004 * Time: 11:40:22 AM * To change this template use File | Settings | File Templates. */ public class InsufficientFundsException extends InvalidTransactionException { public InsufficientFundsException(final Ledger ledger, final String book, final double amount) { super(ledger, " Insufficient funds in account: " + book + " to cover the amount: " + amount); this.amount = amount; this.book = book; } public double getAmount() { return amount; } public String getBook() { return book; } private final double amount; private final String book; } Index: Ledger.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/Ledger.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Ledger.java 21 Mar 2004 00:48:36 -0000 1.10 --- Ledger.java 22 Mar 2004 17:33:02 -0000 1.11 *************** *** 4,7 **** --- 4,12 ---- * $Id$ * $Log$ + * Revision 1.11 2004/03/22 17:33:02 pelle + * Added a verified transfer to neuclear-ledger. + * Added InsufficientFundsException to be thrown if transfer isnt verified. + * HeldTransfers also are now verified. + * * Revision 1.10 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. *************** *** 132,151 **** * 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 id is returned as an identifier of the transaction. ! * * @param trans Transaction to perform ! * @return Unique ID */ public abstract PostedTransaction performTransaction(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 id is returned as an identifier of the transaction. * * @param trans Transaction to perform - * @return Unique ID */ ! public abstract PostedHeldTransaction performHeldTransaction(UnPostedHeldTransaction trans) throws UnBalancedTransactionException, LowlevelLedgerException, InvalidTransactionException; /** --- 137,187 ---- * 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; /** *************** *** 220,235 **** public abstract PostedHeldTransaction findHeldTransaction(String idstring) throws LowlevelLedgerException, UnknownTransactionException; - /** - * 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; - - public abstract PostedTransaction performCompleteHold(PostedHeldTransaction hold, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, TransactionExpiredException; public final PostedTransaction transfer(String req, String id, String from, String to, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException { --- 256,259 ---- *************** *** 244,255 **** } ! public final PostedHeldTransaction hold(String req, String id, String from, String to, Date expiry, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException { UnPostedHeldTransaction tran = new UnPostedHeldTransaction(req, id, comment, expiry); tran.addItem(from, -amount); tran.addItem(to, amount); ! return performHeldTransaction(tran); } ! public final PostedHeldTransaction hold(String from, String to, Date expiry, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException { return hold(CryptoTools.createRandomID(), CryptoTools.createRandomID(), from, to, expiry, amount, comment); } --- 268,290 ---- } ! 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); ! return performVerifiedTransfer(tran); ! } ! ! 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); ! return performHeldTransfer(tran); } ! public final PostedHeldTransaction hold(String from, String to, Date expiry, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, UnBalancedTransactionException, InsufficientFundsException { return hold(CryptoTools.createRandomID(), CryptoTools.createRandomID(), from, to, expiry, amount, comment); } |