diff --git a/lib/src/models/network.dart b/lib/src/models/network.dart index 0000bed..4332b41 100644 --- a/lib/src/models/network.dart +++ b/lib/src/models/network.dart @@ -48,7 +48,9 @@ abstract class BasedUtxoNetwork implements Enumerate { BitcoinCashNetwork.testnet, BitcoinSVNetwork.mainnet, BitcoinSVNetwork.testnet, - PepeNetwork.mainnet + PepeNetwork.mainnet, + ElectraProtocolNetwork.mainnet, + ElectraProtocolNetwork.testnet, ]; static BasedUtxoNetwork fromName(String name) { @@ -379,6 +381,7 @@ class BitcoinCashNetwork implements BasedUtxoNetwork { /// Constructor for creating a Bitcoin Cash network with a specific configuration. const BitcoinCashNetwork._(this.value, this.conf); + @override final String value; @@ -493,3 +496,76 @@ class PepeNetwork implements BasedUtxoNetwork { return [Bip44Coins.pepecoinTestnet, Bip49Coins.pepecoinTestnet]; } } + +/// Class representing a Electra Protocol network, implementing the `BasedUtxoNetwork` abstract class. +class ElectraProtocolNetwork implements BasedUtxoNetwork { + /// Mainnet configuration with associated `CoinConf`. + static const ElectraProtocolNetwork mainnet = ElectraProtocolNetwork._( + "electraProtocolMainnet", + CoinsConf.electraProtocolMainNet, + ); + + /// Testnet configuration with associated `CoinConf`. + static const ElectraProtocolNetwork testnet = ElectraProtocolNetwork._( + "electraProtocolTestnet", + CoinsConf.electraProtocolTestNet, + ); + + /// Overrides the `conf` property from `BasedUtxoNetwork` with the associated `CoinConf`. + @override + final CoinConf conf; + + /// Constructor for creating a OmniXEP network with a specific configuration. + const ElectraProtocolNetwork._(this.value, this.conf); + + @override + final String value; + + /// Retrieves the Wallet Import Format (WIF) version bytes from the associated `CoinConf`. + @override + List get wifNetVer => conf.params.wifNetVer!; + + /// Retrieves the Pay-to-Public-Key-Hash (P2PKH) version bytes from the associated `CoinConf`. + @override + List get p2pkhNetVer => conf.params.p2pkhNetVer!; + + /// Retrieves the Pay-to-Script-Hash (P2SH) version bytes from the associated `CoinConf`. + @override + List get p2shNetVer => conf.params.p2shNetVer!; + + /// Retrieves the Human-Readable Part (HRP) for Pay-to-Witness-Public-Key-Hash (P2WPKH) addresses. + @override + String get p2wpkhHrp => conf.params.p2wpkhHrp!; + + /// Checks if the current network is the mainnet. + @override + bool get isMainnet => this == ElectraProtocolNetwork.mainnet; + + @override + final List supportedAddress = const [ + PubKeyAddressType.p2pk, + P2pkhAddressType.p2pkh, + SegwitAddresType.p2wpkh, + SegwitAddresType.p2wsh, + P2shAddressType.p2pkInP2sh, + P2shAddressType.p2pkhInP2sh, + P2shAddressType.p2wpkhInP2sh, + P2shAddressType.p2wshInP2sh, + ]; + + @override + List get coins { + if (isMainnet) { + return [ + Bip44Coins.electraProtocol, + Bip49Coins.electraProtocol, + Bip84Coins.electraProtocol, + ]; + } + return [ + Bip44Coins.electraProtocolTestnet, + Bip49Coins.electraProtocolTestnet, + Bip84Coins.electraProtocolTestnet, + ]; + } +}