mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-05-26 03:06:53 +08:00
add to_string() and from_string() trait impls
This commit is contained in:
@@ -18,13 +18,14 @@
|
||||
*/
|
||||
|
||||
use burnchains::Address;
|
||||
use burnchains::Hash160;
|
||||
use burnchains::bitcoin::BitcoinNetworkType;
|
||||
|
||||
use burnchains::bitcoin::Error as btc_error;
|
||||
|
||||
use bitcoin::util::base58;
|
||||
|
||||
use util::hash::Hash160;
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone, Serialize, Deserialize)]
|
||||
pub enum BitcoinAddressType {
|
||||
PublicKeyHash,
|
||||
@@ -173,16 +174,25 @@ impl Address for BitcoinAddress {
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
self.bytes.as_bytes().to_vec()
|
||||
}
|
||||
|
||||
fn to_string(&self) -> String {
|
||||
self.to_b58()
|
||||
}
|
||||
|
||||
fn from_string(s: &String) -> Option<BitcoinAddress> {
|
||||
match BitcoinAddress::from_b58(s) {
|
||||
Ok(a) => Some(a),
|
||||
Err(_e) => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{BitcoinAddress, BitcoinAddressType};
|
||||
use burnchains::bitcoin::BitcoinNetworkType;
|
||||
use burnchains::Address;
|
||||
use burnchains::Hash160;
|
||||
use util::log as logger;
|
||||
use util::hash::hex_bytes;
|
||||
use util::hash::{hex_bytes, Hash160};
|
||||
|
||||
struct AddressFixture {
|
||||
addr: String,
|
||||
@@ -263,7 +273,7 @@ mod tests {
|
||||
test_debug!("Decoded an address when we should not have");
|
||||
assert!(false);
|
||||
}
|
||||
(Err(_e), Some(res)) => {
|
||||
(Err(_e), Some(_res)) => {
|
||||
test_debug!("Failed to decode when we should have: {}", fixture.addr);
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user