コード例 #1
0
 private synchronized void updateChannelInWallet() {
   if (storedServerChannel != null) {
     storedServerChannel.updateValueToMe(bestValueToMe, bestValueSignature);
     StoredPaymentChannelServerStates channels =
         (StoredPaymentChannelServerStates)
             wallet.getExtensions().get(StoredPaymentChannelServerStates.EXTENSION_ID);
     channels.updatedChannel(storedServerChannel);
   }
 }
コード例 #2
0
 PaymentChannelServerState(
     StoredServerChannel storedServerChannel, Wallet wallet, TransactionBroadcaster broadcaster)
     throws VerificationException {
   synchronized (storedServerChannel) {
     this.wallet = checkNotNull(wallet);
     this.broadcaster = checkNotNull(broadcaster);
     this.multisigContract = checkNotNull(storedServerChannel.contract);
     this.multisigScript = multisigContract.getOutput(0).getScriptPubKey();
     this.clientKey = ECKey.fromPublicOnly(multisigScript.getChunks().get(1).data);
     this.clientOutput = checkNotNull(storedServerChannel.clientOutput);
     this.refundTransactionUnlockTimeSecs = storedServerChannel.refundTransactionUnlockTimeSecs;
     this.serverKey = checkNotNull(storedServerChannel.myKey);
     this.totalValue = multisigContract.getOutput(0).getValue();
     this.bestValueToMe = checkNotNull(storedServerChannel.bestValueToMe);
     this.bestValueSignature = storedServerChannel.bestValueSignature;
     checkArgument(bestValueToMe.equals(Coin.ZERO) || bestValueSignature != null);
     this.storedServerChannel = storedServerChannel;
     storedServerChannel.state = this;
     this.state = State.READY;
   }
 }
コード例 #3
0
  /**
   * Stores this channel's state in the wallet as a part of a {@link
   * StoredPaymentChannelServerStates} wallet extension and keeps it up-to-date each time payment is
   * incremented. This will be automatically removed when a call to {@link
   * PaymentChannelServerState#close()} completes successfully. A channel may only be stored after
   * it has fully opened (ie state == State.READY).
   *
   * @param connectedHandler Optional {@link PaymentChannelServer} object that manages this object.
   *     This will set the appropriate pointer in the newly created {@link StoredServerChannel}
   *     before it is committed to wallet. If set, closing the state object will propagate the close
   *     to the handler which can then do a TCP disconnect.
   */
  public synchronized void storeChannelInWallet(@Nullable PaymentChannelServer connectedHandler) {
    checkState(state == State.READY);
    if (storedServerChannel != null) return;

    log.info("Storing state with contract hash {}.", multisigContract.getHash());
    StoredPaymentChannelServerStates channels =
        (StoredPaymentChannelServerStates)
            wallet.addOrGetExistingExtension(
                new StoredPaymentChannelServerStates(wallet, broadcaster));
    storedServerChannel =
        new StoredServerChannel(
            this,
            multisigContract,
            clientOutput,
            refundTransactionUnlockTimeSecs,
            serverKey,
            bestValueToMe,
            bestValueSignature);
    if (connectedHandler != null)
      checkState(
          storedServerChannel.setConnectedHandler(connectedHandler, false) == connectedHandler);
    channels.putChannel(storedServerChannel);
  }