3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-01-31 07:12:17 +00:00

Payment channels: Re-order c'tor of StoredPaymentChannelClientStates.

This makes it consistent with the server side and put the listener last. It's easier to read this way when an anonymous inner class is used.
This commit is contained in:
Mike Hearn 2013-07-19 13:03:35 +02:00
parent da0d6c37a2
commit 4f9bc98e97
4 changed files with 20 additions and 16 deletions

View File

@ -53,7 +53,7 @@ public class StoredPaymentChannelClientStates implements WalletExtension {
* {@link TransactionBroadcaster} which are used to complete and announce contract and refund
* transactions.
*/
public StoredPaymentChannelClientStates(TransactionBroadcaster announcePeerGroup, Wallet containingWallet) {
public StoredPaymentChannelClientStates(Wallet containingWallet, TransactionBroadcaster announcePeerGroup) {
this.announcePeerGroup = checkNotNull(announcePeerGroup);
this.containingWallet = checkNotNull(containingWallet);
}

View File

@ -63,7 +63,7 @@ public class ChannelConnectionTest extends TestWithWallet {
super.setUp();
sendMoneyToWallet(Utils.COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
sendMoneyToWallet(Utils.COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
wallet.addExtension(new StoredPaymentChannelClientStates(failBroadcaster, wallet));
wallet.addExtension(new StoredPaymentChannelClientStates(wallet, failBroadcaster));
chain = new BlockChain(params, wallet, blockStore); // Recreate chain as sendMoneyToWallet will confuse it
serverWallet = new Wallet(params);
serverWallet.addExtension(new StoredPaymentChannelServerStates(serverWallet, failBroadcaster));
@ -404,7 +404,7 @@ public class ChannelConnectionTest extends TestWithWallet {
// Now roll the mock clock and recreate the client object so that it removes the channels and announces refunds.
Utils.rollMockClock(60 * 60 * 24 + 60*5); // Client announces refund 5 minutes after expire time
StoredPaymentChannelClientStates newClientStates = new StoredPaymentChannelClientStates(mockBroadcaster, wallet);
StoredPaymentChannelClientStates newClientStates = new StoredPaymentChannelClientStates(wallet, mockBroadcaster);
newClientStates.deserializeWalletExtension(wallet, clientStoredChannels.serializeWalletExtension());
// Expect two pairs of contract/refund ...
for (int i = 0; i < 2; i++) {
@ -425,7 +425,7 @@ public class ChannelConnectionTest extends TestWithWallet {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
new WalletProtobufSerializer().writeWallet(wallet, bos);
Wallet wallet2 = new Wallet(wallet.getParams());
wallet2.addExtension(new StoredPaymentChannelClientStates(failBroadcaster, wallet2));
wallet2.addExtension(new StoredPaymentChannelClientStates(wallet2, failBroadcaster));
new WalletProtobufSerializer().readWallet(WalletProtobufSerializer.parseToProto(new ByteArrayInputStream(bos.toByteArray())), wallet2);
return wallet2;
}

View File

@ -27,7 +27,6 @@ import org.junit.Test;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutionException;
@ -59,13 +58,13 @@ public class PaymentChannelStateTest extends TestWithWallet {
@Before
public void setUp() throws Exception {
super.setUp();
wallet.addExtension(new StoredPaymentChannelClientStates(new TransactionBroadcaster() {
wallet.addExtension(new StoredPaymentChannelClientStates(wallet, new TransactionBroadcaster() {
@Override
public ListenableFuture<Transaction> broadcastTransaction(Transaction tx) {
fail();
return null;
}
}, wallet));
}));
sendMoneyToWallet(Utils.COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
chain = new BlockChain(params, wallet, blockStore); // Recreate chain as sendMoneyToWallet will confuse it
serverKey = new ECKey();
@ -223,7 +222,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
assertEquals(Utils.CENT, wallet.getBalance());
// Set the wallet's stored states to use our real test PeerGroup
StoredPaymentChannelClientStates stateStorage = new StoredPaymentChannelClientStates(mockBroadcaster, wallet);
StoredPaymentChannelClientStates stateStorage = new StoredPaymentChannelClientStates(wallet, mockBroadcaster);
wallet.addOrUpdateExtension(stateStorage);
Utils.rollMockClock(0); // Use mock clock

View File

@ -16,21 +16,26 @@
package com.google.bitcoin.examples;
import java.io.File;
import java.math.BigInteger;
import java.net.InetSocketAddress;
import com.google.bitcoin.core.*;
import com.google.bitcoin.core.ECKey;
import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.core.Utils;
import com.google.bitcoin.core.Wallet;
import com.google.bitcoin.kits.WalletAppKit;
import com.google.bitcoin.params.TestNet3Params;
import com.google.bitcoin.protocols.channels.PaymentChannelClientConnection;
import com.google.bitcoin.protocols.channels.StoredPaymentChannelClientStates;
import com.google.bitcoin.protocols.channels.ValueOutOfRangeException;
import com.google.bitcoin.utils.BriefLogFormatter;
import com.google.common.util.concurrent.*;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.Uninterruptibles;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.math.BigInteger;
import java.net.InetSocketAddress;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
/**
@ -65,7 +70,7 @@ public class ExamplePaymentChannelClient {
// The StoredPaymentChannelClientStates object is responsible for, amongst other things, broadcasting
// the refund transaction if its lock time has expired. It also persists channels so we can resume them
// after a restart.
wallet().addExtension(new StoredPaymentChannelClientStates(peerGroup(), wallet()));
wallet().addExtension(new StoredPaymentChannelClientStates(wallet(), peerGroup()));
}
};
appKit.startAndWait();