Skip to content

Commit

Permalink
v3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnetwork committed Dec 21, 2023
1 parent e84597e commit 0b834c7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.0.1

* Update dependencies

## 3.0.0

* Downgrade dart SDK from 3.1 to 2.15
Expand Down
15 changes: 5 additions & 10 deletions lib/src/bitcoin/address/core.dart
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -15,6 +16,7 @@ class BitcoinAddressType {
static const BitcoinAddressType p2pkInP2sh =
BitcoinAddressType._("P2SH/P2PK");

@override
final String value;

const BitcoinAddressType._(this.value);
Expand All @@ -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
Expand Down
59 changes: 43 additions & 16 deletions lib/src/models/network.dart
Original file line number Diff line number Diff line change
@@ -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<int> wifNetVer;

Expand All @@ -20,24 +21,38 @@ abstract class BasedUtxoNetwork {
abstract final CoinConf conf;

abstract final List<BitcoinAddressType> 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions lib/src/utils/enumerate.dart
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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: [email protected]
Expand All @@ -16,7 +16,7 @@ environment:


dependencies:
blockchain_utils: ^1.4.0
blockchain_utils: ^1.4.1

dev_dependencies:
test: ^1.24.6
Expand Down

0 comments on commit 0b834c7

Please sign in to comment.