Skip to content

Commit 32d40f0

Browse files
OttoAllmendingerllm-git
andcommitted
feat(wasm-utxo): add to_utxolib_name for Network enum
Adds a new method to convert Network enum values to their corresponding utxolib string names. The implementation is validated with bidirectional tests to ensure consistency. Issue: BTC-2652 Co-authored-by: llm-git <[email protected]>
1 parent 4966e30 commit 32d40f0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

packages/wasm-utxo/src/networks.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,32 @@ impl Network {
174174
}
175175
}
176176

177+
pub fn to_utxolib_name(&self) -> &'static str {
178+
match self {
179+
Network::Bitcoin => "bitcoin",
180+
Network::BitcoinTestnet3 => "testnet",
181+
Network::BitcoinTestnet4 => "bitcoinTestnet4",
182+
Network::BitcoinPublicSignet => "bitcoinPublicSignet",
183+
Network::BitcoinBitGoSignet => "bitcoinBitGoSignet",
184+
Network::BitcoinCash => "bitcoincash",
185+
Network::BitcoinCashTestnet => "bitcoincashTestnet",
186+
Network::Ecash => "ecash",
187+
Network::EcashTestnet => "ecashTest",
188+
Network::BitcoinGold => "bitcoingold",
189+
Network::BitcoinGoldTestnet => "bitcoingoldTestnet",
190+
Network::BitcoinSV => "bitcoinsv",
191+
Network::BitcoinSVTestnet => "bitcoinsvTestnet",
192+
Network::Dash => "dash",
193+
Network::DashTestnet => "dashTest",
194+
Network::Dogecoin => "dogecoin",
195+
Network::DogecoinTestnet => "dogecoinTest",
196+
Network::Litecoin => "litecoin",
197+
Network::LitecoinTestnet => "litecoinTest",
198+
Network::Zcash => "zcash",
199+
Network::ZcashTestnet => "zcashTest",
200+
}
201+
}
202+
177203
/// Convert from a bitgo coin name to a Network enum value.
178204
pub fn from_coin_name(name: &str) -> Option<Network> {
179205
match name {
@@ -323,6 +349,12 @@ mod tests {
323349
"Failed for name: {}",
324350
name
325351
);
352+
assert_eq!(
353+
network.to_utxolib_name(),
354+
name,
355+
"Failed for network: {}",
356+
network
357+
);
326358
}
327359
}
328360

0 commit comments

Comments
 (0)