From c0d40c675b9d935b305d08e98bae35faeec77c83 Mon Sep 17 00:00:00 2001 From: Mohsen <56779182+mrtnetwork@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:19:53 +0330 Subject: [PATCH] v4.3.0 Update dependencies. --- CHANGELOG.md | 4 +++ .../lib/example/contract/call_example.dart | 10 +++++-- example/pubspec.yaml | 2 +- lib/ada/src/ada.dart | 1 + lib/ada/src/address/era/core/address.dart | 5 ++-- .../era/shelly/core/shelly_address.dart | 5 ++-- lib/ada/src/address/utils/utils.dart | 5 ++-- .../builder/builder/transaction_builder.dart | 12 ++++---- lib/ada/src/exception/exception.dart | 6 ++++ lib/ada/src/keypair/keypair/private_key.dart | 3 +- .../models/certificate/core/certificate.dart | 3 +- .../src/models/certificate/core/types.dart | 9 +++--- .../move_instantaneous_reward/types/mir.dart | 3 +- .../types/mir_pot.dart | 6 ++-- .../types/pool/relay/core/relay.dart | 3 +- .../types/pool/relay/core/relay_type.dart | 8 ++--- .../credential/core/stake_cred_type.dart | 7 +++-- .../data_options/core/data_option_type.dart | 7 +++-- .../src/models/data_options/plutus_data.dart | 3 +- .../header_leader_cert_type.dart | 6 ++-- .../metadata/core/tranasction_metadata.dart | 4 ++- .../core/transaction_metadata_types.dart | 4 +-- lib/ada/src/models/metadata/types/bytes.dart | 3 +- .../models/metadata/utils/metadata_utils.dart | 30 ++++++++++--------- .../native_script/core/native_script.dart | 3 +- .../core/native_script_type.dart | 5 ++-- .../utils/native_script_utils.dart | 5 ++-- .../plutus/plutus/core/plutus_data.dart | 5 ++-- .../plutus/plutus/core/plutus_data_type.dart | 6 ++-- .../plutus/types/constr_plutus_data.dart | 3 +- .../src/models/plutus/plutus/types/map.dart | 3 +- .../plutus_script/language/language.dart | 5 ++-- .../redeemer_tag/redeemer_tag.dart | 5 ++-- lib/ada/src/models/plutus/utils/utils.dart | 27 +++++++++-------- .../output/script_ref/core/script_ref.dart | 5 ++-- .../script_ref/core/script_ref_type.dart | 9 +++--- lib/ada/src/models/unit_interval.dart | 4 +-- lib/ada/src/models/update/models/nonce.dart | 5 ++-- lib/ada/src/models/utils.dart | 5 ++-- .../src/provider/blockfrost/core/core.dart | 4 +-- lib/ada/src/serialization/cbor/cbor_i164.dart | 9 +++--- .../cbor/cbor_serialization.dart | 23 +++++++------- lib/ada/src/serialization/cbor/cbor_u64.dart | 8 ++--- lib/ethereum/ethereum.dart | 3 ++ lib/ethereum/src/address/evm_address.dart | 5 ++-- lib/ethereum/src/exception/exception.dart | 6 ++++ lib/ethereum/src/keys/private_key.dart | 3 +- lib/ethereum/src/keys/public_key.dart | 3 +- lib/ethereum/src/models/access_list.dart | 3 +- lib/ethereum/src/rlp/decode.dart | 9 +++--- lib/ethereum/src/rpc/provider/provider.dart | 19 ++++++------ .../src/transaction/eth_transaction.dart | 23 +++++++------- .../transaction/eth_transaction_builder.dart | 15 +++++----- lib/solana/src/exception/exception.dart | 18 ++--------- .../name_service_twitter_helper.dart | 2 +- lib/solana/src/rpc/provider/provider.dart | 20 ++++++------- lib/solana/src/utils/layouts.dart | 6 ++-- lib/solidity/abi/exception/abi_exception.dart | 18 ++--------- lib/tron/src/exception/exception.dart | 18 ++--------- lib/utils/utils/number_utils.dart | 12 ++------ pubspec.yaml | 4 +-- 61 files changed, 245 insertions(+), 230 deletions(-) create mode 100644 lib/ada/src/exception/exception.dart create mode 100644 lib/ethereum/src/exception/exception.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 20197e2..cf2abaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.3.0 + +- Update dependencies. + ## 4.2.0 - Fixed Solana simulate transaction model diff --git a/example/lib/example/contract/call_example.dart b/example/lib/example/contract/call_example.dart index b29ce96..1a18193 100644 --- a/example/lib/example/contract/call_example.dart +++ b/example/lib/example/contract/call_example.dart @@ -97,7 +97,10 @@ void main() async { params: [], )); } on RPCError catch (e) { - final revertErrors = contract.decodeError(e.data); + final data = e.details?["data"]; + if (data != null) { + final revertErrors = contract.decodeError(data); + } } // Another RPC call expected to raise an error, catch the error and decode it @@ -114,7 +117,10 @@ void main() async { ], )); } on RPCError catch (e) { - final revertErrors = contract.decodeError(e.data); + final data = e.details?["data"]; + if (data != null) { + final revertErrors = contract.decodeError(data); + } } // Retrieve the function information for a specific function name diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 6714b46..4e86d69 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -30,7 +30,7 @@ dependencies: http: ^1.1.0 # blockchain_utils: # path: ../../blockchain_utils - blockchain_utils: ^3.3.0 + blockchain_utils: ^3.4.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 diff --git a/lib/ada/src/ada.dart b/lib/ada/src/ada.dart index 4c02574..20183ae 100644 --- a/lib/ada/src/ada.dart +++ b/lib/ada/src/ada.dart @@ -5,3 +5,4 @@ export 'provider/provider.dart'; export 'serialization/cbor_serialization.dart'; export 'utils/ada_helper.dart'; export 'builder/builder.dart'; +export 'exception/exception.dart'; diff --git a/lib/ada/src/address/era/core/address.dart b/lib/ada/src/address/era/core/address.dart index fc5eb86..96690f4 100644 --- a/lib/ada/src/address/era/core/address.dart +++ b/lib/ada/src/address/era/core/address.dart @@ -3,6 +3,7 @@ import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:on_chain/ada/src/address/era/byron/byron.dart'; import 'package:on_chain/ada/src/address/era/shelly/shelly.dart'; import 'package:on_chain/ada/src/address/utils/utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; /// Represents an abstract class for ADA addresses with serialization capabilities. @@ -47,7 +48,7 @@ abstract class ADAAddress with ADASerialization { break; } if (addr is! T) { - throw MessageException("Invalid address type.", details: { + throw ADAPluginException("Invalid address type.", details: { "Excepted": "$T", "Type": addr.runtimeType, "address": addr.address @@ -73,7 +74,7 @@ abstract class ADAAddress with ADASerialization { } if (address is! T) { - throw MessageException("Invalid ADA address type.", details: { + throw ADAPluginException("Invalid ADA address type.", details: { "Excepted": "$T", "Type": address.addressType, "address": address.address diff --git a/lib/ada/src/address/era/shelly/core/shelly_address.dart b/lib/ada/src/address/era/shelly/core/shelly_address.dart index 39d49e3..fe116b9 100644 --- a/lib/ada/src/address/era/shelly/core/shelly_address.dart +++ b/lib/ada/src/address/era/shelly/core/shelly_address.dart @@ -2,6 +2,7 @@ import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:on_chain/ada/src/address/era/core/address.dart'; import 'package:on_chain/ada/src/address/era/shelly/shelly.dart'; import 'package:on_chain/ada/src/address/utils/utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; import 'package:on_chain/ada/src/models/credential/core/stake_cred.dart'; @@ -30,7 +31,7 @@ abstract class ADAShellyAddress extends ADAAddress { case ADAAddressType.enterprise: return ADAEnterpriseAddress(address, network: network); default: - throw const MessageException( + throw const ADAPluginException( "Invalid shelly address. for byron address please use ByronAddress."); } } @@ -44,7 +45,7 @@ abstract class ADAShellyAddress extends ADAAddress { static T deserialize(CborBytesValue cbor) { ADAAddress address = ADAAddress.deserialize(cbor); if (address is! T) { - throw MessageException("Invalid address type.", details: { + throw ADAPluginException("Invalid address type.", details: { "Excepted": "$T", "Type": address.runtimeType, "address": address.address diff --git a/lib/ada/src/address/utils/utils.dart b/lib/ada/src/address/utils/utils.dart index 444907e..9e40a0c 100644 --- a/lib/ada/src/address/utils/utils.dart +++ b/lib/ada/src/address/utils/utils.dart @@ -2,6 +2,7 @@ import 'package:blockchain_utils/bip/address/ada/ada.dart'; import 'package:blockchain_utils/bip/address/addr_key_validator.dart'; import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:on_chain/ada/src/address/era/core/address.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/models/credential/core/stake_cred.dart'; import 'package:on_chain/ada/src/models/credential/core/stake_cred_type.dart'; import 'package:on_chain/ada/src/models/credential/key.dart'; @@ -23,7 +24,7 @@ class AdaAddressUtils { AdaGenericAddrDecoder().decode(address, {"net_tag": network}); if (addrType != null) { if (decodeAddr.type.header != addrType.header) { - throw MessageException("Incorrect address type. ", + throw ADAPluginException("Incorrect address type. ", details: {"Excepted": addrType.name, "type": decodeAddr.type}); } } @@ -59,7 +60,7 @@ class AdaAddressUtils { final decode = AdaGenericAddrDecoder().decode(address, {"net_tag": network}); if (decode.type == ADAAddressType.byron) { - throw MessageException("Invalid shelly address.", + throw ADAPluginException("Invalid shelly address.", details: {"address": address, "type": decode.type}); } if (keepPrefix) { diff --git a/lib/ada/src/builder/builder/transaction_builder.dart b/lib/ada/src/builder/builder/transaction_builder.dart index 7659bd6..1f097dc 100644 --- a/lib/ada/src/builder/builder/transaction_builder.dart +++ b/lib/ada/src/builder/builder/transaction_builder.dart @@ -1,6 +1,7 @@ import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:on_chain/ada/src/address/address.dart'; import 'package:on_chain/ada/src/builder/builder/tranasction_builder_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/models/ada_models.dart'; import 'package:on_chain/ada/src/provider/provider.dart'; import 'certificate_builder.dart'; @@ -77,7 +78,7 @@ class ADATransactionBuilder { final multiAsset = utxos.multiAsset; final asset = multiAsset - _outputs.multiAsset; if (lovelence.isNegative) { - throw MessageException("Insufficient input in transaction.", details: { + throw ADAPluginException("Insufficient input in transaction.", details: { "utxo lovelence": utxos.sumOflovelace, "output lovelence": _outputs.sumOflovelace }); @@ -94,7 +95,8 @@ class ADATransactionBuilder { int estimateSize({ADAAddress? onChangeAddress}) { if (utxos.isEmpty || _outputs.isEmpty) { - throw const MessageException("Utxos and outputs must not be not empty."); + throw const ADAPluginException( + "Utxos and outputs must not be not empty."); } final outs = _outputs.map((e) { if (e.amount.coin == BigInt.zero) { @@ -138,7 +140,7 @@ class ADATransactionBuilder { TransactionOutput? onChangeAddress(ADAAddress onChangeAddress) { if (_fee == null) { - throw const MessageException( + throw const ADAPluginException( "please calculation the transaction fees befor using change address."); } final change = _changeOutput(onChangeAddress); @@ -156,7 +158,7 @@ class ADATransactionBuilder { TransactionBody buildTxBody({AuxiliaryDataHash? auxHash}) { if (fee == null) { - throw const MessageException( + throw const ADAPluginException( "cannot build transaction body before calculation fee."); } final mint = getMint(); @@ -229,7 +231,7 @@ class ADATransactionBuilder { final asset = utxos.multiAsset - outputs.multiAsset; if (lovelence != BigInt.zero || asset != MultiAsset.empty) { - throw MessageException( + throw ADAPluginException( "The amount of inputs and outputs is not calculated correctly", details: {"lovelence": lovelence, "asset": asset}); } diff --git a/lib/ada/src/exception/exception.dart b/lib/ada/src/exception/exception.dart new file mode 100644 index 0000000..b28e6a8 --- /dev/null +++ b/lib/ada/src/exception/exception.dart @@ -0,0 +1,6 @@ +import 'package:blockchain_utils/exception/exceptions.dart'; + +class ADAPluginException extends BlockchainUtilsException { + const ADAPluginException(String message, {Map? details}) + : super(message, details: details); +} diff --git a/lib/ada/src/keypair/keypair/private_key.dart b/lib/ada/src/keypair/keypair/private_key.dart index ce7c5c0..4b2ad36 100644 --- a/lib/ada/src/keypair/keypair/private_key.dart +++ b/lib/ada/src/keypair/keypair/private_key.dart @@ -1,5 +1,6 @@ import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:on_chain/ada/src/address/era/byron/byron.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/models/fixed_bytes/models/models.dart'; import 'package:on_chain/ada/src/models/transaction/witnesses/bootstrap_witness.dart'; import 'package:on_chain/ada/src/models/transaction/witnesses/vkey_witness.dart'; @@ -18,7 +19,7 @@ class AdaPrivateKey { factory AdaPrivateKey.fromBytes(List privateKeyBytes) { if (privateKeyBytes.length != Ed25519KeysConst.privKeyByteLen && privateKeyBytes.length != Ed25519KholawKeysConst.privKeyByteLen) { - throw MessageException("Invalid private key bytes.", details: { + throw ADAPluginException("Invalid private key bytes.", details: { "length": privateKeyBytes.length, "Excepted": "${Ed25519KeysConst.privKeyByteLen} or ${Ed25519KholawKeysConst.privKeyByteLen}" diff --git a/lib/ada/src/models/certificate/core/certificate.dart b/lib/ada/src/models/certificate/core/certificate.dart index 0d7caa6..092ded5 100644 --- a/lib/ada/src/models/certificate/core/certificate.dart +++ b/lib/ada/src/models/certificate/core/certificate.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/models/certificate/certs.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; @@ -37,7 +38,7 @@ abstract class Certificate with ADASerialization { try { type = CertificateType.fromName(json.keys.first); } on StateError { - throw MessageException("Invalid json certificate.", + throw ADAPluginException("Invalid json certificate.", details: {"json": json}); } switch (type) { diff --git a/lib/ada/src/models/certificate/core/types.dart b/lib/ada/src/models/certificate/core/types.dart index 6e63081..e9cc35d 100644 --- a/lib/ada/src/models/certificate/core/types.dart +++ b/lib/ada/src/models/certificate/core/types.dart @@ -1,5 +1,6 @@ import 'package:blockchain_utils/cbor/cbor.dart'; -import 'package:blockchain_utils/exception/exception.dart'; + +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; /// Represents the type of a certificate. @@ -57,7 +58,7 @@ class CertificateType with ADASerialization { {CertificateType? validate}) { final type = fromValue(cbor.value); if (validate != null && type != validate) { - throw MessageException("Invalid Certificate type.", + throw ADAPluginException("Invalid Certificate type.", details: {"Excepted": validate, "Type": type}); } return type; @@ -67,7 +68,7 @@ class CertificateType with ADASerialization { static CertificateType fromValue(int? value) { return values.firstWhere( (element) => element.value == value, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No CertificateType found matching the specified value", details: {"value": value}), ); @@ -77,7 +78,7 @@ class CertificateType with ADASerialization { static CertificateType fromName(String? name) { return values.firstWhere( (element) => element.name == name, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No CertificateType found matching the specified name", details: {"name": name}), ); diff --git a/lib/ada/src/models/certificate/types/move_instantaneous_reward/types/mir.dart b/lib/ada/src/models/certificate/types/move_instantaneous_reward/types/mir.dart index 48b4f3d..e8bfe3f 100644 --- a/lib/ada/src/models/certificate/types/move_instantaneous_reward/types/mir.dart +++ b/lib/ada/src/models/certificate/types/move_instantaneous_reward/types/mir.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; import 'package:on_chain/ada/src/models/certificate/types/move_instantaneous_reward/types/to_other_pot.dart'; import 'package:on_chain/ada/src/models/certificate/types/move_instantaneous_reward/types/to_stake_credentials.dart'; @@ -21,7 +22,7 @@ abstract class MIR with ADASerialization { } factory MIR.fromJson(dynamic json) { if (json is! Map && json is! String) { - throw MessageException("Invalid MIR json. value must be string or map", + throw ADAPluginException("Invalid MIR json. value must be string or map", details: {"json": json}); } if (json is String) { diff --git a/lib/ada/src/models/certificate/types/move_instantaneous_reward/types/mir_pot.dart b/lib/ada/src/models/certificate/types/move_instantaneous_reward/types/mir_pot.dart index bd79433..91c46cc 100644 --- a/lib/ada/src/models/certificate/types/move_instantaneous_reward/types/mir_pot.dart +++ b/lib/ada/src/models/certificate/types/move_instantaneous_reward/types/mir_pot.dart @@ -1,5 +1,5 @@ import 'package:blockchain_utils/cbor/cbor.dart'; -import 'package:blockchain_utils/exception/exceptions.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; /// Represents a pot for Move instance reward. @@ -31,7 +31,7 @@ class MIRPot with ADASerialization { static MIRPot fromValue(int? value) { return values.firstWhere( (element) => element.value == value, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No MIRPot found matching the specified value", details: {"value": value}), ); @@ -41,7 +41,7 @@ class MIRPot with ADASerialization { static MIRPot fromName(String? name) { return values.firstWhere( (element) => element.name == name, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No MIRPot found matching the specified name", details: {"name": name}), ); diff --git a/lib/ada/src/models/certificate/types/pool/relay/core/relay.dart b/lib/ada/src/models/certificate/types/pool/relay/core/relay.dart index 642428e..750c8d3 100644 --- a/lib/ada/src/models/certificate/types/pool/relay/core/relay.dart +++ b/lib/ada/src/models/certificate/types/pool/relay/core/relay.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; import 'package:on_chain/ada/src/models/certificate/types/pool/relay/core/relay_type.dart'; import 'package:on_chain/ada/src/models/certificate/types/pool/relay/relays/multi_host_name.dart'; @@ -30,7 +31,7 @@ abstract class Relay with ADASerialization { try { type = RelayType.fromName(json.keys.first); } on StateError { - throw MessageException("Invalid Relay json.", details: {"json": json}); + throw ADAPluginException("Invalid Relay json.", details: {"json": json}); } switch (type) { case RelayType.multiHostName: diff --git a/lib/ada/src/models/certificate/types/pool/relay/core/relay_type.dart b/lib/ada/src/models/certificate/types/pool/relay/core/relay_type.dart index 08d3c2f..860c8a5 100644 --- a/lib/ada/src/models/certificate/types/pool/relay/core/relay_type.dart +++ b/lib/ada/src/models/certificate/types/pool/relay/core/relay_type.dart @@ -1,5 +1,5 @@ import 'package:blockchain_utils/cbor/cbor.dart'; -import 'package:blockchain_utils/exception/exceptions.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; /// Enum representing the type of relay. @@ -33,7 +33,7 @@ class RelayType with ADASerialization { factory RelayType.deserialize(CborIntValue cbor, {RelayType? validate}) { final type = fromValue(cbor.value); if (validate != null && type != validate) { - throw MessageException("Invalid RelayType.", + throw ADAPluginException("Invalid RelayType.", details: {"Expected": validate, "Type": type}); } return fromValue(cbor.value); @@ -43,7 +43,7 @@ class RelayType with ADASerialization { static RelayType fromValue(int? value) { return values.firstWhere( (element) => element.value == value, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No RelayType found matching the specified value", details: {"value": value}), ); @@ -53,7 +53,7 @@ class RelayType with ADASerialization { static RelayType fromName(String? name) { return values.firstWhere( (element) => element.name == name, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No RelayType found matching the specified name", details: {"name": name}), ); diff --git a/lib/ada/src/models/credential/core/stake_cred_type.dart b/lib/ada/src/models/credential/core/stake_cred_type.dart index cf344e7..620225a 100644 --- a/lib/ada/src/models/credential/core/stake_cred_type.dart +++ b/lib/ada/src/models/credential/core/stake_cred_type.dart @@ -1,5 +1,6 @@ import 'package:blockchain_utils/cbor/cbor.dart'; -import 'package:blockchain_utils/exception/exception.dart'; + +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; /// Represents the type of a stake credential. @@ -31,7 +32,7 @@ class StakeCredType with ADASerialization { static StakeCredType fromValue(int? value) { return values.firstWhere( (element) => element.value == value, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No StakeCredType found matching the specified value", details: {"value": value}), ); @@ -41,7 +42,7 @@ class StakeCredType with ADASerialization { static StakeCredType fromName(String? name) { return values.firstWhere( (element) => element.name == name, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No StakeCredType found matching the specified name", details: {"name": name}), ); diff --git a/lib/ada/src/models/data_options/core/data_option_type.dart b/lib/ada/src/models/data_options/core/data_option_type.dart index 8c2c963..97024da 100644 --- a/lib/ada/src/models/data_options/core/data_option_type.dart +++ b/lib/ada/src/models/data_options/core/data_option_type.dart @@ -1,5 +1,6 @@ import 'package:blockchain_utils/cbor/cbor.dart'; -import 'package:blockchain_utils/exception/exception.dart'; + +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; /// Represents the type of data included in a transaction option with serialization support. @@ -39,7 +40,7 @@ class TransactionDataOptionType with ADASerialization { {TransactionDataOptionType? validate}) { final type = fromValue(cbor.value); if (validate != null && validate != type) { - throw MessageException("Invalid TransactionDataOptionType.", + throw ADAPluginException("Invalid TransactionDataOptionType.", details: {"Excepted": validate, "Type": type}); } return type; @@ -49,7 +50,7 @@ class TransactionDataOptionType with ADASerialization { static TransactionDataOptionType fromValue(int? value) { return values.firstWhere( (element) => element.value == value, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No TransactionDataOptionType found matching the specified value", details: {"value": value}), ); diff --git a/lib/ada/src/models/data_options/plutus_data.dart b/lib/ada/src/models/data_options/plutus_data.dart index 279ba4e..d2c8ef7 100644 --- a/lib/ada/src/models/data_options/plutus_data.dart +++ b/lib/ada/src/models/data_options/plutus_data.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; import 'package:on_chain/ada/src/models/data_options/core/data_option_type.dart'; import 'package:on_chain/ada/src/models/plutus/plutus/core/plutus_data.dart'; @@ -20,7 +21,7 @@ class DataOptionData extends DataOption { validate: TransactionDataOptionType.data); final CborTagValue cborTag = cbor.getIndex(1); if (!BytesUtils.bytesEqual(cborTag.tags, _plutusDataOptionTag)) { - throw MessageException("Invalid date option tag.", + throw ADAPluginException("Invalid date option tag.", details: {"Tag": cborTag.tags, "Excepted": _plutusDataOptionTag}); } final List plutusBytes = cborTag.getValue(); diff --git a/lib/ada/src/models/header/leader_cert/header_leader_cert/header_leader_cert_type.dart b/lib/ada/src/models/header/leader_cert/header_leader_cert/header_leader_cert_type.dart index 817767c..b535fa3 100644 --- a/lib/ada/src/models/header/leader_cert/header_leader_cert/header_leader_cert_type.dart +++ b/lib/ada/src/models/header/leader_cert/header_leader_cert/header_leader_cert_type.dart @@ -1,5 +1,5 @@ import 'package:blockchain_utils/cbor/cbor.dart'; -import 'package:blockchain_utils/exception/exceptions.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; class HeaderLeaderCertType with ADASerialization { @@ -15,7 +15,7 @@ class HeaderLeaderCertType with ADASerialization { {HeaderLeaderCertType? validate}) { final type = fromValue(cbor.value); if (validate != null && type != validate) { - throw MessageException("Invalid HeaderLeaderCertType.", + throw ADAPluginException("Invalid HeaderLeaderCertType.", details: {"Excepted": validate, "Type": type}); } @@ -25,7 +25,7 @@ class HeaderLeaderCertType with ADASerialization { static HeaderLeaderCertType fromValue(int? value) { return values.firstWhere( (element) => element.value == value, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No HeaderLeaderCertType found matching the specified value", details: {"value": value}), ); diff --git a/lib/ada/src/models/metadata/core/tranasction_metadata.dart b/lib/ada/src/models/metadata/core/tranasction_metadata.dart index 65df75b..b341da3 100644 --- a/lib/ada/src/models/metadata/core/tranasction_metadata.dart +++ b/lib/ada/src/models/metadata/core/tranasction_metadata.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/models/metadata/types/types.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; import 'package:on_chain/ada/src/models/metadata/utils/metadata_utils.dart'; @@ -41,7 +42,8 @@ abstract class TransactionMetadata try { type = TransactionMetadataType.fromName(json.keys.first); } on StateError { - throw MessageException("Invalid metadata json.", details: {"json": json}); + throw ADAPluginException("Invalid metadata json.", + details: {"json": json}); } final TransactionMetadata metadata; switch (type) { diff --git a/lib/ada/src/models/metadata/core/transaction_metadata_types.dart b/lib/ada/src/models/metadata/core/transaction_metadata_types.dart index 823ea0c..368d1cb 100644 --- a/lib/ada/src/models/metadata/core/transaction_metadata_types.dart +++ b/lib/ada/src/models/metadata/core/transaction_metadata_types.dart @@ -1,5 +1,5 @@ import 'package:blockchain_utils/cbor/cbor.dart'; -import 'package:blockchain_utils/exception/exceptions.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; /// Represents a type of transaction metadata with serialization support. @@ -44,7 +44,7 @@ class TransactionMetadataType with ADASerialization { static TransactionMetadataType fromName(String? name) { return values.firstWhere( (element) => element.name == name, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No TransactionMetadataType found matching the specified name", details: {"name": name}), ); diff --git a/lib/ada/src/models/metadata/types/bytes.dart b/lib/ada/src/models/metadata/types/bytes.dart index f1c96c5..87af09d 100644 --- a/lib/ada/src/models/metadata/types/bytes.dart +++ b/lib/ada/src/models/metadata/types/bytes.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/models/metadata/core/meta_data.dart'; /// Represents transaction metadata containing bytes. @@ -38,7 +39,7 @@ class TransactionMetadataBytes extends TransactionMetadata> { {MetadataSchemaConfig config = const MetadataSchemaConfig( jsonSchema: MetadataJsonSchema.noConversions)}) { if (config.jsonSchema == MetadataJsonSchema.noConversions) { - throw const MessageException( + throw const ADAPluginException( "bytes not allowed in JSON in specified schema."); } if (config.jsonSchema == MetadataJsonSchema.detailedSchema) { diff --git a/lib/ada/src/models/metadata/utils/metadata_utils.dart b/lib/ada/src/models/metadata/utils/metadata_utils.dart index b4106c6..26bff99 100644 --- a/lib/ada/src/models/metadata/utils/metadata_utils.dart +++ b/lib/ada/src/models/metadata/utils/metadata_utils.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/models/metadata/core/config.dart'; import 'package:on_chain/ada/src/models/metadata/core/metadata_json_schame.dart'; import 'package:on_chain/ada/src/models/metadata/core/tranasction_metadata.dart'; @@ -19,7 +20,7 @@ class TransactionMetadataUtils { if (cbor is! CborMapValue && cbor is! CborListValue && cbor is! CborTagValue) { - throw MessageException("Invalid AuxiliaryData cbor object type.", + throw ADAPluginException("Invalid AuxiliaryData cbor object type.", details: { "Type": cbor.runtimeType, "Excepted": "$CborMapValue, $CborListValue or $CborTagValue" @@ -27,7 +28,7 @@ class TransactionMetadataUtils { } if (cbor is CborTagValue) { if (!BytesUtils.bytesEqual(cbor.tags, auxiliaryDataCborTag)) { - throw MessageException("Invalid AuxiliaryData cbor tag.", + throw ADAPluginException("Invalid AuxiliaryData cbor tag.", details: {"Exepted": auxiliaryDataCborTag, "Tag": cbor.tags}); } } @@ -56,7 +57,7 @@ class TransactionMetadataUtils { static TransactionMetadata _parseDetailed( dynamic value, MetadataJsonSchema jsonSchema) { if (value is! Map || value.length != 1) { - throw const MessageException( + throw const ADAPluginException( "DetailedSchema requires types to be tagged objects"); } final entry = value.entries.first; @@ -70,30 +71,31 @@ class TransactionMetadataUtils { case "bytes": final bytes = BytesUtils.tryFromHexString(v); if (bytes == null) { - throw MessageException("invalid hex string.", details: {"Value": v}); + throw ADAPluginException("invalid hex string.", + details: {"Value": v}); } return TransactionMetadataBytes(value: bytes); case "list": if (v is! List) { - throw MessageException("key does not match type.", + throw ADAPluginException("key does not match type.", details: {"Key": key, "Value": v}); } return _encodeArray(v, jsonSchema); case "map": if (v is! List) { - throw const MessageException( + throw const ADAPluginException( r"entry format in detailed schema map object not correct. Needs to be of form '{'k': 'key', 'v': 'value'}'", ); } final Map values = {}; for (final i in v) { if (i is! Map) { - throw const MessageException( + throw const ADAPluginException( r"entry format in detailed schema map object not correct. Needs to be of form '{'k': 'key', 'v': 'value'}'", ); } if (!i.containsKey("k") || !i.containsKey("v")) { - throw const MessageException( + throw const ADAPluginException( r"entry format in detailed schema map object not correct. Needs to be of form '{'k': 'key', 'v': 'value'}'", ); } @@ -104,7 +106,7 @@ class TransactionMetadataUtils { } return TransactionMetadataMap(value: values); default: - throw MessageException("key is not valid.", details: {"Key": key}); + throw ADAPluginException("key is not valid.", details: {"Key": key}); } } @@ -122,7 +124,7 @@ class TransactionMetadataUtils { } else if (obj is CborListValue) { metadata = TransactionMetadataList.deserialize(obj); } else { - throw MessageException("Invalid metadata type.", + throw ADAPluginException("Invalid metadata type.", details: {"Type": obj.runtimeType}); } return metadata; @@ -136,7 +138,7 @@ class TransactionMetadataUtils { static TransactionMetadata _encodeString( dynamic value, MetadataJsonSchema jsonSchema) { if (value is! String) { - throw MessageException("Invalid string format.", + throw ADAPluginException("Invalid string format.", details: {"Value": "$value", "Type": "${value.runtimeType}"}); } if (jsonSchema == MetadataJsonSchema.basicConversions) { @@ -182,10 +184,10 @@ class TransactionMetadataUtils { val is Map) return; } if (val != null) { - throw MessageException("Invalid metadata format. type not allowed.", + throw ADAPluginException("Invalid metadata format. type not allowed.", details: {"Value": val, "Type": "${val.runtimeType}"}); } - throw const MessageException("null not allowed in metadata"); + throw const ADAPluginException("null not allowed in metadata"); } static dynamic encodeKey( @@ -208,7 +210,7 @@ class TransactionMetadataUtils { case TransactionMetadataType.metadataMap: return key.toJsonSchema(config: config); } - throw MessageException( + throw ADAPluginException( "Key type not allowed in JSON under specified schema.", details: {"Key": key, "type": key.type}); } diff --git a/lib/ada/src/models/native_script/core/native_script.dart b/lib/ada/src/models/native_script/core/native_script.dart index b64860d..833d54a 100644 --- a/lib/ada/src/models/native_script/core/native_script.dart +++ b/lib/ada/src/models/native_script/core/native_script.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; import 'package:on_chain/ada/src/models/fixed_bytes/models/models.dart'; import 'package:on_chain/ada/src/models/native_script/core/native_script_type.dart'; @@ -36,7 +37,7 @@ abstract class NativeScript with ADASerialization { try { type = NativeScriptType.fromName(json.keys.first); } on StateError { - throw MessageException("Invalid NativeScript json.", + throw ADAPluginException("Invalid NativeScript json.", details: {"json": json}); } switch (type) { diff --git a/lib/ada/src/models/native_script/core/native_script_type.dart b/lib/ada/src/models/native_script/core/native_script_type.dart index b1501a5..8138ac6 100644 --- a/lib/ada/src/models/native_script/core/native_script_type.dart +++ b/lib/ada/src/models/native_script/core/native_script_type.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; /// Represents a native script type. @@ -58,7 +59,7 @@ class NativeScriptType with ADASerialization { static NativeScriptType fromValue(int? value) { return values.firstWhere( (element) => element.value == value, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No NativeScriptType found matching the specified value", details: {"value": value}), ); @@ -68,7 +69,7 @@ class NativeScriptType with ADASerialization { static NativeScriptType fromName(String? name) { return values.firstWhere( (element) => element.name == name, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No NativeScriptType found matching the specified name", details: {"name": name}), ); diff --git a/lib/ada/src/models/native_script/utils/native_script_utils.dart b/lib/ada/src/models/native_script/utils/native_script_utils.dart index a5d879a..5f01207 100644 --- a/lib/ada/src/models/native_script/utils/native_script_utils.dart +++ b/lib/ada/src/models/native_script/utils/native_script_utils.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/models/native_script/core/native_script_type.dart'; /// Utility class for native script operations. @@ -7,7 +8,7 @@ class NativeScriptUtils { static void validateCborTypeObject(CborObject cbor, NativeScriptType type) { // Check if the CBOR object is an integer value if (cbor is! CborIntValue) { - throw MessageException("Invalid CBOR type for native script type.", + throw ADAPluginException("Invalid CBOR type for native script type.", details: {"Type": cbor.runtimeType}); } @@ -16,7 +17,7 @@ class NativeScriptUtils { // Check if the deserialized type matches the expected type if (cborType != type) { - throw MessageException("Invalid Native Script type.", + throw ADAPluginException("Invalid Native Script type.", details: {"Expected": type, "Actual": cborType}); } } diff --git a/lib/ada/src/models/plutus/plutus/core/plutus_data.dart b/lib/ada/src/models/plutus/plutus/core/plutus_data.dart index edab252..158d94b 100644 --- a/lib/ada/src/models/plutus/plutus/core/plutus_data.dart +++ b/lib/ada/src/models/plutus/plutus/core/plutus_data.dart @@ -1,5 +1,6 @@ import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:on_chain/ada/src/address/address.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; import 'package:on_chain/ada/src/models/credential/core/stake_cred.dart'; import 'package:on_chain/ada/src/models/credential/core/stake_cred_type.dart'; @@ -29,7 +30,7 @@ abstract class PlutusData try { type = PlutusDataType.fromName(json.keys.first); } on StateError { - throw MessageException("Invalid PlutusData json.", + throw ADAPluginException("Invalid PlutusData json.", details: {"json": json}); } switch (type) { @@ -67,7 +68,7 @@ abstract class PlutusData } else if (cbor is CborNumeric) { return PlutusInteger.deserialize(cbor); } - throw MessageException( + throw ADAPluginException( "Invalid cbor object.", details: {"Value": cbor, "Type": cbor.runtimeType}, ); diff --git a/lib/ada/src/models/plutus/plutus/core/plutus_data_type.dart b/lib/ada/src/models/plutus/plutus/core/plutus_data_type.dart index 73eb581..bd4fa43 100644 --- a/lib/ada/src/models/plutus/plutus/core/plutus_data_type.dart +++ b/lib/ada/src/models/plutus/plutus/core/plutus_data_type.dart @@ -1,5 +1,5 @@ import 'package:blockchain_utils/cbor/cbor.dart'; -import 'package:blockchain_utils/exception/exceptions.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; /// Represents different types of Plutus data. @@ -47,7 +47,7 @@ class PlutusDataType with ADASerialization { static PlutusDataType fromValue(int? value) { return values.firstWhere( (element) => element.value == value, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No PlutusDataType found matching the specified value", details: {"value": value}), ); @@ -57,7 +57,7 @@ class PlutusDataType with ADASerialization { static PlutusDataType fromName(String? name) { return values.firstWhere( (element) => element.name == name, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No PlutusDataType found matching the specified name", details: {"name": name}), ); diff --git a/lib/ada/src/models/plutus/plutus/types/constr_plutus_data.dart b/lib/ada/src/models/plutus/plutus/types/constr_plutus_data.dart index 2b94bab..8230a00 100644 --- a/lib/ada/src/models/plutus/plutus/types/constr_plutus_data.dart +++ b/lib/ada/src/models/plutus/plutus/types/constr_plutus_data.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; import 'package:on_chain/ada/src/models/plutus/plutus/core/plutus.dart'; import 'package:on_chain/ada/src/models/plutus/utils/utils.dart'; @@ -25,7 +26,7 @@ class ConstrPlutusData extends PlutusData { final BigInt? alternative = PlutusDataUtils.cborTagToAlternative(cbor.tags.first); if (alternative == null) { - throw const MessageException("Invalid ConstrPlutusData tag."); + throw const ADAPluginException("Invalid ConstrPlutusData tag."); } return ConstrPlutusData( alternative: alternative, diff --git a/lib/ada/src/models/plutus/plutus/types/map.dart b/lib/ada/src/models/plutus/plutus/types/map.dart index bd15144..4d9b3bd 100644 --- a/lib/ada/src/models/plutus/plutus/types/map.dart +++ b/lib/ada/src/models/plutus/plutus/types/map.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/models/plutus/plutus/core/plutus.dart'; import 'package:on_chain/ada/src/models/plutus/plutus/types/integer.dart'; import 'package:on_chain/ada/src/models/plutus/plutus/types/bytes.dart'; @@ -51,7 +52,7 @@ class PlutusMap extends PlutusData { final Map json = {}; for (final i in value.entries) { if (i.key is! PlutusInteger && i.key is! PlutusBytes) { - throw MessageException("plutus object are not allowed as key.", + throw ADAPluginException("plutus object are not allowed as key.", details: {"Key": i.key, "Type": i.key.runtimeType}); } final key = i.key.toJsonSchema(config: config).toString(); diff --git a/lib/ada/src/models/plutus/plutus_script/language/language.dart b/lib/ada/src/models/plutus/plutus_script/language/language.dart index f6fcb41..76bff41 100644 --- a/lib/ada/src/models/plutus/plutus_script/language/language.dart +++ b/lib/ada/src/models/plutus/plutus_script/language/language.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; class Language with ADASerialization { @@ -34,7 +35,7 @@ class Language with ADASerialization { static Language fromValue(int? value) { return values.firstWhere( (element) => element.value == value, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No Language found matching the specified value", details: {"value": value}), ); @@ -43,7 +44,7 @@ class Language with ADASerialization { static Language fromName(String? name) { return values.firstWhere( (element) => element.name == name, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No Language found matching the specified name", details: {"name": name}), ); diff --git a/lib/ada/src/models/plutus/plutus_script/redeemer_tag/redeemer_tag.dart b/lib/ada/src/models/plutus/plutus_script/redeemer_tag/redeemer_tag.dart index f9d9993..3cbb908 100644 --- a/lib/ada/src/models/plutus/plutus_script/redeemer_tag/redeemer_tag.dart +++ b/lib/ada/src/models/plutus/plutus_script/redeemer_tag/redeemer_tag.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; class RedeemerTag with ADASerialization { @@ -17,7 +18,7 @@ class RedeemerTag with ADASerialization { static RedeemerTag fromValue(int? value) { return values.firstWhere( (element) => element.value == value, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No RedeemerTag found matching the specified value", details: {"value": value}), ); @@ -26,7 +27,7 @@ class RedeemerTag with ADASerialization { static RedeemerTag fromName(String? name) { return values.firstWhere( (element) => element.name == name, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No RedeemerTag found matching the specified name", details: {"name": name}), ); diff --git a/lib/ada/src/models/plutus/utils/utils.dart b/lib/ada/src/models/plutus/utils/utils.dart index 85abd45..e0bf75f 100644 --- a/lib/ada/src/models/plutus/utils/utils.dart +++ b/lib/ada/src/models/plutus/utils/utils.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/models/fixed_bytes/models/models.dart'; import 'package:on_chain/ada/src/models/plutus/cost_model/cost_model.dart'; import 'package:on_chain/ada/src/models/plutus/plutus/core/plutus_data.dart'; @@ -85,7 +86,7 @@ class PlutusDataUtils { required dynamic value, required bool isKey}) { if (value is! String) { - throw MessageException("Invalid string format.", + throw ADAPluginException("Invalid string format.", details: {"Value": "$value", "Type": "${value.runtimeType}"}); } switch (schame) { @@ -102,7 +103,7 @@ class PlutusDataUtils { return PlutusBytes(value: StringUtils.encode(value)); default: if (value.startsWith("0x")) { - throw MessageException( + throw ADAPluginException( "Hex byte strings in detailed schema should NOT start with 0x", details: {"Value": value}); } @@ -112,7 +113,7 @@ class PlutusDataUtils { static PlutusData _encodeArray(dynamic value, PlutusJsonSchema jsonSchema) { if (value is! List) { - throw MessageException("Invalid list type.", details: {"value": value}); + throw ADAPluginException("Invalid list type.", details: {"value": value}); } return PlutusList(value.map((e) => parsePlutus(e, jsonSchema)).toList()); } @@ -126,10 +127,10 @@ class PlutusDataUtils { val is Map) return; } if (val != null) { - throw MessageException("Invalid plutus format. type not allowed.", + throw ADAPluginException("Invalid plutus format. type not allowed.", details: {"Value": val, "Type": "${val.runtimeType}"}); } - throw const MessageException("null not allowed in plutus data"); + throw const ADAPluginException("null not allowed in plutus data"); } static PlutusData _encodeMap(Map value, PlutusJsonSchema jsonSchema) { @@ -144,7 +145,7 @@ class PlutusDataUtils { static PlutusData _parseDetailed(dynamic value, PlutusJsonSchema schame) { if (value is! Map) { - throw const MessageException( + throw const ADAPluginException( "DetailedSchema requires types to be tagged objects"); } if (value.length == 1) { @@ -160,19 +161,19 @@ class PlutusDataUtils { return _encodeString(schame: schame, value: v, isKey: false); case "map": if (v is! List) { - throw const MessageException( + throw const ADAPluginException( r"entry format in detailed schema map object not correct. Needs to be of form '{'k': 'key', 'v': 'value'}'", ); } final Map values = {}; for (final i in v) { if (i is! Map) { - throw const MessageException( + throw const ADAPluginException( r"entry format in detailed schema map object not correct. Needs to be of form '{'k': 'key', 'v': 'value'}'", ); } if (!i.containsKey("k") || !i.containsKey("v")) { - throw const MessageException( + throw const ADAPluginException( r"entry format in detailed schema map object not correct. Needs to be of form '{'k': 'key', 'v': 'value'}'", ); } @@ -181,21 +182,21 @@ class PlutusDataUtils { } return PlutusMap(values); default: - throw MessageException("key is not valid.", details: {"Key": key}); + throw ADAPluginException("key is not valid.", details: {"Key": key}); } } else { if (value.length != 2) { - throw const MessageException( + throw const ADAPluginException( "detailed schemas must either have only one of the following keys: \"int\", \"bytes\", \"list\" or \"map\", or both of these 2 keys: \"constructor\" + \"fields\""); } final constructor = value["constructor"]; if (constructor is! int && constructor is! BigInt) { - throw const MessageException( + throw const ADAPluginException( "tagged constructors must contain an unsigned integer called \"constructor\""); } final fileds = value["fields"]; if (fileds is! List) { - throw const MessageException( + throw const ADAPluginException( "tagged constructors must contian a list called \"fields\""); } final List plutusList = []; diff --git a/lib/ada/src/models/transaction/output/script_ref/core/script_ref.dart b/lib/ada/src/models/transaction/output/script_ref/core/script_ref.dart index 839dd8d..0d95ffe 100644 --- a/lib/ada/src/models/transaction/output/script_ref/core/script_ref.dart +++ b/lib/ada/src/models/transaction/output/script_ref/core/script_ref.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; import 'package:on_chain/ada/src/models/transaction/output/script_ref/core/script_ref_type.dart'; import 'package:on_chain/ada/src/models/transaction/output/script_ref/refs/native_script.dart'; @@ -14,7 +15,7 @@ abstract class ScriptRef with ADASerialization { if (cbor.hasType()) { final cborTag = cbor.cast(); if (!BytesUtils.bytesEqual(cborTag.tags, _tag)) { - throw MessageException("Invalid ScriptRef cbor tag.", + throw ADAPluginException("Invalid ScriptRef cbor tag.", details: {"Excepted": _tag, "Tag": cborTag.tags}); } cbor = CborObject.fromCbor(cborTag.getValue>()).cast(); @@ -31,7 +32,7 @@ abstract class ScriptRef with ADASerialization { try { type = ScriptRefType.fromName(json.keys.first); } on StateError { - throw MessageException("Invalid ScriptRef json.", + throw ADAPluginException("Invalid ScriptRef json.", details: {"json": json}); } switch (type) { diff --git a/lib/ada/src/models/transaction/output/script_ref/core/script_ref_type.dart b/lib/ada/src/models/transaction/output/script_ref/core/script_ref_type.dart index 8c54e58..fdf2c26 100644 --- a/lib/ada/src/models/transaction/output/script_ref/core/script_ref_type.dart +++ b/lib/ada/src/models/transaction/output/script_ref/core/script_ref_type.dart @@ -1,6 +1,7 @@ import 'package:blockchain_utils/cbor/core/cbor.dart'; import 'package:blockchain_utils/cbor/types/int.dart'; -import 'package:blockchain_utils/exception/exception.dart'; + +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; /// Represents the type of a script reference. @@ -28,7 +29,7 @@ class ScriptRefType with ADASerialization { {ScriptRefType? validate}) { final type = fromValue(cbor.value); if (validate != null && type != validate) { - throw MessageException("Invalid ScriptRefType.", + throw ADAPluginException("Invalid ScriptRefType.", details: {"Expected": validate, "Type": type}); } return fromValue(cbor.value); @@ -43,7 +44,7 @@ class ScriptRefType with ADASerialization { static ScriptRefType fromValue(int? value) { return values.firstWhere( (element) => element.value == value, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No ScriptRefType found matching the specified value", details: {"value": value}), ); @@ -53,7 +54,7 @@ class ScriptRefType with ADASerialization { static ScriptRefType fromName(String? name) { return values.firstWhere( (element) => element.name == name, - orElse: () => throw MessageException( + orElse: () => throw ADAPluginException( "No ScriptRefType found matching the specified name", details: {"name": name}), ); diff --git a/lib/ada/src/models/unit_interval.dart b/lib/ada/src/models/unit_interval.dart index 71ca0ee..e88104a 100644 --- a/lib/ada/src/models/unit_interval.dart +++ b/lib/ada/src/models/unit_interval.dart @@ -1,6 +1,6 @@ import 'package:blockchain_utils/cbor/cbor.dart'; -import 'package:blockchain_utils/exception/exceptions.dart'; import 'package:blockchain_utils/utils/utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; class UnitInterval with ADASerialization { @@ -17,7 +17,7 @@ class UnitInterval with ADASerialization { factory UnitInterval.deserialize(CborTagValue cbor) { if (!BytesUtils.bytesEqual(cbor.tags, _cborTag)) { - throw MessageException("Invalid UnitInterval cbor tag.", + throw ADAPluginException("Invalid UnitInterval cbor tag.", details: {"Excepted": _cborTag, "Tag": cbor.tags}); } final cborList = cbor.getValue(); diff --git a/lib/ada/src/models/update/models/nonce.dart b/lib/ada/src/models/update/models/nonce.dart index 4142015..cdaa8d3 100644 --- a/lib/ada/src/models/update/models/nonce.dart +++ b/lib/ada/src/models/update/models/nonce.dart @@ -1,7 +1,8 @@ import 'package:blockchain_utils/utils/utils.dart'; import 'package:blockchain_utils/cbor/core/cbor.dart'; import 'package:blockchain_utils/cbor/types/types.dart'; -import 'package:blockchain_utils/exception/exception.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; + import 'package:on_chain/ada/src/models/constant.dart'; import 'package:on_chain/ada/src/serialization/cbor_serialization.dart'; import 'package:on_chain/ada/src/models/utils.dart'; @@ -18,7 +19,7 @@ class Nonce with ADASerialization { factory Nonce.deserialize(CborListValue cbor) { final int hasHash = cbor.getIndex(0); if (hasHash != 0 && hasHash != 1) { - throw const MessageException("Invalid Nonce cbor bytes."); + throw const ADAPluginException("Invalid Nonce cbor bytes."); } return Nonce(hasHash == 0 ? null : cbor.getIndex(1)); } diff --git a/lib/ada/src/models/utils.dart b/lib/ada/src/models/utils.dart index 15b0ed1..1563544 100644 --- a/lib/ada/src/models/utils.dart +++ b/lib/ada/src/models/utils.dart @@ -1,5 +1,6 @@ import 'package:blockchain_utils/utils/utils.dart'; import 'package:blockchain_utils/exception/exceptions.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; class AdaTransactionUtils { static List validateFixedLengthBytes( @@ -8,7 +9,7 @@ class AdaTransactionUtils { bool unmodifiable = true, String? objectName}) { if (bytes.length != length) { - throw MessageException("Invalid ${objectName ?? 'hash'} length.", + throw ADAPluginException("Invalid ${objectName ?? 'hash'} length.", details: {"Excepted": length, "length": bytes.length}); } return BytesUtils.toBytes(bytes, unmodifiable: unmodifiable); @@ -27,7 +28,7 @@ class AdaTransactionUtils { } on MessageException { rethrow; } catch (e) { - throw MessageException("Invalid hex bytes.", + throw ADAPluginException("Invalid hex bytes.", details: {"value": hexBytes}); } } diff --git a/lib/ada/src/provider/blockfrost/core/core.dart b/lib/ada/src/provider/blockfrost/core/core.dart index 63cc0ed..99f93c3 100644 --- a/lib/ada/src/provider/blockfrost/core/core.dart +++ b/lib/ada/src/provider/blockfrost/core/core.dart @@ -1,4 +1,4 @@ -import 'package:blockchain_utils/exception/exception.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; import 'package:on_chain/ada/src/provider/blockfrost/models/models/filter_params.dart'; import 'package:on_chain/ada/src/provider/blockfrost/utils/blockforest_provider_utils.dart'; import 'package:on_chain/global_types/provider_request.dart'; @@ -27,7 +27,7 @@ abstract class BlockforestRequestParam BlockforestRequestDetails toRequest(int v) { final pathParams = BlockforestProviderUtils.extractParams(method); if (pathParams.length != pathParameters.length) { - throw MessageException("Invalid Path Parameters.", details: { + throw ADAPluginException("Invalid Path Parameters.", details: { "pathParams": pathParameters, "ExceptedPathParametersLength": pathParams.length }); diff --git a/lib/ada/src/serialization/cbor/cbor_i164.dart b/lib/ada/src/serialization/cbor/cbor_i164.dart index 1de14de..ca5c789 100644 --- a/lib/ada/src/serialization/cbor/cbor_i164.dart +++ b/lib/ada/src/serialization/cbor/cbor_i164.dart @@ -1,7 +1,8 @@ import 'package:blockchain_utils/utils/utils.dart'; import 'package:blockchain_utils/cbor/types/types.dart'; import 'package:blockchain_utils/cbor/core/cbor.dart'; -import 'package:blockchain_utils/exception/exception.dart'; + +import 'package:on_chain/ada/src/exception/exception.dart'; /// A class representing a CBOR (Concise Binary Object Representation) int (64-byte) value. class CborSignedValue implements CborNumeric { @@ -11,20 +12,20 @@ class CborSignedValue implements CborNumeric { factory CborSignedValue.i64(dynamic value) { if (value is! int && value is! BigInt) { - throw MessageException( + throw ADAPluginException( "Invalid unsgined int. value must be int or bigint.", details: {"valye": value}); } if (value is BigInt && value.bitLength > 64) { - throw MessageException("Invalid signed 64-bit Integer.", + throw ADAPluginException("Invalid signed 64-bit Integer.", details: {"Value": value, "bitLength": value.bitLength}); } return CborSignedValue._(value); } factory CborSignedValue.i32(int value) { if (value.bitLength > 32) { - throw MessageException("Invalid signed 32-bit Integer.", + throw ADAPluginException("Invalid signed 32-bit Integer.", details: {"Value": value, "bitLength": value.bitLength}); } return CborSignedValue._(value); diff --git a/lib/ada/src/serialization/cbor/cbor_serialization.dart b/lib/ada/src/serialization/cbor/cbor_serialization.dart index 4b659ea..daf2ea5 100644 --- a/lib/ada/src/serialization/cbor/cbor_serialization.dart +++ b/lib/ada/src/serialization/cbor/cbor_serialization.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; /// A mixin providing serialization functionality to classes. mixin ADASerialization { @@ -19,7 +20,7 @@ mixin ADASerialization { static T desrialize(List cborBytes) { final decode = CborObject.fromCbor(cborBytes); if (decode is! T) { - throw MessageException("Failed to deserialize CBOR bytes into type.", + throw ADAPluginException("Failed to deserialize CBOR bytes into type.", details: {"type": "$T", "Excepted": decode.runtimeType}); } return decode; @@ -40,7 +41,7 @@ extension QuickCborObject on CborObject { try { return this as T; } catch (e) { - throw MessageException(onError ?? "Failed to cast CBOR object", + throw ADAPluginException(onError ?? "Failed to cast CBOR object", details: {"Type": "$T", "Value": value}); } } @@ -56,7 +57,7 @@ extension QuickCborObject on CborObject { } if (null is T && value is CborNullValue) return null as T; if (value is! T) { - throw MessageException("Failed to cast value.", details: { + throw ADAPluginException("Failed to cast value.", details: { "Value": value.runtimeType, "Type": "$T", }); @@ -69,7 +70,7 @@ extension QuickCborObject on CborObject { /// Throws a [MessageException] if the value is not of type [int] or [BigInt]. BigInt getInteger() { if (value is! int && value is! BigInt) { - throw MessageException("Failed to cast value to integer.", details: { + throw ADAPluginException("Failed to cast value to integer.", details: { "Value": value, "Type": value.runtimeType, }); @@ -86,7 +87,7 @@ extension QuickCborObject on CborObject { return toe(this as T); } if (value is! T) { - throw MessageException("Failed to cast value.", details: { + throw ADAPluginException("Failed to cast value.", details: { "Value": "$value", "Type": "$T", }); @@ -108,7 +109,7 @@ extension QuickCborList on CborListValue { T getIndex(int index) { if (index >= value.length) { if (null is T) return null as T; - throw MessageException("Index out of bounds.", + throw ADAPluginException("Index out of bounds.", details: {"length": value.length, "index": index}); } @@ -118,7 +119,7 @@ extension QuickCborList on CborListValue { } if (obj is T) return obj as T; if (obj.value is! T) { - throw MessageException("Failed to cast value.", + throw ADAPluginException("Failed to cast value.", details: {"Excepted": obj.value.runtimeType, "Type": "$T"}); } return obj.value; @@ -130,7 +131,7 @@ extension QuickCborList on CborListValue { /// If [start] or [end] are out of bounds, throws a [MessageException] CborListValue sublist(int start, [int? end]) { if (start >= value.length || (end != null && end >= value.length)) { - throw MessageException("Index out of bounds.", + throw ADAPluginException("Index out of bounds.", details: {"length": value.length, "Start": start, "End": end}); } return CborListValue.fixedLength((value as List) @@ -151,7 +152,7 @@ extension QuickCborMap on CborMapValue { if (null is T && val is CborNullValue) return null as T; if (val is CborObject && val.value is T) return val.value; if (val is! T) { - throw MessageException("Failed to cast value.", + throw ADAPluginException("Failed to cast value.", details: {"Excepted": val.runtimeType, "Type": "$T"}); } return val; @@ -163,7 +164,7 @@ extension QuickCborMap on CborMapValue { T getValue(CborObject key) { if (!value.containsKey(key)) { if (null is T) return null as T; - throw MessageException("Key does not exist.", details: { + throw ADAPluginException("Key does not exist.", details: { "Key": "${key.runtimeType}", "Keys": value.keys.map((e) => e.runtimeType).join(", ") }); @@ -172,7 +173,7 @@ extension QuickCborMap on CborMapValue { if (null is T && val is CborNullValue) return null as T; if (val is CborObject && val.value is T) return val.value; if (val is! T) { - throw MessageException("Failed to cast value.", + throw ADAPluginException("Failed to cast value.", details: {"Excepted": "${val.runtimeType}", "Type": "$T"}); } return val; diff --git a/lib/ada/src/serialization/cbor/cbor_u64.dart b/lib/ada/src/serialization/cbor/cbor_u64.dart index c26dd01..356520f 100644 --- a/lib/ada/src/serialization/cbor/cbor_u64.dart +++ b/lib/ada/src/serialization/cbor/cbor_u64.dart @@ -1,7 +1,7 @@ import 'package:blockchain_utils/utils/utils.dart'; import 'package:blockchain_utils/cbor/types/types.dart'; import 'package:blockchain_utils/cbor/core/cbor.dart'; -import 'package:blockchain_utils/exception/exception.dart'; +import 'package:on_chain/ada/src/exception/exception.dart'; /// A class representing a CBOR (Concise Binary Object Representation) int (64-byte) value. class CborUnsignedValue implements CborNumeric { @@ -11,20 +11,20 @@ class CborUnsignedValue implements CborNumeric { factory CborUnsignedValue.u64(dynamic value) { if (value is! int && value is! BigInt) { - throw MessageException( + throw ADAPluginException( "Invalid unsgined int. value must be int or bigint.", details: {"value": value}); } final BigInt bigintVal = value is int ? BigInt.from(value) : value; if (bigintVal.isNegative || bigintVal.bitLength > 64) { - throw MessageException("Invalid unsigned 64-bit Integer.", + throw ADAPluginException("Invalid unsigned 64-bit Integer.", details: {"Value": bigintVal, "bitLength": bigintVal.bitLength}); } return CborUnsignedValue._(bigintVal); } factory CborUnsignedValue.u32(int value) { if (value.isNegative || value.bitLength > 32) { - throw MessageException("Invalid unsigned 32-bit Integer.", + throw ADAPluginException("Invalid unsigned 32-bit Integer.", details: {"Value": value, "bitLength": value.bitLength}); } return CborUnsignedValue._(value); diff --git a/lib/ethereum/ethereum.dart b/lib/ethereum/ethereum.dart index 1c675a0..0f880b7 100644 --- a/lib/ethereum/ethereum.dart +++ b/lib/ethereum/ethereum.dart @@ -23,3 +23,6 @@ export 'src/transaction/transaction.dart'; /// General Ethereum-related helper functions export 'src/utils/helper.dart'; + +/// All related ethereum exception +export 'src/exception/exception.dart'; diff --git a/lib/ethereum/src/address/evm_address.dart b/lib/ethereum/src/address/evm_address.dart index 1b8c25f..e169e63 100644 --- a/lib/ethereum/src/address/evm_address.dart +++ b/lib/ethereum/src/address/evm_address.dart @@ -1,3 +1,4 @@ +import 'package:on_chain/ethereum/src/exception/exception.dart'; import 'package:on_chain/solidity/address/core.dart'; import 'package:blockchain_utils/bip/address/eth_addr.dart'; import 'package:blockchain_utils/blockchain_utils.dart'; @@ -22,7 +23,7 @@ class ETHAddress extends SolidityAddress { final toAddress = EthAddrEncoder().encodeKey(keyBytes); return ETHAddress._(toAddress); } catch (e) { - throw MessageException("invalid ethreum public key", + throw ETHPluginException("invalid ethreum public key", details: {"input": BytesUtils.toHexString(keyBytes)}); } } @@ -35,7 +36,7 @@ class ETHAddress extends SolidityAddress { EthAddrDecoder().decodeAddr(address, {"skip_chksum_enc": skipChecksum}); return ETHAddress._(EthAddrUtils.toChecksumAddress(address)); } catch (e) { - throw MessageException("invalid ethereum address", + throw ETHPluginException("invalid ethereum address", details: {"input": address}); } } diff --git a/lib/ethereum/src/exception/exception.dart b/lib/ethereum/src/exception/exception.dart new file mode 100644 index 0000000..954dd48 --- /dev/null +++ b/lib/ethereum/src/exception/exception.dart @@ -0,0 +1,6 @@ +import 'package:blockchain_utils/exception/exceptions.dart'; + +class ETHPluginException extends BlockchainUtilsException { + const ETHPluginException(String message, {Map? details}) + : super(message, details: details); +} diff --git a/lib/ethereum/src/keys/private_key.dart b/lib/ethereum/src/keys/private_key.dart index c711542..10cdc9d 100644 --- a/lib/ethereum/src/keys/private_key.dart +++ b/lib/ethereum/src/keys/private_key.dart @@ -1,3 +1,4 @@ +import 'package:on_chain/ethereum/src/exception/exception.dart'; import 'package:on_chain/ethereum/src/keys/public_key.dart'; import 'package:blockchain_utils/blockchain_utils.dart'; @@ -21,7 +22,7 @@ class ETHPrivateKey { Secp256k1PrivateKeyEcdsa.fromBytes(keyBytes); return ETHPrivateKey._(key); } catch (e) { - throw MessageException("invalid ethereum private key", + throw ETHPluginException("invalid ethereum private key", details: {"input": BytesUtils.toHexString(keyBytes)}); } } diff --git a/lib/ethereum/src/keys/public_key.dart b/lib/ethereum/src/keys/public_key.dart index bc8410a..6dad2d0 100644 --- a/lib/ethereum/src/keys/public_key.dart +++ b/lib/ethereum/src/keys/public_key.dart @@ -1,6 +1,7 @@ import 'package:on_chain/ethereum/src/address/evm_address.dart'; import 'package:blockchain_utils/bip/address/p2pkh_addr.dart'; import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ethereum/src/exception/exception.dart'; /// Class representing an Ethereum public key, providing methods for conversion, verification, and address generation. class ETHPublicKey { @@ -16,7 +17,7 @@ class ETHPublicKey { final pubKey = Secp256k1PublicKeyEcdsa.fromBytes(keyBytes); return ETHPublicKey._(pubKey); } catch (e) { - throw MessageException("invalid public key", + throw ETHPluginException("invalid public key", details: {"input": BytesUtils.toHexString(keyBytes)}); } } diff --git a/lib/ethereum/src/models/access_list.dart b/lib/ethereum/src/models/access_list.dart index 856e62f..868caee 100644 --- a/lib/ethereum/src/models/access_list.dart +++ b/lib/ethereum/src/models/access_list.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ethereum/src/exception/exception.dart'; /// Represents a list of access list entries. typedef AccessList = List; @@ -29,7 +30,7 @@ class AccessListEntry { .toList(); return AccessListEntry(address: addr, storageKeys: storageKeys); } catch (e) { - throw const MessageException("invalid AccessListEntry serialized"); + throw const ETHPluginException("invalid AccessListEntry serialized"); } } diff --git a/lib/ethereum/src/rlp/decode.dart b/lib/ethereum/src/rlp/decode.dart index 2bd9e42..69974f9 100644 --- a/lib/ethereum/src/rlp/decode.dart +++ b/lib/ethereum/src/rlp/decode.dart @@ -1,4 +1,5 @@ import 'package:blockchain_utils/blockchain_utils.dart'; +import 'package:on_chain/ethereum/src/exception/exception.dart'; /// Class for decoding data encoded using the Recursive Length Prefix (RLP) encoding scheme. class RLPDecoder { @@ -23,7 +24,7 @@ class RLPDecoder { childOffset += decoded.consumed; if (childOffset > offset + 1 + length) { - throw const MessageException("child data too short"); + throw const ETHPluginException("child data too short"); } } @@ -33,7 +34,7 @@ class RLPDecoder { /// Decode a single RLP-encoded item. static _Decoded _decode(List data, int offset) { if (data.isEmpty) { - throw const MessageException("data too short"); + throw const ETHPluginException("data too short"); } if (data[offset] >= 0xf8) { @@ -64,13 +65,13 @@ class RLPDecoder { try { _Decoded decoded = _decode(data, 0); if (decoded.consumed != data.length) { - throw const MessageException("invalid rpl payload bytes"); + throw const ETHPluginException("invalid rpl payload bytes"); } return decoded.result; } on MessageException { rethrow; } catch (e) { - throw const MessageException("cannot decode rpl payload"); + throw const ETHPluginException("cannot decode rpl payload"); } } } diff --git a/lib/ethereum/src/rpc/provider/provider.dart b/lib/ethereum/src/rpc/provider/provider.dart index adb634d..08ed132 100644 --- a/lib/ethereum/src/rpc/provider/provider.dart +++ b/lib/ethereum/src/rpc/provider/provider.dart @@ -12,18 +12,19 @@ class EVMRPC { /// Creates a new instance of the [EVMRPC] class with the specified [rpc]. EVMRPC(this.rpc); - /// Finds the result in the JSON-RPC response data or throws an [RPCException] + /// Finds the result in the JSON-RPC response data or throws an [RPCError] /// if an error is encountered. dynamic _findResult(Map data, ETHRequestDetails request) { - if (data["error"] != null) { - final code = int.tryParse(((data["error"]?['code']?.toString()) ?? "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 ?? 0, - message: message, - data: data["error"]?["data"], - request: data["request"] ?? StringUtils.toJson(request.toRequestBody()), - ); + errorCode: code, + message: message, + request: + data["request"] ?? StringUtils.toJson(request.toRequestBody()), + details: error); } return data["result"]; diff --git a/lib/ethereum/src/transaction/eth_transaction.dart b/lib/ethereum/src/transaction/eth_transaction.dart index 857f251..b339532 100644 --- a/lib/ethereum/src/transaction/eth_transaction.dart +++ b/lib/ethereum/src/transaction/eth_transaction.dart @@ -1,4 +1,5 @@ import 'package:on_chain/ethereum/src/address/evm_address.dart'; +import 'package:on_chain/ethereum/src/exception/exception.dart'; import 'package:on_chain/ethereum/src/rlp/decode.dart'; import 'package:on_chain/ethereum/src/rlp/encode.dart'; import 'package:on_chain/ethereum/src/models/access_list.dart'; @@ -302,7 +303,7 @@ class ETHTransaction { /// Factory constructor to create an [ETHTransaction] from serialized transaction bytes. factory ETHTransaction.fromSerialized(List transactionBytes) { if (transactionBytes.isEmpty) { - throw const MessageException("invalid transaction bytes"); + throw const ETHPluginException("invalid transaction bytes"); } List bytes = List.from(transactionBytes); final int prefix = bytes[0]; @@ -310,7 +311,7 @@ class ETHTransaction { bytes = bytes.sublist(1); } else { if (prefix < 0x7f) { - throw const MessageException("unsupported transaction type"); + throw const ETHPluginException("unsupported transaction type"); } } final decode = RLPDecoder.decode(bytes); @@ -454,7 +455,7 @@ class ETHTransaction { if (chainId != BigInt.zero) { v = _ETHTransactionUtils.getLegacyChainId(sig.v, chainId); } else if (BigInt.from(sig.v) != v) { - throw const MessageException("Mismatch chainID/Signature.V"); + throw const ETHPluginException("Mismatch chainID/Signature.V"); } fields.add(BigintUtils.toBytes(v, length: BigintUtils.bitlengthInBytes(v))); fields.add(_ETHTransactionUtils.trimLeadingZero(sig.rBytes)); @@ -470,7 +471,7 @@ class ETHTransaction { if (maxFeePerGas != null && maxPriorityFeePerGas != null) { if (maxPriorityFeePerGas! > maxFeePerGas!) { - throw MessageException("priorityFee cannot be more than maxFee", + throw ETHPluginException("priorityFee cannot be more than maxFee", details: { "priorityFee": maxFeePerGas, "maxFee": maxPriorityFeePerGas @@ -481,11 +482,11 @@ class ETHTransaction { if (type == ETHTransactionType.legacy || type == ETHTransactionType.eip2930) { if (gasPrice == null) { - throw const MessageException( + throw const ETHPluginException( "Gas price must not be null for legacy transactions."); } if (maxFeePerGas != null || maxPriorityFeePerGas != null) { - throw MessageException( + throw ETHPluginException( "maxFeePerGas and maxPriorityFeePerGas must be null for legacy transactions.", details: { "maxFeePerGas": maxFeePerGas, @@ -493,24 +494,24 @@ class ETHTransaction { }); } if (type == ETHTransactionType.legacy && hasAccessList) { - throw MessageException( + throw ETHPluginException( "accsesslist must be null or empty for legacy transactions", details: {"accessList": accessList}); } } else { if (gasPrice != null) { - throw MessageException( + throw ETHPluginException( "Gas price must be null for EIP1559 transactions.", details: {"gasPrice": gasPrice}); } if (maxFeePerGas == null || maxPriorityFeePerGas == null) { - throw const MessageException( + throw const ETHPluginException( "maxFeePerGas and maxPriorityFeePerGas must not be null for EIP1559 transactions."); } } } else { if (!hasGasPrice && !isEIP1559) { - throw const MessageException( + throw const ETHPluginException( "use gasPrice for legacy or Eip2930 transaction or priorityFee and maxFee for Eip1559 transactions"); } } @@ -550,7 +551,7 @@ class ETHTransaction { List signedSerialized([ETHSignature? sig]) { sig ??= signature; if (sig == null) { - throw const MessageException( + throw const ETHPluginException( "The transaction signed serialized cannot be obtained before the signing process."); } return _serialized(sig); diff --git a/lib/ethereum/src/transaction/eth_transaction_builder.dart b/lib/ethereum/src/transaction/eth_transaction_builder.dart index 8d8dd1e..9a11f5a 100644 --- a/lib/ethereum/src/transaction/eth_transaction_builder.dart +++ b/lib/ethereum/src/transaction/eth_transaction_builder.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:on_chain/ethereum/src/exception/exception.dart'; import 'package:on_chain/solidity/contract/fragments.dart'; import 'package:on_chain/ethereum/src/address/evm_address.dart'; import 'package:on_chain/ethereum/src/keys/private_key.dart'; @@ -52,7 +53,7 @@ class ETHTransactionBuilder { if (value > BigInt.zero) { if (function.stateMutability != null && function.stateMutability != StateMutability.payable) { - throw const MessageException( + throw const ETHPluginException( "For calling non-payable methods, the transaction value must be set to zero."); } } @@ -137,7 +138,7 @@ class ETHTransactionBuilder { List signedSerializedTransaction([ETHSignature? signature]) { signature ??= _signature; if (signature == null) { - throw const MessageException( + throw const ETHPluginException( "The transaction signed serialized cannot be obtained before the signing process."); } return _transaction.signedSerialized(signature); @@ -194,7 +195,7 @@ class ETHTransactionBuilder { /// is not used in this type of transaction. void setGasPrice(BigInt gasPrice) { if (_type == ETHTransactionType.eip1559) { - throw const MessageException( + throw const ETHPluginException( "Do not specify a gasPrice for non-legacy transactions."); } _gasPrice = gasPrice; @@ -206,7 +207,7 @@ class ETHTransactionBuilder { /// Throws a [MessageException] if the transaction type is not EIP-1559. void setEIP1559FeeDetails(BigInt maxFeePerGas, BigInt maxPriorityFeePerGas) { if (_type != ETHTransactionType.eip1559) { - throw const MessageException( + throw const ETHPluginException( "Do not specify a maxPriorityFeePerGas and maxFeePerGas for legacy transactions. use setGasPrice"); } _maxFeePerGas = maxFeePerGas; @@ -240,7 +241,7 @@ class ETHTransactionBuilder { newestBlock: BlockTagOrNumber.pending, rewardPercentiles: [25, 50, 75])); if (historical == null) { - throw const MessageException( + throw const ETHPluginException( "The network in question does not currently support the London hard fork, including the EIP-1559 upgrade. use legacy transaction"); } final fee = historical.toFee(); @@ -334,7 +335,7 @@ class ETHTransactionBuilder { /// Throws an exception if the transaction is not signed. String get transactionID { if (_signature == null) { - throw const MessageException( + throw const ETHPluginException( "The transaction hash cannot be obtained before the signing process."); } return BytesUtils.toHexString( @@ -346,7 +347,7 @@ class ETHTransactionBuilder { void _checkError() { final errors = _validate(); if (errors.isEmpty) return; - throw MessageException("some fields not filled", details: errors); + throw ETHPluginException("some fields not filled", details: errors); } /// Converts the transaction details into a map for estimating gas or access list. diff --git a/lib/solana/src/exception/exception.dart b/lib/solana/src/exception/exception.dart index f054f19..2cc2c3b 100644 --- a/lib/solana/src/exception/exception.dart +++ b/lib/solana/src/exception/exception.dart @@ -1,20 +1,6 @@ import 'package:blockchain_utils/exception/exceptions.dart'; class SolanaPluginException extends BlockchainUtilsException { - const SolanaPluginException(this.message, {this.details}); - - @override - final String message; - - @override - final Map? details; - - @override - String toString() { - String msg = message; - if (details?.isNotEmpty ?? false) { - msg += ' Details: $details'; - } - return msg; - } + const SolanaPluginException(String message, {Map? details}) + : super(message, details: details); } diff --git a/lib/solana/src/instructions/name_service/name_service_twitter_helper.dart b/lib/solana/src/instructions/name_service/name_service_twitter_helper.dart index f342d4b..7755c66 100644 --- a/lib/solana/src/instructions/name_service/name_service_twitter_helper.dart +++ b/lib/solana/src/instructions/name_service/name_service_twitter_helper.dart @@ -213,7 +213,7 @@ class NameServiceProgramTwitterHelper { return ReverseTwitterRegistryAccount.fromAccountBytes(accountBytes); } } - throw Exception('Registry not found.'); + throw const SolanaPluginException('Registry not found.'); } /// Uses the RPC node filtering feature, execution speed may vary diff --git a/lib/solana/src/rpc/provider/provider.dart b/lib/solana/src/rpc/provider/provider.dart index b9fa0b9..ba2da5f 100644 --- a/lib/solana/src/rpc/provider/provider.dart +++ b/lib/solana/src/rpc/provider/provider.dart @@ -11,20 +11,20 @@ class SolanaRPC { /// Creates a new instance of the [SolanaRPC] class with the specified [rpc]. SolanaRPC(this.rpc); - /// Finds the result in the JSON-RPC response data or throws an [RPCException] + /// Finds the result in the JSON-RPC response data or throws an [RPCError] /// if an error is encountered. dynamic _findResult(Map data, SolanaRequestDetails request) { - if (data["error"] != null) { - final code = int.tryParse(((data["error"]?['code']?.toString()) ?? "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 ?? 0, - message: message, - data: data["error"]?["data"], - request: data["request"] ?? StringUtils.toJson(request.toRequestBody()), - ); + errorCode: code, + message: message, + request: + data["request"] ?? StringUtils.toJson(request.toRequestBody()), + details: error); } - return data["result"]; } diff --git a/lib/solana/src/utils/layouts.dart b/lib/solana/src/utils/layouts.dart index 0fbcd8c..8160374 100644 --- a/lib/solana/src/utils/layouts.dart +++ b/lib/solana/src/utils/layouts.dart @@ -13,11 +13,9 @@ class SolanaLayoutUtils { /// optional [SolAddress] values. static OptionalLayout optionPubkey( - {String? property, bool keepSize = false, Layout? discriminator}) { + {String? property, bool keepSize = false}) { return OptionalLayout(publicKey(), - property: property, - keepLayoutSize: keepSize, - discriminator: discriminator); + property: property, keepLayoutSize: keepSize); } static COptionLayout cOptionPubkey( diff --git a/lib/solidity/abi/exception/abi_exception.dart b/lib/solidity/abi/exception/abi_exception.dart index 4862829..4f42dca 100644 --- a/lib/solidity/abi/exception/abi_exception.dart +++ b/lib/solidity/abi/exception/abi_exception.dart @@ -1,20 +1,6 @@ part of "package:on_chain/solidity/abi/abi.dart"; class SolidityAbiException extends BlockchainUtilsException { - @override - final Map? details; - - @override - final String message; - - const SolidityAbiException(this.message, {this.details}); - - @override - String toString() { - String msg = message; - if (details?.isNotEmpty ?? false) { - msg += ' Details: $details'; - } - return msg; - } + const SolidityAbiException(String message, {Map? details}) + : super(message, details: details); } diff --git a/lib/tron/src/exception/exception.dart b/lib/tron/src/exception/exception.dart index 02808fd..72d040b 100644 --- a/lib/tron/src/exception/exception.dart +++ b/lib/tron/src/exception/exception.dart @@ -1,20 +1,6 @@ import 'package:blockchain_utils/exception/exceptions.dart'; class TronPluginException extends BlockchainUtilsException { - const TronPluginException(this.message, {this.details}); - - @override - final String message; - - @override - final Map? details; - - @override - String toString() { - String msg = message; - if (details?.isNotEmpty ?? false) { - msg += ' Details: $details'; - } - return msg; - } + const TronPluginException(String message, {Map? details}) + : super(message, details: details); } diff --git a/lib/utils/utils/number_utils.dart b/lib/utils/utils/number_utils.dart index 3dbc63a..c68cfd8 100644 --- a/lib/utils/utils/number_utils.dart +++ b/lib/utils/utils/number_utils.dart @@ -41,18 +41,10 @@ class PluginIntUtils { } class PluginBooleanUtils { - static bool hexToBool(String v) { - if (v == "0x" || v != "0x1" && v != "0x0") { - throw ArgumentError("invalid hex for bolean $v"); - } - return v == "0x1"; - } - static bool? tryHexToBool(String? v) { - try { - return hexToBool(v!); - } catch (e) { + if (v == "0x" || v != "0x1" && v != "0x0") { return null; } + return v == "0x1"; } } diff --git a/pubspec.yaml b/pubspec.yaml index 5460dad..57315b9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: on_chain description: Streamline Ethereum, Tron, Solana and Cardano operations. Effortlessly create transactions, interact with smart contracts, sign, and send transactions. -version: 4.2.0 +version: 4.3.0 homepage: "https://github.com/mrtnetwork/on_chain" repository: "https://github.com/mrtnetwork/on_chain" Author: mrhaydari.t@gmail.com @@ -17,7 +17,7 @@ environment: dependencies: - blockchain_utils: ^3.3.0 + blockchain_utils: ^3.4.0 # blockchain_utils: # path: ../blockchain_utils