@Override @VisibleForTesting synchronized void doStoreChannelInWallet(Sha256Hash id) { StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates) wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID); checkNotNull(channels, "You have not added the StoredPaymentChannelClientStates extension to the wallet."); checkState(channels.getChannel(id, multisigContract.getHash()) == null); storedChannel = new StoredClientChannel(getMajorVersion(), id, multisigContract, refundTx, myKey, serverKey, valueToMe, refundFees, 0, true); channels.putChannel(storedChannel); }
private synchronized void deleteChannelFromWallet() { log.info("Close tx has confirmed, deleting channel from wallet: {}", storedChannel); StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates) wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID); channels.removeChannel(storedChannel); storedChannel = null; }
/** * Creates a new StoredPaymentChannelClientStates and associates it with the given {@link Wallet} and * {@link TransactionBroadcaster} which are used to complete and announce contract and refund * transactions. */ public StoredPaymentChannelClientStates(@Nullable Wallet containingWallet, TransactionBroadcaster announcePeerGroup) { setTransactionBroadcaster(announcePeerGroup); this.containingWallet = containingWallet; }
assertTrue(clientStoredChannels.getChannel(someServerId, contractHash).active); assertFalse(clientStoredChannels.getChannel(someServerId, contractHash).active); assertEquals(86640, clientStoredChannels.getSecondsUntilExpiry(someServerId)); Utils.rollMockClock(60 * 60 * 24 + 60 * 5); // Client announces refund 5 minutes after expire time StoredPaymentChannelClientStates newClientStates = new StoredPaymentChannelClientStates(wallet, mockBroadcaster); newClientStates.deserializeWalletExtension(wallet, clientStoredChannels.serializeWalletExtension()); broadcastTxPause.release(); if (isMultiSigContract()) {
/** * <p>Removes the channel with the given id from this set of stored states and notifies the wallet of an update to * this wallet extension.</p> * * <p>Note that the channel will still have its contract and refund transactions broadcast via the connected * {@link TransactionBroadcaster} as long as this {@link StoredPaymentChannelClientStates} continues to * exist in memory.</p> */ void removeChannel(StoredClientChannel channel) { lock.lock(); try { mapChannels.remove(channel.id, channel); } finally { lock.unlock(); } updatedChannel(channel); }
/** * Adds the given channel to this set of stored states, broadcasting the contract and refund transactions when the * channel expires and notifies the wallet of an update to this wallet extension */ void putChannel(final StoredClientChannel channel) { putChannel(channel, true); }
storedChannel = channels.getUsableChannelForServerID(serverId);
lock.lock(); try { final NetworkParameters params = getNetworkParameters();
@Override protected List<WalletExtension> provideWalletExtensions() { // 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. // We should not send a PeerGroup in the StoredPaymentChannelClientStates constructor // since WalletAppKit will find it for us. return ImmutableList.<WalletExtension>of(new StoredPaymentChannelClientStates(null)); } };
/** * <p>Removes the channel with the given id from this set of stored states and notifies the wallet of an update to * this wallet extension.</p> * * <p>Note that the channel will still have its contract and refund transactions broadcast via the connected * {@link TransactionBroadcaster} as long as this {@link StoredPaymentChannelClientStates} continues to * exist in memory.</p> */ void removeChannel(StoredClientChannel channel) { lock.lock(); try { mapChannels.remove(channel.id, channel); } finally { lock.unlock(); } updatedChannel(channel); }
/** * Adds the given channel to this set of stored states, broadcasting the contract and refund transactions when the * channel expires and notifies the wallet of an update to this wallet extension */ void putChannel(final StoredClientChannel channel) { putChannel(channel, true); }
storedChannel = channels.getUsableChannelForServerID(serverId);
lock.lock(); try { final NetworkParameters params = getNetworkParameters();
private static Wallet roundTripClientWallet(Wallet wallet) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); new WalletProtobufSerializer().writeWallet(wallet, bos); org.bitcoinj.wallet.Protos.Wallet proto = WalletProtobufSerializer.parseToProto(new ByteArrayInputStream(bos.toByteArray())); StoredPaymentChannelClientStates state = new StoredPaymentChannelClientStates(null, failBroadcaster); return new WalletProtobufSerializer().readWallet(wallet.getParams(), new WalletExtension[] { state }, proto); }
@Override @VisibleForTesting synchronized void doStoreChannelInWallet(Sha256Hash id) { StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates) wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID); checkNotNull(channels, "You have not added the StoredPaymentChannelClientStates extension to the wallet."); checkState(channels.getChannel(id, contract.getHash()) == null); storedChannel = new StoredClientChannel(getMajorVersion(), id, contract, refundTx, myKey, serverKey, valueToMe, refundFees, expiryTime, true); channels.putChannel(storedChannel); }
/** * <p>Removes the channel with the given id from this set of stored states and notifies the wallet of an update to * this wallet extension.</p> * * <p>Note that the channel will still have its contract and refund transactions broadcast via the connected * {@link TransactionBroadcaster} as long as this {@link StoredPaymentChannelClientStates} continues to * exist in memory.</p> */ void removeChannel(StoredClientChannel channel) { lock.lock(); try { mapChannels.remove(channel.id, channel); } finally { lock.unlock(); } updatedChannel(channel); }
/** * Creates a new StoredPaymentChannelClientStates and associates it with the given {@link Wallet} and * {@link TransactionBroadcaster} which are used to complete and announce contract and refund * transactions. */ public StoredPaymentChannelClientStates(@Nullable Wallet containingWallet, TransactionBroadcaster announcePeerGroup) { setTransactionBroadcaster(announcePeerGroup); this.containingWallet = containingWallet; }
private synchronized void deleteChannelFromWallet() { log.info("Close tx has confirmed, deleting channel from wallet: {}", storedChannel); StoredPaymentChannelClientStates channels = (StoredPaymentChannelClientStates) wallet.getExtensions().get(StoredPaymentChannelClientStates.EXTENSION_ID); channels.removeChannel(storedChannel); storedChannel = null; }
/** * Adds the given channel to this set of stored states, broadcasting the contract and refund transactions when the * channel expires and notifies the wallet of an update to this wallet extension */ void putChannel(final StoredClientChannel channel) { putChannel(channel, true); }
storedChannel = channels.getUsableChannelForServerID(serverId);