mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-08-01 12:31:23 +00:00
Payment channels: inline a superfluous misnamed method on StoredServerChannel and rename getState to getOrCreateState.
This commit is contained in:
@@ -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);
|
||||
|
@@ -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)
|
||||
|
@@ -227,8 +227,4 @@ class StoredClientChannel {
|
||||
this.refundFees = refundFees;
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
void updateValueToMe(BigInteger newValue) {
|
||||
this.valueToMe = newValue;
|
||||
}
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
|
@@ -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();
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user