1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 01:43:29 +01:00

Change tx height to be i32 (to support unconfirmed status)

This commit is contained in:
Roman Zeyde 2018-05-15 08:54:28 +03:00
parent c88b5d4cb0
commit 1d84da30dc
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
2 changed files with 10 additions and 7 deletions

View File

@ -18,14 +18,14 @@ pub struct Query<'a> {
pub struct FundingOutput {
pub txn_id: Sha256dHash,
pub height: u32,
pub height: i32,
pub output_index: usize,
pub value: u64,
}
pub struct SpendingInput {
pub txn_id: Sha256dHash,
pub height: u32,
pub height: i32,
pub input_index: usize,
}
@ -37,7 +37,7 @@ pub struct Status {
struct TxnHeight {
txn: Transaction,
height: u32,
height: i32,
}
fn merklize(left: Sha256dHash, right: Sha256dHash) -> Sha256dHash {
@ -63,7 +63,10 @@ impl<'a> Query<'a> {
let txid: Sha256dHash = deserialize(&key.txid).unwrap();
let txn: Transaction = self.get_tx(&txid);
let height: u32 = bincode::deserialize(&row.value).unwrap();
txns.push(TxnHeight { txn, height })
txns.push(TxnHeight {
txn,
height: height as i32,
})
}
}
txns

View File

@ -25,15 +25,15 @@ fn hash_from_value(val: Option<&Value>) -> Result<Sha256dHash> {
Ok(script_hash)
}
fn history_from_status(status: &Status) -> Vec<(u32, Sha256dHash)> {
let mut txns_map = HashMap::<Sha256dHash, u32>::new();
fn history_from_status(status: &Status) -> Vec<(i32, Sha256dHash)> {
let mut txns_map = HashMap::<Sha256dHash, i32>::new();
for f in &status.funding {
txns_map.insert(f.txn_id, f.height);
}
for s in &status.spending {
txns_map.insert(s.txn_id, s.height);
}
let mut txns: Vec<(u32, Sha256dHash)> =
let mut txns: Vec<(i32, Sha256dHash)> =
txns_map.into_iter().map(|item| (item.1, item.0)).collect();
txns.sort();
txns