Skip to content

Commit 157e4ef

Browse files
committed
Add liquid testnet parameters
1 parent a291549 commit 157e4ef

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/address.rs

+25-18
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ impl AddressParams {
146146
bech_hrp: "ert",
147147
blech_hrp: "el",
148148
};
149+
150+
/// The default liquid testnet network address parameters.
151+
pub const LIQUID_TESTNET: AddressParams = AddressParams {
152+
p2pkh_prefix: 36,
153+
p2sh_prefix: 19,
154+
blinded_prefix: 23,
155+
bech_hrp: "tex",
156+
blech_hrp: "tlq",
157+
};
149158
}
150159

151160
/// The method used to produce an address
@@ -439,7 +448,7 @@ impl Address {
439448
if data.len() < 2 || data.len() > 40 + if blinded { 33 } else { 0 } {
440449
return Err(AddressError::InvalidWitnessProgramLength(data.len() - if blinded { 33 } else { 0 }));
441450
}
442-
451+
443452
// Specific segwit v0 check.
444453
if !blinded && version.to_u8() == 0 && data.len() != 20 && data.len() != 32 {
445454
return Err(AddressError::InvalidSegwitV0ProgramLength(data.len()));
@@ -649,20 +658,19 @@ impl FromStr for Address {
649658
// shorthands
650659
let liq = &AddressParams::LIQUID;
651660
let ele = &AddressParams::ELEMENTS;
661+
let liq_test = &AddressParams::LIQUID_TESTNET;
662+
663+
let net_arr = [liq, ele, liq_test];
652664

653-
// Bech32.
654665
let prefix = find_prefix(s);
655-
if match_prefix(prefix, liq.bech_hrp) {
656-
return Address::from_bech32(s, false, liq);
657-
}
658-
if match_prefix(prefix, liq.blech_hrp) {
659-
return Address::from_bech32(s, true, liq);
660-
}
661-
if match_prefix(prefix, ele.bech_hrp) {
662-
return Address::from_bech32(s, false, ele);
663-
}
664-
if match_prefix(prefix, ele.blech_hrp) {
665-
return Address::from_bech32(s, true, ele);
666+
for net in net_arr {
667+
// Bech32.
668+
if match_prefix(prefix, net.bech_hrp) {
669+
return Address::from_bech32(s, false, net);
670+
}
671+
if match_prefix(prefix, net.blech_hrp) {
672+
return Address::from_bech32(s, true, net);
673+
}
666674
}
667675

668676
// Base58.
@@ -675,11 +683,10 @@ impl FromStr for Address {
675683
}
676684

677685
let p = data[0];
678-
if p == liq.p2pkh_prefix || p == liq.p2sh_prefix || p == liq.blinded_prefix {
679-
return Address::from_base58(&data, liq);
680-
}
681-
if p == ele.p2pkh_prefix || p == ele.p2sh_prefix || p == ele.blinded_prefix {
682-
return Address::from_base58(&data, ele);
686+
for net in net_arr {
687+
if p == net.p2pkh_prefix || p == net.p2sh_prefix || p == net.blinded_prefix {
688+
return Address::from_base58(&data, net);
689+
}
683690
}
684691

685692
Err(AddressError::InvalidAddress(s.to_owned()))

0 commit comments

Comments
 (0)