Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Sep 16, 2024
1 parent 3f4ba5c commit ee8b672
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
12 changes: 8 additions & 4 deletions bitcoin/src/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -368,15 +368,19 @@ impl<V: NetworkValidation> Address<V> {
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 };
Expand Down
18 changes: 14 additions & 4 deletions bitcoin/src/blockdata/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ee8b672

Please sign in to comment.