From 70590dac16afbb93145a5937418c240b26f968d0 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Thu, 25 Jul 2013 15:09:48 +0200 Subject: [PATCH] Payment channels: add wallet printouts of the contents of the extensions. --- .../StoredPaymentChannelClientStates.java | 27 +++++++++++++++++++ .../StoredPaymentChannelServerStates.java | 14 ++++++++++ .../channels/StoredServerChannel.java | 15 +++++++++++ 3 files changed, 56 insertions(+) diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelClientStates.java b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelClientStates.java index b1a7ecd9..4edbe058 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelClientStates.java +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelClientStates.java @@ -201,6 +201,19 @@ public class StoredPaymentChannelClientStates implements WalletExtension { lock.unlock(); } } + + @Override + public String toString() { + lock.lock(); + try { + StringBuilder buf = new StringBuilder("Client payment channel states:\n"); + for (StoredClientChannel channel : mapChannels.values()) + buf.append(" ").append(channel).append("\n"); + return buf.toString(); + } finally { + lock.unlock(); + } + } } /** @@ -227,4 +240,18 @@ class StoredClientChannel { this.refundFees = refundFees; this.active = active; } + + @Override + public String toString() { + final String newline = String.format("%n"); + return String.format("Stored client channel %s (%s)%n" + + " Key: %s%n" + + " Value to me: %d%n" + + " Refund fees: %d%n" + + " Contract: %s" + + "Refund: %s", + id, active ? "active" : "inactive", myKey, valueToMe, refundFees, + contract.toString().replaceAll(newline, newline + " "), + refund.toString().replaceAll(newline, newline + " ")); + } } diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelServerStates.java b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelServerStates.java index d6ad1679..cd0288e0 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelServerStates.java +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredPaymentChannelServerStates.java @@ -185,4 +185,18 @@ public class StoredPaymentChannelServerStates implements WalletExtension { lock.unlock(); } } + + @Override + public String toString() { + lock.lock(); + try { + StringBuilder buf = new StringBuilder(); + for (StoredServerChannel stored : mapChannels.values()) { + buf.append(stored); + } + return buf.toString(); + } finally { + lock.unlock(); + } + } } diff --git a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredServerChannel.java b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredServerChannel.java index 2edfac7b..12f0c224 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/channels/StoredServerChannel.java +++ b/core/src/main/java/com/google/bitcoin/protocols/channels/StoredServerChannel.java @@ -19,6 +19,7 @@ package com.google.bitcoin.protocols.channels; import com.google.bitcoin.core.*; import java.math.BigInteger; +import java.util.Date; import static com.google.common.base.Preconditions.checkArgument; @@ -85,4 +86,18 @@ public class StoredServerChannel { checkArgument(wallet == state.wallet); return state; } + + @Override + public synchronized String toString() { + final String newline = String.format("%n"); + return String.format("Stored server channel (%s)%n" + + " Key: %s%n" + + " Value to me: %d%n" + + " Client output: %s%n" + + " Refund unlock: %s (%d unix time)%n" + + " Contract: %s%n", + connectedHandler != null ? "connected" : "disconnected", myKey, bestValueToMe, + clientOutput, new Date(refundTransactionUnlockTimeSecs * 1000), refundTransactionUnlockTimeSecs, + contract.toString().replaceAll(newline, newline + " ")); + } }