Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong prefix addr #9

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 75 additions & 17 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,17 @@ 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::parse("df").unwrap(),
Network::Testnet | Network::Devnet => Hrp::parse("tf").unwrap(),
Network::Regtest => hrp::BCRT,
};
let encoding = AddressEncoding { payload: self.payload(), p2pkh_prefix, p2sh_prefix, hrp };
Expand Down Expand Up @@ -781,6 +783,10 @@ impl FromStr for Address<NetworkUnchecked> {
(Network::Testnet, Payload::PubkeyHash(PubkeyHash::from_slice(&data[1..]).unwrap())),
SCRIPT_ADDRESS_PREFIX_TEST =>
(Network::Testnet, Payload::ScriptHash(ScriptHash::from_slice(&data[1..]).unwrap())),
PUBKEY_ADDRESS_PREFIX_REGTEST =>
(Network::Testnet, Payload::PubkeyHash(PubkeyHash::from_slice(&data[1..]).unwrap())),
SCRIPT_ADDRESS_PREFIX_REGTEST =>
(Network::Testnet, Payload::ScriptHash(ScriptHash::from_slice(&data[1..]).unwrap())),
x => return Err(ParseError::Base58(base58::Error::InvalidAddressVersion(x))),
};

Expand All @@ -796,6 +802,58 @@ fn segwit_redeem_hash(pubkey_hash: &PubkeyHash) -> crate::hashes::hash160::Hash
crate::hashes::hash160::Hash::from_engine(sha_engine)
}

#[test]
fn test_defi_addr() {
// mainnet
println!("mainnet");
{
let legacy = "8PTeJhFbLR6NFdbXbxMyPVbSHnADbvvBFR";
let legacy = Address::from_str(legacy);
println!("legacy: {:?}", legacy);

let p2sh = "dQgtBZ3rUe89p5xB37BY52ouchoq9eKeSU";
let p2sh = Address::from_str(p2sh);
println!("p2sh: {:?}", p2sh);

let bech32 = "df1q6qvx8rvw4lw6t7dhhvh25s7dm32yh75ufvzdxt";
let bech32 = Address::from_str(bech32);
println!("bech32: {:?}", bech32);
}

// testnet
println!("testnet");
{
let legacy = "73QYLGdMQp7dtsXEfDV5y1APSGDH5AaNpA";
let legacy = Address::from_str(legacy);
println!("legacy: {:?}", legacy);

let p2sh = "ttA5usesnEsseDa2UfRz3HqeDtwEmvMEhr";
let p2sh = Address::from_str(p2sh);
println!("p2sh: {:?}", p2sh);

let bech32 = "tf1qv73jmh3x9ydnzvwuhk739dq7fpquyun7msuppu";
let bech32 = Address::from_str(bech32);
println!("bech32: {:?}", bech32);
}

// regtest
println!("regtest");
{
let legacy = "mwjqFtKDbf8w8bRCLBxxjfyBfBNJcaBAdm";
let legacy = Address::from_str(legacy);
println!("legacy: {:?}", legacy);

let p2sh = "2NFb7jCNEJPz1CyBA6b97mENJPhm6qpfnKc";
let p2sh = Address::from_str(p2sh);
println!("p2sh: {:?}", p2sh);

let bech32 = "bcrt1qeq2g82kj99mqfvnwc2g5w0azzd298q0t84tc6s";
let bech32 = Address::from_str(bech32);
println!("bech32: {:?}", bech32);
}
}


#[cfg(test)]
mod tests {
use core::str::FromStr;
Expand All @@ -805,7 +863,7 @@ mod tests {

use super::*;
use crate::crypto::key::PublicKey;
use crate::network::Network::{Bitcoin, Testnet};
use crate::network::Network::{Mainnet, Testnet};

fn roundtrips(addr: &Address) {
assert_eq!(
Expand Down Expand Up @@ -833,7 +891,7 @@ mod tests {
#[test]
fn test_p2pkh_address_58() {
let addr = Address::new(
Bitcoin,
Mainnet,
Payload::PubkeyHash("162c5ea71c0b23f5b9022ef047c4a86470a5b070".parse().unwrap()),
);

Expand All @@ -849,7 +907,7 @@ mod tests {
#[test]
fn test_p2pkh_from_key() {
let key = "048d5141948c1702e8c95f438815794b87f706a8d4cd2bffad1dc1570971032c9b6042a0431ded2478b5c9cf2d81c124a5e57347a3c63ef0e7716cf54d613ba183".parse::<PublicKey>().unwrap();
let addr = Address::p2pkh(&key, Bitcoin);
let addr = Address::p2pkh(&key, Mainnet);
assert_eq!(&addr.to_string(), "1QJVDzdqb1VpbDK7uDeyVXy9mR27CJiyhY");

let key = "03df154ebfcf29d29cc10d5c2565018bce2d9edbab267c31d2caf44a63056cf99f"
Expand All @@ -864,7 +922,7 @@ mod tests {
#[test]
fn test_p2sh_address_58() {
let addr = Address::new(
Bitcoin,
Mainnet,
Payload::ScriptHash("162c5ea71c0b23f5b9022ef047c4a86470a5b070".parse().unwrap()),
);

Expand Down Expand Up @@ -898,21 +956,21 @@ mod tests {
let mut key = "033bc8c83c52df5712229a2f72206d90192366c36428cb0c12b6af98324d97bfbc"
.parse::<PublicKey>()
.unwrap();
let addr = Address::p2wpkh(&key, Bitcoin).unwrap();
let addr = Address::p2wpkh(&key, Mainnet).unwrap();
assert_eq!(&addr.to_string(), "bc1qvzvkjn4q3nszqxrv3nraga2r822xjty3ykvkuw");
assert_eq!(addr.address_type(), Some(AddressType::P2wpkh));
roundtrips(&addr);

// Test uncompressed pubkey
key.compressed = false;
assert_eq!(Address::p2wpkh(&key, Bitcoin), Err(Error::UncompressedPubkey));
assert_eq!(Address::p2wpkh(&key, Mainnet), Err(Error::UncompressedPubkey));
}

#[test]
fn test_p2wsh() {
// stolen from Bitcoin transaction 5df912fda4becb1c29e928bec8d64d93e9ba8efa9b5b405bd683c86fd2c65667
let script = ScriptBuf::from_hex("52210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae").unwrap();
let addr = Address::p2wsh(&script, Bitcoin);
let addr = Address::p2wsh(&script, Mainnet);
assert_eq!(
&addr.to_string(),
"bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej"
Expand All @@ -927,21 +985,21 @@ mod tests {
let mut key = "026c468be64d22761c30cd2f12cbc7de255d592d7904b1bab07236897cc4c2e766"
.parse::<PublicKey>()
.unwrap();
let addr = Address::p2shwpkh(&key, Bitcoin).unwrap();
let addr = Address::p2shwpkh(&key, Mainnet).unwrap();
assert_eq!(&addr.to_string(), "3QBRmWNqqBGme9er7fMkGqtZtp4gjMFxhE");
assert_eq!(addr.address_type(), Some(AddressType::P2sh));
roundtrips(&addr);

// Test uncompressed pubkey
key.compressed = false;
assert_eq!(Address::p2wpkh(&key, Bitcoin), Err(Error::UncompressedPubkey));
assert_eq!(Address::p2wpkh(&key, Mainnet), Err(Error::UncompressedPubkey));
}

#[test]
fn test_p2shwsh() {
// stolen from Bitcoin transaction f9ee2be4df05041d0e0a35d7caa3157495ca4f93b233234c9967b6901dacf7a9
let script = ScriptBuf::from_hex("522103e5529d8eaa3d559903adb2e881eb06c86ac2574ffa503c45f4e942e2a693b33e2102e5f10fcdcdbab211e0af6a481f5532536ec61a5fdbf7183770cf8680fe729d8152ae").unwrap();
let addr = Address::p2shwsh(&script, Bitcoin);
let addr = Address::p2shwsh(&script, Mainnet);
assert_eq!(&addr.to_string(), "36EqgNnsWW94SreZgBWc1ANC6wpFZwirHr");
assert_eq!(addr.address_type(), Some(AddressType::P2sh));
roundtrips(&addr);
Expand All @@ -954,7 +1012,7 @@ mod tests {
"654f6ea368e0acdfd92976b7c2103a1b26313f430654f6ea368e0acdfd92976b7c2103a1b26313f4"
);
let witness_prog = WitnessProgram::new(WitnessVersion::V13, program.to_vec()).unwrap();
let addr = Address::new(Bitcoin, Payload::WitnessProgram(witness_prog));
let addr = Address::new(Mainnet, Payload::WitnessProgram(witness_prog));
roundtrips(&addr);
}

Expand Down
30 changes: 15 additions & 15 deletions bitcoin/src/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ mod tests {

use super::ChildNumber::{Hardened, Normal};
use super::*;
use crate::network::Network::{self, Bitcoin};
use crate::network::Network::{self, Mainnet};

#[test]
fn test_parse_derivation_path() {
Expand Down Expand Up @@ -1052,32 +1052,32 @@ mod tests {
let seed = hex!("000102030405060708090a0b0c0d0e0f");

// m
test_path(&secp, Bitcoin, &seed, "m".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m".parse().unwrap(),
"xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi",
"xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8");

// m/0h
test_path(&secp, Bitcoin, &seed, "m/0h".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m/0h".parse().unwrap(),
"xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7",
"xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw");

// m/0h/1
test_path(&secp, Bitcoin, &seed, "m/0h/1".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m/0h/1".parse().unwrap(),
"xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs",
"xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ");

// m/0h/1/2h
test_path(&secp, Bitcoin, &seed, "m/0h/1/2h".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m/0h/1/2h".parse().unwrap(),
"xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM",
"xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5");

// m/0h/1/2h/2
test_path(&secp, Bitcoin, &seed, "m/0h/1/2h/2".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m/0h/1/2h/2".parse().unwrap(),
"xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334",
"xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV");

// m/0h/1/2h/2/1000000000
test_path(&secp, Bitcoin, &seed, "m/0h/1/2h/2/1000000000".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m/0h/1/2h/2/1000000000".parse().unwrap(),
"xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76",
"xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy");
}
Expand All @@ -1088,32 +1088,32 @@ mod tests {
let seed = hex!("fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542");

// m
test_path(&secp, Bitcoin, &seed, "m".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m".parse().unwrap(),
"xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U",
"xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB");

// m/0
test_path(&secp, Bitcoin, &seed, "m/0".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m/0".parse().unwrap(),
"xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt",
"xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH");

// m/0/2147483647h
test_path(&secp, Bitcoin, &seed, "m/0/2147483647h".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m/0/2147483647h".parse().unwrap(),
"xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9",
"xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a");

// m/0/2147483647h/1
test_path(&secp, Bitcoin, &seed, "m/0/2147483647h/1".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m/0/2147483647h/1".parse().unwrap(),
"xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef",
"xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon");

// m/0/2147483647h/1/2147483646h
test_path(&secp, Bitcoin, &seed, "m/0/2147483647h/1/2147483646h".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m/0/2147483647h/1/2147483646h".parse().unwrap(),
"xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc",
"xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL");

// m/0/2147483647h/1/2147483646h/2
test_path(&secp, Bitcoin, &seed, "m/0/2147483647h/1/2147483646h/2".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m/0/2147483647h/1/2147483646h/2".parse().unwrap(),
"xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j",
"xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt");
}
Expand All @@ -1124,12 +1124,12 @@ mod tests {
let seed = hex!("4b381541583be4423346c643850da4b320e46a87ae3d2a4e6da11eba819cd4acba45d239319ac14f863b8d5ab5a0d0c64d2e8a1e7d1457df2e5a3c51c73235be");

// m
test_path(&secp, Bitcoin, &seed, "m".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m".parse().unwrap(),
"xprv9s21ZrQH143K25QhxbucbDDuQ4naNntJRi4KUfWT7xo4EKsHt2QJDu7KXp1A3u7Bi1j8ph3EGsZ9Xvz9dGuVrtHHs7pXeTzjuxBrCmmhgC6",
"xpub661MyMwAqRbcEZVB4dScxMAdx6d4nFc9nvyvH3v4gJL378CSRZiYmhRoP7mBy6gSPSCYk6SzXPTf3ND1cZAceL7SfJ1Z3GC8vBgp2epUt13");

// m/0h
test_path(&secp, Bitcoin, &seed, "m/0h".parse().unwrap(),
test_path(&secp, Mainnet, &seed, "m/0h".parse().unwrap(),
"xprv9uPDJpEQgRQfDcW7BkF7eTya6RPxXeJCqCJGHuCJ4GiRVLzkTXBAJMu2qaMWPrS7AANYqdq6vcBcBUdJCVVFceUvJFjaPdGZ2y9WACViL4L",
"xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y");
}
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
4 changes: 2 additions & 2 deletions bitcoin/src/crypto/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ mod tests {

use super::*;
use crate::address::Address;
use crate::network::Network::{Bitcoin, Testnet};
use crate::network::Network::{Mainnet, Testnet};

#[test]
fn test_key_derivation() {
Expand All @@ -797,7 +797,7 @@ mod tests {
// mainnet uncompressed
let sk =
PrivateKey::from_wif("5JYkZjmN7PVMjJUfJWfRFwtuXTGB439XV6faajeHPAM9Z2PT2R3").unwrap();
assert_eq!(sk.network, Bitcoin);
assert_eq!(sk.network, Mainnet);
assert!(!sk.compressed);
assert_eq!(&sk.to_wif(), "5JYkZjmN7PVMjJUfJWfRFwtuXTGB439XV6faajeHPAM9Z2PT2R3");

Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ mod tests {

let mut hd_keypaths: BTreeMap<secp256k1::PublicKey, KeySource> = Default::default();

let mut sk: Xpriv = Xpriv::new_master(Bitcoin, &seed).unwrap();
let mut sk: Xpriv = Xpriv::new_master(Mainnet, &seed).unwrap();

let fprint = sk.fingerprint(secp);

Expand Down
Loading