Merge #261: Remove change_index from listspendtxs response
103c1950ba9af114cadde6f92117b31ec584ac73 Remove change_index from listspendtxs response (edouard)
Pull request description:
Multiple change indexes may be present in a spend
draft transaction and can be detected instead
in the response psbt with the bip32_derivation
outputs fields.
ACKs for top commit:
darosior:
utACK 103c1950ba9af114cadde6f92117b31ec584ac73
Tree-SHA512: 82619792c4424537e7320162c149ae946ca1fdc101661cf9bc3d0ba4d16f0327cc3cffd98f11165a9ab9db5d1690013f8ec9bdfe46bd6b1427c332b045d683a8
This commit is contained in:
commit
12bd92883d
@ -174,7 +174,6 @@ This command does not take any parameter for now.
|
||||
| Field | Type | Description |
|
||||
| -------------- | ----------------- | ----------------------------------------------------------------------- |
|
||||
| `psbt` | string | Base64-encoded PSBT of the Spend transaction. |
|
||||
| `change_index` | int or null | Index of the change output in the transaction outputs, if there is one. |
|
||||
|
||||
|
||||
### `delspendtx`
|
||||
|
||||
@ -10,9 +10,7 @@ use crate::{
|
||||
descriptors, DaemonControl, VERSION,
|
||||
};
|
||||
|
||||
use utils::{
|
||||
change_index, deser_amount_from_sats, deser_base64, deser_hex, ser_amount, ser_base64, ser_hex,
|
||||
};
|
||||
use utils::{deser_amount_from_sats, deser_base64, deser_hex, ser_amount, ser_base64, ser_hex};
|
||||
|
||||
use std::{
|
||||
collections::{hash_map, BTreeMap, HashMap},
|
||||
@ -507,11 +505,7 @@ impl DaemonControl {
|
||||
let spend_txs = db_conn
|
||||
.list_spend()
|
||||
.into_iter()
|
||||
.map(|psbt| {
|
||||
let change_index =
|
||||
change_index(&psbt, &mut db_conn).map(|i| i.try_into().expect("insane usize"));
|
||||
ListSpendEntry { psbt, change_index }
|
||||
})
|
||||
.map(|psbt| ListSpendEntry { psbt })
|
||||
.collect();
|
||||
ListSpendResult { spend_txs }
|
||||
}
|
||||
@ -786,7 +780,6 @@ pub struct CreateSpendResult {
|
||||
pub struct ListSpendEntry {
|
||||
#[serde(serialize_with = "ser_base64", deserialize_with = "deser_base64")]
|
||||
pub psbt: Psbt,
|
||||
pub change_index: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
use crate::database::DatabaseConnection;
|
||||
|
||||
use miniscript::bitcoin::{
|
||||
self, consensus, hashes::hex::FromHex, util::psbt::PartiallySignedTransaction as Psbt,
|
||||
};
|
||||
use miniscript::bitcoin::{self, consensus, hashes::hex::FromHex};
|
||||
use serde::{de, Deserialize, Deserializer, Serializer};
|
||||
|
||||
/// Serialize an amount as sats
|
||||
@ -54,23 +50,3 @@ where
|
||||
let s = Vec::from_hex(&s).map_err(de::Error::custom)?;
|
||||
consensus::deserialize(&s).map_err(de::Error::custom)
|
||||
}
|
||||
|
||||
// Utility to gather the index of a change output in a Psbt, if there is one.
|
||||
pub fn change_index(psbt: &Psbt, db_conn: &mut Box<dyn DatabaseConnection>) -> Option<usize> {
|
||||
let network = db_conn.network();
|
||||
|
||||
for (i, txo) in psbt.unsigned_tx.output.iter().enumerate() {
|
||||
// Small optimization. TODO: adapt once we have Taproot support.
|
||||
if !txo.script_pubkey.is_v0_p2wsh() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Ok(address) = bitcoin::Address::from_script(&txo.script_pubkey, network) {
|
||||
if let Some((_, true)) = db_conn.derivation_index_by_address(&address) {
|
||||
return Some(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
@ -168,9 +168,7 @@ def test_list_spend(lianad, bitcoind):
|
||||
list_res = lianad.rpc.listspendtxs()["spend_txs"]
|
||||
assert len(list_res) == 2
|
||||
first_psbt = next(entry for entry in list_res if entry["psbt"] == res["psbt"])
|
||||
assert first_psbt["change_index"] == 1
|
||||
second_psbt = next(entry for entry in list_res if entry["psbt"] == res_b["psbt"])
|
||||
assert second_psbt["change_index"] is None
|
||||
|
||||
# If we delete the first one, we'll get only the second one.
|
||||
first_psbt = PSBT.from_base64(res["psbt"])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user