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
|
||||
/// encoding modes can be mixed as needed within a QR symbol.
|
||||
pub fn to_qr_string(&self) -> String {
|
||||
let address_string = self.to_string();
|
||||
match self.payload {
|
||||
Payload::WitnessProgram { .. } => address_string.to_ascii_uppercase(),
|
||||
_ => address_string,
|
||||
}
|
||||
format!("{:#}", self)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -392,6 +388,11 @@ impl fmt::Display for Address {
|
|||
version: ver,
|
||||
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 {
|
||||
Network::Bitcoin => "bc",
|
||||
Network::Testnet | Network::Signet => "tb",
|
||||
|
@ -403,6 +404,7 @@ impl fmt::Display for Address {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract the bech32 prefix.
|
||||
|
|
Loading…
Reference in New Issue