mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 15:22:16 +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:
parent
da0d6c37a2
commit
4f9bc98e97
@ -53,7 +53,7 @@ public class StoredPaymentChannelClientStates implements WalletExtension {
|
|||||||
* {@link TransactionBroadcaster} which are used to complete and announce contract and refund
|
* {@link TransactionBroadcaster} which are used to complete and announce contract and refund
|
||||||
* transactions.
|
* transactions.
|
||||||
*/
|
*/
|
||||||
public StoredPaymentChannelClientStates(TransactionBroadcaster announcePeerGroup, Wallet containingWallet) {
|
public StoredPaymentChannelClientStates(Wallet containingWallet, TransactionBroadcaster announcePeerGroup) {
|
||||||
this.announcePeerGroup = checkNotNull(announcePeerGroup);
|
this.announcePeerGroup = checkNotNull(announcePeerGroup);
|
||||||
this.containingWallet = checkNotNull(containingWallet);
|
this.containingWallet = checkNotNull(containingWallet);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ public class ChannelConnectionTest extends TestWithWallet {
|
|||||||
super.setUp();
|
super.setUp();
|
||||||
sendMoneyToWallet(Utils.COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
sendMoneyToWallet(Utils.COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
||||||
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
|
chain = new BlockChain(params, wallet, blockStore); // Recreate chain as sendMoneyToWallet will confuse it
|
||||||
serverWallet = new Wallet(params);
|
serverWallet = new Wallet(params);
|
||||||
serverWallet.addExtension(new StoredPaymentChannelServerStates(serverWallet, failBroadcaster));
|
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.
|
// 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
|
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());
|
newClientStates.deserializeWalletExtension(wallet, clientStoredChannels.serializeWalletExtension());
|
||||||
// Expect two pairs of contract/refund ...
|
// Expect two pairs of contract/refund ...
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
@ -425,7 +425,7 @@ public class ChannelConnectionTest extends TestWithWallet {
|
|||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
new WalletProtobufSerializer().writeWallet(wallet, bos);
|
new WalletProtobufSerializer().writeWallet(wallet, bos);
|
||||||
Wallet wallet2 = new Wallet(wallet.getParams());
|
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);
|
new WalletProtobufSerializer().readWallet(WalletProtobufSerializer.parseToProto(new ByteArrayInputStream(bos.toByteArray())), wallet2);
|
||||||
return wallet2;
|
return wallet2;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
@ -59,13 +58,13 @@ public class PaymentChannelStateTest extends TestWithWallet {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
wallet.addExtension(new StoredPaymentChannelClientStates(new TransactionBroadcaster() {
|
wallet.addExtension(new StoredPaymentChannelClientStates(wallet, new TransactionBroadcaster() {
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<Transaction> broadcastTransaction(Transaction tx) {
|
public ListenableFuture<Transaction> broadcastTransaction(Transaction tx) {
|
||||||
fail();
|
fail();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, wallet));
|
}));
|
||||||
sendMoneyToWallet(Utils.COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
sendMoneyToWallet(Utils.COIN, AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
||||||
chain = new BlockChain(params, wallet, blockStore); // Recreate chain as sendMoneyToWallet will confuse it
|
chain = new BlockChain(params, wallet, blockStore); // Recreate chain as sendMoneyToWallet will confuse it
|
||||||
serverKey = new ECKey();
|
serverKey = new ECKey();
|
||||||
@ -223,7 +222,7 @@ public class PaymentChannelStateTest extends TestWithWallet {
|
|||||||
assertEquals(Utils.CENT, wallet.getBalance());
|
assertEquals(Utils.CENT, wallet.getBalance());
|
||||||
|
|
||||||
// Set the wallet's stored states to use our real test PeerGroup
|
// 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);
|
wallet.addOrUpdateExtension(stateStorage);
|
||||||
|
|
||||||
Utils.rollMockClock(0); // Use mock clock
|
Utils.rollMockClock(0); // Use mock clock
|
||||||
|
@ -16,21 +16,26 @@
|
|||||||
|
|
||||||
package com.google.bitcoin.examples;
|
package com.google.bitcoin.examples;
|
||||||
|
|
||||||
import java.io.File;
|
import com.google.bitcoin.core.ECKey;
|
||||||
import java.math.BigInteger;
|
import com.google.bitcoin.core.NetworkParameters;
|
||||||
import java.net.InetSocketAddress;
|
import com.google.bitcoin.core.Utils;
|
||||||
|
import com.google.bitcoin.core.Wallet;
|
||||||
|
|
||||||
import com.google.bitcoin.core.*;
|
|
||||||
import com.google.bitcoin.kits.WalletAppKit;
|
import com.google.bitcoin.kits.WalletAppKit;
|
||||||
import com.google.bitcoin.params.TestNet3Params;
|
import com.google.bitcoin.params.TestNet3Params;
|
||||||
import com.google.bitcoin.protocols.channels.PaymentChannelClientConnection;
|
import com.google.bitcoin.protocols.channels.PaymentChannelClientConnection;
|
||||||
import com.google.bitcoin.protocols.channels.StoredPaymentChannelClientStates;
|
import com.google.bitcoin.protocols.channels.StoredPaymentChannelClientStates;
|
||||||
import com.google.bitcoin.protocols.channels.ValueOutOfRangeException;
|
import com.google.bitcoin.protocols.channels.ValueOutOfRangeException;
|
||||||
import com.google.bitcoin.utils.BriefLogFormatter;
|
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 org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
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 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
|
// the refund transaction if its lock time has expired. It also persists channels so we can resume them
|
||||||
// after a restart.
|
// after a restart.
|
||||||
wallet().addExtension(new StoredPaymentChannelClientStates(peerGroup(), wallet()));
|
wallet().addExtension(new StoredPaymentChannelClientStates(wallet(), peerGroup()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
appKit.startAndWait();
|
appKit.startAndWait();
|
||||||
|
Loading…
Reference in New Issue
Block a user