rpc_utils.rs (2473B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2022-2026 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 use std::{path::PathBuf, str::FromStr}; 17 18 use bitcoin::{Amount, Network}; 19 20 /// Default chain dir <https://github.com/bitcoin/bitcoin/blob/master/doc/files.md#data-directory-location> 21 pub fn chain_dir(network: Network) -> &'static str { 22 match network { 23 Network::Bitcoin => "main", 24 Network::Testnet => "testnet3", 25 Network::Regtest => "regtest", 26 Network::Signet => "signet", 27 _ => unimplemented!(), 28 } 29 } 30 31 /// Default rpc port <https://github.com/bitcoin/bitcoin/blob/master/share/examples/bitcoin.conf> 32 pub fn rpc_port(network: Network) -> u16 { 33 match network { 34 Network::Bitcoin => 8332, 35 Network::Testnet => 18332, 36 Network::Regtest => 18443, 37 Network::Signet => 38333, 38 _ => unimplemented!(), 39 } 40 } 41 42 /// Default bitcoin data_dir <https://github.com/bitcoin/bitcoin/blob/master/doc/bitcoin-conf.md> 43 pub fn default_data_dir() -> PathBuf { 44 if cfg!(target_os = "windows") { 45 PathBuf::from_str(&std::env::var("APPDATA").unwrap()) 46 .unwrap() 47 .join("Bitcoin") 48 } else if cfg!(target_os = "linux") { 49 PathBuf::from_str(&std::env::var("HOME").unwrap()) 50 .unwrap() 51 .join(".bitcoin") 52 } else if cfg!(target_os = "macos") { 53 PathBuf::from_str(&std::env::var("HOME").unwrap()) 54 .unwrap() 55 .join("Library/Application Support/Bitcoin") 56 } else { 57 unimplemented!("Only windows, linux or macos") 58 } 59 } 60 61 /// Minimum dust amount to perform a transaction to a segwit address 62 pub fn segwit_min_amount() -> Amount { 63 // https://github.com/bitcoin/bitcoin/blob/master/src/policy/policy.cpp 64 Amount::from_sat(294) 65 }