webfunds.token
Class Token

java.lang.Object
  |
  +--webfunds.sox.Encodable
        |
        +--webfunds.token.Token
Direct Known Subclasses:
TokenBuilder, TokenDead, TokenSigner, TokenSpender

public abstract class Token
extends Encodable

This class represents a token (a.k.a. coin) throughout its lifecycle. Token objects are usually created by means of a Withdrawal protocol between client and mint-capable SOXServer. They go through several phases, being potentially: proto signed blinded spent which are handled by extending classes as phases.

See Also:
Serialized Form

Field Summary
protected  long expiry
          Tokens commonly come from a batch that is identified with a series label or an expiry date.
protected  byte[] item
          The item that this token relates to.
protected  int log
          The quantity of the item that this token represents.
protected  int phase
           
static int PHASE_BUILDER
          The Phase of the Token structure: The Token Phase structure is the immediately extending one: e.g., TokenBuilder, TokenSigner, TokenSpender, TokenDead.
static int PHASE_DEAD
          The Phase of the Token structure: The Token Phase structure is the immediately extending one: e.g., TokenBuilder, TokenSigner, TokenSpender, TokenDead.
static int PHASE_SIGNER
          The Phase of the Token structure: The Token Phase structure is the immediately extending one: e.g., TokenBuilder, TokenSigner, TokenSpender, TokenDead.
static int PHASE_SPEND
          The Phase of the Token structure: The Token Phase structure is the immediately extending one: e.g., TokenBuilder, TokenSigner, TokenSpender, TokenDead.
protected  int phaseVersion
          The version number for Token Phase structure is defined by the phase.
static java.lang.String[] ps
           
protected  byte[] series
           
protected  int state
          The state that the token is the state machine within the phase.
protected  int subversion
          The version of the subclass Token that sets the type.
static int TOK_ORIGINAL
          The version number for Token structure: 0: current
protected  int type
          The type of token of this class, e.g., Wagner.
 
Constructor Summary
Token()
          Create an uninitialised token.
Token(byte[] buf)
          Construct a token object from a byte array that was previously returned from the encode() method of a token object.
Token(java.io.InputStream is)
          Construct a token object from data in an input stream, where the data was previously returned from the encode() method of a token object.
 
Method Summary
 void decode(java.io.InputStream is)
          Update this token object with the values from a token encoded as a byte array (such as previously returned from the encode() method of a token object).
 void encode(java.io.OutputStream os)
          Encode a token as a byte array, suitable for saving state.
 boolean equals(java.lang.Object obj)
           
 long getExpiry()
           
 byte[] getItem()
           
 int getLog()
           
 int getPhase()
           
 java.lang.String getPhaseString()
           
 int getPhaseVersion()
           
 long getQty()
          Note (1) that this may be derived information, the real token value may be encoded in the signature key or some other way.
 byte[] getSeries()
           
 int getState()
           
 int getSubVersion()
           
 int getType()
           
abstract  byte[] getUniqueId()
          Get the unique identifier that is used for checking against double-spending.
 int getVersion()
           
 boolean isBuilder()
           
 boolean isDead()
           
 boolean isSigner()
           
 boolean isSpender()
           
 boolean isValidPhase()
           
 void setState(int state)
           
 java.lang.String toString()
           
 java.lang.String vString()
           
 
Methods inherited from class webfunds.sox.Encodable
decode, encode, main, 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

TOK_ORIGINAL

public static final int TOK_ORIGINAL
The version number for Token structure: 0: current

PHASE_BUILDER

public static final int PHASE_BUILDER
The Phase of the Token structure: The Token Phase structure is the immediately extending one: e.g., TokenBuilder, TokenSigner, TokenSpender, TokenDead.

PHASE_SIGNER

public static final int PHASE_SIGNER
The Phase of the Token structure: The Token Phase structure is the immediately extending one: e.g., TokenBuilder, TokenSigner, TokenSpender, TokenDead.

PHASE_SPEND

public static final int PHASE_SPEND
The Phase of the Token structure: The Token Phase structure is the immediately extending one: e.g., TokenBuilder, TokenSigner, TokenSpender, TokenDead.

PHASE_DEAD

public static final int PHASE_DEAD
The Phase of the Token structure: The Token Phase structure is the immediately extending one: e.g., TokenBuilder, TokenSigner, TokenSpender, TokenDead.

phase

protected int phase

ps

public static final java.lang.String[] ps

phaseVersion

protected int phaseVersion
The version number for Token Phase structure is defined by the phase.

type

protected int type
The type of token of this class, e.g., Wagner. See Factory for current definitions.

subversion

protected int subversion
The version of the subclass Token that sets the type.

state

protected int state
The state that the token is the state machine within the phase. How it is set and advanced is up to the phase class. Only the low-order single unsigned byte is saved & restored.

log

protected int log
The quantity of the item that this token represents. Encoded in logarithm - base 2 of the quantity. Log Qty 0 0 1 1 2 2 3 4 4 8 and so forth. -1 could be used for "not stated", meaning it is encoded in the magic parts (by use of certain key, for example).

expiry

protected long expiry
Tokens commonly come from a batch that is identified with a series label or an expiry date. These are interpreted by the subclass, may be ignored.

series

protected byte[] series

item

protected byte[] item
The item that this token relates to. Normally a Ricardian hash.
Constructor Detail

Token

public Token()
Create an uninitialised token.

Token

public Token(byte[] buf)
      throws TokenPacketException
Construct a token object from a byte array that was previously returned from the encode() method of a token object.
Parameters:
token - the previously encoded token

Token

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

getVersion

public final int getVersion()

getPhase

public final int getPhase()

getPhaseString

public java.lang.String getPhaseString()

isValidPhase

public final boolean isValidPhase()

isBuilder

public final boolean isBuilder()

isSigner

public final boolean isSigner()

isSpender

public final boolean isSpender()

isDead

public final boolean isDead()

getPhaseVersion

public final int getPhaseVersion()

getType

public int getType()

getSubVersion

public int getSubVersion()

getState

public int getState()

setState

public void setState(int state)

getLog

public int getLog()

getQty

public long getQty()
Note (1) that this may be derived information, the real token value may be encoded in the signature key or some other way. Note (2) that the unit of account is not encoded within the token, the higher layer code should remember that. See Payments for the encoded Item (a.k.a. Ricardian Contract).
Returns:
quantity of the item that this token represents, being 0 - n representing which bit, or -1 if "not so encoded"

getExpiry

public long getExpiry()

getSeries

public byte[] getSeries()

getUniqueId

public abstract byte[] getUniqueId()
Get the unique identifier that is used for checking against double-spending. Normally called by server on depositing. Only makes sense if in PHASE_SIGNER or later? Or useful as id in all phases?
Parameters:
key - is the signer's public key (of the mint)

getItem

public byte[] getItem()

decode

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

encode

public void encode(java.io.OutputStream os)
            throws java.io.IOException
Encode a token as a byte array, suitable for saving state.
Overrides:
encode in class Encodable
Returns:
byte[] the token in encoded form

toString

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

vString

public java.lang.String vString()

equals

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