public class PaymentChannelClientConnection extends Object
Constructor and Description |
---|
PaymentChannelClientConnection(InetSocketAddress server,
int timeoutSeconds,
Wallet wallet,
ECKey myKey,
Coin maxValue,
String serverId)
Attempts to open a new connection to and open a payment channel with the given host and port, blocking until the
connection is open.
|
PaymentChannelClientConnection(InetSocketAddress server,
int timeoutSeconds,
Wallet wallet,
ECKey myKey,
Coin maxValue,
String serverId,
long timeWindow)
Attempts to open a new connection to and open a payment channel with the given host and port, blocking until the
connection is open.
|
Modifier and Type | Method and Description |
---|---|
void |
disconnectWithoutSettlement()
Disconnects the network connection but doesn't request the server to settle the channel first (literally just
unplugs the network socket and marks the stored channel state as inactive).
|
ListenableFuture<PaymentChannelClientConnection> |
getChannelOpenFuture()
Gets a future which returns this when the channel is successfully opened, or throws an exception if there is
an error before the channel has reached the open state.
|
ListenableFuture<PaymentIncrementAck> |
incrementPayment(Coin size)
Increments the total value which we pay the server.
|
ListenableFuture<PaymentIncrementAck> |
incrementPayment(Coin size,
com.google.protobuf.ByteString info)
Increments the total value which we pay the server.
|
void |
settle()
Closes the connection, notifying the server it should settle the channel by broadcasting the most recent payment
transaction.
|
PaymentChannelClientState |
state()
Gets the
PaymentChannelClientState object which stores the current state of the connection with the
server. |
public PaymentChannelClientConnection(InetSocketAddress server, int timeoutSeconds, Wallet wallet, ECKey myKey, Coin maxValue, String serverId) throws IOException, ValueOutOfRangeException
PaymentChannelClient.DEFAULT_TIME_WINDOW
seconds. If the server proposes a longer time the channel will be closed.server
- The host/port pair where the server is listening.timeoutSeconds
- The connection timeout and read timeout during initialization. This should be large enough
to accommodate ECDSA signature operations and network latency.wallet
- The wallet which will be paid from, and where completed transactions will be committed.
Must already have a StoredPaymentChannelClientStates
object in its extensions set.myKey
- A freshly generated keypair used for the multisig contract and refund output.maxValue
- The maximum value this channel is allowed to requestserverId
- A unique ID which is used to attempt reopening of an existing channel.
This must be unique to the server, and, if your application is exposing payment channels to some
API, this should also probably encompass some caller UID to avoid applications opening channels
which were created by others.IOException
- if there's an issue using the network.ValueOutOfRangeException
- if the balance of wallet is lower than maxValue.public PaymentChannelClientConnection(InetSocketAddress server, int timeoutSeconds, Wallet wallet, ECKey myKey, Coin maxValue, String serverId, long timeWindow) throws IOException, ValueOutOfRangeException
server
- The host/port pair where the server is listening.timeoutSeconds
- The connection timeout and read timeout during initialization. This should be large enough
to accommodate ECDSA signature operations and network latency.wallet
- The wallet which will be paid from, and where completed transactions will be committed.
Must already have a StoredPaymentChannelClientStates
object in its extensions set.myKey
- A freshly generated keypair used for the multisig contract and refund output.maxValue
- The maximum value this channel is allowed to requestserverId
- A unique ID which is used to attempt reopening of an existing channel.
This must be unique to the server, and, if your application is exposing payment channels to some
API, this should also probably encompass some caller UID to avoid applications opening channels
which were created by others.timeWindow
- The time in seconds, relative to now, on how long this channel should be kept open.IOException
- if there's an issue using the network.ValueOutOfRangeException
- if the balance of wallet is lower than maxValue.public ListenableFuture<PaymentChannelClientConnection> getChannelOpenFuture()
Gets a future which returns this when the channel is successfully opened, or throws an exception if there is an error before the channel has reached the open state.
After this future completes successfully, you may call
incrementPayment(Coin)
or incrementPayment(Coin, com.google.protobuf.ByteString)
to begin paying the server.
public ListenableFuture<PaymentIncrementAck> incrementPayment(Coin size) throws ValueOutOfRangeException, IllegalStateException
size
- How many satoshis to increment the payment by (note: not the new total).ValueOutOfRangeException
- If the size is negative or would pay more than this channel's total value
(state()
.getTotalValue())IllegalStateException
- If the channel has been closed or is not yet open
(see getChannelOpenFuture()
for the second)public ListenableFuture<PaymentIncrementAck> incrementPayment(Coin size, com.google.protobuf.ByteString info) throws ValueOutOfRangeException, IllegalStateException
size
- How many satoshis to increment the payment by (note: not the new total).info
- Information about this payment increment, used to extend this protocol.ValueOutOfRangeException
- If the size is negative or would pay more than this channel's total value
(state()
.getTotalValue())IllegalStateException
- If the channel has been closed or is not yet open
(see getChannelOpenFuture()
for the second)public PaymentChannelClientState state()
Gets the PaymentChannelClientState
object which stores the current state of the connection with the
server.
Note that if you call any methods which update state directly the server will not be notified and channel initialization logic in the connection may fail unexpectedly.
public void settle()
public void disconnectWithoutSettlement()
Copyright © 2014. All rights reserved.