Java Code Examples for org.bitcoin.paymentchannel.Protos#ReturnRefund

The following examples show how to use org.bitcoin.paymentchannel.Protos#ReturnRefund . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaymentChannelClient.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@GuardedBy("lock")
private void receiveRefund(Protos.TwoWayChannelMessage refundMsg, @Nullable KeyParameter userKey) throws VerificationException {
    checkState(majorVersion == 1);
    checkState(step == InitStep.WAITING_FOR_REFUND_RETURN && refundMsg.hasReturnRefund());
    log.info("Got RETURN_REFUND message, providing signed contract");
    Protos.ReturnRefund returnedRefund = refundMsg.getReturnRefund();
    // Cast is safe since we've checked the version number
    ((PaymentChannelV1ClientState) state).provideRefundSignature(returnedRefund.getSignature().toByteArray(), userKey);
    step = InitStep.WAITING_FOR_CHANNEL_OPEN;

    // Before we can send the server the contract (ie send it to the network), we must ensure that our refund
    // transaction is safely in the wallet - thus we store it (this also keeps it up-to-date when we pay)
    state.storeChannelInWallet(serverId);

    Protos.ProvideContract.Builder contractMsg = Protos.ProvideContract.newBuilder()
            .setTx(ByteString.copyFrom(state.getContract().unsafeBitcoinSerialize()));
    try {
        // Make an initial payment of the dust limit, and put it into the message as well. The size of the
        // server-requested dust limit was already sanity checked by this point.
        PaymentChannelClientState.IncrementedPayment payment = state().incrementPaymentBy(Coin.valueOf(minPayment), userKey);
        Protos.UpdatePayment.Builder initialMsg = contractMsg.getInitialPaymentBuilder();
        initialMsg.setSignature(ByteString.copyFrom(payment.signature.encodeToBitcoin()));
        initialMsg.setClientChangeValue(state.getValueRefunded().value);
    } catch (ValueOutOfRangeException e) {
        throw new IllegalStateException(e);  // This cannot happen.
    }

    final Protos.TwoWayChannelMessage.Builder msg = Protos.TwoWayChannelMessage.newBuilder();
    msg.setProvideContract(contractMsg);
    msg.setType(Protos.TwoWayChannelMessage.MessageType.PROVIDE_CONTRACT);
    conn.sendToServer(msg.build());
}
 
Example 2
Source File: PaymentChannelClient.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@GuardedBy("lock")
private void receiveRefund(Protos.TwoWayChannelMessage refundMsg, @Nullable KeyParameter userKey) throws VerificationException {
    checkState(majorVersion == 1);
    checkState(step == InitStep.WAITING_FOR_REFUND_RETURN && refundMsg.hasReturnRefund());
    log.info("Got RETURN_REFUND message, providing signed contract");
    Protos.ReturnRefund returnedRefund = refundMsg.getReturnRefund();
    // Cast is safe since we've checked the version number
    ((PaymentChannelV1ClientState)state).provideRefundSignature(returnedRefund.getSignature().toByteArray(), userKey);
    step = InitStep.WAITING_FOR_CHANNEL_OPEN;

    // Before we can send the server the contract (ie send it to the network), we must ensure that our refund
    // transaction is safely in the wallet - thus we store it (this also keeps it up-to-date when we pay)
    state.storeChannelInWallet(serverId);

    Protos.ProvideContract.Builder contractMsg = Protos.ProvideContract.newBuilder()
            .setTx(ByteString.copyFrom(state.getContract().unsafeBitcoinSerialize()));
    try {
        // Make an initial payment of the dust limit, and put it into the message as well. The size of the
        // server-requested dust limit was already sanity checked by this point.
        PaymentChannelClientState.IncrementedPayment payment = state().incrementPaymentBy(Coin.valueOf(minPayment), userKey);
        Protos.UpdatePayment.Builder initialMsg = contractMsg.getInitialPaymentBuilder();
        initialMsg.setSignature(ByteString.copyFrom(payment.signature.encodeToBitcoin()));
        initialMsg.setClientChangeValue(state.getValueRefunded().value);
    } catch (ValueOutOfRangeException e) {
        throw new IllegalStateException(e);  // This cannot happen.
    }

    final Protos.TwoWayChannelMessage.Builder msg = Protos.TwoWayChannelMessage.newBuilder();
    msg.setProvideContract(contractMsg);
    msg.setType(Protos.TwoWayChannelMessage.MessageType.PROVIDE_CONTRACT);
    conn.sendToServer(msg.build());
}
 
Example 3
Source File: PaymentChannelClient.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@GuardedBy("lock")
private void receiveRefund(Protos.TwoWayChannelMessage refundMsg, @Nullable KeyParameter userKey) throws VerificationException {
    checkState(majorVersion == 1);
    checkState(step == InitStep.WAITING_FOR_REFUND_RETURN && refundMsg.hasReturnRefund());
    log.info("Got RETURN_REFUND message, providing signed contract");
    Protos.ReturnRefund returnedRefund = refundMsg.getReturnRefund();
    // Cast is safe since we've checked the version number
    ((PaymentChannelV1ClientState)state).provideRefundSignature(returnedRefund.getSignature().toByteArray(), userKey);
    step = InitStep.WAITING_FOR_CHANNEL_OPEN;

    // Before we can send the server the contract (ie send it to the network), we must ensure that our refund
    // transaction is safely in the wallet - thus we store it (this also keeps it up-to-date when we pay)
    state.storeChannelInWallet(serverId);

    Protos.ProvideContract.Builder contractMsg = Protos.ProvideContract.newBuilder()
            .setTx(ByteString.copyFrom(state.getContract().unsafeBitcoinSerialize()));
    try {
        // Make an initial payment of the dust limit, and put it into the message as well. The size of the
        // server-requested dust limit was already sanity checked by this point.
        PaymentChannelClientState.IncrementedPayment payment = state().incrementPaymentBy(Coin.valueOf(minPayment), userKey);
        Protos.UpdatePayment.Builder initialMsg = contractMsg.getInitialPaymentBuilder();
        initialMsg.setSignature(ByteString.copyFrom(payment.signature.encodeToBitcoin()));
        initialMsg.setClientChangeValue(state.getValueRefunded().value);
    } catch (ValueOutOfRangeException e) {
        throw new IllegalStateException(e);  // This cannot happen.
    }

    final Protos.TwoWayChannelMessage.Builder msg = Protos.TwoWayChannelMessage.newBuilder();
    msg.setProvideContract(contractMsg);
    msg.setType(Protos.TwoWayChannelMessage.MessageType.PROVIDE_CONTRACT);
    conn.sendToServer(msg.build());
}