diff --git a/src/chain.rs b/src/chain.rs index 8abf9a4a..ccb2b353 100644 --- a/src/chain.rs +++ b/src/chain.rs @@ -128,7 +128,7 @@ impl Network { pub fn genesis_hash(network: Network) -> BlockHash { #[cfg(not(feature = "liquid"))] - return bitcoin_genesis_hash(network.into()); + return bitcoin_genesis_hash(network); #[cfg(feature = "liquid")] return liquid_genesis_hash(network); } @@ -139,13 +139,16 @@ pub fn bitcoin_genesis_hash(network: Network) -> bitcoin::BlockHash { genesis_block(BNetwork::Bitcoin).block_hash(); static ref TESTNET_GENESIS: bitcoin::BlockHash = genesis_block(BNetwork::Testnet).block_hash(); - static ref TESTNET4_GENESIS: bitcoin::BlockHash = - BlockHash::from_str("00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043").unwrap(); + static ref TESTNET4_GENESIS: bitcoin::BlockHash = bitcoin::BlockHash::from_str( + "00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043" + ) + .unwrap(); static ref REGTEST_GENESIS: bitcoin::BlockHash = genesis_block(BNetwork::Regtest).block_hash(); static ref SIGNET_GENESIS: bitcoin::BlockHash = genesis_block(BNetwork::Signet).block_hash(); } + #[cfg(not(feature = "liquid"))] match network { Network::Bitcoin => *BITCOIN_GENESIS, Network::Testnet => *TESTNET_GENESIS, @@ -153,6 +156,12 @@ pub fn bitcoin_genesis_hash(network: Network) -> bitcoin::BlockHash { Network::Regtest => *REGTEST_GENESIS, Network::Signet => *SIGNET_GENESIS, } + #[cfg(feature = "liquid")] + match network { + Network::Liquid => *BITCOIN_GENESIS, + Network::LiquidTestnet => *TESTNET_GENESIS, + Network::LiquidRegtest => *REGTEST_GENESIS, + } } #[cfg(feature = "liquid")] diff --git a/src/daemon.rs b/src/daemon.rs index b8bde690..f04045d0 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -295,6 +295,7 @@ pub struct Daemon { } impl Daemon { + #[allow(clippy::too_many_arguments)] pub fn new( daemon_dir: PathBuf, blocks_dir: PathBuf, diff --git a/src/elements/peg.rs b/src/elements/peg.rs index cd339e60..7956973f 100644 --- a/src/elements/peg.rs +++ b/src/elements/peg.rs @@ -19,7 +19,13 @@ pub fn get_pegout_data( let pegged_asset_id = network.pegged_asset()?; txout.pegout_data().filter(|pegout| { pegout.asset == Asset::Explicit(*pegged_asset_id) - && pegout.genesis_hash == bitcoin_genesis_hash(parent_network) + && pegout.genesis_hash + == bitcoin_genesis_hash(match parent_network { + BNetwork::Bitcoin => Network::Liquid, + BNetwork::Testnet => Network::LiquidTestnet, + BNetwork::Signet => return false, + BNetwork::Regtest => Network::LiquidRegtest, + }) }) } diff --git a/src/rest.rs b/src/rest.rs index 2e061b11..ce8bef96 100644 --- a/src/rest.rs +++ b/src/rest.rs @@ -1668,7 +1668,10 @@ fn address_to_scripthash(addr: &str, network: Network) -> Result "${POPULAR_SCRIPTS_FILE_RAW}" + + ## Sorted and deduplicated just in case + sort "${POPULAR_SCRIPTS_FILE_RAW}" | uniq > "${POPULAR_SCRIPTS_FILE}" + rm "${POPULAR_SCRIPTS_FILE_RAW}" +} + +# This function is for inserting the cronjob for generating the popular scripts +CRONJOB_CMD="\"${HOME}/electrs/start\" \"${NETWORK}\" popular-scripts" +insert_cronjob() { + (crontab -l 2>/dev/null; echo "${CRONJOB_TIMING} ${CRONJOB_CMD}") | crontab - +} + +case "${2}" in + popular-scripts) + echo "[*] Only generate popular-scripts, then exit" + generate_popular_scripts + exit 0 + ;; + "") + # If the 2nd arg isn't passed, just run the normal electrs script as-is + ;; + *) + echo "${USAGE}" exit 1 ;; esac @@ -115,31 +175,13 @@ do ELECTRUM_TXS_LIMIT=9000 fi - # Run the popular address txt file generator before each run - POPULAR_SCRIPTS_FOLDER="${HOME}/popular-scripts/${NETWORK}" - POPULAR_SCRIPTS_FILE_RAW="${POPULAR_SCRIPTS_FOLDER}/popular-scripts-raw.txt" - POPULAR_SCRIPTS_FILE="${POPULAR_SCRIPTS_FOLDER}/popular-scripts.txt" - mkdir -p "${POPULAR_SCRIPTS_FOLDER}" - rm -f "${POPULAR_SCRIPTS_FILE_RAW}" "${POPULAR_SCRIPTS_FILE}" - - ## Use nproc * 4 threads to generate the txt file (lots of iowait, so 2x~4x core count is ok) - ## Only pick up addresses with 101 history events or more - ## (Without lowering MIN_HISTORY_ITEMS_TO_CACHE this is the lowest we can go) - ## It prints out progress to STDERR - echo "[*] Generating popular-scripts using ${THREADS} threads..." - HIGH_USAGE_THRESHOLD=101 \ - JOB_THREAD_COUNT=${THREADS} \ - cargo run \ - --release \ - --bin popular-scripts \ - --features "${FEATURES}" \ - -- \ - --network "${NETWORK}" \ - --db-dir "${DB_FOLDER}" \ - > "${POPULAR_SCRIPTS_FILE_RAW}" +# if [ ! -e "${POPULAR_SCRIPTS_FILE}" ];then +# generate_popular_scripts +# fi - ## Sorted and deduplicated just in case - sort "${POPULAR_SCRIPTS_FILE_RAW}" | uniq > "${POPULAR_SCRIPTS_FILE}" + if [ ! (crontab -l | grep "${CRONJOB_CMD}") ];then + insert_cronjob + fi # Run the electrs process (Note: db-dir is used in both commands) cargo run \