Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix output indexes to be represented as a u32 (*requires reindex*) #69

Open
wants to merge 2 commits into
base: new-index
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/elements/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ pub struct IssuedAsset {
#[derive(Serialize, Deserialize, Debug)]
pub struct AssetRow {
pub issuance_txid: FullHash,
pub issuance_vin: u16,
pub issuance_vin: u32,
pub prev_txid: FullHash,
pub prev_vout: u16,
pub prev_vout: u32,
pub issuance: Bytes, // bincode does not like dealing with AssetIssuance, deserialization fails with "invalid type: sequence, expected a struct"
pub reissuance_token: FullHash,
}
Expand Down Expand Up @@ -108,7 +108,7 @@ impl IssuedAsset {
},
issuance_prevout: OutPoint {
txid: deserialize(&asset.prev_txid).unwrap(),
vout: asset.prev_vout as u32,
vout: asset.prev_vout,
},
contract_hash,
reissuance_token,
Expand Down Expand Up @@ -157,7 +157,7 @@ impl LiquidAsset {
#[derive(Serialize, Deserialize, Debug)]
pub struct IssuingInfo {
pub txid: FullHash,
pub vin: u16,
pub vin: u32,
pub is_reissuance: bool,
// None for blinded issuances
pub issued_amount: Option<u64>,
Expand All @@ -167,7 +167,7 @@ pub struct IssuingInfo {
#[derive(Serialize, Deserialize, Debug)]
pub struct BurningInfo {
pub txid: FullHash,
pub vout: u16,
pub vout: u32,
pub value: u64,
}

Expand Down Expand Up @@ -251,7 +251,7 @@ fn index_tx_assets(
pegout.asset.explicit().unwrap(),
TxHistoryInfo::Pegout(PegoutInfo {
txid,
vout: txo_index as u16,
vout: txo_index as u32,
value: pegout.value,
}),
));
Expand All @@ -262,7 +262,7 @@ fn index_tx_assets(
asset_id,
TxHistoryInfo::Burning(BurningInfo {
txid,
vout: txo_index as u16,
vout: txo_index as u32,
value: value,
}),
));
Expand All @@ -277,7 +277,7 @@ fn index_tx_assets(
pegin.asset,
TxHistoryInfo::Pegin(PeginInfo {
txid,
vin: txi_index as u16,
vin: txi_index as u32,
value: pegin.value,
}),
));
Expand All @@ -302,7 +302,7 @@ fn index_tx_assets(
asset_id,
TxHistoryInfo::Issuing(IssuingInfo {
txid,
vin: txi_index as u16,
vin: txi_index as u32,
is_reissuance,
issued_amount,
token_amount,
Expand All @@ -321,9 +321,9 @@ fn index_tx_assets(
asset_id,
AssetRow {
issuance_txid: txid,
issuance_vin: txi_index as u16,
issuance_vin: txi_index as u32,
prev_txid: full_hash(&txi.previous_output.txid[..]),
prev_vout: txi.previous_output.vout as u16,
prev_vout: txi.previous_output.vout as u32,
issuance: serialize(&txi.asset_issuance),
reissuance_token: full_hash(&reissuance_token.into_inner()[..]),
},
Expand Down
4 changes: 2 additions & 2 deletions src/elements/peg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ impl PegoutValue {
#[derive(Serialize, Deserialize, Debug)]
pub struct PeginInfo {
pub txid: FullHash,
pub vin: u16,
pub vin: u32,
pub value: u64,
}

// Inner type for the indexer TxHistoryInfo::Pegout variant
#[derive(Serialize, Deserialize, Debug)]
pub struct PegoutInfo {
pub txid: FullHash,
pub vout: u16,
pub vout: u32,
pub value: u64,
}
6 changes: 3 additions & 3 deletions src/new_index/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::Path;
use crate::config::Config;
use crate::util::{bincode, Bytes};

static DB_VERSION: u32 = 1;
static DB_VERSION: u32 = 2;

#[derive(Debug, Eq, PartialEq)]
pub struct DBRow {
Expand Down Expand Up @@ -201,8 +201,8 @@ impl DB {

if config.light_mode {
// append a byte to indicate light_mode is enabled.
// we're not letting bincode serialize this so that the compatiblity bytes won't change
// (and require a reindex) when light_mode is disabled. this should be chagned the next
// we're not letting bincode serialize this so that the compatibility bytes won't change
// (and require a reindex) when light_mode is disabled. this should be changed the next
// time we bump DB_VERSION and require a re-index anyway.
compatibility_bytes.push(1);
}
Expand Down
8 changes: 4 additions & 4 deletions src/new_index/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl Mempool {

Some(Utxo {
txid: deserialize(&info.txid).expect("invalid txid"),
vout: info.vout as u32,
vout: info.vout,
value: info.value,
confirmed: None,

Expand Down Expand Up @@ -377,9 +377,9 @@ impl Mempool {
compute_script_hash(&prevout.script_pubkey),
TxHistoryInfo::Spending(SpendingInfo {
txid: txid_bytes,
vin: input_index as u16,
vin: input_index,
prev_txid: full_hash(&txi.previous_output.txid[..]),
prev_vout: txi.previous_output.vout as u16,
prev_vout: txi.previous_output.vout,
value: prevout.value.amount_value(),
}),
)
Expand All @@ -398,7 +398,7 @@ impl Mempool {
compute_script_hash(&txo.script_pubkey),
TxHistoryInfo::Funding(FundingInfo {
txid: txid_bytes,
vout: index as u16,
vout: index as u32,
value: txo.value.amount_value(),
}),
)
Expand Down
34 changes: 17 additions & 17 deletions src/new_index/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ impl ChainQuery {
let txid: Txid = deserialize(&edge.key.spending_txid).unwrap();
self.tx_confirming_block(&txid).map(|b| SpendingInput {
txid,
vin: edge.key.spending_vin as u32,
vin: edge.key.spending_vin,
confirmed: Some(b),
})
})
Expand Down Expand Up @@ -1107,7 +1107,7 @@ fn index_transaction(
confirmed_height,
TxHistoryInfo::Funding(FundingInfo {
txid,
vout: txo_index as u16,
vout: txo_index as u32,
value: txo.value.amount_value(),
}),
);
Expand All @@ -1133,19 +1133,19 @@ fn index_transaction(
confirmed_height,
TxHistoryInfo::Spending(SpendingInfo {
txid,
vin: txi_index as u16,
vin: txi_index as u32,
prev_txid: full_hash(&txi.previous_output.txid[..]),
prev_vout: txi.previous_output.vout as u16,
prev_vout: txi.previous_output.vout,
value: prev_txo.value.amount_value(),
}),
);
rows.push(history.into_row());

let edge = TxEdgeRow::new(
full_hash(&txi.previous_output.txid[..]),
txi.previous_output.vout as u16,
txi.previous_output.vout,
txid,
txi_index as u16,
txi_index as u32,
);
rows.push(edge.into_row());
}
Expand Down Expand Up @@ -1265,7 +1265,7 @@ impl TxConfRow {
struct TxOutKey {
code: u8,
txid: FullHash,
vout: u16,
vout: u32,
}

struct TxOutRow {
Expand All @@ -1279,7 +1279,7 @@ impl TxOutRow {
key: TxOutKey {
code: b'O',
txid: *txid,
vout: vout as u16,
vout: vout as u32,
},
value: serialize(txout),
}
Expand All @@ -1288,7 +1288,7 @@ impl TxOutRow {
bincode::serialize_little(&TxOutKey {
code: b'O',
txid: full_hash(&outpoint.txid[..]),
vout: outpoint.vout as u16,
vout: outpoint.vout as u32,
})
.unwrap()
}
Expand Down Expand Up @@ -1378,16 +1378,16 @@ impl BlockRow {
#[derive(Serialize, Deserialize, Debug)]
pub struct FundingInfo {
pub txid: FullHash,
pub vout: u16,
pub vout: u32,
pub value: Value,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct SpendingInfo {
pub txid: FullHash, // spending transaction
pub vin: u16,
pub vin: u32,
pub prev_txid: FullHash, // funding transaction
pub prev_vout: u16,
pub prev_vout: u32,
pub value: Value,
}

Expand Down Expand Up @@ -1503,9 +1503,9 @@ impl TxHistoryInfo {
struct TxEdgeKey {
code: u8,
funding_txid: FullHash,
funding_vout: u16,
funding_vout: u32,
spending_txid: FullHash,
spending_vin: u16,
spending_vin: u32,
}

struct TxEdgeRow {
Expand All @@ -1515,9 +1515,9 @@ struct TxEdgeRow {
impl TxEdgeRow {
fn new(
funding_txid: FullHash,
funding_vout: u16,
funding_vout: u32,
spending_txid: FullHash,
spending_vin: u16,
spending_vin: u32,
) -> Self {
let key = TxEdgeKey {
code: b'S',
Expand All @@ -1531,7 +1531,7 @@ impl TxEdgeRow {

fn filter(outpoint: &OutPoint) -> Bytes {
// TODO build key without using bincode? [ b"S", &outpoint.txid[..], outpoint.vout?? ].concat()
bincode::serialize_little(&(b'S', full_hash(&outpoint.txid[..]), outpoint.vout as u16))
bincode::serialize_little(&(b'S', full_hash(&outpoint.txid[..]), outpoint.vout))
.unwrap()
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl From<Option<BlockId>> for TransactionStatus {
#[derive(Serialize, Deserialize)]
pub struct TxInput {
pub txid: Txid,
pub vin: u16,
pub vin: u32,
}

pub fn is_coinbase(txin: &TxIn) -> bool {
Expand Down
Loading