webfunds.sox
Class ValueAccount

java.lang.Object
  |
  +--webfunds.sox.Encodable
        |
        +--webfunds.sox.SubAccount
              |
              +--webfunds.sox.ValueAccount

public class ValueAccount
extends SubAccount

ValueAccount does SOX standard transactions such as deposit. This is the class to emulate if you wish to extend SOX request types.

See Also:
Serialized Form

Field Summary
static byte[] CANCEL_DESC
           
 
Fields inherited from class webfunds.sox.SubAccount
acct, ACTIVE, FROZEN, issuer, itemId, NEW, REGISTERED, reqNo, RETRY, status
 
Constructor Summary
ValueAccount(byte[] d)
           
ValueAccount(java.io.InputStream is)
           
ValueAccount(ItemId it)
          Create a new ValueAccount object.
 
Method Summary
 MailItem[] cancel(Payment payment)
          Cancel this payment.
 MailItem[] cancel(java.lang.String paymentid)
          Cancel a payment that had a particular id.
protected  MailItem[] cancelFromPayment(Payment cancel)
          Cancel using the payment supplied.
 Payment createPayment(AccountId target, long qty, byte[] desc, boolean changekey, long from, long till, java.lang.String pid)
          Create a payment, with all params specified.
 Payment createPayment(AccountId target, long qty, byte[] desc, long validity)
          Create a payment valid from now (for how long specified)
 Payment createPayment(AccountId target, long qty, byte[] desc, long from, long validity)
          Create a payment, valid from when specified and for how long specified
 Payment createPayment(AccountId target, long qty, java.lang.String desc)
          Create a payment valid from now for next 5 days.
 TokenPayment createTokenPayment(Token[] tokens, byte[] desc, java.lang.String pid)
          Create a proto token payment.
 MailItem[] deposit(AbstractPayment payment, java.lang.String desc, java.lang.String did)
          Deposit a payment.
protected  MailItem[] doCancelGetMail(DepositRequest req)
          Do the cancel and look at the error.
protected  DepositReply doDeposit(DepositRequest req)
          Sort out exceptions.
protected  MailItem[] doDepositGetMail(DepositRequest req, boolean retry, boolean myDID)
          Convert the deposit request into a receipt.
static ValueAccount example()
           
static void main(java.lang.String[] args)
           
protected static void tryit(ValueAccount p)
           
 MailItem[] withdraw(AbstractPayment payment, AbstractPayment proto, java.lang.String desc, java.lang.String did)
          Withdraw a payment, paying with another payment.
 
Methods inherited from class webfunds.sox.SubAccount
adjustTime, adjustTime, checkFrozen, checkNet, decode, delete, doRequest, doRequest, encode, equals, fp, freeze, getAccount, getIssuer, getItemId, getStatus, init, isActive, isFrozen, isNew, isRegistered, isRetry, logmsg, nym, register, requestExtra, setAccount, setIssuer, toString, update
 
Methods inherited from class webfunds.sox.Encodable
decode, encode, readByteArray, readCertificate, readProperties, readString, writeByteArray, writeCertificate, writeProperties, writeString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CANCEL_DESC

public static final byte[] CANCEL_DESC
Constructor Detail

ValueAccount

public ValueAccount(ItemId it)
Create a new ValueAccount object. A ValueAccount manages the transactions for a particular item, which is (normally) a Ricardian contract hash. A subaccount is normally part of an account, which holds the keys.
Parameters:
acct - the account that holds authentication keys
itemid - the identifier for this subaccount

ValueAccount

public ValueAccount(byte[] d)
             throws SOXPacketException

ValueAccount

public ValueAccount(java.io.InputStream is)
             throws SOXPacketException
Method Detail

deposit

public MailItem[] deposit(AbstractPayment payment,
                          java.lang.String desc,
                          java.lang.String did)
                   throws SOXSubAccountException,
                          SOXLaterException,
                          SOXKeyException,
                          SOXArgsException,
                          SOXDepositException
Deposit a payment. The deposit is what makes this a ValueAccount, over the top of the standard SOXAccount.
Parameters:
payment - to deposit
desc - is binary description
did - is a suggested idempotent Id to use, ignore if invalid
Throws:
SOXArgsException - if item in payment is invalid
SOXLaterException - if there is no ability to talk to the server
SOXSubAccountException - if something goes wrong with access
SOXKeyException - if something goes wrong with signing

withdraw

public MailItem[] withdraw(AbstractPayment payment,
                           AbstractPayment proto,
                           java.lang.String desc,
                           java.lang.String did)
                    throws SOXSubAccountException,
                           SOXLaterException,
                           SOXKeyException,
                           SOXArgsException,
                           SOXDepositException
Withdraw a payment, paying with another payment. This is similar to Deposit, but involves two payments. The first pays for the second, which latter comes back signed.
Parameters:
payment - that pays for proto withdrawal
proto - is the tokens for signing
desc - is a binary description
did - is a suggested idempotent Id to use, ignore if invalid
Throws:
SOXArgsException - if item in payment is invalid
SOXLaterException - if there is no ability to talk to the server
SOXSubAccountException - if something goes wrong with access
SOXKeyException - if something goes wrong with signing

doDepositGetMail

protected MailItem[] doDepositGetMail(DepositRequest req,
                                      boolean retry,
                                      boolean myDID)
                               throws SOXSubAccountException,
                                      SOXDepositException,
                                      SOXLaterException,
                                      SOXKeyException
Convert the deposit request into a receipt. This catches a number of local snafus that are reported by the issuer, corrects them, and retries. As there are a number of issuers within this account, it is hard to keep track of who has registered where (bearing in mind that there are few issuers, and many contracts). So, we do it by feedback.
Parameters:
retry - true if this call is recursive
myDID - true if DID locally generated (and should be perfect)

doDeposit

protected DepositReply doDeposit(DepositRequest req)
                          throws SOXSubAccountException,
                                 SOXLaterException
Sort out exceptions. There's a problem here. No positive ack is delivered for failure, so can't tell whether it is positive failure or lost/failures.

cancel

public MailItem[] cancel(java.lang.String paymentid)
                  throws SOXSubAccountException,
                         SOXLaterException,
                         SOXKeyException,
                         SOXDepositException
Cancel a payment that had a particular id. By depositing a payment with that id, the id is blocked from further use.

cancel

public MailItem[] cancel(Payment payment)
                  throws SOXSubAccountException,
                         SOXLaterException,
                         SOXKeyException,
                         SOXDepositException
Cancel this payment. The full details are contained within. Creates a deposit with an empty payment with the same pid.
Parameters:
payment - the previously signed payment to cancel

cancelFromPayment

protected MailItem[] cancelFromPayment(Payment cancel)
                                throws SOXSubAccountException,
                                       SOXLaterException,
                                       SOXKeyException,
                                       SOXDepositException
Cancel using the payment supplied. Just send it. Creates a deposit with the payment.
Parameters:
payment - the previously signed payment to cancel

doCancelGetMail

protected MailItem[] doCancelGetMail(DepositRequest req)
                              throws SOXSubAccountException,
                                     SOXDepositException,
                                     SOXLaterException
Do the cancel and look at the error. Like doDepositGetMail() but handles cancel errors, which should be far fewer as it is all locally organised.

createPayment

public Payment createPayment(AccountId target,
                             long qty,
                             java.lang.String desc)
                      throws SOXSubAccountException
Create a payment valid from now for next 5 days.
Parameters:
target - the target account
qty - the number of items of which the payment is for
desc - a description of what this payment is for (optional) //@param boolean wether or not the payment is a rollover payment

createPayment

public Payment createPayment(AccountId target,
                             long qty,
                             byte[] desc,
                             long validity)
                      throws SOXSubAccountException
Create a payment valid from now (for how long specified)
Parameters:
target - the target account
qty - the number of items of which the payment is for
desc - a description of what this payment is for (optional) //@param boolean wether or not the payment is a rollover payment
validity - the payment is valid for validity seconds (from now)

createPayment

public Payment createPayment(AccountId target,
                             long qty,
                             byte[] desc,
                             long from,
                             long validity)
                      throws SOXSubAccountException
Create a payment, valid from when specified and for how long specified
Parameters:
target - the target account
qty - the number of items of which the payment is for
desc - a description of what this payment is for (optional) //@param boolean wether or not the payment is a rollover payment
validFrom - the time from which the payment is valid
validity - the time in seconds for which the payment is valid

createPayment

public Payment createPayment(AccountId target,
                             long qty,
                             byte[] desc,
                             boolean changekey,
                             long from,
                             long till,
                             java.lang.String pid)
                      throws SOXSubAccountException
Create a payment, with all params specified.
Parameters:
target - the target account
qty - the number of items of which the payment is for
desc - a description of what this payment is for (optional)
boolean - whether or not the payment is a rollover payment
from - the time from which the payment is valid
till - the time till which the payment is valid
pid - a unique payment identifier, replaced if empty

createTokenPayment

public TokenPayment createTokenPayment(Token[] tokens,
                                       byte[] desc,
                                       java.lang.String pid)
                                throws SOXSubAccountException
Create a proto token payment. A little different to normal payments - as there are no special needs like signing, so this call is not needed.
Parameters:
tokens - the individual tokens or coins that need withdrawing
desc - a description of what this payment is for (optional)
pid - a unique payment identifier, replaced if empty

example

public static ValueAccount example()

main

public static void main(java.lang.String[] args)

tryit

protected static void tryit(ValueAccount p)
                     throws java.lang.Exception