Payment channels: inline a superfluous misnamed method on StoredServerChannel and rename getState to getOrCreateState.

This commit is contained in:
Mike Hearn
2013-07-19 13:11:22 +02:00
parent 4f9bc98e97
commit dcf04f6cb6
7 changed files with 15 additions and 20 deletions

View File

@@ -16,9 +16,6 @@
package com.google.bitcoin.protocols.channels;
import java.math.BigInteger;
import java.util.List;
import com.google.bitcoin.core.*;
import com.google.bitcoin.crypto.TransactionSignature;
import com.google.bitcoin.script.Script;
@@ -29,6 +26,9 @@ import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigInteger;
import java.util.List;
import static com.google.common.base.Preconditions.*;
/**
@@ -326,7 +326,7 @@ public class PaymentChannelClientState {
private synchronized void updateChannelInWallet() {
if (storedChannel == null)
return;
storedChannel.updateValueToMe(valueToMe);
storedChannel.valueToMe = valueToMe;
StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates)
wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID);
wallet.addOrUpdateExtension(channels);

View File

@@ -158,7 +158,7 @@ public class PaymentChannelServer {
if (storedServerChannel != null) {
if (storedServerChannel.setConnectedHandler(this)) {
log.info("Got resume version message, responding with VERSIONS and CHANNEL_OPEN");
state = storedServerChannel.getState(wallet, broadcaster);
state = storedServerChannel.getOrCreateState(wallet, broadcaster);
step = InitStep.CHANNEL_OPEN;
conn.sendToClient(Protos.TwoWayChannelMessage.newBuilder()
.setType(Protos.TwoWayChannelMessage.MessageType.CHANNEL_OPEN)

View File

@@ -227,8 +227,4 @@ class StoredClientChannel {
this.refundFees = refundFees;
this.active = active;
}
void updateValueToMe(BigInteger newValue) {
this.valueToMe = newValue;
}
}

View File

@@ -81,7 +81,7 @@ public class StoredPaymentChannelServerStates implements WalletExtension {
if (channel.connectedHandler != null) // connectedHandler will be reset to null in connectionClosed
channel.connectedHandler.close(); // Closes the actual connection, not the channel
try {//TODO add event listener to PaymentChannelServerStateManager
channel.getState(wallet, broadcaster).close();
channel.getOrCreateState(wallet, broadcaster).close();
} catch (ValueOutOfRangeException e) {
e.printStackTrace();
} catch (VerificationException e) {

View File

@@ -16,11 +16,10 @@
package com.google.bitcoin.protocols.channels;
import java.io.Serializable;
import java.math.BigInteger;
import com.google.bitcoin.core.*;
import java.math.BigInteger;
import static com.google.common.base.Preconditions.checkArgument;
/**
@@ -80,7 +79,7 @@ public class StoredServerChannel {
* be used to complete transactions
* @param broadcaster The {@link TransactionBroadcaster} which will be used to broadcast contract/payment transactions.
*/
public synchronized PaymentChannelServerState getState(Wallet wallet, TransactionBroadcaster broadcaster) throws VerificationException {
public synchronized PaymentChannelServerState getOrCreateState(Wallet wallet, TransactionBroadcaster broadcaster) throws VerificationException {
if (state == null)
state = new PaymentChannelServerState(this, wallet, broadcaster);
checkArgument(wallet == state.wallet);

View File

@@ -167,7 +167,7 @@ public class ChannelConnectionTest extends TestWithWallet {
StoredPaymentChannelServerStates channels = (StoredPaymentChannelServerStates)serverWallet.getExtensions().get(StoredPaymentChannelServerStates.EXTENSION_ID);
StoredServerChannel storedServerChannel = channels.getChannel(broadcastMultiSig.getHash());
PaymentChannelServerState serverState = storedServerChannel.getState(serverWallet, mockBroadcaster);
PaymentChannelServerState serverState = storedServerChannel.getOrCreateState(serverWallet, mockBroadcaster);
// Check that you can call close multiple times with no exceptions.
client.close();

View File

@@ -16,10 +16,6 @@
package com.google.bitcoin.examples;
import java.io.File;
import java.math.BigInteger;
import java.net.SocketAddress;
import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.core.Sha256Hash;
import com.google.bitcoin.core.Utils;
@@ -30,6 +26,10 @@ import com.google.bitcoin.protocols.channels.*;
import com.google.bitcoin.utils.BriefLogFormatter;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.math.BigInteger;
import java.net.SocketAddress;
/**
* Simple server that listens on port 4242 for incoming payment channels.
*/
@@ -79,7 +79,7 @@ public class ExamplePaymentChannelServer implements PaymentChannelServerListener
// Try to get the state object from the stored state set in our wallet
PaymentChannelServerState state = null;
try {
state = storedStates.getChannel(channelId).getState(appKit.wallet(), appKit.peerGroup());
state = storedStates.getChannel(channelId).getOrCreateState(appKit.wallet(), appKit.peerGroup());
} catch (VerificationException e) {
// This indicates corrupted data, and since the channel was just opened, cannot happen
throw new RuntimeException(e);