anychain_bitcoin/network/
dogecoin_testnet.rs1use crate::{BitcoinFormat, BitcoinNetwork, Prefix};
2use anychain_core::no_std::*;
3use anychain_core::{AddressError, Network, NetworkError};
4
5use core::{fmt, str::FromStr};
6use serde::Serialize;
7
8#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
9pub struct DogecoinTestnet;
10
11impl Network for DogecoinTestnet {
12 const NAME: &'static str = "dogecoin testnet";
13}
14
15pub static mut LOOP: u8 = 0;
16
17impl BitcoinNetwork for DogecoinTestnet {
18 fn to_address_prefix(format: BitcoinFormat) -> Result<Prefix, AddressError> {
20 match format {
21 BitcoinFormat::P2PKH => Ok(Prefix::Version(0x71)),
22 BitcoinFormat::P2WSH => Ok(Prefix::Version(0x00)),
23 BitcoinFormat::P2SH_P2WPKH => Ok(Prefix::Version(0xc4)),
24 f => Err(AddressError::Message(format!(
25 "{} does not support address format {}",
26 Self::NAME,
27 f,
28 ))),
29 }
30 }
31
32 fn from_address_prefix(prefix: Prefix) -> Result<Self, AddressError> {
34 match prefix {
35 Prefix::Version(version) => match version {
36 0x71 | 0xc4 => Ok(Self),
37 _ => Err(AddressError::Message(format!(
38 "Invalid version byte {:#0x} for {} network",
39 version,
40 Self::NAME,
41 ))),
42 },
43 _ => Err(AddressError::Message(format!(
44 "{} does not support address format Bech32 or CashAddr",
45 Self::NAME,
46 ))),
47 }
48 }
49}
50
51impl FromStr for DogecoinTestnet {
52 type Err = NetworkError;
53
54 fn from_str(s: &str) -> Result<Self, Self::Err> {
55 match s {
56 Self::NAME => Ok(Self),
57 _ => Err(NetworkError::InvalidNetwork(s.into())),
58 }
59 }
60}
61
62impl fmt::Display for DogecoinTestnet {
63 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
64 write!(f, "{}", Self::NAME)
65 }
66}