implements alternate formatting for address
This commit is contained in:
parent
cac3f460a2
commit
104836a042
|
@ -359,11 +359,7 @@ impl Address {
|
||||||
/// Even inside Bitcoin URI may be more efficient to use the uppercase address since in QR codes
|
/// Even inside Bitcoin URI may be more efficient to use the uppercase address since in QR codes
|
||||||
/// encoding modes can be mixed as needed within a QR symbol.
|
/// encoding modes can be mixed as needed within a QR symbol.
|
||||||
pub fn to_qr_string(&self) -> String {
|
pub fn to_qr_string(&self) -> String {
|
||||||
let address_string = self.to_string();
|
format!("{:#}", self)
|
||||||
match self.payload {
|
|
||||||
Payload::WitnessProgram { .. } => address_string.to_ascii_uppercase(),
|
|
||||||
_ => address_string,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,6 +388,11 @@ impl fmt::Display for Address {
|
||||||
version: ver,
|
version: ver,
|
||||||
program: ref prog,
|
program: ref prog,
|
||||||
} => {
|
} => {
|
||||||
|
if fmt.alternate() {
|
||||||
|
//TODO format without allocation when alternate uppercase is in bech32
|
||||||
|
let lower = self.to_string();
|
||||||
|
write!(fmt, "{}", lower.to_ascii_uppercase())
|
||||||
|
} else {
|
||||||
let hrp = match self.network {
|
let hrp = match self.network {
|
||||||
Network::Bitcoin => "bc",
|
Network::Bitcoin => "bc",
|
||||||
Network::Testnet | Network::Signet => "tb",
|
Network::Testnet | Network::Signet => "tb",
|
||||||
|
@ -404,6 +405,7 @@ impl fmt::Display for Address {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Extract the bech32 prefix.
|
/// Extract the bech32 prefix.
|
||||||
/// Returns the same slice when no prefix is found.
|
/// Returns the same slice when no prefix is found.
|
||||||
|
|
Loading…
Reference in New Issue