From 2b3db4f4987e6e7aa85927b89718b68a1f86e577 Mon Sep 17 00:00:00 2001 From: shamardy <39480341+shamardy@users.noreply.github.com> Date: Wed, 21 Apr 2021 06:34:22 +0200 Subject: [PATCH] Make SIGHASH_FORKID configurable with coins file #905 (#912) * Make SIGHASH_FORKID configurable with coins file * added hardcoded BCH fork_id for non updated config * fix code format --- mm2src/coins/utxo.rs | 12 +++++++----- mm2src/mm2_tests.rs | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mm2src/coins/utxo.rs b/mm2src/coins/utxo.rs index e065b0d404..3710fc15fc 100644 --- a/mm2src/coins/utxo.rs +++ b/mm2src/coins/utxo.rs @@ -916,11 +916,13 @@ impl<'a> UtxoConfBuilder<'a> { } fn fork_id(&self) -> u32 { - if self.ticker == "BCH" { - 0x40 - } else { - 0 - } + let default_fork_id = match self.ticker { + "BCH" => "0x40", + _ => "0x0", + }; + let hex_string = self.conf["fork_id"].as_str().unwrap_or(default_fork_id); + let fork_id = u32::from_str_radix(hex_string.trim_start_matches("0x"), 16).unwrap(); + fork_id } fn required_confirmations(&self) -> u64 { diff --git a/mm2src/mm2_tests.rs b/mm2src/mm2_tests.rs index c00d371a7c..88de4d6208 100644 --- a/mm2src/mm2_tests.rs +++ b/mm2src/mm2_tests.rs @@ -3417,7 +3417,7 @@ fn spin_n_nodes(seednodes: &[&str], coins: &Json, n: usize) -> Vec<(MarketMakerI #[cfg(not(target_arch = "wasm32"))] fn test_withdraw_cashaddresses() { let coins = json!([ - {"coin":"BCH","pubtype":0,"p2shtype":5,"mm2":1,"protocol":{"type":"UTXO"}, + {"coin":"BCH","pubtype":0,"p2shtype":5,"mm2":1,"fork_id": "0x40","protocol":{"type":"UTXO"}, "address_format":{"format":"cashaddress","network":"bchtest"}}, ]);