From 880b413b241152807ee098aaecff559d9d979cc4 Mon Sep 17 00:00:00 2001
From: Matt Corallo
Date: Wed, 26 Jun 2013 23:55:34 +0200
Subject: [PATCH] Add a TransactionBroadcaster abstraction to PeerGroup.
---
.../com/google/bitcoin/core/PeerGroup.java | 2 +-
.../bitcoin/core/TransactionBroadcaster.java | 28 +++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
create mode 100644 core/src/main/java/com/google/bitcoin/core/TransactionBroadcaster.java
diff --git a/core/src/main/java/com/google/bitcoin/core/PeerGroup.java b/core/src/main/java/com/google/bitcoin/core/PeerGroup.java
index e78101a3..3c345867 100644
--- a/core/src/main/java/com/google/bitcoin/core/PeerGroup.java
+++ b/core/src/main/java/com/google/bitcoin/core/PeerGroup.java
@@ -67,7 +67,7 @@ import static com.google.common.base.Preconditions.checkState;
* when finished. Note that not all methods of PeerGroup are safe to call from a UI thread as some may do
* network IO, but starting and stopping the service should be fine.
*/
-public class PeerGroup extends AbstractIdleService {
+public class PeerGroup extends AbstractIdleService implements TransactionBroadcaster {
private static final int DEFAULT_CONNECTIONS = 4;
private static final Logger log = LoggerFactory.getLogger(PeerGroup.class);
diff --git a/core/src/main/java/com/google/bitcoin/core/TransactionBroadcaster.java b/core/src/main/java/com/google/bitcoin/core/TransactionBroadcaster.java
new file mode 100644
index 00000000..23f2e8d4
--- /dev/null
+++ b/core/src/main/java/com/google/bitcoin/core/TransactionBroadcaster.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.bitcoin.core;
+
+import com.google.common.util.concurrent.ListenableFuture;
+
+/**
+ * A general interface which declares the ability to broadcast transactions. This is implemented
+ * by {@link com.google.bitcoin.core.PeerGroup}.
+ */
+public interface TransactionBroadcaster {
+ /** Broadcast the given transaction on the network */
+ public ListenableFuture broadcastTransaction(final Transaction tx);
+}