From 3a0580d166cedbca82c0b840a80cb4053927f233 Mon Sep 17 00:00:00 2001 From: Mohsen <56779182+mrtnetwork@users.noreply.github.com> Date: Sat, 15 Jun 2024 21:37:43 +0330 Subject: [PATCH] v4.4.0 Update dependencies --- CHANGELOG.md | 4 ++ .../lib/bitcoin_cash/burn_token_example.dart | 2 +- .../create_cash_token_example.dart | 2 +- .../lib/bitcoin_cash/create_nft_example.dart | 2 +- .../lib/bitcoin_cash/make_vout0_example.dart | 2 +- .../lib/bitcoin_cash/minting_nft_example.dart | 3 +- .../bitcoin_cash/p2sh32_spend_example.dart | 2 +- .../bitcoin_cash/send_ft_token_example.dart | 2 +- .../bitcoin_cash/transfer_bch_example.dart | 2 +- example/lib/global/bch_example.dart | 2 +- example/pubspec.lock | 32 ++++----- example/pubspec.yaml | 6 +- .../bitcoin/address/utils/address_utils.dart | 28 ++++---- lib/src/bitcoin/script/control_block.dart | 2 +- lib/src/bitcoin/script/input.dart | 5 +- lib/src/bitcoin/script/op_code/tools.dart | 3 +- lib/src/bitcoin/script/output.dart | 5 +- lib/src/bitcoin/script/sequence.dart | 4 +- lib/src/bitcoin/script/transaction.dart | 6 +- lib/src/bitcoin/script/witness.dart | 3 +- lib/src/bytes_utils/dynamic_byte.dart | 15 ---- lib/src/crypto/crypto.dart | 2 +- lib/src/models/network.dart | 70 +++++++++++++++++++ lib/src/utils/btc_utils.dart | 2 +- pubspec.yaml | 2 +- 25 files changed, 126 insertions(+), 82 deletions(-) delete mode 100644 lib/src/bytes_utils/dynamic_byte.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 595be94..37195bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.4.0 + +* Update dependencies + ## 4.3.0 * Update dependencies diff --git a/example/lib/bitcoin_cash/burn_token_example.dart b/example/lib/bitcoin_cash/burn_token_example.dart index 0b3f005..9b25036 100644 --- a/example/lib/bitcoin_cash/burn_token_example.dart +++ b/example/lib/bitcoin_cash/burn_token_example.dart @@ -1,5 +1,5 @@ import 'package:bitcoin_base/bitcoin_base.dart'; -import 'package:blockchain_utils/binary/utils.dart'; +import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:example/services_examples/electrum/electrum_websocket_service.dart'; /// https://github.com/cashtokens/cashtokens diff --git a/example/lib/bitcoin_cash/create_cash_token_example.dart b/example/lib/bitcoin_cash/create_cash_token_example.dart index 2d887a0..bb93937 100644 --- a/example/lib/bitcoin_cash/create_cash_token_example.dart +++ b/example/lib/bitcoin_cash/create_cash_token_example.dart @@ -1,5 +1,5 @@ import 'package:bitcoin_base/bitcoin_base.dart'; -import 'package:blockchain_utils/binary/utils.dart'; +import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:example/services_examples/electrum/electrum_websocket_service.dart'; /// please make sure read this before create transaction on mainnet diff --git a/example/lib/bitcoin_cash/create_nft_example.dart b/example/lib/bitcoin_cash/create_nft_example.dart index e999dfc..28404cd 100644 --- a/example/lib/bitcoin_cash/create_nft_example.dart +++ b/example/lib/bitcoin_cash/create_nft_example.dart @@ -1,5 +1,5 @@ import 'package:bitcoin_base/bitcoin_base.dart'; -import 'package:blockchain_utils/binary/utils.dart'; +import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:example/services_examples/electrum/electrum_websocket_service.dart'; /// please make sure read this before create transaction on mainnet diff --git a/example/lib/bitcoin_cash/make_vout0_example.dart b/example/lib/bitcoin_cash/make_vout0_example.dart index e7af23f..aa71f8b 100644 --- a/example/lib/bitcoin_cash/make_vout0_example.dart +++ b/example/lib/bitcoin_cash/make_vout0_example.dart @@ -1,5 +1,5 @@ import 'package:bitcoin_base/bitcoin_base.dart'; -import 'package:blockchain_utils/binary/utils.dart'; +import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:example/services_examples/electrum/electrum_ssl_service.dart'; /// make vout 0 for account for create token hash diff --git a/example/lib/bitcoin_cash/minting_nft_example.dart b/example/lib/bitcoin_cash/minting_nft_example.dart index 484ae74..092fb24 100644 --- a/example/lib/bitcoin_cash/minting_nft_example.dart +++ b/example/lib/bitcoin_cash/minting_nft_example.dart @@ -1,7 +1,6 @@ import 'dart:convert'; - import 'package:bitcoin_base/bitcoin_base.dart'; -import 'package:blockchain_utils/binary/utils.dart'; +import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:example/services_examples/electrum/electrum_websocket_service.dart'; /// https://github.com/cashtokens/cashtokens diff --git a/example/lib/bitcoin_cash/p2sh32_spend_example.dart b/example/lib/bitcoin_cash/p2sh32_spend_example.dart index afb771b..d46b23d 100644 --- a/example/lib/bitcoin_cash/p2sh32_spend_example.dart +++ b/example/lib/bitcoin_cash/p2sh32_spend_example.dart @@ -1,5 +1,5 @@ import 'package:bitcoin_base/bitcoin_base.dart'; -import 'package:blockchain_utils/binary/utils.dart'; +import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:example/services_examples/electrum/electrum_websocket_service.dart'; /// CHIP-2022-05 Pay-to-Script-Hash-32 (P2SH32) for Bitcoin Cash diff --git a/example/lib/bitcoin_cash/send_ft_token_example.dart b/example/lib/bitcoin_cash/send_ft_token_example.dart index 8079149..d875661 100644 --- a/example/lib/bitcoin_cash/send_ft_token_example.dart +++ b/example/lib/bitcoin_cash/send_ft_token_example.dart @@ -1,5 +1,5 @@ import 'package:bitcoin_base/bitcoin_base.dart'; -import 'package:blockchain_utils/binary/utils.dart'; +import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:example/services_examples/electrum/electrum_websocket_service.dart'; /// please make sure read this before create transaction on mainnet diff --git a/example/lib/bitcoin_cash/transfer_bch_example.dart b/example/lib/bitcoin_cash/transfer_bch_example.dart index c1d1bfc..f9631f9 100644 --- a/example/lib/bitcoin_cash/transfer_bch_example.dart +++ b/example/lib/bitcoin_cash/transfer_bch_example.dart @@ -1,5 +1,5 @@ import 'package:bitcoin_base/bitcoin_base.dart'; -import 'package:blockchain_utils/binary/utils.dart'; +import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:example/services_examples/electrum/electrum_websocket_service.dart'; /// CHIP-2022-05 Pay-to-Script-Hash-32 (P2SH32) for Bitcoin Cash diff --git a/example/lib/global/bch_example.dart b/example/lib/global/bch_example.dart index 3c877d5..6b31303 100644 --- a/example/lib/global/bch_example.dart +++ b/example/lib/global/bch_example.dart @@ -1,5 +1,5 @@ import 'package:bitcoin_base/bitcoin_base.dart'; -import 'package:blockchain_utils/binary/utils.dart'; +import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:example/services_examples/electrum/electrum_websocket_service.dart'; void main() async { diff --git a/example/pubspec.lock b/example/pubspec.lock index adef0c3..5faf2af 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -19,10 +19,9 @@ packages: blockchain_utils: dependency: "direct main" description: - name: blockchain_utils - sha256: "699d72427447814bd574b95b0d3baf9b2c0ec9c9b82deef3c6264c6f5efa4406" - url: "https://pub.dev" - source: hosted + path: "../../blockchain_utils" + relative: true + source: path version: "3.0.0" boolean_selector: dependency: transitive @@ -110,26 +109,26 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" url: "https://pub.dev" source: hosted - version: "10.0.0" + version: "10.0.4" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.3" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.1" lints: dependency: transitive description: @@ -158,10 +157,10 @@ packages: dependency: transitive description: name: meta - sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.12.0" path: dependency: transitive description: @@ -219,10 +218,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.0" typed_data: dependency: transitive description: @@ -243,10 +242,10 @@ packages: dependency: transitive description: name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" url: "https://pub.dev" source: hosted - version: "13.0.0" + version: "14.2.1" web: dependency: transitive description: @@ -257,3 +256,4 @@ packages: version: "0.5.1" sdks: dart: ">=3.3.0 <4.0.0" + flutter: ">=3.18.0-18.0.pre.54" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 99ecd27..873539b 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -37,9 +37,9 @@ dependencies: cupertino_icons: ^1.0.2 bitcoin_base: path: ../ - # blockchain_utils: - # path: ../../blockchain_utils - blockchain_utils: ^3.0.0 + blockchain_utils: + path: ../../blockchain_utils + # blockchain_utils: ^3.0.0 http: ^1.2.0 dev_dependencies: diff --git a/lib/src/bitcoin/address/utils/address_utils.dart b/lib/src/bitcoin/address/utils/address_utils.dart index 5093e3b..06c34e6 100644 --- a/lib/src/bitcoin/address/utils/address_utils.dart +++ b/lib/src/bitcoin/address/utils/address_utils.dart @@ -43,7 +43,7 @@ class _BitcoinAddressUtils { /// Verify the checksum. List hash = QuickCrypto.sha256DoubleHash(data) .sublist(0, Base58Const.checksumByteLen); - if (!bytesEqual(checksum, hash)) { + if (!BytesUtils.bytesEqual(checksum, hash)) { return null; } @@ -65,9 +65,9 @@ class _BitcoinAddressUtils { return null; } final decodedHex = BytesUtils.toHexString(decode.item1); - if (bytesEqual(decode.item2, networks.p2pkhNetVer)) { + if (BytesUtils.bytesEqual(decode.item2, networks.p2pkhNetVer)) { return P2pkhAddress.fromHash160(addrHash: decodedHex); - } else if (bytesEqual(decode.item2, networks.p2shNetVer)) { + } else if (BytesUtils.bytesEqual(decode.item2, networks.p2shNetVer)) { return P2shAddress.fromHash160(addrHash: decodedHex); } return null; @@ -229,18 +229,18 @@ class _BitcoinAddressUtils { return null; } if (scriptLength == hash160DigestLength) { - final legacyP2pk = bytesEqual(network.p2pkhNetVer, version); + final legacyP2pk = BytesUtils.bytesEqual(network.p2pkhNetVer, version); - if (bytesEqual(network.p2pkhNetVer, version) || - bytesEqual(network.p2pkhWtNetVer, version)) { + if (BytesUtils.bytesEqual(network.p2pkhNetVer, version) || + BytesUtils.bytesEqual(network.p2pkhWtNetVer, version)) { return P2pkhAddress.fromHash160( addrHash: scriptHex, type: legacyP2pk ? P2pkhAddressType.p2pkh : P2pkhAddressType.p2pkhwt); } - final legacyP2sh = bytesEqual(network.p2shNetVer, version); - if (bytesEqual(network.p2shNetVer, version) || - bytesEqual(network.p2shwt20NetVer, version)) { + final legacyP2sh = BytesUtils.bytesEqual(network.p2shNetVer, version); + if (BytesUtils.bytesEqual(network.p2shNetVer, version) || + BytesUtils.bytesEqual(network.p2shwt20NetVer, version)) { return P2shAddress.fromHash160( addrHash: scriptHex, type: legacyP2sh @@ -248,9 +248,9 @@ class _BitcoinAddressUtils { : P2shAddressType.p2pkhInP2shwt); } } else { - final legacyP2sh = bytesEqual(network.p2sh32NetVer, version); - if (bytesEqual(network.p2sh32NetVer, version) || - bytesEqual(network.p2shwt32NetVer, version)) { + final legacyP2sh = BytesUtils.bytesEqual(network.p2sh32NetVer, version); + if (BytesUtils.bytesEqual(network.p2sh32NetVer, version) || + BytesUtils.bytesEqual(network.p2shwt32NetVer, version)) { return P2shAddress.fromHash160( addrHash: scriptHex, type: legacyP2sh @@ -296,7 +296,7 @@ class _BitcoinAddressUtils { switch (type) { case P2pkhAddressType.p2pkh: - if (bytesEqual(version, network.p2pkhNetVer)) { + if (BytesUtils.bytesEqual(version, network.p2pkhNetVer)) { return scriptHex; } return null; @@ -304,7 +304,7 @@ class _BitcoinAddressUtils { case P2shAddressType.p2pkInP2sh: case P2shAddressType.p2wshInP2sh: case P2shAddressType.p2wpkhInP2sh: - if (bytesEqual(version, network.p2shNetVer)) { + if (BytesUtils.bytesEqual(version, network.p2shNetVer)) { return scriptHex; } return null; diff --git a/lib/src/bitcoin/script/control_block.dart b/lib/src/bitcoin/script/control_block.dart index 6e4a12c..d6a07b2 100644 --- a/lib/src/bitcoin/script/control_block.dart +++ b/lib/src/bitcoin/script/control_block.dart @@ -1,6 +1,6 @@ import 'package:bitcoin_base/src/bitcoin/script/op_code/constant.dart'; import 'package:bitcoin_base/src/crypto/keypair/ec_public.dart'; -import 'package:blockchain_utils/binary/utils.dart'; +import 'package:blockchain_utils/utils/binary/utils.dart'; import 'script.dart'; diff --git a/lib/src/bitcoin/script/input.dart b/lib/src/bitcoin/script/input.dart index 534147d..b0ed835 100644 --- a/lib/src/bitcoin/script/input.dart +++ b/lib/src/bitcoin/script/input.dart @@ -1,8 +1,5 @@ import 'package:bitcoin_base/src/bitcoin/script/op_code/constant.dart'; -import 'package:blockchain_utils/binary/binary_operation.dart'; -import 'package:blockchain_utils/binary/utils.dart'; -import 'package:blockchain_utils/numbers/int_utils.dart'; -import 'package:blockchain_utils/tuple/tuple.dart'; +import 'package:blockchain_utils/utils/utils.dart'; import 'script.dart'; /// A transaction input requires a transaction id of a UTXO and the index of that UTXO. diff --git a/lib/src/bitcoin/script/op_code/tools.dart b/lib/src/bitcoin/script/op_code/tools.dart index 688e5d8..af0f520 100644 --- a/lib/src/bitcoin/script/op_code/tools.dart +++ b/lib/src/bitcoin/script/op_code/tools.dart @@ -1,5 +1,4 @@ -import 'package:blockchain_utils/binary/binary_operation.dart'; -import 'package:blockchain_utils/binary/utils.dart'; +import 'package:blockchain_utils/utils/utils.dart'; List opPushData(String hexData) { final List dataBytes = BytesUtils.fromHexString(hexData); diff --git a/lib/src/bitcoin/script/output.dart b/lib/src/bitcoin/script/output.dart index 38db1a8..8a25497 100644 --- a/lib/src/bitcoin/script/output.dart +++ b/lib/src/bitcoin/script/output.dart @@ -1,10 +1,7 @@ import 'dart:typed_data'; import 'package:bitcoin_base/src/cash_token/cash_token.dart'; import 'package:bitcoin_base/src/bitcoin/script/script.dart'; -import 'package:blockchain_utils/binary/utils.dart'; -import 'package:blockchain_utils/numbers/bigint_utils.dart'; -import 'package:blockchain_utils/numbers/int_utils.dart'; -import 'package:blockchain_utils/tuple/tuple.dart'; +import 'package:blockchain_utils/utils/utils.dart'; /// Represents a transaction output. /// diff --git a/lib/src/bitcoin/script/sequence.dart b/lib/src/bitcoin/script/sequence.dart index 91c3cd0..b16fd74 100644 --- a/lib/src/bitcoin/script/sequence.dart +++ b/lib/src/bitcoin/script/sequence.dart @@ -1,8 +1,6 @@ import 'dart:typed_data'; - import 'package:bitcoin_base/src/bitcoin/script/op_code/constant.dart'; -import 'package:blockchain_utils/binary/binary_operation.dart'; -import 'package:blockchain_utils/numbers/int_utils.dart'; +import 'package:blockchain_utils/utils/utils.dart'; /// Helps setting up appropriate sequence. Used to provide the sequence to transaction inputs and to scripts. /// diff --git a/lib/src/bitcoin/script/transaction.dart b/lib/src/bitcoin/script/transaction.dart index 7214718..a0e43f1 100644 --- a/lib/src/bitcoin/script/transaction.dart +++ b/lib/src/bitcoin/script/transaction.dart @@ -2,12 +2,8 @@ import 'dart:typed_data'; import 'package:bitcoin_base/src/cash_token/cash_token.dart'; import 'package:bitcoin_base/src/bitcoin/script/op_code/constant.dart'; import 'package:bitcoin_base/src/crypto/crypto.dart'; -import 'package:bitcoin_base/src/bytes_utils/dynamic_byte.dart'; -import 'package:blockchain_utils/binary/binary_operation.dart'; -import 'package:blockchain_utils/binary/utils.dart'; +import 'package:blockchain_utils/utils/utils.dart'; import 'package:blockchain_utils/crypto/quick_crypto.dart'; -import 'package:blockchain_utils/numbers/bigint_utils.dart'; -import 'package:blockchain_utils/numbers/int_utils.dart'; import 'input.dart'; import 'output.dart'; import 'script.dart'; diff --git a/lib/src/bitcoin/script/witness.dart b/lib/src/bitcoin/script/witness.dart index ec0e1f0..86b0db5 100644 --- a/lib/src/bitcoin/script/witness.dart +++ b/lib/src/bitcoin/script/witness.dart @@ -1,5 +1,4 @@ -import 'package:blockchain_utils/binary/utils.dart'; -import 'package:blockchain_utils/numbers/int_utils.dart'; +import 'package:blockchain_utils/utils/utils.dart'; /// A list of the witness items required to satisfy the locking conditions of a segwit input (aka witness stack). /// diff --git a/lib/src/bytes_utils/dynamic_byte.dart b/lib/src/bytes_utils/dynamic_byte.dart deleted file mode 100644 index 934a78d..0000000 --- a/lib/src/bytes_utils/dynamic_byte.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:blockchain_utils/binary/binary_operation.dart'; - -class DynamicByteTracker { - final List _buffer = List.empty(growable: true); - - List toBytes() { - return List.from(_buffer, growable: false); - } - - void add(List chunk) { - for (int i in chunk) { - _buffer.add(i & mask8); - } - } -} diff --git a/lib/src/crypto/crypto.dart b/lib/src/crypto/crypto.dart index c7d4732..2af7a21 100644 --- a/lib/src/crypto/crypto.dart +++ b/lib/src/crypto/crypto.dart @@ -2,7 +2,7 @@ library bitcoin_crypto; import 'package:bitcoin_base/src/bitcoin/script/op_code/constant_lib.dart'; import 'package:blockchain_utils/crypto/quick_crypto.dart'; -import 'package:blockchain_utils/numbers/int_utils.dart'; +import 'package:blockchain_utils/utils/utils.dart'; export 'keypair/ec_private.dart'; export 'keypair/ec_public.dart'; diff --git a/lib/src/models/network.dart b/lib/src/models/network.dart index d7c87f9..3f5f407 100644 --- a/lib/src/models/network.dart +++ b/lib/src/models/network.dart @@ -1,5 +1,10 @@ import 'package:bitcoin_base/bitcoin_base.dart'; import 'package:bitcoin_base/src/utils/enumerate.dart'; +import 'package:blockchain_utils/bip/bip/conf/bip44/bip44_coins.dart'; +import 'package:blockchain_utils/bip/bip/conf/bip49/bip49_coins.dart'; +import 'package:blockchain_utils/bip/bip/conf/bip84/bip84_coins.dart'; +import 'package:blockchain_utils/bip/bip/conf/bip86/bip86_coins.dart'; +import 'package:blockchain_utils/bip/bip/conf/bip_coins.dart'; import 'package:blockchain_utils/bip/coin_conf/coin_conf.dart'; import 'package:blockchain_utils/bip/coin_conf/coins_conf.dart'; @@ -51,6 +56,11 @@ abstract class BasedUtxoNetwork implements Enumerate { static BasedUtxoNetwork fromName(String name) { return values.firstWhere((element) => element.value == name); } + + List get coins; + + /// Checks if the current network is the mainnet. + bool get isMainnet => this == BitcoinNetwork.mainnet; } /// Class representing a Bitcoin network, implementing the `BasedUtxoNetwork` abstract class. @@ -91,11 +101,18 @@ class BitcoinSVNetwork implements BasedUtxoNetwork { String get p2wpkhHrp => conf.params.p2wpkhHrp!; /// Checks if the current network is the mainnet. + @override bool get isMainnet => this == BitcoinSVNetwork.mainnet; @override List get supportedAddress => [P2pkhAddressType.p2pkh, PubKeyAddressType.p2pk]; + + @override + List get coins { + if (isMainnet) return [Bip44Coins.bitcoinSv]; + return [Bip44Coins.bitcoinSvTestnet]; + } } /// Class representing a Bitcoin network, implementing the `BasedUtxoNetwork` abstract class. @@ -136,6 +153,7 @@ class BitcoinNetwork implements BasedUtxoNetwork { String get p2wpkhHrp => conf.params.p2wpkhHrp!; /// Checks if the current network is the mainnet. + @override bool get isMainnet => this == BitcoinNetwork.mainnet; @override @@ -150,6 +168,24 @@ class BitcoinNetwork implements BasedUtxoNetwork { P2shAddressType.p2pkhInP2sh, P2shAddressType.p2pkInP2sh, ]; + + @override + List get coins { + if (isMainnet) { + return [ + Bip44Coins.bitcoin, + Bip49Coins.bitcoin, + Bip84Coins.bitcoin, + Bip86Coins.bitcoin, + ]; + } + return [ + Bip44Coins.bitcoinTestnet, + Bip49Coins.bitcoinTestnet, + Bip84Coins.bitcoinTestnet, + Bip86Coins.bitcoinTestnet, + ]; + } } /// Class representing a Litecoin network, implementing the `BasedUtxoNetwork` abstract class. @@ -189,6 +225,7 @@ class LitecoinNetwork implements BasedUtxoNetwork { String get p2wpkhHrp => conf.params.p2wpkhHrp!; /// Checks if the current network is the mainnet. + @override bool get isMainnet => this == LitecoinNetwork.mainnet; @override @@ -202,6 +239,18 @@ class LitecoinNetwork implements BasedUtxoNetwork { P2shAddressType.p2pkhInP2sh, P2shAddressType.p2pkInP2sh, ]; + + @override + List get coins { + if (isMainnet) { + return [Bip44Coins.litecoin, Bip49Coins.litecoin, Bip84Coins.litecoin]; + } + return [ + Bip44Coins.litecoinTestnet, + Bip49Coins.litecoinTestnet, + Bip84Coins.litecoinTestnet + ]; + } } /// Class representing a Dash network, implementing the `BasedUtxoNetwork` abstract class. @@ -239,6 +288,7 @@ class DashNetwork implements BasedUtxoNetwork { "DashNetwork network does not support P2WPKH/P2WSH"); /// Checks if the current network is the mainnet. + @override bool get isMainnet => this == DashNetwork.mainnet; @override @@ -251,6 +301,12 @@ class DashNetwork implements BasedUtxoNetwork { @override final String value; + + @override + List get coins { + if (isMainnet) return [Bip44Coins.dash, Bip49Coins.dash]; + return [Bip44Coins.dashTestnet, Bip49Coins.dashTestnet]; + } } /// Class representing a Dogecoin network, implementing the `BasedUtxoNetwork` abstract class. @@ -291,6 +347,7 @@ class DogecoinNetwork implements BasedUtxoNetwork { "DogecoinNetwork network does not support P2WPKH/P2WSH"); /// Checks if the current network is the mainnet. + @override bool get isMainnet => this == DogecoinNetwork.mainnet; @override @@ -300,6 +357,12 @@ class DogecoinNetwork implements BasedUtxoNetwork { P2shAddressType.p2pkhInP2sh, P2shAddressType.p2pkInP2sh ]; + + @override + List get coins { + if (isMainnet) return [Bip44Coins.dogecoin, Bip49Coins.dogecoin]; + return [Bip44Coins.dogecoinTestnet, Bip49Coins.dogecoinTestnet]; + } } /// Class representing a Bitcoin Cash network, implementing the `BasedUtxoNetwork` abstract class. @@ -354,6 +417,7 @@ class BitcoinCashNetwork implements BasedUtxoNetwork { String get networkHRP => conf.params.p2pkhStdHrp!; /// Checks if the current network is the mainnet. + @override bool get isMainnet => this == BitcoinCashNetwork.mainnet; @override @@ -370,4 +434,10 @@ class BitcoinCashNetwork implements BasedUtxoNetwork { P2shAddressType.p2pkhInP2shwt, P2shAddressType.p2pkInP2shwt, ]; + + @override + List get coins { + if (isMainnet) return [Bip44Coins.bitcoinCash, Bip49Coins.bitcoinCash]; + return [Bip44Coins.bitcoinCashTestnet, Bip49Coins.bitcoinCashTestnet]; + } } diff --git a/lib/src/utils/btc_utils.dart b/lib/src/utils/btc_utils.dart index ed6dd66..767464c 100644 --- a/lib/src/utils/btc_utils.dart +++ b/lib/src/utils/btc_utils.dart @@ -1,4 +1,4 @@ -import 'package:blockchain_utils/numbers/big_rational.dart'; +import 'package:blockchain_utils/utils/numbers/rational/big_rational.dart'; class BtcUtils { static BigInt toSatoshi(String decimal) { diff --git a/pubspec.yaml b/pubspec.yaml index 088f06a..6f49131 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ environment: dependencies: - blockchain_utils: ^3.0.0 + blockchain_utils: ^3.1.0 # blockchain_utils: # path: ../blockchain_utils