diff --git a/CHANGELOG.md b/CHANGELOG.md index 25ab574..6c89343 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.7.0 + +* Update dependencies + ## 4.6.0 * add asyncTransactionBuilder method to support building transactions asynchronously. diff --git a/example/pubspec.lock b/example/pubspec.lock index 55d2efb..c6b6a24 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -15,14 +15,14 @@ packages: path: ".." relative: true source: path - version: "4.4.0" + version: "4.7.0" blockchain_utils: dependency: "direct main" description: path: "../../blockchain_utils" relative: true source: path - version: "3.1.0" + version: "3.3.0" boolean_selector: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 873539b..849c3ab 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -39,7 +39,7 @@ dependencies: path: ../ blockchain_utils: path: ../../blockchain_utils - # blockchain_utils: ^3.0.0 + # blockchain_utils: ^3.3.0 http: ^1.2.0 dev_dependencies: diff --git a/lib/src/models/network.dart b/lib/src/models/network.dart index 38c1399..89e32b3 100644 --- a/lib/src/models/network.dart +++ b/lib/src/models/network.dart @@ -2,7 +2,6 @@ import 'package:bitcoin_base/bitcoin_base.dart'; import 'package:bitcoin_base/src/exception/exception.dart'; import 'package:bitcoin_base/src/utils/enumerate.dart'; import 'package:blockchain_utils/bip/bip/bip.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'; @@ -56,7 +55,7 @@ abstract class BasedUtxoNetwork implements Enumerate { return values.firstWhere((element) => element.value == name); } - List get coins; + List get coins; /// Checks if the current network is the mainnet. bool get isMainnet => this == BitcoinNetwork.mainnet; @@ -108,7 +107,7 @@ class BitcoinSVNetwork implements BasedUtxoNetwork { [P2pkhAddressType.p2pkh, PubKeyAddressType.p2pk]; @override - List get coins { + List get coins { if (isMainnet) return [Bip44Coins.bitcoinSv]; return [Bip44Coins.bitcoinSvTestnet]; } @@ -169,7 +168,7 @@ class BitcoinNetwork implements BasedUtxoNetwork { ]; @override - List get coins { + List get coins { if (isMainnet) { return [ Bip44Coins.bitcoin, @@ -240,7 +239,7 @@ class LitecoinNetwork implements BasedUtxoNetwork { ]; @override - List get coins { + List get coins { if (isMainnet) { return [Bip44Coins.litecoin, Bip49Coins.litecoin, Bip84Coins.litecoin]; } @@ -302,7 +301,7 @@ class DashNetwork implements BasedUtxoNetwork { final String value; @override - List get coins { + List get coins { if (isMainnet) return [Bip44Coins.dash, Bip49Coins.dash]; return [Bip44Coins.dashTestnet, Bip49Coins.dashTestnet]; } @@ -358,7 +357,7 @@ class DogecoinNetwork implements BasedUtxoNetwork { ]; @override - List get coins { + List get coins { if (isMainnet) return [Bip44Coins.dogecoin, Bip49Coins.dogecoin]; return [Bip44Coins.dogecoinTestnet, Bip49Coins.dogecoinTestnet]; } @@ -435,7 +434,7 @@ class BitcoinCashNetwork implements BasedUtxoNetwork { ]; @override - List get coins { + List get coins { if (isMainnet) return [Bip44Coins.bitcoinCash, Bip49Coins.bitcoinCash]; return [Bip44Coins.bitcoinCashTestnet, Bip49Coins.bitcoinCashTestnet]; } @@ -487,7 +486,7 @@ class PepeNetwork implements BasedUtxoNetwork { ]; @override - List get coins { + List get coins { if (isMainnet) { return [Bip44Coins.pepecoin, Bip49Coins.pepecoin]; } diff --git a/lib/src/provider/api_provider/api_provider.dart b/lib/src/provider/api_provider/api_provider.dart index f9014fc..1dc5c81 100644 --- a/lib/src/provider/api_provider/api_provider.dart +++ b/lib/src/provider/api_provider/api_provider.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:bitcoin_base/src/provider/models/models.dart'; import 'package:bitcoin_base/src/provider/service/http/http_service.dart'; import 'package:bitcoin_base/src/models/network.dart'; +import 'package:blockchain_utils/utils/string/string.dart'; class ApiProvider { ApiProvider( @@ -138,4 +139,20 @@ class ApiProvider { return transactions; } } + + Future getBlockHeight(int height) async { + final url = api.getBlockHeight(height); + final response = await _getRequest(url); + switch (api.apiType) { + case APIType.mempool: + return response; + default: + final toJson = StringUtils.toJson>(response); + return toJson["hash"]; + } + } + + Future genesis() async { + return getBlockHeight(0); + } } diff --git a/lib/src/provider/models/config.dart b/lib/src/provider/models/config.dart index 61dbced..9369398 100644 --- a/lib/src/provider/models/config.dart +++ b/lib/src/provider/models/config.dart @@ -10,6 +10,7 @@ class APIConfig { final String transaction; final String transactions; final String sendTransaction; + final String blockHeight; final APIType apiType; final BasedUtxoNetwork network; @@ -41,6 +42,11 @@ class APIConfig { return baseUrl.replaceAll("###", address); } + String getBlockHeight(int blockHaight) { + String baseUrl = blockHeight; + return baseUrl.replaceAll("###", "$blockHaight"); + } + factory APIConfig.fromBlockCypher(BasedUtxoNetwork network) { String baseUrl; switch (network) { @@ -65,14 +71,15 @@ class APIConfig { } return APIConfig( - url: "$baseUrl/addrs/###/?unspentOnly=true&includeScript=true&limit=2000", - feeRate: baseUrl, - transaction: "$baseUrl/txs/###", - sendTransaction: "$baseUrl/txs/push", - apiType: APIType.blockCypher, - transactions: "$baseUrl/addrs/###/full?limit=200", - network: network, - ); + url: + "$baseUrl/addrs/###/?unspentOnly=true&includeScript=true&limit=2000", + feeRate: baseUrl, + transaction: "$baseUrl/txs/###", + sendTransaction: "$baseUrl/txs/push", + apiType: APIType.blockCypher, + transactions: "$baseUrl/addrs/###/full?limit=200", + network: network, + blockHeight: "$baseUrl/blocks/###"); } factory APIConfig.mempool(BasedUtxoNetwork network) { @@ -90,23 +97,23 @@ class APIConfig { } return APIConfig( - url: "$baseUrl/address/###/utxo", - feeRate: "$baseUrl/v1/fees/recommended", - transaction: "$baseUrl/tx/###", - sendTransaction: "$baseUrl/tx", - apiType: APIType.mempool, - transactions: "$baseUrl/address/###/txs", - network: network, - ); + url: "$baseUrl/address/###/utxo", + feeRate: "$baseUrl/v1/fees/recommended", + transaction: "$baseUrl/tx/###", + sendTransaction: "$baseUrl/tx", + apiType: APIType.mempool, + transactions: "$baseUrl/address/###/txs", + network: network, + blockHeight: "$baseUrl/block-height/###"); } - APIConfig({ - required this.url, - required this.feeRate, - required this.transaction, - required this.transactions, - required this.sendTransaction, - required this.apiType, - required this.network, - }); + APIConfig( + {required this.url, + required this.feeRate, + required this.transaction, + required this.transactions, + required this.sendTransaction, + required this.apiType, + required this.network, + required this.blockHeight}); } diff --git a/pubspec.yaml b/pubspec.yaml index baf8f1f..61b1090 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bitcoin_base description: A versatile library for Bitcoin, Dogecoin, Litecoin, Dash, BSV, and BCH. Supports P2PKH, P2SH, P2WPKH, P2WSH, P2TR, with advanced creation, signing, and spending capabilities. -version: 4.6.0 +version: 4.7.0 homepage: "https://github.com/mrtnetwork/bitcoin_base" repository: "https://github.com/mrtnetwork/bitcoin_base" Author: mrhaydari.t@gmail.com @@ -16,10 +16,10 @@ environment: dependencies: - blockchain_utils: ^3.2.0 + # blockchain_utils: ^3.3.0 - # blockchain_utils: - # path: ../blockchain_utils + blockchain_utils: + path: ../blockchain_utils dev_dependencies: