From ee8b672def878ef464730f20c2befa50fe1f6bd0 Mon Sep 17 00:00:00 2001 From: canonbrother Date: Mon, 16 Sep 2024 15:14:56 +0800 Subject: [PATCH] fix --- bitcoin/src/address/mod.rs | 12 ++++++++---- bitcoin/src/blockdata/constants.rs | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/bitcoin/src/address/mod.rs b/bitcoin/src/address/mod.rs index 5e0a4fd5..82d86448 100644 --- a/bitcoin/src/address/mod.rs +++ b/bitcoin/src/address/mod.rs @@ -39,8 +39,8 @@ use secp256k1::{Secp256k1, Verification, XOnlyPublicKey}; use crate::base58; use crate::blockdata::constants::{ - MAX_SCRIPT_ELEMENT_SIZE, PUBKEY_ADDRESS_PREFIX_MAIN, PUBKEY_ADDRESS_PREFIX_TEST, - SCRIPT_ADDRESS_PREFIX_MAIN, SCRIPT_ADDRESS_PREFIX_TEST, + MAX_SCRIPT_ELEMENT_SIZE, PUBKEY_ADDRESS_PREFIX_MAIN, PUBKEY_ADDRESS_PREFIX_REGTEST, PUBKEY_ADDRESS_PREFIX_TEST, + SCRIPT_ADDRESS_PREFIX_MAIN, SCRIPT_ADDRESS_PREFIX_REGTEST, SCRIPT_ADDRESS_PREFIX_TEST, }; use crate::blockdata::script::witness_program::WitnessProgram; use crate::blockdata::script::witness_version::WitnessVersion; @@ -368,15 +368,19 @@ impl Address { fn fmt_internal(&self, fmt: &mut fmt::Formatter) -> fmt::Result { let p2pkh_prefix = match self.network() { Network::Mainnet => PUBKEY_ADDRESS_PREFIX_MAIN, - Network::Testnet | Network::Devnet | Network::Regtest => PUBKEY_ADDRESS_PREFIX_TEST, + Network::Testnet | Network::Devnet | Network::Devnet => PUBKEY_ADDRESS_PREFIX_TEST, + Network::Regtest => PUBKEY_ADDRESS_PREFIX_REGTEST, }; let p2sh_prefix = match self.network() { Network::Mainnet => SCRIPT_ADDRESS_PREFIX_MAIN, - Network::Testnet | Network::Devnet | Network::Regtest => SCRIPT_ADDRESS_PREFIX_TEST, + Network::Testnet | Network::Devnet | Network::Devnet => SCRIPT_ADDRESS_PREFIX_TEST, + Network::Regtest => SCRIPT_ADDRESS_PREFIX_REGTEST, }; let hrp = match self.network() { Network::Mainnet => hrp::BC, Network::Testnet | Network::Devnet => hrp::TB, + // Network::Mainnet => hrp::DF, + // Network::Testnet | Network::Devnet => hrp::TF, Network::Regtest => hrp::BCRT, }; let encoding = AddressEncoding { payload: self.payload(), p2pkh_prefix, p2sh_prefix, hrp }; diff --git a/bitcoin/src/blockdata/constants.rs b/bitcoin/src/blockdata/constants.rs index 544350c5..d716a88f 100644 --- a/bitcoin/src/blockdata/constants.rs +++ b/bitcoin/src/blockdata/constants.rs @@ -36,18 +36,28 @@ pub const DIFFCHANGE_TIMESPAN: u32 = 14 * 24 * 3600; pub const WITNESS_SCALE_FACTOR: usize = 4; /// The maximum allowed number of signature check operations in a block. pub const MAX_BLOCK_SIGOPS_COST: i64 = 80_000; + /// Mainnet (bitcoin) pubkey address prefix. // pub const PUBKEY_ADDRESS_PREFIX_MAIN: u8 = 0; // 0x00 -pub const PUBKEY_ADDRESS_PREFIX_MAIN: u8 = 18; // 0x12 (defichain) +pub const PUBKEY_ADDRESS_PREFIX_MAIN: u8 = 18; // 0x12 (defichain mainnet) + /// Mainnet (bitcoin) script address prefix. // pub const SCRIPT_ADDRESS_PREFIX_MAIN: u8 = 5; // 0x05 -pub const SCRIPT_ADDRESS_PREFIX_MAIN: u8 = 90; // 0x5a (defichain) +pub const SCRIPT_ADDRESS_PREFIX_MAIN: u8 = 90; // 0x5a (defichain mainnet) + /// Test (tesnet, signet, regtest) pubkey address prefix. // pub const PUBKEY_ADDRESS_PREFIX_TEST: u8 = 111; // 0x6f -pub const PUBKEY_ADDRESS_PREFIX_TEST: u8 = 15; // 0xf (defichain) +pub const PUBKEY_ADDRESS_PREFIX_TEST: u8 = 15; // 0xf (defichain testnet, devnet, changi) + /// Test (tesnet, signet, regtest) script address prefix. // pub const SCRIPT_ADDRESS_PREFIX_TEST: u8 = 196; // 0xc4 -pub const SCRIPT_ADDRESS_PREFIX_TEST: u8 = 128; // 0x80 (defichain) +pub const SCRIPT_ADDRESS_PREFIX_TEST: u8 = 128; // 0x80 (defichain testnet, devnet changi) + +/// Regtest pubkey address prefix. +pub const PUBKEY_ADDRESS_PREFIX_REGTEST: u8 = 111; // 0x6f (defichain regtest) +/// Regtest script address prefix. +pub const SCRIPT_ADDRESS_PREFIX_REGTEST: u8 = 196; // 0xc4 (defichain regtest) + /// The maximum allowed script size. pub const MAX_SCRIPT_ELEMENT_SIZE: usize = 520; /// How may blocks between halvings.