public class PaymentChannelV1ClientState extends PaymentChannelClientState
PaymentChannelClientState.IncrementedPayment, PaymentChannelClientState.State
stateMachine, storedChannel, valueToMe
Constructor and Description |
---|
PaymentChannelV1ClientState(Wallet wallet,
ECKey myKey,
ECKey serverMultisigKey,
Coin value,
long expiryTimeInSeconds)
Creates a state object for a payment channel client.
|
Modifier and Type | Method and Description |
---|---|
Transaction |
getCompletedRefundTransaction()
Once the servers signature over the refund transaction has been received and provided using
provideRefundSignature(byte[], KeyParameter) then this
method can be called to receive the now valid and broadcastable refund transaction. |
Transaction |
getContract()
Returns the transaction that locks the money to the agreement of both parties.
|
protected Transaction |
getContractInternal()
Gets the contract without changing the state machine
|
protected Script |
getContractScript() |
protected long |
getExpiryTime() |
Transaction |
getIncompleteRefundTransaction()
Returns a partially signed (invalid) refund transaction that should be passed to the server.
|
int |
getMajorVersion() |
Coin |
getRefundTxFees()
Returns the fees that will be paid if the refund transaction has to be claimed because the server failed to settle
the channel properly.
|
protected Script |
getSignedScript()
Gets the script that is signed.
|
protected Multimap<PaymentChannelClientState.State,PaymentChannelClientState.State> |
getStateTransitions() |
Coin |
getTotalValue()
Gets the total value of this channel (ie the maximum payment possible)
|
protected Coin |
getValueToMe() |
void |
initiate(org.spongycastle.crypto.params.KeyParameter userKey)
Creates the initial multisig contract and incomplete refund transaction which can be requested at the appropriate
time using
getIncompleteRefundTransaction() and
getContract() . |
void |
provideRefundSignature(byte[] theirSignature,
org.spongycastle.crypto.params.KeyParameter userKey)
When the servers signature for the refund transaction is received, call this to verify it and sign the
complete refund ourselves.
|
checkNotExpired, disconnectFromChannel, editContractSendRequest, getState, getValueRefunded, getValueSpent, incrementPaymentBy, initiate, initWalletListeners, isSettlementTransaction, storeChannelInWallet, updateChannelInWallet, watchCloseConfirmations
public PaymentChannelV1ClientState(Wallet wallet, ECKey myKey, ECKey serverMultisigKey, Coin value, long expiryTimeInSeconds) throws VerificationException
PaymentChannelClientState.initiate()
after construction (to avoid creating objects for channels which are
not going to finish opening) and thus some parameters provided here are only used in
PaymentChannelClientState.initiate()
to create the Multisig contract and refund transaction.wallet
- a wallet that contains at least the specified amount of value.myKey
- a freshly generated private key for this channel.serverMultisigKey
- a public key retrieved from the server used for the initial multisig contractvalue
- how many satoshis to put into this contract. If the channel reaches this limit, it must be closed.expiryTimeInSeconds
- At what point (UNIX timestamp +/- a few hours) the channel will expireVerificationException
- If either myKey's pubkey or serverKey's pubkey are non-canonical (ie invalid)protected Multimap<PaymentChannelClientState.State,PaymentChannelClientState.State> getStateTransitions()
getStateTransitions
in class PaymentChannelClientState
public int getMajorVersion()
getMajorVersion
in class PaymentChannelClientState
public void initiate(@Nullable org.spongycastle.crypto.params.KeyParameter userKey) throws ValueOutOfRangeException, InsufficientMoneyException
getIncompleteRefundTransaction()
and
getContract()
. The way the contract is crafted can be adjusted by
overriding PaymentChannelV1ClientState#editContractSendRequest(org.bitcoinj.core.Wallet.SendRequest)
.
By default unconfirmed coins are allowed to be used, as for micropayments the risk should be relatively low.initiate
in class PaymentChannelClientState
userKey
- Key derived from a user password, needed for any signing when the wallet is encrypted.
The wallet KeyCrypter is assumed.ValueOutOfRangeException
- if the value being used is too small to be accepted by the networkInsufficientMoneyException
- if the wallet doesn't contain enough balance to initiatepublic Transaction getContract()
PaymentChannelClientState.incrementPaymentBy(Coin, KeyParameter)
to
start paying the server.getContract
in class PaymentChannelClientState
protected Transaction getContractInternal()
PaymentChannelClientState
getContractInternal
in class PaymentChannelClientState
protected Script getContractScript()
getContractScript
in class PaymentChannelClientState
protected Script getSignedScript()
PaymentChannelClientState
getSignedScript
in class PaymentChannelClientState
public Transaction getIncompleteRefundTransaction()
provideRefundSignature(byte[], KeyParameter)
with the result.public void provideRefundSignature(byte[] theirSignature, @Nullable org.spongycastle.crypto.params.KeyParameter userKey) throws VerificationException
When the servers signature for the refund transaction is received, call this to verify it and sign the complete refund ourselves.
If this does not throw an exception, we are secure against the loss of funds and can safely provide the server with the multi-sig contract to lock in the agreement. In this case, both the multisig contract and the refund transaction are automatically committed to wallet so that it can handle broadcasting the refund transaction at the appropriate time if necessary.
VerificationException
protected Coin getValueToMe()
getValueToMe
in class PaymentChannelClientState
protected long getExpiryTime()
getExpiryTime
in class PaymentChannelClientState
public Coin getRefundTxFees()
PaymentChannelClientState
PaymentChannelClientState.initiate()
getRefundTxFees
in class PaymentChannelClientState
public Transaction getCompletedRefundTransaction()
provideRefundSignature(byte[], KeyParameter)
then this
method can be called to receive the now valid and broadcastable refund transaction.public Coin getTotalValue()
getTotalValue
in class PaymentChannelClientState
Copyright © 2016. All rights reserved.