Skip to content

Commit c663c7c

Browse files
committed
liquid: make the server work with custom initial issuance prevout (generic test chain with same parameters of testnet)
1 parent 6fb0170 commit c663c7c

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

src/config.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use std::sync::Arc;
88
use stderrlog;
99

1010
use crate::chain::Network;
11+
#[cfg(feature = "liquid")]
12+
use crate::chain::Txid;
1113
use crate::daemon::CookieGetter;
1214
use crate::errors::*;
1315

@@ -81,6 +83,8 @@ pub struct Config {
8183
pub parent_network: BNetwork,
8284
#[cfg(feature = "liquid")]
8385
pub asset_db_path: Option<PathBuf>,
86+
#[cfg(feature = "liquid")]
87+
pub initial_issuance_prevtx: Option<Txid>,
8488

8589
#[cfg(feature = "electrum-discovery")]
8690
pub electrum_public_hosts: Option<crate::electrum::ServerHosts>,
@@ -295,6 +299,12 @@ impl Config {
295299
.long("asset-db-path")
296300
.help("Directory for liquid/elements asset db")
297301
.takes_value(true),
302+
)
303+
.arg(
304+
Arg::with_name("initial_issuance_prevtx")
305+
.long("initial-issuance-prevtx")
306+
.help("Custom initial issuance prevtx TXID — the txid spent by the issuance tx's input (required for custom liquid testnets/signets)")
307+
.takes_value(true),
298308
);
299309

300310
#[cfg(feature = "electrum-discovery")]
@@ -334,6 +344,12 @@ impl Config {
334344
#[cfg(feature = "liquid")]
335345
let asset_db_path = m.value_of("asset_db_path").map(PathBuf::from);
336346

347+
#[cfg(feature = "liquid")]
348+
let initial_issuance_prevtx = m.value_of("initial_issuance_prevtx").map(|s| {
349+
s.parse::<Txid>()
350+
.expect("invalid initial-issuance-prevtx TXID")
351+
});
352+
337353
let default_daemon_port = match network_type {
338354
#[cfg(not(feature = "liquid"))]
339355
Network::Bitcoin => 8332,
@@ -516,6 +532,8 @@ impl Config {
516532
parent_network,
517533
#[cfg(feature = "liquid")]
518534
asset_db_path,
535+
#[cfg(feature = "liquid")]
536+
initial_issuance_prevtx,
519537

520538
#[cfg(feature = "electrum-discovery")]
521539
electrum_public_hosts,
@@ -524,6 +542,7 @@ impl Config {
524542
#[cfg(feature = "electrum-discovery")]
525543
tor_proxy: m.value_of("tor_proxy").map(|s| s.parse().unwrap()),
526544
};
545+
527546
eprintln!("{:?}", config);
528547
config
529548
}

src/new_index/schema.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ impl Store {
109109
HeaderList::empty()
110110
};
111111

112+
#[cfg(feature = "liquid")]
113+
if let Some(prevtx) = config.initial_issuance_prevtx {
114+
// Seed a dummy zero-value txo so the indexer can resolve the
115+
// initial issuance input via a normal lookup, instead of a
116+
// special-case in has_prevout(). See issue #125.
117+
let outpoint = OutPoint { txid: prevtx, vout: 0 };
118+
let key = TxOutRow::key(&outpoint);
119+
if txstore_db.get(&key).is_none() {
120+
txstore_db.put(&key, &serialize(&TxOut::default()));
121+
}
122+
}
123+
112124
Store {
113125
txstore_db,
114126
history_db,

src/util/transaction.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use std::collections::{BTreeSet, HashMap};
55

66
#[cfg(feature = "liquid")]
77
lazy_static! {
8-
static ref REGTEST_INITIAL_ISSUANCE_PREVOUT: Txid =
8+
static ref REGTEST_INITIAL_ISSUANCE_PREVTX: Txid =
99
"50cdc410c9d0d61eeacc531f52d2c70af741da33af127c364e52ac1ee7c030a5"
1010
.parse()
1111
.unwrap();
12-
static ref TESTNET_INITIAL_ISSUANCE_PREVOUT: Txid =
12+
static ref TESTNET_INITIAL_ISSUANCE_PREVTX: Txid =
1313
"0c52d2526a5c9f00e9fb74afd15dd3caaf17c823159a514f929ae25193a43a52"
1414
.parse()
1515
.unwrap();
@@ -80,8 +80,8 @@ pub fn has_prevout(txin: &TxIn) -> bool {
8080
#[cfg(feature = "liquid")]
8181
return !txin.is_coinbase()
8282
&& !txin.is_pegin
83-
&& txin.previous_output.txid != *REGTEST_INITIAL_ISSUANCE_PREVOUT
84-
&& txin.previous_output.txid != *TESTNET_INITIAL_ISSUANCE_PREVOUT;
83+
&& txin.previous_output.txid != *REGTEST_INITIAL_ISSUANCE_PREVTX
84+
&& txin.previous_output.txid != *TESTNET_INITIAL_ISSUANCE_PREVTX;
8585
}
8686

8787
pub fn is_spendable(txout: &TxOut) -> bool {
@@ -203,4 +203,4 @@ mod test {
203203
Some(value)
204204
);
205205
}
206-
}
206+
}

0 commit comments

Comments
 (0)