/** * Gets the canonical {@link PaymentChannelServerState} object for this channel, either by returning an existing one * or by creating a new one. * * @param wallet The wallet which holds the {@link PaymentChannelServerState} in which this is saved and which will * be used to complete transactions * @param broadcaster The {@link TransactionBroadcaster} which will be used to broadcast contract/payment transactions. */ public synchronized PaymentChannelServerState getOrCreateState(Wallet wallet, TransactionBroadcaster broadcaster) throws VerificationException { if (state == null) { switch (majorVersion) { case 1: state = new PaymentChannelV1ServerState(this, wallet, broadcaster); break; case 2: state = new PaymentChannelV2ServerState(this, wallet, broadcaster); break; default: throw new IllegalStateException("Invalid version number found"); } } checkArgument(wallet == state.wallet); return state; }
/** * Gets the canonical {@link PaymentChannelServerState} object for this channel, either by returning an existing one * or by creating a new one. * * @param wallet The wallet which holds the {@link PaymentChannelServerState} in which this is saved and which will * be used to complete transactions * @param broadcaster The {@link TransactionBroadcaster} which will be used to broadcast contract/payment transactions. */ public synchronized PaymentChannelServerState getOrCreateState(Wallet wallet, TransactionBroadcaster broadcaster) throws VerificationException { if (state == null) { switch (majorVersion) { case 1: state = new PaymentChannelV1ServerState(this, wallet, broadcaster); break; case 2: state = new PaymentChannelV2ServerState(this, wallet, broadcaster); break; default: throw new IllegalStateException("Invalid version number found"); } } checkArgument(wallet == state.wallet); return state; }
/** * Gets the canonical {@link PaymentChannelServerState} object for this channel, either by returning an existing one * or by creating a new one. * * @param wallet The wallet which holds the {@link PaymentChannelServerState} in which this is saved and which will * be used to complete transactions * @param broadcaster The {@link TransactionBroadcaster} which will be used to broadcast contract/payment transactions. */ public synchronized PaymentChannelServerState getOrCreateState(Wallet wallet, TransactionBroadcaster broadcaster) throws VerificationException { if (state == null) { switch (majorVersion) { case 1: state = new PaymentChannelV1ServerState(this, wallet, broadcaster); break; case 2: state = new PaymentChannelV2ServerState(this, wallet, broadcaster); break; default: throw new IllegalStateException("Invalid version number found"); } } checkArgument(wallet == state.wallet); return state; }
/** * Gets the canonical {@link PaymentChannelServerState} object for this channel, either by returning an existing one * or by creating a new one. * * @param wallet The wallet which holds the {@link PaymentChannelServerState} in which this is saved and which will * be used to complete transactions * @param broadcaster The {@link TransactionBroadcaster} which will be used to broadcast contract/payment transactions. */ public synchronized PaymentChannelServerState getOrCreateState(Wallet wallet, TransactionBroadcaster broadcaster) throws VerificationException { if (state == null) { switch (majorVersion) { case 1: state = new PaymentChannelV1ServerState(this, wallet, broadcaster); break; case 2: state = new PaymentChannelV2ServerState(this, wallet, broadcaster); break; default: throw new IllegalStateException("Invalid version number found"); } } checkArgument(wallet == state.wallet); return state; }
private PaymentChannelServerState makeServerState(TransactionBroadcaster broadcaster, Wallet wallet, ECKey serverKey, long time) { switch (versionSelector) { case VERSION_1: return new PaymentChannelV1ServerState(broadcaster, wallet, serverKey, time); case VERSION_2_ALLOW_1: case VERSION_2: return new PaymentChannelV2ServerState(broadcaster, wallet, serverKey, time); default: return null; } }
@GuardedBy("lock") private void receiveContractMessage(Protos.TwoWayChannelMessage msg) throws VerificationException { checkState(majorVersion == 1 || majorVersion == 2); checkState(step == InitStep.WAITING_ON_CONTRACT && msg.hasProvideContract()); log.info("Got contract, broadcasting and responding with CHANNEL_OPEN"); final Protos.ProvideContract providedContract = msg.getProvideContract(); if (majorVersion == 2) { state = new PaymentChannelV2ServerState(broadcaster, wallet, myKey, expireTime); checkState(providedContract.hasClientKey(), "ProvideContract didn't have a client key in protocol v2"); ((PaymentChannelV2ServerState)state).provideClientKey(providedContract.getClientKey().toByteArray()); } //TODO notify connection handler that timeout should be significantly extended as we wait for network propagation? final Transaction contract = wallet.getParams().getDefaultSerializer().makeTransaction(providedContract.getTx().toByteArray()); step = InitStep.WAITING_ON_MULTISIG_ACCEPTANCE; state.provideContract(contract) .addListener(new Runnable() { @Override public void run() { multisigContractPropogated(providedContract, contract.getHash()); } }, Threading.SAME_THREAD); }
@GuardedBy("lock") private void receiveContractMessage(Protos.TwoWayChannelMessage msg) throws VerificationException { checkState(majorVersion == 1 || majorVersion == 2); checkState(step == InitStep.WAITING_ON_CONTRACT && msg.hasProvideContract()); log.info("Got contract, broadcasting and responding with CHANNEL_OPEN"); final Protos.ProvideContract providedContract = msg.getProvideContract(); if (majorVersion == 2) { state = new PaymentChannelV2ServerState(broadcaster, wallet, myKey, expireTime); checkState(providedContract.hasClientKey(), "ProvideContract didn't have a client key in protocol v2"); ((PaymentChannelV2ServerState)state).provideClientKey(providedContract.getClientKey().toByteArray()); } //TODO notify connection handler that timeout should be significantly extended as we wait for network propagation? final Transaction contract = wallet.getParams().getDefaultSerializer().makeTransaction(providedContract.getTx().toByteArray()); step = InitStep.WAITING_ON_MULTISIG_ACCEPTANCE; state.provideContract(contract) .addListener(new Runnable() { @Override public void run() { multisigContractPropogated(providedContract, contract.getHash()); } }, Threading.SAME_THREAD); }
@GuardedBy("lock") private void receiveContractMessage(Protos.TwoWayChannelMessage msg) throws VerificationException { checkState(majorVersion == 1 || majorVersion == 2); checkState(step == InitStep.WAITING_ON_CONTRACT && msg.hasProvideContract()); log.info("Got contract, broadcasting and responding with CHANNEL_OPEN"); final Protos.ProvideContract providedContract = msg.getProvideContract(); if (majorVersion == 2) { state = new PaymentChannelV2ServerState(broadcaster, wallet, myKey, expireTime); checkState(providedContract.hasClientKey(), "ProvideContract didn't have a client key in protocol v2"); ((PaymentChannelV2ServerState)state).provideClientKey(providedContract.getClientKey().toByteArray()); } //TODO notify connection handler that timeout should be significantly extended as we wait for network propagation? final Transaction contract = wallet.getParams().getDefaultSerializer().makeTransaction(providedContract.getTx().toByteArray()); step = InitStep.WAITING_ON_MULTISIG_ACCEPTANCE; state.provideContract(contract) .addListener(new Runnable() { @Override public void run() { multisigContractPropogated(providedContract, contract.getHash()); } }, Threading.SAME_THREAD); }
@GuardedBy("lock") private void receiveContractMessage(Protos.TwoWayChannelMessage msg) throws VerificationException { checkState(majorVersion == 1 || majorVersion == 2); checkState(step == InitStep.WAITING_ON_CONTRACT && msg.hasProvideContract()); log.info("Got contract, broadcasting and responding with CHANNEL_OPEN"); final Protos.ProvideContract providedContract = msg.getProvideContract(); if (majorVersion == 2) { state = new PaymentChannelV2ServerState(broadcaster, wallet, myKey, expireTime); checkState(providedContract.hasClientKey(), "ProvideContract didn't have a client key in protocol v2"); ((PaymentChannelV2ServerState)state).provideClientKey(providedContract.getClientKey().toByteArray()); } //TODO notify connection handler that timeout should be significantly extended as we wait for network propagation? final Transaction contract = wallet.getParams().getDefaultSerializer().makeTransaction(providedContract.getTx().toByteArray()); step = InitStep.WAITING_ON_MULTISIG_ACCEPTANCE; state.provideContract(contract) .addListener(new Runnable() { @Override public void run() { multisigContractPropogated(providedContract, contract.getHash()); } }, Threading.SAME_THREAD); }