From d14c9d30cd4b3f5f10c5fbe382594c71c5802177 Mon Sep 17 00:00:00 2001
From: Christian Decker <decker.christian@gmail.com>
Date: Fri, 1 Sep 2017 14:33:21 +0200
Subject: [PATCH] moveonly: Move make wallet_extract_owned available publicly

This was so far only used in the walletrpc, but we'll need it in a few
places.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
---
 wallet/wallet.c    | 31 +++++++++++++++++++++++++++++++
 wallet/wallet.h    |  7 +++++++
 wallet/walletrpc.c | 33 ---------------------------------
 3 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/wallet/wallet.c b/wallet/wallet.c
index 9617b4956..f0021132b 100644
--- a/wallet/wallet.c
+++ b/wallet/wallet.c
@@ -808,6 +808,37 @@ bool wallet_channel_save(struct wallet *w, struct wallet_channel *chan){
 	tal_free(tmpctx);
       	return ok;
 }
+
+int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
+				 u64 *total_satoshi)
+{
+	int num_utxos = 0;
+	for (size_t output = 0; output < tal_count(tx->output); output++) {
+		struct utxo *utxo;
+		u32 index;
+		bool is_p2sh;
+
+		if (!wallet_can_spend(w, tx->output[output].script, &index,
+				      &is_p2sh))
+			continue;
+
+		utxo = tal(w, struct utxo);
+		utxo->keyindex = index;
+		utxo->is_p2sh = is_p2sh;
+		utxo->amount = tx->output[output].amount;
+		utxo->status = output_state_available;
+		bitcoin_txid(tx, &utxo->txid);
+		utxo->outnum = output;
+		if (!wallet_add_utxo(w, utxo, p2sh_wpkh)) {
+			tal_free(utxo);
+			return -1;
+		}
+		*total_satoshi += utxo->amount;
+		num_utxos++;
+	}
+	return num_utxos;
+}
+
 /**
  * wallet_shachain_delete - Drop the shachain from the database
  *
diff --git a/wallet/wallet.h b/wallet/wallet.h
index 160474e20..553e2acf1 100644
--- a/wallet/wallet.h
+++ b/wallet/wallet.h
@@ -3,6 +3,7 @@
 
 #include "config.h"
 #include "db.h"
+#include <bitcoin/tx.h>
 #include <ccan/crypto/shachain/shachain.h>
 #include <ccan/list/list.h>
 #include <ccan/tal/tal.h>
@@ -211,4 +212,10 @@ bool wallet_peer_by_nodeid(struct wallet *w, const struct pubkey *nodeid,
  */
 bool wallet_channels_load_active(struct wallet *w, struct list_head *peers);
 
+/**
+ * wallet_extract_owned_outputs - given a tx, extract all of our outputs
+ */
+int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
+				 u64 *total_satoshi);
+
 #endif /* WALLET_WALLET_H */
diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c
index 2c9f66879..124df8c54 100644
--- a/wallet/walletrpc.c
+++ b/wallet/walletrpc.c
@@ -27,39 +27,6 @@ struct withdrawal {
 	const char *hextx;
 };
 
-/**
- * wallet_extract_owned_outputs - given a tx, extract all of our outputs
- */
-static int wallet_extract_owned_outputs(struct wallet *w,
-					const struct bitcoin_tx *tx,
-					u64 *total_satoshi)
-{
-	int num_utxos = 0;
-	for (size_t output = 0; output < tal_count(tx->output); output++) {
-		struct utxo *utxo;
-		u32 index;
-		bool is_p2sh;
-
-		if (!wallet_can_spend(w, tx->output[output].script, &index, &is_p2sh))
-			continue;
-
-		utxo = tal(w, struct utxo);
-		utxo->keyindex = index;
-		utxo->is_p2sh = is_p2sh;
-		utxo->amount = tx->output[output].amount;
-		utxo->status = output_state_available;
-		bitcoin_txid(tx, &utxo->txid);
-		utxo->outnum = output;
-		if (!wallet_add_utxo(w, utxo, p2sh_wpkh)) {
-			tal_free(utxo);
-			return -1;
-		}
-		*total_satoshi += utxo->amount;
-		num_utxos++;
-	}
-	return num_utxos;
-}
-
 /**
  * wallet_withdrawal_broadcast - The tx has been broadcast (or it failed)
  *