webfunds.sox
Class TokenPayment

java.lang.Object
  |
  +--webfunds.sox.Encodable
        |
        +--webfunds.sox.AbstractPayment
              |
              +--webfunds.sox.TokenPayment

public class TokenPayment
extends AbstractPayment

This class represents a token payment. A token payment consists of tokens, sometimes called coins, which at this level can be thought of as big unguessable numbers. These are created by collecting the tokens out of a database, or by acquiring them from a mint- enabled Issuer with a WithdrawalRequest. It may be useful for classes to derive from this one, in order to have different functionality. For example, it may be easier to derive from this class for the various blinded methods than to have another class. Or maybe not.

See Also:
Serialized Form

Field Summary
protected  AccountId source
          The account from which the payment was drawn.
static int TOKEN_SUBVERSION
          The sub version number for this payment structure (*NOT* the super packet type number).
static int TOKEN_TYPE
          The type of payment of this class.
protected  Token[] tokens
          List of Tokens.
 
Fields inherited from class webfunds.sox.AbstractPayment
desc, item, paymentId, PF_VERSION, qty, SINGLETON_VERSION, subversion, type, version
 
Constructor Summary
TokenPayment(byte[] paymentData)
          Construct a payment object from a byte array that was previously returned from the encode() method of a payment object.
TokenPayment(java.io.InputStream is)
          Construct a payment object an input stream, where the data was previously returned from the encode() method of a payment object.
TokenPayment(java.lang.String pid, AccountId source, ItemId item, Token[] tokens, byte[] desc)
          Create a token payment from an array of tokens.
 
Method Summary
 long calculateQuantity()
          Count up the total Quantity that the tokens CLAIM to represent.
protected static void cycle()
           
 void decode(java.io.InputStream is)
          Update this payment object with the values from a payment encoded as a byte array (such as previously returned from the encode() method of a payment object).
 void encode(java.io.OutputStream os)
          Encode a payment as a byte array, suitable for sending to third parties for depositing.
 boolean equals(java.lang.Object obj)
           
static TokenPayment example()
           
static TokenPayment example(Token[] tokens)
           
 AccountId getSource()
          Get the account from which the transaction is drawn
 Token[] getTokens()
          Get the tokens within the payment
 int getType()
          The type of payment of this class.
protected static void input()
           
 boolean isSigned()
          Check to see if this payment is signed, always false on a token payment? This may not be the case, the tokens themselves may may be signed.
static void main(java.lang.String[] args)
           
protected static void output()
           
protected static void readWrite()
           
 void setId(java.lang.String id)
          Set the paymentId, so that you can strip it clean on export.
 void setSource(AccountId id)
           
 java.lang.String toString()
           
 
Methods inherited from class webfunds.sox.AbstractPayment
getDesc, getId, getItem, getQty, getSubVersion, getTarget, getValidFrom, getValidTill, getVersion, isBearer, vString
 
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

TOKEN_TYPE

public static final int TOKEN_TYPE
The type of payment of this class. See the PaymentFactory for the other types.

TOKEN_SUBVERSION

public static final int TOKEN_SUBVERSION
The sub version number for this payment structure (*NOT* the super packet type number).

source

protected AccountId source
The account from which the payment was drawn. This is meaningless in a token concept, just here for informational purposes. A client would probably strip this on sending it out.

tokens

protected Token[] tokens
List of Tokens.
Constructor Detail

TokenPayment

public TokenPayment(java.lang.String pid,
                    AccountId source,
                    ItemId item,
                    Token[] tokens,
                    byte[] desc)
Create a token payment from an array of tokens. An empty or null array is not supported, it generates an error from the Issuer. In the time-honoured SOX tradition, a zero payment can be made with a zero-valued token. The item is indicated so that a pointer to a valid SOXServer can be determined at the receiving end. There can only be one item in each TP. Validity times are ignored ofr now, although token systems do have times involved to slice the coin float into batches.
Parameters:
source - the source account, can be empty / null
item - the item for which the payment is for
desc - a description of what this payment is for (null ==> empty)
tokens - an array of tokens, cannot be null or contain nulls, may be empty
pid - identifier for local storage only

TokenPayment

public TokenPayment(byte[] paymentData)
             throws SOXPacketException
Construct a payment object from a byte array that was previously returned from the encode() method of a payment object.
Parameters:
paymentData - the previosly encoded payment

TokenPayment

public TokenPayment(java.io.InputStream is)
             throws SOXPacketException
Construct a payment object an input stream, where the data was previously returned from the encode() method of a payment object.
Parameters:
is - the input stream from which to read the payment data
Method Detail

getType

public int getType()
Description copied from interface: Value
The type of payment of this class. See PaymentFactory for types.
Overrides:
getType in class AbstractPayment

getSource

public AccountId getSource()
Get the account from which the transaction is drawn
Overrides:
getSource in class AbstractPayment

setSource

public void setSource(AccountId id)

getTokens

public Token[] getTokens()
Get the tokens within the payment

setId

public void setId(java.lang.String id)
Set the paymentId, so that you can strip it clean on export.

calculateQuantity

public long calculateQuantity()
Count up the total Quantity that the tokens CLAIM to represent.
Returns:
a claimed total quantity

isSigned

public boolean isSigned()
Check to see if this payment is signed, always false on a token payment? This may not be the case, the tokens themselves may may be signed.
Returns:
boolean false (no signature on a token payment)

decode

public void decode(java.io.InputStream is)
            throws java.io.IOException,
                   SOXPacketException
Update this payment object with the values from a payment encoded as a byte array (such as previously returned from the encode() method of a payment object).
Overrides:
decode in class AbstractPayment
Parameters:
paymentData - the previously encoded payment

encode

public void encode(java.io.OutputStream os)
            throws java.io.IOException
Encode a payment as a byte array, suitable for sending to third parties for depositing.
Overrides:
encode in class AbstractPayment
Returns:
byte[] the payment in encoded form

toString

public java.lang.String toString()
Overrides:
toString in class AbstractPayment

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class AbstractPayment

example

public static TokenPayment example(Token[] tokens)

example

public static TokenPayment example()

main

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

cycle

protected static void cycle()
                     throws java.lang.Exception

output

protected static void output()
                      throws java.lang.Exception

readWrite

protected static void readWrite()
                         throws java.lang.Exception

input

protected static void input()
                     throws java.lang.Exception