diff --git a/src/config.rs b/src/config.rs index 85c591e59..7c4f067e6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,6 +9,8 @@ use std::time::Duration; use stderrlog; use crate::chain::Network; +#[cfg(feature = "liquid")] +use crate::chain::Txid; use crate::daemon::CookieGetter; use crate::errors::*; @@ -85,6 +87,8 @@ pub struct Config { pub parent_network: BNetwork, #[cfg(feature = "liquid")] pub asset_db_path: Option, + #[cfg(feature = "liquid")] + pub initial_issuance_prevtx: Option, #[cfg(feature = "electrum-discovery")] pub electrum_public_hosts: Option, @@ -317,6 +321,12 @@ impl Config { .long("asset-db-path") .help("Directory for liquid/elements asset db") .takes_value(true), + ) + .arg( + Arg::with_name("initial_issuance_prevtx") + .long("initial-issuance-prevtx") + .help("Custom initial issuance prevtx TXID — the txid spent by the issuance tx's input (required for custom liquid testnets/signets)") + .takes_value(true), ); #[cfg(feature = "electrum-discovery")] @@ -356,6 +366,12 @@ impl Config { #[cfg(feature = "liquid")] let asset_db_path = m.value_of("asset_db_path").map(PathBuf::from); + #[cfg(feature = "liquid")] + let initial_issuance_prevtx = m.value_of("initial_issuance_prevtx").map(|s| { + s.parse::() + .expect("invalid initial-issuance-prevtx TXID") + }); + let default_daemon_port = match network_type { #[cfg(not(feature = "liquid"))] Network::Bitcoin => 8332, @@ -551,6 +567,8 @@ impl Config { parent_network, #[cfg(feature = "liquid")] asset_db_path, + #[cfg(feature = "liquid")] + initial_issuance_prevtx, #[cfg(feature = "electrum-discovery")] electrum_public_hosts, @@ -559,6 +577,7 @@ impl Config { #[cfg(feature = "electrum-discovery")] tor_proxy: m.value_of("tor_proxy").map(|s| s.parse().unwrap()), }; + eprintln!("{:?}", config); config } diff --git a/src/new_index/schema.rs b/src/new_index/schema.rs index 8807aca39..84aa07daf 100644 --- a/src/new_index/schema.rs +++ b/src/new_index/schema.rs @@ -244,6 +244,22 @@ pub struct ChainQuery { // TODO: &[Block] should be an iterator / a queue. impl Indexer { pub fn open(store: Arc, from: FetchFrom, config: &Config, metrics: &Metrics) -> Self { + #[cfg(feature = "liquid")] + if let Some(prevtx) = config.initial_issuance_prevtx { + // Seed a dummy zero-value txo so the indexer can resolve the + // initial issuance input via a normal lookup, instead of a + // special-case in has_prevout(). See issue #125. + let outpoint = OutPoint { + txid: prevtx, + vout: 0, + }; + let key = TxOutRow::key(&outpoint); + let txstore_db = store.txstore_db(); + if txstore_db.get(&key).is_none() { + txstore_db.put(&key, &serialize(&TxOut::default())); + } + } + Indexer { store, flush: DBFlush::Disable, diff --git a/src/util/transaction.rs b/src/util/transaction.rs index e8fbb4c2d..334d196a0 100644 --- a/src/util/transaction.rs +++ b/src/util/transaction.rs @@ -5,11 +5,11 @@ use std::collections::{BTreeSet, HashMap}; #[cfg(feature = "liquid")] lazy_static! { - static ref REGTEST_INITIAL_ISSUANCE_PREVOUT: Txid = + static ref REGTEST_INITIAL_ISSUANCE_PREVTX: Txid = "50cdc410c9d0d61eeacc531f52d2c70af741da33af127c364e52ac1ee7c030a5" .parse() .unwrap(); - static ref TESTNET_INITIAL_ISSUANCE_PREVOUT: Txid = + static ref TESTNET_INITIAL_ISSUANCE_PREVTX: Txid = "0c52d2526a5c9f00e9fb74afd15dd3caaf17c823159a514f929ae25193a43a52" .parse() .unwrap(); @@ -80,8 +80,8 @@ pub fn has_prevout(txin: &TxIn) -> bool { #[cfg(feature = "liquid")] return !txin.is_coinbase() && !txin.is_pegin - && txin.previous_output.txid != *REGTEST_INITIAL_ISSUANCE_PREVOUT - && txin.previous_output.txid != *TESTNET_INITIAL_ISSUANCE_PREVOUT; + && txin.previous_output.txid != *REGTEST_INITIAL_ISSUANCE_PREVTX + && txin.previous_output.txid != *TESTNET_INITIAL_ISSUANCE_PREVTX; } pub fn is_spendable(txout: &TxOut) -> bool { @@ -203,4 +203,4 @@ mod test { Some(value) ); } -} +} \ No newline at end of file diff --git a/tests/common.rs b/tests/common.rs index 99a7730fd..2989b450c 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -120,6 +120,8 @@ impl TestRunner { asset_db_path: None, // XXX #[cfg(feature = "liquid")] parent_network: bitcoin::Network::Regtest, + #[cfg(feature = "liquid")] + initial_issuance_prevtx: None, db_block_cache_mb: 8, db_parallelism: 2, db_write_buffer_size_mb: 256,