Skip to content

Commit

Permalink
add some types for find network address support
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnetwork committed Dec 6, 2023
1 parent e70868d commit 959ed04
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.1

* add some types for find network address support

## 2.0.0

* Added support for Dogecoin, Litecoin, Bitcoin Cash, and Dash.
Expand Down
36 changes: 36 additions & 0 deletions lib/src/models/network.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:bitcoin_base/bitcoin_base.dart';
import 'package:blockchain_utils/bip/coin_conf/coin_conf.dart';
import 'package:blockchain_utils/bip/coin_conf/coins_conf.dart';

Expand All @@ -17,6 +18,8 @@ abstract class BasedUtxoNetwork {

/// Configuration object specific to the coin.
abstract final CoinConf conf;

abstract final List<BitcoinAddressType> supportedAddress;
}

/// Enum representing different Bitcoin networks, implementing the `BasedUtxoNetwork` abstract class.
Expand Down Expand Up @@ -53,6 +56,10 @@ enum BitcoinNetwork implements BasedUtxoNetwork {

/// Checks if the current network is the mainnet.
bool get isMainnet => this == BitcoinNetwork.mainnet;

@override
List<BitcoinAddressType> get supportedAddress =>
BitcoinAddressType.values.toList();
}

/// Enum representing different Litecoin networks, implementing the `BasedUtxoNetwork` abstract class.
Expand Down Expand Up @@ -89,6 +96,11 @@ enum LitecoinNetwork implements BasedUtxoNetwork {

/// Checks if the current network is the mainnet.
bool get isMainnet => this == LitecoinNetwork.mainnet;

@override
List<BitcoinAddressType> get supportedAddress => BitcoinAddressType.values
.where((element) => element != BitcoinAddressType.p2tr)
.toList();
}

/// Enum representing different Dash networks, implementing the `BasedUtxoNetwork` abstract class.
Expand Down Expand Up @@ -125,6 +137,14 @@ enum DashNetwork implements BasedUtxoNetwork {

/// Checks if the current network is the mainnet.
bool get isMainnet => this == DashNetwork.mainnet;

@override
final List<BitcoinAddressType> supportedAddress = const [
BitcoinAddressType.p2pk,
BitcoinAddressType.p2pkh,
BitcoinAddressType.p2pkhInP2sh,
BitcoinAddressType.p2pkInP2sh
];
}

/// Enum representing different Dogecoin networks, implementing the `BasedUtxoNetwork` abstract class.
Expand Down Expand Up @@ -161,6 +181,14 @@ enum DogecoinNetwork implements BasedUtxoNetwork {

/// Checks if the current network is the mainnet.
bool get isMainnet => this == DogecoinNetwork.mainnet;

@override
final List<BitcoinAddressType> supportedAddress = const [
BitcoinAddressType.p2pk,
BitcoinAddressType.p2pkh,
BitcoinAddressType.p2pkhInP2sh,
BitcoinAddressType.p2pkInP2sh
];
}

/// Enum representing different Bitcoin Cash networks, implementing the `BasedUtxoNetwork` abstract class.
Expand Down Expand Up @@ -197,4 +225,12 @@ enum BitcoinCashNetwork implements BasedUtxoNetwork {

/// Checks if the current network is the mainnet.
bool get isMainnet => this == BitcoinCashNetwork.mainnet;

@override
final List<BitcoinAddressType> supportedAddress = const [
BitcoinAddressType.p2pk,
BitcoinAddressType.p2pkh,
BitcoinAddressType.p2pkhInP2sh,
BitcoinAddressType.p2pkInP2sh
];
}
16 changes: 16 additions & 0 deletions lib/src/provider/models/multisig_script.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ class MultiSignatureAddress {
script: multiSigScript, type: BitcoinAddressType.p2pkhInP2sh);
}

BitcoinAddress fromType(
{required BasedUtxoNetwork network,
required BitcoinAddressType addressType}) {
switch (addressType) {
case BitcoinAddressType.p2wsh:
return toP2wshAddress(network: network);
case BitcoinAddressType.p2wshInP2sh:
return toP2wshInP2shAddress(network: network);
case BitcoinAddressType.p2pkhInP2sh:
return toP2shAddress();
default:
throw ArgumentError(
"invalid multisig address type. use of of them [BitcoinAddressType.p2wsh, BitcoinAddressType.p2wshInP2sh, BitcoinAddressType.p2pkhInP2sh]");
}
}

MultiSignatureAddress._(
{required this.signers,
required this.threshold,
Expand Down
2 changes: 1 addition & 1 deletion 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: 2.0.0
version: 2.0.1
homepage: "https://github.com/mrtnetwork/bitcoin_base"
repository: "https://github.com/mrtnetwork/bitcoin_base"
Author: mrhaydari.t@gmail.com
Expand Down

0 comments on commit 959ed04

Please sign in to comment.