com.google.bitcoin.protocols.channels
Class StoredPaymentChannelServerStates

java.lang.Object
  extended by com.google.bitcoin.protocols.channels.StoredPaymentChannelServerStates
All Implemented Interfaces:
WalletExtension

public class StoredPaymentChannelServerStates
extends Object
implements WalletExtension

Keeps track of a set of StoredServerChannels and expires them 2 hours before their refund transactions unlock.


Field Summary
static long CHANNEL_EXPIRE_OFFSET
          The offset between the refund transaction's lock time and the time channels will be automatically closed.
 
Constructor Summary
StoredPaymentChannelServerStates(Wallet wallet, TransactionBroadcaster broadcaster)
          Creates a new PaymentChannelServerStateManager and associates it with the given Wallet and TransactionBroadcaster which are used to complete and announce payment transactions.
 
Method Summary
 void closeChannel(StoredServerChannel channel)
          Closes the given channel using ServerConnectionEventHandler.closeChannel() and PaymentChannelServerState.close() to notify any connected client of channel closure and to complete and broadcast the latest payment transaction.
 void deserializeWalletExtension(Wallet containingWallet, byte[] data)
          Loads the contents of this object from the wallet.
 StoredServerChannel getChannel(Sha256Hash id)
          Gets the StoredServerChannel with the given channel id (ie contract transaction hash).
 String getWalletExtensionID()
          Returns a Java package/class style name used to disambiguate this extension from others.
 boolean isWalletExtensionMandatory()
          If this returns true, the mandatory flag is set when the wallet is serialized and attempts to load it without the extension being in the wallet will throw an exception.
 void putChannel(StoredServerChannel channel)
          Puts the given channel in the channels map and automatically closes it 2 hours before its refund transaction becomes spendable.
 byte[] serializeWalletExtension()
          Returns bytes that will be saved in the wallet.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CHANNEL_EXPIRE_OFFSET

public static final long CHANNEL_EXPIRE_OFFSET
The offset between the refund transaction's lock time and the time channels will be automatically closed. This defines a window during which we must get the last payment transaction verified, ie it should allow time for network propagation and for the payment transaction to be included in a block. Note that the channel expire time is measured in terms of our local clock, and the refund transaction's lock time is measured in terms of Bitcoin block header timestamps, which are allowed to drift up to two hours in the future, as measured by relaying nodes.

See Also:
Constant Field Values
Constructor Detail

StoredPaymentChannelServerStates

public StoredPaymentChannelServerStates(Wallet wallet,
                                        TransactionBroadcaster broadcaster)
Creates a new PaymentChannelServerStateManager and associates it with the given Wallet and TransactionBroadcaster which are used to complete and announce payment transactions.

Method Detail

closeChannel

public void closeChannel(StoredServerChannel channel)

Closes the given channel using ServerConnectionEventHandler.closeChannel() and PaymentChannelServerState.close() to notify any connected client of channel closure and to complete and broadcast the latest payment transaction.

Removes the given channel from this set of StoredServerChannels and notifies the wallet of a change to this wallet extension.


getChannel

public StoredServerChannel getChannel(Sha256Hash id)
Gets the StoredServerChannel with the given channel id (ie contract transaction hash).


putChannel

public void putChannel(StoredServerChannel channel)

Puts the given channel in the channels map and automatically closes it 2 hours before its refund transaction becomes spendable.

Because there must be only one, canonical StoredServerChannel per channel, this method throws if the channel is already present in the set of channels.


getWalletExtensionID

public String getWalletExtensionID()
Description copied from interface: WalletExtension
Returns a Java package/class style name used to disambiguate this extension from others.

Specified by:
getWalletExtensionID in interface WalletExtension

isWalletExtensionMandatory

public boolean isWalletExtensionMandatory()
Description copied from interface: WalletExtension
If this returns true, the mandatory flag is set when the wallet is serialized and attempts to load it without the extension being in the wallet will throw an exception. This method should not change its result during the objects lifetime.

Specified by:
isWalletExtensionMandatory in interface WalletExtension

serializeWalletExtension

public byte[] serializeWalletExtension()
Description copied from interface: WalletExtension
Returns bytes that will be saved in the wallet.

Specified by:
serializeWalletExtension in interface WalletExtension

deserializeWalletExtension

public void deserializeWalletExtension(Wallet containingWallet,
                                       byte[] data)
                                throws Exception
Description copied from interface: WalletExtension
Loads the contents of this object from the wallet.

Specified by:
deserializeWalletExtension in interface WalletExtension
Throws:
Exception

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2014. All rights reserved.