diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c89343..dc41c5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.8.0 + +* Update dependencies + ## 4.7.0 * Update dependencies diff --git a/example/pubspec.lock b/example/pubspec.lock index d7800dd..9cabb7b 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -15,15 +15,15 @@ packages: path: ".." relative: true source: path - version: "4.7.0" + version: "4.8.0" blockchain_utils: dependency: "direct main" description: name: blockchain_utils - sha256: aebc3a32b927b34f638817c4bfdb85f86a97e6ad35f0cd962660b0c6e8d5c56b + sha256: ebb6c336ba0120de0982c50d8bc597cb494a530bd22bd462895bb5cebde405af url: "https://pub.dev" source: hosted - version: "3.3.0" + version: "3.4.0" boolean_selector: dependency: transitive description: @@ -110,18 +110,18 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.5" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.5" leak_tracker_testing: dependency: transitive description: @@ -150,18 +150,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.15.0" path: dependency: transitive description: @@ -219,10 +219,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.7.2" typed_data: dependency: transitive description: @@ -243,10 +243,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "14.2.5" web: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index ca4fb33..2fad8b2 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -39,7 +39,7 @@ dependencies: path: ../ # blockchain_utils: # path: ../../blockchain_utils - blockchain_utils: ^3.3.0 + blockchain_utils: ^3.4.0 http: ^1.2.0 dev_dependencies: diff --git a/lib/src/bitcoin/address/core.dart b/lib/src/bitcoin/address/core.dart index 1211396..51a04e8 100644 --- a/lib/src/bitcoin/address/core.dart +++ b/lib/src/bitcoin/address/core.dart @@ -9,7 +9,7 @@ abstract class BitcoinAddressType implements Enumerate { /// Factory method to create a BitcoinAddressType enum value from a name or value. static BitcoinAddressType fromValue(String value) { return values.firstWhere((element) => element.value == value, - orElse: () => throw BitcoinBasePluginException( + orElse: () => throw DartBitcoinPluginException( 'Invalid BitcoinAddressType: $value')); } diff --git a/lib/src/bitcoin/address/legacy_address.dart b/lib/src/bitcoin/address/legacy_address.dart index c3952cf..30b1445 100644 --- a/lib/src/bitcoin/address/legacy_address.dart +++ b/lib/src/bitcoin/address/legacy_address.dart @@ -14,7 +14,7 @@ abstract class LegacyAddress implements BitcoinBaseAddress { final decode = _BitcoinAddressUtils.decodeLagacyAddressWithNetworkAndType( address: address, type: type, network: network); if (decode == null) { - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "Invalid ${network.conf.coinName} address"); } _addressProgram = decode; @@ -63,7 +63,7 @@ class P2shAddress extends LegacyAddress { @override String toAddress(BasedUtxoNetwork network) { if (!network.supportedAddress.contains(type)) { - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "network does not support ${type.value} address"); } return super.toAddress(network); @@ -111,7 +111,7 @@ class P2pkAddress extends LegacyAddress { P2pkAddress({required String publicKey}) : super._() { final toBytes = BytesUtils.fromHexString(publicKey); if (!Secp256k1PublicKeyEcdsa.isValidBytes(toBytes)) { - throw const BitcoinBasePluginException("Invalid secp256k1 public key"); + throw const DartBitcoinPluginException("Invalid secp256k1 public key"); } publicHex = publicKey; } diff --git a/lib/src/bitcoin/address/network_address.dart b/lib/src/bitcoin/address/network_address.dart index e1c4307..69950da 100644 --- a/lib/src/bitcoin/address/network_address.dart +++ b/lib/src/bitcoin/address/network_address.dart @@ -107,7 +107,7 @@ class BitcoinCashAddress extends BitcoinNetworkAddress { address, network, validateNetworkHRP: validateNetworkPrefix); if (decodeAddress == null) { - throw BitcoinBasePluginException("Invalid ${network.value} address."); + throw DartBitcoinPluginException("Invalid ${network.value} address."); } return BitcoinCashAddress._(decodeAddress, address); } diff --git a/lib/src/bitcoin/address/segwit_address.dart b/lib/src/bitcoin/address/segwit_address.dart index a68574f..039395d 100644 --- a/lib/src/bitcoin/address/segwit_address.dart +++ b/lib/src/bitcoin/address/segwit_address.dart @@ -6,7 +6,7 @@ abstract class SegwitAddress implements BitcoinBaseAddress { required BasedUtxoNetwork network, required this.segwitVersion}) { if (!network.supportedAddress.contains(type)) { - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "network does not support ${type.value} address"); } addressProgram = _BitcoinAddressUtils.toSegwitProgramWithVersionAndNetwork( @@ -30,7 +30,7 @@ abstract class SegwitAddress implements BitcoinBaseAddress { @override String toAddress(BasedUtxoNetwork network) { if (!network.supportedAddress.contains(type)) { - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "network does not support ${type.value} address"); } return _BitcoinAddressUtils.segwitToAddress( diff --git a/lib/src/bitcoin/address/utils/address_utils.dart b/lib/src/bitcoin/address/utils/address_utils.dart index f6d2baa..af88a82 100644 --- a/lib/src/bitcoin/address/utils/address_utils.dart +++ b/lib/src/bitcoin/address/utils/address_utils.dart @@ -89,7 +89,7 @@ class _BitcoinAddressUtils { final convert = SegwitBech32Decoder.decode(network.p2wpkhHrp, address); final witnessVersion = convert.item1; if (witnessVersion != version) { - throw const BitcoinBasePluginException("Invalid segwit version"); + throw const DartBitcoinPluginException("Invalid segwit version"); } return BytesUtils.toHexString(convert.item2); } @@ -137,7 +137,7 @@ class _BitcoinAddressUtils { if (network.supportedAddress.contains(address.type)) { return address; } - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "${network.value} does not support ${address.type.value} address"); } @@ -158,7 +158,7 @@ class _BitcoinAddressUtils { } baseAddress ??= toLegacy(address, network); if (baseAddress == null) { - throw const BitcoinBasePluginException("Invalid Bitcoin address"); + throw const DartBitcoinPluginException("Invalid Bitcoin address"); } return validateAddress(baseAddress, network); } @@ -180,7 +180,7 @@ class _BitcoinAddressUtils { } // ignore: empty_catches } catch (e) {} - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Invalid Bitcoin address program length (program length should be 32 or 20 bytes)"); } @@ -276,7 +276,7 @@ class _BitcoinAddressUtils { required BitcoinAddressType type, required BasedUtxoNetwork network}) { if (!network.supportedAddress.contains(type)) { - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "${network.value} does not support ${type.value} address type"); } if (network is BitcoinCashNetwork) { diff --git a/lib/src/bitcoin/script/input.dart b/lib/src/bitcoin/script/input.dart index b55b68a..c9d0aee 100644 --- a/lib/src/bitcoin/script/input.dart +++ b/lib/src/bitcoin/script/input.dart @@ -63,7 +63,7 @@ class TxInput { List inpHash = txInputRaw.sublist(cursor, cursor + 32).reversed.toList(); if (inpHash.isEmpty) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Input transaction hash not found. Probably malformed raw transaction"); } List outputN = diff --git a/lib/src/bitcoin/script/op_code/tools.dart b/lib/src/bitcoin/script/op_code/tools.dart index 9bb44e5..8d17869 100644 --- a/lib/src/bitcoin/script/op_code/tools.dart +++ b/lib/src/bitcoin/script/op_code/tools.dart @@ -19,14 +19,14 @@ List opPushData(String hexData) { writeUint32LE(lengthBytes.length, lengthBytes); return List.from([0x4e, ...lengthBytes, ...dataBytes]); } else { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Data too large. Cannot push into script"); } } List pushInteger(int integer) { if (integer < 0) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( 'Integer is currently required to be positive.'); } diff --git a/lib/src/bitcoin/script/sequence.dart b/lib/src/bitcoin/script/sequence.dart index f202eff..920212f 100644 --- a/lib/src/bitcoin/script/sequence.dart +++ b/lib/src/bitcoin/script/sequence.dart @@ -13,7 +13,7 @@ class Sequence { {required this.seqType, required this.value, this.isTypeBlock = true}) { if (seqType == BitcoinOpCodeConst.TYPE_RELATIVE_TIMELOCK && (value < 1 || value > mask16)) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( 'Sequence should be between 1 and 65535'); } } @@ -39,13 +39,13 @@ class Sequence { return IntUtils.toBytes(seq, length: 4, byteOrder: Endian.little); } - throw const BitcoinBasePluginException("Invalid seqType"); + throw const DartBitcoinPluginException("Invalid seqType"); } /// Returns the appropriate integer for a script; e.g. for relative timelocks int forScript() { if (seqType == BitcoinOpCodeConst.TYPE_REPLACE_BY_FEE) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "RBF is not to be included in a script."); } int scriptIntiger = value; diff --git a/lib/src/bitcoin/script/transaction.dart b/lib/src/bitcoin/script/transaction.dart index da9b409..380067f 100644 --- a/lib/src/bitcoin/script/transaction.dart +++ b/lib/src/bitcoin/script/transaction.dart @@ -159,7 +159,7 @@ class BtcTransaction { } } else if ((sighash & 0x1f) == BitcoinOpCodeConst.SIGHASH_SINGLE) { if (txInIndex >= tx.outputs.length) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Transaction index is greater than the available outputs"); } diff --git a/lib/src/cash_token/cash_token.dart b/lib/src/cash_token/cash_token.dart index 53f852c..e322257 100644 --- a/lib/src/cash_token/cash_token.dart +++ b/lib/src/cash_token/cash_token.dart @@ -63,7 +63,7 @@ class CashTokenCapability { final int intCapability = _getCapability(bitfield); return values.firstWhere((element) => element.value == intCapability); } on StateError { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Invalid CashToken NFT Capability"); } } @@ -73,7 +73,7 @@ class CashTokenCapability { try { return values.firstWhere((element) => element.name == name); } on StateError { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Invalid CashToken NFT Capability Name"); } } @@ -273,30 +273,30 @@ class CashToken { List? commitment, required int bitfield}) { if (!CashTokenUtils.isValidBitfield(bitfield)) { - throw const BitcoinBasePluginException("Invalid bitfield"); + throw const DartBitcoinPluginException("Invalid bitfield"); } if (CashTokenUtils.hasAmount(bitfield) && amount == null) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Invalid cash token: the bitfield indicates an amount, but the amount is null."); } if (amount != null) { if (amount < BigInt.zero || amount > CashTokenUtils.maxTokenAmount) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Invalid amount. Amount must be between zero and 99."); } } if (!StringUtils.isHexBytes(category)) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Invalid category hexadecimal bytes."); } final toBytes = BytesUtils.fromHexString(category); if (toBytes.length != CashTokenUtils.idBytesLength) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Invalid category. The category should consist of 32 bytes."); } if (CashTokenUtils.hasCommitmentLength(bitfield) && (commitment == null || commitment.isEmpty)) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Invalid cash token: the bitfield indicates an commitment, but the commitment is null or empty."); } return CashToken.noValidate( @@ -336,7 +336,7 @@ class CashToken { amount < BigInt.zero || amount > CashTokenUtils.maxTokenAmount || CashTokenUtils.hasCommitmentLength(bitfield) && commitment.isEmpty) { - throw const BitcoinBasePluginException('Invalid cash token'); + throw const DartBitcoinPluginException('Invalid cash token'); } return Tuple( CashToken( diff --git a/lib/src/crypto/keypair/ec_public.dart b/lib/src/crypto/keypair/ec_public.dart index 03f85b2..b33e29f 100644 --- a/lib/src/crypto/keypair/ec_public.dart +++ b/lib/src/crypto/keypair/ec_public.dart @@ -9,7 +9,7 @@ class ECPublic { factory ECPublic.fromBip32(Bip32PublicKey publicKey) { if (publicKey.curveType != EllipticCurveTypes.secp256k1) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "invalid public key curve for bitcoin"); } return ECPublic._(publicKey); diff --git a/lib/src/exception/exception.dart b/lib/src/exception/exception.dart index f06d838..09652ba 100644 --- a/lib/src/exception/exception.dart +++ b/lib/src/exception/exception.dart @@ -1,9 +1,7 @@ import 'package:blockchain_utils/blockchain_utils.dart'; -class BitcoinBasePluginException extends BlockchainUtilsException { - @override - final String message; - @override - final Map? details; - const BitcoinBasePluginException(this.message, {this.details}); +class DartBitcoinPluginException extends BlockchainUtilsException { + const DartBitcoinPluginException(String message, + {Map? details}) + : super(message, details: details); } diff --git a/lib/src/models/network.dart b/lib/src/models/network.dart index 89e32b3..67c1277 100644 --- a/lib/src/models/network.dart +++ b/lib/src/models/network.dart @@ -282,7 +282,7 @@ class DashNetwork implements BasedUtxoNetwork { /// Retrieves the Human-Readable Part (HRP) for Pay-to-Witness-Public-Key-Hash (P2WPKH) addresses. @override - String get p2wpkhHrp => throw const BitcoinBasePluginException( + String get p2wpkhHrp => throw const DartBitcoinPluginException( "DashNetwork network does not support P2WPKH/P2WSH"); /// Checks if the current network is the mainnet. @@ -341,7 +341,7 @@ class DogecoinNetwork implements BasedUtxoNetwork { /// Retrieves the Human-Readable Part (HRP) for Pay-to-Witness-Public-Key-Hash (P2WPKH) addresses. @override - String get p2wpkhHrp => throw const BitcoinBasePluginException( + String get p2wpkhHrp => throw const DartBitcoinPluginException( "DogecoinNetwork network does not support P2WPKH/P2WSH"); /// Checks if the current network is the mainnet. @@ -409,7 +409,7 @@ class BitcoinCashNetwork implements BasedUtxoNetwork { /// Retrieves the Human-Readable Part (HRP) for Pay-to-Witness-Public-Key-Hash (P2WPKH) addresses /// from the associated `CoinConf`. @override - String get p2wpkhHrp => throw const BitcoinBasePluginException( + String get p2wpkhHrp => throw const DartBitcoinPluginException( "network does not support p2wpkh HRP"); String get networkHRP => conf.params.p2pkhStdHrp!; @@ -470,7 +470,7 @@ class PepeNetwork implements BasedUtxoNetwork { /// Retrieves the Human-Readable Part (HRP) for Pay-to-Witness-Public-Key-Hash (P2WPKH) addresses. @override - String get p2wpkhHrp => throw const BitcoinBasePluginException( + String get p2wpkhHrp => throw const DartBitcoinPluginException( "DogecoinNetwork network does not support P2WPKH/P2WSH"); /// Checks if the current network is the mainnet. diff --git a/lib/src/provider/api_provider/electrum_api_provider.dart b/lib/src/provider/api_provider/electrum_api_provider.dart index 9cd90ec..835cc2d 100644 --- a/lib/src/provider/api_provider/electrum_api_provider.dart +++ b/lib/src/provider/api_provider/electrum_api_provider.dart @@ -21,16 +21,15 @@ class ElectrumApiProvider { dynamic _findResult( Map data, ElectrumRequestDetails request) { - if (data["error"] != null) { - final code = - int.tryParse(((data["error"]?['code']?.toString()) ?? "0")) ?? 0; - final message = data["error"]?['message'] ?? ""; + final error = data["error"]; + if (error != null) { + final code = int.tryParse(error["code"]?.toString() ?? ""); + final message = error['message'] ?? ""; throw RPCError( - errorCode: code, - message: message, - data: data["error"]?["data"], - request: data["request"] ?? request.params, - ); + errorCode: code, + message: message, + request: data["request"] ?? request.params, + details: error); } return data["result"]; diff --git a/lib/src/provider/models/config.dart b/lib/src/provider/models/config.dart index 9369398..44ebefb 100644 --- a/lib/src/provider/models/config.dart +++ b/lib/src/provider/models/config.dart @@ -66,7 +66,7 @@ class APIConfig { baseUrl = BtcApiConst.blockCypherLitecoinBaseUri; break; default: - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "blockcypher does not support ${network.conf.coinName.name}, u must use your own provider"); } @@ -92,7 +92,7 @@ class APIConfig { baseUrl = BtcApiConst.mempoolBaseURL; break; default: - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "mempool does not support ${network.conf.coinName.name}"); } diff --git a/lib/src/provider/models/fee_rate/fee_rate.dart b/lib/src/provider/models/fee_rate/fee_rate.dart index 09c6312..8064aaa 100644 --- a/lib/src/provider/models/fee_rate/fee_rate.dart +++ b/lib/src/provider/models/fee_rate/fee_rate.dart @@ -99,7 +99,7 @@ BigInt _parseMempoolFees(dynamic data) { } else if (data is int) { return BigInt.from((data * kb)); } else { - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "cannot parse mempool fees excepted double, string got ${data.runtimeType}"); } } diff --git a/lib/src/provider/models/multisig_script.dart b/lib/src/provider/models/multisig_script.dart index 657f912..7a8aed6 100644 --- a/lib/src/provider/models/multisig_script.dart +++ b/lib/src/provider/models/multisig_script.dart @@ -51,7 +51,7 @@ class MultiSignatureAddress { BitcoinBaseAddress toP2wshAddress({required BasedUtxoNetwork network}) { if (network is! LitecoinNetwork && network is! BitcoinNetwork) { - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "${network.conf.coinName.name} Bitcoin forks that do not support Segwit. use toP2shAddress"); } return P2wshAddress.fromScript(script: multiSigScript); @@ -66,7 +66,7 @@ class MultiSignatureAddress { BitcoinBaseAddress toP2shAddress( [P2shAddressType addressType = P2shAddressType.p2pkhInP2sh]) { if (!legacySupportP2shTypes.contains(addressType)) { - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "invalid p2sh type please use one of them ${legacySupportP2shTypes.map((e) => "$e").join(", ")}"); } @@ -94,7 +94,7 @@ class MultiSignatureAddress { case P2shAddressType.p2pkhInP2sh32wt: return toP2shAddress(addressType as P2shAddressType); default: - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "invalid multisig address type. use of of them [BitcoinAddressType.p2wsh, BitcoinAddressType.p2wshInP2sh, BitcoinAddressType.p2pkhInP2sh]"); } } @@ -116,15 +116,15 @@ class MultiSignatureAddress { final sumWeight = signers.fold(0, (sum, signer) => sum + signer.weight); if (threshold > 16 || threshold < 1) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( 'The threshold should be between 1 and 16'); } if (sumWeight > 16) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( 'The total weight of the owners should not exceed 16'); } if (sumWeight < threshold) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( 'The total weight of the signatories should reach the threshold'); } final multiSigScript = ['OP_$threshold']; diff --git a/lib/src/provider/models/utxo_details.dart b/lib/src/provider/models/utxo_details.dart index a6ecb98..4917e98 100644 --- a/lib/src/provider/models/utxo_details.dart +++ b/lib/src/provider/models/utxo_details.dart @@ -48,11 +48,11 @@ class UtxoWithAddress { ECPublic public() { if (isMultiSig()) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Cannot access public key in multi-signature address"); } if (ownerDetails._publicKey == null) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Cannot access public key in watch only address; use UtxoAddressDetails constractor instead `UtxoAddressDetails.watchOnly`"); } return ECPublic.fromHex(ownerDetails._publicKey!); @@ -64,7 +64,7 @@ class UtxoWithAddress { MultiSignatureAddress get multiSigAddress => isMultiSig() ? ownerDetails._multiSigAddress! - : throw const BitcoinBasePluginException( + : throw const DartBitcoinPluginException( "The address is not associated with a multi-signature setup"); } diff --git a/lib/src/provider/transaction_builder/forked_transaction_builder.dart b/lib/src/provider/transaction_builder/forked_transaction_builder.dart index 862b0f0..542c208 100644 --- a/lib/src/provider/transaction_builder/forked_transaction_builder.dart +++ b/lib/src/provider/transaction_builder/forked_transaction_builder.dart @@ -46,7 +46,7 @@ class ForkedTransactionBuilder implements BasedBitcoinTransacationBuilder { void _validateBuilder() { if (network is! BitcoinCashNetwork && network is! BitcoinSVNetwork) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "invalid network. use ForkedTransactionBuilder for BitcoinCashNetwork and BSVNetwork otherwise use BitcoinTransactionBuilder"); } for (final i in utxosInfo) { @@ -125,7 +125,7 @@ class ForkedTransactionBuilder implements BasedBitcoinTransacationBuilder { case P2shAddressType.p2pkhInP2sh32wt: return script; default: - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "unsuported multi-sig type ${utxo.utxo.scriptType} for ${network.conf.coinName.name}"); } } @@ -146,7 +146,7 @@ class ForkedTransactionBuilder implements BasedBitcoinTransacationBuilder { case P2shAddressType.p2pkhInP2sh32wt: return senderPub.toAddress().toScriptPubKey(); default: - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "${utxo.utxo.scriptType} does not sudpport on ${network.conf.coinName.name}"); } } @@ -225,7 +225,7 @@ that demonstrate the right to spend the bitcoins associated with the correspondi final script = senderPub.toRedeemScript(); return [signedDigest, script.toHex()]; default: - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( 'Cannot send from this type of address ${utx.utxo.scriptType}'); } } @@ -328,7 +328,7 @@ be retrieved by anyone who examines the blockchain's history. required BigInt sumUtxoAmount, required BigInt sumOutputAmounts}) { if (!isFakeTransaction && sumAmountsWithFee != sumUtxoAmount) { - throw BitcoinBasePluginException('Sum value of utxo not spending', + throw DartBitcoinPluginException('Sum value of utxo not spending', details: { "inputAmount": sumUtxoAmount, "fee": fee, @@ -353,7 +353,7 @@ be retrieved by anyone who examines the blockchain's history. previousValue + (element.value ?? BigInt.zero)); if (amount != i.value) { - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( 'Sum token value of UTXOs not spending. use BitcoinBurnableOutput if you want to burn tokens.', details: { "token": i.key, @@ -379,7 +379,7 @@ be retrieved by anyone who examines the blockchain's history. element.utxoHash == i.utxo.txHash && element.categoryID == token.category); if (hasBurnableOutput) continue; - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( 'Some NFTs in the inputs lack the corresponding spending in the outputs. If you intend to burn tokens, consider utilizing the BitcoinBurnableOutput.', details: {"category id": token.category}); } @@ -420,7 +420,7 @@ be retrieved by anyone who examines the blockchain's history. } } if (sumMultiSigWeight != multiSigAddress.threshold) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "some multisig signature does not exist"); } continue; @@ -503,7 +503,7 @@ be retrieved by anyone who examines the blockchain's history. } } if (sumMultiSigWeight != multiSigAddress.threshold) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "some multisig signature does not exist"); } @@ -593,7 +593,7 @@ be retrieved by anyone who examines the blockchain's history. } } if (sumMultiSigWeight != multiSigAddress.threshold) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "some multisig signature does not exist"); } diff --git a/lib/src/provider/transaction_builder/transaction_builder.dart b/lib/src/provider/transaction_builder/transaction_builder.dart index a20130d..07587c6 100644 --- a/lib/src/provider/transaction_builder/transaction_builder.dart +++ b/lib/src/provider/transaction_builder/transaction_builder.dart @@ -48,14 +48,14 @@ class BitcoinTransactionBuilder implements BasedBitcoinTransacationBuilder { /// validate network and address suport before create transaction void _validateBuilder() { if (network is BitcoinCashNetwork || network is BitcoinSVNetwork) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "invalid network for BitcoinCashNetwork and BSVNetwork use ForkedTransactionBuilder"); } final token = utxosInfo.any((element) => element.utxo.token != null); final tokenInput = outPuts.whereType(); final burn = outPuts.whereType(); if (token || tokenInput.isNotEmpty || burn.isNotEmpty) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "Cash Token only work on Bitcoin cash network"); } for (final i in utxosInfo) { @@ -193,7 +193,7 @@ class BitcoinTransactionBuilder implements BasedBitcoinTransacationBuilder { } return script; default: - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "unsuported multi-sig type ${utxo.utxo.scriptType}"); } } @@ -237,7 +237,7 @@ class BitcoinTransactionBuilder implements BasedBitcoinTransacationBuilder { } return senderPub.toRedeemScript(); } - throw const BitcoinBasePluginException("invalid bitcoin address type"); + throw const DartBitcoinPluginException("invalid bitcoin address type"); } /// generateTransactionDigest generates and returns a transaction digest for a given input in the context of a Bitcoin @@ -314,7 +314,7 @@ class BitcoinTransactionBuilder implements BasedBitcoinTransacationBuilder { final p2wsh = P2wshAddress.fromScript(script: script); return [p2wsh.toScriptPubKey().toHex()]; default: - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "Invalid p2sh nested segwit type ${utxo.utxo.scriptType.value}"); } } @@ -327,7 +327,7 @@ class BitcoinTransactionBuilder implements BasedBitcoinTransacationBuilder { final script = senderPub.toSegwitAddress().toScriptPubKey(); return [script.toHex()]; default: - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "Invalid p2sh nested segwit type ${utxo.utxo.scriptType.value}"); } } @@ -353,7 +353,7 @@ that demonstrate the right to spend the bitcoins associated with the correspondi case P2shAddressType.p2wpkhInP2sh: return [signedDigest, senderPub.toHex()]; default: - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "invalid segwit address type ${utx.utxo.scriptType.value}"); } } else { @@ -369,7 +369,7 @@ that demonstrate the right to spend the bitcoins associated with the correspondi final script = senderPub.toRedeemScript(); return [signedDigest, script.toHex()]; default: - throw BitcoinBasePluginException( + throw DartBitcoinPluginException( "invalid address type ${utx.utxo.scriptType.value}"); } } @@ -494,7 +494,7 @@ that demonstrate the right to spend the bitcoins associated with the correspondi /// We will check whether you have spent the correct amounts or not if (!isFakeTransaction && sumAmountsWithFee != sumUtxoAmount) { - throw const BitcoinBasePluginException('Sum value of utxo not spending'); + throw const DartBitcoinPluginException('Sum value of utxo not spending'); } /// create new transaction with inputs and outputs and isSegwit transaction or not @@ -552,7 +552,7 @@ that demonstrate the right to spend the bitcoins associated with the correspondi } } if (sumMultiSigWeight != multiSigAddress.threshold) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "some multisig signature does not exist"); } _addUnlockScriptScript( @@ -615,7 +615,7 @@ that demonstrate the right to spend the bitcoins associated with the correspondi } } if (sumMultiSigWeight != multiSigAddress.threshold) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "some multisig signature does not exist"); } continue; @@ -656,7 +656,7 @@ that demonstrate the right to spend the bitcoins associated with the correspondi /// We will check whether you have spent the correct amounts or not if (!isFakeTransaction && sumAmountsWithFee != sumUtxoAmount) { - throw const BitcoinBasePluginException('Sum value of utxo not spending'); + throw const DartBitcoinPluginException('Sum value of utxo not spending'); } /// create new transaction with inputs and outputs and isSegwit transaction or not @@ -714,7 +714,7 @@ that demonstrate the right to spend the bitcoins associated with the correspondi } } if (sumMultiSigWeight != multiSigAddress.threshold) { - throw const BitcoinBasePluginException( + throw const DartBitcoinPluginException( "some multisig signature does not exist"); } _addUnlockScriptScript( diff --git a/pubspec.yaml b/pubspec.yaml index b86dce4..f1c3442 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.7.0 +version: 4.8.0 homepage: "https://github.com/mrtnetwork/bitcoin_base" repository: "https://github.com/mrtnetwork/bitcoin_base" Author: mrhaydari.t@gmail.com @@ -16,14 +16,14 @@ environment: dependencies: - blockchain_utils: ^3.3.0 + blockchain_utils: ^3.4.0 # blockchain_utils: # path: ../blockchain_utils dev_dependencies: - test: ^1.25.5 + test: ^1.25.8 lints: ^4.0.0 flutter_lints: ^4.0.0