Search in sources :

Example 1 with PaymentChannelServer

use of com.google.bitcoin.protocols.channels.PaymentChannelServer in project PayFile by mikehearn.

the class Server method maybeInitPayments.

private PaymentChannelServer maybeInitPayments() {
    if (payments != null)
        return payments;
    BigInteger minPayment = BigInteger.valueOf(defaultPricePerChunk * MIN_ACCEPTED_CHUNKS);
    payments = new PaymentChannelServer(transactionBroadcaster, wallet, minPayment, new PaymentChannelServer.ServerConnection() {

        @Override
        public void sendToClient(Protos.TwoWayChannelMessage msg) {
            Payfile.PayFileMessage.Builder m = Payfile.PayFileMessage.newBuilder();
            m.setPayment(msg.toByteString());
            m.setType(Payfile.PayFileMessage.Type.PAYMENT);
            writeMessage(m.build());
        }

        @Override
        public void destroyConnection(PaymentChannelCloseException.CloseReason reason) {
            if (reason != PaymentChannelCloseException.CloseReason.CLIENT_REQUESTED_CLOSE) {
                log.error("{}: Payments terminated abnormally: {}", peerName, reason);
            }
            payments = null;
        }

        @Override
        public void channelOpen(Sha256Hash contractHash) {
            log.info("{}: Payments negotiated: {}", peerName, contractHash);
        }

        @Override
        public void paymentIncrease(BigInteger by, BigInteger to) {
            log.info("{}: Increased balance by {} to {}", peerName, by, to);
        }
    });
    payments.connectionOpen();
    return payments;
}
Also used : Sha256Hash(com.google.bitcoin.core.Sha256Hash) BigInteger(java.math.BigInteger) PaymentChannelServer(com.google.bitcoin.protocols.channels.PaymentChannelServer)

Aggregations

Sha256Hash (com.google.bitcoin.core.Sha256Hash)1 PaymentChannelServer (com.google.bitcoin.protocols.channels.PaymentChannelServer)1 BigInteger (java.math.BigInteger)1