Skip to content

Commit

Permalink
Merge pull request #11 from sandrocsimas/main
Browse files Browse the repository at this point in the history
Support Electra Protocol network
  • Loading branch information
mrtnetwork authored Dec 4, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents f9b8f24 + eeb34b9 commit f451e9c
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion lib/src/models/network.dart
Original file line number Diff line number Diff line change
@@ -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<int> get wifNetVer => conf.params.wifNetVer!;

/// Retrieves the Pay-to-Public-Key-Hash (P2PKH) version bytes from the associated `CoinConf`.
@override
List<int> get p2pkhNetVer => conf.params.p2pkhNetVer!;

/// Retrieves the Pay-to-Script-Hash (P2SH) version bytes from the associated `CoinConf`.
@override
List<int> 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<BitcoinAddressType> supportedAddress = const [
PubKeyAddressType.p2pk,
P2pkhAddressType.p2pkh,
SegwitAddresType.p2wpkh,
SegwitAddresType.p2wsh,
P2shAddressType.p2pkInP2sh,
P2shAddressType.p2pkhInP2sh,
P2shAddressType.p2wpkhInP2sh,
P2shAddressType.p2wshInP2sh,
];

@override
List<BipCoins> get coins {
if (isMainnet) {
return [
Bip44Coins.electraProtocol,
Bip49Coins.electraProtocol,
Bip84Coins.electraProtocol,
];
}
return [
Bip44Coins.electraProtocolTestnet,
Bip49Coins.electraProtocolTestnet,
Bip84Coins.electraProtocolTestnet,
];
}
}

0 comments on commit f451e9c

Please sign in to comment.