From 0b834c746cb6b3860acdb9ee0d2bc6af027343b6 Mon Sep 17 00:00:00 2001 From: Mohsen <56779182+mrtnetwork@users.noreply.github.com> Date: Thu, 21 Dec 2023 07:10:08 +0330 Subject: [PATCH] v3.0.1 --- CHANGELOG.md | 4 +++ lib/src/bitcoin/address/core.dart | 15 +++----- lib/src/models/network.dart | 59 ++++++++++++++++++++++--------- lib/src/utils/enumerate.dart | 13 +++++++ pubspec.yaml | 4 +-- 5 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 lib/src/utils/enumerate.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index d2fc4de..9d46831 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 3.0.1 + +* Update dependencies + ## 3.0.0 * Downgrade dart SDK from 3.1 to 2.15 diff --git a/lib/src/bitcoin/address/core.dart b/lib/src/bitcoin/address/core.dart index 773abe4..33ea7f2 100644 --- a/lib/src/bitcoin/address/core.dart +++ b/lib/src/bitcoin/address/core.dart @@ -1,6 +1,7 @@ import 'package:bitcoin_base/bitcoin_base.dart'; +import 'package:bitcoin_base/src/utils/enumerate.dart'; -class BitcoinAddressType { +class BitcoinAddressType implements Enumerate { static const BitcoinAddressType p2pkh = BitcoinAddressType._("P2PKH"); static const BitcoinAddressType p2wpkh = BitcoinAddressType._("P2WPKH"); static const BitcoinAddressType p2pk = BitcoinAddressType._("P2PK"); @@ -15,6 +16,7 @@ class BitcoinAddressType { static const BitcoinAddressType p2pkInP2sh = BitcoinAddressType._("P2SH/P2PK"); + @override final String value; const BitcoinAddressType._(this.value); @@ -28,15 +30,8 @@ class BitcoinAddressType { /// Check if the address type is Pay-to-Script-Hash (P2SH). bool get isP2sh { - switch (this) { - case p2wshInP2sh: - case p2wpkhInP2sh: - case p2pkhInP2sh: - case p2pkInP2sh: - return true; - default: - return false; - } + if (value.startsWith("P2SH")) return true; + return false; } // Enum values as a list for iteration diff --git a/lib/src/models/network.dart b/lib/src/models/network.dart index fd9fbed..61b21f0 100644 --- a/lib/src/models/network.dart +++ b/lib/src/models/network.dart @@ -1,9 +1,10 @@ import 'package:bitcoin_base/bitcoin_base.dart'; +import 'package:bitcoin_base/src/utils/enumerate.dart'; import 'package:blockchain_utils/bip/coin_conf/coin_conf.dart'; import 'package:blockchain_utils/bip/coin_conf/coins_conf.dart'; /// Abstract class representing a base for UTXO-based cryptocurrency networks. -abstract class BasedUtxoNetwork { +abstract class BasedUtxoNetwork implements Enumerate { /// List of version bytes for Wallet Import Format (WIF). abstract final List wifNetVer; @@ -20,24 +21,38 @@ abstract class BasedUtxoNetwork { abstract final CoinConf conf; abstract final List supportedAddress; + + @override + operator ==(other) { + if (identical(other, this)) return true; + return other is BasedUtxoNetwork && + other.runtimeType == runtimeType && + value == other.value; + } + + @override + int get hashCode => value.hashCode; } /// Class representing a Bitcoin network, implementing the `BasedUtxoNetwork` abstract class. class BitcoinNetwork implements BasedUtxoNetwork { /// Mainnet configuration with associated `CoinConf`. static const BitcoinNetwork mainnet = - BitcoinNetwork._(CoinsConf.bitcoinMainNet); + BitcoinNetwork._("bitcoinMainnet", CoinsConf.bitcoinMainNet); /// Testnet configuration with associated `CoinConf`. static const BitcoinNetwork testnet = - BitcoinNetwork._(CoinsConf.bitcoinTestNet); + BitcoinNetwork._("bitcoinTestnet", CoinsConf.bitcoinTestNet); /// Overrides the `conf` property from `BasedUtxoNetwork` with the associated `CoinConf`. @override final CoinConf conf; + @override + final String value; + /// Constructor for creating a Bitcoin network with a specific configuration. - const BitcoinNetwork._(this.conf); + const BitcoinNetwork._(this.value, this.conf); /// Retrieves the Wallet Import Format (WIF) version bytes from the associated `CoinConf`. @override @@ -67,18 +82,20 @@ class BitcoinNetwork implements BasedUtxoNetwork { class LitecoinNetwork implements BasedUtxoNetwork { /// Mainnet configuration with associated `CoinConf`. static const LitecoinNetwork mainnet = - LitecoinNetwork._(CoinsConf.litecoinMainNet); + LitecoinNetwork._("litecoinMainnet", CoinsConf.litecoinMainNet); /// Testnet configuration with associated `CoinConf`. static const LitecoinNetwork testnet = - LitecoinNetwork._(CoinsConf.litecoinTestNet); + LitecoinNetwork._("litecoinTestnet", CoinsConf.litecoinTestNet); /// Overrides the `conf` property from `BasedUtxoNetwork` with the associated `CoinConf`. @override final CoinConf conf; + @override + final String value; /// Constructor for creating a Litecoin network with a specific configuration. - const LitecoinNetwork._(this.conf); + const LitecoinNetwork._(this.value, this.conf); /// Retrieves the Wallet Import Format (WIF) version bytes from the associated `CoinConf`. @override @@ -116,17 +133,19 @@ class LitecoinNetwork implements BasedUtxoNetwork { /// Class representing a Dash network, implementing the `BasedUtxoNetwork` abstract class. class DashNetwork implements BasedUtxoNetwork { /// Mainnet configuration with associated `CoinConf`. - static const DashNetwork mainnet = DashNetwork._(CoinsConf.dashMainNet); + static const DashNetwork mainnet = + DashNetwork._("dashMainnet", CoinsConf.dashMainNet); /// Testnet configuration with associated `CoinConf`. - static const DashNetwork testnet = DashNetwork._(CoinsConf.dashTestNet); + static const DashNetwork testnet = + DashNetwork._("dashTestnet", CoinsConf.dashTestNet); /// Overrides the `conf` property from `BasedUtxoNetwork` with the associated `CoinConf`. @override final CoinConf conf; /// Constructor for creating a Dash network with a specific configuration. - const DashNetwork._(this.conf); + const DashNetwork._(this.value, this.conf); /// Retrieves the Wallet Import Format (WIF) version bytes from the associated `CoinConf`. @override @@ -155,24 +174,30 @@ class DashNetwork implements BasedUtxoNetwork { BitcoinAddressType.p2pkhInP2sh, BitcoinAddressType.p2pkInP2sh ]; + + @override + final String value; } /// Class representing a Dogecoin network, implementing the `BasedUtxoNetwork` abstract class. class DogecoinNetwork implements BasedUtxoNetwork { /// Mainnet configuration with associated `CoinConf`. static const DogecoinNetwork mainnet = - DogecoinNetwork._(CoinsConf.dogecoinMainNet); + DogecoinNetwork._("dogeMainnet", CoinsConf.dogecoinMainNet); /// Testnet configuration with associated `CoinConf`. static const DogecoinNetwork testnet = - DogecoinNetwork._(CoinsConf.dogecoinTestNet); + DogecoinNetwork._("dogeTestnet", CoinsConf.dogecoinTestNet); /// Overrides the `conf` property from `BasedUtxoNetwork` with the associated `CoinConf`. @override final CoinConf conf; /// Constructor for creating a Dogecoin network with a specific configuration. - const DogecoinNetwork._(this.conf); + const DogecoinNetwork._(this.value, this.conf); + + @override + final String value; /// Retrieves the Wallet Import Format (WIF) version bytes from the associated `CoinConf`. @override @@ -207,18 +232,20 @@ class DogecoinNetwork implements BasedUtxoNetwork { class BitcoinCashNetwork implements BasedUtxoNetwork { /// Mainnet configuration with associated `CoinConf`. static const BitcoinCashNetwork mainnet = - BitcoinCashNetwork._(CoinsConf.bitcoinCashMainNet); + BitcoinCashNetwork._("bitcoinCashMainnet", CoinsConf.bitcoinCashMainNet); /// Testnet configuration with associated `CoinConf`. static const BitcoinCashNetwork testnet = - BitcoinCashNetwork._(CoinsConf.bitcoinCashTestNet); + BitcoinCashNetwork._("bitcoinCashTestnet", CoinsConf.bitcoinCashTestNet); /// Overrides the `conf` property from `BasedUtxoNetwork` with the associated `CoinConf`. @override final CoinConf conf; /// Constructor for creating a Bitcoin Cash network with a specific configuration. - const BitcoinCashNetwork._(this.conf); + const BitcoinCashNetwork._(this.value, this.conf); + @override + final String value; /// Retrieves the Wallet Import Format (WIF) version bytes from the associated `CoinConf`. @override diff --git a/lib/src/utils/enumerate.dart b/lib/src/utils/enumerate.dart new file mode 100644 index 0000000..d92347e --- /dev/null +++ b/lib/src/utils/enumerate.dart @@ -0,0 +1,13 @@ +abstract class Enumerate { + String get value; + + @override + operator ==(other) { + if (identical(other, this)) return true; + if (other is! Enumerate) return false; + return other.runtimeType == runtimeType && value == other.value; + } + + @override + int get hashCode => value.hashCode; +} diff --git a/pubspec.yaml b/pubspec.yaml index 802ade5..d37c492 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bitcoin_base description: A versatile library for Bitcoin, Dogecoin, Litecoin, Dash, and BCH. Supports P2PKH, P2SH, P2WPKH, P2WSH, Taproot, with advanced creation, signing, and spending capabilities. -version: 3.0.0 +version: 3.0.1 homepage: "https://github.com/mrtnetwork/bitcoin_base" repository: "https://github.com/mrtnetwork/bitcoin_base" Author: mrhaydari.t@gmail.com @@ -16,7 +16,7 @@ environment: dependencies: - blockchain_utils: ^1.4.0 + blockchain_utils: ^1.4.1 dev_dependencies: test: ^1.24.6