mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
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>
This commit is contained in:
parent
006d664b59
commit
d14c9d30cd
3 changed files with 38 additions and 33 deletions
|
@ -808,6 +808,37 @@ bool wallet_channel_save(struct wallet *w, struct wallet_channel *chan){
|
||||||
tal_free(tmpctx);
|
tal_free(tmpctx);
|
||||||
return ok;
|
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
|
* wallet_shachain_delete - Drop the shachain from the database
|
||||||
*
|
*
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "db.h"
|
#include "db.h"
|
||||||
|
#include <bitcoin/tx.h>
|
||||||
#include <ccan/crypto/shachain/shachain.h>
|
#include <ccan/crypto/shachain/shachain.h>
|
||||||
#include <ccan/list/list.h>
|
#include <ccan/list/list.h>
|
||||||
#include <ccan/tal/tal.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);
|
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 */
|
#endif /* WALLET_WALLET_H */
|
||||||
|
|
|
@ -27,39 +27,6 @@ struct withdrawal {
|
||||||
const char *hextx;
|
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)
|
* wallet_withdrawal_broadcast - The tx has been broadcast (or it failed)
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue