Skip to content
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
19 changes: 19 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::sync::Arc;
use stderrlog;

use crate::chain::Network;
#[cfg(feature = "liquid")]
use crate::chain::Txid;
use crate::daemon::CookieGetter;
use crate::errors::*;

Expand Down Expand Up @@ -81,6 +83,8 @@ pub struct Config {
pub parent_network: BNetwork,
#[cfg(feature = "liquid")]
pub asset_db_path: Option<PathBuf>,
#[cfg(feature = "liquid")]
pub initial_issuance_prevtx: Option<Txid>,

#[cfg(feature = "electrum-discovery")]
pub electrum_public_hosts: Option<crate::electrum::ServerHosts>,
Expand Down Expand Up @@ -295,6 +299,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")]
Expand Down Expand Up @@ -334,6 +344,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::<Txid>()
.expect("invalid initial-issuance-prevtx TXID")
});

let default_daemon_port = match network_type {
#[cfg(not(feature = "liquid"))]
Network::Bitcoin => 8332,
Expand Down Expand Up @@ -516,6 +532,8 @@ impl Config {
parent_network,
#[cfg(feature = "liquid")]
asset_db_path,
#[cfg(feature = "liquid")]
initial_issuance_prevtx,

#[cfg(feature = "electrum-discovery")]
electrum_public_hosts,
Expand All @@ -524,6 +542,7 @@ impl Config {
#[cfg(feature = "electrum-discovery")]
tor_proxy: m.value_of("tor_proxy").map(|s| s.parse().unwrap()),
};

eprintln!("{:?}", config);
config
}
Expand Down
12 changes: 12 additions & 0 deletions src/new_index/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ impl Store {
HeaderList::empty()
};

#[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);
if txstore_db.get(&key).is_none() {
txstore_db.put(&key, &serialize(&TxOut::default()));
}
}

Store {
txstore_db,
history_db,
Expand Down
10 changes: 5 additions & 5 deletions src/util/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -203,4 +203,4 @@ mod test {
Some(value)
);
}
}
}
2 changes: 2 additions & 0 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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,
Expand Down